]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/netfilter/nf_conntrack_netlink.c
netfilter: ctnetlink: add missing netlink attribute policies
[net-next-2.6.git] / net / netfilter / nf_conntrack_netlink.c
index 59d8064eb5224b8b1278c2275b0af31573be3575..5c103b8c7df09c948f82f7f9f57e833ee55f623b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <linux/netfilter.h>
 #include <net/netlink.h>
+#include <net/sock.h>
 #include <net/netfilter/nf_conntrack.h>
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_expect.h>
@@ -456,6 +457,7 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct)
 static int
 ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
 {
+       struct net *net;
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
        struct nlattr *nest_parms;
@@ -482,7 +484,8 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
        } else
                return 0;
 
-       if (!item->report && !nfnetlink_has_listeners(group))
+       net = nf_ct_net(ct);
+       if (!item->report && !nfnetlink_has_listeners(net, group))
                return 0;
 
        skb = nlmsg_new(ctnetlink_nlmsg_size(ct), GFP_ATOMIC);
@@ -559,7 +562,8 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
        rcu_read_unlock();
 
        nlmsg_end(skb, nlh);
-       err = nfnetlink_send(skb, item->pid, group, item->report, GFP_ATOMIC);
+       err = nfnetlink_send(skb, net, item->pid, group, item->report,
+                            GFP_ATOMIC);
        if (err == -ENOBUFS || err == -EAGAIN)
                return -ENOBUFS;
 
@@ -571,7 +575,7 @@ nla_put_failure:
 nlmsg_failure:
        kfree_skb(skb);
 errout:
-       nfnetlink_set_err(0, group, -ENOBUFS);
+       nfnetlink_set_err(net, 0, group, -ENOBUFS);
        return 0;
 }
 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
@@ -586,6 +590,7 @@ static int ctnetlink_done(struct netlink_callback *cb)
 static int
 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = sock_net(skb->sk);
        struct nf_conn *ct, *last;
        struct nf_conntrack_tuple_hash *h;
        struct hlist_nulls_node *n;
@@ -594,9 +599,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 
        rcu_read_lock();
        last = (struct nf_conn *)cb->args[1];
-       for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++) {
+       for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) {
 restart:
-               hlist_nulls_for_each_entry_rcu(h, n, &init_net.ct.hash[cb->args[0]],
+               hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[cb->args[0]],
                                         hnnode) {
                        if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
                                continue;
@@ -703,6 +708,11 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
        return ret;
 }
 
+static const struct nla_policy tuple_nla_policy[CTA_TUPLE_MAX+1] = {
+       [CTA_TUPLE_IP]          = { .type = NLA_NESTED },
+       [CTA_TUPLE_PROTO]       = { .type = NLA_NESTED },
+};
+
 static int
 ctnetlink_parse_tuple(const struct nlattr * const cda[],
                      struct nf_conntrack_tuple *tuple,
@@ -713,7 +723,7 @@ ctnetlink_parse_tuple(const struct nlattr * const cda[],
 
        memset(tuple, 0, sizeof(*tuple));
 
-       nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], NULL);
+       nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], tuple_nla_policy);
 
        if (!tb[CTA_TUPLE_IP])
                return -EINVAL;
@@ -740,12 +750,16 @@ ctnetlink_parse_tuple(const struct nlattr * const cda[],
        return 0;
 }
 
