netfilter: nf_ct_icmp: add namespace support
authorGao feng <gaofeng@cn.fujitsu.com>
Mon, 28 May 2012 21:04:15 +0000 (21:04 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 7 Jun 2012 12:58:40 +0000 (14:58 +0200)
This patch adds namespace support for ICMPv6 protocol tracker.

Acked-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netns/conntrack.h
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
net/netfilter/nf_conntrack_proto.c

index 3d8e9e3b08a62b82090323d7ec53fed0579e9bbe..3aecdc7a84fb145255d6ae2c8457945d55a3c732 100644 (file)
@@ -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;
index 3e81904fbbcdf09b13c2b830bd40f0b2b7ed313a..f606355200d85f52e105197431c6913b36eebc21 100644 (file)
 
 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,
 };
index dbade5f2b1d3639026abf8820b55e72b1a73cd90..1ea919450fc3b654ab9445cc7d6543adb79bb0fc 100644 (file)
@@ -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: