1 /* Connection tracking via netlink socket. Allows for user space
2 * protocol helpers and general trouble making from userspace.
4 * (C) 2001 by Jay Schulist <jschlst@samba.org>
5 * (C) 2002-2006 by Harald Welte <laforge@gnumonks.org>
6 * (C) 2003 by Patrick Mchardy <kaber@trash.net>
7 * (C) 2005 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.93";
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;
168 const struct nf_conn_help *help = nfct_help(ct);
170 if (!help || !help->helper)
173 nest_helper = NFA_NEST(skb, CTA_HELP);
174 NFA_PUT(skb, CTA_HELP_NAME, strlen(help->helper->name), help->helper->name);
176 if (help->helper->to_nfattr)
177 help->helper->to_nfattr(skb, ct);
179 NFA_NEST_END(skb, nest_helper);
187 #ifdef CONFIG_NF_CT_ACCT
189 ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct,
190 enum ip_conntrack_dir dir)
192 enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
193 struct nfattr *nest_count = NFA_NEST(skb, type);
196 tmp = htonl(ct->counters[dir].packets);
197 NFA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp);
199 tmp = htonl(ct->counters[dir].bytes);
200 NFA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp);
202 NFA_NEST_END(skb, nest_count);
210 #define ctnetlink_dump_counters(a, b, c) (0)
213 #ifdef CONFIG_NF_CONNTRACK_MARK
215 ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct)
217 u_int32_t mark = htonl(ct->mark);
219 NFA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark);
226 #define ctnetlink_dump_mark(a, b) (0)
230 ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
232 u_int32_t id = htonl(ct->id);
233 NFA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id);
241 ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct)
243 u_int32_t use = htonl(atomic_read(&ct->ct_general.use));
245 NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use);
252 #define tuple(ct, dir) (&(ct)->tuplehash[dir].tuple)
255 ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
256 int event, int nowait,
257 const struct nf_conn *ct)
259 struct nlmsghdr *nlh;
260 struct nfgenmsg *nfmsg;
261 struct nfattr *nest_parms;
266 event |= NFNL_SUBSYS_CTNETLINK << 8;
267 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
268 nfmsg = NLMSG_DATA(nlh);
270 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
271 nfmsg->nfgen_family =
272 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
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_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 nf_conn *ct = (struct nf_conn *)ptr;
317 unsigned int flags = 0, group;
319 /* ignore our fake conntrack entry */
320 if (ct == &nf_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 /* FIXME: Check if there are any listeners before, don't hurt performance */
344 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
350 type |= NFNL_SUBSYS_CTNETLINK << 8;
351 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
352 nfmsg = NLMSG_DATA(nlh);
354 nlh->nlmsg_flags = flags;
355 nfmsg->nfgen_family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
356 nfmsg->version = NFNETLINK_V0;
359 nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG);
360 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
362 NFA_NEST_END(skb, nest_parms);
364 nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY);
365 if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0)
367 NFA_NEST_END(skb, nest_parms);
369 /* NAT stuff is now a status flag */
370 if ((events & IPCT_STATUS || events & IPCT_NATINFO)
371 && ctnetlink_dump_status(skb, ct) < 0)
373 if (events & IPCT_REFRESH
374 && ctnetlink_dump_timeout(skb, ct) < 0)
376 if (events & IPCT_PROTOINFO
377 && ctnetlink_dump_protoinfo(skb, ct) < 0)
379 if (events & IPCT_HELPINFO
380 && ctnetlink_dump_helpinfo(skb, ct) < 0)
383 if (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 ||
384 ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0)
387 nlh->nlmsg_len = skb->tail - b;
388 nfnetlink_send(skb, 0, group, 0);
396 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
398 static int ctnetlink_done(struct netlink_callback *cb)
400 DEBUGP("entered %s\n", __FUNCTION__);
404 #define L3PROTO(ct) ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num
407 ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
409 struct nf_conn *ct = NULL;
410 struct nf_conntrack_tuple_hash *h;
412 u_int32_t *id = (u_int32_t *) &cb->args[1];
413 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
414 u_int8_t l3proto = nfmsg->nfgen_family;
416 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__,
419 read_lock_bh(&nf_conntrack_lock);
420 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
421 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
422 h = (struct nf_conntrack_tuple_hash *) i;
423 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
425 ct = nf_ct_tuplehash_to_ctrack(h);
426 /* Dump entries of a given L3 protocol number.
427 * If it is not specified, ie. l3proto == 0,
428 * then dump everything. */
429 if (l3proto && L3PROTO(ct) != l3proto)
433 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
442 read_unlock_bh(&nf_conntrack_lock);
444 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
449 #ifdef CONFIG_NF_CT_ACCT
451 ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
453 struct nf_conn *ct = NULL;
454 struct nf_conntrack_tuple_hash *h;
456 u_int32_t *id = (u_int32_t *) &cb->args[1];
457 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
458 u_int8_t l3proto = nfmsg->nfgen_family;
460 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__,
463 write_lock_bh(&nf_conntrack_lock);
464 for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
465 list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
466 h = (struct nf_conntrack_tuple_hash *) i;
467 if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
469 ct = nf_ct_tuplehash_to_ctrack(h);
470 if (l3proto && L3PROTO(ct) != l3proto)
474 if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
481 memset(&ct->counters, 0, sizeof(ct->counters));
485 write_unlock_bh(&nf_conntrack_lock);
487 DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
494 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
496 struct nfattr *tb[CTA_IP_MAX];
497 struct nf_conntrack_l3proto *l3proto;
500 DEBUGP("entered %s\n", __FUNCTION__);
502 nfattr_parse_nested(tb, CTA_IP_MAX, attr);
504 l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
506 if (likely(l3proto->nfattr_to_tuple))
507 ret = l3proto->nfattr_to_tuple(tb, tuple);
509 nf_ct_l3proto_put(l3proto);
516 static const size_t cta_min_proto[CTA_PROTO_MAX] = {
517 [CTA_PROTO_NUM-1] = sizeof(u_int8_t),
521 ctnetlink_parse_tuple_proto(struct nfattr *attr,
522 struct nf_conntrack_tuple *tuple)
524 struct nfattr *tb[CTA_PROTO_MAX];
525 struct nf_conntrack_protocol *proto;
528 DEBUGP("entered %s\n", __FUNCTION__);
530 nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
532 if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
535 if (!tb[CTA_PROTO_NUM-1])
537 tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
539 proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
541 if (likely(proto->nfattr_to_tuple))
542 ret = proto->nfattr_to_tuple(tb, tuple);
544 nf_ct_proto_put(proto);
550 ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple,
551 enum ctattr_tuple type, u_int8_t l3num)
553 struct nfattr *tb[CTA_TUPLE_MAX];
556 DEBUGP("entered %s\n", __FUNCTION__);
558 memset(tuple, 0, sizeof(*tuple));
560 nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
562 if (!tb[CTA_TUPLE_IP-1])
565 tuple->src.l3num = l3num;
567 err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple);
571 if (!tb[CTA_TUPLE_PROTO-1])
574 err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple);
578 /* orig and expect tuples get DIR_ORIGINAL */
579 if (type == CTA_TUPLE_REPLY)
580 tuple->dst.dir = IP_CT_DIR_REPLY;
582 tuple->dst.dir = IP_CT_DIR_ORIGINAL;
584 NF_CT_DUMP_TUPLE(tuple);
591 #ifdef CONFIG_IP_NF_NAT_NEEDED
592 static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = {
593 [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t),
594 [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t),
597 static int ctnetlink_parse_nat_proto(struct nfattr *attr,
598 const struct nf_conn *ct,
599 struct ip_nat_range *range)
601 struct nfattr *tb[CTA_PROTONAT_MAX];
602 struct ip_nat_protocol *npt;
604 DEBUGP("entered %s\n", __FUNCTION__);
606 nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
608 if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
611 npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
613 if (!npt->nfattr_to_range) {
614 ip_nat_proto_put(npt);
618 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
619 if (npt->nfattr_to_range(tb, range) > 0)
620 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
622 ip_nat_proto_put(npt);
628 static const size_t cta_min_nat[CTA_NAT_MAX] = {
629 [CTA_NAT_MINIP-1] = sizeof(u_int32_t),
630 [CTA_NAT_MAXIP-1] = sizeof(u_int32_t),
634 ctnetlink_parse_nat(struct nfattr *cda[],
635 const struct nf_conn *ct, struct ip_nat_range *range)
637 struct nfattr *tb[CTA_NAT_MAX];
640 DEBUGP("entered %s\n", __FUNCTION__);
642 memset(range, 0, sizeof(*range));
644 nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]);
646 if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat))
649 if (tb[CTA_NAT_MINIP-1])
650 range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
652 if (!tb[CTA_NAT_MAXIP-1])
653 range->max_ip = range->min_ip;
655 range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]);
658 range->flags |= IP_NAT_RANGE_MAP_IPS;
660 if (!tb[CTA_NAT_PROTO-1])
663 err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range);
673 ctnetlink_parse_help(struct nfattr *attr, char **helper_name)
675 struct nfattr *tb[CTA_HELP_MAX];
677 DEBUGP("entered %s\n", __FUNCTION__);
679 nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
681 if (!tb[CTA_HELP_NAME-1])
684 *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
689 static const size_t cta_min[CTA_MAX] = {
690 [CTA_STATUS-1] = sizeof(u_int32_t),
691 [CTA_TIMEOUT-1] = sizeof(u_int32_t),
692 [CTA_MARK-1] = sizeof(u_int32_t),
693 [CTA_USE-1] = sizeof(u_int32_t),
694 [CTA_ID-1] = sizeof(u_int32_t)
698 ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
699 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
701 struct nf_conntrack_tuple_hash *h;
702 struct nf_conntrack_tuple tuple;
704 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
705 u_int8_t u3 = nfmsg->nfgen_family;
708 DEBUGP("entered %s\n", __FUNCTION__);
710 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
713 if (cda[CTA_TUPLE_ORIG-1])
714 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
715 else if (cda[CTA_TUPLE_REPLY-1])
716 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
718 /* Flush the whole table */
719 nf_conntrack_flush();
726 h = nf_conntrack_find_get(&tuple, NULL);
728 DEBUGP("tuple not found in conntrack hash\n");
732 ct = nf_ct_tuplehash_to_ctrack(h);
735 u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1]));
741 if (del_timer(&ct->timeout))
742 ct->timeout.function((unsigned long)ct);
751 ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
752 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
754 struct nf_conntrack_tuple_hash *h;
755 struct nf_conntrack_tuple tuple;
757 struct sk_buff *skb2 = NULL;
758 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
759 u_int8_t u3 = nfmsg->nfgen_family;
762 DEBUGP("entered %s\n", __FUNCTION__);
764 if (nlh->nlmsg_flags & NLM_F_DUMP) {
767 if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
768 IPCTNL_MSG_CT_GET_CTRZERO) {
769 #ifdef CONFIG_NF_CT_ACCT
770 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
771 ctnetlink_dump_table_w,
772 ctnetlink_done)) != 0)
778 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
779 ctnetlink_dump_table,
780 ctnetlink_done)) != 0)
784 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
791 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
794 if (cda[CTA_TUPLE_ORIG-1])
795 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3);
796 else if (cda[CTA_TUPLE_REPLY-1])
797 err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3);
804 h = nf_conntrack_find_get(&tuple, NULL);
806 DEBUGP("tuple not found in conntrack hash");
809 DEBUGP("tuple found\n");
810 ct = nf_ct_tuplehash_to_ctrack(h);
813 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
818 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
820 err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq,
821 IPCTNL_MSG_CT_NEW, 1, ct);
826 err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
840 ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[])
843 unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1]));
844 d = ct->status ^ status;
846 if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING))
850 if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY))
851 /* SEEN_REPLY bit can only be set */
855 if (d & IPS_ASSURED && !(status & IPS_ASSURED))
856 /* ASSURED bit can only be set */
859 if (cda[CTA_NAT-1]) {
860 #ifndef CONFIG_IP_NF_NAT_NEEDED
863 unsigned int hooknum;
864 struct ip_nat_range range;
866 if (ctnetlink_parse_nat(cda, ct, &range) < 0)
869 DEBUGP("NAT: %u.%u.%u.%u-%u.%u.%u.%u:%u-%u\n",
870 NIPQUAD(range.min_ip), NIPQUAD(range.max_ip),
871 htons(range.min.all), htons(range.max.all));
873 /* This is tricky but it works. ip_nat_setup_info needs the
874 * hook number as parameter, so let's do the correct
875 * conversion and run away */
876 if (status & IPS_SRC_NAT_DONE)
877 hooknum = NF_IP_POST_ROUTING; /* IP_NAT_MANIP_SRC */
878 else if (status & IPS_DST_NAT_DONE)
879 hooknum = NF_IP_PRE_ROUTING; /* IP_NAT_MANIP_DST */
881 return -EINVAL; /* Missing NAT flags */
883 DEBUGP("NAT status: %lu\n",
884 status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
886 if (ip_nat_initialized(ct, HOOK2MANIP(hooknum)))
888 ip_nat_setup_info(ct, &range, hooknum);
890 DEBUGP("NAT status after setup_info: %lu\n",
891 ct->status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK));
895 /* Be careful here, modifying NAT bits can screw up things,
896 * so don't let users modify them directly if they don't pass
898 ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK);
904 ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[])
906 struct nf_conntrack_helper *helper;
907 struct nf_conn_help *help = nfct_help(ct);
911 DEBUGP("entered %s\n", __FUNCTION__);
914 /* FIXME: we need to reallocate and rehash */
918 /* don't change helper of sibling connections */
922 err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname);
926 helper = __nf_conntrack_helper_find_byname(helpname);
928 if (!strcmp(helpname, ""))
936 /* we had a helper before ... */
937 nf_ct_remove_expectations(ct);
940 /* need to zero data of old helper */
941 memset(&help->help, 0, sizeof(help->help));
945 help->helper = helper;
951 ctnetlink_change_timeout(struct nf_conn *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 nf_conn *ct, struct nfattr *cda[])
967 struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1];
968 struct nf_conntrack_protocol *proto;
969 u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
970 u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
973 nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
975 proto = nf_ct_proto_find_get(l3num, npt);
977 if (proto->from_nfattr)
978 err = proto->from_nfattr(tb, ct);
979 nf_ct_proto_put(proto);
985 ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[])
989 DEBUGP("entered %s\n", __FUNCTION__);
991 if (cda[CTA_HELP-1]) {
992 err = ctnetlink_change_helper(ct, cda);
997 if (cda[CTA_TIMEOUT-1]) {
998 err = ctnetlink_change_timeout(ct, cda);
1003 if (cda[CTA_STATUS-1]) {
1004 err = ctnetlink_change_status(ct, cda);
1009 if (cda[CTA_PROTOINFO-1]) {
1010 err = ctnetlink_change_protoinfo(ct, cda);
1015 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1016 if (cda[CTA_MARK-1])
1017 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1020 DEBUGP("all done\n");
1025 ctnetlink_create_conntrack(struct nfattr *cda[],
1026 struct nf_conntrack_tuple *otuple,
1027 struct nf_conntrack_tuple *rtuple)
1032 DEBUGP("entered %s\n", __FUNCTION__);
1034 ct = nf_conntrack_alloc(otuple, rtuple);
1035 if (ct == NULL || IS_ERR(ct))
1038 if (!cda[CTA_TIMEOUT-1])
1040 ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1]));
1042 ct->timeout.expires = jiffies + ct->timeout.expires * HZ;
1043 ct->status |= IPS_CONFIRMED;
1045 err = ctnetlink_change_status(ct, cda);
1049 if (cda[CTA_PROTOINFO-1]) {
1050 err = ctnetlink_change_protoinfo(ct, cda);
1055 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1056 if (cda[CTA_MARK-1])
1057 ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
1060 add_timer(&ct->timeout);
1061 nf_conntrack_hash_insert(ct);
1063 DEBUGP("conntrack with id %u inserted\n", ct->id);
1067 nf_conntrack_free(ct);
1072 ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
1073 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1075 struct nf_conntrack_tuple otuple, rtuple;
1076 struct nf_conntrack_tuple_hash *h = NULL;
1077 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1078 u_int8_t u3 = nfmsg->nfgen_family;
1081 DEBUGP("entered %s\n", __FUNCTION__);
1083 if (nfattr_bad_size(cda, CTA_MAX, cta_min))
1086 if (cda[CTA_TUPLE_ORIG-1]) {
1087 err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3);
1092 if (cda[CTA_TUPLE_REPLY-1]) {
1093 err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3);
1098 write_lock_bh(&nf_conntrack_lock);
1099 if (cda[CTA_TUPLE_ORIG-1])
1100 h = __nf_conntrack_find(&otuple, NULL);
1101 else if (cda[CTA_TUPLE_REPLY-1])
1102 h = __nf_conntrack_find(&rtuple, NULL);
1105 write_unlock_bh(&nf_conntrack_lock);
1106 DEBUGP("no such conntrack, create new\n");
1108 if (nlh->nlmsg_flags & NLM_F_CREATE)
1109 err = ctnetlink_create_conntrack(cda, &otuple, &rtuple);
1112 /* implicit 'else' */
1114 /* we only allow nat config for new conntracks */
1115 if (cda[CTA_NAT-1]) {
1120 /* We manipulate the conntrack inside the global conntrack table lock,
1121 * so there's no need to increase the refcount */
1122 DEBUGP("conntrack found\n");
1124 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1125 err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), cda);
1128 write_unlock_bh(&nf_conntrack_lock);
1132 /***********************************************************************
1134 ***********************************************************************/
1137 ctnetlink_exp_dump_tuple(struct sk_buff *skb,
1138 const struct nf_conntrack_tuple *tuple,
1139 enum ctattr_expect type)
1141 struct nfattr *nest_parms = NFA_NEST(skb, type);
1143 if (ctnetlink_dump_tuples(skb, tuple) < 0)
1144 goto nfattr_failure;
1146 NFA_NEST_END(skb, nest_parms);
1155 ctnetlink_exp_dump_expect(struct sk_buff *skb,
1156 const struct nf_conntrack_expect *exp)
1158 struct nf_conn *master = exp->master;
1159 u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ);
1160 u_int32_t id = htonl(exp->id);
1162 if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
1163 goto nfattr_failure;
1164 if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
1165 goto nfattr_failure;
1166 if (ctnetlink_exp_dump_tuple(skb,
1167 &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
1168 CTA_EXPECT_MASTER) < 0)
1169 goto nfattr_failure;
1171 NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout);
1172 NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id);
1181 ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq,
1184 const struct nf_conntrack_expect *exp)
1186 struct nlmsghdr *nlh;
1187 struct nfgenmsg *nfmsg;
1192 event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1193 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg));
1194 nfmsg = NLMSG_DATA(nlh);
1196 nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0;
1197 nfmsg->nfgen_family = exp->tuple.src.l3num;
1198 nfmsg->version = NFNETLINK_V0;
1201 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1202 goto nfattr_failure;
1204 nlh->nlmsg_len = skb->tail - b;
1209 skb_trim(skb, b - skb->data);
1213 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1214 static int ctnetlink_expect_event(struct notifier_block *this,
1215 unsigned long events, void *ptr)
1217 struct nlmsghdr *nlh;
1218 struct nfgenmsg *nfmsg;
1219 struct nf_conntrack_expect *exp = (struct nf_conntrack_expect *)ptr;
1220 struct sk_buff *skb;
1225 if (events & IPEXP_NEW) {
1226 type = IPCTNL_MSG_EXP_NEW;
1227 flags = NLM_F_CREATE|NLM_F_EXCL;
1231 skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
1237 type |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
1238 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg));
1239 nfmsg = NLMSG_DATA(nlh);
1241 nlh->nlmsg_flags = flags;
1242 nfmsg->nfgen_family = exp->tuple.src.l3num;
1243 nfmsg->version = NFNETLINK_V0;
1246 if (ctnetlink_exp_dump_expect(skb, exp) < 0)
1247 goto nfattr_failure;
1249 nlh->nlmsg_len = skb->tail - b;
1250 nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0);
1261 ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
1263 struct nf_conntrack_expect *exp = NULL;
1264 struct list_head *i;
1265 u_int32_t *id = (u_int32_t *) &cb->args[0];
1266 struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
1267 u_int8_t l3proto = nfmsg->nfgen_family;
1269 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id);
1271 read_lock_bh(&nf_conntrack_lock);
1272 list_for_each_prev(i, &nf_conntrack_expect_list) {
1273 exp = (struct nf_conntrack_expect *) i;
1274 if (l3proto && exp->tuple.src.l3num != l3proto)
1278 if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid,
1286 read_unlock_bh(&nf_conntrack_lock);
1288 DEBUGP("leaving, last id=%llu\n", *id);
1293 static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
1294 [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t),
1295 [CTA_EXPECT_ID-1] = sizeof(u_int32_t)
1299 ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
1300 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1302 struct nf_conntrack_tuple tuple;
1303 struct nf_conntrack_expect *exp;
1304 struct sk_buff *skb2;
1305 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1306 u_int8_t u3 = nfmsg->nfgen_family;
1309 DEBUGP("entered %s\n", __FUNCTION__);
1311 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1314 if (nlh->nlmsg_flags & NLM_F_DUMP) {
1317 if ((*errp = netlink_dump_start(ctnl, skb, nlh,
1318 ctnetlink_exp_dump_table,
1319 ctnetlink_done)) != 0)
1321 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1322 if (rlen > skb->len)
1324 skb_pull(skb, rlen);
1328 if (cda[CTA_EXPECT_MASTER-1])
1329 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3);
1336 exp = nf_conntrack_expect_find(&tuple);
1340 if (cda[CTA_EXPECT_ID-1]) {
1341 u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1342 if (exp->id != ntohl(id)) {
1343 nf_conntrack_expect_put(exp);
1349 skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1352 NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid;
1354 err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid,
1355 nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW,
1360 nf_conntrack_expect_put(exp);
1362 return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
1367 nf_conntrack_expect_put(exp);
1372 ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
1373 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1375 struct nf_conntrack_expect *exp, *tmp;
1376 struct nf_conntrack_tuple tuple;
1377 struct nf_conntrack_helper *h;
1378 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1379 u_int8_t u3 = nfmsg->nfgen_family;
1382 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1385 if (cda[CTA_EXPECT_TUPLE-1]) {
1386 /* delete a single expect by tuple */
1387 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1391 /* bump usage count to 2 */
1392 exp = nf_conntrack_expect_find(&tuple);
1396 if (cda[CTA_EXPECT_ID-1]) {
1398 *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]);
1399 if (exp->id != ntohl(id)) {
1400 nf_conntrack_expect_put(exp);
1405 /* after list removal, usage count == 1 */
1406 nf_conntrack_unexpect_related(exp);
1407 /* have to put what we 'get' above.
1408 * after this line usage count == 0 */
1409 nf_conntrack_expect_put(exp);
1410 } else if (cda[CTA_EXPECT_HELP_NAME-1]) {
1411 char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]);
1413 /* delete all expectations for this helper */
1414 write_lock_bh(&nf_conntrack_lock);
1415 h = __nf_conntrack_helper_find_byname(name);
1417 write_unlock_bh(&nf_conntrack_lock);
1420 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1422 struct nf_conn_help *m_help = nfct_help(exp->master);
1423 if (m_help->helper == h
1424 && del_timer(&exp->timeout)) {
1425 nf_ct_unlink_expect(exp);
1426 nf_conntrack_expect_put(exp);
1429 write_unlock_bh(&nf_conntrack_lock);
1431 /* This basically means we have to flush everything*/
1432 write_lock_bh(&nf_conntrack_lock);
1433 list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list,
1435 if (del_timer(&exp->timeout)) {
1436 nf_ct_unlink_expect(exp);
1437 nf_conntrack_expect_put(exp);
1440 write_unlock_bh(&nf_conntrack_lock);
1446 ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nfattr *cda[])
1452 ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
1454 struct nf_conntrack_tuple tuple, mask, master_tuple;
1455 struct nf_conntrack_tuple_hash *h = NULL;
1456 struct nf_conntrack_expect *exp;
1458 struct nf_conn_help *help;
1461 DEBUGP("entered %s\n", __FUNCTION__);
1463 /* caller guarantees that those three CTA_EXPECT_* exist */
1464 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1467 err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK, u3);
1470 err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER, u3);
1474 /* Look for master conntrack of this expectation */
1475 h = nf_conntrack_find_get(&master_tuple, NULL);
1478 ct = nf_ct_tuplehash_to_ctrack(h);
1479 help = nfct_help(ct);
1481 if (!help || !help->helper) {
1482 /* such conntrack hasn't got any helper, abort */
1487 exp = nf_conntrack_expect_alloc(ct);
1493 exp->expectfn = NULL;
1496 memcpy(&exp->tuple, &tuple, sizeof(struct nf_conntrack_tuple));
1497 memcpy(&exp->mask, &mask, sizeof(struct nf_conntrack_tuple));
1499 err = nf_conntrack_expect_related(exp);
1500 nf_conntrack_expect_put(exp);
1503 nf_ct_put(nf_ct_tuplehash_to_ctrack(h));
1508 ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
1509 struct nlmsghdr *nlh, struct nfattr *cda[], int *errp)
1511 struct nf_conntrack_tuple tuple;
1512 struct nf_conntrack_expect *exp;
1513 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
1514 u_int8_t u3 = nfmsg->nfgen_family;
1517 DEBUGP("entered %s\n", __FUNCTION__);
1519 if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp))
1522 if (!cda[CTA_EXPECT_TUPLE-1]
1523 || !cda[CTA_EXPECT_MASK-1]
1524 || !cda[CTA_EXPECT_MASTER-1])
1527 err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3);
1531 write_lock_bh(&nf_conntrack_lock);
1532 exp = __nf_conntrack_expect_find(&tuple);
1535 write_unlock_bh(&nf_conntrack_lock);
1537 if (nlh->nlmsg_flags & NLM_F_CREATE)
1538 err = ctnetlink_create_expect(cda, u3);
1543 if (!(nlh->nlmsg_flags & NLM_F_EXCL))
1544 err = ctnetlink_change_expect(exp, cda);
1545 write_unlock_bh(&nf_conntrack_lock);
1547 DEBUGP("leaving\n");
1552 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1553 static struct notifier_block ctnl_notifier = {
1554 .notifier_call = ctnetlink_conntrack_event,
1557 static struct notifier_block ctnl_notifier_exp = {
1558 .notifier_call = ctnetlink_expect_event,
1562 static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = {
1563 [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack,
1564 .attr_count = CTA_MAX, },
1565 [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack,
1566 .attr_count = CTA_MAX, },
1567 [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack,
1568 .attr_count = CTA_MAX, },
1569 [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack,
1570 .attr_count = CTA_MAX, },
1573 static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = {
1574 [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect,
1575 .attr_count = CTA_EXPECT_MAX, },
1576 [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect,
1577 .attr_count = CTA_EXPECT_MAX, },
1578 [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect,
1579 .attr_count = CTA_EXPECT_MAX, },
1582 static struct nfnetlink_subsystem ctnl_subsys = {
1583 .name = "conntrack",
1584 .subsys_id = NFNL_SUBSYS_CTNETLINK,
1585 .cb_count = IPCTNL_MSG_MAX,
1589 static struct nfnetlink_subsystem ctnl_exp_subsys = {
1590 .name = "conntrack_expect",
1591 .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP,
1592 .cb_count = IPCTNL_MSG_EXP_MAX,
1596 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK);
1597 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_EXP);
1599 static int __init ctnetlink_init(void)
1603 printk("ctnetlink v%s: registering with nfnetlink.\n", version);
1604 ret = nfnetlink_subsys_register(&ctnl_subsys);
1606 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1610 ret = nfnetlink_subsys_register(&ctnl_exp_subsys);
1612 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1613 goto err_unreg_subsys;
1616 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1617 ret = nf_conntrack_register_notifier(&ctnl_notifier);
1619 printk("ctnetlink_init: cannot register notifier.\n");
1620 goto err_unreg_exp_subsys;
1623 ret = nf_conntrack_expect_register_notifier(&ctnl_notifier_exp);
1625 printk("ctnetlink_init: cannot expect register notifier.\n");
1626 goto err_unreg_notifier;
1632 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1634 nf_conntrack_unregister_notifier(&ctnl_notifier);
1635 err_unreg_exp_subsys:
1636 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1639 nfnetlink_subsys_unregister(&ctnl_subsys);
1644 static void __exit ctnetlink_exit(void)
1646 printk("ctnetlink: unregistering from nfnetlink.\n");
1648 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1649 nf_conntrack_unregister_notifier(&ctnl_notifier_exp);
1650 nf_conntrack_unregister_notifier(&ctnl_notifier);
1653 nfnetlink_subsys_unregister(&ctnl_exp_subsys);
1654 nfnetlink_subsys_unregister(&ctnl_subsys);
1658 module_init(ctnetlink_init);
1659 module_exit(ctnetlink_exit);