History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next

Pablo Neira Ayuso says: ==================== Netfilter/IPVS updates for net-next The following patchset contains Netfilter updates for your net-next tree, they are: 1) Remove useless debug message when deleting IPVS service, from Yannick Brosseau. 2) Get rid of compilation warning when CONFIG_PROC_FS is unset in several spots of the IPVS code, from Arnd Bergmann. 3) Add prandom_u32 support to nft_meta, from Florian Westphal. 4) Remove unused variable in xt_osf, from Sudip Mukherjee. 5) Don't calculate IP checksum twice from netfilter ipv4 defrag hook since fixing af_packet defragmentation issues, from Joe Stringer. 6) On-demand hook registration for iptables from netns. Instead of registering the hooks for every available netns whenever we need one of the support tables, we register this on the specific netns that needs it, patchset from Florian Westphal. 7) Add missing port range selection to nf_tables masquerading support. BTW, just for the record, there is a typo in the description of 5f6c253ebe93b0 ("netfilter: bridge: register hooks only when bridge interface is added") that refers to the cluster match as deprecated, but it is actually the CLUSTERIP target (which registers hooks inconditionally) the one that is scheduled for removal. ====================

David S. Miller committed 10 years ago

Commit 4c38cd62 parents d24ad3f 8a6bf5d32 files · +626 −353Browse files

Unified · Split

32 files
  1. include/linux/netfilter.h +11 −18
  2. include/linux/netfilter/x_tables.h +4 −2
  3. include/linux/netfilter_arp/arp_tables.h +5 −4
  4. include/linux/netfilter_ipv4/ip_tables.h +5 −4
  5. include/linux/netfilter_ipv6/ip6_tables.h +5 −4
  6. include/net/netfilter/nft_masq.h +3 −1
  7. include/uapi/linux/netfilter/nf_tables.h +6 −0
  8. lib/random32.c +1 −0
  9. net/bridge/br_netfilter_hooks.c +65 −3
  10. net/ipv4/netfilter/arp_tables.c +41 −25
  11. net/ipv4/netfilter/arptable_filter.c +23 −17
  12. net/ipv4/netfilter/ip_tables.c +38 −25
  13. net/ipv4/netfilter/iptable_filter.c +29 −15
  14. net/ipv4/netfilter/iptable_mangle.c +28 −13
  15. net/ipv4/netfilter/iptable_nat.c +22 −19
  16. net/ipv4/netfilter/iptable_raw.c +26 −12
  17. net/ipv4/netfilter/iptable_security.c +28 −16
  18. net/ipv4/netfilter/nf_defrag_ipv4.c +1 −3
  19. net/ipv4/netfilter/nft_masq_ipv4.c +6 −1
  20. net/ipv6/netfilter/ip6_tables.c +40 −25
  21. net/ipv6/netfilter/ip6table_filter.c +29 −18
  22. net/ipv6/netfilter/ip6table_mangle.c +28 −18
  23. net/ipv6/netfilter/ip6table_nat.c +22 −19
  24. net/ipv6/netfilter/ip6table_raw.c +28 −18
  25. net/ipv6/netfilter/ip6table_security.c +27 −17
  26. net/ipv6/netfilter/nft_masq_ipv6.c +6 −1
  27. net/netfilter/ipvs/ip_vs_app.c +2 −6
  28. net/netfilter/ipvs/ip_vs_ctl.c +6 −11
  29. net/netfilter/nft_masq.c +40 −11
  30. net/netfilter/nft_meta.c +11 −0
  31. net/netfilter/x_tables.c +40 −25
  32. net/netfilter/xt_osf.c +0 −2