+static const struct nla_policy help_nla_policy[CTA_HELP_MAX+1] = {
+       [CTA_HELP_NAME]         = { .type = NLA_NUL_STRING },
+};
+
 static inline int
 ctnetlink_parse_help(const struct nlattr *attr, char **helper_name)
 {
        struct nlattr *tb[CTA_HELP_MAX+1];
 
-       nla_parse_nested(tb, CTA_HELP_MAX, attr, NULL);
+       nla_parse_nested(tb, CTA_HELP_MAX, attr, help_nla_policy);
 
        if (!tb[CTA_HELP_NAME])
                return -EINVAL;
@@ -756,11 +770,17 @@ ctnetlink_parse_help(const struct nlattr *attr, char **helper_name)
 }
 
 static const struct nla_policy ct_nla_policy[CTA_MAX+1] = {
+       [CTA_TUPLE_ORIG]        = { .type = NLA_NESTED },
+       [CTA_TUPLE_REPLY]       = { .type = NLA_NESTED },
        [CTA_STATUS]            = { .type = NLA_U32 },
+       [CTA_PROTOINFO]         = { .type = NLA_NESTED },
+       [CTA_HELP]              = { .type = NLA_NESTED },
+       [CTA_NAT_SRC]           = { .type = NLA_NESTED },
        [CTA_TIMEOUT]           = { .type = NLA_U32 },
        [CTA_MARK]              = { .type = NLA_U32 },
-       [CTA_USE]               = { .type = NLA_U32 },
        [CTA_ID]                = { .type = NLA_U32 },
+       [CTA_NAT_DST]           = { .type = NLA_NESTED },
+       [CTA_TUPLE_MASTER]      = { .type = NLA_NESTED },
 };
 
 static int
@@ -768,6 +788,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        const struct nlmsghdr *nlh,
                        const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_tuple_hash *h;
        struct nf_conntrack_tuple tuple;
        struct nf_conn *ct;
@@ -781,7 +802,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
                err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
        else {
                /* Flush the whole table */
-               nf_conntrack_flush_report(&init_net,
+               nf_conntrack_flush_report(net,
                                         NETLINK_CB(skb).pid,
                                         nlmsg_report(nlh));
                return 0;
@@ -790,7 +811,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
        if (err < 0)
                return err;
 
-       h = nf_conntrack_find_get(&init_net, &tuple);
+       h = nf_conntrack_find_get(net, &tuple);
        if (!h)
                return -ENOENT;
 
@@ -828,6 +849,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        const struct nlmsghdr *nlh,
                        const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_tuple_hash *h;
        struct nf_conntrack_tuple tuple;
        struct nf_conn *ct;
@@ -850,7 +872,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
        if (err < 0)
                return err;
 
-       h = nf_conntrack_find_get(&init_net, &tuple);
+       h = nf_conntrack_find_get(net, &tuple);
        if (!h)
                return -ENOENT;
 
@@ -994,7 +1016,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
                return 0;
        }
 
-       helper = __nf_conntrack_helper_find_byname(helpname);
+       helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
+                                           nf_ct_protonum(ct));
        if (helper == NULL) {
 #ifdef CONFIG_MODULES
                spin_unlock_bh(&nf_conntrack_lock);
@@ -1005,7 +1028,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
                }
 
                spin_lock_bh(&nf_conntrack_lock);
-               helper = __nf_conntrack_helper_find_byname(helpname);
+               helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
+                                                   nf_ct_protonum(ct));
                if (helper)
                        return -EAGAIN;
 #endif
@@ -1044,6 +1068,12 @@ ctnetlink_change_timeout(struct nf_conn *ct, const struct nlattr * const cda[])
        return 0;
 }
 
+static const struct nla_policy protoinfo_policy[CTA_PROTOINFO_MAX+1] = {
+       [CTA_PROTOINFO_TCP]     = { .type = NLA_NESTED },
+       [CTA_PROTOINFO_DCCP]    = { .type = NLA_NESTED },
+       [CTA_PROTOINFO_SCTP]    = { .type = NLA_NESTED },
+};
+
 static inline int
 ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[])
 {
@@ -1052,7 +1082,7 @@ ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]
        struct nf_conntrack_l4proto *l4proto;
        int err = 0;
 
-       nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, NULL);
+       nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, protoinfo_policy);
 
        rcu_read_lock();
        l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
@@ -1064,12 +1094,18 @@ ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[]
 }
 
 #ifdef CONFIG_NF_NAT_NEEDED
