====== Olsrd internals ====== ===== Olsrd plugin ===== ==== olsrd's IPC Socket parser ==== A plugin register it's IPC socket with olsrd. The olsrd scheduler periodically checks all registered socket for pending actions (read/write) then calls the registered funtion. === Scheduler === main.c/main() starts scheduler.c/olsr_scheduler(). olsr_scheduler starts a loop and call scheduler.c/poll_sockets() periodically... === Registering plugin socket === ==== olsrd's Package parser ==== Olsrd also registers its socket for core messages (port 689) with the scheduler. When a message arrives, the function parser.c/olsr_input() is called. There the message is processed and forwarded to parser.c/parse_packet(). This function checks the message for type and loop through the registered parser functions and forward the message to the appropriate one. A plugin wishing to process a message should register its parser function and the respective message type with olsrd. ===== Olsrd plugin mdns ===== ==== InitMDNS() ==== ... 463 //Tells OLSR to launch olsr_parser when the packets for this plugin arrive 464 olsr_parser_add_function(&olsr_parser, PARSER_TYPE); 465 //Creates captures sockets and register them to the OLSR scheduler 466 CreateBmfNetworkInterfaces(skipThisIntf); ... 'olsr_parser_add_function()' registers &olsr_parser, which will be called when a message of PARSER_TYPE is received. 'CreateBmfNetworkInterfaces(skipThisIntf)' prepares the interfaces (non olsrd??) prior to forwarding dns messages. ==== CreateBmfNetworkInterfaces(struct interface *skipThisIntf) ==== * gets all available interfaces on system: * create socket for this purpose * call ioctl(skfd, SIOCGIFCONF, &ifc) * check if each iface is in plugin's config * if yes pass iface_name to 'CreateInterface(ifr->ifr_name, NULL)' ==== CreateInterface(const char *ifName, struct interface *olsrIntf) ==== * call capturingSkfd = CreateCaptureSocket(ifName) with the parameter ifName * assign ioctlSkfd = (capturingSkfd >= 0) ? capturingSkfd : encapsulatingSkfd, denpending on socket type cap/encap * get MAC of the iface using ioctl(ioctlSkfd, SIOCGIFHWADDR, &ifr) < 0) * copy data to struct TBmfInterface *newIf: * copy captureingSkdf, encapsulatingSkfd, listeningSkfd, above MAC, ifname * if olsrIntf != NULL copy intAddr and broadAddr * else * retrieve IP addr with ioctl(ioctlSkfd, SIOCGIFADDR, &ifr) * retrieve Broadcast IP with ioctl(ioctlSkfd, SIOCGIFBRDADDR, &ifr) * add newIf to BmfInterfaces ==== CreateCaptureSocket(const char *ifName) ==== * open socket skfd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)) * set iface to promiscuous mode setsockopt(skfd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) * get MAC ioctl(skfd, SIOCGIFHWADDR, &req) < 0) * bind socket * set socket to blocking operation * Register newly created socket with olsrd socket parser add_olsr_socket(skfd, &DoMDNS,NULL, NULL, SP_PR_READ) ==== DoMDNS ==== DoMDNS is registerd with olsrd socket parser and is called whenever a packet is capture on registered interfaces. DoMDNS inspects the captured packet and call BmfPacketCaptured to process it. ==== BmfPacketCaptured ==== This function check if the packet is a MDNS packet (UDP 5353). If yes it pass the packet to olsr_mdns_gen(encapsulationUdpData, nBytes); to forward it in olsrd network. ==== olsr_mdns_gen(encapsulationUdpData, nBytes) ====