linux Netfilterr中扩展match target
Match:
netfilter定义了一个通用的match数据结构struct xt_match
/*
每个struct xt_match代表一个扩展match,netfilter中各个扩展match自己定义自己的匹配参数数据结构,自己实现匹配函数
*/
struct xt_match {
struct list_head list;
//match名字,和iptables配置的-m参数相同
const char name[XT_EXTENSION_MAXNAMELEN];
u_int8_t revision; /* Return true or false: return FALSE and set *hotdrop = 1 to
force immediate packet drop. */
/* Arguments changed since 2.6.9, as this must now handle
non-linear skb, using skb_header_pointer and
skb_ip_make_writable. *///规则匹配函数
bool (*match)(const struct sk_buff *skb,
struct xt_action_param *); /* Called when user tries to insert an entry of this type. */
int (*checkentry)(const struct xt_mtchk_param *);/* 匹配函数入参检查函数 */ /* Called when entry of this type deleted. */
void (*destroy)(const struct xt_mtdtor_param *);
#ifdef CONFIG_COMPAT
/* Called when userspace align differs from kernel space one */
void (*compat_from_user)(void *dst, const void *src);
int (*compat_to_user)(void __user *dst, const void *src);
#endif
/* Set this to THIS_MODULE if you are a module, otherwise NULL */
struct module *me; const char *table;
unsigned int matchsize;//match的自定义数据长度
#ifdef CONFIG_COMPAT
unsigned int compatsize;
#endif
unsigned int hooks;
unsigned short proto; unsigned short family;
};
每个struct xt_match代表一个扩展match,netfilter中各个扩展match自己定义自己的匹配参数数据结构,自己实现匹配函数。
在netfilter中,每个扩展match 被注册到全局变量xt管理的match链表上,可根据match的名字来找到相应的struct xt_match。
用户使用-m 来配置的扩展match下发给内核,在内核中以struct xt_entry_match数据结构来存储,该结构后紧跟着存储着扩展match自定义的匹配参数数据。
Match的基本处理流程
1、取到rule中存储的xt_entry_match,这里记录着iptables下发给内核的值,同时找到内核中注册的xt_match,从xt_match里找到相应的match函数.
2、根据xt_entry_match中记录的配置值初始化xt_match_param,
3、把报文和xt_match_param传给match函数进行匹配处理。
int xt_register_match(struct xt_match *match)
{
u_int8_t af = match->family; mutex_lock(&xt[af].mutex);
//加入Netfilter管理的全局Match链表上
list_add(&match->list, &xt[af].match);
mutex_unlock(&xt[af].mutex);
return 0;
}
Target:
struct xt_standard_target {
struct xt_entry_target target;
/*verdict 可以是指定返回值,也可以是goto到下一个rule的偏移量,
也可以是queue的队列号。
*/
int verdict;
};
/*
如果struct xt_entry->target 值为空,表示是标准target,根据verdict值来处理报文。
如果struct xt_entry->target不为空,表示不是标准target,就使用target的target函数返回值来处理报文
*/
linux Netfilterr中扩展match target的更多相关文章
- 嵌入式C语言自我修养 01:Linux 内核中的GNU C语言语法扩展
1.1 Linux 内核驱动中的奇怪语法 大家在看一些 GNU 开源软件,或者阅读 Linux 内核.驱动源码时会发现,在 Linux 内核源码中,有大量的 C 程序看起来“怪怪的”.说它是C语言吧, ...
- 三、Linux系统中的文件类型和文件扩展名
.sock文件也是一类特殊的文件,这类文件通常用在网络之间进行数据连接,如:我们可以启动一个程序来监听客户端的要求,客户端可以通过套接字来进行通信: linux中的文件类型 文件类型介绍 Linux系 ...
- Linux内核中流量控制
linux内核中提供了流量控制的相关处理功能,相关代码在net/sched目录下:而应用层上的控制是通过iproute2软件包中的tc来实现, tc和sched的关系就好象iptables和netfi ...
- linux内核中的GPIO系统之(1):软件框架
一.前言 作为一个工作多年的系统工程师,免不了做两件事情:培训新员工和给新员工分配任务.对于那些刚刚从学校出来的学生,一般在开始的时候总是分配一些非常简单的任务,例如GPIO driver.LED d ...
- 在linux系统中安装VSCode(Visual Studio Code)
在linux系统中安装VSCode(Visual Studio Code) 1.从官网下载压缩包(话说下载下来解压就直接可以运行了咧,都不需要make) 访问Visual Studio Code官网 ...
- Linux 内核中的 Device Mapper 机制
本文结合具体代码对 Linux 内核中的 device mapper 映射机制进行了介绍.Device mapper 是 Linux 2.6 内核中提供的一种从逻辑设备到物理设备的映射框架机制,在该机 ...
- Linux命令中特殊符号
转自:http://blog.chinaunix.net/uid-16946891-id-5088144.html 在shell中常用的特殊符号罗列如下:# ; ;; . , / \ 'strin ...
- Linux内核中的fastcall和asmlinkage宏
代码中看见:#define _fastcall 所以了解下fastcall -------------------------------------------------------------- ...
- Linux内核中的GPIO系统之(3):pin controller driver代码分析
一.前言 对于一个嵌入式软件工程师,我们的软件模块经常和硬件打交道,pin control subsystem也不例外,被它驱动的硬件叫做pin controller(一般ARM soc的datash ...
随机推荐
- 很多人都搞不清楚C语言和C++的关系!今天我们来一探究竟为大家解惑~
最近,身边有许多小伙伴已经开始学习编程了,但是呢,学习又会碰到许多的问题,其中作为新手小白提到最多的问题就是编程语言的选择. 每次遇到这种问题,看起来很简单,但是又有很多小伙伴搞不清编程语言之间的关系 ...
- filebeat- 配置
wget https://mirrors.huaweicloud.com/filebeat/7.9.1/filebeat-7.9.1-linux-x86_64.tar.gz tar -zxvf fil ...
- swoole为什么不建议使用static和global
$http = new swoole_http_server("0.0.0.0", 9501); $http->on("request", functio ...
- composer慢 设置阿里云镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
- java中true不是关键字?
java中true ,false , null在java中不是关键字,也不是保留字,它们只是显式常量值,但是你在程序中不能使用它们作为标识符. 其中const和goto是java的保留字.java中所 ...
- 开源项目bootdo的实战开发笔记
开源项目bootdo 源码地址:https://github.com/lcg0124/bootdo 技术选型 1.后端 核心框架:Spring Boot 安全框架:Apache Shiro 模板引擎: ...
- 跟我一起学.NetCore之MediatR好像有点火
前言 随着微服务的流行,而DDD(领域驱动设计)也光速般兴起,CRQS(Command Query Responsibility Seperation--命令查询职责分离).领域事件名词是不是经常在耳 ...
- 批量安装Zabbix_Agent
使用自动化部署工具Ansible批量部署zabbix_agent. 1. 安装Ansible yum –y install ansible 内网情况下,现在ansible及其依赖的rpm包,添加到yu ...
- 云计算管理平台之OpenStack网络服务neutron
一.简介 neutron的主要作用是在openstack中为启动虚拟机实例提供网络服务,对于neutron来讲,它可以提供两种类型的网络:第一种是provider network,这种网络就是我们常说 ...
- ui 自动化的测试用例从哪来
从手工测试当中选取,尽量选择 1.简单且需要反复回归 2.稳定且不会经常变化 3.优先覆盖核心功能