[En-Nut-Discussion] RFC: Registering Protocols

Harald Kipp harald.kipp at egnite.de
Mon Aug 11 17:09:06 CEST 2008

Ole Reinhardt wrote:
> Hi Harald,
>> However, the IP protocols UDP and TCP should be optional, because some 
>> applications may use one of them only. The decision can be based on 
>> NutTcpCreateSocket() and NutUdpCreateSocket(). If any of these is called 
>> for the first time, they will register the related protocol in the IP layer.
> E.g. you could define an array of callback function pointers that will
> be NULL in case the protocol is not registered and point to the protocol
> input function in case the protocol was first used anywhere in the code.
> This kind of implementation avoids loping through the linked list and
> the array will still be quite short as we don't have that much unused
> protocols, right?

Thanks for looking into this.

The way you suggested is the way some OSes are doing it. IMHO it is a 
bad idea for a tiny system, because you need to translate all potential 
frame types to a table index. If done statically, it requires a lot of 
code. When done dynamically for registered protocols, you'll end up with 
a loop again.

My current implementation has two advantages:

1. Almost no additional code is added, if the application doesn't 
register any handler, just a simple 'if (handler == NULL)'.

2. By using a type in combination with a mask, a handler may register 
itself for more than one protocol. By setting mask and type to zero, it 
will even receive all frames. Via a return value the handler indicates, 
if it will process the frame (and release the NETBUF). This allows to 
use the same code to implement a filter.

I almost finished this for the Ethernet level. Let's discuss this again 
after I tested and committed it. By looking at the code it will become 
clearer what I'm talking about.


More information about the En-Nut-Discussion mailing list