[OLSR-users] Plugin development: how to avoid buffer/packet size overrun when olsr message is of dynamic length.

Andreas Tønnesen (spam-protected)
Tue Jul 13 18:38:47 CEST 2004


Hei Christoffer,

My comments are inline.

> I am making a plugin where I am adding a packet transform function (add_ptf) to check a packet and add an extra olsr messge at the end.
> 
> This ekstra olsr message checks the messages in the packet to build its own message.
> 
> This olsr message is therefore dynamic in size.  So far I have come up with the following solution:
> 
> Assume that I have to add data from every olsr message in the packet.
> Find out how much space my new olsr message needs if the packet contains the maximum possible number of the smallest messages in olsr (which is HELLO?).
> Limit the packet size so that I can always add my message in this scenario, hence never exceeding the packet size.
> 
> 1. Is this a valid approach?
> 

Yes. But the smallest message is the empty TC. Lets see if I can
remember this by heart:
message header 12 bytes + TC header 4 bytes.

> 2. I am struggling a bit in the code of the secure plugin to find out how you limited the packet size 
> to make sure that you always have room for the signature at the end of the packet.  I can tell that you 
> have defined a MAXMESSAGESIZE of 512, but I cannot see where or how you use this to tell olsr that it
> has to leave room for the signature to avoid packet buffer overrun, or max packet size overrun.

The maximum bytes olsrd will put in a OLSR packet is set by the global
variable maxmessagesize(not to be confused with the MAXMESSAGESIZE
symbol) defined in defs.h. The plugin can access this
variable trough the GETD__MAXMESSAGESIZE command. In the security
plugin you'll probably see something like:
maxmessagesize -= sizeof(signature_message);

This makes sure there is enough room left in the outputbuffer for the
signature message.

Hope this was of help!

- Andreas 

-- 
Andreas Tønnesen((spam-protected))
UniK University Graduation Center
University of Oslo
http://www.olsr.org



More information about the Olsr-users mailing list