My Wiki!

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().

olsrscheduler starts a loop and call scheduler.c/pollsockets() 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/olsrinput() is called. There the message is processed and forwarded to parser.c/parsepacket(). 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);
...

'olsrparseraddfunction()' registers &olsrparser, 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 ifacename to 'CreateInterface(ifr→ifrname, 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(PFPACKET, SOCKDGRAM, htons(ETHPIP))
  • set iface to promiscuous mode setsockopt(skfd, SOLPACKET, PACKETADDMEMBERSHIP, &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 addolsrsocket(skfd, &DoMDNS,NULL, NULL, SPPR_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 olsrmdnsgen(encapsulationUdpData, nBytes); to forward it in olsrd network.

olsr_mdns_gen(encapsulationUdpData, nBytes)


Navigation