From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 20 19:40:00 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 142F216A400 for ; Wed, 20 Jun 2007 19:40:00 +0000 (UTC) (envelope-from n.cormier@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.182]) by mx1.freebsd.org (Postfix) with ESMTP id AF39613C44B for ; Wed, 20 Jun 2007 19:39:59 +0000 (UTC) (envelope-from n.cormier@gmail.com) Received: by py-out-1112.google.com with SMTP id a29so589207pyi for ; Wed, 20 Jun 2007 12:39:59 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rcVIFUi8R94PNTYfQyEJeBHMg0Zb4afQgOlLJa8HUaPPf/1ZgVQfDRcSBVmzq4uX2LFHIIgporZzLN9ZVR6ZeIA+NXT96B+43TZeImMGGe9032kar64FdXzZ7tkBsTm/5d/dBxXWi0/6ap6m9ds0fzMhkBJQu/PxL+M5208Tubg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Vc+NVnquLaVSrrStuBIvKkFGuX9WVwxo7JUvufYfWF4ji49fJJmLIKb2XwreaSbu8o5gSiMkuKKKojUNILWgdkb1/Rrcm3jsQL9tRbb1cz5Uilex7xMXkSzzDRPbeLtC271m1kFtSlV0ayFMxrkQYfvVA35YcJEg3eI7Rgw7dzI= Received: by 10.35.50.1 with SMTP id c1mr1674079pyk.1182368398944; Wed, 20 Jun 2007 12:39:58 -0700 (PDT) Received: by 10.35.40.11 with HTTP; Wed, 20 Jun 2007 12:39:58 -0700 (PDT) Message-ID: Date: Wed, 20 Jun 2007 21:39:58 +0200 From: "Nicolas Cormier" To: "John Polstra" In-Reply-To: <46797825.10900@polstra.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <467787EF.9060009@elischer.org> <46797825.10900@polstra.com> Cc: freebsd-hackers@freebsd.org, Julian Elischer Subject: Re: in-kernel tcp server X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jun 2007 19:40:00 -0000 On 6/20/07, John Polstra wrote: > 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. Thx, I have started with ng_ksockets, for the now it is sufficient. > Unfortunately, my contract forbids me to release the source code publicly. Bad news ! Thanks a lot for your answer, a last question "why did you not used so* functions ?" -- Nicolas Cormier