Date: Wed, 20 Jun 2007 11:55:33 -0700 From: John Polstra <jdp@polstra.com> To: Julian Elischer <julian@elischer.org> Cc: freebsd-hackers@freebsd.org, Nicolas Cormier <n.cormier@gmail.com> Subject: Re: in-kernel tcp server Message-ID: <46797825.10900@polstra.com> In-Reply-To: <467787EF.9060009@elischer.org> References: <c4630b800706180227x2f1f433dr4ef55e8623062bf1@mail.gmail.com> <467787EF.9060009@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Julian Elischer wrote: > Nicolas Cormier wrote: >> Hi, >> >> I'm trying to write a little tcp-server kernel module (like tftp). >> I didn't find a lot of documents about the kernel network programming, >> just one thread which talks about netgraph. >> In the freebsd includes I found /usr/include/sys/socketvar.h (so*). >> >> What's the easy way to create a basic tcp server >> (create/bind/listen/accept/send/recv) : use netgraph's ksocket or so* >> ? >> >> Thanks in advance ! >> PS: the whole job must be done in the kernel. > > > > yes it can (and has been) done.. > John Polstra did it many years ago.. using netgraph ksockets. > He had an in-kernel web server. > At least I THINK it was him :-) Yes, that's right. I started out using netgraph ksockets, but later on it evolved, mainly for performance reasons. (I needed it to be really, really fast.) The first change was that I eliminated the ksockets and worked directly at the link layer, using ng_ether nodes. I implemented a small, stripped down TCP stack and bypassed the FreeBSD native TCP/IP/socket layers. This was still done with netgraph, using just the ng_ether nodes talking to my own ng_webclient / ng_webserver nodes. It improved the performance immensely. More recently I restructured it quite a bit to get better MP performance using FreeBSD 7.x. (The original version was based on 4.x). I found that the netgraph locking and internode communication mechanism impacted performance too much under 7.x. So I eliminated the ng_ether nodes and made the webserver / webclient nodes talk directly to the interfaces via the if_input / if_output hooks. It still uses netgraph, but really only as a configuration and management mechanism. No actual network traffic flows between netgraph nodes. This change also resulted in a big performance improvement. Unfortunately, my contract forbids me to release the source code publicly. John
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46797825.10900>