linuxlinux-kernelnetwork-programmingnetfilter

How to write a linux kernel module to modify source MAC address of a packet?


I want to write a Linux kernel module to modify the source MAC address of a packet that will be sent from my computer.

I have tried Netfilter hook at NF_INET_POST_ROUTING, but it can only process the L3(IP) header.

I'm looking forward to the L2(MAC) hook funtion.


Solution

  • As its name suggests, NF_INET_POST_ROUTING is an INET layer hook. I think that you need NF_BR_POST_ROUTING which lives in 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