kernel network

Robert Watson rwatson at FreeBSD.org
Tue Dec 30 18:46:47 UTC 2008


On Tue, 30 Dec 2008, Max Laier wrote:

> On Tuesday 30 December 2008 12:49:55 Ferner Cilloniz wrote:
>
>> I do not think I could ever be more tired of this topic but I cannot seem 
>> to understand what to do. I have tried more about a month now to send 
>> arbitrary UDP packets from a kernel module but cannot achieve it. I have 
>> looked at udp_send but found that building a socket* was much to tedious. 
>> Later i looked at in-kernel webservers (http://openketa.sourceforge.net/) 
>> but could not find anything useful.
>>
>> Netgraph is a possibility, but there isn't any documentation on accessing 
>> the network from kernel space.
>>
>> What do you all suggest?
>
> $ man 9 socket

Definitely the preferred solution, if it meets the application model.  Call 
socreate(9) to allocate the socket, sobind(9) if required, calls to sosend(9) 
to generate packets, and soclose(9) when done.  Direct calls to the 
udp_output() and udp_send() functions won't work without a socket context, and 
doing sosend(9) will isolate in-kernel consumers from future changes in UDP 
internals.  ip_output() could be invoked directly to generate IP packets, but 
won't allow you to easily receive replies, etc.

Robert N M Watson
Computer Laboratory
University of Cambridge


More information about the freebsd-net mailing list