Re: Example network protocol implementation

2006-12-11 Thread Robert Watson


On Sun, 10 Dec 2006, M. Warner Losh wrote:


In message: [EMAIL PROTECTED]
   Vishal Patil [EMAIL PROTECTED] writes:
: Would like to thank you all folks. These conversations are really good way
: of learning things...Also it is good to know different perspectives for
: solving the same problem

Yes.  the ng_iscsi suggestion is also viable.  It may be a little less work 
than going to the raw sockets.  Careful performance measurements may be 
necessary, however, since there have been cases when the ng_foo 
implementation wasn't fast enough and going to a lower level was necessary. 
There have also been many cases where ng_bar was perfectly fast enough and 
there was no need to go to the lower leve.  At the very least, the ng code 
will get you to layer your code well and provide a faster means of 
development than going to the raw socket layer.


As someone who doesn't consume Netgraph a lot, can you tell me what benefit 
using Netgraph for something like iSCSI might have when compared with the 
kernel socket API used to implement user sockets, NFS, SMB, etc?  Are there 
parsing/decapsulation parts of the protocol that lend themselves well to 
netgraphs more modular approach vs. the more traditional approach of layering 
RPC wrapping over the socket layer?


BTW, one of the things on my todo list is a socket(9) man page, which is well 
overdue.  I've been postponing writing it while finishing up the kernel socket 
API cleanup in -CURRENT.


Robert N M Watson
Computer Laboratory
University of Cambridge
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-11 Thread Robert Watson

On Sat, 9 Dec 2006, Vishal Patil wrote:

Could someone point me to an example that shows a SIMPLE network protocol 
implemented over TCP/IP inside the FreeBSD kernel. I think I could look at 
the NFS client driver but is there an example simpler than that. Also is 
there a guide explaining how to go about developing TCP/IP based network 
protocols for FreeBSD. Thanks


Here are some consumers of sockets in the kernel:

- NFS client, which creates and connects both UDP and TCP sockets, uses them
  for I/O, etc.

- NFS server, which uses UDP and TCP sockets for I/O.  Unlike the NFS client,
  it doesn't open the sockets in kernel, rather, it relies on a user process
  (nfsd) passing validated sockets into the kernel.

- System V streams (dev/streams), which uses socket pairs to implement
  streams.  Does creation and I/O.

- fifofs, which implements POSIX fifos using a pair of UNIX domain sockets.
  Again, does creation and I/O.

- portalfs, which implements the portal file system using sockets.

- ng_ksocket, which provides a netgraph interface to sockets in the kernel.

- netncp, which provides an NCP RPC interface over SPX/IPX for nwfs.

- netsmb, which provides an SMB RPC interface over TCP/IP for smbfs.

- rpclnt, which is used by the nfs4client, and is functionally similar to the
  NFS client RPC code for NFS2/NFS3 in nfsclient.

- bootp_subr.c and krpc_subr.c, which are used by the NFS root code to set up
  NFS access during a diskless boot: they perform the bootp exchange to
  retrieve an IP address, and then the necessary RPC mount protocol to query a
  root file handle to set up the NFS client for the file system root.

All of these examples have upsides and downsides, and vary in maturity.  I'd 
probably start by looking at the NFS client and fifofs.  One of the biggest 
questions you'll need to answer is what your event model is and how it will 
relate to any worker threads you may have.  Many of the in-kernel socket 
consumers use socket upcalls to get direct notifications of socket events from 
within the network stack, allowing for fast socket draining and TCP acking. 
On the other hand, in the netisr/ithread context, you can't perform blocking 
memory allocation and disk I/O, so if that will be involved, you'll need 
worker threads in the style of the NFS server.


Robert N M Watson
Computer Laboratory
University of Cambridge
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-10 Thread Garrett Cooper
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

M. Warner Losh wrote:
 In message: [EMAIL PROTECTED]
 Vishal Patil [EMAIL PROTECTED] writes:
 : Would like to thank you all folks. These conversations are really good way
 : of learning things...Also it is good to know different perspectives for
 : solving the same problem
 
 Yes.  the ng_iscsi suggestion is also viable.  It may be a little less
 work than going to the raw sockets.  Careful performance measurements
 may be necessary, however, since there have been cases when the ng_foo
 implementation wasn't fast enough and going to a lower level was
 necessary.  There have also been many cases where ng_bar was perfectly
 fast enough and there was no need to go to the lower leve.  At the
 very least, the ng code will get you to layer your code well and
 provide a faster means of development than going to the raw socket
 layer.
 
 Warner
 
 : On 12/10/06, Julian Elischer [EMAIL PROTECTED] wrote:
 : 
 :  Özkan KIRIK wrote:
 :   I think netgraph subsystem provides this infrastructure for implementing
 :   new protocols.
 :  
 :   according to netgraph (4) man page:
 :  
 :  The aim of *netgraph* is to supplement rather than replace the
 :  existing
 :   kernel networking infrastructure.It provides:
 :  
 :   *·* A flexible way of combining protocol and link level drivers.
 :   *·* A modular way to implement new protocols.
 :   *·* A common framework for kernel entities to inter-communicate.
 :   *·* A reasonably fast, kernel-based implementation.
 :  
 :   There are many examples and applications at this address:
 :   http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netgraph/
 : 
 :  also look it up in the daemon news archives at:
 :  http://ezine.daemonnews.org/23/netgraph.html
 : 
 :  a little out of date but the basic ideas are still right.
 : 
 : 
 :  
 :  
 :   you implementation may be ng_iscsi :)
 : 
 :  I thought of this but the trick is to do with the locking..
 :  You would need to get a transfer of control from the
 :  netgraph locking domain to the geom or scsi universe's locking domain.
 : 
 :  There are all the components needed if you consider using the ksocket
 :  netgraph node to open a TCP socket within the kernel, and you could hook
 :  that to a scsi device netgraph node almost directly if you wrote it,
 :  but the hardest part will be to create a method of crossing that locking
 :  divide.
 : 
 :  Still it's possibly worth looking at. Of course the method suggested by
 :  Warner is also very valid and may be about the same amount of work.
 : 
 : 
 :  
 :   I hope this helps,
 :  
 :   Özkan KIRIK
 :   EnderUNIX SDT @ Turkey
 :   Software Developer
 :  

