报文处理流程
Linux
Linux
LLiinnuuxx 报文处理流程。
newmaker@163.com
1
1
11 目的
了解linux 报文转发流程好比理解Linux网络的骨架。有个宏观的概念,对于网络开发,
提高性能,bug解决起到至关重要的作用。
2
2
22 处理一级流程图
驱动(收报文)
软中断(NET_RX_SOFTIRQ)
协议栈
软 中 断
NET_RX_SOFTIRQ
驱动(发报文)
3
3
33 软中断处理与驱动
3.1软中断
软中断中取报文,是通过 NAPI 结构的poll 函数取的,每个CPU 拥有一个NAPI 列
表。、
NAPI 是驱动注册的取报文的结构。 使用NAPI 主要是采用poll 方式取报文,而不是依
1
赖硬中断处理,对于小包,报文数比较多的情况下,大大的提高的效率,毕竟硬中断太
影响性能。
struct napi_struct {
/*Thepoll_list must only bemanaged bythe entitywhich
*changes thestate ofthe NAPI_STATE_SCHED bit. Thismeans
*whoever atomically setsthat bit can add this napi_struct
*totheper-cpu poll_list, and whoever clears that bit
*can remove from thelist right before clearingthebit.
*/
struct list_head poll_list;
unsigned long state;
weight
weight
int wweeiigghhtt; //为poll 函数的第2个参数,表示每次期望取多少报文。如果取
的报文不足该数,则从cpu napi 队列去掉该napi。
poll
poll
int (*ppoollll)(struct napi_struct *,int); //处理函数。
#ifdef CONFIG_NETPOLL
spinlock_t poll_lock;
int poll_owner;
#endif
unsigned int gro_count;
struct net_device *dev;
struct list_head dev_list;
struct sk_buff *gro_list;
struct sk_buff *skb;
};
net_rx_action
net_rx_action
static void nneett__rrxx__aaccttiioonn(struct softirq_action *h)
{
struct list_head *list =&__get_cpu_var(softnet_data).poll_list;
unsigned longtime_limit =