zoukankan      html  css  js  c++  java
  • 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代表一个扩展matchnetfilter中各个扩展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函数返回值来处理报文
    */

    http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子
  • 相关阅读:
    itoa
    sprintf用法 [转载]
    atoi 与 itoa的实现
    数组排序总结(冒泡,选择,插入,希尔)
    XML入门精解之文件格式定义(DTD)
    malloc()函数的工作机制 结构体的总结
    字符串指针与字符数组(ZT)
    sprintf函数你了解有多深!
    sprintf
    sql ldr 笔记
  • 原文地址:https://www.cnblogs.com/codestack/p/10850665.html
Copyright © 2011-2022 走看看