Olsrd registers all control-traffic sockets with the socket parser at startup. These sockets are registered with a packet parser function to be called whenever data is available. This way the packet parser receives all broadcasted traffic received on UPD port 698 on either interface. As explained earlier, one socket is maintained per communication interface running olsrd. So upon startup the situation will be as illustrated in figure 6.2 given that only OLSR sockets are registered with the socket-parser.
The packet parser receives OLSR packets on the form illustrated in figure 3.1. It checks if the reported size in the OLSR header matches the received amount of data. If so, it parses the packet into messages. These messages are passed on to registered message-parsing functions. If the received size does not match the size read from the OLSR header, the packet is silently discarded.
This design is similar to the socket parser. Message-parser
functions can be registered and removed for all message types
dynamically. One can also register functions with a packet type
of PROMISCUOUS(defined in
parser.h), such functions will receive all incoming messages.
A function, defined in parser.h, is used to add a message-parser
function:
void
olsr_parser_add_function(void (*)(union olsr_message *,
struct interface *,
union olsr_ip_addr *),
int,
int);
The first argument is the function to call upon receiving a message of the given type. This function is passed the message, information of on what interface the message arrived and the IP address of the neighbor that transmitted it. The next argument is the packet type, and the last is a boolean value stating whether or not the registered function is forwarding the message. If this value is set to 0, the default forwarding algorithm is applied to the messages of the registered type by the packet parser.
The packet parser delivers all OLSR messages contained in a packet
to the functions registered to parse this message-type. All messages
are also delivered to message parser entries registered with
the PROMISCUOUS type. If none of these functions are
registered to forward the message, then the packet parser forwards
the message according to the default forwarding algorithm.
Andreas 2004-07-29