【问题标题】:How to write a linux kernel module to modify source MAC address of a packet?如何编写linux内核模块来修改数据包的源MAC地址?
【发布时间】:2020-10-17 11:10:09
【问题描述】:

我想编写一个 Linux 内核模块来修改将从我的计算机发送的数据包的源 MAC 地址。

我试过Netfilter钩子NF_INET_POST_ROUTING,但它只能处理L3(IP)头。

我期待 L2(MAC) 挂钩功能。

【问题讨论】:

    标签: linux linux-kernel network-programming netfilter


    【解决方案1】:

    顾名思义,NF_INET_POST_ROUTING 是一个INET 层挂钩。我认为你需要NF_BR_POST_ROUTING,它住在netfilter_bridge.h (source):

    /* Bridge Hooks */
    /* After promisc drops, checksum checks. */
    #define NF_BR_PRE_ROUTING   0
    /* If the packet is destined for this box. */
    #define NF_BR_LOCAL_IN      1
    /* If the packet is destined for another interface. */
    #define NF_BR_FORWARD       2
    /* Packets coming from a local process. */
    #define NF_BR_LOCAL_OUT     3
    /* Packets about to hit the wire. */
    #define NF_BR_POST_ROUTING  4
    

    【讨论】:

    • 感谢您的帮助!我马上试试这个方法。
    • 您好,如果 NIC 未桥接。那么数据包将不会通过这些钩子函数。我希望数据包由内核协议栈处理,而不是网桥。内核协议栈处理完数据包后,修改数据包的源MAC地址。
    猜你喜欢
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2012-02-22
    • 1970-01-01
    • 2014-06-28
    • 2020-10-12
    相关资源
    最近更新 更多