May be better to start from scratch though, studying other protocols,
given the fact that networking technology is going to be increasing in
leaps and bounds it seems in the next couple years (1Gbit - 10Gbit -
100Gbit).
Just a thought, but it seems like an ad-hoc solution may be better in
the long run..
- -Garrett
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFfP/c6CkrZkzMC68RAsUWAJ0YIstzev855y9t7tmtArvlSoQO4wCfblfa
SmiAvkWrVJKvIxGb3skdwOg=
=Bxm3
-END PGP SIGNATURE-
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Example network protocol implementation

2006-12-09 Thread Vishal Patil

Could someone point me to an example that shows a SIMPLE network protocol
implemented over TCP/IP inside the FreeBSD kernel. I think I could look at
the NFS client driver but is there an example simpler than that. Also is
there a guide explaining how to go about developing TCP/IP based network
protocols for FreeBSD.
Thanks

- Vishal
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-09 Thread perryh
Vishal Patil [EMAIL PROTECTED] wrote:

 Could someone point me to an example that shows a SIMPLE network
 protocol implemented over TCP/IP inside the FreeBSD kernel.
 I think I could look at the NFS client driver but is there an
 example simpler than that.

NFS normally runs over UDP, not TCP.  Telnet is one of the simpler
TCP-based applications, but it is not done in the kernel (nor are
most network apps).  Is there some particular reason why you need
an example that is implemented inside the kernel, vs in userland?
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-09 Thread Daniel Molina Wegener
On Saturday 09 December 2006 17:18, Vishal Patil wrote:
 Could someone point me to an example that shows a SIMPLE
 network protocol implemented over TCP/IP inside the FreeBSD
 kernel. I think I could look at the NFS client driver but is
 there an example simpler than that. Also is there a guide
 explaining how to go about developing TCP/IP based network
 protocols for FreeBSD.

  Try looking at telnet(1) and telnetd(8) source code, also 
fetch(1) should works too...

 Thanks

 - Vishal
 ___
 freebsd-hackers@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
 To unsubscribe, send any mail to
 [EMAIL PROTECTED]

Best regards,
-- 
 . 0 . | Daniel Molina Wegener
 . . 0 | dmw at unete dot cl
 0 0 0 | FreeBSD User
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-09 Thread Vishal Patil

For implementing iSCSI protocol as a kernel driver.

On 12/9/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


Vishal Patil [EMAIL PROTECTED] wrote:

 Could someone point me to an example that shows a SIMPLE network
 protocol implemented over TCP/IP inside the FreeBSD kernel.
 I think I could look at the NFS client driver but is there an
 example simpler than that.

NFS normally runs over UDP, not TCP.  Telnet is one of the simpler
TCP-based applications, but it is not done in the kernel (nor are
most network apps).  Is there some particular reason why you need
an example that is implemented inside the kernel, vs in userland?


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Example network protocol implementation

2006-12-09 Thread M. Warner Losh
In message: [EMAIL PROTECTED]
Vishal Patil [EMAIL PROTECTED] writes:
: Could someone point me to an example that shows a SIMPLE network protocol
: implemented over TCP/IP inside the FreeBSD kernel. I think I could look at
: the NFS client driver but is there an example simpler than that. Also is
: there a guide explaining how to go about developing TCP/IP based network
: protocols for FreeBSD.

[ to implement iSCSI in the kernel ]

I'm unsure which side you wish to be on.

There's accept filters that you can write, but I doubt that's what you
want to do.  This would be good if you are implementing an iSCSI
target on FreeBSD, maybe (then again, maybe not).

If you want to be an iSCSI initiator (I think that's the right term),
then you'll need to do things similar to what
sys/nfsclient/nfs_socket.c does.  I could do a quick code walkthrough,
but you'd likely be better off studying the nfs code since it will
give you a better understanding than I can in a few lines.  In
addition, because locking has changed over time, the exact version
matters.  Careful study will show differences in what locks are
needed, if any.

But in a nutshell, you call socreate to get a socket.  You setup the
various fields in the socket data structures.  You call sosetopt to do
the latter.  sobind will set this host's endpoint, and soconnect will
connect the socket to the remote side.  You'll need to setup send and
receive buffers and manage them with soreceive and sosend.  there's
some callbacks that also need to be established as well.  And some
socket layer locking that may be exposed to your code because there
are so few in-kernel protocol implementations that aren't peers to
TCP, UDP or IP.

I hope this helps.

Warner


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]