1 /* Connection tracking via netlink socket. Allows for user space
2 * protocol helpers and general trouble making from userspace.
4 * (C) 2001 by Jay Schulist <jschlst@samba.org>
5 * (C) 2002-2006 by Harald Welte <laforge@gnumonks.org>
6 * (C) 2003 by Patrick Mchardy <kaber@trash.net>
7 * (C) 2005-2012 by Pablo Neira Ayuso <pablo@netfilter.org>
9 * Initial connection tracking via netlink development funded and
10 * generally made possible by Network Robots, Inc. (www.networkrobots.com)
12 * Further development of this code funded by Astaro AG (http://www.astaro.com)
14 * This software may be used and distributed according to the terms
15 * of the GNU General Public License, incorporated herein by reference.
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/rculist.h>
22 #include <linux/rculist_nulls.h>
23 #include <linux/types.h>
24 #include <linux/timer.h>
25 #include <linux/security.h>
26 #include <linux/skbuff.h>
27 #include <linux/errno.h>
28 #include <linux/netlink.h>
29 #include <linux/spinlock.h>
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
33 #include <linux/netfilter.h>
34 #include <net/netlink.h>
36 #include <net/netfilter/nf_conntrack.h>
37 #include <net/netfilter/nf_conntrack_core.h>
38 #include <net/netfilter/nf_conntrack_expect.h>
39 #include <net/netfilter/nf_conntrack_helper.h>
40 #include <net/netfilter/nf_conntrack_seqadj.h>
41 #include <net/netfilter/nf_conntrack_l3proto.h>
42 #include <net/netfilter/nf_conntrack_l4proto.h>
43 #include <net/netfilter/nf_conntrack_tuple.h>
44 #include <net/netfilter/nf_conntrack_acct.h>
45 #include <net/netfilter/nf_conntrack_zones.h>
46 #include <net/netfilter/nf_conntrack_timestamp.h>
47 #include <net/netfilter/nf_conntrack_labels.h>
48 #ifdef CONFIG_NF_NAT_NEEDED
49 #include <net/netfilter/nf_nat_core.h>
50 #include <net/netfilter/nf_nat_l4proto.h>
51 #include <net/netfilter/nf_nat_helper.h>
54 #include <linux/netfilter/nfnetlink.h>
55 #include <linux/netfilter/nfnetlink_conntrack.h>
57 MODULE_LICENSE("GPL");
59 static char __initdata version[] = "0.93";
62 ctnetlink_dump_tuples_proto(struct sk_buff *skb,
63 const struct nf_conntrack_tuple *tuple,
64 struct nf_conntrack_l4proto *l4proto)
67 struct nlattr *nest_parms;
69 nest_parms = nla_nest_start(skb, CTA_TUPLE_PROTO | NLA_F_NESTED);
72 if (nla_put_u8(skb, CTA_PROTO_NUM, tuple->dst.protonum))
75 if (likely(l4proto->tuple_to_nlattr))
76 ret = l4proto->tuple_to_nlattr(skb, tuple);
78 nla_nest_end(skb, nest_parms);
87 ctnetlink_dump_tuples_ip(struct sk_buff *skb,
88 const struct nf_conntrack_tuple *tuple,
89 struct nf_conntrack_l3proto *l3proto)
92 struct nlattr *nest_parms;
94 nest_parms = nla_nest_start(skb, CTA_TUPLE_IP | NLA_F_NESTED);
98 if (likely(l3proto->tuple_to_nlattr))
99 ret = l3proto->tuple_to_nlattr(skb, tuple);
101 nla_nest_end(skb, nest_parms);
110 ctnetlink_dump_tuples(struct sk_buff *skb,
111 const struct nf_conntrack_tuple *tuple)
114 struct nf_conntrack_l3proto *l3proto;
115 struct nf_conntrack_l4proto *l4proto;
118 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
119 ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
122 l4proto = __nf_ct_l4proto_find(tuple->src.l3num,
123 tuple->dst.protonum);
124 ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto);
131 ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct)
133 if (nla_put_be32(skb, CTA_STATUS, htonl(ct->status)))
134 goto nla_put_failure;
142 ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)
144 long timeout = ((long)ct->timeout.expires - (long)jiffies) / HZ;
149 if (nla_put_be32(skb, CTA_TIMEOUT, htonl(timeout)))
150 goto nla_put_failure;
158 ctnetlink_dump_protoinfo(struct sk_buff *skb, struct nf_conn *ct)
160 struct nf_conntrack_l4proto *l4proto;
161 struct nlattr *nest_proto;
164 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
165 if (!l4proto->to_nlattr)
168 nest_proto = nla_nest_start(skb, CTA_PROTOINFO | NLA_F_NESTED);
170 goto nla_put_failure;
172 ret = l4proto->to_nlattr(skb, nest_proto, ct);
174 nla_nest_end(skb, nest_proto);
183 ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
185 struct nlattr *nest_helper;
186 const struct nf_conn_help *help = nfct_help(ct);
187 struct nf_conntrack_helper *helper;
192 helper = rcu_dereference(help->helper);
196 nest_helper = nla_nest_start(skb, CTA_HELP | NLA_F_NESTED);
198 goto nla_put_failure;
199 if (nla_put_string(skb, CTA_HELP_NAME, helper->name))
200 goto nla_put_failure;
202 if (helper->to_nlattr)
203 helper->to_nlattr(skb, ct);
205 nla_nest_end(skb, nest_helper);
214 dump_counters(struct sk_buff *skb, struct nf_conn_acct *acct,
215 enum ip_conntrack_dir dir, int type)
217 enum ctattr_type attr = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
218 struct nf_conn_counter *counter = acct->counter;
219 struct nlattr *nest_count;
222 if (type == IPCTNL_MSG_CT_GET_CTRZERO) {
223 pkts = atomic64_xchg(&counter[dir].packets, 0);
224 bytes = atomic64_xchg(&counter[dir].bytes, 0);
226 pkts = atomic64_read(&counter[dir].packets);
227 bytes = atomic64_read(&counter[dir].bytes);
230 nest_count = nla_nest_start(skb, attr | NLA_F_NESTED);
232 goto nla_put_failure;
234 if (nla_put_be64(skb, CTA_COUNTERS_PACKETS, cpu_to_be64(pkts)) ||
235 nla_put_be64(skb, CTA_COUNTERS_BYTES, cpu_to_be64(bytes)))
236 goto nla_put_failure;
238 nla_nest_end(skb, nest_count);
247 ctnetlink_dump_acct(struct sk_buff *skb, const struct nf_conn *ct, int type)
249 struct nf_conn_acct *acct = nf_conn_acct_find(ct);
254 if (dump_counters(skb, acct, IP_CT_DIR_ORIGINAL, type) < 0)
256 if (dump_counters(skb, acct, IP_CT_DIR_REPLY, type) < 0)
263 ctnetlink_dump_timestamp(struct sk_buff *skb, const struct nf_conn *ct)
265 struct nlattr *nest_count;
266 const struct nf_conn_tstamp *tstamp;
268 tstamp = nf_conn_tstamp_find(ct);
272 nest_count = nla_nest_start(skb, CTA_TIMESTAMP | NLA_F_NESTED);
274 goto nla_put_failure;
276 if (nla_put_be64(skb, CTA_TIMESTAMP_START, cpu_to_be64(tstamp->start)) ||
277 (tstamp->stop != 0 && nla_put_be64(skb, CTA_TIMESTAMP_STOP,
278 cpu_to_be64(tstamp->stop))))
279 goto nla_put_failure;
280 nla_nest_end(skb, nest_count);
288 #ifdef CONFIG_NF_CONNTRACK_MARK
290 ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct)
292 if (nla_put_be32(skb, CTA_MARK, htonl(ct->mark)))
293 goto nla_put_failure;
300 #define ctnetlink_dump_mark(a, b) (0)
303 #ifdef CONFIG_NF_CONNTRACK_SECMARK
305 ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
307 struct nlattr *nest_secctx;
311 ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
316 nest_secctx = nla_nest_start(skb, CTA_SECCTX | NLA_F_NESTED);
318 goto nla_put_failure;
320 if (nla_put_string(skb, CTA_SECCTX_NAME, secctx))
321 goto nla_put_failure;
322 nla_nest_end(skb, nest_secctx);
326 security_release_secctx(secctx, len);
330 #define ctnetlink_dump_secctx(a, b) (0)
333 #ifdef CONFIG_NF_CONNTRACK_LABELS
334 static int ctnetlink_label_size(const struct nf_conn *ct)
336 struct nf_conn_labels *labels = nf_ct_labels_find(ct);
340 return nla_total_size(labels->words * sizeof(long));
344 ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)
346 struct nf_conn_labels *labels = nf_ct_labels_find(ct);
352 len = labels->words * sizeof(long);
355 if (labels->bits[i] != 0)
356 return nla_put(skb, CTA_LABELS, len, labels->bits);
358 } while (i < labels->words);
363 #define ctnetlink_dump_labels(a, b) (0)
364 #define ctnetlink_label_size(a) (0)
367 #define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
370 ctnetlink_dump_master(struct sk_buff *skb, const struct nf_conn *ct)
372 struct nlattr *nest_parms;
374 if (!(ct->status & IPS_EXPECTED))
377 nest_parms = nla_nest_start(skb, CTA_TUPLE_MASTER | NLA_F_NESTED);
379 goto nla_put_failure;
380 if (ctnetlink_dump_tuples(skb, master_tuple(ct)) < 0)
381 goto nla_put_failure;
382 nla_nest_end(skb, nest_parms);
391 dump_ct_seq_adj(struct sk_buff *skb, const struct nf_ct_seqadj *seq, int type)
393 struct nlattr *nest_parms;
395 nest_parms = nla_nest_start(skb, type | NLA_F_NESTED);
397 goto nla_put_failure;
399 if (nla_put_be32(skb, CTA_SEQADJ_CORRECTION_POS,
400 htonl(seq->correction_pos)) ||
401 nla_put_be32(skb, CTA_SEQADJ_OFFSET_BEFORE,
402 htonl(seq->offset_before)) ||
403 nla_put_be32(skb, CTA_SEQADJ_OFFSET_AFTER,
404 htonl(seq->offset_after)))
405 goto nla_put_failure;
407 nla_nest_end(skb, nest_parms);
416 ctnetlink_dump_ct_seq_adj(struct sk_buff *skb, const struct nf_conn *ct)
418 struct nf_conn_seqadj *seqadj = nfct_seqadj(ct);
419 struct nf_ct_seqadj *seq;
421 if (!(ct->status & IPS_SEQ_ADJUST) || !seqadj)
424 seq = &seqadj->seq[IP_CT_DIR_ORIGINAL];
425 if (dump_ct_seq_adj(skb, seq, CTA_SEQ_ADJ_ORIG) == -1)
428 seq = &seqadj->seq[IP_CT_DIR_REPLY];
429 if (dump_ct_seq_adj(skb, seq, CTA_SEQ_ADJ_REPLY) == -1)
436 ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
438 if (nla_put_be32(skb, CTA_ID, htonl((unsigned long)ct)))
439 goto nla_put_failure;
447 ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct)
449 if (nla_put_be32(skb, CTA_USE, htonl(atomic_read(&ct->ct_general.use))))
450 goto nla_put_failure;
458 ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
461 struct nlmsghdr *nlh;
462 struct nfgenmsg *nfmsg;
463 struct nlattr *nest_parms;
464 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
466 event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_NEW);
467 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
471 nfmsg = nlmsg_data(nlh);
472 nfmsg->nfgen_family = nf_ct_l3num(ct);
473 nfmsg->version = NFNETLINK_V0;
476 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
478 goto nla_put_failure;
479 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
480 goto nla_put_failure;
481 nla_nest_end(skb, nest_parms);
483 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED);
485 goto nla_put_failure;
486 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
487 goto nla_put_failure;
488 nla_nest_end(skb, nest_parms);
490 if (nf_ct_zone(ct) &&
491 nla_put_be16(skb, CTA_ZONE, htons(nf_ct_zone(ct))))
492 goto nla_put_failure;
494 if (ctnetlink_dump_status(skb, ct) < 0 ||
495 ctnetlink_dump_timeout(skb, ct) < 0 ||
496 ctnetlink_dump_acct(skb, ct, type) < 0 ||
497 ctnetlink_dump_timestamp(skb, ct) < 0 ||
498 ctnetlink_dump_protoinfo(skb, ct) < 0 ||
499 ctnetlink_dump_helpinfo(skb, ct) < 0 ||
500 ctnetlink_dump_mark(skb, ct) < 0 ||
501 ctnetlink_dump_secctx(skb, ct) < 0 ||
502 ctnetlink_dump_labels(skb, ct) < 0 ||
503 ctnetlink_dump_id(skb, ct) < 0 ||
504 ctnetlink_dump_use(skb, ct) < 0 ||
505 ctnetlink_dump_master(skb, ct) < 0 ||
506 ctnetlink_dump_ct_seq_adj(skb, ct) < 0)
507 goto nla_put_failure;
514 nlmsg_cancel(skb, nlh);
519 ctnetlink_proto_size(const struct nf_conn *ct)
521 struct nf_conntrack_l3proto *l3proto;
522 struct nf_conntrack_l4proto *l4proto;
526 l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
527 len += l3proto->nla_size;
529 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
530 len += l4proto->nla_size;
537 ctnetlink_acct_size(const struct nf_conn *ct)
539 if (!nf_ct_ext_exist(ct, NF_CT_EXT_ACCT))
541 return 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */
542 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_PACKETS */
543 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_BYTES */
548 ctnetlink_secctx_size(const struct nf_conn *ct)
550 #ifdef CONFIG_NF_CONNTRACK_SECMARK
553 ret = security_secid_to_secctx(ct->secmark, NULL, &len);
557 return nla_total_size(0) /* CTA_SECCTX */
558 + nla_total_size(sizeof(char) * len); /* CTA_SECCTX_NAME */
565 ctnetlink_timestamp_size(const struct nf_conn *ct)
567 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
568 if (!nf_ct_ext_exist(ct, NF_CT_EXT_TSTAMP))
570 return nla_total_size(0) + 2 * nla_total_size(sizeof(uint64_t));
577 ctnetlink_nlmsg_size(const struct nf_conn *ct)
579 return NLMSG_ALIGN(sizeof(struct nfgenmsg))
580 + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */
581 + 3 * nla_total_size(0) /* CTA_TUPLE_IP */
582 + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */
583 + 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */
584 + nla_total_size(sizeof(u_int32_t)) /* CTA_ID */
585 + nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */
586 + ctnetlink_acct_size(ct)
587 + ctnetlink_timestamp_size(ct)
588 + nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */
589 + nla_total_size(0) /* CTA_PROTOINFO */
590 + nla_total_size(0) /* CTA_HELP */
591 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
592 + ctnetlink_secctx_size(ct)
593 #ifdef CONFIG_NF_NAT_NEEDED
594 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
595 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */
597 #ifdef CONFIG_NF_CONNTRACK_MARK
598 + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */
600 + ctnetlink_proto_size(ct)
601 + ctnetlink_label_size(ct)
605 #ifdef CONFIG_NF_CONNTRACK_EVENTS
607 ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
610 struct nlmsghdr *nlh;
611 struct nfgenmsg *nfmsg;
612 struct nlattr *nest_parms;
613 struct nf_conn *ct = item->ct;
616 unsigned int flags = 0, group;
619 /* ignore our fake conntrack entry */
620 if (nf_ct_is_untracked(ct))
623 if (events & (1 << IPCT_DESTROY)) {
624 type = IPCTNL_MSG_CT_DELETE;
625 group = NFNLGRP_CONNTRACK_DESTROY;
626 } else if (events & ((1 << IPCT_NEW) | (1 << IPCT_RELATED))) {
627 type = IPCTNL_MSG_CT_NEW;
628 flags = NLM_F_CREATE|NLM_F_EXCL;
629 group = NFNLGRP_CONNTRACK_NEW;
631 type = IPCTNL_MSG_CT_NEW;
632 group = NFNLGRP_CONNTRACK_UPDATE;
637 if (!item->report && !nfnetlink_has_listeners(net, group))
640 skb = nlmsg_new(ctnetlink_nlmsg_size(ct), GFP_ATOMIC);
644 type |= NFNL_SUBSYS_CTNETLINK << 8;
645 nlh = nlmsg_put(skb, item->portid, 0, type, sizeof(*nfmsg), flags);
649 nfmsg = nlmsg_data(nlh);
650 nfmsg->nfgen_family = nf_ct_l3num(ct);
651 nfmsg->version = NFNETLINK_V0;
655 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
657 goto nla_put_failure;
658 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
659 goto nla_put_failure;
660 nla_nest_end(skb, nest_parms);
662 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED);
664 goto nla_put_failure;
665 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
666 goto nla_put_failure;
667 nla_nest_end(skb, nest_parms);
669 if (nf_ct_zone(ct) &&
670 nla_put_be16(skb, CTA_ZONE, htons(nf_ct_zone(ct))))
671 goto nla_put_failure;
673 if (ctnetlink_dump_id(skb, ct) < 0)
674 goto nla_put_failure;
676 if (ctnetlink_dump_status(skb, ct) < 0)
677 goto nla_put_failure;
679 if (events & (1 << IPCT_DESTROY)) {
680 if (ctnetlink_dump_acct(skb, ct, type) < 0 ||
681 ctnetlink_dump_timestamp(skb, ct) < 0)
682 goto nla_put_failure;
684 if (ctnetlink_dump_timeout(skb, ct) < 0)
685 goto nla_put_failure;
687 if (events & (1 << IPCT_PROTOINFO)
688 && ctnetlink_dump_protoinfo(skb, ct) < 0)
689 goto nla_put_failure;
691 if ((events & (1 << IPCT_HELPER) || nfct_help(ct))
692 && ctnetlink_dump_helpinfo(skb, ct) < 0)
693 goto nla_put_failure;
695 #ifdef CONFIG_NF_CONNTRACK_SECMARK
696 if ((events & (1 << IPCT_SECMARK) || ct->secmark)
697 && ctnetlink_dump_secctx(skb, ct) < 0)
698 goto nla_put_failure;
700 if (events & (1 << IPCT_LABEL) &&
701 ctnetlink_dump_labels(skb, ct) < 0)
702 goto nla_put_failure;
704 if (events & (1 << IPCT_RELATED) &&
705 ctnetlink_dump_master(skb, ct) < 0)
706 goto nla_put_failure;
708 if (events & (1 << IPCT_SEQADJ) &&
709 ctnetlink_dump_ct_seq_adj(skb, ct) < 0)
710 goto nla_put_failure;
713 #ifdef CONFIG_NF_CONNTRACK_MARK
714 if ((events & (1 << IPCT_MARK) || ct->mark)
715 && ctnetlink_dump_mark(skb, ct) < 0)
716 goto nla_put_failure;
721 err = nfnetlink_send(skb, net, item->portid, group, item->report,
723 if (err == -ENOBUFS || err == -EAGAIN)
730 nlmsg_cancel(skb, nlh);
734 if (nfnetlink_set_err(net, 0, group, -ENOBUFS) > 0)
739 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
741 static int ctnetlink_done(struct netlink_callback *cb)
744 nf_ct_put((struct nf_conn *)cb->args[1]);
750 struct ctnetlink_dump_filter {
758 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
760 struct net *net = sock_net(skb->sk);
761 struct nf_conn *ct, *last;
762 struct nf_conntrack_tuple_hash *h;
763 struct hlist_nulls_node *n;
764 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
765 u_int8_t l3proto = nfmsg->nfgen_family;
769 #ifdef CONFIG_NF_CONNTRACK_MARK
770 const struct ctnetlink_dump_filter *filter = cb->data;
773 last = (struct nf_conn *)cb->args[1];
776 for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) {
778 lockp = &nf_conntrack_locks[cb->args[0] % CONNTRACK_LOCKS];
780 if (cb->args[0] >= net->ct.htable_size) {
784 hlist_nulls_for_each_entry(h, n, &net->ct.hash[cb->args[0]],
786 if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
788 ct = nf_ct_tuplehash_to_ctrack(h);
789 /* Dump entries of a given L3 protocol number.
790 * If it is not specified, ie. l3proto == 0,
791 * then dump everything. */
792 if (l3proto && nf_ct_l3num(ct) != l3proto)
799 #ifdef CONFIG_NF_CONNTRACK_MARK
800 if (filter && !((ct->mark & filter->mark.mask) ==
807 ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).portid,
809 NFNL_MSG_TYPE(cb->nlh->nlmsg_type),
813 nf_conntrack_get(&ct->ct_general);
814 cb->args[1] = (unsigned long)ct;
834 ctnetlink_parse_tuple_ip(struct nlattr *attr, struct nf_conntrack_tuple *tuple)
836 struct nlattr *tb[CTA_IP_MAX+1];
837 struct nf_conntrack_l3proto *l3proto;
840 ret = nla_parse_nested(tb, CTA_IP_MAX, attr, NULL);
845 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
847 if (likely(l3proto->nlattr_to_tuple)) {
848 ret = nla_validate_nested(attr, CTA_IP_MAX,
849 l3proto->nla_policy);
851 ret = l3proto->nlattr_to_tuple(tb, tuple);
859 static const struct nla_policy proto_nla_policy[CTA_PROTO_MAX+1] = {
860 [CTA_PROTO_NUM] = { .type = NLA_U8 },
864 ctnetlink_parse_tuple_proto(struct nlattr *attr,
865 struct nf_conntrack_tuple *tuple)
867 struct nlattr *tb[CTA_PROTO_MAX+1];
868 struct nf_conntrack_l4proto *l4proto;
871 ret = nla_parse_nested(tb, CTA_PROTO_MAX, attr, proto_nla_policy);
875 if (!tb[CTA_PROTO_NUM])
877 tuple->dst.protonum = nla_get_u8(tb[CTA_PROTO_NUM]);
880 l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum);
882 if (likely(l4proto->nlattr_to_tuple)) {
883 ret = nla_validate_nested(attr, CTA_PROTO_MAX,
884 l4proto->nla_policy);
886 ret = l4proto->nlattr_to_tuple(tb, tuple);
894 static const struct nla_policy tuple_nla_policy[CTA_TUPLE_MAX+1] = {
895 [CTA_TUPLE_IP] = { .type = NLA_NESTED },
896 [CTA_TUPLE_PROTO] = { .type = NLA_NESTED },
900 ctnetlink_parse_tuple(const struct nlattr * const cda[],
901 struct nf_conntrack_tuple *tuple,
902 enum ctattr_type type, u_int8_t l3num)
904 struct nlattr *tb[CTA_TUPLE_MAX+1];
907 memset(tuple, 0, sizeof(*tuple));
909 err = nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], tuple_nla_policy);
913 if (!tb[CTA_TUPLE_IP])
916 tuple->src.l3num = l3num;
918 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP], tuple);
922 if (!tb[CTA_TUPLE_PROTO])
925 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO], tuple);
929 /* orig and expect tuples get DIR_ORIGINAL */
930 if (type == CTA_TUPLE_REPLY)
931 tuple->dst.dir = IP_CT_DIR_REPLY;
933 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
939 ctnetlink_parse_zone(const struct nlattr *attr, u16 *zone)
942 #ifdef CONFIG_NF_CONNTRACK_ZONES
943 *zone = ntohs(nla_get_be16(attr));
953 static const struct nla_policy help_nla_policy[CTA_HELP_MAX+1] = {
954 [CTA_HELP_NAME] = { .type = NLA_NUL_STRING,
955 .len = NF_CT_HELPER_NAME_LEN - 1 },
959 ctnetlink_parse_help(const struct nlattr *attr, char **helper_name,
960 struct nlattr **helpinfo)
963 struct nlattr *tb[CTA_HELP_MAX+1];
965 err = nla_parse_nested(tb, CTA_HELP_MAX, attr, help_nla_policy);
969 if (!tb[CTA_HELP_NAME])
972 *helper_name = nla_data(tb[CTA_HELP_NAME]);
974 if (tb[CTA_HELP_INFO])
975 *helpinfo = tb[CTA_HELP_INFO];
980 static const struct nla_policy ct_nla_policy[CTA_MAX+1] = {
981 [CTA_TUPLE_ORIG] = { .type = NLA_NESTED },
982 [CTA_TUPLE_REPLY] = { .type = NLA_NESTED },
983 [CTA_STATUS] = { .type = NLA_U32 },
984 [CTA_PROTOINFO] = { .type = NLA_NESTED },
985 [CTA_HELP] = { .type = NLA_NESTED },
986 [CTA_NAT_SRC] = { .type = NLA_NESTED },
987 [CTA_TIMEOUT] = { .type = NLA_U32 },
988 [CTA_MARK] = { .type = NLA_U32 },
989 [CTA_ID] = { .type = NLA_U32 },
990 [CTA_NAT_DST] = { .type = NLA_NESTED },
991 [CTA_TUPLE_MASTER] = { .type = NLA_NESTED },
992 [CTA_NAT_SEQ_ADJ_ORIG] = { .type = NLA_NESTED },
993 [CTA_NAT_SEQ_ADJ_REPLY] = { .type = NLA_NESTED },
994 [CTA_ZONE] = { .type = NLA_U16 },
995 [CTA_MARK_MASK] = { .type = NLA_U32 },
996 [CTA_LABELS] = { .type = NLA_BINARY,
997 .len = NF_CT_LABELS_MAX_SIZE },
998 [CTA_LABELS_MASK] = { .type = NLA_BINARY,
999 .len = NF_CT_LABELS_MAX_SIZE },
1003 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
1004 const struct nlmsghdr *nlh,
1005 const struct nlattr * const cda[])
1007 struct net *net = sock_net(ctnl);
1008 struct nf_conntrack_tuple_hash *h;
1009 struct nf_conntrack_tuple tuple;
1011 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1012 u_int8_t u3 = nfmsg->nfgen_family;
1016 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
1020 if (cda[CTA_TUPLE_ORIG])
1021 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
1022 else if (cda[CTA_TUPLE_REPLY])
1023 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
1025 /* Flush the whole table */
1026 nf_conntrack_flush_report(net,
1027 NETLINK_CB(skb).portid,
1035 h = nf_conntrack_find_get(net, zone, &tuple);
1039 ct = nf_ct_tuplehash_to_ctrack(h);
1042 u_int32_t id = ntohl(nla_get_be32(cda[CTA_ID]));
1043 if (id != (u32)(unsigned long)ct) {
1049 if (del_timer(&ct->timeout))
1050 nf_ct_delete(ct, NETLINK_CB(skb).portid, nlmsg_report(nlh));
1058 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
1059 const struct nlmsghdr *nlh,
1060 const struct nlattr * const cda[])
1062 struct net *net = sock_net(ctnl);
1063 struct nf_conntrack_tuple_hash *h;
1064 struct nf_conntrack_tuple tuple;
1066 struct sk_buff *skb2 = NULL;
1067 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1068 u_int8_t u3 = nfmsg->nfgen_family;
1072 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1073 struct netlink_dump_control c = {
1074 .dump = ctnetlink_dump_table,
1075 .done = ctnetlink_done,
1077 #ifdef CONFIG_NF_CONNTRACK_MARK
1078 if (cda[CTA_MARK] && cda[CTA_MARK_MASK]) {
1079 struct ctnetlink_dump_filter *filter;
1081 filter = kzalloc(sizeof(struct ctnetlink_dump_filter),
1086 filter->mark.val = ntohl(nla_get_be32(cda[CTA_MARK]));
1088 ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
1092 return netlink_dump_start(ctnl, skb, nlh, &c);
1095 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
1099 if (cda[CTA_TUPLE_ORIG])
1100 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
1101 else if (cda[CTA_TUPLE_REPLY])
1102 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
1109 h = nf_conntrack_find_get(net, zone, &tuple);
1113 ct = nf_ct_tuplehash_to_ctrack(h);
1116 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1123 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
1124 NFNL_MSG_TYPE(nlh->nlmsg_type), ct);
1130 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT);
1139 /* this avoids a loop in nfnetlink. */
1140 return err == -EAGAIN ? -ENOBUFS : err;
1143 static int ctnetlink_done_list(struct netlink_callback *cb)
1146 nf_ct_put((struct nf_conn *)cb->args[1]);
1151 ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying)
1153 struct nf_conn *ct, *last;
1154 struct nf_conntrack_tuple_hash *h;
1155 struct hlist_nulls_node *n;
1156 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
1157 u_int8_t l3proto = nfmsg->nfgen_family;
1160 struct hlist_nulls_head *list;
1161 struct net *net = sock_net(skb->sk);
1166 last = (struct nf_conn *)cb->args[1];
1168 for (cpu = cb->args[0]; cpu < nr_cpu_ids; cpu++) {
1169 struct ct_pcpu *pcpu;
1171 if (!cpu_possible(cpu))
1174 pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu);
1175 spin_lock_bh(&pcpu->lock);
1176 list = dying ? &pcpu->dying : &pcpu->unconfirmed;
1178 hlist_nulls_for_each_entry(h, n, list, hnnode) {
1179 ct = nf_ct_tuplehash_to_ctrack(h);
1180 if (l3proto && nf_ct_l3num(ct) != l3proto)
1188 res = ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).portid,
1190 NFNL_MSG_TYPE(cb->nlh->nlmsg_type),
1194 if (!atomic_inc_not_zero(&ct->ct_general.use))
1197 cb->args[1] = (unsigned long)ct;
1198 spin_unlock_bh(&pcpu->lock);
1206 spin_unlock_bh(&pcpu->lock);
1217 ctnetlink_dump_dying(struct sk_buff *skb, struct netlink_callback *cb)
1219 return ctnetlink_dump_list(skb, cb, true);
1223 ctnetlink_get_ct_dying(struct sock *ctnl, struct sk_buff *skb,
1224 const struct nlmsghdr *nlh,
1225 const struct nlattr * const cda[])
1227 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1228 struct netlink_dump_control c = {
1229 .dump = ctnetlink_dump_dying,
1230 .done = ctnetlink_done_list,
1232 return netlink_dump_start(ctnl, skb, nlh, &c);
1239 ctnetlink_dump_unconfirmed(struct sk_buff *skb, struct netlink_callback *cb)
1241 return ctnetlink_dump_list(skb, cb, false);
1245 ctnetlink_get_ct_unconfirmed(struct sock *ctnl, struct sk_buff *skb,
1246 const struct nlmsghdr *nlh,
1247 const struct nlattr * const cda[])
1249 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1250 struct netlink_dump_control c = {
1251 .dump = ctnetlink_dump_unconfirmed,
1252 .done = ctnetlink_done_list,
1254 return netlink_dump_start(ctnl, skb, nlh, &c);
1260 #ifdef CONFIG_NF_NAT_NEEDED
1262 ctnetlink_parse_nat_setup(struct nf_conn *ct,
1263 enum nf_nat_manip_type manip,
1264 const struct nlattr *attr)
1266 typeof(nfnetlink_parse_nat_setup_hook) parse_nat_setup;
1269 parse_nat_setup = rcu_dereference(nfnetlink_parse_nat_setup_hook);
1270 if (!parse_nat_setup) {
1271 #ifdef CONFIG_MODULES
1273 nfnl_unlock(NFNL_SUBSYS_CTNETLINK);
1274 if (request_module("nf-nat") < 0) {
1275 nfnl_lock(NFNL_SUBSYS_CTNETLINK);
1279 nfnl_lock(NFNL_SUBSYS_CTNETLINK);
1281 if (nfnetlink_parse_nat_setup_hook)
1287 err = parse_nat_setup(ct, manip, attr);
1288 if (err == -EAGAIN) {
1289 #ifdef CONFIG_MODULES
1291 nfnl_unlock(NFNL_SUBSYS_CTNETLINK);
1292 if (request_module("nf-nat-%u", nf_ct_l3num(ct)) < 0) {
1293 nfnl_lock(NFNL_SUBSYS_CTNETLINK);
1297 nfnl_lock(NFNL_SUBSYS_CTNETLINK);
1308 ctnetlink_change_status(struct nf_conn *ct, const struct nlattr * const cda[])
1311 unsigned int status = ntohl(nla_get_be32(cda[CTA_STATUS]));
1312 d = ct->status ^ status;
1314 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
1318 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
1319 /* SEEN_REPLY bit can only be set */
1322 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
1323 /* ASSURED bit can only be set */
1326 /* Be careful here, modifying NAT bits can screw up things,
1327 * so don't let users modify them directly if they don't pass
1329 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
1334 ctnetlink_setup_nat(struct nf_conn *ct, const struct nlattr * const cda[])
1336 #ifdef CONFIG_NF_NAT_NEEDED
1339 if (!cda[CTA_NAT_DST] && !cda[CTA_NAT_SRC])
1342 ret = ctnetlink_parse_nat_setup(ct, NF_NAT_MANIP_DST,
1347 ret = ctnetlink_parse_nat_setup(ct, NF_NAT_MANIP_SRC,
1351 if (!cda[CTA_NAT_DST] && !cda[CTA_NAT_SRC])
1358 ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
1360 struct nf_conntrack_helper *helper;
1361 struct nf_conn_help *help = nfct_help(ct);
1362 char *helpname = NULL;
1363 struct nlattr *helpinfo = NULL;
1366 /* don't change helper of sibling connections */
1370 err = ctnetlink_parse_help(cda[CTA_HELP], &helpname, &helpinfo);
1374 if (!strcmp(helpname, "")) {
1375 if (help && help->helper) {
1376 /* we had a helper before ... */
1377 nf_ct_remove_expectations(ct);
1378 RCU_INIT_POINTER(help->helper, NULL);
1384 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1385 nf_ct_protonum(ct));
1386 if (helper == NULL) {
1387 #ifdef CONFIG_MODULES
1388 spin_unlock_bh(&nf_conntrack_expect_lock);
1390 if (request_module("nfct-helper-%s", helpname) < 0) {
1391 spin_lock_bh(&nf_conntrack_expect_lock);
1395 spin_lock_bh(&nf_conntrack_expect_lock);
1396 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1397 nf_ct_protonum(ct));
1405 if (help->helper == helper) {
1406 /* update private helper data if allowed. */
1407 if (helper->from_nlattr)
1408 helper->from_nlattr(helpinfo, ct);
1414 /* we cannot set a helper for an existing conntrack */
1419 ctnetlink_change_timeout(struct nf_conn *ct, const struct nlattr * const cda[])
1421 u_int32_t timeout = ntohl(nla_get_be32(cda[CTA_TIMEOUT]));
1423 if (!del_timer(&ct->timeout))
1426 ct->timeout.expires = jiffies + timeout * HZ;
1427 add_timer(&ct->timeout);
1432 static const struct nla_policy protoinfo_policy[CTA_PROTOINFO_MAX+1] = {
1433 [CTA_PROTOINFO_TCP] = { .type = NLA_NESTED },
1434 [CTA_PROTOINFO_DCCP] = { .type = NLA_NESTED },
1435 [CTA_PROTOINFO_SCTP] = { .type = NLA_NESTED },
1439 ctnetlink_change_protoinfo(struct nf_conn *ct, const struct nlattr * const cda[])
1441 const struct nlattr *attr = cda[CTA_PROTOINFO];
1442 struct nlattr *tb[CTA_PROTOINFO_MAX+1];
1443 struct nf_conntrack_l4proto *l4proto;
1446 err = nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, protoinfo_policy);
1451 l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
1452 if (l4proto->from_nlattr)
1453 err = l4proto->from_nlattr(tb, ct);
1459 static const struct nla_policy seqadj_policy[CTA_SEQADJ_MAX+1] = {
1460 [CTA_SEQADJ_CORRECTION_POS] = { .type = NLA_U32 },
1461 [CTA_SEQADJ_OFFSET_BEFORE] = { .type = NLA_U32 },
1462 [CTA_SEQADJ_OFFSET_AFTER] = { .type = NLA_U32 },
1466 change_seq_adj(struct nf_ct_seqadj *seq, const struct nlattr * const attr)
1469 struct nlattr *cda[CTA_SEQADJ_MAX+1];
1471 err = nla_parse_nested(cda, CTA_SEQADJ_MAX, attr, seqadj_policy);
1475 if (!cda[CTA_SEQADJ_CORRECTION_POS])
1478 seq->correction_pos =
1479 ntohl(nla_get_be32(cda[CTA_SEQADJ_CORRECTION_POS]));
1481 if (!cda[CTA_SEQADJ_OFFSET_BEFORE])
1484 seq->offset_before =
1485 ntohl(nla_get_be32(cda[CTA_SEQADJ_OFFSET_BEFORE]));
1487 if (!cda[CTA_SEQADJ_OFFSET_AFTER])
1491 ntohl(nla_get_be32(cda[CTA_SEQADJ_OFFSET_AFTER]));
1497 ctnetlink_change_seq_adj(struct nf_conn *ct,
1498 const struct nlattr * const cda[])
1500 struct nf_conn_seqadj *seqadj = nfct_seqadj(ct);
1506 if (cda[CTA_SEQ_ADJ_ORIG]) {
1507 ret = change_seq_adj(&seqadj->seq[IP_CT_DIR_ORIGINAL],
1508 cda[CTA_SEQ_ADJ_ORIG]);
1512 ct->status |= IPS_SEQ_ADJUST;
1515 if (cda[CTA_SEQ_ADJ_REPLY]) {
1516 ret = change_seq_adj(&seqadj->seq[IP_CT_DIR_REPLY],
1517 cda[CTA_SEQ_ADJ_REPLY]);
1521 ct->status |= IPS_SEQ_ADJUST;
1528 ctnetlink_attach_labels(struct nf_conn *ct, const struct nlattr * const cda[])
1530 #ifdef CONFIG_NF_CONNTRACK_LABELS
1531 size_t len = nla_len(cda[CTA_LABELS]);
1532 const void *mask = cda[CTA_LABELS_MASK];
1534 if (len & (sizeof(u32)-1)) /* must be multiple of u32 */
1538 if (nla_len(cda[CTA_LABELS_MASK]) == 0 ||
1539 nla_len(cda[CTA_LABELS_MASK]) != len)
1541 mask = nla_data(cda[CTA_LABELS_MASK]);
1546 return nf_connlabels_replace(ct, nla_data(cda[CTA_LABELS]), mask, len);
1553 ctnetlink_change_conntrack(struct nf_conn *ct,
1554 const struct nlattr * const cda[])
1558 /* only allow NAT changes and master assignation for new conntracks */
1559 if (cda[CTA_NAT_SRC] || cda[CTA_NAT_DST] || cda[CTA_TUPLE_MASTER])
1562 if (cda[CTA_HELP]) {
1563 err = ctnetlink_change_helper(ct, cda);
1568 if (cda[CTA_TIMEOUT]) {
1569 err = ctnetlink_change_timeout(ct, cda);
1574 if (cda[CTA_STATUS]) {
1575 err = ctnetlink_change_status(ct, cda);
1580 if (cda[CTA_PROTOINFO]) {
1581 err = ctnetlink_change_protoinfo(ct, cda);
1586 #if defined(CONFIG_NF_CONNTRACK_MARK)
1588 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
1591 if (cda[CTA_SEQ_ADJ_ORIG] || cda[CTA_SEQ_ADJ_REPLY]) {
1592 err = ctnetlink_change_seq_adj(ct, cda);
1597 if (cda[CTA_LABELS]) {
1598 err = ctnetlink_attach_labels(ct, cda);
1606 static struct nf_conn *
1607 ctnetlink_create_conntrack(struct net *net, u16 zone,
1608 const struct nlattr * const cda[],
1609 struct nf_conntrack_tuple *otuple,
1610 struct nf_conntrack_tuple *rtuple,
1615 struct nf_conntrack_helper *helper;
1616 struct nf_conn_tstamp *tstamp;
1618 ct = nf_conntrack_alloc(net, zone, otuple, rtuple, GFP_ATOMIC);
1620 return ERR_PTR(-ENOMEM);
1622 if (!cda[CTA_TIMEOUT])
1624 ct->timeout.expires = ntohl(nla_get_be32(cda[CTA_TIMEOUT]));
1626 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1629 if (cda[CTA_HELP]) {
1630 char *helpname = NULL;
1631 struct nlattr *helpinfo = NULL;
1633 err = ctnetlink_parse_help(cda[CTA_HELP], &helpname, &helpinfo);
1637 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1638 nf_ct_protonum(ct));
1639 if (helper == NULL) {
1641 #ifdef CONFIG_MODULES
1642 if (request_module("nfct-helper-%s", helpname) < 0) {
1648 helper = __nf_conntrack_helper_find(helpname,
1650 nf_ct_protonum(ct));
1660 struct nf_conn_help *help;
1662 help = nf_ct_helper_ext_add(ct, helper, GFP_ATOMIC);
1667 /* set private helper data if allowed. */
1668 if (helper->from_nlattr)
1669 helper->from_nlattr(helpinfo, ct);
1671 /* not in hash table yet so not strictly necessary */
1672 RCU_INIT_POINTER(help->helper, helper);
1675 /* try an implicit helper assignation */
1676 err = __nf_ct_try_assign_helper(ct, NULL, GFP_ATOMIC);
1681 err = ctnetlink_setup_nat(ct, cda);
1685 nf_ct_acct_ext_add(ct, GFP_ATOMIC);
1686 nf_ct_tstamp_ext_add(ct, GFP_ATOMIC);
1687 nf_ct_ecache_ext_add(ct, 0, 0, GFP_ATOMIC);
1688 nf_ct_labels_ext_add(ct);
1690 /* we must add conntrack extensions before confirmation. */
1691 ct->status |= IPS_CONFIRMED;
1693 if (cda[CTA_STATUS]) {
1694 err = ctnetlink_change_status(ct, cda);
1699 if (cda[CTA_SEQ_ADJ_ORIG] || cda[CTA_SEQ_ADJ_REPLY]) {
1700 err = ctnetlink_change_seq_adj(ct, cda);
1705 memset(&ct->proto, 0, sizeof(ct->proto));
1706 if (cda[CTA_PROTOINFO]) {
1707 err = ctnetlink_change_protoinfo(ct, cda);
1712 #if defined(CONFIG_NF_CONNTRACK_MARK)
1714 ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
1717 /* setup master conntrack: this is a confirmed expectation */
1718 if (cda[CTA_TUPLE_MASTER]) {
1719 struct nf_conntrack_tuple master;
1720 struct nf_conntrack_tuple_hash *master_h;
1721 struct nf_conn *master_ct;
1723 err = ctnetlink_parse_tuple(cda, &master, CTA_TUPLE_MASTER, u3);
1727 master_h = nf_conntrack_find_get(net, zone, &master);
1728 if (master_h == NULL) {
1732 master_ct = nf_ct_tuplehash_to_ctrack(master_h);
1733 __set_bit(IPS_EXPECTED_BIT, &ct->status);
1734 ct->master = master_ct;
1736 tstamp = nf_conn_tstamp_find(ct);
1738 tstamp->start = ktime_to_ns(ktime_get_real());
1740 err = nf_conntrack_hash_check_insert(ct);
1751 nf_conntrack_free(ct);
1752 return ERR_PTR(err);
1756 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1757 const struct nlmsghdr *nlh,
1758 const struct nlattr * const cda[])
1760 struct net *net = sock_net(ctnl);
1761 struct nf_conntrack_tuple otuple, rtuple;
1762 struct nf_conntrack_tuple_hash *h = NULL;
1763 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1765 u_int8_t u3 = nfmsg->nfgen_family;
1769 err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
1773 if (cda[CTA_TUPLE_ORIG]) {
1774 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
1779 if (cda[CTA_TUPLE_REPLY]) {
1780 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
1785 if (cda[CTA_TUPLE_ORIG])
1786 h = nf_conntrack_find_get(net, zone, &otuple);
1787 else if (cda[CTA_TUPLE_REPLY])
1788 h = nf_conntrack_find_get(net, zone, &rtuple);
1792 if (nlh->nlmsg_flags & NLM_F_CREATE) {
1793 enum ip_conntrack_events events;
1795 if (!cda[CTA_TUPLE_ORIG] || !cda[CTA_TUPLE_REPLY])
1798 ct = ctnetlink_create_conntrack(net, zone, cda, &otuple,
1804 if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1805 events = IPCT_RELATED;
1809 if (cda[CTA_LABELS] &&
1810 ctnetlink_attach_labels(ct, cda) == 0)
1811 events |= (1 << IPCT_LABEL);
1813 nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
1814 (1 << IPCT_ASSURED) |
1815 (1 << IPCT_HELPER) |
1816 (1 << IPCT_PROTOINFO) |
1817 (1 << IPCT_SEQADJ) |
1818 (1 << IPCT_MARK) | events,
1819 ct, NETLINK_CB(skb).portid,
1826 /* implicit 'else' */
1829 ct = nf_ct_tuplehash_to_ctrack(h);
1830 if (!(nlh->nlmsg_flags & NLM_F_EXCL)) {
1831 spin_lock_bh(&nf_conntrack_expect_lock);
1832 err = ctnetlink_change_conntrack(ct, cda);
1833 spin_unlock_bh(&nf_conntrack_expect_lock);
1835 nf_conntrack_eventmask_report((1 << IPCT_REPLY) |
1836 (1 << IPCT_ASSURED) |
1837 (1 << IPCT_HELPER) |
1839 (1 << IPCT_PROTOINFO) |
1840 (1 << IPCT_SEQADJ) |
1842 ct, NETLINK_CB(skb).portid,
1852 ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
1853 __u16 cpu, const struct ip_conntrack_stat *st)
1855 struct nlmsghdr *nlh;
1856 struct nfgenmsg *nfmsg;
1857 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
1859 event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS_CPU);
1860 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
1864 nfmsg = nlmsg_data(nlh);
1865 nfmsg->nfgen_family = AF_UNSPEC;
1866 nfmsg->version = NFNETLINK_V0;
1867 nfmsg->res_id = htons(cpu);
1869 if (nla_put_be32(skb, CTA_STATS_SEARCHED, htonl(st->searched)) ||
1870 nla_put_be32(skb, CTA_STATS_FOUND, htonl(st->found)) ||
1871 nla_put_be32(skb, CTA_STATS_NEW, htonl(st->new)) ||
1872 nla_put_be32(skb, CTA_STATS_INVALID, htonl(st->invalid)) ||
1873 nla_put_be32(skb, CTA_STATS_IGNORE, htonl(st->ignore)) ||
1874 nla_put_be32(skb, CTA_STATS_DELETE, htonl(st->delete)) ||
1875 nla_put_be32(skb, CTA_STATS_DELETE_LIST, htonl(st->delete_list)) ||
1876 nla_put_be32(skb, CTA_STATS_INSERT, htonl(st->insert)) ||
1877 nla_put_be32(skb, CTA_STATS_INSERT_FAILED,
1878 htonl(st->insert_failed)) ||
1879 nla_put_be32(skb, CTA_STATS_DROP, htonl(st->drop)) ||
1880 nla_put_be32(skb, CTA_STATS_EARLY_DROP, htonl(st->early_drop)) ||
1881 nla_put_be32(skb, CTA_STATS_ERROR, htonl(st->error)) ||
1882 nla_put_be32(skb, CTA_STATS_SEARCH_RESTART,
1883 htonl(st->search_restart)))
1884 goto nla_put_failure;
1886 nlmsg_end(skb, nlh);
1891 nlmsg_cancel(skb, nlh);
1896 ctnetlink_ct_stat_cpu_dump(struct sk_buff *skb, struct netlink_callback *cb)
1899 struct net *net = sock_net(skb->sk);
1901 if (cb->args[0] == nr_cpu_ids)
1904 for (cpu = cb->args[0]; cpu < nr_cpu_ids; cpu++) {
1905 const struct ip_conntrack_stat *st;
1907 if (!cpu_possible(cpu))
1910 st = per_cpu_ptr(net->ct.stat, cpu);
1911 if (ctnetlink_ct_stat_cpu_fill_info(skb,
1912 NETLINK_CB(cb->skb).portid,
1923 ctnetlink_stat_ct_cpu(struct sock *ctnl, struct sk_buff *skb,
1924 const struct nlmsghdr *nlh,
1925 const struct nlattr * const cda[])
1927 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1928 struct netlink_dump_control c = {
1929 .dump = ctnetlink_ct_stat_cpu_dump,
1931 return netlink_dump_start(ctnl, skb, nlh, &c);
1938 ctnetlink_stat_ct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
1941 struct nlmsghdr *nlh;
1942 struct nfgenmsg *nfmsg;
1943 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
1944 unsigned int nr_conntracks = atomic_read(&net->ct.count);
1946 event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS);
1947 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
1951 nfmsg = nlmsg_data(nlh);
1952 nfmsg->nfgen_family = AF_UNSPEC;
1953 nfmsg->version = NFNETLINK_V0;
1956 if (nla_put_be32(skb, CTA_STATS_GLOBAL_ENTRIES, htonl(nr_conntracks)))
1957 goto nla_put_failure;
1959 nlmsg_end(skb, nlh);
1964 nlmsg_cancel(skb, nlh);
1969 ctnetlink_stat_ct(struct sock *ctnl, struct sk_buff *skb,
1970 const struct nlmsghdr *nlh,
1971 const struct nlattr * const cda[])
1973 struct sk_buff *skb2;
1976 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1980 err = ctnetlink_stat_ct_fill_info(skb2, NETLINK_CB(skb).portid,
1982 NFNL_MSG_TYPE(nlh->nlmsg_type),
1987 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT);
1996 /* this avoids a loop in nfnetlink. */
1997 return err == -EAGAIN ? -ENOBUFS : err;
2000 static const struct nla_policy exp_nla_policy[CTA_EXPECT_MAX+1] = {
2001 [CTA_EXPECT_MASTER] = { .type = NLA_NESTED },
2002 [CTA_EXPECT_TUPLE] = { .type = NLA_NESTED },
2003 [CTA_EXPECT_MASK] = { .type = NLA_NESTED },
2004 [CTA_EXPECT_TIMEOUT] = { .type = NLA_U32 },
2005 [CTA_EXPECT_ID] = { .type = NLA_U32 },
2006 [CTA_EXPECT_HELP_NAME] = { .type = NLA_NUL_STRING,
2007 .len = NF_CT_HELPER_NAME_LEN - 1 },
2008 [CTA_EXPECT_ZONE] = { .type = NLA_U16 },
2009 [CTA_EXPECT_FLAGS] = { .type = NLA_U32 },
2010 [CTA_EXPECT_CLASS] = { .type = NLA_U32 },
2011 [CTA_EXPECT_NAT] = { .type = NLA_NESTED },
2012 [CTA_EXPECT_FN] = { .type = NLA_NUL_STRING },
2015 static struct nf_conntrack_expect *
2016 ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct,
2017 struct nf_conntrack_helper *helper,
2018 struct nf_conntrack_tuple *tuple,
2019 struct nf_conntrack_tuple *mask);
2021 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT
2023 ctnetlink_nfqueue_build_size(const struct nf_conn *ct)
2025 return 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */
2026 + 3 * nla_total_size(0) /* CTA_TUPLE_IP */
2027 + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */
2028 + 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */
2029 + nla_total_size(sizeof(u_int32_t)) /* CTA_ID */
2030 + nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */
2031 + nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */
2032 + nla_total_size(0) /* CTA_PROTOINFO */
2033 + nla_total_size(0) /* CTA_HELP */
2034 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
2035 + ctnetlink_secctx_size(ct)
2036 #ifdef CONFIG_NF_NAT_NEEDED
2037 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
2038 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */
2040 #ifdef CONFIG_NF_CONNTRACK_MARK
2041 + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */
2043 + ctnetlink_proto_size(ct)
2048 ctnetlink_nfqueue_build(struct sk_buff *skb, struct nf_conn *ct)
2050 struct nlattr *nest_parms;
2053 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED);
2055 goto nla_put_failure;
2056 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
2057 goto nla_put_failure;
2058 nla_nest_end(skb, nest_parms);
2060 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED);
2062 goto nla_put_failure;
2063 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
2064 goto nla_put_failure;
2065 nla_nest_end(skb, nest_parms);
2067 if (nf_ct_zone(ct)) {
2068 if (nla_put_be16(skb, CTA_ZONE, htons(nf_ct_zone(ct))))
2069 goto nla_put_failure;
2072 if (ctnetlink_dump_id(skb, ct) < 0)
2073 goto nla_put_failure;
2075 if (ctnetlink_dump_status(skb, ct) < 0)
2076 goto nla_put_failure;
2078 if (ctnetlink_dump_timeout(skb, ct) < 0)
2079 goto nla_put_failure;
2081 if (ctnetlink_dump_protoinfo(skb, ct) < 0)
2082 goto nla_put_failure;
2084 if (ctnetlink_dump_helpinfo(skb, ct) < 0)
2085 goto nla_put_failure;
2087 #ifdef CONFIG_NF_CONNTRACK_SECMARK
2088 if (ct->secmark && ctnetlink_dump_secctx(skb, ct) < 0)
2089 goto nla_put_failure;
2091 if (ct->master && ctnetlink_dump_master(skb, ct) < 0)
2092 goto nla_put_failure;
2094 if ((ct->status & IPS_SEQ_ADJUST) &&
2095 ctnetlink_dump_ct_seq_adj(skb, ct) < 0)
2096 goto nla_put_failure;
2098 #ifdef CONFIG_NF_CONNTRACK_MARK
2099 if (ct->mark && ctnetlink_dump_mark(skb, ct) < 0)
2100 goto nla_put_failure;
2102 if (ctnetlink_dump_labels(skb, ct) < 0)
2103 goto nla_put_failure;
2113 ctnetlink_nfqueue_parse_ct(const struct nlattr *cda[], struct nf_conn *ct)
2117 if (cda[CTA_TIMEOUT]) {
2118 err = ctnetlink_change_timeout(ct, cda);
2122 if (cda[CTA_STATUS]) {
2123 err = ctnetlink_change_status(ct, cda);
2127 if (cda[CTA_HELP]) {
2128 err = ctnetlink_change_helper(ct, cda);
2132 if (cda[CTA_LABELS]) {
2133 err = ctnetlink_attach_labels(ct, cda);
2137 #if defined(CONFIG_NF_CONNTRACK_MARK)
2138 if (cda[CTA_MARK]) {
2139 u32 mask = 0, mark, newmark;
2140 if (cda[CTA_MARK_MASK])
2141 mask = ~ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
2143 mark = ntohl(nla_get_be32(cda[CTA_MARK]));
2144 newmark = (ct->mark & mask) ^ mark;
2145 if (newmark != ct->mark)
2153 ctnetlink_nfqueue_parse(const struct nlattr *attr, struct nf_conn *ct)
2155 struct nlattr *cda[CTA_MAX+1];
2158 ret = nla_parse_nested(cda, CTA_MAX, attr, ct_nla_policy);
2162 spin_lock_bh(&nf_conntrack_expect_lock);
2163 ret = ctnetlink_nfqueue_parse_ct((const struct nlattr **)cda, ct);
2164 spin_unlock_bh(&nf_conntrack_expect_lock);
2169 static int ctnetlink_nfqueue_exp_parse(const struct nlattr * const *cda,
2170 const struct nf_conn *ct,
2171 struct nf_conntrack_tuple *tuple,
2172 struct nf_conntrack_tuple *mask)
2176 err = ctnetlink_parse_tuple(cda, tuple, CTA_EXPECT_TUPLE,
2181 return ctnetlink_parse_tuple(cda, mask, CTA_EXPECT_MASK,
2186 ctnetlink_nfqueue_attach_expect(const struct nlattr *attr, struct nf_conn *ct,
2187 u32 portid, u32 report)
2189 struct nlattr *cda[CTA_EXPECT_MAX+1];
2190 struct nf_conntrack_tuple tuple, mask;
2191 struct nf_conntrack_helper *helper = NULL;
2192 struct nf_conntrack_expect *exp;
2195 err = nla_parse_nested(cda, CTA_EXPECT_MAX, attr, exp_nla_policy);
2199 err = ctnetlink_nfqueue_exp_parse((const struct nlattr * const *)cda,
2204 if (cda[CTA_EXPECT_HELP_NAME]) {
2205 const char *helpname = nla_data(cda[CTA_EXPECT_HELP_NAME]);
2207 helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
2208 nf_ct_protonum(ct));
2213 exp = ctnetlink_alloc_expect((const struct nlattr * const *)cda, ct,
2214 helper, &tuple, &mask);
2216 return PTR_ERR(exp);
2218 err = nf_ct_expect_related_report(exp, portid, report);
2220 nf_ct_expect_put(exp);
2227 static struct nfq_ct_hook ctnetlink_nfqueue_hook = {
2228 .build_size = ctnetlink_nfqueue_build_size,
2229 .build = ctnetlink_nfqueue_build,
2230 .parse = ctnetlink_nfqueue_parse,
2231 .attach_expect = ctnetlink_nfqueue_attach_expect,
2232 .seq_adjust = nf_ct_tcp_seqadj_set,
2234 #endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT */
2236 /***********************************************************************
2238 ***********************************************************************/
2241 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
2242 const struct nf_conntrack_tuple *tuple,
2243 enum ctattr_expect type)
2245 struct nlattr *nest_parms;
2247 nest_parms = nla_nest_start(skb, type | NLA_F_NESTED);
2249 goto nla_put_failure;
2250 if (ctnetlink_dump_tuples(skb, tuple) < 0)
2251 goto nla_put_failure;
2252 nla_nest_end(skb, nest_parms);
2261 ctnetlink_exp_dump_mask(struct sk_buff *skb,
2262 const struct nf_conntrack_tuple *tuple,
2263 const struct nf_conntrack_tuple_mask *mask)
2266 struct nf_conntrack_l3proto *l3proto;
2267 struct nf_conntrack_l4proto *l4proto;
2268 struct nf_conntrack_tuple m;
2269 struct nlattr *nest_parms;
2271 memset(&m, 0xFF, sizeof(m));
2272 memcpy(&m.src.u3, &mask->src.u3, sizeof(m.src.u3));
2273 m.src.u.all = mask->src.u.all;
2274 m.dst.protonum = tuple->dst.protonum;
2276 nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED);
2278 goto nla_put_failure;
2281 l3proto = __nf_ct_l3proto_find(tuple->src.l3num);
2282 ret = ctnetlink_dump_tuples_ip(skb, &m, l3proto);
2284 l4proto = __nf_ct_l4proto_find(tuple->src.l3num,
2285 tuple->dst.protonum);
2286 ret = ctnetlink_dump_tuples_proto(skb, &m, l4proto);
2290 if (unlikely(ret < 0))
2291 goto nla_put_failure;
2293 nla_nest_end(skb, nest_parms);
2301 static const union nf_inet_addr any_addr;
2304 ctnetlink_exp_dump_expect(struct sk_buff *skb,
2305 const struct nf_conntrack_expect *exp)
2307 struct nf_conn *master = exp->master;
2308 long timeout = ((long)exp->timeout.expires - (long)jiffies) / HZ;
2309 struct nf_conn_help *help;
2310 #ifdef CONFIG_NF_NAT_NEEDED
2311 struct nlattr *nest_parms;
2312 struct nf_conntrack_tuple nat_tuple = {};
2314 struct nf_ct_helper_expectfn *expfn;
2319 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
2320 goto nla_put_failure;
2321 if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
2322 goto nla_put_failure;
2323 if (ctnetlink_exp_dump_tuple(skb,
2324 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
2325 CTA_EXPECT_MASTER) < 0)
2326 goto nla_put_failure;
2328 #ifdef CONFIG_NF_NAT_NEEDED
2329 if (!nf_inet_addr_cmp(&exp->saved_addr, &any_addr) ||
2330 exp->saved_proto.all) {
2331 nest_parms = nla_nest_start(skb, CTA_EXPECT_NAT | NLA_F_NESTED);
2333 goto nla_put_failure;
2335 if (nla_put_be32(skb, CTA_EXPECT_NAT_DIR, htonl(exp->dir)))
2336 goto nla_put_failure;
2338 nat_tuple.src.l3num = nf_ct_l3num(master);
2339 nat_tuple.src.u3 = exp->saved_addr;
2340 nat_tuple.dst.protonum = nf_ct_protonum(master);
2341 nat_tuple.src.u = exp->saved_proto;
2343 if (ctnetlink_exp_dump_tuple(skb, &nat_tuple,
2344 CTA_EXPECT_NAT_TUPLE) < 0)
2345 goto nla_put_failure;
2346 nla_nest_end(skb, nest_parms);
2349 if (nla_put_be32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)) ||
2350 nla_put_be32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp)) ||
2351 nla_put_be32(skb, CTA_EXPECT_FLAGS, htonl(exp->flags)) ||
2352 nla_put_be32(skb, CTA_EXPECT_CLASS, htonl(exp->class)))
2353 goto nla_put_failure;
2354 help = nfct_help(master);
2356 struct nf_conntrack_helper *helper;
2358 helper = rcu_dereference(help->helper);
2360 nla_put_string(skb, CTA_EXPECT_HELP_NAME, helper->name))
2361 goto nla_put_failure;
2363 expfn = nf_ct_helper_expectfn_find_by_symbol(exp->expectfn);
2364 if (expfn != NULL &&
2365 nla_put_string(skb, CTA_EXPECT_FN, expfn->name))
2366 goto nla_put_failure;
2375 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
2376 int event, const struct nf_conntrack_expect *exp)
2378 struct nlmsghdr *nlh;
2379 struct nfgenmsg *nfmsg;
2380 unsigned int flags = portid ? NLM_F_MULTI : 0;
2382 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
2383 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
2387 nfmsg = nlmsg_data(nlh);
2388 nfmsg->nfgen_family = exp->tuple.src.l3num;
2389 nfmsg->version = NFNETLINK_V0;
2392 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
2393 goto nla_put_failure;
2395 nlmsg_end(skb, nlh);
2400 nlmsg_cancel(skb, nlh);
2404 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2406 ctnetlink_expect_event(unsigned int events, struct nf_exp_event *item)
2408 struct nf_conntrack_expect *exp = item->exp;
2409 struct net *net = nf_ct_exp_net(exp);
2410 struct nlmsghdr *nlh;
2411 struct nfgenmsg *nfmsg;
2412 struct sk_buff *skb;
2413 unsigned int type, group;
2416 if (events & (1 << IPEXP_DESTROY)) {
2417 type = IPCTNL_MSG_EXP_DELETE;
2418 group = NFNLGRP_CONNTRACK_EXP_DESTROY;
2419 } else if (events & (1 << IPEXP_NEW)) {
2420 type = IPCTNL_MSG_EXP_NEW;
2421 flags = NLM_F_CREATE|NLM_F_EXCL;
2422 group = NFNLGRP_CONNTRACK_EXP_NEW;
2426 if (!item->report && !nfnetlink_has_listeners(net, group))
2429 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
2433 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
2434 nlh = nlmsg_put(skb, item->portid, 0, type, sizeof(*nfmsg), flags);
2438 nfmsg = nlmsg_data(nlh);
2439 nfmsg->nfgen_family = exp->tuple.src.l3num;
2440 nfmsg->version = NFNETLINK_V0;
2444 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
2445 goto nla_put_failure;
2448 nlmsg_end(skb, nlh);
2449 nfnetlink_send(skb, net, item->portid, group, item->report, GFP_ATOMIC);
2454 nlmsg_cancel(skb, nlh);
2458 nfnetlink_set_err(net, 0, 0, -ENOBUFS);
2462 static int ctnetlink_exp_done(struct netlink_callback *cb)
2465 nf_ct_expect_put((struct nf_conntrack_expect *)cb->args[1]);
2470 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
2472 struct net *net = sock_net(skb->sk);
2473 struct nf_conntrack_expect *exp, *last;
2474 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
2475 u_int8_t l3proto = nfmsg->nfgen_family;
2478 last = (struct nf_conntrack_expect *)cb->args[1];
2479 for (; cb->args[0] < nf_ct_expect_hsize; cb->args[0]++) {
2481 hlist_for_each_entry(exp, &net->ct.expect_hash[cb->args[0]],
2483 if (l3proto && exp->tuple.src.l3num != l3proto)
2490 if (ctnetlink_exp_fill_info(skb,
2491 NETLINK_CB(cb->skb).portid,
2495 if (!atomic_inc_not_zero(&exp->use))
2497 cb->args[1] = (unsigned long)exp;
2509 nf_ct_expect_put(last);
2515 ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
2517 struct nf_conntrack_expect *exp, *last;
2518 struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
2519 struct nf_conn *ct = cb->data;
2520 struct nf_conn_help *help = nfct_help(ct);
2521 u_int8_t l3proto = nfmsg->nfgen_family;
2527 last = (struct nf_conntrack_expect *)cb->args[1];
2529 hlist_for_each_entry(exp, &help->expectations, lnode) {
2530 if (l3proto && exp->tuple.src.l3num != l3proto)
2537 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).portid,
2541 if (!atomic_inc_not_zero(&exp->use))
2543 cb->args[1] = (unsigned long)exp;
2555 nf_ct_expect_put(last);
2560 static int ctnetlink_dump_exp_ct(struct sock *ctnl, struct sk_buff *skb,
2561 const struct nlmsghdr *nlh,
2562 const struct nlattr * const cda[])
2565 struct net *net = sock_net(ctnl);
2566 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2567 u_int8_t u3 = nfmsg->nfgen_family;
2568 struct nf_conntrack_tuple tuple;
2569 struct nf_conntrack_tuple_hash *h;
2572 struct netlink_dump_control c = {
2573 .dump = ctnetlink_exp_ct_dump_table,
2574 .done = ctnetlink_exp_done,
2577 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
2581 if (cda[CTA_EXPECT_ZONE]) {
2582 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
2587 h = nf_conntrack_find_get(net, zone, &tuple);
2591 ct = nf_ct_tuplehash_to_ctrack(h);
2594 err = netlink_dump_start(ctnl, skb, nlh, &c);
2601 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
2602 const struct nlmsghdr *nlh,
2603 const struct nlattr * const cda[])
2605 struct net *net = sock_net(ctnl);
2606 struct nf_conntrack_tuple tuple;
2607 struct nf_conntrack_expect *exp;
2608 struct sk_buff *skb2;
2609 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2610 u_int8_t u3 = nfmsg->nfgen_family;
2614 if (nlh->nlmsg_flags & NLM_F_DUMP) {
2615 if (cda[CTA_EXPECT_MASTER])
2616 return ctnetlink_dump_exp_ct(ctnl, skb, nlh, cda);
2618 struct netlink_dump_control c = {
2619 .dump = ctnetlink_exp_dump_table,
2620 .done = ctnetlink_exp_done,
2622 return netlink_dump_start(ctnl, skb, nlh, &c);
2626 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
2630 if (cda[CTA_EXPECT_TUPLE])
2631 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2632 else if (cda[CTA_EXPECT_MASTER])
2633 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
2640 exp = nf_ct_expect_find_get(net, zone, &tuple);
2644 if (cda[CTA_EXPECT_ID]) {
2645 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
2646 if (ntohl(id) != (u32)(unsigned long)exp) {
2647 nf_ct_expect_put(exp);
2653 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2655 nf_ct_expect_put(exp);
2660 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).portid,
2661 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, exp);
2663 nf_ct_expect_put(exp);
2667 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT);
2676 /* this avoids a loop in nfnetlink. */
2677 return err == -EAGAIN ? -ENOBUFS : err;
2681 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
2682 const struct nlmsghdr *nlh,
2683 const struct nlattr * const cda[])
2685 struct net *net = sock_net(ctnl);
2686 struct nf_conntrack_expect *exp;
2687 struct nf_conntrack_tuple tuple;
2688 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2689 struct hlist_node *next;
2690 u_int8_t u3 = nfmsg->nfgen_family;
2695 if (cda[CTA_EXPECT_TUPLE]) {
2696 /* delete a single expect by tuple */
2697 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
2701 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2705 /* bump usage count to 2 */
2706 exp = nf_ct_expect_find_get(net, zone, &tuple);
2710 if (cda[CTA_EXPECT_ID]) {
2711 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
2712 if (ntohl(id) != (u32)(unsigned long)exp) {
2713 nf_ct_expect_put(exp);
2718 /* after list removal, usage count == 1 */
2719 spin_lock_bh(&nf_conntrack_expect_lock);
2720 if (del_timer(&exp->timeout)) {
2721 nf_ct_unlink_expect_report(exp, NETLINK_CB(skb).portid,
2723 nf_ct_expect_put(exp);
2725 spin_unlock_bh(&nf_conntrack_expect_lock);
2726 /* have to put what we 'get' above.
2727 * after this line usage count == 0 */
2728 nf_ct_expect_put(exp);
2729 } else if (cda[CTA_EXPECT_HELP_NAME]) {
2730 char *name = nla_data(cda[CTA_EXPECT_HELP_NAME]);
2731 struct nf_conn_help *m_help;
2733 /* delete all expectations for this helper */
2734 spin_lock_bh(&nf_conntrack_expect_lock);
2735 for (i = 0; i < nf_ct_expect_hsize; i++) {
2736 hlist_for_each_entry_safe(exp, next,
2737 &net->ct.expect_hash[i],
2739 m_help = nfct_help(exp->master);
2740 if (!strcmp(m_help->helper->name, name) &&
2741 del_timer(&exp->timeout)) {
2742 nf_ct_unlink_expect_report(exp,
2743 NETLINK_CB(skb).portid,
2745 nf_ct_expect_put(exp);
2749 spin_unlock_bh(&nf_conntrack_expect_lock);
2751 /* This basically means we have to flush everything*/
2752 spin_lock_bh(&nf_conntrack_expect_lock);
2753 for (i = 0; i < nf_ct_expect_hsize; i++) {
2754 hlist_for_each_entry_safe(exp, next,
2755 &net->ct.expect_hash[i],
2757 if (del_timer(&exp->timeout)) {
2758 nf_ct_unlink_expect_report(exp,
2759 NETLINK_CB(skb).portid,
2761 nf_ct_expect_put(exp);
2765 spin_unlock_bh(&nf_conntrack_expect_lock);
2771 ctnetlink_change_expect(struct nf_conntrack_expect *x,
2772 const struct nlattr * const cda[])
2774 if (cda[CTA_EXPECT_TIMEOUT]) {
2775 if (!del_timer(&x->timeout))
2778 x->timeout.expires = jiffies +
2779 ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ;
2780 add_timer(&x->timeout);
2785 static const struct nla_policy exp_nat_nla_policy[CTA_EXPECT_NAT_MAX+1] = {
2786 [CTA_EXPECT_NAT_DIR] = { .type = NLA_U32 },
2787 [CTA_EXPECT_NAT_TUPLE] = { .type = NLA_NESTED },
2791 ctnetlink_parse_expect_nat(const struct nlattr *attr,
2792 struct nf_conntrack_expect *exp,
2795 #ifdef CONFIG_NF_NAT_NEEDED
2796 struct nlattr *tb[CTA_EXPECT_NAT_MAX+1];
2797 struct nf_conntrack_tuple nat_tuple = {};
2800 err = nla_parse_nested(tb, CTA_EXPECT_NAT_MAX, attr, exp_nat_nla_policy);
2804 if (!tb[CTA_EXPECT_NAT_DIR] || !tb[CTA_EXPECT_NAT_TUPLE])
2807 err = ctnetlink_parse_tuple((const struct nlattr * const *)tb,
2808 &nat_tuple, CTA_EXPECT_NAT_TUPLE, u3);
2812 exp->saved_addr = nat_tuple.src.u3;
2813 exp->saved_proto = nat_tuple.src.u;
2814 exp->dir = ntohl(nla_get_be32(tb[CTA_EXPECT_NAT_DIR]));
2822 static struct nf_conntrack_expect *
2823 ctnetlink_alloc_expect(const struct nlattr * const cda[], struct nf_conn *ct,
2824 struct nf_conntrack_helper *helper,
2825 struct nf_conntrack_tuple *tuple,
2826 struct nf_conntrack_tuple *mask)
2828 u_int32_t class = 0;
2829 struct nf_conntrack_expect *exp;
2830 struct nf_conn_help *help;
2833 if (cda[CTA_EXPECT_CLASS] && helper) {
2834 class = ntohl(nla_get_be32(cda[CTA_EXPECT_CLASS]));
2835 if (class > helper->expect_class_max)
2836 return ERR_PTR(-EINVAL);
2838 exp = nf_ct_expect_alloc(ct);
2840 return ERR_PTR(-ENOMEM);
2842 help = nfct_help(ct);
2844 if (!cda[CTA_EXPECT_TIMEOUT]) {
2848 exp->timeout.expires =
2849 jiffies + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ;
2851 exp->flags = NF_CT_EXPECT_USERSPACE;
2852 if (cda[CTA_EXPECT_FLAGS]) {
2854 ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
2857 if (cda[CTA_EXPECT_FLAGS]) {
2858 exp->flags = ntohl(nla_get_be32(cda[CTA_EXPECT_FLAGS]));
2859 exp->flags &= ~NF_CT_EXPECT_USERSPACE;
2863 if (cda[CTA_EXPECT_FN]) {
2864 const char *name = nla_data(cda[CTA_EXPECT_FN]);
2865 struct nf_ct_helper_expectfn *expfn;
2867 expfn = nf_ct_helper_expectfn_find_by_name(name);
2868 if (expfn == NULL) {
2872 exp->expectfn = expfn->expectfn;
2874 exp->expectfn = NULL;
2878 exp->helper = helper;
2879 exp->tuple = *tuple;
2880 exp->mask.src.u3 = mask->src.u3;
2881 exp->mask.src.u.all = mask->src.u.all;
2883 if (cda[CTA_EXPECT_NAT]) {
2884 err = ctnetlink_parse_expect_nat(cda[CTA_EXPECT_NAT],
2885 exp, nf_ct_l3num(ct));
2891 nf_ct_expect_put(exp);
2892 return ERR_PTR(err);
2896 ctnetlink_create_expect(struct net *net, u16 zone,
2897 const struct nlattr * const cda[],
2898 u_int8_t u3, u32 portid, int report)
2900 struct nf_conntrack_tuple tuple, mask, master_tuple;
2901 struct nf_conntrack_tuple_hash *h = NULL;
2902 struct nf_conntrack_helper *helper = NULL;
2903 struct nf_conntrack_expect *exp;
2907 /* caller guarantees that those three CTA_EXPECT_* exist */
2908 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2911 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK, u3);
2914 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER, u3);
2918 /* Look for master conntrack of this expectation */
2919 h = nf_conntrack_find_get(net, zone, &master_tuple);
2922 ct = nf_ct_tuplehash_to_ctrack(h);
2924 if (cda[CTA_EXPECT_HELP_NAME]) {
2925 const char *helpname = nla_data(cda[CTA_EXPECT_HELP_NAME]);
2927 helper = __nf_conntrack_helper_find(helpname, u3,
2928 nf_ct_protonum(ct));
2929 if (helper == NULL) {
2930 #ifdef CONFIG_MODULES
2931 if (request_module("nfct-helper-%s", helpname) < 0) {
2935 helper = __nf_conntrack_helper_find(helpname, u3,
2936 nf_ct_protonum(ct));
2947 exp = ctnetlink_alloc_expect(cda, ct, helper, &tuple, &mask);
2953 err = nf_ct_expect_related_report(exp, portid, report);
2959 nf_ct_expect_put(exp);
2966 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
2967 const struct nlmsghdr *nlh,
2968 const struct nlattr * const cda[])
2970 struct net *net = sock_net(ctnl);
2971 struct nf_conntrack_tuple tuple;
2972 struct nf_conntrack_expect *exp;
2973 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
2974 u_int8_t u3 = nfmsg->nfgen_family;
2978 if (!cda[CTA_EXPECT_TUPLE]
2979 || !cda[CTA_EXPECT_MASK]
2980 || !cda[CTA_EXPECT_MASTER])
2983 err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
2987 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
2991 spin_lock_bh(&nf_conntrack_expect_lock);
2992 exp = __nf_ct_expect_find(net, zone, &tuple);
2995 spin_unlock_bh(&nf_conntrack_expect_lock);
2997 if (nlh->nlmsg_flags & NLM_F_CREATE) {
2998 err = ctnetlink_create_expect(net, zone, cda,
3000 NETLINK_CB(skb).portid,
3007 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
3008 err = ctnetlink_change_expect(exp, cda);
3009 spin_unlock_bh(&nf_conntrack_expect_lock);
3015 ctnetlink_exp_stat_fill_info(struct sk_buff *skb, u32 portid, u32 seq, int cpu,
3016 const struct ip_conntrack_stat *st)
3018 struct nlmsghdr *nlh;
3019 struct nfgenmsg *nfmsg;
3020 unsigned int flags = portid ? NLM_F_MULTI : 0, event;
3022 event = (NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_EXP_GET_STATS_CPU);
3023 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
3027 nfmsg = nlmsg_data(nlh);
3028 nfmsg->nfgen_family = AF_UNSPEC;
3029 nfmsg->version = NFNETLINK_V0;
3030 nfmsg->res_id = htons(cpu);
3032 if (nla_put_be32(skb, CTA_STATS_EXP_NEW, htonl(st->expect_new)) ||
3033 nla_put_be32(skb, CTA_STATS_EXP_CREATE, htonl(st->expect_create)) ||
3034 nla_put_be32(skb, CTA_STATS_EXP_DELETE, htonl(st->expect_delete)))
3035 goto nla_put_failure;
3037 nlmsg_end(skb, nlh);
3042 nlmsg_cancel(skb, nlh);
3047 ctnetlink_exp_stat_cpu_dump(struct sk_buff *skb, struct netlink_callback *cb)
3050 struct net *net = sock_net(skb->sk);
3052 if (cb->args[0] == nr_cpu_ids)
3055 for (cpu = cb->args[0]; cpu < nr_cpu_ids; cpu++) {
3056 const struct ip_conntrack_stat *st;
3058 if (!cpu_possible(cpu))
3061 st = per_cpu_ptr(net->ct.stat, cpu);
3062 if (ctnetlink_exp_stat_fill_info(skb, NETLINK_CB(cb->skb).portid,
3073 ctnetlink_stat_exp_cpu(struct sock *ctnl, struct sk_buff *skb,
3074 const struct nlmsghdr *nlh,
3075 const struct nlattr * const cda[])
3077 if (nlh->nlmsg_flags & NLM_F_DUMP) {
3078 struct netlink_dump_control c = {
3079 .dump = ctnetlink_exp_stat_cpu_dump,
3081 return netlink_dump_start(ctnl, skb, nlh, &c);
3087 #ifdef CONFIG_NF_CONNTRACK_EVENTS
3088 static struct nf_ct_event_notifier ctnl_notifier = {
3089 .fcn = ctnetlink_conntrack_event,
3092 static struct nf_exp_event_notifier ctnl_notifier_exp = {
3093 .fcn = ctnetlink_expect_event,
3097 static const struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
3098 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
3099 .attr_count = CTA_MAX,
3100 .policy = ct_nla_policy },
3101 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
3102 .attr_count = CTA_MAX,
3103 .policy = ct_nla_policy },
3104 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
3105 .attr_count = CTA_MAX,
3106 .policy = ct_nla_policy },
3107 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
3108 .attr_count = CTA_MAX,
3109 .policy = ct_nla_policy },
3110 [IPCTNL_MSG_CT_GET_STATS_CPU] = { .call = ctnetlink_stat_ct_cpu },
3111 [IPCTNL_MSG_CT_GET_STATS] = { .call = ctnetlink_stat_ct },
3112 [IPCTNL_MSG_CT_GET_DYING] = { .call = ctnetlink_get_ct_dying },
3113 [IPCTNL_MSG_CT_GET_UNCONFIRMED] = { .call = ctnetlink_get_ct_unconfirmed },
3116 static const struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
3117 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
3118 .attr_count = CTA_EXPECT_MAX,
3119 .policy = exp_nla_policy },
3120 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
3121 .attr_count = CTA_EXPECT_MAX,
3122 .policy = exp_nla_policy },
3123 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
3124 .attr_count = CTA_EXPECT_MAX,
3125 .policy = exp_nla_policy },
3126 [IPCTNL_MSG_EXP_GET_STATS_CPU] = { .call = ctnetlink_stat_exp_cpu },
3129 static const struct nfnetlink_subsystem ctnl_subsys = {
3130 .name = "conntrack",
3131 .subsys_id = NFNL_SUBSYS_CTNETLINK,
3132 .cb_count = IPCTNL_MSG_MAX,
3136 static const struct nfnetlink_subsystem ctnl_exp_subsys = {
3137 .name = "conntrack_expect",
3138 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
3139 .cb_count = IPCTNL_MSG_EXP_MAX,
3143 MODULE_ALIAS("ip_conntrack_netlink");
3144 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
3145 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_EXP);
3147 static int __net_init ctnetlink_net_init(struct net *net)
3149 #ifdef CONFIG_NF_CONNTRACK_EVENTS
3152 ret = nf_conntrack_register_notifier(net, &ctnl_notifier);
3154 pr_err("ctnetlink_init: cannot register notifier.\n");
3158 ret = nf_ct_expect_register_notifier(net, &ctnl_notifier_exp);
3160 pr_err("ctnetlink_init: cannot expect register notifier.\n");
3161 goto err_unreg_notifier;
3166 #ifdef CONFIG_NF_CONNTRACK_EVENTS
3168 nf_conntrack_unregister_notifier(net, &ctnl_notifier);
3174 static void ctnetlink_net_exit(struct net *net)
3176 #ifdef CONFIG_NF_CONNTRACK_EVENTS
3177 nf_ct_expect_unregister_notifier(net, &ctnl_notifier_exp);
3178 nf_conntrack_unregister_notifier(net, &ctnl_notifier);
3182 static void __net_exit ctnetlink_net_exit_batch(struct list_head *net_exit_list)
3186 list_for_each_entry(net, net_exit_list, exit_list)
3187 ctnetlink_net_exit(net);
3190 static struct pernet_operations ctnetlink_net_ops = {
3191 .init = ctnetlink_net_init,
3192 .exit_batch = ctnetlink_net_exit_batch,
3195 static int __init ctnetlink_init(void)
3199 pr_info("ctnetlink v%s: registering with nfnetlink.\n", version);
3200 ret = nfnetlink_subsys_register(&ctnl_subsys);
3202 pr_err("ctnetlink_init: cannot register with nfnetlink.\n");
3206 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
3208 pr_err("ctnetlink_init: cannot register exp with nfnetlink.\n");
3209 goto err_unreg_subsys;
3212 ret = register_pernet_subsys(&ctnetlink_net_ops);
3214 pr_err("ctnetlink_init: cannot register pernet operations\n");
3215 goto err_unreg_exp_subsys;
3217 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT
3218 /* setup interaction between nf_queue and nf_conntrack_netlink. */
3219 RCU_INIT_POINTER(nfq_ct_hook, &ctnetlink_nfqueue_hook);
3223 err_unreg_exp_subsys:
3224 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
3226 nfnetlink_subsys_unregister(&ctnl_subsys);
3231 static void __exit ctnetlink_exit(void)
3233 pr_info("ctnetlink: unregistering from nfnetlink.\n");
3235 unregister_pernet_subsys(&ctnetlink_net_ops);
3236 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
3237 nfnetlink_subsys_unregister(&ctnl_subsys);
3238 #ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT
3239 RCU_INIT_POINTER(nfq_ct_hook, NULL);
3243 module_init(ctnetlink_init);
3244 module_exit(ctnetlink_exit);