Netfilter hook registration with networking sub system

RootPhoenix

While exploring netfilter functionality I tried to write a simple netfilter module and registered a hook as follows:

    dhcp_nfho.owner             = THIS_MODULE;
    dhcp_nfho.hook              = dhcp_hook_function;
    dhcp_nfho.hooknum           = NF_INET_POST_ROUTING;
    dhcp_nfho.priority          = NF_IP_PRI_FIRST;
    dhcp_nfho.pf            = PF_INET; // not on bridge interface
    nf_register_hook(&dhcp_nfho);

I looked into the code of nf_register_hook in the LXR page: (3.13 version)

int nf_register_hook(struct nf_hook_ops *reg)
 69 {
 70         struct nf_hook_ops *elem;
 71         int err;
 72 
 73         err = mutex_lock_interruptible(&nf_hook_mutex);
 74         if (err < 0)
 75                 return err;
 76         list_for_each_entry(elem, &nf_hooks[reg->pf][reg->hooknum], list) {
 77                 if (reg->priority < elem->priority)
 78                         break;
 79         }
 80         list_add_rcu(&reg->list, elem->list.prev);
 81         mutex_unlock(&nf_hook_mutex);
 82 #if defined(CONFIG_JUMP_LABEL)
 83         static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]);
 84 #endif
 85         return 0;
 86 }

What is this 2D linked list nf_hooks[PF][hooknum]. It looks like for each protocol family there is a list of PRE/INPUT/FORWARD/OUTPUT/POST hooks?

How is this 2D array used by the netfilter sub system ?

And is the netfilter subsystem code interacting with the network driver code? (since the hooks are processed in Soft-irq and the network driver also uses soft-irq's to process the packets)?

Where can I find the code that invokes the Netfilter Hooks once a packet is recvd by the driver?

Joel C

You are correct. For each protocol family, there is indeed a list of hooks, which are actually set by the PF itself (eg. NFPROTO_BRIDGE has a BROUTE hooklist, but neither IPv4 or IPv6 does).

When a packet comes in to a logical network interface (ethernet bridge, ethernet interface, etc), it will get passed around the stack. If it is an IPv4 packet, it eventually ip_rcv() will get called. This will call the NF_INET_PRE_ROUTING hooks before continuing on to the packet routing proper. Similarly, ip_output calls the NF_INET_POST_ROUTING hooks before actually sending the packet on its way.

Putting the Netfilter hooks into the main networking code allows the network interface drivers themselves to be blissfully ignorant of the whole process.

To get a better idea of how this all flows, check out http://lxr.free-electrons.com/source/net/ipv4/ip_input.c and http://lxr.free-electrons.com/source/net/ipv4/ip_output.c. You'll see the NF_HOOK and NF_HOOK_COND macros being called when packets transition to different layers, etc.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Understanding spinlocks in netfilter hook

From Dev

What is the correct way to define a Netfilter hook function?

From Dev

Netfilter hook on router not getting called for bridged interfaces

From Dev

registration system using python

From Dev

PHP Lua registration system

From Dev

How to add hook on submit registration in wordpress to drupal?

From Dev

Hook into GHC runtime system

From Dev

System is broken (login loop and no networking) after update

From Dev

Instantiate new "players" in a sub folder in Hierarchy view | Unity networking with Vuforia

From Dev

Invalid sub system

From Dev

Basic PHP Registration/Login System

From Dev

Database model (entry and registration to the system)

From Dev

Hook system power button in Windows

From Dev

Mouse and Keyboard system Global Hook

From Dev

Is it possible to hook up Devise Registration Controller with Administrate dashboard?

From Dev

dnsmasq requires a restart of the networking system on BeagleBone Black (Debian 8.5)

From Dev

SonicWall: Unable to manage networking component. Operating system corruption

From Dev

Additional Processing Required in Registration for a Devise Login System

From Dev

Why is this login and registration system not checking the password correctly?

From Dev

Handling Multiple Social Login/Registration System

From Dev

Debate: Exclude - or not - characters from registration system? Safety?

From Dev

Changing System Registration Information in Installers in Windows 7

From Dev

Handling Multiple Social Login/Registration System

From Java

Where in the Windows networking stack do WinPcap/Npcap hook/filter to "listen" for packets?

From Dev

Local (sub) NetWorking between : VirtualBox with Deice on Win7 and local machine on Ubuntu

From Dev

Hook into System.out.println(); and modify

From Dev

System Tray temporary file shutdown hook

From Dev

How to hook system calls of my android app

From Dev

Windows 10 bash(ubuntu sub system)

Related Related

  1. 1

    Understanding spinlocks in netfilter hook

  2. 2

    What is the correct way to define a Netfilter hook function?

  3. 3

    Netfilter hook on router not getting called for bridged interfaces

  4. 4

    registration system using python

  5. 5

    PHP Lua registration system

  6. 6

    How to add hook on submit registration in wordpress to drupal?

  7. 7

    Hook into GHC runtime system

  8. 8

    System is broken (login loop and no networking) after update

  9. 9

    Instantiate new "players" in a sub folder in Hierarchy view | Unity networking with Vuforia

  10. 10

    Invalid sub system

  11. 11

    Basic PHP Registration/Login System

  12. 12

    Database model (entry and registration to the system)

  13. 13

    Hook system power button in Windows

  14. 14

    Mouse and Keyboard system Global Hook

  15. 15

    Is it possible to hook up Devise Registration Controller with Administrate dashboard?

  16. 16

    dnsmasq requires a restart of the networking system on BeagleBone Black (Debian 8.5)

  17. 17

    SonicWall: Unable to manage networking component. Operating system corruption

  18. 18

    Additional Processing Required in Registration for a Devise Login System

  19. 19

    Why is this login and registration system not checking the password correctly?

  20. 20

    Handling Multiple Social Login/Registration System

  21. 21

    Debate: Exclude - or not - characters from registration system? Safety?

  22. 22

    Changing System Registration Information in Installers in Windows 7

  23. 23

    Handling Multiple Social Login/Registration System

  24. 24

    Where in the Windows networking stack do WinPcap/Npcap hook/filter to "listen" for packets?

  25. 25

    Local (sub) NetWorking between : VirtualBox with Deice on Win7 and local machine on Ubuntu

  26. 26

    Hook into System.out.println(); and modify

  27. 27

    System Tray temporary file shutdown hook

  28. 28

    How to hook system calls of my android app

  29. 29

    Windows 10 bash(ubuntu sub system)

HotTag

Archive