zoukankan      html  css  js  c++  java
  • iptables分析(一)

    四表五链
    四表:filter , nat, manager, raw
    五链: 五个HOOK点的链接,pre_rout, foward, post_rout, in ,out

    iptables 命令查看命令,默认显示的是filter表的配置,如果要显示其他表的情况,使用-t参数,插入删除的操作亦然。

    各个表的作用于功能

    1. filter表

    2. mangle表

    mangle表的作用,主要是根据规则修改包的一些标志位,其他程序和规则可以利用这些标志位,执行过滤规则和策略路由。

    iptable 中配置-j MARK --set-mark 用于给匹配规则的数据包,打上标签。-m mark 用于匹配规则。

    使用iptables -j mark --help 命令查看,设置规则:

    使用iptables -m mark --help 查看匹配规则:

    设置mask掩码,用于设置相应的标志位。

    上面的规则,标示匹配mark为0x2掩码为0x3的标记。在匹配规则的时候,先用skb的mark和mask取与,然后和掩码匹配。

    参见内核code:

    修改的标志位,主要有:

    3. nat 表

    4. raw表

    内核模块

    问题:
    内核如何匹配,内核使能

    iptable 命令转换,和内核交互
    libiptc库和内核交互


    最终是转换到hook点的处理函数上来.

    match模块被添加到系统的链表中
    当iptables 调用命令,会把这个过滤规则添加到过滤表中.

    在每个HOOK点用操作表组成了操作链,分别调用表中的匹配和过滤函数.


    内和match注册:
    xt_register_match


    filter表分析


    match 模块查找
    do_command4
    command_match
    xtables_find_match


    表的插入
    insert_entry
    iptc_insert_entry <libiptc.h>


    libiptc和内核交互
    http://blog.chinaunix.net/uid-29732842-id-4975834.html
    get_socket
    set_socket

    网络命名空间相关

    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

    问题1

    mangle表在添加的时候

    欢迎评论交流
  • 相关阅读:
    stenciljs 学习四 组件装饰器
    stenciljs 学习三 组件生命周期
    stenciljs 学习二 pwa 简单应用开发
    stenciljs ionic 团队开发的方便web 组件框架
    stenciljs 学习一 web 组件开发
    使用npm init快速创建web 应用
    adnanh webhook 框架 hook rule
    adnanh webhook 框架 hook 定义
    adnanh webhook 框架request values 说明
    adnanh webhook 框架execute-command 以及参数传递处理
  • 原文地址:https://www.cnblogs.com/linengier/p/9222126.html
Copyright © 2011-2022 走看看