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函数返回值来处理报文
*/

最新文章

  1. IRandomAccessStream, IBuffer, Stream, byte[] 之间相互转换
  2. js中的this关键字详解
  3. 转:Bat命令学习
  4. iOS应用日志:开始编写日志组件与异常日志
  5. HDU4570----Multi-bit Trie----简单的DP
  6. Redis操作List工具类封装,Java Redis List命令封装
  7. 如何测试一个U盘
  8. 关于libgdx中UI控件的旋转和缩放的备忘
  9. nodejs 开发指南 书中小项目 代码
  10. Linux查看内存占用情况
  11. JavaScript的DOM编程--04--获取元素节点的子节点
  12. 配置 java web Tomcat
  13. win7下通过easyBCD引导安装Ubuntu16.04(并处理遇到的坑)
  14. 命令行程序增加 GUI 外壳
  15. 用Python3、NetCore、Shell分别开发一个Ubuntu版的定时提醒(附NetCore跨平台两种发布方式)
  16. 记一次maven的包冲突经历
  17. Asp.net core 学习笔记 (AutoMapper)
  18. xml与Excel转换
  19. 初步认识linux的top命令
  20. sql server 2008 R2

热门文章

  1. Redis GEO 功能使用场景
  2. 第3天 | 12天搞定Python,用VSCode编写代码
  3. linux 虚拟机下 安装redis
  4. MeteoInfoLab脚本示例:格点数据散点图
  5. centos8上安装mysql8
  6. 多态(polymorphism)
  7. 【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)
  8. Linux用户和组的配置文件
  9. C++学习---二叉树的输入及非递归遍历
  10. 通过两行代码即可调整苹果电脑 Launchpad 图标大小