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-2005 by Harald Welte <laforge@gnumonks.org>
6 * (C) 2003 by Patrick Mchardy <kaber@trash.net>
7 * (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net>
9 * I've reworked this stuff to use attributes instead of conntrack
10 * structures. 5.44 am. I need more tea. --pablo 05/07/11.
12 * Initial connection tracking via netlink development funded and
13 * generally made possible by Network Robots, Inc. (www.networkrobots.com)
15 * Further development of this code funded by Astaro AG (http://www.astaro.com)
17 * This software may be used and distributed according to the terms
18 * of the GNU General Public License, incorporated herein by reference.
20 * Derived from ip_conntrack_netlink.c: Port by Pablo Neira Ayuso (05/11/14)
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/timer.h>
28 #include <linux/skbuff.h>
29 #include <linux/errno.h>
30 #include <linux/netlink.h>
31 #include <linux/spinlock.h>
32 #include <linux/notifier.h>
34 #include <linux/netfilter.h>
35 #include <net/netfilter/nf_conntrack.h>
36 #include <net/netfilter/nf_conntrack_core.h>
37 #include <net/netfilter/nf_conntrack_helper.h>
38 #include <net/netfilter/nf_conntrack_l3proto.h>
39 #include <net/netfilter/nf_conntrack_protocol.h>
40 #include <linux/netfilter_ipv4/ip_nat_protocol.h>
42 #include <linux/netfilter/nfnetlink.h>
43 #include <linux/netfilter/nfnetlink_conntrack.h>
45 MODULE_LICENSE("GPL");
47 static char __initdata version[] = "0.92";
52 #define DEBUGP(format, args...)
57 ctnetlink_dump_tuples_proto(struct sk_buff *skb,
58 const struct nf_conntrack_tuple *tuple)
60 struct nf_conntrack_protocol *proto;
63 NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
65 /* If no protocol helper is found, this function will return the
66 * generic protocol helper, so proto won't *ever* be NULL */
67 proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
68 if (likely(proto->tuple_to_nfattr))
69 ret = proto->tuple_to_nfattr(skb, tuple);
71 nf_ct_proto_put(proto);
80 ctnetlink_dump_tuples(struct sk_buff *skb,
81 const struct nf_conntrack_tuple *tuple)
83 struct nfattr *nest_parms;
84 struct nf_conntrack_l3proto *l3proto;
87 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
89 nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
90 if (likely(l3proto->tuple_to_nfattr))
91 ret = l3proto->tuple_to_nfattr(skb, tuple);
92 NFA_NEST_END(skb, nest_parms);
94 nf_ct_l3proto_put(l3proto);
96 if (unlikely(ret < 0))
99 nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
100 ret = ctnetlink_dump_tuples_proto(skb, tuple);
101 NFA_NEST_END(skb, nest_parms);
110 ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct)
112 u_int32_t status = htonl((u_int32_t) ct->status);
113 NFA_PUT(skb, CTA_STATUS, sizeof(status), &status);
121 ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct)
123 long timeout_l = ct->timeout.expires - jiffies;
129 timeout = htonl(timeout_l / HZ);
131 NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout);
139 ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct)
141 struct nf_conntrack_protocol *proto = nf_ct_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
142 struct nfattr *nest_proto;
145 if (!proto->to_nfattr) {
146 nf_ct_proto_put(proto);
150 nest_proto = NFA_NEST(skb, CTA_PROTOINFO);
152 ret = proto->to_nfattr(skb, nest_proto, ct);
154 nf_ct_proto_put(proto);
156 NFA_NEST_END(skb, nest_proto);
165 ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
167 struct nfattr *nest_helper;
172 nest_helper = NFA_NEST(skb, CTA_HELP);
173 NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name);
175 if (ct->helper->to_nfattr)
176 ct->helper->to_nfattr(skb, ct);
178 NFA_NEST_END(skb, nest_helper);
186 #ifdef CONFIG_NF_CT_ACCT
188 ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct,
189 enum ip_conntrack_dir dir)
191 enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
192 struct nfattr *nest_count = NFA_NEST(skb, type);
195 tmp = htonl(ct->counters[dir].packets);
196 NFA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp);
198 tmp = htonl(ct->counters[dir].bytes);
199 NFA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp);
201 NFA_NEST_END(skb, nest_count);
209 #define ctnetlink_dump_counters(a, b, c) (0)
212 #ifdef CONFIG_NF_CONNTRACK_MARK
214 ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct)
216 u_int32_t mark = htonl(ct->mark);
218 NFA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark);
225 #define ctnetlink_dump_mark(a, b) (0)
229 ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
231 u_int32_t id = htonl(ct->id);
232 NFA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id);
240 ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct)
242 u_int32_t use = htonl(atomic_read(&ct->ct_general.use));
244 NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use);
251 #define tuple(ct, dir) (&(ct)->tuplehash[dir].tuple)
254 ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
255 int event, int nowait,
256 const struct nf_conn *ct)
258 struct nlmsghdr *nlh;
259 struct nfgenmsg *nfmsg;
260 struct nfattr *nest_parms;
265 event |= NFNL_SUBSYS_CTNETLINK << 8;
266 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
267 nfmsg = NLMSG_DATA(nlh);
269 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
270 nfmsg->nfgen_family =
271 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
272 nfmsg->version = NFNETLINK_V0;
275 nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
276 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
278 NFA_NEST_END(skb, nest_parms);
280 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
281 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
283 NFA_NEST_END(skb, nest_parms);
285 if (ctnetlink_dump_status(skb, ct) < 0 ||
286 ctnetlink_dump_timeout(skb, ct) < 0 ||
287 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
288 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0 ||
289 ctnetlink_dump_protoinfo(skb, ct) < 0 ||
290 ctnetlink_dump_helpinfo(skb, ct) < 0 ||
291 ctnetlink_dump_mark(skb, ct) < 0 ||
292 ctnetlink_dump_id(skb, ct) < 0 ||
293 ctnetlink_dump_use(skb, ct) < 0)
296 nlh->nlmsg_len = skb->tail - b;
301 skb_trim(skb, b - skb->data);
305 #ifdef CONFIG_NF_CONNTRACK_EVENTS
306 static int ctnetlink_conntrack_event(struct notifier_block *this,
307 unsigned long events, void *ptr)
309 struct nlmsghdr *nlh;
310 struct nfgenmsg *nfmsg;
311 struct nfattr *nest_parms;
312 struct nf_conn *ct = (struct nf_conn *)ptr;
316 unsigned int flags = 0, group;
318 /* ignore our fake conntrack entry */
319 if (ct == &nf_conntrack_untracked)
322 if (events & IPCT_DESTROY) {
323 type = IPCTNL_MSG_CT_DELETE;
324 group = NFNLGRP_CONNTRACK_DESTROY;
325 } else if (events & (IPCT_NEW | IPCT_RELATED)) {
326 type = IPCTNL_MSG_CT_NEW;
327 flags = NLM_F_CREATE|NLM_F_EXCL;
328 /* dump everything */
330 group = NFNLGRP_CONNTRACK_NEW;
331 } else if (events & (IPCT_STATUS |
336 type = IPCTNL_MSG_CT_NEW;
337 group = NFNLGRP_CONNTRACK_UPDATE;
341 /* FIXME: Check if there are any listeners before, don't hurt performance */
343 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
349 type |= NFNL_SUBSYS_CTNETLINK << 8;
350 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
351 nfmsg = NLMSG_DATA(nlh);
353 nlh->nlmsg_flags = flags;
354 nfmsg->nfgen_family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
355 nfmsg->version = NFNETLINK_V0;
358 nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
359 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
361 NFA_NEST_END(skb, nest_parms);
363 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
364 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
366 NFA_NEST_END(skb, nest_parms);
368 /* NAT stuff is now a status flag */
369 if ((events & IPCT_STATUS || events & IPCT_NATINFO)
370 && ctnetlink_dump_status(skb, ct) < 0)
372 if (events & IPCT_REFRESH
373 && ctnetlink_dump_timeout(skb, ct) < 0)
375 if (events & IPCT_PROTOINFO
376 && ctnetlink_dump_protoinfo(skb, ct) < 0)
378 if (events & IPCT_HELPINFO
379 && ctnetlink_dump_helpinfo(skb, ct) < 0)
382 if (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
383 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0)
386 nlh->nlmsg_len = skb->tail - b;
387 nfnetlink_send(skb, 0, group, 0);
395 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
397 static int ctnetlink_done(struct netlink_callback *cb)
399 DEBUGP("entered %s\n", __FUNCTION__);
404 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
406 struct nf_conn *ct = NULL;
407 struct nf_conntrack_tuple_hash *h;
409 u_int32_t *id = (u_int32_t *) &cb->args[1];
411 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__,
414 read_lock_bh(&nf_conntrack_lock);
415 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
416 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
417 h = (struct nf_conntrack_tuple_hash *) i;
418 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
420 ct = nf_ct_tuplehash_to_ctrack(h);
423 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
432 read_unlock_bh(&nf_conntrack_lock);
434 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
439 #ifdef CONFIG_NF_CT_ACCT
441 ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
443 struct nf_conn *ct = NULL;
444 struct nf_conntrack_tuple_hash *h;
446 u_int32_t *id = (u_int32_t *) &cb->args[1];
448 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__,
451 write_lock_bh(&nf_conntrack_lock);
452 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
453 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
454 h = (struct nf_conntrack_tuple_hash *) i;
455 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
457 ct = nf_ct_tuplehash_to_ctrack(h);
460 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
467 memset(&ct->counters, 0, sizeof(ct->counters));
471 write_unlock_bh(&nf_conntrack_lock);
473 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
480 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
482 struct nfattr *tb[CTA_IP_MAX];
483 struct nf_conntrack_l3proto *l3proto;
486 DEBUGP("entered %s\n", __FUNCTION__);
488 nfattr_parse_nested(tb, CTA_IP_MAX, attr);
490 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
492 if (likely(l3proto->nfattr_to_tuple))
493 ret = l3proto->nfattr_to_tuple(tb, tuple);
495 nf_ct_l3proto_put(l3proto);
502 static const size_t cta_min_proto[CTA_PROTO_MAX] = {
503 [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
507 ctnetlink_parse_tuple_proto(struct nfattr *attr,
508 struct nf_conntrack_tuple *tuple)
510 struct nfattr *tb[CTA_PROTO_MAX];
511 struct nf_conntrack_protocol *proto;
514 DEBUGP("entered %s\n", __FUNCTION__);
516 nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
518 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
521 if (!tb[CTA_PROTO_NUM-1])
523 tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
525 proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
527 if (likely(proto->nfattr_to_tuple))
528 ret = proto->nfattr_to_tuple(tb, tuple);
530 nf_ct_proto_put(proto);
536 ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
537 enum ctattr_tuple type, u_int8_t l3num)
539 struct nfattr *tb[CTA_TUPLE_MAX];
542 DEBUGP("entered %s\n", __FUNCTION__);
544 memset(tuple, 0, sizeof(*tuple));
546 nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
548 if (!tb[CTA_TUPLE_IP-1])
551 tuple->src.l3num = l3num;
553 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
557 if (!tb[CTA_TUPLE_PROTO-1])
560 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
564 /* orig and expect tuples get DIR_ORIGINAL */
565 if (type == CTA_TUPLE_REPLY)
566 tuple->dst.dir = IP_CT_DIR_REPLY;
568 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
570 NF_CT_DUMP_TUPLE(tuple);
577 #ifdef CONFIG_IP_NF_NAT_NEEDED
578 static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
579 [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
580 [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
583 static int ctnetlink_parse_nat_proto(struct nfattr *attr,
584 const struct nf_conn *ct,
585 struct ip_nat_range *range)
587 struct nfattr *tb[CTA_PROTONAT_MAX];
588 struct ip_nat_protocol *npt;
590 DEBUGP("entered %s\n", __FUNCTION__);
592 nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
594 if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
597 npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
599 if (!npt->nfattr_to_range) {
600 ip_nat_proto_put(npt);
604 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
605 if (npt->nfattr_to_range(tb, range) > 0)
606 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
608 ip_nat_proto_put(npt);
614 static const size_t cta_min_nat[CTA_NAT_MAX] = {
615 [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
616 [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
620 ctnetlink_parse_nat(struct nfattr *cda[],
621 const struct nf_conn *ct, struct ip_nat_range *range)
623 struct nfattr *tb[CTA_NAT_MAX];
626 DEBUGP("entered %s\n", __FUNCTION__);
628 memset(range, 0, sizeof(*range));
630 nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]);
632 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
635 if (tb[CTA_NAT_MINIP-1])
636 range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
638 if (!tb[CTA_NAT_MAXIP-1])
639 range->max_ip = range->min_ip;
641 range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
644 range->flags |= IP_NAT_RANGE_MAP_IPS;
646 if (!tb[CTA_NAT_PROTO-1])
649 err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
659 ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
661 struct nfattr *tb[CTA_HELP_MAX];
663 DEBUGP("entered %s\n", __FUNCTION__);
665 nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
667 if (!tb[CTA_HELP_NAME-1])
670 *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
675 static const size_t cta_min[CTA_MAX] = {
676 [CTA_STATUS-1] = sizeof(u_int32_t),
677 [CTA_TIMEOUT-1] = sizeof(u_int32_t),
678 [CTA_MARK-1] = sizeof(u_int32_t),
679 [CTA_USE-1] = sizeof(u_int32_t),
680 [CTA_ID-1] = sizeof(u_int32_t)
684 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
685 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
687 struct nf_conntrack_tuple_hash *h;
688 struct nf_conntrack_tuple tuple;
690 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
691 u_int8_t u3 = nfmsg->nfgen_family;
694 DEBUGP("entered %s\n", __FUNCTION__);
696 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
699 if (cda[CTA_TUPLE_ORIG-1])
700 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
701 else if (cda[CTA_TUPLE_REPLY-1])
702 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
704 /* Flush the whole table */
705 nf_conntrack_flush();
712 h = nf_conntrack_find_get(&tuple, NULL);
714 DEBUGP("tuple not found in conntrack hash\n");
718 ct = nf_ct_tuplehash_to_ctrack(h);
721 u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1]));
727 if (del_timer(&ct->timeout))
728 ct->timeout.function((unsigned long)ct);
737 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
738 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
740 struct nf_conntrack_tuple_hash *h;
741 struct nf_conntrack_tuple tuple;
743 struct sk_buff *skb2 = NULL;
744 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
745 u_int8_t u3 = nfmsg->nfgen_family;
748 DEBUGP("entered %s\n", __FUNCTION__);
750 if (nlh->nlmsg_flags & NLM_F_DUMP) {
753 if (nfmsg->nfgen_family != AF_INET)
754 return -EAFNOSUPPORT;
756 if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
757 IPCTNL_MSG_CT_GET_CTRZERO) {
758 #ifdef CONFIG_NF_CT_ACCT
759 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
760 ctnetlink_dump_table_w,
761 ctnetlink_done)) != 0)
767 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
768 ctnetlink_dump_table,
769 ctnetlink_done)) != 0)
773 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
780 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
783 if (cda[CTA_TUPLE_ORIG-1])
784 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
785 else if (cda[CTA_TUPLE_REPLY-1])
786 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
793 h = nf_conntrack_find_get(&tuple, NULL);
795 DEBUGP("tuple not found in conntrack hash");
798 DEBUGP("tuple found\n");
799 ct = nf_ct_tuplehash_to_ctrack(h);
802 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
807 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
809 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
810 IPCTNL_MSG_CT_NEW, 1, ct);
815 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
829 ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
832 unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1]));
833 d = ct->status ^ status;
835 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
839 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
840 /* SEEN_REPLY bit can only be set */
844 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
845 /* ASSURED bit can only be set */
848 if (cda[CTA_NAT-1]) {
849 #ifndef CONFIG_IP_NF_NAT_NEEDED
852 unsigned int hooknum;
853 struct ip_nat_range range;
855 if (ctnetlink_parse_nat(cda, ct, &range) < 0)
858 DEBUGP("NAT: %u.%u.%u.%u-%u.%u.%u.%u:%u-%u\n",
859 NIPQUAD(range.min_ip), NIPQUAD(range.max_ip),
860 htons(range.min.all), htons(range.max.all));
862 /* This is tricky but it works. ip_nat_setup_info needs the
863 * hook number as parameter, so let's do the correct
864 * conversion and run away */
865 if (status & IPS_SRC_NAT_DONE)
866 hooknum = NF_IP_POST_ROUTING; /* IP_NAT_MANIP_SRC */
867 else if (status & IPS_DST_NAT_DONE)
868 hooknum = NF_IP_PRE_ROUTING; /* IP_NAT_MANIP_DST */
870 return -EINVAL; /* Missing NAT flags */
872 DEBUGP("NAT status: %lu\n",
873 status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
875 if (ip_nat_initialized(ct, HOOK2MANIP(hooknum)))
877 ip_nat_setup_info(ct, &range, hooknum);
879 DEBUGP("NAT status after setup_info: %lu\n",
880 ct->status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
884 /* Be careful here, modifying NAT bits can screw up things,
885 * so don't let users modify them directly if they don't pass
887 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
893 ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
895 struct nf_conntrack_helper *helper;
899 DEBUGP("entered %s\n", __FUNCTION__);
901 /* don't change helper of sibling connections */
905 err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
909 helper = __nf_conntrack_helper_find_byname(helpname);
911 if (!strcmp(helpname, ""))
919 /* we had a helper before ... */
920 nf_ct_remove_expectations(ct);
923 /* need to zero data of old helper */
924 memset(&ct->help, 0, sizeof(ct->help));
934 ctnetlink_change_timeout(struct nf_conn *ct, struct nfattr *cda[])
936 u_int32_t timeout = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
938 if (!del_timer(&ct->timeout))
941 ct->timeout.expires = jiffies + timeout * HZ;
942 add_timer(&ct->timeout);
948 ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[])
950 struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
951 struct nf_conntrack_protocol *proto;
952 u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
953 u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
956 nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
958 proto = nf_ct_proto_find_get(l3num, npt);
960 if (proto->from_nfattr)
961 err = proto->from_nfattr(tb, ct);
962 nf_ct_proto_put(proto);
968 ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
972 DEBUGP("entered %s\n", __FUNCTION__);
974 if (cda[CTA_HELP-1]) {
975 err = ctnetlink_change_helper(ct, cda);
980 if (cda[CTA_TIMEOUT-1]) {
981 err = ctnetlink_change_timeout(ct, cda);
986 if (cda[CTA_STATUS-1]) {
987 err = ctnetlink_change_status(ct, cda);
992 if (cda[CTA_PROTOINFO-1]) {
993 err = ctnetlink_change_protoinfo(ct, cda);
998 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1000 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1003 DEBUGP("all done\n");
1008 ctnetlink_create_conntrack(struct nfattr *cda[],
1009 struct nf_conntrack_tuple *otuple,
1010 struct nf_conntrack_tuple *rtuple)
1015 DEBUGP("entered %s\n", __FUNCTION__);
1017 ct = nf_conntrack_alloc(otuple, rtuple);
1018 if (ct == NULL || IS_ERR(ct))
1021 if (!cda[CTA_TIMEOUT-1])
1023 ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
1025 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1026 ct->status |= IPS_CONFIRMED;
1028 err = ctnetlink_change_status(ct, cda);
1032 if (cda[CTA_PROTOINFO-1]) {
1033 err = ctnetlink_change_protoinfo(ct, cda);
1038 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1039 if (cda[CTA_MARK-1])
1040 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1043 ct->helper = nf_ct_helper_find_get(rtuple);
1045 add_timer(&ct->timeout);
1046 nf_conntrack_hash_insert(ct);
1049 nf_ct_helper_put(ct->helper);
1051 DEBUGP("conntrack with id %u inserted\n", ct->id);
1055 nf_conntrack_free(ct);
1060 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1061 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1063 struct nf_conntrack_tuple otuple, rtuple;
1064 struct nf_conntrack_tuple_hash *h = NULL;
1065 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1066 u_int8_t u3 = nfmsg->nfgen_family;
1069 DEBUGP("entered %s\n", __FUNCTION__);
1071 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
1074 if (cda[CTA_TUPLE_ORIG-1]) {
1075 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
1080 if (cda[CTA_TUPLE_REPLY-1]) {
1081 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
1086 write_lock_bh(&nf_conntrack_lock);
1087 if (cda[CTA_TUPLE_ORIG-1])
1088 h = __nf_conntrack_find(&otuple, NULL);
1089 else if (cda[CTA_TUPLE_REPLY-1])
1090 h = __nf_conntrack_find(&rtuple, NULL);
1093 write_unlock_bh(&nf_conntrack_lock);
1094 DEBUGP("no such conntrack, create new\n");
1096 if (nlh->nlmsg_flags & NLM_F_CREATE)
1097 err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
1100 /* implicit 'else' */
1102 /* we only allow nat config for new conntracks */
1103 if (cda[CTA_NAT-1]) {
1108 /* We manipulate the conntrack inside the global conntrack table lock,
1109 * so there's no need to increase the refcount */
1110 DEBUGP("conntrack found\n");
1112 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1113 err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), cda);
1116 write_unlock_bh(&nf_conntrack_lock);
1120 /***********************************************************************
1122 ***********************************************************************/
1125 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1126 const struct nf_conntrack_tuple *tuple,
1127 enum ctattr_expect type)
1129 struct nfattr *nest_parms = NFA_NEST(skb, type);
1131 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1132 goto nfattr_failure;
1134 NFA_NEST_END(skb, nest_parms);
1143 ctnetlink_exp_dump_expect(struct sk_buff *skb,
1144 const struct nf_conntrack_expect *exp)
1146 struct nf_conn *master = exp->master;
1147 u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ);
1148 u_int32_t id = htonl(exp->id);
1150 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
1151 goto nfattr_failure;
1152 if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
1153 goto nfattr_failure;
1154 if (ctnetlink_exp_dump_tuple(skb,
1155 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1156 CTA_EXPECT_MASTER) < 0)
1157 goto nfattr_failure;
1159 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
1160 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
1169 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1172 const struct nf_conntrack_expect *exp)
1174 struct nlmsghdr *nlh;
1175 struct nfgenmsg *nfmsg;
1180 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1181 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
1182 nfmsg = NLMSG_DATA(nlh);
1184 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1185 nfmsg->nfgen_family = exp->tuple.src.l3num;
1186 nfmsg->version = NFNETLINK_V0;
1189 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1190 goto nfattr_failure;
1192 nlh->nlmsg_len = skb->tail - b;
1197 skb_trim(skb, b - skb->data);
1201 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1202 static int ctnetlink_expect_event(struct notifier_block *this,
1203 unsigned long events, void *ptr)
1205 struct nlmsghdr *nlh;
1206 struct nfgenmsg *nfmsg;
1207 struct nf_conntrack_expect *exp = (struct nf_conntrack_expect *)ptr;
1208 struct sk_buff *skb;
1213 if (events & IPEXP_NEW) {
1214 type = IPCTNL_MSG_EXP_NEW;
1215 flags = NLM_F_CREATE|NLM_F_EXCL;
1219 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
1225 type |= NFNL_SUBSYS_CTNETLINK << 8;
1226 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
1227 nfmsg = NLMSG_DATA(nlh);
1229 nlh->nlmsg_flags = flags;
1230 nfmsg->nfgen_family = exp->tuple.src.l3num;
1231 nfmsg->version = NFNETLINK_V0;
1234 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1235 goto nfattr_failure;
1237 nlh->nlmsg_len = skb->tail - b;
1238 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
1249 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1251 struct nf_conntrack_expect *exp = NULL;
1252 struct list_head *i;
1253 u_int32_t *id = (u_int32_t *) &cb->args[0];
1255 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
1257 read_lock_bh(&nf_conntrack_lock);
1258 list_for_each_prev(i, &nf_conntrack_expect_list) {
1259 exp = (struct nf_conntrack_expect *) i;
1262 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid,
1270 read_unlock_bh(&nf_conntrack_lock);
1272 DEBUGP("leaving, last id=%llu\n", *id);
1277 static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1278 [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
1279 [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
1283 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1284 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1286 struct nf_conntrack_tuple tuple;
1287 struct nf_conntrack_expect *exp;
1288 struct sk_buff *skb2;
1289 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1290 u_int8_t u3 = nfmsg->nfgen_family;
1293 DEBUGP("entered %s\n", __FUNCTION__);
1295 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1298 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1301 if (nfmsg->nfgen_family != AF_INET)
1302 return -EAFNOSUPPORT;
1304 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1305 ctnetlink_exp_dump_table,
1306 ctnetlink_done)) != 0)
1308 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1309 if (rlen > skb->len)
1311 skb_pull(skb, rlen);
1315 if (cda[CTA_EXPECT_MASTER-1])
1316 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
1323 exp = nf_conntrack_expect_find(&tuple);
1327 if (cda[CTA_EXPECT_ID-1]) {
1328 u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1329 if (exp->id != ntohl(id)) {
1330 nf_conntrack_expect_put(exp);
1336 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1339 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
1341 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1342 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1347 nf_conntrack_expect_put(exp);
1349 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1354 nf_conntrack_expect_put(exp);
1359 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1360 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1362 struct nf_conntrack_expect *exp, *tmp;
1363 struct nf_conntrack_tuple tuple;
1364 struct nf_conntrack_helper *h;
1365 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1366 u_int8_t u3 = nfmsg->nfgen_family;
1369 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1372 if (cda[CTA_EXPECT_TUPLE-1]) {
1373 /* delete a single expect by tuple */
1374 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1378 /* bump usage count to 2 */
1379 exp = nf_conntrack_expect_find(&tuple);
1383 if (cda[CTA_EXPECT_ID-1]) {
1385 *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1386 if (exp->id != ntohl(id)) {
1387 nf_conntrack_expect_put(exp);
1392 /* after list removal, usage count == 1 */
1393 nf_conntrack_unexpect_related(exp);
1394 /* have to put what we 'get' above.
1395 * after this line usage count == 0 */
1396 nf_conntrack_expect_put(exp);
1397 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
1398 char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
1400 /* delete all expectations for this helper */
1401 write_lock_bh(&nf_conntrack_lock);
1402 h = __nf_conntrack_helper_find_byname(name);
1404 write_unlock_bh(&nf_conntrack_lock);
1407 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1409 if (exp->master->helper == h
1410 && del_timer(&exp->timeout)) {
1411 nf_ct_unlink_expect(exp);
1412 nf_conntrack_expect_put(exp);
1415 write_unlock_bh(&nf_conntrack_lock);
1417 /* This basically means we have to flush everything*/
1418 write_lock_bh(&nf_conntrack_lock);
1419 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1421 if (del_timer(&exp->timeout)) {
1422 nf_ct_unlink_expect(exp);
1423 nf_conntrack_expect_put(exp);
1426 write_unlock_bh(&nf_conntrack_lock);
1432 ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nfattr *cda[])
1438 ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
1440 struct nf_conntrack_tuple tuple, mask, master_tuple;
1441 struct nf_conntrack_tuple_hash *h = NULL;
1442 struct nf_conntrack_expect *exp;
1446 DEBUGP("entered %s\n", __FUNCTION__);
1448 /* caller guarantees that those three CTA_EXPECT_* exist */
1449 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1452 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK, u3);
1455 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER, u3);
1459 /* Look for master conntrack of this expectation */
1460 h = nf_conntrack_find_get(&master_tuple, NULL);
1463 ct = nf_ct_tuplehash_to_ctrack(h);
1466 /* such conntrack hasn't got any helper, abort */
1471 exp = nf_conntrack_expect_alloc(ct);
1477 exp->expectfn = NULL;
1480 memcpy(&exp->tuple, &tuple, sizeof(struct nf_conntrack_tuple));
1481 memcpy(&exp->mask, &mask, sizeof(struct nf_conntrack_tuple));
1483 err = nf_conntrack_expect_related(exp);
1484 nf_conntrack_expect_put(exp);
1487 nf_ct_put(nf_ct_tuplehash_to_ctrack(h));
1492 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1493 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1495 struct nf_conntrack_tuple tuple;
1496 struct nf_conntrack_expect *exp;
1497 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1498 u_int8_t u3 = nfmsg->nfgen_family;
1501 DEBUGP("entered %s\n", __FUNCTION__);
1503 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1506 if (!cda[CTA_EXPECT_TUPLE-1]
1507 || !cda[CTA_EXPECT_MASK-1]
1508 || !cda[CTA_EXPECT_MASTER-1])
1511 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1515 write_lock_bh(&nf_conntrack_lock);
1516 exp = __nf_conntrack_expect_find(&tuple);
1519 write_unlock_bh(&nf_conntrack_lock);
1521 if (nlh->nlmsg_flags & NLM_F_CREATE)
1522 err = ctnetlink_create_expect(cda, u3);
1527 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1528 err = ctnetlink_change_expect(exp, cda);
1529 write_unlock_bh(&nf_conntrack_lock);
1531 DEBUGP("leaving\n");
1536 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1537 static struct notifier_block ctnl_notifier = {
1538 .notifier_call = ctnetlink_conntrack_event,
1541 static struct notifier_block ctnl_notifier_exp = {
1542 .notifier_call = ctnetlink_expect_event,
1546 static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
1547 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
1548 .attr_count = CTA_MAX, },
1549 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
1550 .attr_count = CTA_MAX, },
1551 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
1552 .attr_count = CTA_MAX, },
1553 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
1554 .attr_count = CTA_MAX, },
1557 static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
1558 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
1559 .attr_count = CTA_EXPECT_MAX, },
1560 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
1561 .attr_count = CTA_EXPECT_MAX, },
1562 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
1563 .attr_count = CTA_EXPECT_MAX, },
1566 static struct nfnetlink_subsystem ctnl_subsys = {
1567 .name = "conntrack",
1568 .subsys_id = NFNL_SUBSYS_CTNETLINK,
1569 .cb_count = IPCTNL_MSG_MAX,
1573 static struct nfnetlink_subsystem ctnl_exp_subsys = {
1574 .name = "conntrack_expect",
1575 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
1576 .cb_count = IPCTNL_MSG_EXP_MAX,
1580 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
1582 static int __init ctnetlink_init(void)
1586 printk("ctnetlink v%s: registering with nfnetlink.\n", version);
1587 ret = nfnetlink_subsys_register(&ctnl_subsys);
1589 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1593 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
1595 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1596 goto err_unreg_subsys;
1599 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1600 ret = nf_conntrack_register_notifier(&ctnl_notifier);
1602 printk("ctnetlink_init: cannot register notifier.\n");
1603 goto err_unreg_exp_subsys;
1606 ret = nf_conntrack_expect_register_notifier(&ctnl_notifier_exp);
1608 printk("ctnetlink_init: cannot expect register notifier.\n");
1609 goto err_unreg_notifier;
1615 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1617 nf_conntrack_unregister_notifier(&ctnl_notifier);
1618 err_unreg_exp_subsys:
1619 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1622 nfnetlink_subsys_unregister(&ctnl_subsys);
1627 static void __exit ctnetlink_exit(void)
1629 printk("ctnetlink: unregistering from nfnetlink.\n");
1631 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1632 nf_conntrack_unregister_notifier(&ctnl_notifier_exp);
1633 nf_conntrack_unregister_notifier(&ctnl_notifier);
1636 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1637 nfnetlink_subsys_unregister(&ctnl_subsys);
1641 module_init(ctnetlink_init);
1642 module_exit(ctnetlink_exit);