13.3. Protocol Handler OrganizationFigure 13-7 shows how the different protocol handlers are organized in the kernel. Each protocol is described by a packet_type data structure. Figure 13-7. Data structure used to store the registered protocol handlers![]() To make access faster, a very simple hash function is used for most of the protocols. Sixteen lists are organized into an array to which the global variable ptype_base points. When a protocol is registered, using the dev_add_pack function, described in the next section, this function runs a hash function over the protocol type and assigns the packet_type structure to one of the 16 lists. Later on, to find a packet_type structure, the kernel can simply rerun the hash and go through the matching list. The ETH_P_ALL protocols (see Table 13-1) are organized in their own list to which the global variable ptype_all points.[*] The number of protocols in this list is stored in neTDev_nit. The latter is used by dev_queue_xmit and qdisc_restart to check whether a PF_PACKET socket is open (i.e., a listening sniffer) to which it can deliver a copy of ingress frames (see Chapter 10).
![]() |