ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] 在iptables中,有四表五链的说法,本文介绍iptables的表、链、规则在内核中的数据结构是什么样的。 ### **表** 在每一个网络命名空间(`struct net`),它的里面有一个`ipv4`对象,这个对象中有iptables的四张表。net与ipv4的结构体如下: > include/net/net_namespace.h ``` struct net { ... struct list_head list;       /* list of network namespaces */ ... struct netns_ipv4 ipv4; ... } ``` > include/net/netns/ipv4.h ``` struct netns_ipv4 { ... #ifdef CONFIG_NETFILTER struct xt_table *iptable_filter; struct xt_table *iptable_mangle; struct xt_table *iptable_raw; struct xt_table *arptable_filter; #ifdef CONFIG_SECURITY struct xt_table *iptable_security; #endif struct xt_table *nat_table; #endif ... } ``` 也就是说,iptables的四张表,存储在网络命名空间下的ipv4中,分别对应`iptable_raw`、`iptable_mangle`、`iptable_filter`、`nat_table`。 这四张表的数据结构为`struct xt_table`,我们看一下这个结构体的定义,如下: > include/linux/netfilter/x_tables.h ``` /* Furniture shopping... */ struct xt_table { struct list_head list; /* What hooks you will enter on */ unsigned int valid_hooks; /* Man behind the curtain... */ struct xt_table_info *private; // 存储链与规则的变量 /* Set this to THIS_MODULE if you are a module, otherwise NULL */ struct module *me; u_int8_t af; /* address/protocol family */ int priority; /* hook order */ /* A unique name... */ const char name[XT_TABLE_MAXNAMELEN]; // 该表的名字 }; ``` ### **参考** https://segmentfault.com/a/1190000010954272 https://blog.csdn.net/lickylin/article/details/33347301 http://sysadm.blog.chinaunix.net/uid-24530400-id-4680979.html