[Graphic linux][Network stack series]: Introduction to the data structure of network equipment

Insert picture description here

net_device network device structure

The core data structure of the network interface module is the network device structure struct net_device, which corresponds to the actual physical network card and is used to record and describe the relevant information and actions of the network card. The specific definition is as
follows.

struct net_device
{
    
    
	char name[IFNAMSIZ]; 	/*网卡名称*/
	int s; 				 	/*建立的 PACKET 套接字描述符*/
	struct sockaddr_ll to;  /*目的网卡地址结构*/
	int index 				/*网络设备的索引*/
	int mtu; 				/*网卡最大传输单元*/
	__u8 hwaddr_len; 		/*硬件地址长度*/
	__u8 hwaddr[ETH_ALEN];  /*硬件地址,MAC*/
	sem_t recv_sem; 		/*接收信号量*/
	sem_t send_sem; 		/*发送信号量*/
	struct queue *recv_queue; /*接收队列*/
	struct queue *send_queue; /*发送队列*/
	__u8 (* input)(struct skbuff **skb,struct net_device *dev); /*从网络设备获取数据帧*/
	__u8 (* output)(struct skbuff *skb,struct net_device *dev); /*从网络设备发送数据帧*/
	__u8 (* filter)(unsigned char *frame, struct net_device *dev); /*用户注册的过滤函数*/
};

In the initialization phase, the network interface module applies for a
management object of this structure for each physical network card that participates in forwarding , and binds the PACKETtype of socket for the sending and receiving of underlying data frames. During operation of the data frame, one for each network interface module card sending thread and the receiving thread to maintain, and be sent to be treated are mounted in a send queue and a receive queue, wherein the transmitting and receiving thread thread calls input()and output()functions from a single card data transceiver frame, input()and output()the internal read and write functions PACKETsocket implementation.

sk_buff packet management structure

sk_buffDefinition of the structure below, wherein the nextpointer is used to construct sk_buffa linked list structure,
sdeva recorded data frame which is received from the card device, ddevthe data frame sent from the LAN equipment which the recording process, nhand phyare the network layer and the physical layer header pointer enumeration , respectively, points to the start position of the network layer and the physical layer data, tot_lenrecord sk_buffthe total length of the data frame structure, lenthe recording layer of the data length of the current protocol. headThe pointer points to the head of the actual data frame, datapoints to the head of the current layer network data, tailpoints to the end of the current layer network data, and endpoints to the end of the actual data frame.

struct skbuff
{
    
    
	struct skbuff *next; 		/*指向下一个 skbuff 结构*/
	struct net_device *sdev; 	/*接收设备*/
	struct net_device *ddev; 	/*发送设备*/
	/*网络层枚举变量*/
	union{
    
     
		struct iphdr *iph;
		struct arph *arph;
		__u8 *raw;
	} nh;
	/*物理层枚举变量*/
	union{
    
    
		struct ethhdr *ethh;
		__u8 *raw;
	} phy;
	__u32 tot_len; 	/*skbuff 中网络数据的总长度*/
	__u32 len; 		/*skbuff 中当前协议层的数据长度*/
	__u8 *head, 	/*实际网络数据的头部指针*/
	*data, 			/*当前层网络数据的头部指针*/
	*tail, 			/*当前层数据的尾部指针*/
	*end; 			/*实际网络数据的尾部指针*/
};

Guess you like

Origin blog.csdn.net/qq_33487044/article/details/108230187