作者:做条温顺的鱼_169 | 来源:互联网 | 2023-10-10 19:19
WhileexploringnetfilterfunctionalityItriedtowriteasimplenetfiltermoduleandregistereda
While exploring netfilter functionality I tried to write a simple netfilter module and registered a hook as follows:
在探索netfilter功能的同时,我尝试编写一个简单的netfilter模块,并注册了一个钩子如下:
dhcp_nfho.owner = THIS_MODULE;
dhcp_nfho.hook = dhcp_hook_function;
dhcp_nfho.hooknum = NF_INET_POST_ROUTING;
dhcp_nfho.priority = NF_IP_PRI_FIRST;
dhcp_nfho.pf = PF_INET; // not on bridge interface
nf_register_hook(&dhcp_nfho);
I looked into the code of nf_register_hook in the LXR page: (3.13 version)
我在LXR页面中查看了nf_register_hook的代码:(3.13版本)
int nf_register_hook(struct nf_hook_ops *reg)
69 {
70 struct nf_hook_ops *elem;
71 int err;
72
73 err = mutex_lock_interruptible(&nf_hook_mutex);
74 if (err <0)
75 return err;
76 list_for_each_entry(elem, &nf_hooks[reg->pf][reg->hooknum], list) {
77 if (reg->priority priority)
78 break;
79 }
80 list_add_rcu(®->list, elem->list.prev);
81 mutex_unlock(&nf_hook_mutex);
82 #if defined(CONFIG_JUMP_LABEL)
83 static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]);
84 #endif
85 return 0;
86 }
What is this 2D linked list nf_hooks[PF][hooknum]. It looks like for each protocol family there is a list of PRE/INPUT/FORWARD/OUTPUT/POST hooks?
这个二维链表nf_hooks[PF][hooknum]是什么?似乎每个协议族都有一个预/输入/前向/输出/后向钩子的列表?
How is this 2D array used by the netfilter sub system ?
netfilter子系统如何使用这个2D数组?
And is the netfilter subsystem code interacting with the network driver code? (since the hooks are processed in Soft-irq and the network driver also uses soft-irq's to process the packets)?
netfilter子系统代码与网络驱动程序代码交互吗?(因为钩子是在软irq中处理的,网络驱动也使用软irq来处理数据包)?
Where can I find the code that invokes the Netfilter Hooks once a packet is recvd by the driver?
一旦数据包被驱动程序接收,我在哪里可以找到调用Netfilter钩子的代码?
1 个解决方案