History

netfilter: defrag: only register defrag functionality if needed

nf_defrag modules for ipv4 and ipv6 export an empty stub function. Any module that needs the defragmentation hooks registered simply 'calls' this empty function to create a phony module dependency -- modprobe will then load the defrag module too. This extends netfilter ipv4/ipv6 defragmentation modules to delay the hook registration until the functionality is requested within a network namespace instead of module load time for all namespaces. Hooks are only un-registered on module unload or when a namespace that used such defrag functionality exits. We have to use struct net for this as the register hooks can be called before netns initialization here from the ipv4/ipv6 conntrack module init path. There is no unregister functionality support, defrag will always be active once it was requested inside a net namespace. The reason is that defrag has impact on nft and iptables rulesets (without defrag we might see framents).

Florian Westphal committed 10 years ago

Commit 834184b1 parent 481fa379 files · +136 −21Browse files

Showing the changes to include/net (3 of 9 files). Show all

Unified · Split

3 files
  1. include/net/netfilter/ipv4/nf_defrag_ipv4.h +2 −1
  2. include/net/netfilter/ipv6/nf_defrag_ipv6.h +2 −1
  3. include/net/netns/netfilter.h +6 −0
include/net/netfilter/ipv4/nf_defrag_ipv4.h+2−1
@@ -1,6 +1,7 @@
11 #ifndef _NF_DEFRAG_IPV4_H
22 #define _NF_DEFRAG_IPV4_H
33
4−void nf_defrag_ipv4_enable(void);
4+struct net;
5+int nf_defrag_ipv4_enable(struct net *);
56
67 #endif /* _NF_DEFRAG_IPV4_H */
include/net/netfilter/ipv6/nf_defrag_ipv6.h+2−1
@@ -1,7 +1,8 @@
11 #ifndef _NF_DEFRAG_IPV6_H
22 #define _NF_DEFRAG_IPV6_H
33
4−void nf_defrag_ipv6_enable(void);
4+struct net;
5+int nf_defrag_ipv6_enable(struct net *);
56
67 int nf_ct_frag6_init(void);
78 void nf_ct_frag6_cleanup(void);
include/net/netns/netfilter.h+6−0
@@ -17,5 +17,11 @@ struct netns_nf { · 16 unmodified lines
1717 struct ctl_table_header *nf_log_dir_header;
1818 #endif
1919 struct nf_hook_entry __rcu *hooks[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
20+#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
21+ bool defrag_ipv4;
22+#endif
23+#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
24+ bool defrag_ipv6;
25+#endif
2026 };
2127 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t