+static const struct nla_policy nat_seq_policy[CTA_NAT_SEQ_MAX+1] = {
+       [CTA_NAT_SEQ_CORRECTION_POS]    = { .type = NLA_U32 },
+       [CTA_NAT_SEQ_OFFSET_BEFORE]     = { .type = NLA_U32 },
+       [CTA_NAT_SEQ_OFFSET_AFTER]      = { .type = NLA_U32 },
+};
+
 static inline int
 change_nat_seq_adj(struct nf_nat_seq *natseq, const struct nlattr * const attr)
 {
        struct nlattr *cda[CTA_NAT_SEQ_MAX+1];
 
-       nla_parse_nested(cda, CTA_NAT_SEQ_MAX, attr, NULL);
+       nla_parse_nested(cda, CTA_NAT_SEQ_MAX, attr, nat_seq_policy);
 
        if (!cda[CTA_NAT_SEQ_CORRECTION_POS])
                return -EINVAL;
@@ -1175,7 +1211,8 @@ ctnetlink_change_conntrack(struct nf_conn *ct,
 }
 
 static struct nf_conn *
-ctnetlink_create_conntrack(const struct nlattr * const cda[],
+ctnetlink_create_conntrack(struct net *net,
+                          const struct nlattr * const cda[],
                           struct nf_conntrack_tuple *otuple,
                           struct nf_conntrack_tuple *rtuple,
                           u8 u3)
@@ -1184,7 +1221,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
        int err = -EINVAL;
        struct nf_conntrack_helper *helper;
 
-       ct = nf_conntrack_alloc(&init_net, otuple, rtuple, GFP_ATOMIC);
+       ct = nf_conntrack_alloc(net, otuple, rtuple, GFP_ATOMIC);
        if (IS_ERR(ct))
                return ERR_PTR(-ENOMEM);
 
@@ -1203,7 +1240,8 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
                if (err < 0)
                        goto err2;
 
-               helper = __nf_conntrack_helper_find_byname(helpname);
+               helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
+                                                   nf_ct_protonum(ct));
                if (helper == NULL) {
                        rcu_read_unlock();
 #ifdef CONFIG_MODULES
@@ -1213,7 +1251,9 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
                        }
 
                        rcu_read_lock();
-                       helper = __nf_conntrack_helper_find_byname(helpname);
+                       helper = __nf_conntrack_helper_find(helpname,
+                                                           nf_ct_l3num(ct),
+                                                           nf_ct_protonum(ct));
                        if (helper) {
                                err = -EAGAIN;
                                goto err2;
@@ -1236,7 +1276,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
                }
        } else {
                /* try an implicit helper assignation */
-               err = __nf_ct_try_assign_helper(ct, GFP_ATOMIC);
+               err = __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
                if (err < 0)
                        goto err2;
        }
@@ -1268,7 +1308,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
        }
 
        nf_ct_acct_ext_add(ct, GFP_ATOMIC);
-       nf_ct_ecache_ext_add(ct, GFP_ATOMIC);
+       nf_ct_ecache_ext_add(ct, 0, 0, GFP_ATOMIC);
 
 #if defined(CONFIG_NF_CONNTRACK_MARK)
        if (cda[CTA_MARK])
