Title: ip_hash_proto() / ip_unhash_proto()


An ip file descriptor either accepts packets of any protocol type (the NWIO_PROTOANY flag for the file descriptor is set) or accepts packets of a specific protocol (NWIO_PROTOSPEC is set). A few of the different protocols that a packet may have are ICMP, UDP, TCP, EGP, and OSPF.

When a packet arrives at an ip port, the ip port must find the appropriate ip file descriptors and then deliver the packets to them.

In order to find matching ip file descriptors quickly, ip ports have one linked list (ip_proto_any - for ip file descriptors with the NWIO_PROTOANY flag set) and one array of linked lists (ip_proto[] - NWIO_PROTOSPEC is set). When a packet arrives at an ip port, the ip port first searches for matching ip file descriptors in the ip_proto_any linked list and then in the ip_port[] element that corresponds to the protocol of the packet (actually, it's a hash - several protocols will share a single element). In this way, the ip port avoids searching through all of the ip file descriptors.

ip_hash_proto(ip_fd) puts an ip file descriptor (ip_fd) into the appropriate linked list.

This ip file descriptor may be later removed from the linked list by ip_unhash_proto(ip_fd).