netfilter updates from net-next (upcoming 3.6)
Subsystems (7)
[email protected]
maintainercover netfilter updates from net-next (upcoming 3.6)
From: Pablo Neira Ayuso <[email protected]>
Hi Davidm
The following patchset contains netfilter updates for your net-next tree. Short summary:
* Netns support for all our nf_conntrack sysctl tweaks, including global timeout adjustment from Gao Feng.
* Add fail-open support to NFQUEUE, ie. don't drop packets if the kernel-space nfqueue gets full, instead we allow packets to go through, from Krishna Kumar.
* Remove support for connlimit revision 0, as we already scheduled, from Cong Wang.
* Improve load distribution in NFQUEUE if multi-queue is used from Florian Westphal.
* Minor cleanups from Alban Crequy to use NFPROTO_* constants instead of PF_* as we do in other parts of the Netfilter code.
You can pull these changes from:
git://1984.lsi.us.es/net-next master
Thanks!
Alban Crequy (5):
netfilter: decnet: switch hook PFs to nfproto
netfilter: bridge: switch hook PFs to nfproto
netfilter: ipv4, defrag: switch hook PFs to nfproto
netfilter: ipvs: switch hook PFs to nfproto
netfilter: selinux: switch hook PFs to nfproto
Cong Wang (2):
netfilter: remove include/linux/netfilter_ipv4/ipt_addrtype.h
netfilter: xt_connlimit: remove revision 0
Denys Fedoryshchenko (1):
netfilter: xt_recent: add address masking option
Florian Westphal (1):
netfilter: NFQUEUE: don't xor src/dst ip address for load
distribution
Gao feng (14):
netfilter: nf_conntrack: prepare namespace support for l4 protocol trackers
netfilter: nf_conntrack: prepare namespace support for l3 protocol trackers
netfilter: nf_ct_generic: add namespace support
netfilter: nf_ct_tcp: add namespace support
netfilter: nf_ct_udp: add namespace support
netfilter: nf_ct_icmp: add namespace support
netfilter: nf_ct_icmp: add namespace support
netfilter: nf_ct_ipv4: add namespace support
netfilter: nf_ct_ipv6: add namespace support
netfilter: nf_ct_sctp: add namespace support
netfilter: nf_ct_udplite: add namespace support
netfilter: nf_ct_dccp: use new namespace support
netfilter: nf_ct_gre: use new namespace support
netfilter: nf_conntrack: add namespace support for cttimeout
Krishna Kumar (1):
netfilter: Add fail-open support
Pablo Neira Ayuso (1):
netfilter: nf_conntrack: remove now unused sysctl for nf_conntrack_l[3|4]proto
Documentation/feature-removal-schedule.txt | 22 +- include/linux/netfilter.h | 10 + include/linux/netfilter/nfnetlink_queue.h | 5 + include/linux/netfilter/xt_connlimit.h | 9 +- include/linux/netfilter/xt_recent.h | 10 + include/linux/netfilter_ipv4/Kbuild | 1 - include/linux/netfilter_ipv4/ipt_addrtype.h | 27 --- include/net/netfilter/nf_conntrack_core.h | 4 +- include/net/netfilter/nf_conntrack_l3proto.h | 11 +- include/net/netfilter/nf_conntrack_l4proto.h | 22 +- include/net/netns/conntrack.h | 55 +++++ net/bridge/br_netfilter.c | 28 +-- net/decnet/netfilter/dn_rtmsg.c | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 124 +++++++---- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 52 +++-- net/ipv4/netfilter/nf_defrag_ipv4.c | 4 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 88 +++++--- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 36 +++- net/netfilter/ipvs/ip_vs_core.c | 24 +-- net/netfilter/nf_conntrack_core.c | 17 +- net/netfilter/nf_conntrack_proto.c | 273 +++++++++++++++++------- net/netfilter/nf_conntrack_proto_dccp.c | 137 ++++++------ net/netfilter/nf_conntrack_proto_generic.c | 52 +++-- net/netfilter/nf_conntrack_proto_gre.c | 63 +++--- net/netfilter/nf_conntrack_proto_sctp.c | 196 +++++++++++++---- net/netfilter/nf_conntrack_proto_tcp.c | 183 ++++++++++++---- net/netfilter/nf_conntrack_proto_udp.c | 123 ++++++++--- net/netfilter/nf_conntrack_proto_udplite.c | 118 +++++++--- net/netfilter/nfnetlink_cttimeout.c | 13 +- net/netfilter/nfnetlink_queue.c | 40 +++- net/netfilter/xt_NFQUEUE.c | 28 ++- net/netfilter/xt_connlimit.c | 35 +-- net/netfilter/xt_recent.c | 62 +++++- security/selinux/hooks.c | 10 +- 34 files changed, 1300 insertions(+), 584 deletions(-) delete mode 100644 include/linux/netfilter_ipv4/ipt_addrtype.h
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 1/25 netfilter: remove include/linux/netfilter_ipv4/ipt_addrtype.h
From: Cong Wang <[email protected]>
It was scheduled to be removed.
--- Documentation/feature-removal-schedule.txt | 8 -------- include/linux/netfilter_ipv4/Kbuild | 1 - include/linux/netfilter_ipv4/ipt_addrtype.h | 27 --------------------------- 3 files changed, 36 deletions(-) delete mode 100644 include/linux/netfilter_ipv4/ipt_addrtype.h
Documentation/feature-removal-schedule.txt +0 -8
@@ -421,14 +421,6 @@ Files: net/netfilter/xt_connlimit.c ---------------------------- -What: ipt_addrtype match include file -When: 2012 -Why: superseded by xt_addrtype -Who: Florian Westphal <[email protected]> -Files: include/linux/netfilter_ipv4/ipt_addrtype.h - ----------------------------- - What: i2c_driver.attach_adapter i2c_driver.detach_adapter When: September 2011
include/linux/netfilter_ipv4/Kbuild +0 -1
@@ -5,7 +5,6 @@ header-y += ipt_LOG.h header-y += ipt_REJECT.h header-y += ipt_TTL.h header-y += ipt_ULOG.h -header-y += ipt_addrtype.h header-y += ipt_ah.h header-y += ipt_ecn.h header-y += ipt_ttl.h
include/linux/netfilter_ipv4/ipt_addrtype.h deleted +0 -27
@@ -1,27 +0,0 @@ -#ifndef _IPT_ADDRTYPE_H -#define _IPT_ADDRTYPE_H - -#include <linux/types.h> - -enum { -IPT_ADDRTYPE_INVERT_SOURCE =0x0001 , -IPT_ADDRTYPE_INVERT_DEST =0x0002 , -IPT_ADDRTYPE_LIMIT_IFACE_IN =0x0004 , -IPT_ADDRTYPE_LIMIT_IFACE_OUT =0x0008 , -}; - -struct ipt_addrtype_info_v1 { -__u16 source;/* source-type mask */ -__u16 dest;/* dest-type mask */ -__u32 flags; -}; - -/* revision 0 */ -struct ipt_addrtype_info { -__u16 source;/* source-type mask */ -__u16 dest;/* dest-type mask */ -__u32 invert_source; -__u32 invert_dest; -}; - -#endif
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 2/25 netfilter: xt_connlimit: remove revision 0
In reply to [email protected]From: Cong Wang <[email protected]>
It was scheduled to be removed.
--- Documentation/feature-removal-schedule.txt | 7 ------ include/linux/netfilter/xt_connlimit.h | 9 ++----- net/netfilter/xt_connlimit.c | 35 +++++++++------------------- 3 files changed, 13 insertions(+), 38 deletions(-)
Documentation/feature-removal-schedule.txt +0 -7
@@ -414,13 +414,6 @@ Who: Jean Delvare <[email protected]> ---------------------------- -What: xt_connlimit rev 0 -When: 2012 -Who: Jan Engelhardt <[email protected]> -Files: net/netfilter/xt_connlimit.c - ----------------------------- - What: i2c_driver.attach_adapter i2c_driver.detach_adapter When: September 2011
include/linux/netfilter/xt_connlimit.h +2 -7
@@ -22,13 +22,8 @@ struct xt_connlimit_info {#endif };unsigned int limit; -union { -/* revision 0 */ -unsigned int inverse; - -/* revision 1 */ -__u32 flags; - }; +/* revision 1 */ +__u32 flags;/* Used internally by the kernel */ struct xt_connlimit_data *data __attribute__((aligned(8)));
net/netfilter/xt_connlimit.c +11 -24
@@ -274,38 +274,25 @@ static void connlimit_mt_destroy(const struct xt_mtdtor_param *par)kfree (info->data); } -static struct xt_match connlimit_mt_reg[]__read_mostly = { - { - .name ="connlimit" , - .revision =0 , - .family =NFPROTO_UNSPEC , - .checkentry = connlimit_mt_check, - .match = connlimit_mt, - .matchsize =sizeof (struct xt_connlimit_info ), - .destroy = connlimit_mt_destroy, - .me =THIS_MODULE , - }, - { - .name ="connlimit" , - .revision =1 , - .family =NFPROTO_UNSPEC , - .checkentry = connlimit_mt_check, - .match = connlimit_mt, - .matchsize =sizeof (struct xt_connlimit_info ), - .destroy = connlimit_mt_destroy, - .me =THIS_MODULE , - }, +static struct xt_match connlimit_mt_reg__read_mostly = { + .name ="connlimit" , + .revision =1 , + .family =NFPROTO_UNSPEC , + .checkentry = connlimit_mt_check, + .match = connlimit_mt, + .matchsize =sizeof (struct xt_connlimit_info ), + .destroy = connlimit_mt_destroy, + .me =THIS_MODULE , };static int __init connlimit_mt_init (void ) { -return xt_register_matches (connlimit_mt_reg, -ARRAY_SIZE (connlimit_mt_reg)); +return xt_register_match (&connlimit_mt_reg); } static void __exit connlimit_mt_exit(void) { -xt_unregister_matches (connlimit_mt_reg,ARRAY_SIZE (connlimit_mt_reg)); +xt_unregister_match (&connlimit_mt_reg); }module_init (connlimit_mt_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 3/25 netfilter: Add fail-open support
In reply to [email protected]From: Krishna Kumar <[email protected]>
Implement a new "fail-open" mode where packets are not dropped upon queue-full condition. This mode can be enabled/disabled per queue using netlink NFQA_CFG_FLAGS & NFQA_CFG_MASK attributes.
--- include/linux/netfilter/nfnetlink_queue.h | 5 ++++ net/netfilter/nfnetlink_queue.c | 40 ++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-)
include/linux/netfilter/nfnetlink_queue.h +5 -0
@@ -84,8 +84,13 @@ enum nfqnl_attr_config {NFQA_CFG_CMD ,/* nfqnl_msg_config_cmd */ NFQA_CFG_PARAMS ,/* nfqnl_msg_config_params */ NFQA_CFG_QUEUE_MAXLEN ,/* __u32 */ +NFQA_CFG_MASK ,/* identify which flags to change */ +NFQA_CFG_FLAGS ,/* value of these flags (__u32) */ __NFQA_CFG_MAX };#define NFQA_CFG_MAX (__NFQA_CFG_MAX-1) +/* Flags for NFQA_CFG_FLAGS */ +#define NFQA_CFG_F_FAIL_OPEN (1 << 0) +#endif /* _NFNETLINK_QUEUE_H */
net/netfilter/nfnetlink_queue.c +37 -3
@@ -52,6 +52,7 @@ struct nfqnl_instance {u_int16_t queue_num;/* number of this queue */ u_int8_t copy_mode; +u_int32_t flags;/* Set using NFQA_CFG_FLAGS */ /* * Following fields are dirtied for each queued packet, * keep them in same cache line if possible.
@@ -406,6 +407,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)struct nfqnl_instance *queue;int err = -ENOBUFS ;__be32 *packet_id_ptr; +int failopen =0 ;/* rcu_read_lock()ed by nf_hook_slow() */ queue =instance_lookup (queuenum);
@@ -431,9 +433,14 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) goto err_out_free_nskb; }if (queue->queue_total >= queue->queue_maxlen) { - queue->queue_dropped++; -net_warn_ratelimited ("nf_queue: full at %d entries, dropping packets(s)\n" , - queue->queue_total); +if (queue->flags &NFQA_CFG_F_FAIL_OPEN ) { + failopen =1 ; + err =0 ; + }else { + queue->queue_dropped++; +net_warn_ratelimited ("nf_queue: full at %d entries, dropping packets(s)\n" , + queue->queue_total); + } goto err_out_free_nskb; } entry->id = ++queue->id_sequence;
@@ -455,6 +462,8 @@ err_out_free_nskb:kfree_skb (nskb); err_out_unlock:spin_unlock_bh (&queue->lock); +if (failopen) +nf_reinject (entry,NF_ACCEPT ); err_out:return err; }
@@ -858,6 +867,31 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,spin_unlock_bh (&queue->lock); } +if (nfqa[NFQA_CFG_FLAGS ]) { +__u32 flags, mask; + +if (!queue) { + ret = -ENODEV ; + goto err_out_unlock; + } + +if (!nfqa[NFQA_CFG_MASK ]) { +/* A mask is needed to specify which flags are being +* changed. +*/ + ret = -EINVAL ; + goto err_out_unlock; + } + + flags =ntohl (nla_get_be32 (nfqa[NFQA_CFG_FLAGS ])); + mask =ntohl (nla_get_be32 (nfqa[NFQA_CFG_MASK ])); + +spin_lock_bh (&queue->lock); + queue->flags &= ~mask; + queue->flags |= flags & mask; +spin_unlock_bh (&queue->lock); + } + err_out_unlock:rcu_read_unlock ();return ret;
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 4/25 netfilter: nf_conntrack: prepare namespace support for l4 protocol trackers
In reply to [email protected]From: Gao feng <[email protected]>
This patch prepares the namespace support for layer 4 protocol trackers. Basically, this modifies the following interfaces:
* nf_ct_[un]register_sysctl
* nf_conntrack_l4proto_[un]register
to include the namespace parameter. We still use init_net in this patch to prepare the ground for follow-up patches for each layer 4 protocol tracker.
We add a new net_id field to struct nf_conntrack_l4proto that is used to store the pernet_operations id for each layer 4 protocol tracker.
Note that AF_INET6's protocols do not need to do sysctl compat. Thus, we only register compat sysctl when l4proto.l3proto != AF_INET6.
--- include/net/netfilter/nf_conntrack_l4proto.h | 11 +- include/net/netns/conntrack.h | 12 ++ net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 18 +-- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 18 +-- net/netfilter/nf_conntrack_proto.c | 143 +++++++++++++++++------- net/netfilter/nf_conntrack_proto_dccp.c | 10 +- net/netfilter/nf_conntrack_proto_gre.c | 6 +- net/netfilter/nf_conntrack_proto_sctp.c | 10 +- net/netfilter/nf_conntrack_proto_udplite.c | 10 +- 9 files changed, 159 insertions(+), 79 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +9 -2
@@ -12,6 +12,7 @@#include <linux/netlink.h> #include <net/netlink.h> #include <net/netfilter/nf_conntrack.h> +#include <net/netns/generic.h> struct seq_file ;
@@ -103,6 +104,10 @@ struct nf_conntrack_l4proto {struct ctl_table *ctl_compat_table;#endif #endif +int *net_id; +/* Init l4proto pernet data */ +int (*init_net)(struct net *net); +/* Protocol name */ const char *name;
@@ -123,8 +128,10 @@ nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t l4proto);extern void nf_ct_l4proto_put (struct nf_conntrack_l4proto *p);/* Protocol registration. */ -extern int nf_conntrack_l4proto_register (struct nf_conntrack_l4proto *proto); -extern void nf_conntrack_l4proto_unregister (struct nf_conntrack_l4proto *proto); +extern int nf_conntrack_l4proto_register (struct net *net, +struct nf_conntrack_l4proto *proto); +extern void nf_conntrack_l4proto_unregister (struct net *net, +struct nf_conntrack_l4proto *proto);/* Generic netlink helpers */ extern int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
include/net/netns/conntrack.h +12 -0
@@ -8,6 +8,18 @@struct ctl_table_header ;struct nf_conntrack_ecache ; +struct nf_proto_net { +#ifdef CONFIG_SYSCTL +struct ctl_table_header *ctl_table_header; +struct ctl_table *ctl_table; +#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT +struct ctl_table_header *ctl_compat_header; +struct ctl_table *ctl_compat_table; +#endif +#endif +unsigned int users; +}; +struct netns_ct {atomic_t count;unsigned int expect_count;
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +9 -9
@@ -391,19 +391,19 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)return ret; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_tcp4); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_tcp4);if (ret <0 ) {pr_err ("nf_conntrack_ipv4: can't register tcp.\n" ); goto cleanup_sockopt; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_udp4); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udp4);if (ret <0 ) {pr_err ("nf_conntrack_ipv4: can't register udp.\n" ); goto cleanup_tcp; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_icmp); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_icmp);if (ret <0 ) {pr_err ("nf_conntrack_ipv4: can't register icmp.\n" ); goto cleanup_udp;
@@ -434,11 +434,11 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) cleanup_ipv4:nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv4); cleanup_icmp: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_icmp); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp); cleanup_udp: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp4); cleanup_tcp: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_tcp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp4); cleanup_sockopt:nf_unregister_sockopt (&so_getorigdst);return ret;
@@ -452,9 +452,9 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void)#endif nf_unregister_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops));nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv4); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_icmp); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udp4); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_tcp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp4);nf_unregister_sockopt (&so_getorigdst); }
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +9 -9
@@ -340,19 +340,19 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)need_conntrack ();nf_defrag_ipv6_enable (); - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_tcp6); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_tcp6);if (ret <0 ) {pr_err ("nf_conntrack_ipv6: can't register tcp.\n" );return ret; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_udp6); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udp6);if (ret <0 ) {pr_err ("nf_conntrack_ipv6: can't register udp.\n" ); goto cleanup_tcp; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_icmpv6); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_icmpv6);if (ret <0 ) {pr_err ("nf_conntrack_ipv6: can't register icmpv6.\n" ); goto cleanup_udp;
@@ -376,11 +376,11 @@ static int __init nf_conntrack_l3proto_ipv6_init(void) cleanup_ipv6:nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv6); cleanup_icmpv6: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_icmpv6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6); cleanup_udp: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udp6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp6); cleanup_tcp: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_tcp6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp6);return ret; }
@@ -389,9 +389,9 @@ static void __exit nf_conntrack_l3proto_ipv6_fini(void)synchronize_net ();nf_unregister_hooks (ipv6_conntrack_ops,ARRAY_SIZE (ipv6_conntrack_ops));nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv6); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_icmpv6); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udp6); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_tcp6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp6); }module_init (nf_conntrack_l3proto_ipv6_init);
net/netfilter/nf_conntrack_proto.c +102 -41
254 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_dccp.c +5 -5
@@ -945,17 +945,17 @@ static int __init nf_conntrack_proto_dccp_init(void)if (err <0 ) goto err1; - err =nf_conntrack_l4proto_register (&dccp_proto4); + err =nf_conntrack_l4proto_register (&init_net, &dccp_proto4);if (err <0 ) goto err2; - err =nf_conntrack_l4proto_register (&dccp_proto6); + err =nf_conntrack_l4proto_register (&init_net, &dccp_proto6);if (err <0 ) goto err3;return 0 ; err3: -nf_conntrack_l4proto_unregister (&dccp_proto4); +nf_conntrack_l4proto_unregister (&init_net, &dccp_proto4); err2:unregister_pernet_subsys (&dccp_net_ops); err1:
@@ -965,8 +965,8 @@ err1: static void __exit nf_conntrack_proto_dccp_fini(void) {unregister_pernet_subsys (&dccp_net_ops); -nf_conntrack_l4proto_unregister (&dccp_proto6); -nf_conntrack_l4proto_unregister (&dccp_proto4); +nf_conntrack_l4proto_unregister (&init_net, &dccp_proto6); +nf_conntrack_l4proto_unregister (&init_net, &dccp_proto4); }module_init (nf_conntrack_proto_dccp_init);
net/netfilter/nf_conntrack_proto_gre.c +3 -3
@@ -396,18 +396,18 @@ static int __init nf_ct_proto_gre_init(void) {int rv; - rv =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_gre4); + rv =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_gre4);if (rv <0 )return rv; rv =register_pernet_subsys (&proto_gre_net_ops);if (rv <0 ) -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_gre4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_gre4);return rv; } static void __exit nf_ct_proto_gre_fini(void) { -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_gre4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_gre4);unregister_pernet_subsys (&proto_gre_net_ops); }
net/netfilter/nf_conntrack_proto_sctp.c +5 -5
@@ -791,12 +791,12 @@ static int __init nf_conntrack_proto_sctp_init(void) {int ret; - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_sctp4); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_sctp4);if (ret) {pr_err ("nf_conntrack_l4proto_sctp4: protocol register failed\n" ); goto out; } - ret =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_sctp6); + ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_sctp6);if (ret) {pr_err ("nf_conntrack_l4proto_sctp6: protocol register failed\n" ); goto cleanup_sctp4;
@@ -805,15 +805,15 @@ static int __init nf_conntrack_proto_sctp_init(void)return ret; cleanup_sctp4: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_sctp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp4); out:return ret; } static void __exit nf_conntrack_proto_sctp_fini(void) { -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_sctp6); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_sctp4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp4); }module_init (nf_conntrack_proto_sctp_init);
net/netfilter/nf_conntrack_proto_udplite.c +5 -5
@@ -299,23 +299,23 @@ static int __init nf_conntrack_proto_udplite_init(void) {int err; - err =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_udplite4); + err =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udplite4);if (err <0 ) goto err1; - err =nf_conntrack_l4proto_register (&nf_conntrack_l4proto_udplite6); + err =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udplite6);if (err <0 ) goto err2;return 0 ; err2: -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udplite4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite4); err1:return err; } static void __exit nf_conntrack_proto_udplite_exit(void) { -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udplite6); -nf_conntrack_l4proto_unregister (&nf_conntrack_l4proto_udplite4); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite6); +nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite4); }module_init (nf_conntrack_proto_udplite_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 5/25 netfilter: nf_conntrack: prepare namespace support for l3 protocol trackers
In reply to [email protected]From: Gao feng <[email protected]>
This patch prepares the namespace support for layer 3 protocol trackers. Basically, this modifies the following interfaces:
* nf_ct_l3proto_[un]register_sysctl.
* nf_conntrack_l3proto_[un]register.
We add a new nf_ct_l3proto_net is used to get the pernet data of l3proto.
This adds rhe new struct nf_ip_net that is used to store the sysctl header and l3proto_ipv4,l4proto_tcp(6),l4proto_udp(6),l4proto_icmp(v6) because the protos such tcp and tcp6 use the same data,so making nf_ip_net as a field of netns_ct is the easiest way to manager it.
This patch also adds init_net to struct nf_conntrack_l3proto to initial the layer 3 protocol pernet data.
--- include/net/netfilter/nf_conntrack_l3proto.h | 9 ++- include/net/netns/conntrack.h | 8 +++ net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 6 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 6 +- net/netfilter/nf_conntrack_proto.c | 92 ++++++++++++++++++------ 5 files changed, 91 insertions(+), 30 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +7 -2
@@ -69,6 +69,9 @@ struct nf_conntrack_l3proto {struct ctl_table *ctl_table;#endif /* CONFIG_SYSCTL */ +/* Init l3proto pernet data */ +int (*init_net)(struct net *net); +/* Module (if any) which this is connected to. */ struct module *me; };
@@ -76,8 +79,10 @@ struct nf_conntrack_l3proto {extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[AF_MAX ];/* Protocol registration. */ -extern int nf_conntrack_l3proto_register (struct nf_conntrack_l3proto *proto); -extern void nf_conntrack_l3proto_unregister (struct nf_conntrack_l3proto *proto); +extern int nf_conntrack_l3proto_register (struct net *net, +struct nf_conntrack_l3proto *proto); +extern void nf_conntrack_l3proto_unregister (struct net *net, +struct nf_conntrack_l3proto *proto);extern struct nf_conntrack_l3proto *nf_ct_l3proto_find_get (u_int16_t l3proto);extern void nf_ct_l3proto_put (struct nf_conntrack_l3proto *p);
include/net/netns/conntrack.h +8 -0
@@ -20,6 +20,13 @@ struct nf_proto_net {unsigned int users; }; +struct nf_ip_net { +#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT ) +struct ctl_table_header *ctl_table_header; +struct ctl_table *ctl_table; +#endif +}; +struct netns_ct {atomic_t count;unsigned int expect_count;
@@ -40,6 +47,7 @@ struct netns_ct {unsigned int sysctl_log_invalid;/* Log invalid packets */ int sysctl_auto_assign_helper;bool auto_assign_helper_warned; +struct nf_ip_net nf_ct_proto;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_header;struct ctl_table_header *acct_sysctl_header;
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +3 -3
@@ -409,7 +409,7 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) goto cleanup_udp; } - ret =nf_conntrack_l3proto_register (&nf_conntrack_l3proto_ipv4); + ret =nf_conntrack_l3proto_register (&init_net, &nf_conntrack_l3proto_ipv4);if (ret <0 ) {pr_err ("nf_conntrack_ipv4: can't register ipv4\n" ); goto cleanup_icmp;
@@ -432,7 +432,7 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)nf_unregister_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops));#endif cleanup_ipv4: -nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv4); +nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv4); cleanup_icmp:nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp); cleanup_udp:
@@ -451,7 +451,7 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void)nf_conntrack_ipv4_compat_fini ();#endif nf_unregister_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops)); -nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv4); +nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv4);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp4);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp4);
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +3 -3
@@ -358,7 +358,7 @@ static int __init nf_conntrack_l3proto_ipv6_init(void) goto cleanup_udp; } - ret =nf_conntrack_l3proto_register (&nf_conntrack_l3proto_ipv6); + ret =nf_conntrack_l3proto_register (&init_net, &nf_conntrack_l3proto_ipv6);if (ret <0 ) {pr_err ("nf_conntrack_ipv6: can't register ipv6\n" ); goto cleanup_icmpv6;
@@ -374,7 +374,7 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)return ret; cleanup_ipv6: -nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv6); +nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv6); cleanup_icmpv6:nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6); cleanup_udp:
@@ -388,7 +388,7 @@ static void __exit nf_conntrack_l3proto_ipv6_fini(void) {synchronize_net ();nf_unregister_hooks (ipv6_conntrack_ops,ARRAY_SIZE (ipv6_conntrack_ops)); -nf_conntrack_l3proto_unregister (&nf_conntrack_l3proto_ipv6); +nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv6);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp6);nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp6);
net/netfilter/nf_conntrack_proto.c +70 -22
139 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 6/25 netfilter: nf_ct_generic: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for the generic layer 4 protocol tracker.
--- include/net/netfilter/nf_conntrack_core.h | 4 +-- include/net/netns/conntrack.h | 6 ++++ net/netfilter/nf_conntrack_core.c | 17 ++++------ net/netfilter/nf_conntrack_proto.c | 46 ++++++++++++++++++---------- net/netfilter/nf_conntrack_proto_generic.c | 38 +++++++++++++++++++++-- 5 files changed, 78 insertions(+), 33 deletions(-)
include/net/netfilter/nf_conntrack_core.h +2 -2
@@ -28,8 +28,8 @@ extern unsigned int nf_conntrack_in(struct net *net,extern int nf_conntrack_init (struct net *net);extern void nf_conntrack_cleanup (struct net *net); -extern int nf_conntrack_proto_init (void ); -extern void nf_conntrack_proto_fini (void ); +extern int nf_conntrack_proto_init (struct net *net); +extern void nf_conntrack_proto_fini (struct net *net); extern bool nf_ct_get_tuple(const struct sk_buff *skb,
include/net/netns/conntrack.h +6 -0
@@ -20,7 +20,13 @@ struct nf_proto_net {unsigned int users; }; +struct nf_generic_net { +struct nf_proto_net pn; +unsigned int timeout; +}; +struct nf_ip_net { +struct nf_generic_net generic;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )struct ctl_table_header *ctl_table_header;struct ctl_table *ctl_table;
net/netfilter/nf_conntrack_core.c +6 -11
@@ -1333,7 +1333,6 @@ static void nf_conntrack_cleanup_init_net(void)while (untrack_refs () >0 )schedule (); -nf_conntrack_proto_fini ();#ifdef CONFIG_NF_CONNTRACK_ZONES nf_ct_extend_unregister (&nf_ct_zone_extend);#endif
@@ -1372,7 +1371,7 @@ void nf_conntrack_cleanup(struct net *net)netfilter framework. Roll on, two-stage module delete... */ synchronize_net (); - +nf_conntrack_proto_fini (net);nf_conntrack_cleanup_net (net);if (net_eq (net, &init_net)) {
@@ -1496,11 +1495,6 @@ static int nf_conntrack_init_init_net(void)printk (KERN_INFO "nf_conntrack version %s (%u buckets, %d max)\n" ,NF_CONNTRACK_VERSION , nf_conntrack_htable_size, nf_conntrack_max); - - ret =nf_conntrack_proto_init (); -if (ret <0 ) - goto err_proto; -#ifdef CONFIG_NF_CONNTRACK_ZONES ret =nf_ct_extend_register (&nf_ct_zone_extend);if (ret <0 )
@@ -1518,9 +1512,7 @@ static int nf_conntrack_init_init_net(void)#ifdef CONFIG_NF_CONNTRACK_ZONES err_extend: -nf_conntrack_proto_fini ();#endif -err_proto:return ret; }
@@ -1583,9 +1575,7 @@ static int nf_conntrack_init_net(struct net *net) ret =nf_conntrack_helper_init (net);if (ret <0 ) goto err_helper; -return 0 ; - err_helper:nf_conntrack_timeout_fini (net); err_timeout:
@@ -1622,6 +1612,9 @@ int nf_conntrack_init(struct net *net)if (ret <0 ) goto out_init_net; } + ret =nf_conntrack_proto_init (net); +if (ret <0 ) + goto out_proto; ret =nf_conntrack_init_net (net);if (ret <0 ) goto out_net;
@@ -1637,6 +1630,8 @@ int nf_conntrack_init(struct net *net)return 0 ; out_net: +nf_conntrack_proto_fini (net); +out_proto:if (net_eq (net, &init_net))nf_conntrack_cleanup_init_net (); out_init_net:
net/netfilter/nf_conntrack_proto.c +29 -17
67 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_generic.c +35 -3
@@ -14,6 +14,11 @@static unsigned int nf_ct_generic_timeout__read_mostly =600 *HZ ; +static inline struct nf_generic_net *generic_pernet (struct net *net) +{ +return &net->ct.nf_ct_proto.generic; +} +static bool generic_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff,struct nf_conntrack_tuple *tuple)
@@ -42,7 +47,7 @@ static int generic_print_tuple(struct seq_file *s,static unsigned int *generic_get_timeouts (struct net *net) { -return &nf_ct_generic_timeout; +return &(generic_pernet (net)->timeout); }/* Returns verdict for packet, or -1 for invalid. */
@@ -110,7 +115,6 @@ static struct ctl_table_header *generic_sysctl_header;static struct ctl_table generic_sysctl_table[] = { { .procname ="nf_conntrack_generic_timeout" , - .data = &nf_ct_generic_timeout, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -121,7 +125,6 @@ static struct ctl_table generic_sysctl_table[] = {static struct ctl_table generic_compat_sysctl_table[] = { { .procname ="ip_conntrack_generic_timeout" , - .data = &nf_ct_generic_timeout, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -131,6 +134,34 @@ static struct ctl_table generic_compat_sysctl_table[] = {#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ #endif /* CONFIG_SYSCTL */ +static int generic_init_net (struct net *net) +{ +struct nf_generic_net *gn =generic_pernet (net); +struct nf_proto_net *pn = (struct nf_proto_net *)gn; + gn->timeout = nf_ct_generic_timeout; +#ifdef CONFIG_SYSCTL + pn->ctl_table =kmemdup (generic_sysctl_table, +sizeof (generic_sysctl_table), +GFP_KERNEL ); +if (!pn->ctl_table) +return -ENOMEM ; + pn->ctl_table[0 ].data = &gn->timeout; + +#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT + pn->ctl_compat_table =kmemdup (generic_compat_sysctl_table, +sizeof (generic_compat_sysctl_table), +GFP_KERNEL ); +if (!pn->ctl_compat_table) { +kfree (pn->ctl_table); + pn->ctl_table =NULL ; +return -ENOMEM ; + } + pn->ctl_compat_table[0 ].data = &gn->timeout; +#endif +#endif +return 0 ; +} +struct nf_conntrack_l4proto nf_conntrack_l4proto_generic__read_mostly = { .l3proto =PF_UNSPEC ,
@@ -158,4 +189,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly = .ctl_compat_table = generic_compat_sysctl_table,#endif #endif + .init_net = generic_init_net, };
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 7/25 netfilter: nf_ct_tcp: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for TCP protocol tracker.
--- include/net/netns/conntrack.h | 10 ++ net/netfilter/nf_conntrack_proto.c | 2 + net/netfilter/nf_conntrack_proto_tcp.c | 162 ++++++++++++++++++++++++++------ 3 files changed, 145 insertions(+), 29 deletions(-)
include/net/netns/conntrack.h +10 -0
@@ -4,6 +4,7 @@#include <linux/list.h> #include <linux/list_nulls.h> #include <linux/atomic.h> +#include <linux/netfilter/nf_conntrack_tcp.h> struct ctl_table_header ;struct nf_conntrack_ecache ;
@@ -25,8 +26,17 @@ struct nf_generic_net {unsigned int timeout; }; +struct nf_tcp_net { +struct nf_proto_net pn; +unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX ]; +unsigned int tcp_loose; +unsigned int tcp_be_liberal; +unsigned int tcp_max_retrans; +}; +struct nf_ip_net {struct nf_generic_net generic; +struct nf_tcp_net tcp;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )struct ctl_table_header *ctl_table_header;struct ctl_table *ctl_table;
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -303,6 +303,8 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, struct nf_conntrack_l4proto *l4proto) {switch (l4proto->l4proto) { +case IPPROTO_TCP : +return (struct nf_proto_net *)&net->ct.nf_ct_proto.tcp;case 255 :/* l4proto_generic */ return (struct nf_proto_net *)&net->ct.nf_ct_proto.generic;default :
net/netfilter/nf_conntrack_proto_tcp.c +133 -29
377 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 8/25 netfilter: nf_ct_udp: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for UDP protocol tracker.
--- include/net/netns/conntrack.h | 12 ++++ net/netfilter/nf_conntrack_proto.c | 2 + net/netfilter/nf_conntrack_proto_udp.c | 100 ++++++++++++++++++++++++++++---- 3 files changed, 103 insertions(+), 11 deletions(-)
include/net/netns/conntrack.h +12 -0
@@ -34,9 +34,21 @@ struct nf_tcp_net {unsigned int tcp_max_retrans; }; +enum udp_conntrack { +UDP_CT_UNREPLIED , +UDP_CT_REPLIED , +UDP_CT_MAX +}; + +struct nf_udp_net { +struct nf_proto_net pn; +unsigned int timeouts[UDP_CT_MAX ]; +}; +struct nf_ip_net {struct nf_generic_net generic;struct nf_tcp_net tcp; +struct nf_udp_net udp;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )struct ctl_table_header *ctl_table_header;struct ctl_table *ctl_table;
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -305,6 +305,8 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,switch (l4proto->l4proto) {case IPPROTO_TCP :return (struct nf_proto_net *)&net->ct.nf_ct_proto.tcp; +case IPPROTO_UDP : +return (struct nf_proto_net *)&net->ct.nf_ct_proto.udp;case 255 :/* l4proto_generic */ return (struct nf_proto_net *)&net->ct.nf_ct_proto.generic;default :
net/netfilter/nf_conntrack_proto_udp.c +89 -11
158 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 9/25 netfilter: nf_ct_icmp: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for ICMP protocol tracker.
--- include/net/netns/conntrack.h | 6 ++++ net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 38 ++++++++++++++++++++++++-- net/netfilter/nf_conntrack_proto.c | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-)
include/net/netns/conntrack.h +6 -0
@@ -45,10 +45,16 @@ struct nf_udp_net {unsigned int timeouts[UDP_CT_MAX ]; }; +struct nf_icmp_net { +struct nf_proto_net pn; +unsigned int timeout; +}; +struct nf_ip_net {struct nf_generic_net generic;struct nf_tcp_net tcp;struct nf_udp_net udp; +struct nf_icmp_net icmp;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )struct ctl_table_header *ctl_table_header;struct ctl_table *ctl_table;
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +35 -3
@@ -23,6 +23,11 @@static unsigned int nf_ct_icmp_timeout__read_mostly =30 *HZ ; +static inline struct nf_icmp_net *icmp_pernet (struct net *net) +{ +return &net->ct.nf_ct_proto.icmp; +} +static bool icmp_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff,struct nf_conntrack_tuple *tuple) {
@@ -77,7 +82,7 @@ static int icmp_print_tuple(struct seq_file *s,static unsigned int *icmp_get_timeouts (struct net *net) { -return &nf_ct_icmp_timeout; +return &icmp_pernet (net)->timeout; }/* Returns verdict for packet, or -1 for invalid. */
@@ -312,7 +317,6 @@ static struct ctl_table_header *icmp_sysctl_header;static struct ctl_table icmp_sysctl_table[] = { { .procname ="nf_conntrack_icmp_timeout" , - .data = &nf_ct_icmp_timeout, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -323,7 +327,6 @@ static struct ctl_table icmp_sysctl_table[] = {static struct ctl_table icmp_compat_sysctl_table[] = { { .procname ="ip_conntrack_icmp_timeout" , - .data = &nf_ct_icmp_timeout, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -333,6 +336,34 @@ static struct ctl_table icmp_compat_sysctl_table[] = {#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ #endif /* CONFIG_SYSCTL */ +static int icmp_init_net (struct net *net) +{ +struct nf_icmp_net *in =icmp_pernet (net); +struct nf_proto_net *pn = (struct nf_proto_net *)in; + in->timeout = nf_ct_icmp_timeout; + +#ifdef CONFIG_SYSCTL + pn->ctl_table =kmemdup (icmp_sysctl_table, +sizeof (icmp_sysctl_table), +GFP_KERNEL ); +if (!pn->ctl_table) +return -ENOMEM ; + pn->ctl_table[0 ].data = &in->timeout; +#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT + pn->ctl_compat_table =kmemdup (icmp_compat_sysctl_table, +sizeof (icmp_compat_sysctl_table), +GFP_KERNEL ); +if (!pn->ctl_compat_table) { +kfree (pn->ctl_table); + pn->ctl_table =NULL ; +return -ENOMEM ; + } + pn->ctl_compat_table[0 ].data = &in->timeout; +#endif +#endif +return 0 ; +} +struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp__read_mostly = { .l3proto =PF_INET ,
@@ -369,4 +400,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp __read_mostly = .ctl_compat_table = icmp_compat_sysctl_table,#endif #endif + .init_net = icmp_init_net, };
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -307,6 +307,8 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,return (struct nf_proto_net *)&net->ct.nf_ct_proto.tcp;case IPPROTO_UDP :return (struct nf_proto_net *)&net->ct.nf_ct_proto.udp; +case IPPROTO_ICMP : +return (struct nf_proto_net *)&net->ct.nf_ct_proto.icmp;case 255 :/* l4proto_generic */ return (struct nf_proto_net *)&net->ct.nf_ct_proto.generic;default :
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 10/25 netfilter: nf_ct_icmp: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for ICMPv6 protocol tracker.
--- include/net/netns/conntrack.h | 1 + net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 25 ++++++++++++++++++++++-- net/netfilter/nf_conntrack_proto.c | 2 ++ 3 files changed, 26 insertions(+), 2 deletions(-)
include/net/netns/conntrack.h +1 -0
@@ -55,6 +55,7 @@ struct nf_ip_net {struct nf_tcp_net tcp;struct nf_udp_net udp;struct nf_icmp_net icmp; +struct nf_icmp_net icmpv6;#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )struct ctl_table_header *ctl_table_header;struct ctl_table *ctl_table;
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +23 -2
@@ -29,6 +29,11 @@static unsigned int nf_ct_icmpv6_timeout__read_mostly =30 *HZ ; +static inline struct nf_icmp_net *icmpv6_pernet (struct net *net) +{ +return &net->ct.nf_ct_proto.icmpv6; +} +static bool icmpv6_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff,struct nf_conntrack_tuple *tuple)
@@ -90,7 +95,7 @@ static int icmpv6_print_tuple(struct seq_file *s,static unsigned int *icmpv6_get_timeouts (struct net *net) { -return &nf_ct_icmpv6_timeout; +return &icmpv6_pernet (net)->timeout; }/* Returns verdict for packet, or -1 for invalid. */
@@ -319,7 +324,6 @@ static struct ctl_table_header *icmpv6_sysctl_header;static struct ctl_table icmpv6_sysctl_table[] = { { .procname ="nf_conntrack_icmpv6_timeout" , - .data = &nf_ct_icmpv6_timeout, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -328,6 +332,22 @@ static struct ctl_table icmpv6_sysctl_table[] = { };#endif /* CONFIG_SYSCTL */ +static int icmpv6_init_net (struct net *net) +{ +struct nf_icmp_net *in =icmpv6_pernet (net); +struct nf_proto_net *pn = (struct nf_proto_net *)in; + in->timeout = nf_ct_icmpv6_timeout; +#ifdef CONFIG_SYSCTL + pn->ctl_table =kmemdup (icmpv6_sysctl_table, +sizeof (icmpv6_sysctl_table), +GFP_KERNEL ); +if (!pn->ctl_table) +return -ENOMEM ; + pn->ctl_table[0 ].data = &in->timeout; +#endif +return 0 ; +} +struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6__read_mostly = { .l3proto =PF_INET6 ,
@@ -359,4 +379,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly = .ctl_table_header = &icmpv6_sysctl_header, .ctl_table = icmpv6_sysctl_table, #endif + .init_net = icmpv6_init_net, };
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -309,6 +309,8 @@ static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,return (struct nf_proto_net *)&net->ct.nf_ct_proto.udp;case IPPROTO_ICMP :return (struct nf_proto_net *)&net->ct.nf_ct_proto.icmp; +case IPPROTO_ICMPV6 : +return (struct nf_proto_net *)&net->ct.nf_ct_proto.icmpv6;case 255 :/* l4proto_generic */ return (struct nf_proto_net *)&net->ct.nf_ct_proto.generic;default :
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 11/25 netfilter: nf_ct_ipv4: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for IPv4 protocol tracker.
--- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 123 ++++++++++++++++-------- 1 file changed, 85 insertions(+), 38 deletions(-)
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +85 -38
@@ -207,35 +207,30 @@ static int log_invalid_proto_max = 255;static ctl_table ip_ct_sysctl_table[] = { { .procname ="ip_conntrack_max" , - .data = &nf_conntrack_max, .maxlen =sizeof (int ), .mode =0644 , .proc_handler = proc_dointvec, }, { .procname ="ip_conntrack_count" , - .data = &init_net.ct.count, .maxlen =sizeof (int ), .mode =0444 , .proc_handler = proc_dointvec, }, { .procname ="ip_conntrack_buckets" , - .data = &init_net.ct.htable_size, .maxlen =sizeof (unsigned int ), .mode =0444 , .proc_handler = proc_dointvec, }, { .procname ="ip_conntrack_checksum" , - .data = &init_net.ct.sysctl_checksum, .maxlen =sizeof (int ), .mode =0644 , .proc_handler = proc_dointvec, }, { .procname ="ip_conntrack_log_invalid" , - .data = &init_net.ct.sysctl_log_invalid, .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_minmax,
@@ -351,6 +346,25 @@ static struct nf_sockopt_ops so_getorigdst = { .owner = THIS_MODULE, }; +static int ipv4_init_net (struct net *net) +{ +#if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT ) +struct nf_ip_net *in = &net->ct.nf_ct_proto; + in->ctl_table =kmemdup (ip_ct_sysctl_table, +sizeof (ip_ct_sysctl_table), +GFP_KERNEL ); +if (!in->ctl_table) +return -ENOMEM ; + + in->ctl_table[0 ].data = &nf_conntrack_max; + in->ctl_table[1 ].data = &net->ct.count; + in->ctl_table[2 ].data = &net->ct.htable_size; + in->ctl_table[3 ].data = &net->ct.sysctl_checksum; + in->ctl_table[4 ].data = &net->ct.sysctl_log_invalid; +#endif +return 0 ; +} +struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4__read_mostly = { .l3proto =PF_INET , .name ="ipv4" ,
@@ -368,6 +382,7 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = { .ctl_table_path = "net/ipv4/netfilter", .ctl_table = ip_ct_sysctl_table, #endif + .init_net = ipv4_init_net, .me = THIS_MODULE, };
@@ -378,6 +393,65 @@ MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET));MODULE_ALIAS ("ip_conntrack" );MODULE_LICENSE ("GPL" ); +static int ipv4_net_init (struct net *net) +{ +int ret =0 ; + + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_tcp4); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_tcp4 :protocol register failed\n" ); + goto out_tcp; + } + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_udp4); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_udp4 :protocol register failed\n" ); + goto out_udp; + } + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_icmp); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_icmp4 :protocol register failed\n" ); + goto out_icmp; + } + ret =nf_conntrack_l3proto_register (net, + &nf_conntrack_l3proto_ipv4); +if (ret <0 ) { +pr_err ("nf_conntrack_l3proto_ipv4 :protocol register failed\n" ); + goto out_ipv4; + } +return 0 ; +out_ipv4: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_icmp); +out_icmp: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_udp4); +out_udp: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_tcp4); +out_tcp: +return ret; +} + +static void ipv4_net_exit (struct net *net) +{ +nf_conntrack_l3proto_unregister (net, + &nf_conntrack_l3proto_ipv4); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_icmp); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_udp4); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_tcp4); +} + +static struct pernet_operations ipv4_net_ops = { + .init = ipv4_net_init, + .exit = ipv4_net_exit, +}; +static int __init nf_conntrack_l3proto_ipv4_init (void ) {int ret =0 ;
@@ -391,35 +465,17 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)return ret; } - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_tcp4); + ret =register_pernet_subsys (&ipv4_net_ops);if (ret <0 ) { -pr_err ("nf_conntrack_ipv4: can't register tcp.\n" ); +pr_err ("nf_conntrack_ipv4: can't register pernet ops\n" ); goto cleanup_sockopt; } - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udp4); -if (ret <0 ) { -pr_err ("nf_conntrack_ipv4: can't register udp.\n" ); - goto cleanup_tcp; - } - - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_icmp); -if (ret <0 ) { -pr_err ("nf_conntrack_ipv4: can't register icmp.\n" ); - goto cleanup_udp; - } - - ret =nf_conntrack_l3proto_register (&init_net, &nf_conntrack_l3proto_ipv4); -if (ret <0 ) { -pr_err ("nf_conntrack_ipv4: can't register ipv4\n" ); - goto cleanup_icmp; - } - ret =nf_register_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops));if (ret <0 ) {pr_err ("nf_conntrack_ipv4: can't register hooks.\n" ); - goto cleanup_ipv4; + goto cleanup_pernet; }#if defined(CONFIG_PROC_FS ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT ) ret =nf_conntrack_ipv4_compat_init ();
@@ -431,14 +487,8 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) cleanup_hooks:nf_unregister_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops));#endif - cleanup_ipv4: -nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv4); - cleanup_icmp: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp); - cleanup_udp: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp4); - cleanup_tcp: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp4); + cleanup_pernet: +unregister_pernet_subsys (&ipv4_net_ops); cleanup_sockopt:nf_unregister_sockopt (&so_getorigdst);return ret;
@@ -451,10 +501,7 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void)nf_conntrack_ipv4_compat_fini ();#endif nf_unregister_hooks (ipv4_conntrack_ops,ARRAY_SIZE (ipv4_conntrack_ops)); -nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv4); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmp); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp4); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp4); +unregister_pernet_subsys (&ipv4_net_ops);nf_unregister_sockopt (&so_getorigdst); }
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 12/25 netfilter: nf_ct_ipv6: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for IPv6 protocol tracker.
--- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 88 ++++++++++++++++-------- 1 file changed, 59 insertions(+), 29 deletions(-)
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +59 -29
@@ -333,37 +333,75 @@ MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6));MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Yasuyuki KOZAKAI @USAGI <[email protected]>" ); -static int __init nf_conntrack_l3proto_ipv6_init (void ) +static int ipv6_net_init (struct net *net) {int ret =0 ; -need_conntrack (); -nf_defrag_ipv6_enable (); - - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_tcp6); + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_tcp6);if (ret <0 ) { -pr_err ("nf_conntrack_ipv6: can't register tcp.\n" ); -return ret; +printk (KERN_ERR "nf_conntrack_l4proto_tcp6: protocol register failed\n" ); + goto out; } - - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udp6); + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_udp6);if (ret <0 ) { -pr_err ("nf_conntrack_ipv6: can't register udp.\n" ); - goto cleanup_tcp; +printk (KERN_ERR "nf_conntrack_l4proto_udp6: protocol register failed\n" ); + goto cleanup_tcp6; } - - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_icmpv6); + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_icmpv6);if (ret <0 ) { -pr_err ("nf_conntrack_ipv6: can't register icmpv6.\n" ); - goto cleanup_udp; +printk (KERN_ERR "nf_conntrack_l4proto_icmp6: protocol register failed\n" ); + goto cleanup_udp6; } - - ret =nf_conntrack_l3proto_register (&init_net, &nf_conntrack_l3proto_ipv6); + ret =nf_conntrack_l3proto_register (net, + &nf_conntrack_l3proto_ipv6);if (ret <0 ) { -pr_err ("nf_conntrack_ipv6: can't register ipv6\n" ); +printk (KERN_ERR "nf_conntrack_l3proto_ipv6: protocol register failed\n" ); goto cleanup_icmpv6; } +return 0 ; + cleanup_icmpv6: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_icmpv6); + cleanup_udp6: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_udp6); + cleanup_tcp6: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_tcp6); + out: +return ret; +} +static void ipv6_net_exit (struct net *net) +{ +nf_conntrack_l3proto_unregister (net, + &nf_conntrack_l3proto_ipv6); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_icmpv6); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_udp6); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_tcp6); +} + +static struct pernet_operations ipv6_net_ops = { + .init = ipv6_net_init, + .exit = ipv6_net_exit, +}; + +static int __init nf_conntrack_l3proto_ipv6_init (void ) +{ +int ret =0 ; + +need_conntrack (); +nf_defrag_ipv6_enable (); + + ret =register_pernet_subsys (&ipv6_net_ops); +if (ret <0 ) + goto cleanup_pernet; ret =nf_register_hooks (ipv6_conntrack_ops,ARRAY_SIZE (ipv6_conntrack_ops));if (ret <0 ) {
@@ -374,13 +412,8 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)return ret; cleanup_ipv6: -nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv6); - cleanup_icmpv6: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6); - cleanup_udp: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp6); - cleanup_tcp: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp6); +unregister_pernet_subsys (&ipv6_net_ops); + cleanup_pernet:return ret; }
@@ -388,10 +421,7 @@ static void __exit nf_conntrack_l3proto_ipv6_fini(void) {synchronize_net ();nf_unregister_hooks (ipv6_conntrack_ops,ARRAY_SIZE (ipv6_conntrack_ops)); -nf_conntrack_l3proto_unregister (&init_net, &nf_conntrack_l3proto_ipv6); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_icmpv6); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udp6); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_tcp6); +unregister_pernet_subsys (&ipv6_net_ops); }module_init (nf_conntrack_l3proto_ipv6_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 13/25 netfilter: nf_ct_sctp: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for SCTP protocol tracker.
--- net/netfilter/nf_conntrack_proto_sctp.c | 175 ++++++++++++++++++++++++++----- 1 file changed, 146 insertions(+), 29 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +146 -29
@@ -127,6 +127,17 @@ static const u8 sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = { } }; +static int sctp_net_id__read_mostly ; +struct sctp_net { +struct nf_proto_net pn; +unsigned int timeouts[SCTP_CONNTRACK_MAX ]; +}; + +static inline struct sctp_net *sctp_pernet (struct net *net) +{ +return net_generic (net, sctp_net_id); +} +static bool sctp_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff,struct nf_conntrack_tuple *tuple) {
@@ -281,7 +292,7 @@ static int sctp_new_state(enum ip_conntrack_dir dir,static unsigned int *sctp_get_timeouts (struct net *net) { -return sctp_timeouts; +return sctp_pernet (net)->timeouts; }/* Returns verdict for packet, or -NF_ACCEPT for invalid. */
@@ -604,49 +615,42 @@ static struct ctl_table_header *sctp_sysctl_header;static struct ctl_table sctp_sysctl_table[] = { { .procname ="nf_conntrack_sctp_timeout_closed" , - .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_cookie_wait" , - .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_cookie_echoed" , - .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_established" , - .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_shutdown_sent" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_shutdown_recd" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_sctp_timeout_shutdown_ack_sent" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -658,49 +662,42 @@ static struct ctl_table sctp_sysctl_table[] = {static struct ctl_table sctp_compat_sysctl_table[] = { { .procname ="ip_conntrack_sctp_timeout_closed" , - .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_cookie_wait" , - .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_cookie_echoed" , - .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_established" , - .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_shutdown_sent" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_shutdown_recd" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="ip_conntrack_sctp_timeout_shutdown_ack_sent" , - .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -710,6 +707,101 @@ static struct ctl_table sctp_compat_sysctl_table[] = {#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ #endif +static void sctp_init_net_data (struct sctp_net *sn) +{ +int i; +#ifdef CONFIG_SYSCTL + if (!sn->pn.ctl_table) { +#else + if (!sn->pn.users++) { +#endif + for (i = 0; i < SCTP_CONNTRACK_MAX; i++) + sn->timeouts[i] = sctp_timeouts[i]; + } +} + +static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn) +{ +#ifdef CONFIG_SYSCTL + struct sctp_net *sn = (struct sctp_net *)pn; + if (pn->ctl_table) + return 0; + + pn->ctl_table = kmemdup(sctp_sysctl_table, + sizeof(sctp_sysctl_table), + GFP_KERNEL); + if (!pn->ctl_table) + return -ENOMEM; + + pn->ctl_table[0].data = &sn->timeouts[SCTP_CONNTRACK_CLOSED]; + pn->ctl_table[1].data = &sn->timeouts[SCTP_CONNTRACK_COOKIE_WAIT]; + pn->ctl_table[2].data = &sn->timeouts[SCTP_CONNTRACK_COOKIE_ECHOED]; + pn->ctl_table[3].data = &sn->timeouts[SCTP_CONNTRACK_ESTABLISHED]; + pn->ctl_table[4].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT]; + pn->ctl_table[5].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD]; + pn->ctl_table[6].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT]; +#endif + return 0; +} + +static int sctp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) +{ +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT + struct sctp_net *sn = (struct sctp_net *)pn; + pn->ctl_compat_table = kmemdup(sctp_compat_sysctl_table, + sizeof(sctp_compat_sysctl_table), + GFP_KERNEL); + if (!pn->ctl_compat_table) + return -ENOMEM; + + pn->ctl_compat_table[0].data = &sn->timeouts[SCTP_CONNTRACK_CLOSED]; + pn->ctl_compat_table[1].data = &sn->timeouts[SCTP_CONNTRACK_COOKIE_WAIT]; + pn->ctl_compat_table[2].data = &sn->timeouts[SCTP_CONNTRACK_COOKIE_ECHOED]; + pn->ctl_compat_table[3].data = &sn->timeouts[SCTP_CONNTRACK_ESTABLISHED]; + pn->ctl_compat_table[4].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT]; + pn->ctl_compat_table[5].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD]; + pn->ctl_compat_table[6].data = &sn->timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT]; +#endif +#endif + return 0; +} + +static int sctpv4_init_net(struct net *net) +{ + int ret; + struct sctp_net *sn = sctp_pernet(net); + struct nf_proto_net *pn = (struct nf_proto_net *)sn; + + sctp_init_net_data(sn); + + ret = sctp_kmemdup_compat_sysctl_table(pn); + if (ret < 0) + return ret; + + ret = sctp_kmemdup_sysctl_table(pn); + +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT + if (ret < 0) { + + kfree(pn->ctl_compat_table); + pn->ctl_compat_table = NULL; + } +#endif +#endif + return ret; +} + +static int sctpv6_init_net(struct net *net) +{ + struct sctp_net *sn = sctp_pernet(net); + struct nf_proto_net *pn = (struct nf_proto_net *)sn; + + sctp_init_net_data(sn); + return sctp_kmemdup_sysctl_table(pn); +} + static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { .l3proto = PF_INET, .l4proto = IPPROTO_SCTP,
@@ -748,6 +840,8 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { .ctl_compat_table = sctp_compat_sysctl_table,#endif #endif + .net_id = &sctp_net_id, + .init_net = sctpv4_init_net, };static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6__read_mostly = {
@@ -785,35 +879,58 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = { .ctl_table_header = &sctp_sysctl_header, .ctl_table = sctp_sysctl_table, #endif + .net_id = &sctp_net_id, + .init_net = sctpv6_init_net, }; -static int __init nf_conntrack_proto_sctp_init (void ) +static int sctp_net_init (struct net *net) { -int ret; +int ret =0 ; - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_sctp4); -if (ret) { -pr_err ("nf_conntrack_l4proto_sctp4: protocol register failed\n" ); + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_sctp4); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_sctp4 :protocol register failed.\n" ); goto out; } - ret =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_sctp6); -if (ret) { -pr_err ("nf_conntrack_l4proto_sctp6: protocol register failed\n" ); + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_sctp6); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_sctp6 :protocol register failed.\n" ); goto cleanup_sctp4; } +return 0 ; +cleanup_sctp4: +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_sctp4); +out:return ret; +} - cleanup_sctp4: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp4); - out: -return ret; +static void sctp_net_exit (struct net *net) +{ +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_sctp6); +nf_conntrack_l4proto_unregister (net, + &nf_conntrack_l4proto_sctp4); +} + +static struct pernet_operations sctp_net_ops = { + .init = sctp_net_init, + .exit = sctp_net_exit, + .id = &sctp_net_id, + .size =sizeof (struct sctp_net ), +}; + +static int __init nf_conntrack_proto_sctp_init (void ) +{ +return register_pernet_subsys (&sctp_net_ops); } static void __exit nf_conntrack_proto_sctp_fini(void) { -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp6); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_sctp4); +unregister_pernet_subsys (&sctp_net_ops); }module_init (nf_conntrack_proto_sctp_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 14/25 netfilter: nf_ct_udplite: add namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for UDPlite protocol tracker.
--- net/netfilter/nf_conntrack_proto_udplite.c | 98 +++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 18 deletions(-)
net/netfilter/nf_conntrack_proto_udplite.c +80 -18
@@ -35,6 +35,17 @@ static unsigned int udplite_timeouts[UDPLITE_CT_MAX] = { [UDPLITE_CT_REPLIED] = 180*HZ, }; +static int udplite_net_id__read_mostly ; +struct udplite_net { +struct nf_proto_net pn; +unsigned int timeouts[UDPLITE_CT_MAX ]; +}; + +static inline struct udplite_net *udplite_pernet (struct net *net) +{ +return net_generic (net, udplite_net_id); +} +static bool udplite_pkt_to_tuple (const struct sk_buff *skb,unsigned int dataoff,struct nf_conntrack_tuple *tuple)
@@ -70,7 +81,7 @@ static int udplite_print_tuple(struct seq_file *s,static unsigned int *udplite_get_timeouts (struct net *net) { -return udplite_timeouts; +return udplite_pernet (net)->timeouts; }/* Returns verdict for packet, and may modify conntracktype */
@@ -209,14 +220,12 @@ static struct ctl_table_header *udplite_sysctl_header;static struct ctl_table udplite_sysctl_table[] = { { .procname ="nf_conntrack_udplite_timeout" , - .data = &udplite_timeouts[UDPLITE_CT_UNREPLIED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies, }, { .procname ="nf_conntrack_udplite_timeout_stream" , - .data = &udplite_timeouts[UDPLITE_CT_REPLIED ], .maxlen =sizeof (unsigned int ), .mode =0644 , .proc_handler = proc_dointvec_jiffies,
@@ -225,6 +234,31 @@ static struct ctl_table udplite_sysctl_table[] = { };#endif /* CONFIG_SYSCTL */ +static int udplite_init_net (struct net *net) +{ +int i; +struct udplite_net *un =udplite_pernet (net); +struct nf_proto_net *pn = (struct nf_proto_net *)un; +#ifdef CONFIG_SYSCTL + if (!pn->ctl_table) { +#else + if (!pn->users++) { +#endif + for (i = 0 ; i < UDPLITE_CT_MAX; i++) + un->timeouts[i] = udplite_timeouts[i]; +#ifdef CONFIG_SYSCTL + pn->ctl_table = kmemdup(udplite_sysctl_table, + sizeof(udplite_sysctl_table), + GFP_KERNEL); + if (!pn->ctl_table) + return -ENOMEM; + pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED]; + pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED]; +#endif + } + return 0; +} + static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = { .l3proto = PF_INET,
@@ -258,6 +292,8 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = .ctl_table_header = &udplite_sysctl_header, .ctl_table = udplite_sysctl_table, #endif + .net_id = &udplite_net_id, + .init_net = udplite_init_net, }; static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly =
@@ -293,29 +329,55 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = .ctl_table_header = &udplite_sysctl_header, .ctl_table = udplite_sysctl_table, #endif + .net_id = &udplite_net_id, + .init_net = udplite_init_net, }; -static int __init nf_conntrack_proto_udplite_init (void ) +static int udplite_net_init (struct net *net) { -int err; - - err =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udplite4); -if (err <0 ) - goto err1; - err =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_udplite6); -if (err <0 ) - goto err2; +int ret =0 ; + + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_udplite4); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_udplite4 :protocol register failed.\n" ); + goto out; + } + ret =nf_conntrack_l4proto_register (net, + &nf_conntrack_l4proto_udplite6); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_udplite4 :protocol register failed.\n" ); + goto cleanup_udplite4; + }return 0 ; -err2: -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite4); -err1: -return err; + +cleanup_udplite4: +nf_conntrack_l4proto_unregister (net, &nf_conntrack_l4proto_udplite4); +out: +return ret; +} + +static void udplite_net_exit (struct net *net) +{ +nf_conntrack_l4proto_unregister (net, &nf_conntrack_l4proto_udplite6); +nf_conntrack_l4proto_unregister (net, &nf_conntrack_l4proto_udplite4); +} + +static struct pernet_operations udplite_net_ops = { + .init = udplite_net_init, + .exit = udplite_net_exit, + .id = &udplite_net_id, + .size =sizeof (struct udplite_net ), +}; + +static int __init nf_conntrack_proto_udplite_init (void ) +{ +return register_pernet_subsys (&udplite_net_ops); } static void __exit nf_conntrack_proto_udplite_exit(void) { -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite6); -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_udplite4); +unregister_pernet_subsys (&udplite_net_ops); }module_init (nf_conntrack_proto_udplite_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 15/25 netfilter: nf_ct_dccp: use new namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch modifies the DCCP protocol tracker to use the new namespace infrastructure for nf_conntrack.
--- net/netfilter/nf_conntrack_proto_dccp.c | 132 +++++++++++++++---------------- 1 file changed, 66 insertions(+), 66 deletions(-)
net/netfilter/nf_conntrack_proto_dccp.c +66 -66
@@ -387,12 +387,9 @@ dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] =/* this module per-net specifics */ static int dccp_net_id__read_mostly ;struct dccp_net { +struct nf_proto_net np;int dccp_loose;unsigned int dccp_timeout[CT_DCCP_MAX +1 ]; -#ifdef CONFIG_SYSCTL -struct ctl_table_header *sysctl_header; -struct ctl_table *sysctl_table; -#endif };static inline struct dccp_net *dccp_pernet (struct net *net)
@@ -817,6 +814,45 @@ static struct ctl_table dccp_sysctl_table[] = { };#endif /* CONFIG_SYSCTL */ +static int dccp_init_net (struct net *net) +{ +struct dccp_net *dn =dccp_pernet (net); +struct nf_proto_net *pn = (struct nf_proto_net *)dn; + +#ifdef CONFIG_SYSCTL + if (!pn->ctl_table) { +#else + if (!pn->users++) { +#endif + /* default values */ + dn->dccp_loose = 1; + dn->dccp_timeout[CT_DCCP_REQUEST] = 2 * DCCP_MSL; + dn->dccp_timeout[CT_DCCP_RESPOND] = 4 * DCCP_MSL; + dn->dccp_timeout[CT_DCCP_PARTOPEN] = 4 * DCCP_MSL; + dn->dccp_timeout[CT_DCCP_OPEN] = 12 * 3600 * HZ; + dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ; + dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ; + dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL; +#ifdef CONFIG_SYSCTL + pn->ctl_table = kmemdup(dccp_sysctl_table, + sizeof(dccp_sysctl_table), + GFP_KERNEL); + if (!pn->ctl_table) + return -ENOMEM; + + pn->ctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST]; + pn->ctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND]; + pn->ctl_table[2].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN]; + pn->ctl_table[3].data = &dn->dccp_timeout[CT_DCCP_OPEN]; + pn->ctl_table[4].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ]; + pn->ctl_table[5].data = &dn->dccp_timeout[CT_DCCP_CLOSING]; + pn->ctl_table[6].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT]; + pn->ctl_table[7].data = &dn->dccp_loose; +#endif + } + return 0; +} + static struct nf_conntrack_l4proto dccp_proto4 __read_mostly = { .l3proto = AF_INET, .l4proto = IPPROTO_DCCP,
@@ -847,6 +883,8 @@ static struct nf_conntrack_l4proto dccp_proto4 __read_mostly = { .nla_policy = dccp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ + .net_id = &dccp_net_id, + .init_net = dccp_init_net, }; static struct nf_conntrack_l4proto dccp_proto6 __read_mostly = {
@@ -879,55 +917,39 @@ static struct nf_conntrack_l4proto dccp_proto6 __read_mostly = { .nla_policy = dccp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ + .net_id = &dccp_net_id, + .init_net = dccp_init_net, };static __net_init int dccp_net_init (struct net *net) { -struct dccp_net *dn =dccp_pernet (net); - -/* default values */ - dn->dccp_loose =1 ; - dn->dccp_timeout[CT_DCCP_REQUEST ] =2 *DCCP_MSL ; - dn->dccp_timeout[CT_DCCP_RESPOND ] =4 *DCCP_MSL ; - dn->dccp_timeout[CT_DCCP_PARTOPEN ] =4 *DCCP_MSL ; - dn->dccp_timeout[CT_DCCP_OPEN ] =12 *3600 *HZ ; - dn->dccp_timeout[CT_DCCP_CLOSEREQ ] =64 *HZ ; - dn->dccp_timeout[CT_DCCP_CLOSING ] =64 *HZ ; - dn->dccp_timeout[CT_DCCP_TIMEWAIT ] =2 *DCCP_MSL ; - -#ifdef CONFIG_SYSCTL - dn->sysctl_table =kmemdup (dccp_sysctl_table, -sizeof (dccp_sysctl_table),GFP_KERNEL ); -if (!dn->sysctl_table) -return -ENOMEM ; - - dn->sysctl_table[0 ].data = &dn->dccp_timeout[CT_DCCP_REQUEST ]; - dn->sysctl_table[1 ].data = &dn->dccp_timeout[CT_DCCP_RESPOND ]; - dn->sysctl_table[2 ].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN ]; - dn->sysctl_table[3 ].data = &dn->dccp_timeout[CT_DCCP_OPEN ]; - dn->sysctl_table[4 ].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ ]; - dn->sysctl_table[5 ].data = &dn->dccp_timeout[CT_DCCP_CLOSING ]; - dn->sysctl_table[6 ].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT ]; - dn->sysctl_table[7 ].data = &dn->dccp_loose; - - dn->sysctl_header =register_net_sysctl (net,"net/netfilter" , - dn->sysctl_table); -if (!dn->sysctl_header) { -kfree (dn->sysctl_table); -return -ENOMEM ; +int ret =0 ; + ret =nf_conntrack_l4proto_register (net, + &dccp_proto4); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_dccp4 :protocol register failed.\n" ); + goto out; + } + ret =nf_conntrack_l4proto_register (net, + &dccp_proto6); +if (ret <0 ) { +pr_err ("nf_conntrack_l4proto_dccp6 :protocol register failed.\n" ); + goto cleanup_dccp4; } -#endif -return 0 ; +cleanup_dccp4: +nf_conntrack_l4proto_unregister (net, + &dccp_proto4); +out: +return ret; } static __net_exit void dccp_net_exit(struct net *net) { -struct dccp_net *dn =dccp_pernet (net); -#ifdef CONFIG_SYSCTL -unregister_net_sysctl_table (dn->sysctl_header); -kfree (dn->sysctl_table); -#endif +nf_conntrack_l4proto_unregister (net, + &dccp_proto6); +nf_conntrack_l4proto_unregister (net, + &dccp_proto4); } static struct pernet_operations dccp_net_ops = {
@@ -939,34 +961,12 @@ static struct pernet_operations dccp_net_ops = {static int __init nf_conntrack_proto_dccp_init (void ) { -int err; - - err =register_pernet_subsys (&dccp_net_ops); -if (err <0 ) - goto err1; - - err =nf_conntrack_l4proto_register (&init_net, &dccp_proto4); -if (err <0 ) - goto err2; - - err =nf_conntrack_l4proto_register (&init_net, &dccp_proto6); -if (err <0 ) - goto err3; -return 0 ; - -err3: -nf_conntrack_l4proto_unregister (&init_net, &dccp_proto4); -err2: -unregister_pernet_subsys (&dccp_net_ops); -err1: -return err; +return register_pernet_subsys (&dccp_net_ops); } static void __exit nf_conntrack_proto_dccp_fini(void) {unregister_pernet_subsys (&dccp_net_ops); -nf_conntrack_l4proto_unregister (&init_net, &dccp_proto6); -nf_conntrack_l4proto_unregister (&init_net, &dccp_proto4); }module_init (nf_conntrack_proto_dccp_init);
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 16/25 netfilter: nf_ct_gre: use new namespace support
In reply to [email protected]From: Gao feng <[email protected]>
This patch modifies the GRE protocol tracker, which partially supported namespace before this patch, to use the new namespace infrastructure for nf_conntrack.
--- net/netfilter/nf_conntrack_proto_gre.c | 55 ++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-)
net/netfilter/nf_conntrack_proto_gre.c +34 -21
@@ -54,13 +54,20 @@ static unsigned int gre_timeouts[GRE_CT_MAX] = {static int proto_gre_net_id__read_mostly ;struct netns_proto_gre { +struct nf_proto_net nf;rwlock_t keymap_lock;struct list_head keymap_list; +unsigned int gre_timeouts[GRE_CT_MAX ]; }; +static inline struct netns_proto_gre *gre_pernet (struct net *net) +{ +return net_generic (net, proto_gre_net_id); +} +void nf_ct_gre_keymap_flush (struct net *net) { -struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); +struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_ct_gre_keymap *km, *tmp;write_lock_bh (&net_gre->keymap_lock);
@@ -85,7 +92,7 @@ static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km,/* look up the source key for a given tuple */ static __be16 gre_keymap_lookup (struct net *net,struct nf_conntrack_tuple *t) { -struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); +struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_ct_gre_keymap *km;__be16 key =0 ;
@@ -109,7 +116,7 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir, struct nf_conntrack_tuple *t) {struct net *net =nf_ct_net (ct); -struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); +struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_conn_help *help =nfct_help (ct);struct nf_ct_gre_keymap **kmp, *km;
@@ -150,7 +157,7 @@ EXPORT_SYMBOL_GPL(nf_ct_gre_keymap_add);void nf_ct_gre_keymap_destroy (struct nf_conn *ct) {struct net *net =nf_ct_net (ct); -struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); +struct netns_proto_gre *net_gre =gre_pernet (net);struct nf_conn_help *help =nfct_help (ct);enum ip_conntrack_dir dir;
@@ -237,7 +244,7 @@ static int gre_print_conntrack(struct seq_file *s, struct nf_conn *ct)static unsigned int *gre_get_timeouts (struct net *net) { -return gre_timeouts; +return gre_pernet (net)->gre_timeouts; }/* Returns verdict for packet, and may modify conntrack */
@@ -339,6 +346,19 @@ gre_timeout_nla_policy[CTA_TIMEOUT_GRE_MAX+1] = { };#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ +static int gre_init_net (struct net *net) +{ +struct netns_proto_gre *net_gre =gre_pernet (net); +int i; + +rwlock_init (&net_gre->keymap_lock); +INIT_LIST_HEAD (&net_gre->keymap_list); +for (i =0 ; i <GRE_CT_MAX ; i++) + net_gre->gre_timeouts[i] = gre_timeouts[i]; + +return 0 ; +} +/* protocol helper struct */ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4__read_mostly = { .l3proto =AF_INET ,
@@ -368,20 +388,22 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 __read_mostly = { .nla_policy = gre_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ + .net_id = &proto_gre_net_id, + .init_net = gre_init_net, };static int proto_gre_net_init (struct net *net) { -struct netns_proto_gre *net_gre =net_generic (net, proto_gre_net_id); - -rwlock_init (&net_gre->keymap_lock); -INIT_LIST_HEAD (&net_gre->keymap_list); - -return 0 ; +int ret =0 ; + ret =nf_conntrack_l4proto_register (net, &nf_conntrack_l4proto_gre4); +if (ret <0 ) +pr_err ("nf_conntrack_l4proto_gre4 :protocol register failed.\n" ); +return ret; }static void proto_gre_net_exit (struct net *net) { +nf_conntrack_l4proto_unregister (net, &nf_conntrack_l4proto_gre4);nf_ct_gre_keymap_flush (net); }
@@ -394,20 +416,11 @@ static struct pernet_operations proto_gre_net_ops = {static int __init nf_ct_proto_gre_init (void ) { -int rv; - - rv =nf_conntrack_l4proto_register (&init_net, &nf_conntrack_l4proto_gre4); -if (rv <0 ) -return rv; - rv =register_pernet_subsys (&proto_gre_net_ops); -if (rv <0 ) -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_gre4); -return rv; +return register_pernet_subsys (&proto_gre_net_ops); } static void __exit nf_ct_proto_gre_fini(void) { -nf_conntrack_l4proto_unregister (&init_net, &nf_conntrack_l4proto_gre4);unregister_pernet_subsys (&proto_gre_net_ops); }
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 17/25 netfilter: nf_conntrack: remove now unused sysctl for nf_conntrack_l[3|4]proto
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
Since the sysctl data for l[3|4]proto now resides in pernet nf_proto_net. We can now remove this unused fields from struct nf_contrack_l[3,4]proto.
--- include/net/netfilter/nf_conntrack_l3proto.h | 2 -- include/net/netfilter/nf_conntrack_l4proto.h | 10 ---------- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 - net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 8 -------- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 5 ----- net/netfilter/nf_conntrack_proto_generic.c | 8 -------- net/netfilter/nf_conntrack_proto_sctp.c | 15 --------------- net/netfilter/nf_conntrack_proto_tcp.c | 15 --------------- net/netfilter/nf_conntrack_proto_udp.c | 15 --------------- net/netfilter/nf_conntrack_proto_udplite.c | 12 ------------ 10 files changed, 91 deletions(-)
include/net/netfilter/nf_conntrack_l3proto.h +0 -2
@@ -64,9 +64,7 @@ struct nf_conntrack_l3proto {size_t nla_size;#ifdef CONFIG_SYSCTL -struct ctl_table_header *ctl_table_header;const char *ctl_table_path; -struct ctl_table *ctl_table;#endif /* CONFIG_SYSCTL */ /* Init l3proto pernet data */
include/net/netfilter/nf_conntrack_l4proto.h +0 -10
@@ -94,16 +94,6 @@ struct nf_conntrack_l4proto { const struct nla_policy *nla_policy; } ctnl_timeout;#endif - -#ifdef CONFIG_SYSCTL -struct ctl_table_header **ctl_table_header; -struct ctl_table *ctl_table; -unsigned int *ctl_table_users; -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT -struct ctl_table_header *ctl_compat_table_header; -struct ctl_table *ctl_compat_table; -#endif -#endif int *net_id;/* Init l4proto pernet data */ int (*init_net)(struct net *net);
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +0 -1
@@ -380,7 +380,6 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = {#endif #if defined(CONFIG_SYSCTL ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT ) .ctl_table_path = "net/ipv4/netfilter", - .ctl_table = ip_ct_sysctl_table, #endif .init_net = ipv4_init_net, .me = THIS_MODULE,
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +0 -8
@@ -313,7 +313,6 @@ icmp_timeout_nla_policy[CTA_TIMEOUT_ICMP_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static struct ctl_table_header *icmp_sysctl_header; static struct ctl_table icmp_sysctl_table[] = { { .procname = "nf_conntrack_icmp_timeout",
@@ -393,12 +392,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp __read_mostly = .nla_policy = icmp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_header = &icmp_sysctl_header, - .ctl_table = icmp_sysctl_table, -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT - .ctl_compat_table = icmp_compat_sysctl_table, -#endif -#endif .init_net = icmp_init_net, };
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +0 -5
@@ -320,7 +320,6 @@ icmpv6_timeout_nla_policy[CTA_TIMEOUT_ICMPV6_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static struct ctl_table_header *icmpv6_sysctl_header; static struct ctl_table icmpv6_sysctl_table[] = { { .procname = "nf_conntrack_icmpv6_timeout",
@@ -375,9 +374,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 __read_mostly = .nla_policy = icmpv6_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_header = &icmpv6_sysctl_header, - .ctl_table = icmpv6_sysctl_table, -#endif .init_net = icmpv6_init_net, };
net/netfilter/nf_conntrack_proto_generic.c +0 -8
@@ -111,7 +111,6 @@ generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static struct ctl_table_header *generic_sysctl_header; static struct ctl_table generic_sysctl_table[] = { { .procname = "nf_conntrack_generic_timeout",
@@ -182,12 +181,5 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly = .nla_policy = generic_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_header = &generic_sysctl_header, - .ctl_table = generic_sysctl_table, -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT - .ctl_compat_table = generic_compat_sysctl_table, -#endif -#endif .init_net = generic_init_net, };
net/netfilter/nf_conntrack_proto_sctp.c +0 -15
@@ -610,8 +610,6 @@ sctp_timeout_nla_policy[CTA_TIMEOUT_SCTP_MAX+1] = { #ifdef CONFIG_SYSCTL -static unsigned int sctp_sysctl_table_users; -static struct ctl_table_header *sctp_sysctl_header; static struct ctl_table sctp_sysctl_table[] = { { .procname = "nf_conntrack_sctp_timeout_closed",
@@ -832,14 +830,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { .nla_policy = sctp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &sctp_sysctl_table_users, - .ctl_table_header = &sctp_sysctl_header, - .ctl_table = sctp_sysctl_table, -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT - .ctl_compat_table = sctp_compat_sysctl_table, -#endif -#endif .net_id = &sctp_net_id, .init_net = sctpv4_init_net, };
@@ -874,11 +864,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = { },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #endif -#ifdef CONFIG_SYSCTL - .ctl_table_users = &sctp_sysctl_table_users, - .ctl_table_header = &sctp_sysctl_header, - .ctl_table = sctp_sysctl_table, -#endif .net_id = &sctp_net_id, .init_net = sctpv6_init_net, };
net/netfilter/nf_conntrack_proto_tcp.c +0 -15
@@ -1364,8 +1364,6 @@ static const struct nla_policy tcp_timeout_nla_policy[CTA_TIMEOUT_TCP_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static unsigned int tcp_sysctl_table_users; -static struct ctl_table_header *tcp_sysctl_header; static struct ctl_table tcp_sysctl_table[] = { { .procname = "nf_conntrack_tcp_timeout_syn_sent",
@@ -1684,14 +1682,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly = .nla_policy = tcp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &tcp_sysctl_table_users, - .ctl_table_header = &tcp_sysctl_header, - .ctl_table = tcp_sysctl_table, -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT - .ctl_compat_table = tcp_compat_sysctl_table, -#endif -#endif .init_net = tcpv4_init_net, };EXPORT_SYMBOL_GPL (nf_conntrack_l4proto_tcp4);
@@ -1728,11 +1718,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6 __read_mostly = .nla_policy = tcp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &tcp_sysctl_table_users, - .ctl_table_header = &tcp_sysctl_header, - .ctl_table = tcp_sysctl_table, -#endif .init_net = tcpv6_init_net, };EXPORT_SYMBOL_GPL (nf_conntrack_l4proto_tcp6);
net/netfilter/nf_conntrack_proto_udp.c +0 -15
@@ -199,8 +199,6 @@ udp_timeout_nla_policy[CTA_TIMEOUT_UDP_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static unsigned int udp_sysctl_table_users; -static struct ctl_table_header *udp_sysctl_header; static struct ctl_table udp_sysctl_table[] = { { .procname = "nf_conntrack_udp_timeout",
@@ -343,14 +341,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = .nla_policy = udp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &udp_sysctl_table_users, - .ctl_table_header = &udp_sysctl_header, - .ctl_table = udp_sysctl_table, -#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT - .ctl_compat_table = udp_compat_sysctl_table, -#endif -#endif .init_net = udpv4_init_net, };EXPORT_SYMBOL_GPL (nf_conntrack_l4proto_udp4);
@@ -382,11 +372,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = .nla_policy = udp_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &udp_sysctl_table_users, - .ctl_table_header = &udp_sysctl_header, - .ctl_table = udp_sysctl_table, -#endif .init_net = udpv6_init_net, };EXPORT_SYMBOL_GPL (nf_conntrack_l4proto_udp6);
net/netfilter/nf_conntrack_proto_udplite.c +0 -12
@@ -215,8 +215,6 @@ udplite_timeout_nla_policy[CTA_TIMEOUT_UDPLITE_MAX+1] = {#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ #ifdef CONFIG_SYSCTL -static unsigned int udplite_sysctl_table_users; -static struct ctl_table_header *udplite_sysctl_header; static struct ctl_table udplite_sysctl_table[] = { { .procname = "nf_conntrack_udplite_timeout",
@@ -287,11 +285,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = .nla_policy = udplite_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &udplite_sysctl_table_users, - .ctl_table_header = &udplite_sysctl_header, - .ctl_table = udplite_sysctl_table, -#endif .net_id = &udplite_net_id, .init_net = udplite_init_net, };
@@ -324,11 +317,6 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = .nla_policy = udplite_timeout_nla_policy, },#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ -#ifdef CONFIG_SYSCTL - .ctl_table_users = &udplite_sysctl_table_users, - .ctl_table_header = &udplite_sysctl_header, - .ctl_table = udplite_sysctl_table, -#endif .net_id = &udplite_net_id, .init_net = udplite_init_net, };
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 18/25 netfilter: nf_conntrack: add namespace support for cttimeout
In reply to [email protected]From: Gao feng <[email protected]>
This patch adds namespace support for cttimeout.
--- include/net/netfilter/nf_conntrack_l4proto.h | 3 ++- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 6 ++++-- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 6 ++++-- net/netfilter/nf_conntrack_proto_dccp.c | 5 +++-- net/netfilter/nf_conntrack_proto_generic.c | 6 ++++-- net/netfilter/nf_conntrack_proto_gre.c | 8 +++++--- net/netfilter/nf_conntrack_proto_sctp.c | 6 ++++-- net/netfilter/nf_conntrack_proto_tcp.c | 6 ++++-- net/netfilter/nf_conntrack_proto_udp.c | 8 +++++--- net/netfilter/nf_conntrack_proto_udplite.c | 8 +++++--- net/netfilter/nfnetlink_cttimeout.c | 13 ++++++++----- 11 files changed, 48 insertions(+), 27 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +2 -1
@@ -87,7 +87,8 @@ struct nf_conntrack_l4proto { #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) struct { size_t obj_size; - int (*nlattr_to_obj)(struct nlattr *tb[], void *data); + int (*nlattr_to_obj)(struct nlattr *tb[], + struct net *net, void *data); int (*obj_to_nlattr)(struct sk_buff *skb, const void *data); unsigned int nlattr_max;
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +4 -2
@@ -279,16 +279,18 @@ static int icmp_nlattr_tuple_size(void)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int icmp_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int icmp_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeout = data; +struct nf_icmp_net *in =icmp_pernet (net);if (tb[CTA_TIMEOUT_ICMP_TIMEOUT ]) { *timeout =ntohl (nla_get_be32 (tb[CTA_TIMEOUT_ICMP_TIMEOUT ])) *HZ ; }else {/* Set default ICMP timeout. */ - *timeout = nf_ct_icmp_timeout; + *timeout = in->timeout; }return 0 ; }
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +4 -2
@@ -286,16 +286,18 @@ static int icmpv6_nlattr_tuple_size(void)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int icmpv6_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int icmpv6_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeout = data; +struct nf_icmp_net *in =icmpv6_pernet (net);if (tb[CTA_TIMEOUT_ICMPV6_TIMEOUT ]) { *timeout =ntohl (nla_get_be32 (tb[CTA_TIMEOUT_ICMPV6_TIMEOUT ])) *HZ ; }else {/* Set default ICMPv6 timeout. */ - *timeout = nf_ct_icmpv6_timeout; + *timeout = in->timeout; }return 0 ; }
net/netfilter/nf_conntrack_proto_dccp.c +3 -2
@@ -712,9 +712,10 @@ static int dccp_nlattr_size(void)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int dccp_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int dccp_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) { -struct dccp_net *dn =dccp_pernet (&init_net); +struct dccp_net *dn =dccp_pernet (net);unsigned int *timeouts = data;int i;
net/netfilter/nf_conntrack_proto_generic.c +4 -2
@@ -75,16 +75,18 @@ static bool generic_new(struct nf_conn *ct, const struct sk_buff *skb,#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int generic_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int generic_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeout = data; +struct nf_generic_net *gn =generic_pernet (net);if (tb[CTA_TIMEOUT_GENERIC_TIMEOUT ]) *timeout =ntohl (nla_get_be32 (tb[CTA_TIMEOUT_GENERIC_TIMEOUT ])) *HZ ;else {/* Set default generic timeout. */ - *timeout = nf_ct_generic_timeout; + *timeout = gn->timeout; }return 0 ;
net/netfilter/nf_conntrack_proto_gre.c +5 -3
@@ -304,13 +304,15 @@ static void gre_destroy(struct nf_conn *ct)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int gre_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int gre_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeouts = data; +struct netns_proto_gre *net_gre =gre_pernet (net);/* set default timeouts for GRE. */ - timeouts[GRE_CT_UNREPLIED ] = gre_timeouts[GRE_CT_UNREPLIED ]; - timeouts[GRE_CT_REPLIED ] = gre_timeouts[GRE_CT_REPLIED ]; + timeouts[GRE_CT_UNREPLIED ] = net_gre->gre_timeouts[GRE_CT_UNREPLIED ]; + timeouts[GRE_CT_REPLIED ] = net_gre->gre_timeouts[GRE_CT_REPLIED ];if (tb[CTA_TIMEOUT_GRE_UNREPLIED ]) { timeouts[GRE_CT_UNREPLIED] =
net/netfilter/nf_conntrack_proto_sctp.c +4 -2
@@ -562,14 +562,16 @@ static int sctp_nlattr_size(void)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int sctp_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int sctp_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeouts = data; +struct sctp_net *sn =sctp_pernet (net);int i;/* set default SCTP timeouts. */ for (i=0 ; i<SCTP_CONNTRACK_MAX ; i++) - timeouts[i] = sctp_timeouts[i]; + timeouts[i] = sn->timeouts[i];/* there's a 1:1 mapping between attributes and protocol states. */ for (i=CTA_TIMEOUT_SCTP_UNSPEC +1 ; i<CTA_TIMEOUT_SCTP_MAX +1 ; i++) {
net/netfilter/nf_conntrack_proto_tcp.c +4 -2
@@ -1260,14 +1260,16 @@ static int tcp_nlattr_tuple_size(void)#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int tcp_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int tcp_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeouts = data; +struct nf_tcp_net *tn =tcp_pernet (net);int i;/* set default TCP timeouts. */ for (i=0 ; i<TCP_CONNTRACK_TIMEOUT_MAX ; i++) - timeouts[i] = tcp_timeouts[i]; + timeouts[i] = tn->timeouts[i];if (tb[CTA_TIMEOUT_TCP_SYN_SENT ]) { timeouts[TCP_CONNTRACK_SYN_SENT] =
net/netfilter/nf_conntrack_proto_udp.c +5 -3
@@ -156,13 +156,15 @@ static int udp_error(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int udp_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int udp_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeouts = data; +struct nf_udp_net *un =udp_pernet (net);/* set default timeouts for UDP. */ - timeouts[UDP_CT_UNREPLIED ] = udp_timeouts[UDP_CT_UNREPLIED ]; - timeouts[UDP_CT_REPLIED ] = udp_timeouts[UDP_CT_REPLIED ]; + timeouts[UDP_CT_UNREPLIED ] = un->timeouts[UDP_CT_UNREPLIED ]; + timeouts[UDP_CT_REPLIED ] = un->timeouts[UDP_CT_REPLIED ];if (tb[CTA_TIMEOUT_UDP_UNREPLIED ]) { timeouts[UDP_CT_UNREPLIED] =
net/netfilter/nf_conntrack_proto_udplite.c +5 -3
@@ -172,13 +172,15 @@ static int udplite_error(struct net *net, struct nf_conn *tmpl,#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> -static int udplite_timeout_nlattr_to_obj (struct nlattr *tb[],void *data) +static int udplite_timeout_nlattr_to_obj (struct nlattr *tb[], +struct net *net,void *data) {unsigned int *timeouts = data; +struct udplite_net *un =udplite_pernet (net);/* set default timeouts for UDPlite. */ - timeouts[UDPLITE_CT_UNREPLIED ] = udplite_timeouts[UDPLITE_CT_UNREPLIED ]; - timeouts[UDPLITE_CT_REPLIED ] = udplite_timeouts[UDPLITE_CT_REPLIED ]; + timeouts[UDPLITE_CT_UNREPLIED ] = un->timeouts[UDPLITE_CT_UNREPLIED ]; + timeouts[UDPLITE_CT_REPLIED ] = un->timeouts[UDPLITE_CT_REPLIED ];if (tb[CTA_TIMEOUT_UDPLITE_UNREPLIED ]) { timeouts[UDPLITE_CT_UNREPLIED] =
net/netfilter/nfnetlink_cttimeout.c +8 -5
@@ -49,8 +49,9 @@ static const struct nla_policy cttimeout_nla_policy[CTA_TIMEOUT_MAX+1] = {static int ctnl_timeout_parse_policy (struct ctnl_timeout *timeout, -struct nf_conntrack_l4proto *l4proto, -const struct nlattr *attr) +struct nf_conntrack_l4proto *l4proto, +struct net *net, +const struct nlattr *attr) {int ret =0 ;
@@ -60,7 +61,8 @@ ctnl_timeout_parse_policy(struct ctnl_timeout *timeout,nla_parse_nested (tb, l4proto->ctnl_timeout.nlattr_max, attr, l4proto->ctnl_timeout.nla_policy); - ret = l4proto->ctnl_timeout.nlattr_to_obj (tb, &timeout->data); + ret = l4proto->ctnl_timeout.nlattr_to_obj (tb, net, + &timeout->data); }return ret; }
@@ -74,6 +76,7 @@ cttimeout_new_timeout(struct sock *ctnl, struct sk_buff *skb,__u8 l4num;struct nf_conntrack_l4proto *l4proto;struct ctnl_timeout *timeout, *matching =NULL ; +struct net *net =sock_net (skb->sk);char *name;int ret;
@@ -117,7 +120,7 @@ cttimeout_new_timeout(struct sock *ctnl, struct sk_buff *skb, goto err_proto_put; } - ret =ctnl_timeout_parse_policy (matching, l4proto, + ret =ctnl_timeout_parse_policy (matching, l4proto, net, cda[CTA_TIMEOUT_DATA ]);return ret; }
@@ -132,7 +135,7 @@ cttimeout_new_timeout(struct sock *ctnl, struct sk_buff *skb, goto err_proto_put; } - ret =ctnl_timeout_parse_policy (timeout, l4proto, + ret =ctnl_timeout_parse_policy (timeout, l4proto, net, cda[CTA_TIMEOUT_DATA ]);if (ret <0 ) goto err;
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 19/25 netfilter: NFQUEUE: don't xor src/dst ip address for load distribution
In reply to [email protected]From: Florian Westphal <[email protected]>
because reply packets need to go to the same nfqueue, src/dst ip address were xor'd prior to jhash().
However, this causes bad distribution for some workloads, e.g. flows a.b.1.{1,n} -> a.b.2.{1,n} all share the same hash value.
Avoid this by hashing both. To get same hash for replies, first argument is the smaller address.
--- net/netfilter/xt_NFQUEUE.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
net/netfilter/xt_NFQUEUE.c +19 -9
@@ -41,26 +41,36 @@ nfqueue_tg(struct sk_buff *skb, const struct xt_action_param *par)static u32 hash_v4 (const struct sk_buff *skb) {const struct iphdr *iph =ip_hdr (skb); -__be32 ipaddr;/* packets in either direction go into same queue */ - ipaddr = iph->saddr ^ iph->daddr; +if (iph->saddr < iph->daddr) +return jhash_3words ((__force u32 )iph->saddr, + (__force u32 )iph->daddr, iph->protocol, jhash_initval); -return jhash_2words ((__force u32 )ipaddr, iph->protocol, jhash_initval); +return jhash_3words ((__force u32 )iph->daddr, + (__force u32 )iph->saddr, iph->protocol, jhash_initval); }#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )static u32 hash_v6 (const struct sk_buff *skb) {const struct ipv6hdr *ip6h =ipv6_hdr (skb); -__be32 addr[4 ]; +u32 a, b, c; + +if (ip6h->saddr.s6_addr32[3 ] < ip6h->daddr.s6_addr32[3 ]) { + a = (__force u32 ) ip6h->saddr.s6_addr32[3 ]; + b = (__force u32 ) ip6h->daddr.s6_addr32[3 ]; + }else { + b = (__force u32 ) ip6h->saddr.s6_addr32[3 ]; + a = (__force u32 ) ip6h->daddr.s6_addr32[3 ]; + } - addr[0 ] = ip6h->saddr.s6_addr32[0 ] ^ ip6h->daddr.s6_addr32[0 ]; - addr[1 ] = ip6h->saddr.s6_addr32[1 ] ^ ip6h->daddr.s6_addr32[1 ]; - addr[2 ] = ip6h->saddr.s6_addr32[2 ] ^ ip6h->daddr.s6_addr32[2 ]; - addr[3 ] = ip6h->saddr.s6_addr32[3 ] ^ ip6h->daddr.s6_addr32[3 ]; +if (ip6h->saddr.s6_addr32[1 ] < ip6h->daddr.s6_addr32[1 ]) + c = (__force u32 ) ip6h->saddr.s6_addr32[1 ]; +else + c = (__force u32 ) ip6h->daddr.s6_addr32[1 ]; -return jhash2 ((__force u32 *)addr,ARRAY_SIZE (addr), jhash_initval); +return jhash_3words (a, b, c, jhash_initval); }#endif
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 20/25 netfilter: xt_recent: add address masking option
In reply to [email protected]From: Denys Fedoryshchenko <[email protected]>
The mask option allows you put all address belonging that mask into the same recent slot. This can be useful in case that recent is used to detect attacks from the same network segment.
Tested for backward compatibility.
--- Documentation/feature-removal-schedule.txt | 7 ++++ include/linux/netfilter.h | 10 +++++ include/linux/netfilter/xt_recent.h | 10 +++++ net/netfilter/xt_recent.c | 62 ++++++++++++++++++++++++---- 4 files changed, 80 insertions(+), 9 deletions(-)
Documentation/feature-removal-schedule.txt +7 -0
@@ -574,6 +574,13 @@ Why: Remount currently allows changing bound subsystems and ---------------------------- +What: xt_recent rev 0 +When: 2013 +Who: Pablo Neira Ayuso <[email protected]> +Files: net/netfilter/xt_recent.c + +---------------------------- + What: KVM debugfs statistics When: 2013 Why: KVM tracepoints provide mostly equivalent information in a much more
include/linux/netfilter.h +10 -0
@@ -94,6 +94,16 @@ static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1, a1->all[3 ] == a2->all[3 ]; } +static inline void nf_inet_addr_mask (const union nf_inet_addr *a1, +union nf_inet_addr *result, +const union nf_inet_addr *mask) +{ + result->all[0 ] = a1->all[0 ] & mask->all[0 ]; + result->all[1 ] = a1->all[1 ] & mask->all[1 ]; + result->all[2 ] = a1->all[2 ] & mask->all[2 ]; + result->all[3 ] = a1->all[3 ] & mask->all[3 ]; +} +extern void netfilter_init (void );/* Largest hook number + 1 */
include/linux/netfilter/xt_recent.h +10 -0
@@ -32,4 +32,14 @@ struct xt_recent_mtinfo { __u8 side; }; +struct xt_recent_mtinfo_v1 { +__u32 seconds; +__u32 hit_count; +__u8 check_set; +__u8 invert; +char name[XT_RECENT_NAME_LEN ]; +__u8 side; +union nf_inet_addr mask; +}; +#endif /* _LINUX_NETFILTER_XT_RECENT_H */
net/netfilter/xt_recent.c +53 -9
124 lines not on this page · raw message
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 21/25 netfilter: decnet: switch hook PFs to nfproto
In reply to [email protected]From: Alban Crequy <[email protected]>
This patch is a cleanup. Use NFPROTO_* for consistency with other netfilter code.
--- net/decnet/netfilter/dn_rtmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/decnet/netfilter/dn_rtmsg.c +1 -1
@@ -117,7 +117,7 @@ static inline void dnrmg_receive_user_skb(struct sk_buff *skb)static struct nf_hook_ops dnrmg_ops__read_mostly = { .hook = dnrmg_hook, - .pf = PF_DECnet, + .pf =NFPROTO_DECNET , .hooknum =NF_DN_ROUTE , .priority =NF_DN_PRI_DNRTMSG , };
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 22/25 netfilter: bridge: switch hook PFs to nfproto
In reply to [email protected]From: Alban Crequy <[email protected]>
This patch is a cleanup. Use NFPROTO_* for consistency with other netfilter code.
--- net/bridge/br_netfilter.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/bridge/br_netfilter.c +14 -14
@@ -764,9 +764,9 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb,return NF_DROP ;if (IS_IP (skb) ||IS_VLAN_IP (skb) ||IS_PPPOE_IP (skb)) - pf =PF_INET ; + pf =NFPROTO_IPV4 ;else if (IS_IPV6 (skb) ||IS_VLAN_IPV6 (skb) ||IS_PPPOE_IPV6 (skb)) - pf =PF_INET6 ; + pf =NFPROTO_IPV6 ;else return NF_ACCEPT ;
@@ -778,13 +778,13 @@ static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff *skb, nf_bridge->mask |=BRNF_PKT_TYPE ; } -if (pf ==PF_INET &&br_parse_ip_options (skb)) +if (pf ==NFPROTO_IPV4 &&br_parse_ip_options (skb))return NF_DROP ;/* The physdev module checks on this */ nf_bridge->mask |=BRNF_BRIDGED ; nf_bridge->physoutdev = skb->dev; -if (pf ==PF_INET ) +if (pf ==NFPROTO_IPV4 ) skb->protocol =htons (ETH_P_IP );else skb->protocol =htons (ETH_P_IPV6 );
@@ -871,9 +871,9 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,return NF_DROP ;if (IS_IP (skb) ||IS_VLAN_IP (skb) ||IS_PPPOE_IP (skb)) - pf =PF_INET ; + pf =NFPROTO_IPV4 ;else if (IS_IPV6 (skb) ||IS_VLAN_IPV6 (skb) ||IS_PPPOE_IPV6 (skb)) - pf =PF_INET6 ; + pf =NFPROTO_IPV6 ;else return NF_ACCEPT ;
@@ -886,7 +886,7 @@ static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff *skb,nf_bridge_pull_encap_header (skb);nf_bridge_save_header (skb); -if (pf ==PF_INET ) +if (pf ==NFPROTO_IPV4 ) skb->protocol =htons (ETH_P_IP );else skb->protocol =htons (ETH_P_IPV6 );
@@ -919,49 +919,49 @@ static struct nf_hook_ops br_nf_ops[] __read_mostly = { { .hook = br_nf_pre_routing, .owner = THIS_MODULE, - .pf = PF_BRIDGE, + .pf = NFPROTO_BRIDGE, .hooknum = NF_BR_PRE_ROUTING, .priority = NF_BR_PRI_BRNF, }, { .hook = br_nf_local_in, .owner = THIS_MODULE, - .pf = PF_BRIDGE, + .pf = NFPROTO_BRIDGE, .hooknum = NF_BR_LOCAL_IN, .priority = NF_BR_PRI_BRNF, }, { .hook = br_nf_forward_ip, .owner = THIS_MODULE, - .pf = PF_BRIDGE, + .pf = NFPROTO_BRIDGE, .hooknum = NF_BR_FORWARD, .priority = NF_BR_PRI_BRNF - 1, }, { .hook = br_nf_forward_arp, .owner = THIS_MODULE, - .pf = PF_BRIDGE, + .pf = NFPROTO_BRIDGE, .hooknum = NF_BR_FORWARD, .priority = NF_BR_PRI_BRNF, }, { .hook = br_nf_post_routing, .owner = THIS_MODULE, - .pf = PF_BRIDGE, + .pf = NFPROTO_BRIDGE, .hooknum = NF_BR_POST_ROUTING, .priority = NF_BR_PRI_LAST, }, { .hook = ip_sabotage_in, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_PRE_ROUTING, .priority = NF_IP_PRI_FIRST, }, { .hook = ip_sabotage_in, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_PRE_ROUTING, .priority = NF_IP6_PRI_FIRST, },
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 23/25 netfilter: ipv4, defrag: switch hook PFs to nfproto
In reply to [email protected]From: Alban Crequy <[email protected]>
This patch is a cleanup. Use NFPROTO_* for consistency with other netfilter code.
--- net/ipv4/netfilter/nf_defrag_ipv4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_defrag_ipv4.c +2 -2
@@ -94,14 +94,14 @@ static struct nf_hook_ops ipv4_defrag_ops[] = { { .hook = ipv4_conntrack_defrag, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_PRE_ROUTING, .priority = NF_IP_PRI_CONNTRACK_DEFRAG, }, { .hook = ipv4_conntrack_defrag, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_CONNTRACK_DEFRAG, },
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 24/25 netfilter: ipvs: switch hook PFs to nfproto
In reply to [email protected]From: Alban Crequy <[email protected]>
This patch is a cleanup. Use NFPROTO_* for consistency with other netfilter code.
--- net/netfilter/ipvs/ip_vs_core.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +12 -12
@@ -1742,7 +1742,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_reply4, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP_PRI_NAT_SRC - 2, },
@@ -1752,7 +1752,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_remote_request4, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP_PRI_NAT_SRC - 1, },
@@ -1760,7 +1760,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_local_reply4, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_NAT_DST + 1, },
@@ -1768,7 +1768,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_local_request4, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_NAT_DST + 2, },
@@ -1777,7 +1777,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_forward_icmp, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = 99, },
@@ -1785,7 +1785,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_reply4, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = 100, },
@@ -1794,7 +1794,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_reply6, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP6_PRI_NAT_SRC - 2, },
@@ -1804,7 +1804,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_remote_request6, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_IN, .priority = NF_IP6_PRI_NAT_SRC - 1, },
@@ -1812,7 +1812,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_local_reply6, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_NAT_DST + 1, },
@@ -1820,7 +1820,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_local_request6, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP6_PRI_NAT_DST + 2, },
@@ -1829,7 +1829,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_forward_icmp_v6, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = 99, },
@@ -1837,7 +1837,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { { .hook = ip_vs_reply6, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = 100, },
Signature · 1 line
1.7.10
[email protected]
maintainerPATCH 25/25 netfilter: selinux: switch hook PFs to nfproto
In reply to [email protected]From: Alban Crequy <[email protected]>
This patch is a cleanup. Use NFPROTO_* for consistency with other netfilter code.
--- security/selinux/hooks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
security/selinux/hooks.c +5 -5
@@ -5763,21 +5763,21 @@ static struct nf_hook_ops selinux_ipv4_ops[] = { { .hook = selinux_ipv4_postroute, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP_PRI_SELINUX_LAST, }, { .hook = selinux_ipv4_forward, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_FORWARD, .priority = NF_IP_PRI_SELINUX_FIRST, }, { .hook = selinux_ipv4_output, .owner = THIS_MODULE, - .pf = PF_INET, + .pf = NFPROTO_IPV4, .hooknum = NF_INET_LOCAL_OUT, .priority = NF_IP_PRI_SELINUX_FIRST, }
@@ -5789,14 +5789,14 @@ static struct nf_hook_ops selinux_ipv6_ops[] = { { .hook = selinux_ipv6_postroute, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_POST_ROUTING, .priority = NF_IP6_PRI_SELINUX_LAST, }, { .hook = selinux_ipv6_forward, .owner = THIS_MODULE, - .pf = PF_INET6, + .pf = NFPROTO_IPV6, .hooknum = NF_INET_FORWARD, .priority = NF_IP6_PRI_SELINUX_FIRST, }
Signature · 1 line
1.7.10
David Miller
maintainerFrom: [email protected]
Date: Mon, 11 Jun 2012 16:43:36 +0200
Quoted 12 lines
* Netns support for all our
nf_conntracksysctl tweaks, including global timeout adjustment from Gao Feng.* Add fail-open support to NFQUEUE, ie. don't drop packets if the kernel-space nfqueue gets full, instead we allow packets to go through, from Krishna Kumar.
* Remove support for connlimit revision 0, as we already scheduled, from Cong Wang.
* Improve load distribution in NFQUEUE if multi-queue is used from Florian Westphal.
Quoted 6 lines
* Minor cleanups from Alban Crequy to use NFPROTO_* constants instead of PF_* as we do in other parts of the Netfilter code.
You can pull these changes from:
git://1984.lsi.us.es/net-nextmaster
Pulled, thanks Pablo!