Search code examples
network-programmingiptablesnetfilterswitchingebtables

How to capture packets at the switching layer


I have written 2 modules which are netfilter hook based and work at the IP layer.

However I wan to now capture packets at the switch layer. Are there any hooks to capture at the switching layer.

Any references to code snippets would be appreciated.

Edit: What kind of Software does a managed switch like DELL switch run on. Isn't it Linux, then how does that software deal with Layer 2 Packets.

Thanks


Solution

  • You can use similar hooks to your IP netfilter hooks. The main thing you will need to change is the protocol family: instead of NFPROTO_IP you will use NFPROTO_BRIDGE.

    Do be aware that these hooks will only work on bridged interfaces, not on regular layer 2 packets that are just coming into non-bridged interfaces.