linux 1.2.8 network


再次看《understanding-linux-network-internals》,这本书以前看过好几遍了,看完后也没什么印象,效果也不好。

这次对着代码看,突然发现有很多共鸣,印象深刻。

选用的代码是前几天的linux-1.2.8版本,虽然老点,但是网络模块改动不大。

11.1.3. dev_queue_xmit Function
11.1.3.2. Queueless devices
Some devices, such as the loopback device, do not have a queue: whenever a frame is transmitted, it is immediately delivered.
Since there is no input queue for the loopback device, 
the transmission function accomplishes two tasks: transmit on one side and receive on the other.
 (a) Queueful device transmission; (b) loopback transmission
   
  
共鸣,^_^,下面是我今天在linux-1.2.8上调试ftp的运行流程:
  
  
  

13.1. Overview of Network Stack 13.1.1. The Big Picture about the AF_PACKET socket type. It's the Linux way to capture frames at the link layer and inject frames into the link layer, directly bypassing all the intermediate protocol layers. Network sniffers such as tcpdump and Ethereal are common users of AF_SOCKET sockets. You can see from the figure that AF_PACKET sockets hand frames directly to dev_queue_xmit, and receive ingress frames directly from the network protocol dispatcher routine 13.4. Protocol Handler Registration At system startup and other times when a protocol is registered, the kernel calls dev_add_pack, passing it a data structure of type packet_type, which is defined in include/linux/netdevice.h as follows: type: The protocol code. eg, ETH_P_ALL, ETH_P_802.3, ETH_P_802.2 dev: a command such as tcpdump -i eth0 creates a packet_type instance via a PF_PACKET socket and initializes dev to the net_device instance associated with eth0. func: The function handler called by netif_receive_skb (see Chapter 10) when it needs to process one frame with skb->protocol=type (an example is ip_rcv). Note that one of func's input parameters is a pointer to a packet_type structure: it is used by PF_PACKET sockets to access the af_packet_priv field. dev_add_pack is quite simple: it checks whether the handler to add is a protocol sniffer (pt->type==htons(ETH_P_ALL)). If so, the function adds it to the list pointed to by ptype_all and increments the number of protocol sniffers registered (netdev_nit++). If the handler is not a sniffer, it is inserted into one of the 16 lists pointed to by ptype_base depending on the value of the hash code. The data structures pointed to by ptype_base and ptype_all are protected by the ptype_lock spin lock.

上篇: linux init 执行流程 下篇: linux 1.2.8 tcp 三次握手