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__);
403 #define L3PROTO(ct) ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num
406 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
408 struct nf_conn *ct = NULL;
409 struct nf_conntrack_tuple_hash *h;
411 u_int32_t *id = (u_int32_t *) &cb->args[1];
412 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
413 u_int8_t l3proto = nfmsg->nfgen_family;
415 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__,
418 read_lock_bh(&nf_conntrack_lock);
419 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
420 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
421 h = (struct nf_conntrack_tuple_hash *) i;
422 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
424 ct = nf_ct_tuplehash_to_ctrack(h);
425 /* Dump entries of a given L3 protocol number.
426 * If it is not specified, ie. l3proto == 0,
427 * then dump everything. */
428 if (l3proto && L3PROTO(ct) != l3proto)
432 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
441 read_unlock_bh(&nf_conntrack_lock);
443 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
448 #ifdef CONFIG_NF_CT_ACCT
450 ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
452 struct nf_conn *ct = NULL;
453 struct nf_conntrack_tuple_hash *h;
455 u_int32_t *id = (u_int32_t *) &cb->args[1];
456 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
457 u_int8_t l3proto = nfmsg->nfgen_family;
459 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__,
462 write_lock_bh(&nf_conntrack_lock);
463 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
464 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
465 h = (struct nf_conntrack_tuple_hash *) i;
466 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
468 ct = nf_ct_tuplehash_to_ctrack(h);
469 if (l3proto && L3PROTO(ct) != l3proto)
473 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
480 memset(&ct->counters, 0, sizeof(ct->counters));
484 write_unlock_bh(&nf_conntrack_lock);
486 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
493 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
495 struct nfattr *tb[CTA_IP_MAX];
496 struct nf_conntrack_l3proto *l3proto;
499 DEBUGP("entered %s\n", __FUNCTION__);
501 nfattr_parse_nested(tb, CTA_IP_MAX, attr);
503 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
505 if (likely(l3proto->nfattr_to_tuple))
506 ret = l3proto->nfattr_to_tuple(tb, tuple);
508 nf_ct_l3proto_put(l3proto);
515 static const size_t cta_min_proto[CTA_PROTO_MAX] = {
516 [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
520 ctnetlink_parse_tuple_proto(struct nfattr *attr,
521 struct nf_conntrack_tuple *tuple)
523 struct nfattr *tb[CTA_PROTO_MAX];
524 struct nf_conntrack_protocol *proto;
527 DEBUGP("entered %s\n", __FUNCTION__);
529 nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
531 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
534 if (!tb[CTA_PROTO_NUM-1])
536 tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
538 proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
540 if (likely(proto->nfattr_to_tuple))
541 ret = proto->nfattr_to_tuple(tb, tuple);
543 nf_ct_proto_put(proto);
549 ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
550 enum ctattr_tuple type, u_int8_t l3num)
552 struct nfattr *tb[CTA_TUPLE_MAX];
555 DEBUGP("entered %s\n", __FUNCTION__);
557 memset(tuple, 0, sizeof(*tuple));
559 nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
561 if (!tb[CTA_TUPLE_IP-1])
564 tuple->src.l3num = l3num;
566 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
570 if (!tb[CTA_TUPLE_PROTO-1])
573 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
577 /* orig and expect tuples get DIR_ORIGINAL */
578 if (type == CTA_TUPLE_REPLY)
579 tuple->dst.dir = IP_CT_DIR_REPLY;
581 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
583 NF_CT_DUMP_TUPLE(tuple);
590 #ifdef CONFIG_IP_NF_NAT_NEEDED
591 static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
592 [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
593 [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
596 static int ctnetlink_parse_nat_proto(struct nfattr *attr,
597 const struct nf_conn *ct,
598 struct ip_nat_range *range)
600 struct nfattr *tb[CTA_PROTONAT_MAX];
601 struct ip_nat_protocol *npt;
603 DEBUGP("entered %s\n", __FUNCTION__);
605 nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
607 if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
610 npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
612 if (!npt->nfattr_to_range) {
613 ip_nat_proto_put(npt);
617 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
618 if (npt->nfattr_to_range(tb, range) > 0)
619 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
621 ip_nat_proto_put(npt);
627 static const size_t cta_min_nat[CTA_NAT_MAX] = {
628 [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
629 [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
633 ctnetlink_parse_nat(struct nfattr *cda[],
634 const struct nf_conn *ct, struct ip_nat_range *range)
636 struct nfattr *tb[CTA_NAT_MAX];
639 DEBUGP("entered %s\n", __FUNCTION__);
641 memset(range, 0, sizeof(*range));
643 nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]);
645 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
648 if (tb[CTA_NAT_MINIP-1])
649 range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
651 if (!tb[CTA_NAT_MAXIP-1])
652 range->max_ip = range->min_ip;
654 range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
657 range->flags |= IP_NAT_RANGE_MAP_IPS;
659 if (!tb[CTA_NAT_PROTO-1])
662 err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
672 ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
674 struct nfattr *tb[CTA_HELP_MAX];
676 DEBUGP("entered %s\n", __FUNCTION__);
678 nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
680 if (!tb[CTA_HELP_NAME-1])
683 *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
688 static const size_t cta_min[CTA_MAX] = {
689 [CTA_STATUS-1] = sizeof(u_int32_t),
690 [CTA_TIMEOUT-1] = sizeof(u_int32_t),
691 [CTA_MARK-1] = sizeof(u_int32_t),
692 [CTA_USE-1] = sizeof(u_int32_t),
693 [CTA_ID-1] = sizeof(u_int32_t)
697 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
698 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
700 struct nf_conntrack_tuple_hash *h;
701 struct nf_conntrack_tuple tuple;
703 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
704 u_int8_t u3 = nfmsg->nfgen_family;
707 DEBUGP("entered %s\n", __FUNCTION__);
709 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
712 if (cda[CTA_TUPLE_ORIG-1])
713 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
714 else if (cda[CTA_TUPLE_REPLY-1])
715 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
717 /* Flush the whole table */
718 nf_conntrack_flush();
725 h = nf_conntrack_find_get(&tuple, NULL);
727 DEBUGP("tuple not found in conntrack hash\n");
731 ct = nf_ct_tuplehash_to_ctrack(h);
734 u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1]));
740 if (del_timer(&ct->timeout))
741 ct->timeout.function((unsigned long)ct);
750 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
751 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
753 struct nf_conntrack_tuple_hash *h;
754 struct nf_conntrack_tuple tuple;
756 struct sk_buff *skb2 = NULL;
757 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
758 u_int8_t u3 = nfmsg->nfgen_family;
761 DEBUGP("entered %s\n", __FUNCTION__);
763 if (nlh->nlmsg_flags & NLM_F_DUMP) {
766 if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
767 IPCTNL_MSG_CT_GET_CTRZERO) {
768 #ifdef CONFIG_NF_CT_ACCT
769 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
770 ctnetlink_dump_table_w,
771 ctnetlink_done)) != 0)
777 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
778 ctnetlink_dump_table,
779 ctnetlink_done)) != 0)
783 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
790 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
793 if (cda[CTA_TUPLE_ORIG-1])
794 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
795 else if (cda[CTA_TUPLE_REPLY-1])
796 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
803 h = nf_conntrack_find_get(&tuple, NULL);
805 DEBUGP("tuple not found in conntrack hash");
808 DEBUGP("tuple found\n");
809 ct = nf_ct_tuplehash_to_ctrack(h);
812 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
817 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
819 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
820 IPCTNL_MSG_CT_NEW, 1, ct);
825 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
839 ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
842 unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1]));
843 d = ct->status ^ status;
845 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
849 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
850 /* SEEN_REPLY bit can only be set */
854 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
855 /* ASSURED bit can only be set */
858 if (cda[CTA_NAT-1]) {
859 #ifndef CONFIG_IP_NF_NAT_NEEDED
862 unsigned int hooknum;
863 struct ip_nat_range range;
865 if (ctnetlink_parse_nat(cda, ct, &range) < 0)
868 DEBUGP("NAT: %u.%u.%u.%u-%u.%u.%u.%u:%u-%u\n",
869 NIPQUAD(range.min_ip), NIPQUAD(range.max_ip),
870 htons(range.min.all), htons(range.max.all));
872 /* This is tricky but it works. ip_nat_setup_info needs the
873 * hook number as parameter, so let's do the correct
874 * conversion and run away */
875 if (status & IPS_SRC_NAT_DONE)
876 hooknum = NF_IP_POST_ROUTING; /* IP_NAT_MANIP_SRC */
877 else if (status & IPS_DST_NAT_DONE)
878 hooknum = NF_IP_PRE_ROUTING; /* IP_NAT_MANIP_DST */
880 return -EINVAL; /* Missing NAT flags */
882 DEBUGP("NAT status: %lu\n",
883 status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
885 if (ip_nat_initialized(ct, HOOK2MANIP(hooknum)))
887 ip_nat_setup_info(ct, &range, hooknum);
889 DEBUGP("NAT status after setup_info: %lu\n",
890 ct->status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
894 /* Be careful here, modifying NAT bits can screw up things,
895 * so don't let users modify them directly if they don't pass
897 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
903 ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
905 struct nf_conntrack_helper *helper;
909 DEBUGP("entered %s\n", __FUNCTION__);
911 /* don't change helper of sibling connections */
915 err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
919 helper = __nf_conntrack_helper_find_byname(helpname);
921 if (!strcmp(helpname, ""))
929 /* we had a helper before ... */
930 nf_ct_remove_expectations(ct);
933 /* need to zero data of old helper */
934 memset(&ct->help, 0, sizeof(ct->help));
944 ctnetlink_change_timeout(struct nf_conn *ct, struct nfattr *cda[])
946 u_int32_t timeout = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
948 if (!del_timer(&ct->timeout))
951 ct->timeout.expires = jiffies + timeout * HZ;
952 add_timer(&ct->timeout);
958 ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[])
960 struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
961 struct nf_conntrack_protocol *proto;
962 u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
963 u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
966 nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
968 proto = nf_ct_proto_find_get(l3num, npt);
970 if (proto->from_nfattr)
971 err = proto->from_nfattr(tb, ct);
972 nf_ct_proto_put(proto);
978 ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
982 DEBUGP("entered %s\n", __FUNCTION__);
984 if (cda[CTA_HELP-1]) {
985 err = ctnetlink_change_helper(ct, cda);
990 if (cda[CTA_TIMEOUT-1]) {
991 err = ctnetlink_change_timeout(ct, cda);
996 if (cda[CTA_STATUS-1]) {
997 err = ctnetlink_change_status(ct, cda);
1002 if (cda[CTA_PROTOINFO-1]) {
1003 err = ctnetlink_change_protoinfo(ct, cda);
1008 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1009 if (cda[CTA_MARK-1])
1010 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1013 DEBUGP("all done\n");
1018 ctnetlink_create_conntrack(struct nfattr *cda[],
1019 struct nf_conntrack_tuple *otuple,
1020 struct nf_conntrack_tuple *rtuple)
1025 DEBUGP("entered %s\n", __FUNCTION__);
1027 ct = nf_conntrack_alloc(otuple, rtuple);
1028 if (ct == NULL || IS_ERR(ct))
1031 if (!cda[CTA_TIMEOUT-1])
1033 ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
1035 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1036 ct->status |= IPS_CONFIRMED;
1038 err = ctnetlink_change_status(ct, cda);
1042 if (cda[CTA_PROTOINFO-1]) {
1043 err = ctnetlink_change_protoinfo(ct, cda);
1048 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1049 if (cda[CTA_MARK-1])
1050 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1053 ct->helper = nf_ct_helper_find_get(rtuple);
1055 add_timer(&ct->timeout);
1056 nf_conntrack_hash_insert(ct);
1059 nf_ct_helper_put(ct->helper);
1061 DEBUGP("conntrack with id %u inserted\n", ct->id);
1065 nf_conntrack_free(ct);
1070 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1071 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1073 struct nf_conntrack_tuple otuple, rtuple;
1074 struct nf_conntrack_tuple_hash *h = NULL;
1075 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1076 u_int8_t u3 = nfmsg->nfgen_family;
1079 DEBUGP("entered %s\n", __FUNCTION__);
1081 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
1084 if (cda[CTA_TUPLE_ORIG-1]) {
1085 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
1090 if (cda[CTA_TUPLE_REPLY-1]) {
1091 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
1096 write_lock_bh(&nf_conntrack_lock);
1097 if (cda[CTA_TUPLE_ORIG-1])
1098 h = __nf_conntrack_find(&otuple, NULL);
1099 else if (cda[CTA_TUPLE_REPLY-1])
1100 h = __nf_conntrack_find(&rtuple, NULL);
1103 write_unlock_bh(&nf_conntrack_lock);
1104 DEBUGP("no such conntrack, create new\n");
1106 if (nlh->nlmsg_flags & NLM_F_CREATE)
1107 err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
1110 /* implicit 'else' */
1112 /* we only allow nat config for new conntracks */
1113 if (cda[CTA_NAT-1]) {
1118 /* We manipulate the conntrack inside the global conntrack table lock,
1119 * so there's no need to increase the refcount */
1120 DEBUGP("conntrack found\n");
1122 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1123 err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), cda);
1126 write_unlock_bh(&nf_conntrack_lock);
1130 /***********************************************************************
1132 ***********************************************************************/
1135 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1136 const struct nf_conntrack_tuple *tuple,
1137 enum ctattr_expect type)
1139 struct nfattr *nest_parms = NFA_NEST(skb, type);
1141 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1142 goto nfattr_failure;
1144 NFA_NEST_END(skb, nest_parms);
1153 ctnetlink_exp_dump_expect(struct sk_buff *skb,
1154 const struct nf_conntrack_expect *exp)
1156 struct nf_conn *master = exp->master;
1157 u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ);
1158 u_int32_t id = htonl(exp->id);
1160 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
1161 goto nfattr_failure;
1162 if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
1163 goto nfattr_failure;
1164 if (ctnetlink_exp_dump_tuple(skb,
1165 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1166 CTA_EXPECT_MASTER) < 0)
1167 goto nfattr_failure;
1169 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
1170 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
1179 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1182 const struct nf_conntrack_expect *exp)
1184 struct nlmsghdr *nlh;
1185 struct nfgenmsg *nfmsg;
1190 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1191 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
1192 nfmsg = NLMSG_DATA(nlh);
1194 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1195 nfmsg->nfgen_family = exp->tuple.src.l3num;
1196 nfmsg->version = NFNETLINK_V0;
1199 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1200 goto nfattr_failure;
1202 nlh->nlmsg_len = skb->tail - b;
1207 skb_trim(skb, b - skb->data);
1211 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1212 static int ctnetlink_expect_event(struct notifier_block *this,
1213 unsigned long events, void *ptr)
1215 struct nlmsghdr *nlh;
1216 struct nfgenmsg *nfmsg;
1217 struct nf_conntrack_expect *exp = (struct nf_conntrack_expect *)ptr;
1218 struct sk_buff *skb;
1223 if (events & IPEXP_NEW) {
1224 type = IPCTNL_MSG_EXP_NEW;
1225 flags = NLM_F_CREATE|NLM_F_EXCL;
1229 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
1235 type |= NFNL_SUBSYS_CTNETLINK << 8;
1236 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
1237 nfmsg = NLMSG_DATA(nlh);
1239 nlh->nlmsg_flags = flags;
1240 nfmsg->nfgen_family = exp->tuple.src.l3num;
1241 nfmsg->version = NFNETLINK_V0;
1244 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1245 goto nfattr_failure;
1247 nlh->nlmsg_len = skb->tail - b;
1248 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
1259 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1261 struct nf_conntrack_expect *exp = NULL;
1262 struct list_head *i;
1263 u_int32_t *id = (u_int32_t *) &cb->args[0];
1264 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
1265 u_int8_t l3proto = nfmsg->nfgen_family;
1267 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
1269 read_lock_bh(&nf_conntrack_lock);
1270 list_for_each_prev(i, &nf_conntrack_expect_list) {
1271 exp = (struct nf_conntrack_expect *) i;
1272 if (l3proto && exp->tuple.src.l3num != l3proto)
1276 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid,
1284 read_unlock_bh(&nf_conntrack_lock);
1286 DEBUGP("leaving, last id=%llu\n", *id);
1291 static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1292 [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
1293 [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
1297 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1298 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1300 struct nf_conntrack_tuple tuple;
1301 struct nf_conntrack_expect *exp;
1302 struct sk_buff *skb2;
1303 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1304 u_int8_t u3 = nfmsg->nfgen_family;
1307 DEBUGP("entered %s\n", __FUNCTION__);
1309 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1312 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1315 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1316 ctnetlink_exp_dump_table,
1317 ctnetlink_done)) != 0)
1319 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1320 if (rlen > skb->len)
1322 skb_pull(skb, rlen);
1326 if (cda[CTA_EXPECT_MASTER-1])
1327 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
1334 exp = nf_conntrack_expect_find(&tuple);
1338 if (cda[CTA_EXPECT_ID-1]) {
1339 u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1340 if (exp->id != ntohl(id)) {
1341 nf_conntrack_expect_put(exp);
1347 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1350 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
1352 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1353 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1358 nf_conntrack_expect_put(exp);
1360 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1365 nf_conntrack_expect_put(exp);
1370 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1371 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1373 struct nf_conntrack_expect *exp, *tmp;
1374 struct nf_conntrack_tuple tuple;
1375 struct nf_conntrack_helper *h;
1376 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1377 u_int8_t u3 = nfmsg->nfgen_family;
1380 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1383 if (cda[CTA_EXPECT_TUPLE-1]) {
1384 /* delete a single expect by tuple */
1385 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1389 /* bump usage count to 2 */
1390 exp = nf_conntrack_expect_find(&tuple);
1394 if (cda[CTA_EXPECT_ID-1]) {
1396 *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1397 if (exp->id != ntohl(id)) {
1398 nf_conntrack_expect_put(exp);
1403 /* after list removal, usage count == 1 */
1404 nf_conntrack_unexpect_related(exp);
1405 /* have to put what we 'get' above.
1406 * after this line usage count == 0 */
1407 nf_conntrack_expect_put(exp);
1408 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
1409 char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
1411 /* delete all expectations for this helper */
1412 write_lock_bh(&nf_conntrack_lock);
1413 h = __nf_conntrack_helper_find_byname(name);
1415 write_unlock_bh(&nf_conntrack_lock);
1418 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1420 if (exp->master->helper == h
1421 && del_timer(&exp->timeout)) {
1422 nf_ct_unlink_expect(exp);
1423 nf_conntrack_expect_put(exp);
1426 write_unlock_bh(&nf_conntrack_lock);
1428 /* This basically means we have to flush everything*/
1429 write_lock_bh(&nf_conntrack_lock);
1430 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1432 if (del_timer(&exp->timeout)) {
1433 nf_ct_unlink_expect(exp);
1434 nf_conntrack_expect_put(exp);
1437 write_unlock_bh(&nf_conntrack_lock);
1443 ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nfattr *cda[])
1449 ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
1451 struct nf_conntrack_tuple tuple, mask, master_tuple;
1452 struct nf_conntrack_tuple_hash *h = NULL;
1453 struct nf_conntrack_expect *exp;
1457 DEBUGP("entered %s\n", __FUNCTION__);
1459 /* caller guarantees that those three CTA_EXPECT_* exist */
1460 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1463 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK, u3);
1466 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER, u3);
1470 /* Look for master conntrack of this expectation */
1471 h = nf_conntrack_find_get(&master_tuple, NULL);
1474 ct = nf_ct_tuplehash_to_ctrack(h);
1477 /* such conntrack hasn't got any helper, abort */
1482 exp = nf_conntrack_expect_alloc(ct);
1488 exp->expectfn = NULL;
1491 memcpy(&exp->tuple, &tuple, sizeof(struct nf_conntrack_tuple));
1492 memcpy(&exp->mask, &mask, sizeof(struct nf_conntrack_tuple));
1494 err = nf_conntrack_expect_related(exp);
1495 nf_conntrack_expect_put(exp);
1498 nf_ct_put(nf_ct_tuplehash_to_ctrack(h));
1503 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1504 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1506 struct nf_conntrack_tuple tuple;
1507 struct nf_conntrack_expect *exp;
1508 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1509 u_int8_t u3 = nfmsg->nfgen_family;
1512 DEBUGP("entered %s\n", __FUNCTION__);
1514 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1517 if (!cda[CTA_EXPECT_TUPLE-1]
1518 || !cda[CTA_EXPECT_MASK-1]
1519 || !cda[CTA_EXPECT_MASTER-1])
1522 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1526 write_lock_bh(&nf_conntrack_lock);
1527 exp = __nf_conntrack_expect_find(&tuple);
1530 write_unlock_bh(&nf_conntrack_lock);
1532 if (nlh->nlmsg_flags & NLM_F_CREATE)
1533 err = ctnetlink_create_expect(cda, u3);
1538 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1539 err = ctnetlink_change_expect(exp, cda);
1540 write_unlock_bh(&nf_conntrack_lock);
1542 DEBUGP("leaving\n");
1547 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1548 static struct notifier_block ctnl_notifier = {
1549 .notifier_call = ctnetlink_conntrack_event,
1552 static struct notifier_block ctnl_notifier_exp = {
1553 .notifier_call = ctnetlink_expect_event,
1557 static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
1558 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
1559 .attr_count = CTA_MAX, },
1560 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
1561 .attr_count = CTA_MAX, },
1562 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
1563 .attr_count = CTA_MAX, },
1564 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
1565 .attr_count = CTA_MAX, },
1568 static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
1569 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
1570 .attr_count = CTA_EXPECT_MAX, },
1571 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
1572 .attr_count = CTA_EXPECT_MAX, },
1573 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
1574 .attr_count = CTA_EXPECT_MAX, },
1577 static struct nfnetlink_subsystem ctnl_subsys = {
1578 .name = "conntrack",
1579 .subsys_id = NFNL_SUBSYS_CTNETLINK,
1580 .cb_count = IPCTNL_MSG_MAX,
1584 static struct nfnetlink_subsystem ctnl_exp_subsys = {
1585 .name = "conntrack_expect",
1586 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
1587 .cb_count = IPCTNL_MSG_EXP_MAX,
1591 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
1593 static int __init ctnetlink_init(void)
1597 printk("ctnetlink v%s: registering with nfnetlink.\n", version);
1598 ret = nfnetlink_subsys_register(&ctnl_subsys);
1600 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1604 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
1606 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1607 goto err_unreg_subsys;
1610 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1611 ret = nf_conntrack_register_notifier(&ctnl_notifier);
1613 printk("ctnetlink_init: cannot register notifier.\n");
1614 goto err_unreg_exp_subsys;
1617 ret = nf_conntrack_expect_register_notifier(&ctnl_notifier_exp);
1619 printk("ctnetlink_init: cannot expect register notifier.\n");
1620 goto err_unreg_notifier;
1626 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1628 nf_conntrack_unregister_notifier(&ctnl_notifier);
1629 err_unreg_exp_subsys:
1630 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1633 nfnetlink_subsys_unregister(&ctnl_subsys);
1638 static void __exit ctnetlink_exit(void)
1640 printk("ctnetlink: unregistering from nfnetlink.\n");
1642 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1643 nf_conntrack_unregister_notifier(&ctnl_notifier_exp);
1644 nf_conntrack_unregister_notifier(&ctnl_notifier);
1647 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1648 nfnetlink_subsys_unregister(&ctnl_subsys);
1652 module_init(ctnetlink_init);
1653 module_exit(ctnetlink_exit);