The problem is rearding the routing protocol packet flow in any linux/unix device where multiple routing protocol daemons are running.

How any routing protocol packet reaches(flows of operations) from NIC card (physical layer) to any Routing (OSPF/RIP/BGP) daemon ?


You didn't specified what kernel are you talking about.
From BSD's point of view it's all explained in TCP/IP Illustrated, Volume 2: The Implementation By Gary R. Wright, W. Richard Stevens

Short version follows:

  1. Frame arrives at NIC's rx descriptor ring. Through DMA it gets transferred to RX ring in RAM.
  2. Driver converts device specific descriptors in RX ring to some kind of general network kernel structure (e.g. mbuf / mbuf_cluster or sk_buff). Also here packet gets copied to bpf device.
  3. In ether_input depending on protocol and address families of the frame it gets processed by corresponding protosw (protocol switch) array entry.
  4. Then after ip_input or tcp_input / udp_input datagram arrives at socket layer to the corresponding routing daemon's so_rcvbuf (socket receive buffer).
  5. From this point routing daemon usually gets notified about pending data on socket via some kind of I/O notification facility (select(2) / poll(2) / epoll(7) / kqueue(2)) and uses recv(3) on that socket to extract packets' payload. Here (e)glibc / libc / libSystem takes it's place.
  6. Routing daemon does it's magic and alters kernels' routing table(s) via routing sockets (PF_ROUTE in BSD derivatives or PF_NETLINK's NETLINK_ROUTE in Linux)

Routing daemons and suites manipulate the routing table in the Kernel. So packets down't flow through the routing daemon, but rather packets get routed according to the routing table.

When it comes to which routes get priority when there are two choices of equal specificity (the most specific route always wins) in the routing table, it is which ever one has the best (lowest) metric (see route). In Cisco land is called 'Administrative Distance.' Different protocols such as RIP and BGP have default metrics. I am not sure if there is a Linux specific reference, but if you look at the administrative distance link I would venture a guess that routing daemons use the same priority.

As far as the routing protocol packets themselves, it depends on the routing protocol, but they generally use standard transport protocols. For example, BGP uses a TCP/IP session on port 179. So the daemon would just bind a socket accordingly.

  • Dear Kyle Brandt, thank you very much. Would you please confirm my final understanding: "When any packet arrives at router interface, first interface's Layer-2 forwarding table lookup will be done(like Cisco express forwarding), then if needed, the routing table lookup will be performed on that interface's routing table(patricia trie or hash table lookup depending upon implementation). At this point it is assumed that, all the routing daemons are running at Fully loaded state and populated latest routing info at interface's routing table". – mav_2k Feb 9 '12 at 5:46
  • In BSD for example there is no separate so-called "switching table" - arp entries are located as nodes in the same radix(patricia) trie as IPv4 routes. – SaveTheRbtz Feb 10 '12 at 10:57
  • Dear SaveTheRbtz, thanks so much, now the idea is really clear. – mav_2k Feb 17 '12 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.