[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
- 应用层
- HTTP
- Cookie
- Session
- HTTP报文格式
- HTTP的Header字段
- HTTPS
- 简介
- 原理
- RSA加密与解密
- 证书签名与验证
- TLS双向认证
- openssl命令汇总
- DNS
- DNS的记录类型
- DNS的报文格式
- FAQ
- 传输层
- TCP
- CloseWait
- 网络层
- IPv6
- 链路层
- 链接层基础知识
- VLAN
- FAQ
- Linux网络收发包
- 网卡收包
- 网卡发包
- 收发包FAQ
- LVS
- 安装-DR模式
- 基本原理
- Ipvsadm命令
- Netfilter
- Netfilter简介
- 注册钩子函数
- Netfilter中数据包流向
- Iptables的数据结构
- 连接跟踪
- 初识连接跟踪
- 连接跟踪详解
- 连接跟踪数据结构
- 数据包与连接的状态
- NAT
- IPVS
- KubeProxy的IPVS模式
- Linux虚拟网络设备
- 虚拟网络设备简介
- Tap
- VethPair
- Vlan
- Vxlan
- Flannel的VXLAN原理
- Openstack的VXLAN原理
- VXLAN总结
- Bridge
- 给容器设置主机网段IP
- Macvlan
- Ipvlan
- IPIP
- IPIP使用介绍
- IPIP源码分析
- Limdiag网络
- 详细设计
- kubeovn
- IP命令
- Calico
- Calico常见问题
- ARP无响应
- 其他