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 ...
随机推荐
- 多测师讲解自动化 _rf 变量_高级讲师肖sir
rf变量 log 打印全局变量 列表变量: 字典变量: 查看当前工程下的变量 紫色表示变量名有误 设置全局变量 设置列表变量 设置字段变量 关键字书写格式问题
- 多测试_linux_003_肖sir
一.linux 介绍os 操作系统:windows,dos,android ,ios,unix ,linux linux系统:是一个免费,开源的操作系统,能多cpu,多用户,多线程的操作系统,比win ...
- 关于.netMVC 出现@ViewBag 出现错误(波浪红线)的解决方法
解决vs2015.vs2013解决mvc5 viewbag问题 1.关闭vs2015或者vs2013 打开我的电脑或者文件夹 2.打开我的电脑 在地址栏输入 %UserProfile%\AppData ...
- Nuxt+Vue聊天室|nuxt仿微信App界面|nuxt.js聊天实例
一.项目简述 nuxt-chatroom 基于Nuxt.js+Vue.js+Vuex+Vant+VPopup等技术构建开发的仿微信|探探App界面社交聊天室项目.实现了卡片式翻牌滑动.消息发送/emo ...
- Docker安装以及运行第一个HelloWorld
Docker安装以及运行第一个HelloWorld
- go批量转换视频为音频
package main import ( "bytes" "fmt" "io/ioutil" "log" " ...
- go内建方法 new和make区别
package mainimport ( "fmt" "reflect")func main() { // make函数 //makeSlice() // 创建 ...
- poj2187 Beauty Contest (凸包 + 旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38349 Accepted: 11851 ...
- django—Form组件校验方法(is_valid)执行流程
1.从is_valid方法入手 def is_valid(self): """Return True if the form has no errors, or Fals ...
- win10使用U盘安装Linux系统教程
win10安装Linux系统详细教程 目前想要再Windows系统上安装Linux系统有三种方式:其一是安装在虚拟机上(VMWare或者VirtualBox),其二是使用win10最新支持的Linux ...