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 if (events & IPCT_MARK
389 && ctnetlink_dump_mark(skb, ct) < 0)
392 nlh->nlmsg_len = skb->tail - b;
393 nfnetlink_send(skb, 0, group, 0);
401 #endif /* CONFIG_IP_NF_CONNTRACK_EVENTS */
403 static int ctnetlink_done(struct netlink_callback *cb)
405 DEBUGP("entered %s\n", __FUNCTION__);
407 ip_conntrack_put((struct ip_conntrack *)cb->args[1]);
412 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
414 struct ip_conntrack *ct, *last;
415 struct ip_conntrack_tuple_hash *h;
418 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__,
421 read_lock_bh(&ip_conntrack_lock);
422 last = (struct ip_conntrack *)cb->args[1];
423 for (; cb->args[0] < ip_conntrack_htable_size; cb->args[0]++) {
425 list_for_each_prev(i, &ip_conntrack_hash[cb->args[0]]) {
426 h = (struct ip_conntrack_tuple_hash *) i;
427 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
429 ct = tuplehash_to_ctrack(h);
435 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
439 nf_conntrack_get(&ct->ct_general);
440 cb->args[1] = (unsigned long)ct;
450 read_unlock_bh(&ip_conntrack_lock);
452 ip_conntrack_put(last);
454 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
458 #ifdef CONFIG_IP_NF_CT_ACCT
460 ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
462 struct ip_conntrack *ct = NULL;
463 struct ip_conntrack_tuple_hash *h;
465 u_int32_t *id = (u_int32_t *) &cb->args[1];
467 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__,
470 write_lock_bh(&ip_conntrack_lock);
471 for (; cb->args[0] < ip_conntrack_htable_size; cb->args[0]++, *id = 0) {
472 list_for_each_prev(i, &ip_conntrack_hash[cb->args[0]]) {
473 h = (struct ip_conntrack_tuple_hash *) i;
474 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
476 ct = tuplehash_to_ctrack(h);
479 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
486 memset(&ct->counters, 0, sizeof(ct->counters));
490 write_unlock_bh(&ip_conntrack_lock);
492 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
498 static const size_t cta_min_ip[CTA_IP_MAX] = {
499 [CTA_IP_V4_SRC-1] = sizeof(u_int32_t),
500 [CTA_IP_V4_DST-1] = sizeof(u_int32_t),
504 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct ip_conntrack_tuple *tuple)
506 struct nfattr *tb[CTA_IP_MAX];
508 DEBUGP("entered %s\n", __FUNCTION__);
510 nfattr_parse_nested(tb, CTA_IP_MAX, attr);
512 if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip))
515 if (!tb[CTA_IP_V4_SRC-1])
517 tuple->src.ip = *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_SRC-1]);
519 if (!tb[CTA_IP_V4_DST-1])
521 tuple->dst.ip = *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_DST-1]);
528 static const size_t cta_min_proto[CTA_PROTO_MAX] = {
529 [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
530 [CTA_PROTO_SRC_PORT-1] = sizeof(u_int16_t),
531 [CTA_PROTO_DST_PORT-1] = sizeof(u_int16_t),
532 [CTA_PROTO_ICMP_TYPE-1] = sizeof(u_int8_t),
533 [CTA_PROTO_ICMP_CODE-1] = sizeof(u_int8_t),
534 [CTA_PROTO_ICMP_ID-1] = sizeof(u_int16_t),
538 ctnetlink_parse_tuple_proto(struct nfattr *attr,
539 struct ip_conntrack_tuple *tuple)
541 struct nfattr *tb[CTA_PROTO_MAX];
542 struct ip_conntrack_protocol *proto;
545 DEBUGP("entered %s\n", __FUNCTION__);
547 nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
549 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
552 if (!tb[CTA_PROTO_NUM-1])
554 tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
556 proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
558 if (likely(proto->nfattr_to_tuple))
559 ret = proto->nfattr_to_tuple(tb, tuple);
561 ip_conntrack_proto_put(proto);
567 ctnetlink_parse_tuple(struct nfattr *cda[], struct ip_conntrack_tuple *tuple,
568 enum ctattr_tuple type)
570 struct nfattr *tb[CTA_TUPLE_MAX];
573 DEBUGP("entered %s\n", __FUNCTION__);
575 memset(tuple, 0, sizeof(*tuple));
577 nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
579 if (!tb[CTA_TUPLE_IP-1])
582 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
586 if (!tb[CTA_TUPLE_PROTO-1])
589 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
593 /* orig and expect tuples get DIR_ORIGINAL */
594 if (type == CTA_TUPLE_REPLY)
595 tuple->dst.dir = IP_CT_DIR_REPLY;
597 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
606 #ifdef CONFIG_IP_NF_NAT_NEEDED
607 static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
608 [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
609 [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
612 static int ctnetlink_parse_nat_proto(struct nfattr *attr,
613 const struct ip_conntrack *ct,
614 struct ip_nat_range *range)
616 struct nfattr *tb[CTA_PROTONAT_MAX];
617 struct ip_nat_protocol *npt;
619 DEBUGP("entered %s\n", __FUNCTION__);
621 nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
623 if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
626 npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
628 if (!npt->nfattr_to_range) {
629 ip_nat_proto_put(npt);
633 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
634 if (npt->nfattr_to_range(tb, range) > 0)
635 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
637 ip_nat_proto_put(npt);
643 static const size_t cta_min_nat[CTA_NAT_MAX] = {
644 [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
645 [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
649 ctnetlink_parse_nat(struct nfattr *nat,
650 const struct ip_conntrack *ct, struct ip_nat_range *range)
652 struct nfattr *tb[CTA_NAT_MAX];
655 DEBUGP("entered %s\n", __FUNCTION__);
657 memset(range, 0, sizeof(*range));
659 nfattr_parse_nested(tb, CTA_NAT_MAX, nat);
661 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
664 if (tb[CTA_NAT_MINIP-1])
665 range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
667 if (!tb[CTA_NAT_MAXIP-1])
668 range->max_ip = range->min_ip;
670 range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
673 range->flags |= IP_NAT_RANGE_MAP_IPS;
675 if (!tb[CTA_NAT_PROTO-1])
678 err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
688 ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
690 struct nfattr *tb[CTA_HELP_MAX];
692 DEBUGP("entered %s\n", __FUNCTION__);
694 nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
696 if (!tb[CTA_HELP_NAME-1])
699 *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
704 static const size_t cta_min[CTA_MAX] = {
705 [CTA_STATUS-1] = sizeof(u_int32_t),
706 [CTA_TIMEOUT-1] = sizeof(u_int32_t),
707 [CTA_MARK-1] = sizeof(u_int32_t),
708 [CTA_USE-1] = sizeof(u_int32_t),
709 [CTA_ID-1] = sizeof(u_int32_t)
713 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
714 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
716 struct ip_conntrack_tuple_hash *h;
717 struct ip_conntrack_tuple tuple;
718 struct ip_conntrack *ct;
721 DEBUGP("entered %s\n", __FUNCTION__);
723 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
726 if (cda[CTA_TUPLE_ORIG-1])
727 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG);
728 else if (cda[CTA_TUPLE_REPLY-1])
729 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY);
731 /* Flush the whole table */
732 ip_conntrack_flush();
739 h = ip_conntrack_find_get(&tuple, NULL);
741 DEBUGP("tuple not found in conntrack hash\n");
745 ct = tuplehash_to_ctrack(h);
748 u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1]));
750 ip_conntrack_put(ct);
754 if (del_timer(&ct->timeout))
755 ct->timeout.function((unsigned long)ct);
757 ip_conntrack_put(ct);
764 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
765 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
767 struct ip_conntrack_tuple_hash *h;
768 struct ip_conntrack_tuple tuple;
769 struct ip_conntrack *ct;
770 struct sk_buff *skb2 = NULL;
773 DEBUGP("entered %s\n", __FUNCTION__);
775 if (nlh->nlmsg_flags & NLM_F_DUMP) {
776 struct nfgenmsg *msg = NLMSG_DATA(nlh);
779 if (msg->nfgen_family != AF_INET)
780 return -EAFNOSUPPORT;
782 if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
783 IPCTNL_MSG_CT_GET_CTRZERO) {
784 #ifdef CONFIG_IP_NF_CT_ACCT
785 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
786 ctnetlink_dump_table_w,
787 ctnetlink_done)) != 0)
793 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
794 ctnetlink_dump_table,
795 ctnetlink_done)) != 0)
799 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
806 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
809 if (cda[CTA_TUPLE_ORIG-1])
810 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG);
811 else if (cda[CTA_TUPLE_REPLY-1])
812 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY);
819 h = ip_conntrack_find_get(&tuple, NULL);
821 DEBUGP("tuple not found in conntrack hash");
824 DEBUGP("tuple found\n");
825 ct = tuplehash_to_ctrack(h);
828 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
830 ip_conntrack_put(ct);
833 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
835 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
836 IPCTNL_MSG_CT_NEW, 1, ct);
837 ip_conntrack_put(ct);
841 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
855 ctnetlink_change_status(struct ip_conntrack *ct, struct nfattr *cda[])
858 unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1]));
859 d = ct->status ^ status;
861 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
865 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
866 /* SEEN_REPLY bit can only be set */
870 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
871 /* ASSURED bit can only be set */
874 if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
875 #ifndef CONFIG_IP_NF_NAT_NEEDED
878 struct ip_nat_range range;
880 if (cda[CTA_NAT_DST-1]) {
881 if (ctnetlink_parse_nat(cda[CTA_NAT_DST-1], ct,
884 if (ip_nat_initialized(ct,
885 HOOK2MANIP(NF_IP_PRE_ROUTING)))
887 ip_nat_setup_info(ct, &range, NF_IP_PRE_ROUTING);
889 if (cda[CTA_NAT_SRC-1]) {
890 if (ctnetlink_parse_nat(cda[CTA_NAT_SRC-1], ct,
893 if (ip_nat_initialized(ct,
894 HOOK2MANIP(NF_IP_POST_ROUTING)))
896 ip_nat_setup_info(ct, &range, NF_IP_POST_ROUTING);
901 /* Be careful here, modifying NAT bits can screw up things,
902 * so don't let users modify them directly if they don't pass
904 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
910 ctnetlink_change_helper(struct ip_conntrack *ct, struct nfattr *cda[])
912 struct ip_conntrack_helper *helper;
916 DEBUGP("entered %s\n", __FUNCTION__);
918 /* don't change helper of sibling connections */
922 err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
926 helper = __ip_conntrack_helper_find_byname(helpname);
928 if (!strcmp(helpname, ""))
936 /* we had a helper before ... */
937 ip_ct_remove_expectations(ct);
940 /* need to zero data of old helper */
941 memset(&ct->help, 0, sizeof(ct->help));
951 ctnetlink_change_timeout(struct ip_conntrack *ct, struct nfattr *cda[])
953 u_int32_t timeout = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
955 if (!del_timer(&ct->timeout))
958 ct->timeout.expires = jiffies + timeout * HZ;
959 add_timer(&ct->timeout);
965 ctnetlink_change_protoinfo(struct ip_conntrack *ct, struct nfattr *cda[])
967 struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
968 struct ip_conntrack_protocol *proto;
969 u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
972 nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
974 proto = ip_conntrack_proto_find_get(npt);
976 if (proto->from_nfattr)
977 err = proto->from_nfattr(tb, ct);
978 ip_conntrack_proto_put(proto);
984 ctnetlink_change_conntrack(struct ip_conntrack *ct, struct nfattr *cda[])
988 DEBUGP("entered %s\n", __FUNCTION__);
990 if (cda[CTA_HELP-1]) {
991 err = ctnetlink_change_helper(ct, cda);
996 if (cda[CTA_TIMEOUT-1]) {
997 err = ctnetlink_change_timeout(ct, cda);
1002 if (cda[CTA_STATUS-1]) {
1003 err = ctnetlink_change_status(ct, cda);
1008 if (cda[CTA_PROTOINFO-1]) {
1009 err = ctnetlink_change_protoinfo(ct, cda);
1014 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1015 if (cda[CTA_MARK-1])
1016 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1019 DEBUGP("all done\n");
1024 ctnetlink_create_conntrack(struct nfattr *cda[],
1025 struct ip_conntrack_tuple *otuple,
1026 struct ip_conntrack_tuple *rtuple)
1028 struct ip_conntrack *ct;
1031 DEBUGP("entered %s\n", __FUNCTION__);
1033 ct = ip_conntrack_alloc(otuple, rtuple);
1034 if (ct == NULL || IS_ERR(ct))
1037 if (!cda[CTA_TIMEOUT-1])
1039 ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
1041 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1042 ct->status |= IPS_CONFIRMED;
1044 err = ctnetlink_change_status(ct, cda);
1048 if (cda[CTA_PROTOINFO-1]) {
1049 err = ctnetlink_change_protoinfo(ct, cda);
1054 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1055 if (cda[CTA_MARK-1])
1056 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1059 ct->helper = ip_conntrack_helper_find_get(rtuple);
1061 add_timer(&ct->timeout);
1062 ip_conntrack_hash_insert(ct);
1065 ip_conntrack_helper_put(ct->helper);
1067 DEBUGP("conntrack with id %u inserted\n", ct->id);
1071 ip_conntrack_free(ct);
1076 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1077 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1079 struct ip_conntrack_tuple otuple, rtuple;
1080 struct ip_conntrack_tuple_hash *h = NULL;
1083 DEBUGP("entered %s\n", __FUNCTION__);
1085 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
1088 if (cda[CTA_TUPLE_ORIG-1]) {
1089 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG);
1094 if (cda[CTA_TUPLE_REPLY-1]) {
1095 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY);
1100 write_lock_bh(&ip_conntrack_lock);
1101 if (cda[CTA_TUPLE_ORIG-1])
1102 h = __ip_conntrack_find(&otuple, NULL);
1103 else if (cda[CTA_TUPLE_REPLY-1])
1104 h = __ip_conntrack_find(&rtuple, NULL);
1107 write_unlock_bh(&ip_conntrack_lock);
1108 DEBUGP("no such conntrack, create new\n");
1110 if (nlh->nlmsg_flags & NLM_F_CREATE)
1111 err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
1114 /* implicit 'else' */
1116 /* we only allow nat config for new conntracks */
1117 if (cda[CTA_NAT_SRC-1] || cda[CTA_NAT_DST-1]) {
1122 /* We manipulate the conntrack inside the global conntrack table lock,
1123 * so there's no need to increase the refcount */
1124 DEBUGP("conntrack found\n");
1126 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1127 err = ctnetlink_change_conntrack(tuplehash_to_ctrack(h), cda);
1130 write_unlock_bh(&ip_conntrack_lock);
1134 /***********************************************************************
1136 ***********************************************************************/
1139 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1140 const struct ip_conntrack_tuple *tuple,
1141 enum ctattr_expect type)
1143 struct nfattr *nest_parms = NFA_NEST(skb, type);
1145 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1146 goto nfattr_failure;
1148 NFA_NEST_END(skb, nest_parms);
1157 ctnetlink_exp_dump_mask(struct sk_buff *skb,
1158 const struct ip_conntrack_tuple *tuple,
1159 const struct ip_conntrack_tuple *mask)
1162 struct ip_conntrack_protocol *proto;
1163 struct nfattr *nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);
1165 ret = ctnetlink_dump_tuples_ip(skb, mask);
1166 if (unlikely(ret < 0))
1167 goto nfattr_failure;
1169 proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
1170 ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
1171 ip_conntrack_proto_put(proto);
1172 if (unlikely(ret < 0))
1173 goto nfattr_failure;
1175 NFA_NEST_END(skb, nest_parms);
1184 ctnetlink_exp_dump_expect(struct sk_buff *skb,
1185 const struct ip_conntrack_expect *exp)
1187 struct ip_conntrack *master = exp->master;
1188 u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ);
1189 u_int32_t id = htonl(exp->id);
1191 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
1192 goto nfattr_failure;
1193 if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
1194 goto nfattr_failure;
1195 if (ctnetlink_exp_dump_tuple(skb,
1196 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1197 CTA_EXPECT_MASTER) < 0)
1198 goto nfattr_failure;
1200 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
1201 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
1210 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1213 const struct ip_conntrack_expect *exp)
1215 struct nlmsghdr *nlh;
1216 struct nfgenmsg *nfmsg;
1221 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1222 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
1223 nfmsg = NLMSG_DATA(nlh);
1225 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1226 nfmsg->nfgen_family = AF_INET;
1227 nfmsg->version = NFNETLINK_V0;
1230 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1231 goto nfattr_failure;
1233 nlh->nlmsg_len = skb->tail - b;
1238 skb_trim(skb, b - skb->data);
1242 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1243 static int ctnetlink_expect_event(struct notifier_block *this,
1244 unsigned long events, void *ptr)
1246 struct nlmsghdr *nlh;
1247 struct nfgenmsg *nfmsg;
1248 struct ip_conntrack_expect *exp = (struct ip_conntrack_expect *)ptr;
1249 struct sk_buff *skb;
1254 if (events & IPEXP_NEW) {
1255 type = IPCTNL_MSG_EXP_NEW;
1256 flags = NLM_F_CREATE|NLM_F_EXCL;
1260 if (!nfnetlink_has_listeners(NFNLGRP_CONNTRACK_EXP_NEW))
1263 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
1269 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1270 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
1271 nfmsg = NLMSG_DATA(nlh);
1273 nlh->nlmsg_flags = flags;
1274 nfmsg->nfgen_family = AF_INET;
1275 nfmsg->version = NFNETLINK_V0;
1278 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1279 goto nfattr_failure;
1281 nlh->nlmsg_len = skb->tail - b;
1282 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
1293 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1295 struct ip_conntrack_expect *exp = NULL;
1296 struct list_head *i;
1297 u_int32_t *id = (u_int32_t *) &cb->args[0];
1299 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
1301 read_lock_bh(&ip_conntrack_lock);
1302 list_for_each_prev(i, &ip_conntrack_expect_list) {
1303 exp = (struct ip_conntrack_expect *) i;
1306 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid,
1314 read_unlock_bh(&ip_conntrack_lock);
1316 DEBUGP("leaving, last id=%llu\n", *id);
1321 static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1322 [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
1323 [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
1327 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1328 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1330 struct ip_conntrack_tuple tuple;
1331 struct ip_conntrack_expect *exp;
1332 struct sk_buff *skb2;
1335 DEBUGP("entered %s\n", __FUNCTION__);
1337 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1340 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1341 struct nfgenmsg *msg = NLMSG_DATA(nlh);
1344 if (msg->nfgen_family != AF_INET)
1345 return -EAFNOSUPPORT;
1347 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1348 ctnetlink_exp_dump_table,
1349 ctnetlink_done)) != 0)
1351 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1352 if (rlen > skb->len)
1354 skb_pull(skb, rlen);
1358 if (cda[CTA_EXPECT_MASTER-1])
1359 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER);
1366 exp = ip_conntrack_expect_find(&tuple);
1370 if (cda[CTA_EXPECT_ID-1]) {
1371 u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1372 if (exp->id != ntohl(id)) {
1373 ip_conntrack_expect_put(exp);
1379 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1382 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
1384 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1385 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1390 ip_conntrack_expect_put(exp);
1392 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1397 ip_conntrack_expect_put(exp);
1402 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1403 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1405 struct ip_conntrack_expect *exp, *tmp;
1406 struct ip_conntrack_tuple tuple;
1407 struct ip_conntrack_helper *h;
1410 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1413 if (cda[CTA_EXPECT_TUPLE-1]) {
1414 /* delete a single expect by tuple */
1415 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1419 /* bump usage count to 2 */
1420 exp = ip_conntrack_expect_find(&tuple);
1424 if (cda[CTA_EXPECT_ID-1]) {
1426 *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1427 if (exp->id != ntohl(id)) {
1428 ip_conntrack_expect_put(exp);
1433 /* after list removal, usage count == 1 */
1434 ip_conntrack_unexpect_related(exp);
1435 /* have to put what we 'get' above.
1436 * after this line usage count == 0 */
1437 ip_conntrack_expect_put(exp);
1438 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
1439 char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
1441 /* delete all expectations for this helper */
1442 write_lock_bh(&ip_conntrack_lock);
1443 h = __ip_conntrack_helper_find_byname(name);
1445 write_unlock_bh(&ip_conntrack_lock);
1448 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list,
1450 if (exp->master->helper == h
1451 && del_timer(&exp->timeout)) {
1452 ip_ct_unlink_expect(exp);
1453 ip_conntrack_expect_put(exp);
1456 write_unlock_bh(&ip_conntrack_lock);
1458 /* This basically means we have to flush everything*/
1459 write_lock_bh(&ip_conntrack_lock);
1460 list_for_each_entry_safe(exp, tmp, &ip_conntrack_expect_list,
1462 if (del_timer(&exp->timeout)) {
1463 ip_ct_unlink_expect(exp);
1464 ip_conntrack_expect_put(exp);
1467 write_unlock_bh(&ip_conntrack_lock);
1473 ctnetlink_change_expect(struct ip_conntrack_expect *x, struct nfattr *cda[])
1479 ctnetlink_create_expect(struct nfattr *cda[])
1481 struct ip_conntrack_tuple tuple, mask, master_tuple;
1482 struct ip_conntrack_tuple_hash *h = NULL;
1483 struct ip_conntrack_expect *exp;
1484 struct ip_conntrack *ct;
1487 DEBUGP("entered %s\n", __FUNCTION__);
1489 /* caller guarantees that those three CTA_EXPECT_* exist */
1490 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1493 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK);
1496 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER);
1500 /* Look for master conntrack of this expectation */
1501 h = ip_conntrack_find_get(&master_tuple, NULL);
1504 ct = tuplehash_to_ctrack(h);
1507 /* such conntrack hasn't got any helper, abort */
1512 exp = ip_conntrack_expect_alloc(ct);
1518 exp->expectfn = NULL;
1521 memcpy(&exp->tuple, &tuple, sizeof(struct ip_conntrack_tuple));
1522 memcpy(&exp->mask, &mask, sizeof(struct ip_conntrack_tuple));
1524 err = ip_conntrack_expect_related(exp);
1525 ip_conntrack_expect_put(exp);
1528 ip_conntrack_put(tuplehash_to_ctrack(h));
1533 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1534 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1536 struct ip_conntrack_tuple tuple;
1537 struct ip_conntrack_expect *exp;
1540 DEBUGP("entered %s\n", __FUNCTION__);
1542 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1545 if (!cda[CTA_EXPECT_TUPLE-1]
1546 || !cda[CTA_EXPECT_MASK-1]
1547 || !cda[CTA_EXPECT_MASTER-1])
1550 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE);
1554 write_lock_bh(&ip_conntrack_lock);
1555 exp = __ip_conntrack_expect_find(&tuple);
1558 write_unlock_bh(&ip_conntrack_lock);
1560 if (nlh->nlmsg_flags & NLM_F_CREATE)
1561 err = ctnetlink_create_expect(cda);
1566 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1567 err = ctnetlink_change_expect(exp, cda);
1568 write_unlock_bh(&ip_conntrack_lock);
1570 DEBUGP("leaving\n");
1575 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1576 static struct notifier_block ctnl_notifier = {
1577 .notifier_call = ctnetlink_conntrack_event,
1580 static struct notifier_block ctnl_notifier_exp = {
1581 .notifier_call = ctnetlink_expect_event,
1585 static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
1586 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
1587 .attr_count = CTA_MAX, },
1588 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
1589 .attr_count = CTA_MAX, },
1590 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
1591 .attr_count = CTA_MAX, },
1592 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
1593 .attr_count = CTA_MAX, },
1596 static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
1597 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
1598 .attr_count = CTA_EXPECT_MAX, },
1599 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
1600 .attr_count = CTA_EXPECT_MAX, },
1601 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
1602 .attr_count = CTA_EXPECT_MAX, },
1605 static struct nfnetlink_subsystem ctnl_subsys = {
1606 .name = "conntrack",
1607 .subsys_id = NFNL_SUBSYS_CTNETLINK,
1608 .cb_count = IPCTNL_MSG_MAX,
1612 static struct nfnetlink_subsystem ctnl_exp_subsys = {
1613 .name = "conntrack_expect",
1614 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
1615 .cb_count = IPCTNL_MSG_EXP_MAX,
1619 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
1620 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_EXP);
1622 static int __init ctnetlink_init(void)
1626 printk("ctnetlink v%s: registering with nfnetlink.\n", version);
1627 ret = nfnetlink_subsys_register(&ctnl_subsys);
1629 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1633 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
1635 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1636 goto err_unreg_subsys;
1639 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1640 ret = ip_conntrack_register_notifier(&ctnl_notifier);
1642 printk("ctnetlink_init: cannot register notifier.\n");
1643 goto err_unreg_exp_subsys;
1646 ret = ip_conntrack_expect_register_notifier(&ctnl_notifier_exp);
1648 printk("ctnetlink_init: cannot expect register notifier.\n");
1649 goto err_unreg_notifier;
1655 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1657 ip_conntrack_unregister_notifier(&ctnl_notifier);
1658 err_unreg_exp_subsys:
1659 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1662 nfnetlink_subsys_unregister(&ctnl_subsys);
1667 static void __exit ctnetlink_exit(void)
1669 printk("ctnetlink: unregistering from nfnetlink.\n");
1671 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1672 ip_conntrack_expect_unregister_notifier(&ctnl_notifier_exp);
1673 ip_conntrack_unregister_notifier(&ctnl_notifier);
1676 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1677 nfnetlink_subsys_unregister(&ctnl_subsys);
1681 module_init(ctnetlink_init);
1682 module_exit(ctnetlink_exit);