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-2006 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.
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/timer.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/notifier.h>
33 #include <linux/netfilter.h>
34 #include <linux/netfilter_ipv4/ip_conntrack.h>
35 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
36 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
37 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
38 #include <linux/netfilter_ipv4/ip_nat_protocol.h>
40 #include <linux/netfilter/nfnetlink.h>
41 #include <linux/netfilter/nfnetlink_conntrack.h>
43 MODULE_LICENSE("GPL");
45 static char __initdata version[] = "0.90";
50 #define DEBUGP(format, args...)
55 ctnetlink_dump_tuples_proto(struct sk_buff *skb,
56 const struct ip_conntrack_tuple *tuple,
57 struct ip_conntrack_protocol *proto)
60 struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
62 NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);
64 if (likely(proto->tuple_to_nfattr))
65 ret = proto->tuple_to_nfattr(skb, tuple);
67 NFA_NEST_END(skb, nest_parms);
76 ctnetlink_dump_tuples_ip(struct sk_buff *skb,
77 const struct ip_conntrack_tuple *tuple)
79 struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
81 NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(u_int32_t), &tuple->src.ip);
82 NFA_PUT(skb, CTA_IP_V4_DST, sizeof(u_int32_t), &tuple->dst.ip);
84 NFA_NEST_END(skb, nest_parms);
93 ctnetlink_dump_tuples(struct sk_buff *skb,
94 const struct ip_conntrack_tuple *tuple)
97 struct ip_conntrack_protocol *proto;
99 ret = ctnetlink_dump_tuples_ip(skb, tuple);
100 if (unlikely(ret < 0))
103 proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
104 ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
105 ip_conntrack_proto_put(proto);
111 ctnetlink_dump_status(struct sk_buff *skb, const struct ip_conntrack *ct)
113 u_int32_t status = htonl((u_int32_t) ct->status);
114 NFA_PUT(skb, CTA_STATUS, sizeof(status), &status);
122 ctnetlink_dump_timeout(struct sk_buff *skb, const struct ip_conntrack *ct)
124 long timeout_l = ct->timeout.expires - jiffies;
130 timeout = htonl(timeout_l / HZ);
132 NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout);
140 ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct ip_conntrack *ct)
142 struct ip_conntrack_protocol *proto = ip_conntrack_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
144 struct nfattr *nest_proto;
147 if (!proto->to_nfattr) {
148 ip_conntrack_proto_put(proto);
152 nest_proto = NFA_NEST(skb, CTA_PROTOINFO);
154 ret = proto->to_nfattr(skb, nest_proto, ct);
156 ip_conntrack_proto_put(proto);
158 NFA_NEST_END(skb, nest_proto);
167 ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct ip_conntrack *ct)
169 struct nfattr *nest_helper;
174 nest_helper = NFA_NEST(skb, CTA_HELP);
175 NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name);
177 if (ct->helper->to_nfattr)
178 ct->helper->to_nfattr(skb, ct);
180 NFA_NEST_END(skb, nest_helper);
188 #ifdef CONFIG_IP_NF_CT_ACCT
190 ctnetlink_dump_counters(struct sk_buff *skb, const struct ip_conntrack *ct,
191 enum ip_conntrack_dir dir)
193 enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
194 struct nfattr *nest_count = NFA_NEST(skb, type);
197 tmp = htonl(ct->counters[dir].packets);
198 NFA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp);
200 tmp = htonl(ct->counters[dir].bytes);
201 NFA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp);
203 NFA_NEST_END(skb, nest_count);
211 #define ctnetlink_dump_counters(a, b, c) (0)
214 #ifdef CONFIG_IP_NF_CONNTRACK_MARK
216 ctnetlink_dump_mark(struct sk_buff *skb, const struct ip_conntrack *ct)
218 u_int32_t mark = htonl(ct->mark);
220 NFA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark);
227 #define ctnetlink_dump_mark(a, b) (0)
231 ctnetlink_dump_id(struct sk_buff *skb, const struct ip_conntrack *ct)
233 u_int32_t id = htonl(ct->id);
234 NFA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id);
242 ctnetlink_dump_use(struct sk_buff *skb, const struct ip_conntrack *ct)
244 u_int32_t use = htonl(atomic_read(&ct->ct_general.use));
246 NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use);
253 #define tuple(ct, dir) (&(ct)->tuplehash[dir].tuple)
256 ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
257 int event, int nowait,
258 const struct ip_conntrack *ct)
260 struct nlmsghdr *nlh;
261 struct nfgenmsg *nfmsg;
262 struct nfattr *nest_parms;
267 event |= NFNL_SUBSYS_CTNETLINK << 8;
268 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
269 nfmsg = NLMSG_DATA(nlh);
271 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
272 nfmsg->nfgen_family = AF_INET;
273 nfmsg->version = NFNETLINK_V0;
276 nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
277 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
279 NFA_NEST_END(skb, nest_parms);
281 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
282 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
284 NFA_NEST_END(skb, nest_parms);
286 if (ctnetlink_dump_status(skb, ct) < 0 ||
287 ctnetlink_dump_timeout(skb, ct) < 0 ||
288 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
289 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0 ||
290 ctnetlink_dump_protoinfo(skb, ct) < 0 ||
291 ctnetlink_dump_helpinfo(skb, ct) < 0 ||
292 ctnetlink_dump_mark(skb, ct) < 0 ||
293 ctnetlink_dump_id(skb, ct) < 0 ||
294 ctnetlink_dump_use(skb, ct) < 0)
297 nlh->nlmsg_len = skb->tail - b;
302 skb_trim(skb, b - skb->data);
306 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
307 static int ctnetlink_conntrack_event(struct notifier_block *this,
308 unsigned long events, void *ptr)
310 struct nlmsghdr *nlh;
311 struct nfgenmsg *nfmsg;
312 struct nfattr *nest_parms;
313 struct ip_conntrack *ct = (struct ip_conntrack *)ptr;
317 unsigned int flags = 0, group;
319 /* ignore our fake conntrack entry */
320 if (ct == &ip_conntrack_untracked)
323 if (events & IPCT_DESTROY) {
324 type = IPCTNL_MSG_CT_DELETE;
325 group = NFNLGRP_CONNTRACK_DESTROY;
326 } else if (events & (IPCT_NEW | IPCT_RELATED)) {
327 type = IPCTNL_MSG_CT_NEW;
328 flags = NLM_F_CREATE|NLM_F_EXCL;
329 /* dump everything */
331 group = NFNLGRP_CONNTRACK_NEW;
332 } else if (events & (IPCT_STATUS |
337 type = IPCTNL_MSG_CT_NEW;
338 group = NFNLGRP_CONNTRACK_UPDATE;
342 if (!nfnetlink_has_listeners(group))
345 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
351 type |= NFNL_SUBSYS_CTNETLINK << 8;
352 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
353 nfmsg = NLMSG_DATA(nlh);
355 nlh->nlmsg_flags = flags;
356 nfmsg->nfgen_family = AF_INET;
357 nfmsg->version = NFNETLINK_V0;
360 nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
361 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
363 NFA_NEST_END(skb, nest_parms);
365 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
366 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
368 NFA_NEST_END(skb, nest_parms);
370 /* NAT stuff is now a status flag */
371 if ((events & IPCT_STATUS || events & IPCT_NATINFO)
372 && ctnetlink_dump_status(skb, ct) < 0)
374 if (events & IPCT_REFRESH
375 && ctnetlink_dump_timeout(skb, ct) < 0)
377 if (events & IPCT_PROTOINFO
378 && ctnetlink_dump_protoinfo(skb, ct) < 0)
380 if (events & IPCT_HELPINFO
381 && ctnetlink_dump_helpinfo(skb, ct) < 0)
384 if (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
385 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0)
388 nlh->nlmsg_len = skb->tail - b;
389 nfnetlink_send(skb, 0, group, 0);
397 #endif /* CONFIG_IP_NF_CONNTRACK_EVENTS */
399 static int ctnetlink_done(struct netlink_callback *cb)
401 DEBUGP("entered %s\n", __FUNCTION__);
403 ip_conntrack_put((struct ip_conntrack *)cb->args[1]);
408 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
410 struct ip_conntrack *ct, *last;
411 struct ip_conntrack_tuple_hash *h;
414 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__,
417 read_lock_bh(&ip_conntrack_lock);
418 for (; cb->args[0] < ip_conntrack_htable_size; cb->args[0]++) {
420 last = (struct ip_conntrack *)cb->args[1];
421 list_for_each_prev(i, &ip_conntrack_hash[cb->args[0]]) {
422 h = (struct ip_conntrack_tuple_hash *) i;
423 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
425 ct = tuplehash_to_ctrack(h);
428 ip_conntrack_put(last);
434 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
438 nf_conntrack_get(&ct->ct_general);
439 cb->args[1] = (unsigned long)ct;
444 ip_conntrack_put(last);
450 read_unlock_bh(&ip_conntrack_lock);
452 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
457 #ifdef CONFIG_IP_NF_CT_ACCT
459 ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
461 struct ip_conntrack *ct = NULL;
462 struct ip_conntrack_tuple_hash *h;
464 u_int32_t *id = (u_int32_t *) &cb->args[1];
466 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__,
469 write_lock_bh(&ip_conntrack_lock);
470 for (; cb->args[0] < ip_conntrack_htable_size; cb->args[0]++, *id = 0) {
471 list_for_each_prev(i, &ip_conntrack_hash[cb->args[0]]) {
472 h = (struct ip_conntrack_tuple_hash *) i;
473 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
475 ct = tuplehash_to_ctrack(h);
478 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
485 memset(&ct->counters, 0, sizeof(ct->counters));
489 write_unlock_bh(&ip_conntrack_lock);
491 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
497 static const size_t cta_min_ip[CTA_IP_MAX] = {
498 [CTA_IP_V4_SRC-1] = sizeof(u_int32_t),
499 [CTA_IP_V4_DST-1] = sizeof(u_int32_t),
503 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct ip_conntrack_tuple *tuple)
505 struct nfattr *tb[CTA_IP_MAX];
507 DEBUGP("entered %s\n", __FUNCTION__);
509 nfattr_parse_nested(tb, CTA_IP_MAX, attr);
511 if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip))
514 if (!tb[CTA_IP_V4_SRC-1])
516 tuple->src.ip = *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_SRC-1]);
518 if (!tb[CTA_IP_V4_DST-1])
520 tuple->dst.ip = *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_DST-1]);
527 static const size_t cta_min_proto[CTA_PROTO_MAX] = {
528 [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
529 [CTA_PROTO_SRC_PORT-1] = sizeof(u_int16_t),
530 [CTA_PROTO_DST_PORT-1] = sizeof(u_int16_t),
531 [CTA_PROTO_ICMP_TYPE-1] = sizeof(u_int8_t),
532 [CTA_PROTO_ICMP_CODE-1] = sizeof(u_int8_t),
533 [CTA_PROTO_ICMP_ID-1] = sizeof(u_int16_t),
537 ctnetlink_parse_tuple_proto(struct nfattr *attr,
538 struct ip_conntrack_tuple *tuple)
540 struct nfattr *tb[CTA_PROTO_MAX];
541 struct ip_conntrack_protocol *proto;
544 DEBUGP("entered %s\n", __FUNCTION__);
546 nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
548 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
551 if (!tb[CTA_PROTO_NUM-1])
553 tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
555 proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
557 if (likely(proto->nfattr_to_tuple))
558 ret = proto->nfattr_to_tuple(tb, tuple);
560 ip_conntrack_proto_put(proto);
566 ctnetlink_parse_tuple(struct nfattr *cda[], struct ip_conntrack_tuple *tuple,
567 enum ctattr_tuple type)
569 struct nfattr *tb[CTA_TUPLE_MAX];
572 DEBUGP("entered %s\n", __FUNCTION__);
574 memset(tuple, 0, sizeof(*tuple));
576 nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
578 if (!tb[CTA_TUPLE_IP-1])
581 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
585 if (!tb[CTA_TUPLE_PROTO-1])
588 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
592 /* orig and expect tuples get DIR_ORIGINAL */
593 if (type == CTA_TUPLE_REPLY)
594 tuple->dst.dir = IP_CT_DIR_REPLY;
596 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
605 #ifdef CONFIG_IP_NF_NAT_NEEDED
606 static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
607 [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
608 [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
611 static int ctnetlink_parse_nat_proto(struct nfattr *attr,
612 const struct ip_conntrack *ct,
613 struct ip_nat_range *range)
615 struct nfattr *tb[CTA_PROTONAT_MAX];
616 struct ip_nat_protocol *npt;
618 DEBUGP("entered %s\n", __FUNCTION__);
620 nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
622 if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
625 npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
627 if (!npt->nfattr_to_range) {
628 ip_nat_proto_put(npt);
632 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
633 if (npt->nfattr_to_range(tb, range) > 0)
634 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
636 ip_nat_proto_put(npt);
642 static const size_t cta_min_nat[CTA_NAT_MAX] = {
643 [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
644 [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
648 ctnetlink_parse_nat(struct nfattr *nat,
649 const struct ip_conntrack *ct, struct ip_nat_range *range)
651 struct nfattr *tb[CTA_NAT_MAX];
654 DEBUGP("entered %s\n", __FUNCTION__);
656 memset(range, 0, sizeof(*range));
658 nfattr_parse_nested(tb, CTA_NAT_MAX, nat);
660 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
663 if (tb[CTA_NAT_MINIP-1])
664 range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
666 if (!tb[CTA_NAT_MAXIP-1])
667 range->max_ip = range->min_ip;
669 range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
672 range->flags |= IP_NAT_RANGE_MAP_IPS;
674 if (!tb[CTA_NAT_PROTO-1])
677 err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
687 ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
689 struct nfattr *tb[CTA_HELP_MAX];
691 DEBUGP("entered %s\n", __FUNCTION__);
693 nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
695 if (!tb[CTA_HELP_NAME-1])
698 *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
703 static const size_t cta_min[CTA_MAX] = {
704 [CTA_STATUS-1] = sizeof(u_int32_t),
705 [CTA_TIMEOUT-1] = sizeof(u_int32_t),
706 [CTA_MARK-1] = sizeof(u_int32_t),
707 [CTA_USE-1] = sizeof(u_int32_t),
708 [CTA_ID-1] = sizeof(u_int32_t)
712 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
713 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
715 struct ip_conntrack_tuple_hash *h;
716 struct ip_conntrack_tuple tuple;
717 struct ip_conntrack *ct;
720 DEBUGP("entered %s\n", __FUNCTION__);
722 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
725 if (cda[CTA_TUPLE_ORIG-1])
726 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG);
727 else if (cda[CTA_TUPLE_REPLY-1])
728 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY);
730 /* Flush the whole table */
731 ip_conntrack_flush();
738 h = ip_conntrack_find_get(&tuple, NULL);
740 DEBUGP("tuple not found in conntrack hash\n");
744 ct = tuplehash_to_ctrack(h);
747 u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1]));
749 ip_conntrack_put(ct);
753 if (del_timer(&ct->timeout))
754 ct->timeout.function((unsigned long)ct);
756 ip_conntrack_put(ct);
763 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
764 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
766 struct ip_conntrack_tuple_hash *h;
767 struct ip_conntrack_tuple tuple;
768 struct ip_conntrack *ct;
769 struct sk_buff *skb2 = NULL;
772 DEBUGP("entered %s\n", __FUNCTION__);
774 if (nlh->nlmsg_flags & NLM_F_DUMP) {
775 struct nfgenmsg *msg = NLMSG_DATA(nlh);
778 if (msg->nfgen_family != AF_INET)
779 return -EAFNOSUPPORT;
781 if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
782 IPCTNL_MSG_CT_GET_CTRZERO) {
783 #ifdef CONFIG_IP_NF_CT_ACCT
784 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
785 ctnetlink_dump_table_w,
786 ctnetlink_done)) != 0)
792 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
793 ctnetlink_dump_table,
794 ctnetlink_done)) != 0)
798 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
805 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
808 if (cda[CTA_TUPLE_ORIG-1])
809 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG);
810 else if (cda[CTA_TUPLE_REPLY-1])
811 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY);
818 h = ip_conntrack_find_get(&tuple, NULL);
820 DEBUGP("tuple not found in conntrack hash");
823 DEBUGP("tuple found\n");
824 ct = tuplehash_to_ctrack(h);
827 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
829 ip_conntrack_put(ct);
832 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
834 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
835 IPCTNL_MSG_CT_NEW, 1, ct);
836 ip_conntrack_put(ct);
840 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
854 ctnetlink_change_status(struct ip_conntrack *ct, struct nfattr *cda[])
857 unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1]));
858 d = ct->status ^ status;
860 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
864 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
865 /* SEEN_REPLY bit can only be set */
869 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
870 /* ASSURED bit can only be set */
873 if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
874 #ifndef CONFIG_IP_NF_NAT_NEEDED
877 struct ip_nat_range range;
879 if (cda[CTA_NAT_DST-1]) {
880 if (ctnetlink_parse_nat(cda[CTA_NAT_DST-1], ct,
883 if (ip_nat_initialized(ct,
884 HOOK2MANIP(NF_IP_PRE_ROUTING)))
886 ip_nat_setup_info(ct, &range, NF_IP_PRE_ROUTING);
888 if (cda[CTA_NAT_SRC-1]) {
889 if (ctnetlink_parse_nat(cda[CTA_NAT_SRC-1], ct,
892 if (ip_nat_initialized(ct,
893 HOOK2MANIP(NF_IP_POST_ROUTING)))
895 ip_nat_setup_info(ct, &range, NF_IP_POST_ROUTING);
900 /* Be careful here, modifying NAT bits can screw up things,
901 * so don't let users modify them directly if they don't pass
903 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
909 ctnetlink_change_helper(struct ip_conntrack *ct, struct nfattr *cda[])
911 struct ip_conntrack_helper *helper;
915 DEBUGP("entered %s\n", __FUNCTION__);
917 /* don't change helper of sibling connections */
921 err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
925 helper = __ip_conntrack_helper_find_byname(helpname);
927 if (!strcmp(helpname, ""))
935 /* we had a helper before ... */
936 ip_ct_remove_expectations(ct);
939 /* need to zero data of old helper */
940 memset(&ct->help, 0, sizeof(ct->help));
950 ctnetlink_change_timeout(struct ip_conntrack *ct, struct nfattr *cda[])
952 u_int32_t timeout = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
954 if (!del_timer(&ct->timeout))
957 ct->timeout.expires = jiffies + timeout * HZ;
958 add_timer(&ct->timeout);
964 ctnetlink_change_protoinfo(struct ip_conntrack *ct, struct nfattr *cda[])
966 struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
967 struct ip_conntrack_protocol *proto;
968 u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
971 nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
973 proto = ip_conntrack_proto_find_get(npt);
975 if (proto->from_nfattr)
976 err = proto->from_nfattr(tb, ct);
977 ip_conntrack_proto_put(proto);
983 ctnetlink_change_conntrack(struct ip_conntrack *ct, struct nfattr *cda[])
987 DEBUGP("entered %s\n", __FUNCTION__);
989 if (cda[CTA_HELP-1]) {
990 err = ctnetlink_change_helper(ct, cda);
995 if (cda[CTA_TIMEOUT-1]) {
996 err = ctnetlink_change_timeout(ct, cda);
1001 if (cda[CTA_STATUS-1]) {
1002 err = ctnetlink_change_status(ct, cda);
1007 if (cda[CTA_PROTOINFO-1]) {
1008 err = ctnetlink_change_protoinfo(ct, cda);
1013 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1014 if (cda[CTA_MARK-1])
1015 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1018 DEBUGP("all done\n");
1023 ctnetlink_create_conntrack(struct nfattr *cda[],
1024 struct ip_conntrack_tuple *otuple,
1025 struct ip_conntrack_tuple *rtuple)
1027 struct ip_conntrack *ct;
1030 DEBUGP("entered %s\n", __FUNCTION__);
1032 ct = ip_conntrack_alloc(otuple, rtuple);
1033 if (ct == NULL || IS_ERR(ct))
1036 if (!cda[CTA_TIMEOUT-1])
1038 ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
1040 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1041 ct->status |= IPS_CONFIRMED;
1043 err = ctnetlink_change_status(ct, cda);
1047 if (cda[CTA_PROTOINFO-1]) {
1048 err = ctnetlink_change_protoinfo(ct, cda);
1053 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1054 if (cda[CTA_MARK-1])
1055 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1058 ct->helper = ip_conntrack_helper_find_get(rtuple);
1060 add_timer(&ct->timeout);
1061 ip_conntrack_hash_insert(ct);
1064 ip_conntrack_helper_put(ct->helper);
1066 DEBUGP("conntrack with id %u inserted\n", ct->id);
1070 ip_conntrack_free(ct);
1075 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1076 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1078 struct ip_conntrack_tuple otuple, rtuple;
1079 struct ip_conntrack_tuple_hash *h = NULL;
1082 DEBUGP("entered %s\n", __FUNCTION__);
1084 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
1087 if (cda[CTA_TUPLE_ORIG-1]) {
1088 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG);
1093 if (cda[CTA_TUPLE_REPLY-1]) {
1094 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY);
1099 write_lock_bh(&ip_conntrack_lock);
1100 if (cda[CTA_TUPLE_ORIG-1])
1101 h = __ip_conntrack_find(&otuple, NULL);
1102 else if (cda[CTA_TUPLE_REPLY-1])
1103 h = __ip_conntrack_find(&rtuple, NULL);
1106 write_unlock_bh(&ip_conntrack_lock);
1107 DEBUGP("no such conntrack, create new\n");
1109 if (nlh->nlmsg_flags & NLM_F_CREATE)
1110 err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
1113 /* implicit 'else' */
1115 /* we only allow nat config for new conntracks */
1116 if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
1121 /* We manipulate the conntrack inside the global conntrack table lock,
1122 * so there's no need to increase the refcount */
1123 DEBUGP("conntrack found\n");
1125 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1126 err = ctnetlink_change_conntrack(tuplehash_to_ctrack(h), cda);
1129 write_unlock_bh(&ip_conntrack_lock);
1133 /***********************************************************************
1135 ***********************************************************************/
1138 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1139 const struct ip_conntrack_tuple *tuple,
1140 enum ctattr_expect type)
1142 struct nfattr *nest_parms = NFA_NEST(skb, type);
1144 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1145 goto nfattr_failure;
1147 NFA_NEST_END(skb, nest_parms);
1156 ctnetlink_exp_dump_mask(struct sk_buff *skb,
1157 const struct ip_conntrack_tuple *tuple,
1158 const struct ip_conntrack_tuple *mask)
1161 struct ip_conntrack_protocol *proto;
1162 struct nfattr *nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);
1164 ret = ctnetlink_dump_tuples_ip(skb, mask);
1165 if (unlikely(ret < 0))
1166 goto nfattr_failure;
1168 proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
1169 ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
1170 ip_conntrack_proto_put(proto);
1171 if (unlikely(ret < 0))
1172 goto nfattr_failure;
1174 NFA_NEST_END(skb, nest_parms);
1183 ctnetlink_exp_dump_expect(struct sk_buff *skb,
1184 const struct ip_conntrack_expect *exp)
1186 struct ip_conntrack *master = exp->master;
1187 u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ);
1188 u_int32_t id = htonl(exp->id);
1190 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
1191 goto nfattr_failure;
1192 if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
1193 goto nfattr_failure;
1194 if (ctnetlink_exp_dump_tuple(skb,
1195 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1196 CTA_EXPECT_MASTER) < 0)
1197 goto nfattr_failure;
1199 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
1200 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
1209 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1212 const struct ip_conntrack_expect *exp)
1214 struct nlmsghdr *nlh;
1215 struct nfgenmsg *nfmsg;
1220 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1221 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
1222 nfmsg = NLMSG_DATA(nlh);
1224 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1225 nfmsg->nfgen_family = AF_INET;
1226 nfmsg->version = NFNETLINK_V0;
1229 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1230 goto nfattr_failure;
1232 nlh->nlmsg_len = skb->tail - b;
1237 skb_trim(skb, b - skb->data);
1241 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1242 static int ctnetlink_expect_event(struct notifier_block *this,
1243 unsigned long events, void *ptr)
1245 struct nlmsghdr *nlh;
1246 struct nfgenmsg *nfmsg;
1247 struct ip_conntrack_expect *exp = (struct ip_conntrack_expect *)ptr;
1248 struct sk_buff *skb;
1253 if (events & IPEXP_NEW) {
1254 type = IPCTNL_MSG_EXP_NEW;
1255 flags = NLM_F_CREATE|NLM_F_EXCL;
1259 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
1265 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1266 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
1267 nfmsg = NLMSG_DATA(nlh);
1269 nlh->nlmsg_flags = flags;
1270 nfmsg->nfgen_family = AF_INET;
1271 nfmsg->version = NFNETLINK_V0;
1274 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1275 goto nfattr_failure;
1277 nlh->nlmsg_len = skb->tail - b;
1278 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
1289 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1291 struct ip_conntrack_expect *exp = NULL;
1292 struct list_head *i;
1293 u_int32_t *id = (u_int32_t *) &cb->args[0];
1295 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
1297 read_lock_bh(&ip_conntrack_lock);
1298 list_for_each_prev(i, &ip_conntrack_expect_list) {
1299 exp = (struct ip_conntrack_expect *) i;
1302 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid,
1310 read_unlock_bh(&ip_conntrack_lock);
1312 DEBUGP("leaving, last id=%llu\n", *id);
1317 static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1318 [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
1319 [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
1323 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1324 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1326 struct ip_conntrack_tuple tuple;
1327 struct ip_conntrack_expect *exp;
1328 struct sk_buff *skb2;
1331 DEBUGP("entered %s\n", __FUNCTION__);
1333 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1336 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1337 struct nfgenmsg *msg = NLMSG_DATA(nlh);
1340 if (msg->nfgen_family != AF_INET)
1341 return -EAFNOSUPPORT;
1343 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1344 ctnetlink_exp_dump_table,
1345 ctnetlink_done)) != 0)
1347 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1348 if (rlen > skb->len)
1350 skb_pull(skb, rlen);
1354 if (cda[CTA_EXPECT_MASTER-1])
1355 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER);
1362 exp = ip_conntrack_expect_find(&tuple);
1366 if (cda[CTA_EXPECT_ID-1]) {
1367 u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1368 if (exp->id != ntohl(id)) {
1369 ip_conntrack_expect_put(exp);
1375 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1378 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
1380 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1381 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1386 ip_conntrack_expect_put(exp);
1388 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1393 ip_conntrack_expect_put(exp);
1398 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1399 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1401 struct ip_conntrack_expect *exp, *tmp;
1402 struct ip_conntrack_tuple tuple;
1403 struct ip_conntrack_helper *h;
1406 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1409 if (cda[CTA_EXPECT_TUPLE-1]) {
1410 /* delete a single expect by tuple */
1411 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1415 /* bump usage count to 2 */
1416 exp = ip_conntrack_expect_find(&tuple);
1420 if (cda[CTA_EXPECT_ID-1]) {
1422 *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1423 if (exp->id != ntohl(id)) {
1424 ip_conntrack_expect_put(exp);
1429 /* after list removal, usage count == 1 */
1430 ip_conntrack_unexpect_related(exp);
1431 /* have to put what we 'get' above.
1432 * after this line usage count == 0 */
1433 ip_conntrack_expect_put(exp);
1434 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
1435 char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
1437 /* delete all expectations for this helper */
1438 write_lock_bh(&ip_conntrack_lock);
1439 h = __ip_conntrack_helper_find_byname(name);
1441 write_unlock_bh(&ip_conntrack_lock);
1444 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list,
1446 if (exp->master->helper == h
1447 && del_timer(&exp->timeout)) {
1448 ip_ct_unlink_expect(exp);
1449 ip_conntrack_expect_put(exp);
1452 write_unlock_bh(&ip_conntrack_lock);
1454 /* This basically means we have to flush everything*/
1455 write_lock_bh(&ip_conntrack_lock);
1456 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list,
1458 if (del_timer(&exp->timeout)) {
1459 ip_ct_unlink_expect(exp);
1460 ip_conntrack_expect_put(exp);
1463 write_unlock_bh(&ip_conntrack_lock);
1469 ctnetlink_change_expect(struct ip_conntrack_expect *x, struct nfattr *cda[])
1475 ctnetlink_create_expect(struct nfattr *cda[])
1477 struct ip_conntrack_tuple tuple, mask, master_tuple;
1478 struct ip_conntrack_tuple_hash *h = NULL;
1479 struct ip_conntrack_expect *exp;
1480 struct ip_conntrack *ct;
1483 DEBUGP("entered %s\n", __FUNCTION__);
1485 /* caller guarantees that those three CTA_EXPECT_* exist */
1486 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1489 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK);
1492 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER);
1496 /* Look for master conntrack of this expectation */
1497 h = ip_conntrack_find_get(&master_tuple, NULL);
1500 ct = tuplehash_to_ctrack(h);
1503 /* such conntrack hasn't got any helper, abort */
1508 exp = ip_conntrack_expect_alloc(ct);
1514 exp->expectfn = NULL;
1517 memcpy(&exp->tuple, &tuple, sizeof(struct ip_conntrack_tuple));
1518 memcpy(&exp->mask, &mask, sizeof(struct ip_conntrack_tuple));
1520 err = ip_conntrack_expect_related(exp);
1521 ip_conntrack_expect_put(exp);
1524 ip_conntrack_put(tuplehash_to_ctrack(h));
1529 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1530 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1532 struct ip_conntrack_tuple tuple;
1533 struct ip_conntrack_expect *exp;
1536 DEBUGP("entered %s\n", __FUNCTION__);
1538 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1541 if (!cda[CTA_EXPECT_TUPLE-1]
1542 || !cda[CTA_EXPECT_MASK-1]
1543 || !cda[CTA_EXPECT_MASTER-1])
1546 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1550 write_lock_bh(&ip_conntrack_lock);
1551 exp = __ip_conntrack_expect_find(&tuple);
1554 write_unlock_bh(&ip_conntrack_lock);
1556 if (nlh->nlmsg_flags & NLM_F_CREATE)
1557 err = ctnetlink_create_expect(cda);
1562 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1563 err = ctnetlink_change_expect(exp, cda);
1564 write_unlock_bh(&ip_conntrack_lock);
1566 DEBUGP("leaving\n");
1571 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1572 static struct notifier_block ctnl_notifier = {
1573 .notifier_call = ctnetlink_conntrack_event,
1576 static struct notifier_block ctnl_notifier_exp = {
1577 .notifier_call = ctnetlink_expect_event,
1581 static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
1582 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
1583 .attr_count = CTA_MAX, },
1584 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
1585 .attr_count = CTA_MAX, },
1586 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
1587 .attr_count = CTA_MAX, },
1588 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
1589 .attr_count = CTA_MAX, },
1592 static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
1593 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
1594 .attr_count = CTA_EXPECT_MAX, },
1595 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
1596 .attr_count = CTA_EXPECT_MAX, },
1597 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
1598 .attr_count = CTA_EXPECT_MAX, },
1601 static struct nfnetlink_subsystem ctnl_subsys = {
1602 .name = "conntrack",
1603 .subsys_id = NFNL_SUBSYS_CTNETLINK,
1604 .cb_count = IPCTNL_MSG_MAX,
1608 static struct nfnetlink_subsystem ctnl_exp_subsys = {
1609 .name = "conntrack_expect",
1610 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
1611 .cb_count = IPCTNL_MSG_EXP_MAX,
1615 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
1616 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_EXP);
1618 static int __init ctnetlink_init(void)
1622 printk("ctnetlink v%s: registering with nfnetlink.\n", version);
1623 ret = nfnetlink_subsys_register(&ctnl_subsys);
1625 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1629 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
1631 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1632 goto err_unreg_subsys;
1635 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1636 ret = ip_conntrack_register_notifier(&ctnl_notifier);
1638 printk("ctnetlink_init: cannot register notifier.\n");
1639 goto err_unreg_exp_subsys;
1642 ret = ip_conntrack_expect_register_notifier(&ctnl_notifier_exp);
1644 printk("ctnetlink_init: cannot expect register notifier.\n");
1645 goto err_unreg_notifier;
1651 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1653 ip_conntrack_unregister_notifier(&ctnl_notifier);
1654 err_unreg_exp_subsys:
1655 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1658 nfnetlink_subsys_unregister(&ctnl_subsys);
1663 static void __exit ctnetlink_exit(void)
1665 printk("ctnetlink: unregistering from nfnetlink.\n");
1667 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1668 ip_conntrack_expect_unregister_notifier(&ctnl_notifier_exp);
1669 ip_conntrack_unregister_notifier(&ctnl_notifier);
1672 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1673 nfnetlink_subsys_unregister(&ctnl_subsys);
1677 module_init(ctnetlink_init);
1678 module_exit(ctnetlink_exit);