include/linux/netfilter.h+11−18
@@ -141,22 +141,6 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg); · 140 unmodified lines
141 141
142#ifdef HAVE_JUMP_LABEL142#ifdef HAVE_JUMP_LABEL
143extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS];143extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
144
145static inline bool nf_hook_list_active(struct list_head *hook_list,
146 u_int8_t pf, unsigned int hook)
147{
148 if (__builtin_constant_p(pf) &&
149 __builtin_constant_p(hook))
150 return static_key_false(&nf_hooks_needed[pf][hook]);
151
152 return !list_empty(hook_list);
153}
154#else
155static inline bool nf_hook_list_active(struct list_head *hook_list,
156 u_int8_t pf, unsigned int hook)
157{
158 return !list_empty(hook_list);
159}
160#endif144#endif
161 145
162int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state);146int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state);
@@ -177,9 +161,18 @@ static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook, · 14 unmodified lines
177 int (*okfn)(struct net *, struct sock *, struct sk_buff *),161 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
178 int thresh)162 int thresh)
179{163{
180 struct list_head *hook_list = &net->nf.hooks[pf][hook];164 struct list_head *hook_list;
165
166#ifdef HAVE_JUMP_LABEL
167 if (__builtin_constant_p(pf) &&
168 __builtin_constant_p(hook) &&
169 !static_key_false(&nf_hooks_needed[pf][hook]))
170 return 1;
171#endif
172
173 hook_list = &net->nf.hooks[pf][hook];
181 174
182 if (nf_hook_list_active(hook_list, pf, hook)) {175 if (!list_empty(hook_list)) {
183 struct nf_hook_state state;176 struct nf_hook_state state;
184 177
185 nf_hook_state_init(&state, hook_list, hook, thresh,178 nf_hook_state_init(&state, hook_list, hook, thresh,
include/linux/netfilter/x_tables.h+4−2
@@ -200,6 +200,9 @@ struct xt_table { · 199 unmodified lines
200 u_int8_t af; /* address/protocol family */200 u_int8_t af; /* address/protocol family */
201 int priority; /* hook order */201 int priority; /* hook order */
202 202
203 /* called when table is needed in the given netns */
204 int (*table_init)(struct net *net);
205
203 /* A unique name... */206 /* A unique name... */
204 const char name[XT_TABLE_MAXNAMELEN];207 const char name[XT_TABLE_MAXNAMELEN];
205};208};
@@ -408,8 +411,7 @@ xt_get_per_cpu_counter(struct xt_counters *cnt, unsigned int cpu) · 202 unmodified lines
408 return cnt;411 return cnt;
409}412}
410 413
411struct nf_hook_ops *xt_hook_link(const struct xt_table *, nf_hookfn *);414struct nf_hook_ops *xt_hook_ops_alloc(const struct xt_table *, nf_hookfn *);
412void xt_hook_unlink(const struct xt_table *, struct nf_hook_ops *);
413 415
414#ifdef CONFIG_COMPAT416#ifdef CONFIG_COMPAT
415#include <net/compat.h>417#include <net/compat.h>
include/linux/netfilter_arp/arp_tables.h+5−4
@@ -48,10 +48,11 @@ struct arpt_error { · 47 unmodified lines
48}48}
49 49
50extern void *arpt_alloc_initial_table(const struct xt_table *);50extern void *arpt_alloc_initial_table(const struct xt_table *);
51extern struct xt_table *arpt_register_table(struct net *net,51int arpt_register_table(struct net *net, const struct xt_table *table,
52 const struct xt_table *table,52 const struct arpt_replace *repl,
53 const struct arpt_replace *repl);53 const struct nf_hook_ops *ops, struct xt_table **res);
54extern void arpt_unregister_table(struct xt_table *table);54void arpt_unregister_table(struct net *net, struct xt_table *table,
55 const struct nf_hook_ops *ops);
55extern unsigned int arpt_do_table(struct sk_buff *skb,56extern unsigned int arpt_do_table(struct sk_buff *skb,
56 const struct nf_hook_state *state,57 const struct nf_hook_state *state,
57 struct xt_table *table);58 struct xt_table *table);
include/linux/netfilter_ipv4/ip_tables.h+5−4
@@ -24,10 +24,11 @@ · 23 unmodified lines
24 24
25extern void ipt_init(void) __init;25extern void ipt_init(void) __init;
26 26
27extern struct xt_table *ipt_register_table(struct net *net,27int ipt_register_table(struct net *net, const struct xt_table *table,
28 const struct xt_table *table,28 const struct ipt_replace *repl,
29 const struct ipt_replace *repl);29 const struct nf_hook_ops *ops, struct xt_table **res);
30extern void ipt_unregister_table(struct net *net, struct xt_table *table);30void ipt_unregister_table(struct net *net, struct xt_table *table,
31 const struct nf_hook_ops *ops);
31 32
32/* Standard entry. */33/* Standard entry. */
33struct ipt_standard {34struct ipt_standard {
include/linux/netfilter_ipv6/ip6_tables.h+5−4
@@ -25,10 +25,11 @@ · 24 unmodified lines
25extern void ip6t_init(void) __init;25extern void ip6t_init(void) __init;
26 26
27extern void *ip6t_alloc_initial_table(const struct xt_table *);27extern void *ip6t_alloc_initial_table(const struct xt_table *);
28extern struct xt_table *ip6t_register_table(struct net *net,28int ip6t_register_table(struct net *net, const struct xt_table *table,
29 const struct xt_table *table,29 const struct ip6t_replace *repl,
30 const struct ip6t_replace *repl);30 const struct nf_hook_ops *ops, struct xt_table **res);
31extern void ip6t_unregister_table(struct net *net, struct xt_table *table);31void ip6t_unregister_table(struct net *net, struct xt_table *table,
32 const struct nf_hook_ops *ops);
32extern unsigned int ip6t_do_table(struct sk_buff *skb,33extern unsigned int ip6t_do_table(struct sk_buff *skb,
33 const struct nf_hook_state *state,34 const struct nf_hook_state *state,
34 struct xt_table *table);35 struct xt_table *table);
include/net/netfilter/nft_masq.h+3−1
@@ -2,7 +2,9 @@ · 1 unmodified line
2#define _NFT_MASQ_H_2#define _NFT_MASQ_H_
3 3
4struct nft_masq {4struct nft_masq {
5 u32 flags;5 u32 flags;
6 enum nft_registers sreg_proto_min:8;
7 enum nft_registers sreg_proto_max:8;
6};8};
7 9
8extern const struct nla_policy nft_masq_policy[];10extern const struct nla_policy nft_masq_policy[];
include/uapi/linux/netfilter/nf_tables.h+6−0
@@ -681,6 +681,7 @@ enum nft_exthdr_attributes { · 680 unmodified lines
681 * @NFT_META_IIFGROUP: packet input interface group681 * @NFT_META_IIFGROUP: packet input interface group
682 * @NFT_META_OIFGROUP: packet output interface group682 * @NFT_META_OIFGROUP: packet output interface group
683 * @NFT_META_CGROUP: socket control group (skb->sk->sk_classid)683 * @NFT_META_CGROUP: socket control group (skb->sk->sk_classid)
684 * @NFT_META_PRANDOM: a 32bit pseudo-random number
684 */685 */
685enum nft_meta_keys {686enum nft_meta_keys {
686 NFT_META_LEN,687 NFT_META_LEN,
@@ -707,6 +708,7 @@ enum nft_meta_keys { · 20 unmodified lines
707 NFT_META_IIFGROUP,708 NFT_META_IIFGROUP,
708 NFT_META_OIFGROUP,709 NFT_META_OIFGROUP,
709 NFT_META_CGROUP,710 NFT_META_CGROUP,
711 NFT_META_PRANDOM,
710};712};
711 713
712/**714/**
@@ -949,10 +951,14 @@ enum nft_nat_attributes { · 236 unmodified lines
949 * enum nft_masq_attributes - nf_tables masquerade expression attributes951 * enum nft_masq_attributes - nf_tables masquerade expression attributes
950 *952 *
951 * @NFTA_MASQ_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32)953 * @NFTA_MASQ_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32)
954 * @NFTA_MASQ_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers)
955 * @NFTA_MASQ_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers)
952 */956 */
953enum nft_masq_attributes {957enum nft_masq_attributes {
954 NFTA_MASQ_UNSPEC,958 NFTA_MASQ_UNSPEC,
955 NFTA_MASQ_FLAGS,959 NFTA_MASQ_FLAGS,
960 NFTA_MASQ_REG_PROTO_MIN,
961 NFTA_MASQ_REG_PROTO_MAX,
956 __NFTA_MASQ_MAX962 __NFTA_MASQ_MAX
957};963};
958#define NFTA_MASQ_MAX (__NFTA_MASQ_MAX - 1)964#define NFTA_MASQ_MAX (__NFTA_MASQ_MAX - 1)
lib/random32.c+1−0
@@ -255,6 +255,7 @@ void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state) · 254 unmodified lines
255 prandom_warmup(state);255 prandom_warmup(state);
256 }256 }
257}257}
258EXPORT_SYMBOL(prandom_seed_full_state);
258 259
259/*260/*
260 * Generate better values after random number generator261 * Generate better values after random number generator
net/bridge/br_netfilter_hooks.c+65−3
@@ -37,6 +37,7 @@ · 36 unmodified lines
37#include <net/addrconf.h>37#include <net/addrconf.h>
38#include <net/route.h>38#include <net/route.h>
39#include <net/netfilter/br_netfilter.h>39#include <net/netfilter/br_netfilter.h>
40#include <net/netns/generic.h>
40 41
41#include <asm/uaccess.h>42#include <asm/uaccess.h>
42#include "br_private.h"43#include "br_private.h"
@@ -44,6 +45,12 @@ · 1 unmodified line
44#include <linux/sysctl.h>45#include <linux/sysctl.h>
45#endif46#endif
46 47
48static int brnf_net_id __read_mostly;
49
50struct brnf_net {
51 bool enabled;
52};
53
47#ifdef CONFIG_SYSCTL54#ifdef CONFIG_SYSCTL
48static struct ctl_table_header *brnf_sysctl_header;55static struct ctl_table_header *brnf_sysctl_header;
49static int brnf_call_iptables __read_mostly = 1;56static int brnf_call_iptables __read_mostly = 1;
@@ -938,6 +945,53 @@ static struct nf_hook_ops br_nf_ops[] __read_mostly = { · 888 unmodified lines
938 },945 },
939};946};
940 947
948static int brnf_device_event(struct notifier_block *unused, unsigned long event,
949 void *ptr)
950{
951 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
952 struct brnf_net *brnet;
953 struct net *net;
954 int ret;
955
956 if (event != NETDEV_REGISTER || !(dev->priv_flags & IFF_EBRIDGE))
957 return NOTIFY_DONE;
958
959 ASSERT_RTNL();
960
961 net = dev_net(dev);
962 brnet = net_generic(net, brnf_net_id);
963 if (brnet->enabled)
964 return NOTIFY_OK;
965
966 ret = nf_register_net_hooks(net, br_nf_ops, ARRAY_SIZE(br_nf_ops));
967 if (ret)
968 return NOTIFY_BAD;
969
970 brnet->enabled = true;
971 return NOTIFY_OK;
972}
973
974static void __net_exit brnf_exit_net(struct net *net)
975{
976 struct brnf_net *brnet = net_generic(net, brnf_net_id);
977
978 if (!brnet->enabled)
979 return;
980
981 nf_unregister_net_hooks(net, br_nf_ops, ARRAY_SIZE(br_nf_ops));
982 brnet->enabled = false;
983}
984
985static struct pernet_operations brnf_net_ops __read_mostly = {
986 .exit = brnf_exit_net,
987 .id = &brnf_net_id,
988 .size = sizeof(struct brnf_net),
989};
990
991static struct notifier_block brnf_notifier __read_mostly = {
992 .notifier_call = brnf_device_event,
993};
994
941#ifdef CONFIG_SYSCTL995#ifdef CONFIG_SYSCTL
942static996static
943int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,997int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,
@@ -1003,16 +1057,23 @@ static int __init br_netfilter_init(void) · 59 unmodified lines
1003{1057{
1004 int ret;1058 int ret;
1005 1059
1006 ret = nf_register_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));1060 ret = register_pernet_subsys(&brnf_net_ops);
1007 if (ret < 0)1061 if (ret < 0)
1008 return ret;1062 return ret;
1009 1063
1064 ret = register_netdevice_notifier(&brnf_notifier);
1065 if (ret < 0) {
1066 unregister_pernet_subsys(&brnf_net_ops);
1067 return ret;
1068 }
1069
1010#ifdef CONFIG_SYSCTL1070#ifdef CONFIG_SYSCTL
1011 brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);1071 brnf_sysctl_header = register_net_sysctl(&init_net, "net/bridge", brnf_table);
1012 if (brnf_sysctl_header == NULL) {1072 if (brnf_sysctl_header == NULL) {
1013 printk(KERN_WARNING1073 printk(KERN_WARNING
1014 "br_netfilter: can't register to sysctl.\n");1074 "br_netfilter: can't register to sysctl.\n");
1015 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));1075 unregister_netdevice_notifier(&brnf_notifier);
1076 unregister_pernet_subsys(&brnf_net_ops);
1016 return -ENOMEM;1077 return -ENOMEM;
1017 }1078 }
1018#endif1079#endif
@@ -1024,7 +1085,8 @@ static int __init br_netfilter_init(void) · 5 unmodified lines
1024static void __exit br_netfilter_fini(void)1085static void __exit br_netfilter_fini(void)
1025{1086{
1026 RCU_INIT_POINTER(nf_br_ops, NULL);1087 RCU_INIT_POINTER(nf_br_ops, NULL);
1027 nf_unregister_hooks(br_nf_ops, ARRAY_SIZE(br_nf_ops));1088 unregister_netdevice_notifier(&brnf_notifier);
1089 unregister_pernet_subsys(&brnf_net_ops);
1028#ifdef CONFIG_SYSCTL1090#ifdef CONFIG_SYSCTL
1029 unregister_net_sysctl_table(brnf_sysctl_header);1091 unregister_net_sysctl_table(brnf_sysctl_header);
1030#endif1092#endif
net/ipv4/netfilter/arp_tables.c+41−25
@@ -1780,9 +1780,29 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len · 1779 unmodified lines
1780 return ret;1780 return ret;
1781}1781}
1782 1782
1783struct xt_table *arpt_register_table(struct net *net,1783static void __arpt_unregister_table(struct xt_table *table)
1784 const struct xt_table *table,1784{
1785 const struct arpt_replace *repl)1785 struct xt_table_info *private;
1786 void *loc_cpu_entry;
1787 struct module *table_owner = table->me;
1788 struct arpt_entry *iter;
1789
1790 private = xt_unregister_table(table);
1791
1792 /* Decrease module usage counts and free resources */
1793 loc_cpu_entry = private->entries;
1794 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1795 cleanup_entry(iter);
1796 if (private->number > private->initial_entries)
1797 module_put(table_owner);
1798 xt_free_table_info(private);
1799}
1800
1801int arpt_register_table(struct net *net,
1802 const struct xt_table *table,
1803 const struct arpt_replace *repl,
1804 const struct nf_hook_ops *ops,
1805 struct xt_table **res)
1786{1806{
1787 int ret;1807 int ret;
1788 struct xt_table_info *newinfo;1808 struct xt_table_info *newinfo;
@@ -1791,10 +1811,8 @@ struct xt_table *arpt_register_table(struct net *net, · 2 unmodified lines
1791 struct xt_table *new_table;1811 struct xt_table *new_table;
1792 1812
1793 newinfo = xt_alloc_table_info(repl->size);1813 newinfo = xt_alloc_table_info(repl->size);
1794 if (!newinfo) {1814 if (!newinfo)
1795 ret = -ENOMEM;1815 return -ENOMEM;
1796 goto out;
1797 }
1798 1816
1799 loc_cpu_entry = newinfo->entries;1817 loc_cpu_entry = newinfo->entries;
1800 memcpy(loc_cpu_entry, repl->entries, repl->size);1818 memcpy(loc_cpu_entry, repl->entries, repl->size);
@@ -1809,30 +1827,28 @@ struct xt_table *arpt_register_table(struct net *net, · 8 unmodified lines
1809 ret = PTR_ERR(new_table);1827 ret = PTR_ERR(new_table);
1810 goto out_free;1828 goto out_free;
1811 }1829 }
1812 return new_table;1830
1831 /* set res now, will see skbs right after nf_register_net_hooks */
1832 WRITE_ONCE(*res, new_table);
1833
1834 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1835 if (ret != 0) {
1836 __arpt_unregister_table(new_table);
1837 *res = NULL;
1838 }
1839
1840 return ret;
1813 1841
1814out_free:1842out_free:
1815 xt_free_table_info(newinfo);1843 xt_free_table_info(newinfo);
1816out:1844 return ret;
1817 return ERR_PTR(ret);
1818}1845}
1819 1846
1820void arpt_unregister_table(struct xt_table *table)1847void arpt_unregister_table(struct net *net, struct xt_table *table,
1848 const struct nf_hook_ops *ops)
1821{1849{
1822 struct xt_table_info *private;1850 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1823 void *loc_cpu_entry;1851 __arpt_unregister_table(table);
1824 struct module *table_owner = table->me;
1825 struct arpt_entry *iter;
1826
1827 private = xt_unregister_table(table);
1828
1829 /* Decrease module usage counts and free resources */
1830 loc_cpu_entry = private->entries;
1831 xt_entry_foreach(iter, loc_cpu_entry, private->size)
1832 cleanup_entry(iter);
1833 if (private->number > private->initial_entries)
1834 module_put(table_owner);
1835 xt_free_table_info(private);
1836}1852}
1837 1853
1838/* The built-in targets: standard (NULL) and error. */1854/* The built-in targets: standard (NULL) and error. */
net/ipv4/netfilter/arptable_filter.c+23−17
@@ -17,12 +17,15 @@ MODULE_DESCRIPTION("arptables filter table"); · 16 unmodified lines
17#define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \17#define FILTER_VALID_HOOKS ((1 << NF_ARP_IN) | (1 << NF_ARP_OUT) | \
18 (1 << NF_ARP_FORWARD))18 (1 << NF_ARP_FORWARD))
19 19
20static int __net_init arptable_filter_table_init(struct net *net);
21
20static const struct xt_table packet_filter = {22static const struct xt_table packet_filter = {
21 .name = "filter",23 .name = "filter",
22 .valid_hooks = FILTER_VALID_HOOKS,24 .valid_hooks = FILTER_VALID_HOOKS,
23 .me = THIS_MODULE,25 .me = THIS_MODULE,
24 .af = NFPROTO_ARP,26 .af = NFPROTO_ARP,
25 .priority = NF_IP_PRI_FILTER,27 .priority = NF_IP_PRI_FILTER,
28 .table_init = arptable_filter_table_init,
26};29};
27 30
28/* The work comes in here from netfilter.c */31/* The work comes in here from netfilter.c */
@@ -35,26 +38,32 @@ arptable_filter_hook(void *priv, struct sk_buff *skb, · 6 unmodified lines
35 38
36static struct nf_hook_ops *arpfilter_ops __read_mostly;39static struct nf_hook_ops *arpfilter_ops __read_mostly;
37 40
38static int __net_init arptable_filter_net_init(struct net *net)41static int __net_init arptable_filter_table_init(struct net *net)
39{42{
40 struct arpt_replace *repl;43 struct arpt_replace *repl;
41 44 int err;
45
46 if (net->ipv4.arptable_filter)
47 return 0;
48
42 repl = arpt_alloc_initial_table(&packet_filter);49 repl = arpt_alloc_initial_table(&packet_filter);
43 if (repl == NULL)50 if (repl == NULL)
44 return -ENOMEM;51 return -ENOMEM;
45 net->ipv4.arptable_filter =52 err = arpt_register_table(net, &packet_filter, repl, arpfilter_ops,
46 arpt_register_table(net, &packet_filter, repl);53 &net->ipv4.arptable_filter);
47 kfree(repl);54 kfree(repl);
48 return PTR_ERR_OR_ZERO(net->ipv4.arptable_filter);55 return err;
49}56}
50 57
51static void __net_exit arptable_filter_net_exit(struct net *net)58static void __net_exit arptable_filter_net_exit(struct net *net)
52{59{
53 arpt_unregister_table(net->ipv4.arptable_filter);60 if (!net->ipv4.arptable_filter)
61 return;
62 arpt_unregister_table(net, net->ipv4.arptable_filter, arpfilter_ops);
63 net->ipv4.arptable_filter = NULL;
54}64}
55 65
56static struct pernet_operations arptable_filter_net_ops = {66static struct pernet_operations arptable_filter_net_ops = {
57 .init = arptable_filter_net_init,
58 .exit = arptable_filter_net_exit,67 .exit = arptable_filter_net_exit,
59};68};
60 69
@@ -62,26 +71,23 @@ static int __init arptable_filter_init(void) · 1 unmodified line
62{71{
63 int ret;72 int ret;
64 73
74 arpfilter_ops = xt_hook_ops_alloc(&packet_filter, arptable_filter_hook);
75 if (IS_ERR(arpfilter_ops))
76 return PTR_ERR(arpfilter_ops);
77
65 ret = register_pernet_subsys(&arptable_filter_net_ops);78 ret = register_pernet_subsys(&arptable_filter_net_ops);
66 if (ret < 0)79 if (ret < 0) {
80 kfree(arpfilter_ops);
67 return ret;81 return ret;
68
69 arpfilter_ops = xt_hook_link(&packet_filter, arptable_filter_hook);
70 if (IS_ERR(arpfilter_ops)) {
71 ret = PTR_ERR(arpfilter_ops);
72 goto cleanup_table;
73 }82 }
74 return ret;
75 83
76cleanup_table:
77 unregister_pernet_subsys(&arptable_filter_net_ops);
78 return ret;84 return ret;
79}85}
80 86
81static void __exit arptable_filter_fini(void)87static void __exit arptable_filter_fini(void)
82{88{
83 xt_hook_unlink(&packet_filter, arpfilter_ops);
84 unregister_pernet_subsys(&arptable_filter_net_ops);89 unregister_pernet_subsys(&arptable_filter_net_ops);
90 kfree(arpfilter_ops);
85}91}
86 92
87module_init(arptable_filter_init);93module_init(arptable_filter_init);
net/ipv4/netfilter/ip_tables.c+38−25
@@ -2062,9 +2062,27 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) · 2061 unmodified lines
2062 return ret;2062 return ret;
2063}2063}
2064 2064
2065struct xt_table *ipt_register_table(struct net *net,2065static void __ipt_unregister_table(struct net *net, struct xt_table *table)
2066 const struct xt_table *table,2066{
2067 const struct ipt_replace *repl)2067 struct xt_table_info *private;
2068 void *loc_cpu_entry;
2069 struct module *table_owner = table->me;
2070 struct ipt_entry *iter;
2071
2072 private = xt_unregister_table(table);
2073
2074 /* Decrease module usage counts and free resources */
2075 loc_cpu_entry = private->entries;
2076 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2077 cleanup_entry(iter, net);
2078 if (private->number > private->initial_entries)
2079 module_put(table_owner);
2080 xt_free_table_info(private);
2081}
2082
2083int ipt_register_table(struct net *net, const struct xt_table *table,
2084 const struct ipt_replace *repl,
2085 const struct nf_hook_ops *ops, struct xt_table **res)
2068{2086{
2069 int ret;2087 int ret;
2070 struct xt_table_info *newinfo;2088 struct xt_table_info *newinfo;
@@ -2073,10 +2091,8 @@ struct xt_table *ipt_register_table(struct net *net, · 2 unmodified lines
2073 struct xt_table *new_table;2091 struct xt_table *new_table;
2074 2092
2075 newinfo = xt_alloc_table_info(repl->size);2093 newinfo = xt_alloc_table_info(repl->size);
2076 if (!newinfo) {2094 if (!newinfo)
2077 ret = -ENOMEM;2095 return -ENOMEM;
2078 goto out;
2079 }
2080 2096
2081 loc_cpu_entry = newinfo->entries;2097 loc_cpu_entry = newinfo->entries;
2082 memcpy(loc_cpu_entry, repl->entries, repl->size);2098 memcpy(loc_cpu_entry, repl->entries, repl->size);
@@ -2091,30 +2107,27 @@ struct xt_table *ipt_register_table(struct net *net, · 8 unmodified lines
2091 goto out_free;2107 goto out_free;
2092 }2108 }
2093 2109
2094 return new_table;2110 /* set res now, will see skbs right after nf_register_net_hooks */
2111 WRITE_ONCE(*res, new_table);
2112
2113 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
2114 if (ret != 0) {
2115 __ipt_unregister_table(net, new_table);
2116 *res = NULL;
2117 }
2118
2119 return ret;
2095 2120
2096out_free:2121out_free:
2097 xt_free_table_info(newinfo);2122 xt_free_table_info(newinfo);
2098out:2123 return ret;
2099 return ERR_PTR(ret);
2100}2124}
2101 2125
2102void ipt_unregister_table(struct net *net, struct xt_table *table)2126void ipt_unregister_table(struct net *net, struct xt_table *table,
2127 const struct nf_hook_ops *ops)
2103{2128{
2104 struct xt_table_info *private;2129 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
2105 void *loc_cpu_entry;2130 __ipt_unregister_table(net, table);
2106 struct module *table_owner = table->me;
2107 struct ipt_entry *iter;
2108
2109 private = xt_unregister_table(table);
2110
2111 /* Decrease module usage counts and free resources */
2112 loc_cpu_entry = private->entries;
2113 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2114 cleanup_entry(iter, net);
2115 if (private->number > private->initial_entries)
2116 module_put(table_owner);
2117 xt_free_table_info(private);
2118}2131}
2119 2132
2120/* Returns 1 if the type and code is matched by the range, 0 otherwise */2133/* Returns 1 if the type and code is matched by the range, 0 otherwise */
net/ipv4/netfilter/iptable_filter.c+29−15
@@ -23,6 +23,7 @@ MODULE_DESCRIPTION("iptables filter table"); · 22 unmodified lines
23#define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \23#define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \
24 (1 << NF_INET_FORWARD) | \24 (1 << NF_INET_FORWARD) | \
25 (1 << NF_INET_LOCAL_OUT))25 (1 << NF_INET_LOCAL_OUT))
26static int __net_init iptable_filter_table_init(struct net *net);
26 27
27static const struct xt_table packet_filter = {28static const struct xt_table packet_filter = {
28 .name = "filter",29 .name = "filter",
@@ -30,6 +31,7 @@ static const struct xt_table packet_filter = { · 1 unmodified line
30 .me = THIS_MODULE,31 .me = THIS_MODULE,
31 .af = NFPROTO_IPV4,32 .af = NFPROTO_IPV4,
32 .priority = NF_IP_PRI_FILTER,33 .priority = NF_IP_PRI_FILTER,
34 .table_init = iptable_filter_table_init,
33};35};
34 36
35static unsigned int37static unsigned int
@@ -48,12 +50,16 @@ iptable_filter_hook(void *priv, struct sk_buff *skb, · 12 unmodified lines
48static struct nf_hook_ops *filter_ops __read_mostly;50static struct nf_hook_ops *filter_ops __read_mostly;
49 51
50/* Default to forward because I got too much mail already. */52/* Default to forward because I got too much mail already. */
51static bool forward = true;53static bool forward __read_mostly = true;
52module_param(forward, bool, 0000);54module_param(forward, bool, 0000);
53 55
54static int __net_init iptable_filter_net_init(struct net *net)56static int __net_init iptable_filter_table_init(struct net *net)
55{57{
56 struct ipt_replace *repl;58 struct ipt_replace *repl;
59 int err;
60
61 if (net->ipv4.iptable_filter)
62 return 0;
57 63
58 repl = ipt_alloc_initial_table(&packet_filter);64 repl = ipt_alloc_initial_table(&packet_filter);
59 if (repl == NULL)65 if (repl == NULL)
@@ -62,15 +68,26 @@ static int __net_init iptable_filter_net_init(struct net *net) · 2 unmodified lines
62 ((struct ipt_standard *)repl->entries)[1].target.verdict =68 ((struct ipt_standard *)repl->entries)[1].target.verdict =
63 forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;69 forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
64 70
65 net->ipv4.iptable_filter =71 err = ipt_register_table(net, &packet_filter, repl, filter_ops,
66 ipt_register_table(net, &packet_filter, repl);72 &net->ipv4.iptable_filter);
67 kfree(repl);73 kfree(repl);
68 return PTR_ERR_OR_ZERO(net->ipv4.iptable_filter);74 return err;
75}
76
77static int __net_init iptable_filter_net_init(struct net *net)
78{
79 if (net == &init_net || !forward)
80 return iptable_filter_table_init(net);
81
82 return 0;
69}83}
70 84
71static void __net_exit iptable_filter_net_exit(struct net *net)85static void __net_exit iptable_filter_net_exit(struct net *net)
72{86{
73 ipt_unregister_table(net, net->ipv4.iptable_filter);87 if (!net->ipv4.iptable_filter)
88 return;
89 ipt_unregister_table(net, net->ipv4.iptable_filter, filter_ops);
90 net->ipv4.iptable_filter = NULL;
74}91}
75 92
76static struct pernet_operations iptable_filter_net_ops = {93static struct pernet_operations iptable_filter_net_ops = {
@@ -82,24 +99,21 @@ static int __init iptable_filter_init(void) · 5 unmodified lines
82{99{
83 int ret;100 int ret;
84 101
102 filter_ops = xt_hook_ops_alloc(&packet_filter, iptable_filter_hook);
103 if (IS_ERR(filter_ops))
104 return PTR_ERR(filter_ops);
105
85 ret = register_pernet_subsys(&iptable_filter_net_ops);106 ret = register_pernet_subsys(&iptable_filter_net_ops);
86 if (ret < 0)107 if (ret < 0)
87 return ret;108 kfree(filter_ops);
88
89 /* Register hooks */
90 filter_ops = xt_hook_link(&packet_filter, iptable_filter_hook);
91 if (IS_ERR(filter_ops)) {
92 ret = PTR_ERR(filter_ops);
93 unregister_pernet_subsys(&iptable_filter_net_ops);
94 }
95 109
96 return ret;110 return ret;
97}111}
98 112
99static void __exit iptable_filter_fini(void)113static void __exit iptable_filter_fini(void)
100{114{
101 xt_hook_unlink(&packet_filter, filter_ops);
102 unregister_pernet_subsys(&iptable_filter_net_ops);115 unregister_pernet_subsys(&iptable_filter_net_ops);
116 kfree(filter_ops);
103}117}
104 118
105module_init(iptable_filter_init);119module_init(iptable_filter_init);
net/ipv4/netfilter/iptable_mangle.c+28−13
@@ -28,12 +28,15 @@ MODULE_DESCRIPTION("iptables mangle table"); · 27 unmodified lines
28 (1 << NF_INET_LOCAL_OUT) | \28 (1 << NF_INET_LOCAL_OUT) | \
29 (1 << NF_INET_POST_ROUTING))29 (1 << NF_INET_POST_ROUTING))
30 30
31static int __net_init iptable_mangle_table_init(struct net *net);
32
31static const struct xt_table packet_mangler = {33static const struct xt_table packet_mangler = {
32 .name = "mangle",34 .name = "mangle",
33 .valid_hooks = MANGLE_VALID_HOOKS,35 .valid_hooks = MANGLE_VALID_HOOKS,
34 .me = THIS_MODULE,36 .me = THIS_MODULE,
35 .af = NFPROTO_IPV4,37 .af = NFPROTO_IPV4,
36 .priority = NF_IP_PRI_MANGLE,38 .priority = NF_IP_PRI_MANGLE,
39 .table_init = iptable_mangle_table_init,
37};40};
38 41
39static unsigned int42static unsigned int
@@ -92,27 +95,32 @@ iptable_mangle_hook(void *priv, · 52 unmodified lines
92}95}
93 96
94static struct nf_hook_ops *mangle_ops __read_mostly;97static struct nf_hook_ops *mangle_ops __read_mostly;
95 98static int __net_init iptable_mangle_table_init(struct net *net)
96static int __net_init iptable_mangle_net_init(struct net *net)
97{99{
98 struct ipt_replace *repl;100 struct ipt_replace *repl;
101 int ret;
102
103 if (net->ipv4.iptable_mangle)
104 return 0;
99 105
100 repl = ipt_alloc_initial_table(&packet_mangler);106 repl = ipt_alloc_initial_table(&packet_mangler);
101 if (repl == NULL)107 if (repl == NULL)
102 return -ENOMEM;108 return -ENOMEM;
103 net->ipv4.iptable_mangle =109 ret = ipt_register_table(net, &packet_mangler, repl, mangle_ops,
104 ipt_register_table(net, &packet_mangler, repl);110 &net->ipv4.iptable_mangle);
105 kfree(repl);111 kfree(repl);
106 return PTR_ERR_OR_ZERO(net->ipv4.iptable_mangle);112 return ret;
107}113}
108 114
109static void __net_exit iptable_mangle_net_exit(struct net *net)115static void __net_exit iptable_mangle_net_exit(struct net *net)
110{116{
111 ipt_unregister_table(net, net->ipv4.iptable_mangle);117 if (!net->ipv4.iptable_mangle)
118 return;
119 ipt_unregister_table(net, net->ipv4.iptable_mangle, mangle_ops);
120 net->ipv4.iptable_mangle = NULL;
112}121}
113 122
114static struct pernet_operations iptable_mangle_net_ops = {123static struct pernet_operations iptable_mangle_net_ops = {
115 .init = iptable_mangle_net_init,
116 .exit = iptable_mangle_net_exit,124 .exit = iptable_mangle_net_exit,
117};125};
118 126
@@ -120,15 +128,22 @@ static int __init iptable_mangle_init(void) · 1 unmodified line
120{128{
121 int ret;129 int ret;
122 130
131 mangle_ops = xt_hook_ops_alloc(&packet_mangler, iptable_mangle_hook);
132 if (IS_ERR(mangle_ops)) {
133 ret = PTR_ERR(mangle_ops);
134 return ret;
135 }
136
123 ret = register_pernet_subsys(&iptable_mangle_net_ops);137 ret = register_pernet_subsys(&iptable_mangle_net_ops);
124 if (ret < 0)138 if (ret < 0) {
139 kfree(mangle_ops);
125 return ret;140 return ret;
141 }
126 142
127 /* Register hooks */143 ret = iptable_mangle_table_init(&init_net);
128 mangle_ops = xt_hook_link(&packet_mangler, iptable_mangle_hook);144 if (ret) {
129 if (IS_ERR(mangle_ops)) {
130 ret = PTR_ERR(mangle_ops);
131 unregister_pernet_subsys(&iptable_mangle_net_ops);145 unregister_pernet_subsys(&iptable_mangle_net_ops);
146 kfree(mangle_ops);
132 }147 }
133 148
134 return ret;149 return ret;
@@ -136,8 +151,8 @@ static int __init iptable_mangle_init(void) · 1 unmodified line
136 151
137static void __exit iptable_mangle_fini(void)152static void __exit iptable_mangle_fini(void)
138{153{
139 xt_hook_unlink(&packet_mangler, mangle_ops);
140 unregister_pernet_subsys(&iptable_mangle_net_ops);154 unregister_pernet_subsys(&iptable_mangle_net_ops);
155 kfree(mangle_ops);
141}156}
142 157
143module_init(iptable_mangle_init);158module_init(iptable_mangle_init);
net/ipv4/netfilter/iptable_nat.c+22−19
@@ -18,6 +18,8 @@ · 17 unmodified lines
18#include <net/netfilter/nf_nat_core.h>18#include <net/netfilter/nf_nat_core.h>
19#include <net/netfilter/nf_nat_l3proto.h>19#include <net/netfilter/nf_nat_l3proto.h>
20 20
21static int __net_init iptable_nat_table_init(struct net *net);
22
21static const struct xt_table nf_nat_ipv4_table = {23static const struct xt_table nf_nat_ipv4_table = {
22 .name = "nat",24 .name = "nat",
23 .valid_hooks = (1 << NF_INET_PRE_ROUTING) |25 .valid_hooks = (1 << NF_INET_PRE_ROUTING) |
@@ -26,6 +28,7 @@ static const struct xt_table nf_nat_ipv4_table = { · 2 unmodified lines
26 (1 << NF_INET_LOCAL_IN),28 (1 << NF_INET_LOCAL_IN),
27 .me = THIS_MODULE,29 .me = THIS_MODULE,
28 .af = NFPROTO_IPV4,30 .af = NFPROTO_IPV4,
31 .table_init = iptable_nat_table_init,
29};32};
30 33
31static unsigned int iptable_nat_do_chain(void *priv,34static unsigned int iptable_nat_do_chain(void *priv,
@@ -95,50 +98,50 @@ static struct nf_hook_ops nf_nat_ipv4_ops[] __read_mostly = { · 63 unmodified lines
95 },98 },
96};99};
97 100
98static int __net_init iptable_nat_net_init(struct net *net)101static int __net_init iptable_nat_table_init(struct net *net)
99{102{
100 struct ipt_replace *repl;103 struct ipt_replace *repl;
104 int ret;
105
106 if (net->ipv4.nat_table)
107 return 0;
101 108
102 repl = ipt_alloc_initial_table(&nf_nat_ipv4_table);109 repl = ipt_alloc_initial_table(&nf_nat_ipv4_table);
103 if (repl == NULL)110 if (repl == NULL)
104 return -ENOMEM;111 return -ENOMEM;
105 net->ipv4.nat_table = ipt_register_table(net, &nf_nat_ipv4_table, repl);112 ret = ipt_register_table(net, &nf_nat_ipv4_table, repl,
113 nf_nat_ipv4_ops, &net->ipv4.nat_table);
106 kfree(repl);114 kfree(repl);
107 return PTR_ERR_OR_ZERO(net->ipv4.nat_table);115 return ret;
108}116}
109 117
110static void __net_exit iptable_nat_net_exit(struct net *net)118static void __net_exit iptable_nat_net_exit(struct net *net)
111{119{
112 ipt_unregister_table(net, net->ipv4.nat_table);120 if (!net->ipv4.nat_table)
121 return;
122 ipt_unregister_table(net, net->ipv4.nat_table, nf_nat_ipv4_ops);
123 net->ipv4.nat_table = NULL;
113}124}
114 125
115static struct pernet_operations iptable_nat_net_ops = {126static struct pernet_operations iptable_nat_net_ops = {
116 .init = iptable_nat_net_init,
117 .exit = iptable_nat_net_exit,127 .exit = iptable_nat_net_exit,
118};128};
119 129
120static int __init iptable_nat_init(void)130static int __init iptable_nat_init(void)
121{131{
122 int err;132 int ret = register_pernet_subsys(&iptable_nat_net_ops);
123 133
124 err = register_pernet_subsys(&iptable_nat_net_ops);134 if (ret)
125 if (err < 0)135 return ret;
126 goto err1;
127 136
128 err = nf_register_hooks(nf_nat_ipv4_ops, ARRAY_SIZE(nf_nat_ipv4_ops));137 ret = iptable_nat_table_init(&init_net);
129 if (err < 0)138 if (ret)
130 goto err2;139 unregister_pernet_subsys(&iptable_nat_net_ops);
131 return 0;140 return ret;
132
133err2:
134 unregister_pernet_subsys(&iptable_nat_net_ops);
135err1:
136 return err;
137}141}
138 142
139static void __exit iptable_nat_exit(void)143static void __exit iptable_nat_exit(void)
140{144{
141 nf_unregister_hooks(nf_nat_ipv4_ops, ARRAY_SIZE(nf_nat_ipv4_ops));
142 unregister_pernet_subsys(&iptable_nat_net_ops);145 unregister_pernet_subsys(&iptable_nat_net_ops);
143}146}
144 147
net/ipv4/netfilter/iptable_raw.c+26−12
@@ -10,12 +10,15 @@ · 9 unmodified lines
10 10
11#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))11#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
12 12
13static int __net_init iptable_raw_table_init(struct net *net);
14
13static const struct xt_table packet_raw = {15static const struct xt_table packet_raw = {
14 .name = "raw",16 .name = "raw",
15 .valid_hooks = RAW_VALID_HOOKS,17 .valid_hooks = RAW_VALID_HOOKS,
16 .me = THIS_MODULE,18 .me = THIS_MODULE,
17 .af = NFPROTO_IPV4,19 .af = NFPROTO_IPV4,
18 .priority = NF_IP_PRI_RAW,20 .priority = NF_IP_PRI_RAW,
21 .table_init = iptable_raw_table_init,
19};22};
20 23
21/* The work comes in here from netfilter.c. */24/* The work comes in here from netfilter.c. */
@@ -34,26 +37,32 @@ iptable_raw_hook(void *priv, struct sk_buff *skb, · 12 unmodified lines
34 37
35static struct nf_hook_ops *rawtable_ops __read_mostly;38static struct nf_hook_ops *rawtable_ops __read_mostly;
36 39
37static int __net_init iptable_raw_net_init(struct net *net)40static int __net_init iptable_raw_table_init(struct net *net)
38{41{
39 struct ipt_replace *repl;42 struct ipt_replace *repl;
43 int ret;
44
45 if (net->ipv4.iptable_raw)
46 return 0;
40 47
41 repl = ipt_alloc_initial_table(&packet_raw);48 repl = ipt_alloc_initial_table(&packet_raw);
42 if (repl == NULL)49 if (repl == NULL)
43 return -ENOMEM;50 return -ENOMEM;
44 net->ipv4.iptable_raw =51 ret = ipt_register_table(net, &packet_raw, repl, rawtable_ops,
45 ipt_register_table(net, &packet_raw, repl);52 &net->ipv4.iptable_raw);
46 kfree(repl);53 kfree(repl);
47 return PTR_ERR_OR_ZERO(net->ipv4.iptable_raw);54 return ret;
48}55}
49 56
50static void __net_exit iptable_raw_net_exit(struct net *net)57static void __net_exit iptable_raw_net_exit(struct net *net)
51{58{
52 ipt_unregister_table(net, net->ipv4.iptable_raw);59 if (!net->ipv4.iptable_raw)
60 return;
61 ipt_unregister_table(net, net->ipv4.iptable_raw, rawtable_ops);
62 net->ipv4.iptable_raw = NULL;
53}63}
54 64
55static struct pernet_operations iptable_raw_net_ops = {65static struct pernet_operations iptable_raw_net_ops = {
56 .init = iptable_raw_net_init,
57 .exit = iptable_raw_net_exit,66 .exit = iptable_raw_net_exit,
58};67};
59 68
@@ -61,15 +70,20 @@ static int __init iptable_raw_init(void) · 1 unmodified line
61{70{
62 int ret;71 int ret;
63 72
73 rawtable_ops = xt_hook_ops_alloc(&packet_raw, iptable_raw_hook);
74 if (IS_ERR(rawtable_ops))
75 return PTR_ERR(rawtable_ops);
76
64 ret = register_pernet_subsys(&iptable_raw_net_ops);77 ret = register_pernet_subsys(&iptable_raw_net_ops);
65 if (ret < 0)78 if (ret < 0) {
79 kfree(rawtable_ops);
66 return ret;80 return ret;
81 }
67 82
68 /* Register hooks */83 ret = iptable_raw_table_init(&init_net);
69 rawtable_ops = xt_hook_link(&packet_raw, iptable_raw_hook);84 if (ret) {
70 if (IS_ERR(rawtable_ops)) {
71 ret = PTR_ERR(rawtable_ops);
72 unregister_pernet_subsys(&iptable_raw_net_ops);85 unregister_pernet_subsys(&iptable_raw_net_ops);
86 kfree(rawtable_ops);
73 }87 }
74 88
75 return ret;89 return ret;
@@ -77,8 +91,8 @@ static int __init iptable_raw_init(void) · 1 unmodified line
77 91
78static void __exit iptable_raw_fini(void)92static void __exit iptable_raw_fini(void)
79{93{
80 xt_hook_unlink(&packet_raw, rawtable_ops);
81 unregister_pernet_subsys(&iptable_raw_net_ops);94 unregister_pernet_subsys(&iptable_raw_net_ops);
95 kfree(rawtable_ops);
82}96}
83 97
84module_init(iptable_raw_init);98module_init(iptable_raw_init);
net/ipv4/netfilter/iptable_security.c+28−16
@@ -28,12 +28,15 @@ MODULE_DESCRIPTION("iptables security table, for MAC rules"); · 27 unmodified lines
28 (1 << NF_INET_FORWARD) | \28 (1 << NF_INET_FORWARD) | \
29 (1 << NF_INET_LOCAL_OUT)29 (1 << NF_INET_LOCAL_OUT)
30 30
31static int __net_init iptable_security_table_init(struct net *net);
32
31static const struct xt_table security_table = {33static const struct xt_table security_table = {
32 .name = "security",34 .name = "security",
33 .valid_hooks = SECURITY_VALID_HOOKS,35 .valid_hooks = SECURITY_VALID_HOOKS,
34 .me = THIS_MODULE,36 .me = THIS_MODULE,
35 .af = NFPROTO_IPV4,37 .af = NFPROTO_IPV4,
36 .priority = NF_IP_PRI_SECURITY,38 .priority = NF_IP_PRI_SECURITY,
39 .table_init = iptable_security_table_init,
37};40};
38 41
39static unsigned int42static unsigned int
@@ -51,26 +54,33 @@ iptable_security_hook(void *priv, struct sk_buff *skb, · 11 unmodified lines
51 54
52static struct nf_hook_ops *sectbl_ops __read_mostly;55static struct nf_hook_ops *sectbl_ops __read_mostly;
53 56
54static int __net_init iptable_security_net_init(struct net *net)57static int __net_init iptable_security_table_init(struct net *net)
55{58{
56 struct ipt_replace *repl;59 struct ipt_replace *repl;
60 int ret;
61
62 if (net->ipv4.iptable_security)
63 return 0;
57 64
58 repl = ipt_alloc_initial_table(&security_table);65 repl = ipt_alloc_initial_table(&security_table);
59 if (repl == NULL)66 if (repl == NULL)
60 return -ENOMEM;67 return -ENOMEM;
61 net->ipv4.iptable_security =68 ret = ipt_register_table(net, &security_table, repl, sectbl_ops,
62 ipt_register_table(net, &security_table, repl);69 &net->ipv4.iptable_security);
63 kfree(repl);70 kfree(repl);
64 return PTR_ERR_OR_ZERO(net->ipv4.iptable_security);71 return ret;
65}72}
66 73
67static void __net_exit iptable_security_net_exit(struct net *net)74static void __net_exit iptable_security_net_exit(struct net *net)
68{75{
69 ipt_unregister_table(net, net->ipv4.iptable_security);76 if (!net->ipv4.iptable_security)
77 return;
78
79 ipt_unregister_table(net, net->ipv4.iptable_security, sectbl_ops);
80 net->ipv4.iptable_security = NULL;
70}81}
71 82
72static struct pernet_operations iptable_security_net_ops = {83static struct pernet_operations iptable_security_net_ops = {
73 .init = iptable_security_net_init,
74 .exit = iptable_security_net_exit,84 .exit = iptable_security_net_exit,
75};85};
76 86
@@ -78,27 +88,29 @@ static int __init iptable_security_init(void) · 1 unmodified line
78{88{
79 int ret;89 int ret;
80 90
91 sectbl_ops = xt_hook_ops_alloc(&security_table, iptable_security_hook);
92 if (IS_ERR(sectbl_ops))
93 return PTR_ERR(sectbl_ops);
94
81 ret = register_pernet_subsys(&iptable_security_net_ops);95 ret = register_pernet_subsys(&iptable_security_net_ops);
82 if (ret < 0)96 if (ret < 0) {
97 kfree(sectbl_ops);
83 return ret;98 return ret;
84
85 sectbl_ops = xt_hook_link(&security_table, iptable_security_hook);
86 if (IS_ERR(sectbl_ops)) {
87 ret = PTR_ERR(sectbl_ops);
88 goto cleanup_table;
89 }99 }
90 100
91 return ret;101 ret = iptable_security_table_init(&init_net);
102 if (ret) {
103 unregister_pernet_subsys(&iptable_security_net_ops);
104 kfree(sectbl_ops);
105 }
92 106
93cleanup_table:
94 unregister_pernet_subsys(&iptable_security_net_ops);
95 return ret;107 return ret;
96}108}
97 109
98static void __exit iptable_security_fini(void)110static void __exit iptable_security_fini(void)
99{111{
100 xt_hook_unlink(&security_table, sectbl_ops);
101 unregister_pernet_subsys(&iptable_security_net_ops);112 unregister_pernet_subsys(&iptable_security_net_ops);
113 kfree(sectbl_ops);
102}114}
103 115
104module_init(iptable_security_init);116module_init(iptable_security_init);
net/ipv4/netfilter/nf_defrag_ipv4.c+1−3
@@ -31,10 +31,8 @@ static int nf_ct_ipv4_gather_frags(struct net *net, struct sk_buff *skb, · 30 unmodified lines
31 err = ip_defrag(net, skb, user);31 err = ip_defrag(net, skb, user);
32 local_bh_enable();32 local_bh_enable();
33 33
34 if (!err) {34 if (!err)
35 ip_send_check(ip_hdr(skb));
36 skb->ignore_df = 1;35 skb->ignore_df = 1;
37 }
38 36
39 return err;37 return err;
40}38}
net/ipv4/netfilter/nft_masq_ipv4.c+6−1
@@ -25,7 +25,12 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr, · 24 unmodified lines
25 25
26 memset(&range, 0, sizeof(range));26 memset(&range, 0, sizeof(range));
27 range.flags = priv->flags;27 range.flags = priv->flags;
28 28 if (priv->sreg_proto_min) {
29 range.min_proto.all =
30 *(__be16 *)&regs->data[priv->sreg_proto_min];
31 range.max_proto.all =
32 *(__be16 *)&regs->data[priv->sreg_proto_max];
33 }
29 regs->verdict.code = nf_nat_masquerade_ipv4(pkt->skb, pkt->hook,34 regs->verdict.code = nf_nat_masquerade_ipv4(pkt->skb, pkt->hook,
30 &range, pkt->out);35 &range, pkt->out);
31}36}
net/ipv6/netfilter/ip6_tables.c+40−25
@@ -2071,9 +2071,28 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) · 2070 unmodified lines
2071 return ret;2071 return ret;
2072}2072}
2073 2073
2074struct xt_table *ip6t_register_table(struct net *net,2074static void __ip6t_unregister_table(struct net *net, struct xt_table *table)
2075 const struct xt_table *table,2075{
2076 const struct ip6t_replace *repl)2076 struct xt_table_info *private;
2077 void *loc_cpu_entry;
2078 struct module *table_owner = table->me;
2079 struct ip6t_entry *iter;
2080
2081 private = xt_unregister_table(table);
2082
2083 /* Decrease module usage counts and free resources */
2084 loc_cpu_entry = private->entries;
2085 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2086 cleanup_entry(iter, net);
2087 if (private->number > private->initial_entries)
2088 module_put(table_owner);
2089 xt_free_table_info(private);
2090}
2091
2092int ip6t_register_table(struct net *net, const struct xt_table *table,
2093 const struct ip6t_replace *repl,
2094 const struct nf_hook_ops *ops,
2095 struct xt_table **res)
2077{2096{
2078 int ret;2097 int ret;
2079 struct xt_table_info *newinfo;2098 struct xt_table_info *newinfo;
@@ -2082,10 +2101,8 @@ struct xt_table *ip6t_register_table(struct net *net, · 2 unmodified lines
2082 struct xt_table *new_table;2101 struct xt_table *new_table;
2083 2102
2084 newinfo = xt_alloc_table_info(repl->size);2103 newinfo = xt_alloc_table_info(repl->size);
2085 if (!newinfo) {2104 if (!newinfo)
2086 ret = -ENOMEM;2105 return -ENOMEM;
2087 goto out;
2088 }
2089 2106
2090 loc_cpu_entry = newinfo->entries;2107 loc_cpu_entry = newinfo->entries;
2091 memcpy(loc_cpu_entry, repl->entries, repl->size);2108 memcpy(loc_cpu_entry, repl->entries, repl->size);
@@ -2099,30 +2116,28 @@ struct xt_table *ip6t_register_table(struct net *net, · 7 unmodified lines
2099 ret = PTR_ERR(new_table);2116 ret = PTR_ERR(new_table);
2100 goto out_free;2117 goto out_free;
2101 }2118 }
2102 return new_table;2119
2120 /* set res now, will see skbs right after nf_register_net_hooks */
2121 WRITE_ONCE(*res, new_table);
2122
2123 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
2124 if (ret != 0) {
2125 __ip6t_unregister_table(net, new_table);
2126 *res = NULL;
2127 }
2128
2129 return ret;
2103 2130
2104out_free:2131out_free:
2105 xt_free_table_info(newinfo);2132 xt_free_table_info(newinfo);
2106out:2133 return ret;
2107 return ERR_PTR(ret);
2108}2134}
2109 2135
2110void ip6t_unregister_table(struct net *net, struct xt_table *table)2136void ip6t_unregister_table(struct net *net, struct xt_table *table,
2137 const struct nf_hook_ops *ops)
2111{2138{
2112 struct xt_table_info *private;2139 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
2113 void *loc_cpu_entry;2140 __ip6t_unregister_table(net, table);
2114 struct module *table_owner = table->me;
2115 struct ip6t_entry *iter;
2116
2117 private = xt_unregister_table(table);
2118
2119 /* Decrease module usage counts and free resources */
2120 loc_cpu_entry = private->entries;
2121 xt_entry_foreach(iter, loc_cpu_entry, private->size)
2122 cleanup_entry(iter, net);
2123 if (private->number > private->initial_entries)
2124 module_put(table_owner);
2125 xt_free_table_info(private);
2126}2141}
2127 2142
2128/* Returns 1 if the type and code is matched by the range, 0 otherwise */2143/* Returns 1 if the type and code is matched by the range, 0 otherwise */
net/ipv6/netfilter/ip6table_filter.c+29−18
@@ -22,12 +22,15 @@ MODULE_DESCRIPTION("ip6tables filter table"); · 21 unmodified lines
22 (1 << NF_INET_FORWARD) | \22 (1 << NF_INET_FORWARD) | \
23 (1 << NF_INET_LOCAL_OUT))23 (1 << NF_INET_LOCAL_OUT))
24 24
25static int __net_init ip6table_filter_table_init(struct net *net);
26
25static const struct xt_table packet_filter = {27static const struct xt_table packet_filter = {
26 .name = "filter",28 .name = "filter",
27 .valid_hooks = FILTER_VALID_HOOKS,29 .valid_hooks = FILTER_VALID_HOOKS,
28 .me = THIS_MODULE,30 .me = THIS_MODULE,
29 .af = NFPROTO_IPV6,31 .af = NFPROTO_IPV6,
30 .priority = NF_IP6_PRI_FILTER,32 .priority = NF_IP6_PRI_FILTER,
33 .table_init = ip6table_filter_table_init,
31};34};
32 35
33/* The work comes in here from netfilter.c. */36/* The work comes in here from netfilter.c. */
@@ -44,9 +47,13 @@ static struct nf_hook_ops *filter_ops __read_mostly; · 10 unmodified lines
44static bool forward = true;47static bool forward = true;
45module_param(forward, bool, 0000);48module_param(forward, bool, 0000);
46 49
47static int __net_init ip6table_filter_net_init(struct net *net)50static int __net_init ip6table_filter_table_init(struct net *net)
48{51{
49 struct ip6t_replace *repl;52 struct ip6t_replace *repl;
53 int err;
54
55 if (net->ipv6.ip6table_filter)
56 return 0;
50 57
51 repl = ip6t_alloc_initial_table(&packet_filter);58 repl = ip6t_alloc_initial_table(&packet_filter);
52 if (repl == NULL)59 if (repl == NULL)
@@ -55,15 +62,26 @@ static int __net_init ip6table_filter_net_init(struct net *net) · 2 unmodified lines
55 ((struct ip6t_standard *)repl->entries)[1].target.verdict =62 ((struct ip6t_standard *)repl->entries)[1].target.verdict =
56 forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;63 forward ? -NF_ACCEPT - 1 : -NF_DROP - 1;
57 64
58 net->ipv6.ip6table_filter =65 err = ip6t_register_table(net, &packet_filter, repl, filter_ops,
59 ip6t_register_table(net, &packet_filter, repl);66 &net->ipv6.ip6table_filter);
60 kfree(repl);67 kfree(repl);
61 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_filter);68 return err;
69}
70
71static int __net_init ip6table_filter_net_init(struct net *net)
72{
73 if (net == &init_net || !forward)
74 return ip6table_filter_table_init(net);
75
76 return 0;
62}77}
63 78
64static void __net_exit ip6table_filter_net_exit(struct net *net)79static void __net_exit ip6table_filter_net_exit(struct net *net)
65{80{
66 ip6t_unregister_table(net, net->ipv6.ip6table_filter);81 if (!net->ipv6.ip6table_filter)
82 return;
83 ip6t_unregister_table(net, net->ipv6.ip6table_filter, filter_ops);
84 net->ipv6.ip6table_filter = NULL;
67}85}
68 86
69static struct pernet_operations ip6table_filter_net_ops = {87static struct pernet_operations ip6table_filter_net_ops = {
@@ -75,28 +93,21 @@ static int __init ip6table_filter_init(void) · 5 unmodified lines
75{93{
76 int ret;94 int ret;
77 95
96 filter_ops = xt_hook_ops_alloc(&packet_filter, ip6table_filter_hook);
97 if (IS_ERR(filter_ops))
98 return PTR_ERR(filter_ops);
99
78 ret = register_pernet_subsys(&ip6table_filter_net_ops);100 ret = register_pernet_subsys(&ip6table_filter_net_ops);
79 if (ret < 0)101 if (ret < 0)
80 return ret;102 kfree(filter_ops);
81
82 /* Register hooks */
83 filter_ops = xt_hook_link(&packet_filter, ip6table_filter_hook);
84 if (IS_ERR(filter_ops)) {
85 ret = PTR_ERR(filter_ops);
86 goto cleanup_table;
87 }
88 103
89 return ret;104 return ret;
90
91 cleanup_table:
92 unregister_pernet_subsys(&ip6table_filter_net_ops);
93 return ret;
94}105}
95 106
96static void __exit ip6table_filter_fini(void)107static void __exit ip6table_filter_fini(void)
97{108{
98 xt_hook_unlink(&packet_filter, filter_ops);
99 unregister_pernet_subsys(&ip6table_filter_net_ops);109 unregister_pernet_subsys(&ip6table_filter_net_ops);
110 kfree(filter_ops);
100}111}
101 112
102module_init(ip6table_filter_init);113module_init(ip6table_filter_init);
net/ipv6/netfilter/ip6table_mangle.c+28−18
@@ -23,12 +23,15 @@ MODULE_DESCRIPTION("ip6tables mangle table"); · 22 unmodified lines
23 (1 << NF_INET_LOCAL_OUT) | \23 (1 << NF_INET_LOCAL_OUT) | \
24 (1 << NF_INET_POST_ROUTING))24 (1 << NF_INET_POST_ROUTING))
25 25
26static int __net_init ip6table_mangle_table_init(struct net *net);
27
26static const struct xt_table packet_mangler = {28static const struct xt_table packet_mangler = {
27 .name = "mangle",29 .name = "mangle",
28 .valid_hooks = MANGLE_VALID_HOOKS,30 .valid_hooks = MANGLE_VALID_HOOKS,
29 .me = THIS_MODULE,31 .me = THIS_MODULE,
30 .af = NFPROTO_IPV6,32 .af = NFPROTO_IPV6,
31 .priority = NF_IP6_PRI_MANGLE,33 .priority = NF_IP6_PRI_MANGLE,
34 .table_init = ip6table_mangle_table_init,
32};35};
33 36
34static unsigned int37static unsigned int
@@ -88,26 +91,33 @@ ip6table_mangle_hook(void *priv, struct sk_buff *skb, · 53 unmodified lines
88}91}
89 92
90static struct nf_hook_ops *mangle_ops __read_mostly;93static struct nf_hook_ops *mangle_ops __read_mostly;
91static int __net_init ip6table_mangle_net_init(struct net *net)94static int __net_init ip6table_mangle_table_init(struct net *net)
92{95{
93 struct ip6t_replace *repl;96 struct ip6t_replace *repl;
97 int ret;
98
99 if (net->ipv6.ip6table_mangle)
100 return 0;
94 101
95 repl = ip6t_alloc_initial_table(&packet_mangler);102 repl = ip6t_alloc_initial_table(&packet_mangler);
96 if (repl == NULL)103 if (repl == NULL)
97 return -ENOMEM;104 return -ENOMEM;
98 net->ipv6.ip6table_mangle =105 ret = ip6t_register_table(net, &packet_mangler, repl, mangle_ops,
99 ip6t_register_table(net, &packet_mangler, repl);106 &net->ipv6.ip6table_mangle);
100 kfree(repl);107 kfree(repl);
101 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_mangle);108 return ret;
102}109}
103 110
104static void __net_exit ip6table_mangle_net_exit(struct net *net)111static void __net_exit ip6table_mangle_net_exit(struct net *net)
105{112{
106 ip6t_unregister_table(net, net->ipv6.ip6table_mangle);113 if (!net->ipv6.ip6table_mangle)
114 return;
115
116 ip6t_unregister_table(net, net->ipv6.ip6table_mangle, mangle_ops);
117 net->ipv6.ip6table_mangle = NULL;
107}118}
108 119
109static struct pernet_operations ip6table_mangle_net_ops = {120static struct pernet_operations ip6table_mangle_net_ops = {
110 .init = ip6table_mangle_net_init,
111 .exit = ip6table_mangle_net_exit,121 .exit = ip6table_mangle_net_exit,
112};122};
113 123
@@ -115,28 +125,28 @@ static int __init ip6table_mangle_init(void) · 1 unmodified line
115{125{
116 int ret;126 int ret;
117 127
128 mangle_ops = xt_hook_ops_alloc(&packet_mangler, ip6table_mangle_hook);
129 if (IS_ERR(mangle_ops))
130 return PTR_ERR(mangle_ops);
131
118 ret = register_pernet_subsys(&ip6table_mangle_net_ops);132 ret = register_pernet_subsys(&ip6table_mangle_net_ops);
119 if (ret < 0)133 if (ret < 0) {
134 kfree(mangle_ops);
120 return ret;135 return ret;
121
122 /* Register hooks */
123 mangle_ops = xt_hook_link(&packet_mangler, ip6table_mangle_hook);
124 if (IS_ERR(mangle_ops)) {
125 ret = PTR_ERR(mangle_ops);
126 goto cleanup_table;
127 }136 }
128 137
129 return ret;138 ret = ip6table_mangle_table_init(&init_net);
130 139 if (ret) {
131 cleanup_table:140 unregister_pernet_subsys(&ip6table_mangle_net_ops);
132 unregister_pernet_subsys(&ip6table_mangle_net_ops);141 kfree(mangle_ops);
142 }
133 return ret;143 return ret;
134}144}
135 145
136static void __exit ip6table_mangle_fini(void)146static void __exit ip6table_mangle_fini(void)
137{147{
138 xt_hook_unlink(&packet_mangler, mangle_ops);
139 unregister_pernet_subsys(&ip6table_mangle_net_ops);148 unregister_pernet_subsys(&ip6table_mangle_net_ops);
149 kfree(mangle_ops);
140}150}
141 151
142module_init(ip6table_mangle_init);152module_init(ip6table_mangle_init);
net/ipv6/netfilter/ip6table_nat.c+22−19
@@ -20,6 +20,8 @@ · 19 unmodified lines
20#include <net/netfilter/nf_nat_core.h>20#include <net/netfilter/nf_nat_core.h>
21#include <net/netfilter/nf_nat_l3proto.h>21#include <net/netfilter/nf_nat_l3proto.h>
22 22
23static int __net_init ip6table_nat_table_init(struct net *net);
24
23static const struct xt_table nf_nat_ipv6_table = {25static const struct xt_table nf_nat_ipv6_table = {
24 .name = "nat",26 .name = "nat",
25 .valid_hooks = (1 << NF_INET_PRE_ROUTING) |27 .valid_hooks = (1 << NF_INET_PRE_ROUTING) |
@@ -28,6 +30,7 @@ static const struct xt_table nf_nat_ipv6_table = { · 2 unmodified lines
28 (1 << NF_INET_LOCAL_IN),30 (1 << NF_INET_LOCAL_IN),
29 .me = THIS_MODULE,31 .me = THIS_MODULE,
30 .af = NFPROTO_IPV6,32 .af = NFPROTO_IPV6,
33 .table_init = ip6table_nat_table_init,
31};34};
32 35
33static unsigned int ip6table_nat_do_chain(void *priv,36static unsigned int ip6table_nat_do_chain(void *priv,
@@ -97,50 +100,50 @@ static struct nf_hook_ops nf_nat_ipv6_ops[] __read_mostly = { · 63 unmodified lines
97 },100 },
98};101};
99 102
100static int __net_init ip6table_nat_net_init(struct net *net)103static int __net_init ip6table_nat_table_init(struct net *net)
101{104{
102 struct ip6t_replace *repl;105 struct ip6t_replace *repl;
106 int ret;
107
108 if (net->ipv6.ip6table_nat)
109 return 0;
103 110
104 repl = ip6t_alloc_initial_table(&nf_nat_ipv6_table);111 repl = ip6t_alloc_initial_table(&nf_nat_ipv6_table);
105 if (repl == NULL)112 if (repl == NULL)
106 return -ENOMEM;113 return -ENOMEM;
107 net->ipv6.ip6table_nat = ip6t_register_table(net, &nf_nat_ipv6_table, repl);114 ret = ip6t_register_table(net, &nf_nat_ipv6_table, repl,
115 nf_nat_ipv6_ops, &net->ipv6.ip6table_nat);
108 kfree(repl);116 kfree(repl);
109 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_nat);117 return ret;
110}118}
111 119
112static void __net_exit ip6table_nat_net_exit(struct net *net)120static void __net_exit ip6table_nat_net_exit(struct net *net)
113{121{
114 ip6t_unregister_table(net, net->ipv6.ip6table_nat);122 if (!net->ipv6.ip6table_nat)
123 return;
124 ip6t_unregister_table(net, net->ipv6.ip6table_nat, nf_nat_ipv6_ops);
125 net->ipv6.ip6table_nat = NULL;
115}126}
116 127
117static struct pernet_operations ip6table_nat_net_ops = {128static struct pernet_operations ip6table_nat_net_ops = {
118 .init = ip6table_nat_net_init,
119 .exit = ip6table_nat_net_exit,129 .exit = ip6table_nat_net_exit,
120};130};
121 131
122static int __init ip6table_nat_init(void)132static int __init ip6table_nat_init(void)
123{133{
124 int err;134 int ret = register_pernet_subsys(&ip6table_nat_net_ops);
125 135
126 err = register_pernet_subsys(&ip6table_nat_net_ops);136 if (ret)
127 if (err < 0)137 return ret;
128 goto err1;
129 138
130 err = nf_register_hooks(nf_nat_ipv6_ops, ARRAY_SIZE(nf_nat_ipv6_ops));139 ret = ip6table_nat_table_init(&init_net);
131 if (err < 0)140 if (ret)
132 goto err2;141 unregister_pernet_subsys(&ip6table_nat_net_ops);
133 return 0;142 return ret;
134
135err2:
136 unregister_pernet_subsys(&ip6table_nat_net_ops);
137err1:
138 return err;
139}143}
140 144
141static void __exit ip6table_nat_exit(void)145static void __exit ip6table_nat_exit(void)
142{146{
143 nf_unregister_hooks(nf_nat_ipv6_ops, ARRAY_SIZE(nf_nat_ipv6_ops));
144 unregister_pernet_subsys(&ip6table_nat_net_ops);147 unregister_pernet_subsys(&ip6table_nat_net_ops);
145}148}
146 149
net/ipv6/netfilter/ip6table_raw.c+28−18
@@ -9,12 +9,15 @@ · 8 unmodified lines
9 9
10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
11 11
12static int __net_init ip6table_raw_table_init(struct net *net);
13
12static const struct xt_table packet_raw = {14static const struct xt_table packet_raw = {
13 .name = "raw",15 .name = "raw",
14 .valid_hooks = RAW_VALID_HOOKS,16 .valid_hooks = RAW_VALID_HOOKS,
15 .me = THIS_MODULE,17 .me = THIS_MODULE,
16 .af = NFPROTO_IPV6,18 .af = NFPROTO_IPV6,
17 .priority = NF_IP6_PRI_RAW,19 .priority = NF_IP6_PRI_RAW,
20 .table_init = ip6table_raw_table_init,
18};21};
19 22
20/* The work comes in here from netfilter.c. */23/* The work comes in here from netfilter.c. */
@@ -27,26 +30,32 @@ ip6table_raw_hook(void *priv, struct sk_buff *skb, · 6 unmodified lines
27 30
28static struct nf_hook_ops *rawtable_ops __read_mostly;31static struct nf_hook_ops *rawtable_ops __read_mostly;
29 32
30static int __net_init ip6table_raw_net_init(struct net *net)33static int __net_init ip6table_raw_table_init(struct net *net)
31{34{
32 struct ip6t_replace *repl;35 struct ip6t_replace *repl;
36 int ret;
37
38 if (net->ipv6.ip6table_raw)
39 return 0;
33 40
34 repl = ip6t_alloc_initial_table(&packet_raw);41 repl = ip6t_alloc_initial_table(&packet_raw);
35 if (repl == NULL)42 if (repl == NULL)
36 return -ENOMEM;43 return -ENOMEM;
37 net->ipv6.ip6table_raw =44 ret = ip6t_register_table(net, &packet_raw, repl, rawtable_ops,
38 ip6t_register_table(net, &packet_raw, repl);45 &net->ipv6.ip6table_raw);
39 kfree(repl);46 kfree(repl);
40 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw);47 return ret;
41}48}
42 49
43static void __net_exit ip6table_raw_net_exit(struct net *net)50static void __net_exit ip6table_raw_net_exit(struct net *net)
44{51{
45 ip6t_unregister_table(net, net->ipv6.ip6table_raw);52 if (!net->ipv6.ip6table_raw)
53 return;
54 ip6t_unregister_table(net, net->ipv6.ip6table_raw, rawtable_ops);
55 net->ipv6.ip6table_raw = NULL;
46}56}
47 57
48static struct pernet_operations ip6table_raw_net_ops = {58static struct pernet_operations ip6table_raw_net_ops = {
49 .init = ip6table_raw_net_init,
50 .exit = ip6table_raw_net_exit,59 .exit = ip6table_raw_net_exit,
51};60};
52 61
@@ -54,28 +63,29 @@ static int __init ip6table_raw_init(void) · 1 unmodified line
54{63{
55 int ret;64 int ret;
56 65
66 /* Register hooks */
67 rawtable_ops = xt_hook_ops_alloc(&packet_raw, ip6table_raw_hook);
68 if (IS_ERR(rawtable_ops))
69 return PTR_ERR(rawtable_ops);
70
57 ret = register_pernet_subsys(&ip6table_raw_net_ops);71 ret = register_pernet_subsys(&ip6table_raw_net_ops);
58 if (ret < 0)72 if (ret < 0) {
73 kfree(rawtable_ops);
59 return ret;74 return ret;
60
61 /* Register hooks */
62 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook);
63 if (IS_ERR(rawtable_ops)) {
64 ret = PTR_ERR(rawtable_ops);
65 goto cleanup_table;
66 }75 }
67 76
68 return ret;77 ret = ip6table_raw_table_init(&init_net);
69 78 if (ret) {
70 cleanup_table:79 unregister_pernet_subsys(&ip6table_raw_net_ops);
71 unregister_pernet_subsys(&ip6table_raw_net_ops);80 kfree(rawtable_ops);
81 }
72 return ret;82 return ret;
73}83}
74 84
75static void __exit ip6table_raw_fini(void)85static void __exit ip6table_raw_fini(void)
76{86{
77 xt_hook_unlink(&packet_raw, rawtable_ops);
78 unregister_pernet_subsys(&ip6table_raw_net_ops);87 unregister_pernet_subsys(&ip6table_raw_net_ops);
88 kfree(rawtable_ops);
79}89}
80 90
81module_init(ip6table_raw_init);91module_init(ip6table_raw_init);
net/ipv6/netfilter/ip6table_security.c+27−17
@@ -27,12 +27,15 @@ MODULE_DESCRIPTION("ip6tables security table, for MAC rules"); · 26 unmodified lines
27 (1 << NF_INET_FORWARD) | \27 (1 << NF_INET_FORWARD) | \
28 (1 << NF_INET_LOCAL_OUT)28 (1 << NF_INET_LOCAL_OUT)
29 29
30static int __net_init ip6table_security_table_init(struct net *net);
31
30static const struct xt_table security_table = {32static const struct xt_table security_table = {
31 .name = "security",33 .name = "security",
32 .valid_hooks = SECURITY_VALID_HOOKS,34 .valid_hooks = SECURITY_VALID_HOOKS,
33 .me = THIS_MODULE,35 .me = THIS_MODULE,
34 .af = NFPROTO_IPV6,36 .af = NFPROTO_IPV6,
35 .priority = NF_IP6_PRI_SECURITY,37 .priority = NF_IP6_PRI_SECURITY,
38 .table_init = ip6table_security_table_init,
36};39};
37 40
38static unsigned int41static unsigned int
@@ -44,26 +47,32 @@ ip6table_security_hook(void *priv, struct sk_buff *skb, · 5 unmodified lines
44 47
45static struct nf_hook_ops *sectbl_ops __read_mostly;48static struct nf_hook_ops *sectbl_ops __read_mostly;
46 49
47static int __net_init ip6table_security_net_init(struct net *net)50static int __net_init ip6table_security_table_init(struct net *net)
48{51{
49 struct ip6t_replace *repl;52 struct ip6t_replace *repl;
53 int ret;
54
55 if (net->ipv6.ip6table_security)
56 return 0;
50 57
51 repl = ip6t_alloc_initial_table(&security_table);58 repl = ip6t_alloc_initial_table(&security_table);
52 if (repl == NULL)59 if (repl == NULL)
53 return -ENOMEM;60 return -ENOMEM;
54 net->ipv6.ip6table_security =61 ret = ip6t_register_table(net, &security_table, repl, sectbl_ops,
55 ip6t_register_table(net, &security_table, repl);62 &net->ipv6.ip6table_security);
56 kfree(repl);63 kfree(repl);
57 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_security);64 return ret;
58}65}
59 66
60static void __net_exit ip6table_security_net_exit(struct net *net)67static void __net_exit ip6table_security_net_exit(struct net *net)
61{68{
62 ip6t_unregister_table(net, net->ipv6.ip6table_security);69 if (!net->ipv6.ip6table_security)
70 return;
71 ip6t_unregister_table(net, net->ipv6.ip6table_security, sectbl_ops);
72 net->ipv6.ip6table_security = NULL;
63}73}
64 74
65static struct pernet_operations ip6table_security_net_ops = {75static struct pernet_operations ip6table_security_net_ops = {
66 .init = ip6table_security_net_init,
67 .exit = ip6table_security_net_exit,76 .exit = ip6table_security_net_exit,
68};77};
69 78
@@ -71,27 +80,28 @@ static int __init ip6table_security_init(void) · 1 unmodified line
71{80{
72 int ret;81 int ret;
73 82
83 sectbl_ops = xt_hook_ops_alloc(&security_table, ip6table_security_hook);
84 if (IS_ERR(sectbl_ops))
85 return PTR_ERR(sectbl_ops);
86
74 ret = register_pernet_subsys(&ip6table_security_net_ops);87 ret = register_pernet_subsys(&ip6table_security_net_ops);
75 if (ret < 0)88 if (ret < 0) {
89 kfree(sectbl_ops);
76 return ret;90 return ret;
77
78 sectbl_ops = xt_hook_link(&security_table, ip6table_security_hook);
79 if (IS_ERR(sectbl_ops)) {
80 ret = PTR_ERR(sectbl_ops);
81 goto cleanup_table;
82 }91 }
83 92
84 return ret;93 ret = ip6table_security_table_init(&init_net);
85 94 if (ret) {
86cleanup_table:95 unregister_pernet_subsys(&ip6table_security_net_ops);
87 unregister_pernet_subsys(&ip6table_security_net_ops);96 kfree(sectbl_ops);
97 }
88 return ret;98 return ret;
89}99}
90 100
91static void __exit ip6table_security_fini(void)101static void __exit ip6table_security_fini(void)
92{102{
93 xt_hook_unlink(&security_table, sectbl_ops);
94 unregister_pernet_subsys(&ip6table_security_net_ops);103 unregister_pernet_subsys(&ip6table_security_net_ops);
104 kfree(sectbl_ops);
95}105}
96 106
97module_init(ip6table_security_init);107module_init(ip6table_security_init);
net/ipv6/netfilter/nft_masq_ipv6.c+6−1
@@ -26,7 +26,12 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr, · 25 unmodified lines
26 26
27 memset(&range, 0, sizeof(range));27 memset(&range, 0, sizeof(range));
28 range.flags = priv->flags;28 range.flags = priv->flags;
29 29 if (priv->sreg_proto_min) {
30 range.min_proto.all =
31 *(__be16 *)&regs->data[priv->sreg_proto_min];
32 range.max_proto.all =
33 *(__be16 *)&regs->data[priv->sreg_proto_max];
34 }
30 regs->verdict.code = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out);35 regs->verdict.code = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out);
31}36}
32 37
net/netfilter/ipvs/ip_vs_app.c+2−6
@@ -605,17 +605,13 @@ static const struct file_operations ip_vs_app_fops = { · 604 unmodified lines
605 605
606int __net_init ip_vs_app_net_init(struct netns_ipvs *ipvs)606int __net_init ip_vs_app_net_init(struct netns_ipvs *ipvs)
607{607{
608 struct net *net = ipvs->net;
609
610 INIT_LIST_HEAD(&ipvs->app_list);608 INIT_LIST_HEAD(&ipvs->app_list);
611 proc_create("ip_vs_app", 0, net->proc_net, &ip_vs_app_fops);609 proc_create("ip_vs_app", 0, ipvs->net->proc_net, &ip_vs_app_fops);
612 return 0;610 return 0;
613}611}
614 612
615void __net_exit ip_vs_app_net_cleanup(struct netns_ipvs *ipvs)613void __net_exit ip_vs_app_net_cleanup(struct netns_ipvs *ipvs)
616{614{
617 struct net *net = ipvs->net;
618
619 unregister_ip_vs_app(ipvs, NULL /* all */);615 unregister_ip_vs_app(ipvs, NULL /* all */);
620 remove_proc_entry("ip_vs_app", net->proc_net);616 remove_proc_entry("ip_vs_app", ipvs->net->proc_net);
621}617}
net/netfilter/ipvs/ip_vs_ctl.c+6−11
@@ -1376,8 +1376,6 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup) · 1375 unmodified lines
1376 struct ip_vs_pe *old_pe;1376 struct ip_vs_pe *old_pe;
1377 struct netns_ipvs *ipvs = svc->ipvs;1377 struct netns_ipvs *ipvs = svc->ipvs;
1378 1378
1379 pr_info("%s: enter\n", __func__);
1380
1381 /* Count only IPv4 services for old get/setsockopt interface */1379 /* Count only IPv4 services for old get/setsockopt interface */
1382 if (svc->af == AF_INET)1380 if (svc->af == AF_INET)
1383 ipvs->num_services--;1381 ipvs->num_services--;
@@ -3947,7 +3945,6 @@ static struct notifier_block ip_vs_dst_notifier = { · 2563 unmodified lines
3947 3945
3948int __net_init ip_vs_control_net_init(struct netns_ipvs *ipvs)3946int __net_init ip_vs_control_net_init(struct netns_ipvs *ipvs)
3949{3947{
3950 struct net *net = ipvs->net;
3951 int i, idx;3948 int i, idx;
3952 3949
3953 /* Initialize rs_table */3950 /* Initialize rs_table */
@@ -3974,9 +3971,9 @@ int __net_init ip_vs_control_net_init(struct netns_ipvs *ipvs) · 20 unmodified lines
3974 3971
3975 spin_lock_init(&ipvs->tot_stats.lock);3972 spin_lock_init(&ipvs->tot_stats.lock);
3976 3973
3977 proc_create("ip_vs", 0, net->proc_net, &ip_vs_info_fops);3974 proc_create("ip_vs", 0, ipvs->net->proc_net, &ip_vs_info_fops);
3978 proc_create("ip_vs_stats", 0, net->proc_net, &ip_vs_stats_fops);3975 proc_create("ip_vs_stats", 0, ipvs->net->proc_net, &ip_vs_stats_fops);
3979 proc_create("ip_vs_stats_percpu", 0, net->proc_net,3976 proc_create("ip_vs_stats_percpu", 0, ipvs->net->proc_net,
3980 &ip_vs_stats_percpu_fops);3977 &ip_vs_stats_percpu_fops);
3981 3978
3982 if (ip_vs_control_net_init_sysctl(ipvs))3979 if (ip_vs_control_net_init_sysctl(ipvs))
@@ -3991,13 +3988,11 @@ err: · 8 unmodified lines
3991 3988
3992void __net_exit ip_vs_control_net_cleanup(struct netns_ipvs *ipvs)3989void __net_exit ip_vs_control_net_cleanup(struct netns_ipvs *ipvs)
3993{3990{
3994 struct net *net = ipvs->net;
3995
3996 ip_vs_trash_cleanup(ipvs);3991 ip_vs_trash_cleanup(ipvs);
3997 ip_vs_control_net_cleanup_sysctl(ipvs);3992 ip_vs_control_net_cleanup_sysctl(ipvs);
3998 remove_proc_entry("ip_vs_stats_percpu", net->proc_net);3993 remove_proc_entry("ip_vs_stats_percpu", ipvs->net->proc_net);
3999 remove_proc_entry("ip_vs_stats", net->proc_net);3994 remove_proc_entry("ip_vs_stats", ipvs->net->proc_net);
4000 remove_proc_entry("ip_vs", net->proc_net);3995 remove_proc_entry("ip_vs", ipvs->net->proc_net);
4001 free_percpu(ipvs->tot_stats.cpustats);3996 free_percpu(ipvs->tot_stats.cpustats);
4002}3997}
4003 3998
net/netfilter/nft_masq.c+40−11
@@ -17,7 +17,9 @@ · 16 unmodified lines
17#include <net/netfilter/nft_masq.h>17#include <net/netfilter/nft_masq.h>
18 18
19const struct nla_policy nft_masq_policy[NFTA_MASQ_MAX + 1] = {19const struct nla_policy nft_masq_policy[NFTA_MASQ_MAX + 1] = {
20 [NFTA_MASQ_FLAGS] = { .type = NLA_U32 },20 [NFTA_MASQ_FLAGS] = { .type = NLA_U32 },
21 [NFTA_MASQ_REG_PROTO_MIN] = { .type = NLA_U32 },
22 [NFTA_MASQ_REG_PROTO_MAX] = { .type = NLA_U32 },
21};23};
22EXPORT_SYMBOL_GPL(nft_masq_policy);24EXPORT_SYMBOL_GPL(nft_masq_policy);
23 25
@@ -40,6 +42,7 @@ int nft_masq_init(const struct nft_ctx *ctx, · 16 unmodified lines
40 const struct nft_expr *expr,42 const struct nft_expr *expr,
41 const struct nlattr * const tb[])43 const struct nlattr * const tb[])
42{44{
45 u32 plen = FIELD_SIZEOF(struct nf_nat_range, min_addr.all);
43 struct nft_masq *priv = nft_expr_priv(expr);46 struct nft_masq *priv = nft_expr_priv(expr);
44 int err;47 int err;
45 48
@@ -47,12 +50,32 @@ int nft_masq_init(const struct nft_ctx *ctx, · 1 unmodified line
47 if (err)50 if (err)
48 return err;51 return err;
49 52
50 if (tb[NFTA_MASQ_FLAGS] == NULL)53 if (tb[NFTA_MASQ_FLAGS]) {
51 return 0;54 priv->flags = ntohl(nla_get_be32(tb[NFTA_MASQ_FLAGS]));
52 55 if (priv->flags & ~NF_NAT_RANGE_MASK)
53 priv->flags = ntohl(nla_get_be32(tb[NFTA_MASQ_FLAGS]));56 return -EINVAL;
54 if (priv->flags & ~NF_NAT_RANGE_MASK)57 }
55 return -EINVAL;58
59 if (tb[NFTA_MASQ_REG_PROTO_MIN]) {
60 priv->sreg_proto_min =
61 nft_parse_register(tb[NFTA_MASQ_REG_PROTO_MIN]);
62
63 err = nft_validate_register_load(priv->sreg_proto_min, plen);
64 if (err < 0)
65 return err;
66
67 if (tb[NFTA_MASQ_REG_PROTO_MAX]) {
68 priv->sreg_proto_max =
69 nft_parse_register(tb[NFTA_MASQ_REG_PROTO_MAX]);
70
71 err = nft_validate_register_load(priv->sreg_proto_max,
72 plen);
73 if (err < 0)
74 return err;
75 } else {
76 priv->sreg_proto_max = priv->sreg_proto_min;
77 }
78 }
56 79
57 return 0;80 return 0;
58}81}
@@ -62,12 +85,18 @@ int nft_masq_dump(struct sk_buff *skb, const struct nft_expr *expr) · 3 unmodified lines
62{85{
63 const struct nft_masq *priv = nft_expr_priv(expr);86 const struct nft_masq *priv = nft_expr_priv(expr);
64 87
65 if (priv->flags == 0)88 if (priv->flags != 0 &&
66 return 0;89 nla_put_be32(skb, NFTA_MASQ_FLAGS, htonl(priv->flags)))
67
68 if (nla_put_be32(skb, NFTA_MASQ_FLAGS, htonl(priv->flags)))
69 goto nla_put_failure;90 goto nla_put_failure;
70 91
92 if (priv->sreg_proto_min) {
93 if (nft_dump_register(skb, NFTA_MASQ_REG_PROTO_MIN,
94 priv->sreg_proto_min) ||
95 nft_dump_register(skb, NFTA_MASQ_REG_PROTO_MAX,
96 priv->sreg_proto_max))
97 goto nla_put_failure;
98 }
99
71 return 0;100 return 0;
72 101
73nla_put_failure:102nla_put_failure:
net/netfilter/nft_meta.c+11−0
@@ -28,6 +28,8 @@ · 27 unmodified lines
28 28
29#include <uapi/linux/netfilter_bridge.h> /* NF_BR_PRE_ROUTING */29#include <uapi/linux/netfilter_bridge.h> /* NF_BR_PRE_ROUTING */
30 30
31static DEFINE_PER_CPU(struct rnd_state, nft_prandom_state);
32
31void nft_meta_get_eval(const struct nft_expr *expr,33void nft_meta_get_eval(const struct nft_expr *expr,
32 struct nft_regs *regs,34 struct nft_regs *regs,
33 const struct nft_pktinfo *pkt)35 const struct nft_pktinfo *pkt)
@@ -181,6 +183,11 @@ void nft_meta_get_eval(const struct nft_expr *expr, · 147 unmodified lines
181 *dest = sock_cgroup_classid(&sk->sk_cgrp_data);183 *dest = sock_cgroup_classid(&sk->sk_cgrp_data);
182 break;184 break;
183#endif185#endif
186 case NFT_META_PRANDOM: {
187 struct rnd_state *state = this_cpu_ptr(&nft_prandom_state);
188 *dest = prandom_u32_state(state);
189 break;
190 }
184 default:191 default:
185 WARN_ON(1);192 WARN_ON(1);
186 goto err;193 goto err;
@@ -277,6 +284,10 @@ int nft_meta_get_init(const struct nft_ctx *ctx, · 90 unmodified lines
277 case NFT_META_OIFNAME:284 case NFT_META_OIFNAME:
278 len = IFNAMSIZ;285 len = IFNAMSIZ;
279 break;286 break;
287 case NFT_META_PRANDOM:
288 prandom_init_once(&nft_prandom_state);
289 len = sizeof(u32);
290 break;
280 default:291 default:
281 return -EOPNOTSUPP;292 return -EOPNOTSUPP;
282 }293 }
net/netfilter/x_tables.c+40−25
@@ -694,12 +694,45 @@ EXPORT_SYMBOL(xt_free_table_info); · 693 unmodified lines
694struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,694struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
695 const char *name)695 const char *name)
696{696{
697 struct xt_table *t;697 struct xt_table *t, *found = NULL;
698 698
699 mutex_lock(&xt[af].mutex);699 mutex_lock(&xt[af].mutex);
700 list_for_each_entry(t, &net->xt.tables[af], list)700 list_for_each_entry(t, &net->xt.tables[af], list)
701 if (strcmp(t->name, name) == 0 && try_module_get(t->me))701 if (strcmp(t->name, name) == 0 && try_module_get(t->me))
702 return t;702 return t;
703
704 if (net == &init_net)
705 goto out;
706
707 /* Table doesn't exist in this netns, re-try init */
708 list_for_each_entry(t, &init_net.xt.tables[af], list) {
709 if (strcmp(t->name, name))
710 continue;
711 if (!try_module_get(t->me))
712 return NULL;
713
714 mutex_unlock(&xt[af].mutex);
715 if (t->table_init(net) != 0) {
716 module_put(t->me);
717 return NULL;
718 }
719
720 found = t;
721
722 mutex_lock(&xt[af].mutex);
723 break;
724 }
725
726 if (!found)
727 goto out;
728
729 /* and once again: */
730 list_for_each_entry(t, &net->xt.tables[af], list)
731 if (strcmp(t->name, name) == 0)
732 return t;
733
734 module_put(found->me);
735 out:
703 mutex_unlock(&xt[af].mutex);736 mutex_unlock(&xt[af].mutex);
704 return NULL;737 return NULL;
705}738}
@@ -1170,20 +1203,20 @@ static const struct file_operations xt_target_ops = { · 464 unmodified lines
1170#endif /* CONFIG_PROC_FS */1203#endif /* CONFIG_PROC_FS */
1171 1204
1172/**1205/**
1173 * xt_hook_link - set up hooks for a new table1206 * xt_hook_ops_alloc - set up hooks for a new table
1174 * @table: table with metadata needed to set up hooks1207 * @table: table with metadata needed to set up hooks
1175 * @fn: Hook function1208 * @fn: Hook function
1176 *1209 *
1177 * This function will take care of creating and registering the necessary1210 * This function will create the nf_hook_ops that the x_table needs
1178 * Netfilter hooks for XT tables.1211 * to hand to xt_hook_link_net().
1179 */1212 */
1180struct nf_hook_ops *xt_hook_link(const struct xt_table *table, nf_hookfn *fn)1213struct nf_hook_ops *
1214xt_hook_ops_alloc(const struct xt_table *table, nf_hookfn *fn)
1181{1215{
1182 unsigned int hook_mask = table->valid_hooks;1216 unsigned int hook_mask = table->valid_hooks;
1183 uint8_t i, num_hooks = hweight32(hook_mask);1217 uint8_t i, num_hooks = hweight32(hook_mask);
1184 uint8_t hooknum;1218 uint8_t hooknum;
1185 struct nf_hook_ops *ops;1219 struct nf_hook_ops *ops;
1186 int ret;
1187 1220
1188 ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);1221 ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
1189 if (ops == NULL)1222 if (ops == NULL)
@@ -1200,27 +1233,9 @@ struct nf_hook_ops *xt_hook_link(const struct xt_table *table, nf_hookfn *fn) · 10 unmodified lines
1200 ++i;1233 ++i;
1201 }1234 }
1202 1235
1203 ret = nf_register_hooks(ops, num_hooks);
1204 if (ret < 0) {
1205 kfree(ops);
1206 return ERR_PTR(ret);
1207 }
1208
1209 return ops;1236 return ops;
1210}1237}
1211EXPORT_SYMBOL_GPL(xt_hook_link);1238EXPORT_SYMBOL_GPL(xt_hook_ops_alloc);
1212
1213/**
1214 * xt_hook_unlink - remove hooks for a table
1215 * @ops: nf_hook_ops array as returned by nf_hook_link
1216 * @hook_mask: the very same mask that was passed to nf_hook_link
1217 */
1218void xt_hook_unlink(const struct xt_table *table, struct nf_hook_ops *ops)
1219{
1220 nf_unregister_hooks(ops, hweight32(table->valid_hooks));
1221 kfree(ops);
1222}
1223EXPORT_SYMBOL_GPL(xt_hook_unlink);
1224 1239
1225int xt_proto_init(struct net *net, u_int8_t af)1240int xt_proto_init(struct net *net, u_int8_t af)
1226{1241{
net/netfilter/xt_osf.c+0−2
@@ -262,7 +262,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p) · 261 unmodified lines
262 if (f->opt[optnum].kind == (*optp)) {262 if (f->opt[optnum].kind == (*optp)) {
263 __u32 len = f->opt[optnum].length;263 __u32 len = f->opt[optnum].length;
264 const __u8 *optend = optp + len;264 const __u8 *optend = optp + len;
265 int loop_cont = 0;
266 265
267 fmatch = FMATCH_OK;266 fmatch = FMATCH_OK;
268 267
@@ -275,7 +274,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct xt_action_param *p) · 6 unmodified lines
275 mss = ntohs((__force __be16)mss);274 mss = ntohs((__force __be16)mss);
276 break;275 break;
277 case OSFOPT_TS:276 case OSFOPT_TS:
278 loop_cont = 1;
279 break;277 break;
280 }278 }
281 279

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