@@ -1285,7 +1325,7 @@ ctnetlink_create_conntrack(const struct nlattr * const cda[],
                if (err < 0)
                        goto err2;
 
-               master_h = nf_conntrack_find_get(&init_net, &master);
+               master_h = nf_conntrack_find_get(net, &master);
                if (master_h == NULL) {
                        err = -ENOENT;
                        goto err2;
@@ -1313,6 +1353,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        const struct nlmsghdr *nlh,
                        const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_tuple otuple, rtuple;
        struct nf_conntrack_tuple_hash *h = NULL;
        struct nfgenmsg *nfmsg = nlmsg_data(nlh);
@@ -1333,9 +1374,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 
        spin_lock_bh(&nf_conntrack_lock);
        if (cda[CTA_TUPLE_ORIG])
-               h = __nf_conntrack_find(&init_net, &otuple);
+               h = __nf_conntrack_find(net, &otuple);
        else if (cda[CTA_TUPLE_REPLY])
-               h = __nf_conntrack_find(&init_net, &rtuple);
+               h = __nf_conntrack_find(net, &rtuple);
 
        if (h == NULL) {
                err = -ENOENT;
@@ -1343,7 +1384,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        struct nf_conn *ct;
                        enum ip_conntrack_events events;
 
-                       ct = ctnetlink_create_conntrack(cda, &otuple,
+                       ct = ctnetlink_create_conntrack(net, cda, &otuple,
                                                        &rtuple, u3);
                        if (IS_ERR(ct)) {
                                err = PTR_ERR(ct);
@@ -1357,7 +1398,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        else
                                events = IPCT_NEW;
 
-                       nf_conntrack_eventmask_report((1 << IPCT_STATUS) |
+                       nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
+                                                     (1 << IPCT_ASSURED) |
                                                      (1 << IPCT_HELPER) |
                                                      (1 << IPCT_PROTOINFO) |
                                                      (1 << IPCT_NATSEQADJ) |
@@ -1382,7 +1424,8 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
                if (err == 0) {
                        nf_conntrack_get(&ct->ct_general);
                        spin_unlock_bh(&nf_conntrack_lock);
-                       nf_conntrack_eventmask_report((1 << IPCT_STATUS) |
+                       nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
+                                                     (1 << IPCT_ASSURED) |
                                                      (1 << IPCT_HELPER) |
                                                      (1 << IPCT_PROTOINFO) |
                                                      (1 << IPCT_NATSEQADJ) |
@@ -1437,8 +1480,9 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb,
        struct nlattr *nest_parms;
 
        memset(&m, 0xFF, sizeof(m));
-       m.src.u.all = mask->src.u.all;
        memcpy(&m.src.u3, &mask->src.u3, sizeof(m.src.u3));
+       m.src.u.all = mask->src.u.all;
+       m.dst.protonum = tuple->dst.protonum;
 
        nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED);
        if (!nest_parms)
@@ -1525,9 +1569,10 @@ nla_put_failure:
 static int
 ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
 {
+       struct nf_conntrack_expect *exp = item->exp;
+       struct net *net = nf_ct_exp_net(exp);
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
-       struct nf_conntrack_expect *exp = item->exp;
        struct sk_buff *skb;
        unsigned int type;
        int flags = 0;
@@ -1539,7 +1584,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
                return 0;
 
        if (!item->report &&
-           !nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW))
+           !nfnetlink_has_listeners(net, NFNLGRP_CONNTRACK_EXP_NEW))
                return 0;
 
        skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
@@ -1562,7 +1607,7 @@ ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
        rcu_read_unlock();
 
        nlmsg_end(skb, nlh);
-       nfnetlink_send(skb, item->pid, NFNLGRP_CONNTRACK_EXP_NEW,
+       nfnetlink_send(skb, net, item->pid, NFNLGRP_CONNTRACK_EXP_NEW,
                       item->report, GFP_ATOMIC);
        return 0;
 
@@ -1572,7 +1617,7 @@ nla_put_failure:
 nlmsg_failure:
        kfree_skb(skb);
 errout:
-       nfnetlink_set_err(0, 0, -ENOBUFS);
+       nfnetlink_set_err(net, 0, 0, -ENOBUFS);
        return 0;
 }
 #endif
@@ -1586,7 +1631,7 @@ static int ctnetlink_exp_done(struct netlink_callback *cb)
 static int
 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct net *net = &init_net;
+       struct net *net = sock_net(skb->sk);
        struct nf_conntrack_expect *exp, *last;
        struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
        struct hlist_node *n;
@@ -1630,8 +1675,12 @@ out:
 }
 
 static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = {
+       [CTA_EXPECT_MASTER]     = { .type = NLA_NESTED },
+       [CTA_EXPECT_TUPLE]      = { .type = NLA_NESTED },
+       [CTA_EXPECT_MASK]       = { .type = NLA_NESTED },
        [CTA_EXPECT_TIMEOUT]    = { .type = NLA_U32 },
        [CTA_EXPECT_ID]         = { .type = NLA_U32 },
+       [CTA_EXPECT_HELP_NAME]  = { .type = NLA_NUL_STRING },
 };
 
 static int
@@ -1639,6 +1688,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
                     const struct nlmsghdr *nlh,
                     const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_tuple tuple;
        struct nf_conntrack_expect *exp;
        struct sk_buff *skb2;
@@ -1660,7 +1710,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
        if (err < 0)
                return err;
 
-       exp = nf_ct_expect_find_get(&init_net, &tuple);
+       exp = nf_ct_expect_find_get(net, &tuple);
        if (!exp)
                return -ENOENT;
 
@@ -1700,9 +1750,9 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
                     const struct nlmsghdr *nlh,
                     const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_expect *exp;
        struct nf_conntrack_tuple tuple;
-       struct nf_conntrack_helper *h;
        struct nfgenmsg *nfmsg = nlmsg_data(nlh);
        struct hlist_node *n, *next;
        u_int8_t u3 = nfmsg->nfgen_family;
@@ -1716,7 +1766,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
                        return err;
 
                /* bump usage count to 2 */
-               exp = nf_ct_expect_find_get(&init_net, &tuple);
+               exp = nf_ct_expect_find_get(net, &tuple);
                if (!exp)
                        return -ENOENT;
 
@@ -1739,18 +1789,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
 
                /* delete all expectations for this helper */
                spin_lock_bh(&nf_conntrack_lock);
-               h = __nf_conntrack_helper_find_byname(name);
-               if (!h) {
-                       spin_unlock_bh(&nf_conntrack_lock);
-                       return -EOPNOTSUPP;
-               }
                for (i = 0; i < nf_ct_expect_hsize; i++) {
                        hlist_for_each_entry_safe(exp, n, next,
-                                                 &init_net.ct.expect_hash[i],
+                                                 &net->ct.expect_hash[i],
                                                  hnode) {
                                m_help = nfct_help(exp->master);
-                               if (m_help->helper == h
-                                   && del_timer(&exp->timeout)) {
+                               if (!strcmp(m_help->helper->name, name) &&
+                                   del_timer(&exp->timeout)) {
                                        nf_ct_unlink_expect(exp);
                                        nf_ct_expect_put(exp);
                                }
@@ -1762,7 +1807,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
                spin_lock_bh(&nf_conntrack_lock);
                for (i = 0; i < nf_ct_expect_hsize; i++) {
                        hlist_for_each_entry_safe(exp, n, next,
-                                                 &init_net.ct.expect_hash[i],
+                                                 &net->ct.expect_hash[i],
                                                  hnode) {
                                if (del_timer(&exp->timeout)) {
                                        nf_ct_unlink_expect(exp);
@@ -1783,7 +1828,8 @@ ctnetlink_change_expect(struct nf_conntrack_expect *x,
 }
 
 static int
-ctnetlink_create_expect(const struct nlattr * const cda[], u_int8_t u3,
+ctnetlink_create_expect(struct net *net, const struct nlattr * const cda[],
+                       u_int8_t u3,
                        u32 pid, int report)
 {
        struct nf_conntrack_tuple tuple, mask, master_tuple;
@@ -1805,7 +1851,7 @@ ctnetlink_create_expect(const struct nlattr * const cda[], u_int8_t u3,
                return err;
 
        /* Look for master conntrack of this expectation */
-       h = nf_conntrack_find_get(&init_net, &master_tuple);
+       h = nf_conntrack_find_get(net, &master_tuple);
        if (!h)
                return -ENOENT;
        ct = nf_ct_tuplehash_to_ctrack(h);
@@ -1845,6 +1891,7 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
                     const struct nlmsghdr *nlh,
                     const struct nlattr * const cda[])
 {
+       struct net *net = sock_net(ctnl);
        struct nf_conntrack_tuple tuple;
        struct nf_conntrack_expect *exp;
        struct nfgenmsg *nfmsg = nlmsg_data(nlh);
@@ -1861,13 +1908,13 @@ ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
                return err;
 
        spin_lock_bh(&nf_conntrack_lock);
-       exp = __nf_ct_expect_find(&init_net, &tuple);
+       exp = __nf_ct_expect_find(net, &tuple);
 
        if (!exp) {
                spin_unlock_bh(&nf_conntrack_lock);
                err = -ENOENT;
                if (nlh->nlmsg_flags & NLM_F_CREATE) {
-                       err = ctnetlink_create_expect(cda,
+                       err = ctnetlink_create_expect(net, cda,
                                                      u3,
                                                      NETLINK_CB(skb).pid,
                                                      nlmsg_report(nlh));