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.
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/notifier.h>
32 #include <linux/netfilter.h>
33 #include <linux/netfilter_ipv4/ip_conntrack.h>
34 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
35 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
36 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
37 #include <linux/netfilter_ipv4/ip_nat_protocol.h>
39 #include <linux/netfilter/nfnetlink.h>
40 #include <linux/netfilter/nfnetlink_conntrack.h>
42 MODULE_LICENSE("GPL");
44 static char __initdata version
[] = "0.90";
49 #define DEBUGP(format, args...)
54 ctnetlink_dump_tuples_proto(struct sk_buff
*skb
,
55 const struct ip_conntrack_tuple
*tuple
)
57 struct ip_conntrack_protocol
*proto
;
60 NFA_PUT(skb
, CTA_PROTO_NUM
, sizeof(u_int8_t
), &tuple
->dst
.protonum
);
62 proto
= ip_conntrack_proto_find_get(tuple
->dst
.protonum
);
63 if (likely(proto
&& proto
->tuple_to_nfattr
)) {
64 ret
= proto
->tuple_to_nfattr(skb
, tuple
);
65 ip_conntrack_proto_put(proto
);
75 ctnetlink_dump_tuples(struct sk_buff
*skb
,
76 const struct ip_conntrack_tuple
*tuple
)
78 struct nfattr
*nest_parms
;
80 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
);
83 NFA_NEST_END(skb
, nest_parms
);
85 nest_parms
= NFA_NEST(skb
, CTA_TUPLE_PROTO
);
86 ctnetlink_dump_tuples_proto(skb
, tuple
);
87 NFA_NEST_END(skb
, nest_parms
);
96 ctnetlink_dump_status(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
98 u_int32_t status
= htonl((u_int32_t
) ct
->status
);
99 NFA_PUT(skb
, CTA_STATUS
, sizeof(status
), &status
);
107 ctnetlink_dump_timeout(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
109 long timeout_l
= ct
->timeout
.expires
- jiffies
;
115 timeout
= htonl(timeout_l
/ HZ
);
117 NFA_PUT(skb
, CTA_TIMEOUT
, sizeof(timeout
), &timeout
);
125 ctnetlink_dump_protoinfo(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
127 struct ip_conntrack_protocol
*proto
= ip_conntrack_proto_find_get(ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
);
129 struct nfattr
*nest_proto
;
132 if (!proto
|| !proto
->to_nfattr
)
135 nest_proto
= NFA_NEST(skb
, CTA_PROTOINFO
);
137 ret
= proto
->to_nfattr(skb
, nest_proto
, ct
);
139 ip_conntrack_proto_put(proto
);
141 NFA_NEST_END(skb
, nest_proto
);
150 ctnetlink_dump_helpinfo(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
152 struct nfattr
*nest_helper
;
157 nest_helper
= NFA_NEST(skb
, CTA_HELP
);
158 NFA_PUT(skb
, CTA_HELP_NAME
, CTA_HELP_MAXNAMESIZE
, &ct
->helper
->name
);
160 if (ct
->helper
->to_nfattr
)
161 ct
->helper
->to_nfattr(skb
, ct
);
163 NFA_NEST_END(skb
, nest_helper
);
171 #ifdef CONFIG_IP_NF_CT_ACCT
173 ctnetlink_dump_counters(struct sk_buff
*skb
, const struct ip_conntrack
*ct
,
174 enum ip_conntrack_dir dir
)
176 enum ctattr_type type
= dir
? CTA_COUNTERS_REPLY
: CTA_COUNTERS_ORIG
;
177 struct nfattr
*nest_count
= NFA_NEST(skb
, type
);
180 tmp
= htonl(ct
->counters
[dir
].packets
);
181 NFA_PUT(skb
, CTA_COUNTERS32_PACKETS
, sizeof(u_int32_t
), &tmp
);
183 tmp
= htonl(ct
->counters
[dir
].bytes
);
184 NFA_PUT(skb
, CTA_COUNTERS32_BYTES
, sizeof(u_int32_t
), &tmp
);
186 NFA_NEST_END(skb
, nest_count
);
194 #define ctnetlink_dump_counters(a, b, c) (0)
197 #ifdef CONFIG_IP_NF_CONNTRACK_MARK
199 ctnetlink_dump_mark(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
201 u_int32_t mark
= htonl(ct
->mark
);
203 NFA_PUT(skb
, CTA_MARK
, sizeof(u_int32_t
), &mark
);
210 #define ctnetlink_dump_mark(a, b) (0)
214 ctnetlink_dump_id(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
216 u_int32_t id
= htonl(ct
->id
);
217 NFA_PUT(skb
, CTA_ID
, sizeof(u_int32_t
), &id
);
225 ctnetlink_dump_use(struct sk_buff
*skb
, const struct ip_conntrack
*ct
)
227 unsigned int use
= htonl(atomic_read(&ct
->ct_general
.use
));
229 NFA_PUT(skb
, CTA_USE
, sizeof(u_int32_t
), &use
);
236 #define tuple(ct, dir) (&(ct)->tuplehash[dir].tuple)
239 ctnetlink_fill_info(struct sk_buff
*skb
, u32 pid
, u32 seq
,
240 int event
, int nowait
,
241 const struct ip_conntrack
*ct
)
243 struct nlmsghdr
*nlh
;
244 struct nfgenmsg
*nfmsg
;
245 struct nfattr
*nest_parms
;
250 event
|= NFNL_SUBSYS_CTNETLINK
<< 8;
251 nlh
= NLMSG_PUT(skb
, pid
, seq
, event
, sizeof(struct nfgenmsg
));
252 nfmsg
= NLMSG_DATA(nlh
);
254 nlh
->nlmsg_flags
= (nowait
&& pid
) ? NLM_F_MULTI
: 0;
255 nfmsg
->nfgen_family
= AF_INET
;
256 nfmsg
->version
= NFNETLINK_V0
;
259 nest_parms
= NFA_NEST(skb
, CTA_TUPLE_ORIG
);
260 if (ctnetlink_dump_tuples(skb
, tuple(ct
, IP_CT_DIR_ORIGINAL
)) < 0)
262 NFA_NEST_END(skb
, nest_parms
);
264 nest_parms
= NFA_NEST(skb
, CTA_TUPLE_REPLY
);
265 if (ctnetlink_dump_tuples(skb
, tuple(ct
, IP_CT_DIR_REPLY
)) < 0)
267 NFA_NEST_END(skb
, nest_parms
);
269 if (ctnetlink_dump_status(skb
, ct
) < 0 ||
270 ctnetlink_dump_timeout(skb
, ct
) < 0 ||
271 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_ORIGINAL
) < 0 ||
272 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_REPLY
) < 0 ||
273 ctnetlink_dump_protoinfo(skb
, ct
) < 0 ||
274 ctnetlink_dump_helpinfo(skb
, ct
) < 0 ||
275 ctnetlink_dump_mark(skb
, ct
) < 0 ||
276 ctnetlink_dump_id(skb
, ct
) < 0 ||
277 ctnetlink_dump_use(skb
, ct
) < 0)
280 nlh
->nlmsg_len
= skb
->tail
- b
;
285 skb_trim(skb
, b
- skb
->data
);
289 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
290 static int ctnetlink_conntrack_event(struct notifier_block
*this,
291 unsigned long events
, void *ptr
)
293 struct nlmsghdr
*nlh
;
294 struct nfgenmsg
*nfmsg
;
295 struct nfattr
*nest_parms
;
296 struct ip_conntrack
*ct
= (struct ip_conntrack
*)ptr
;
300 unsigned int flags
= 0, group
;
302 /* ignore our fake conntrack entry */
303 if (ct
== &ip_conntrack_untracked
)
306 if (events
& IPCT_DESTROY
) {
307 type
= IPCTNL_MSG_CT_DELETE
;
308 group
= NFNLGRP_CONNTRACK_DESTROY
;
311 if (events
& (IPCT_NEW
| IPCT_RELATED
)) {
312 type
= IPCTNL_MSG_CT_NEW
;
313 flags
= NLM_F_CREATE
|NLM_F_EXCL
;
314 /* dump everything */
316 group
= NFNLGRP_CONNTRACK_NEW
;
319 if (events
& (IPCT_STATUS
|
324 type
= IPCTNL_MSG_CT_NEW
;
325 group
= NFNLGRP_CONNTRACK_UPDATE
;
332 /* FIXME: Check if there are any listeners before, don't hurt performance */
334 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_ATOMIC
);
340 type
|= NFNL_SUBSYS_CTNETLINK
<< 8;
341 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(struct nfgenmsg
));
342 nfmsg
= NLMSG_DATA(nlh
);
344 nlh
->nlmsg_flags
= flags
;
345 nfmsg
->nfgen_family
= AF_INET
;
346 nfmsg
->version
= NFNETLINK_V0
;
349 nest_parms
= NFA_NEST(skb
, CTA_TUPLE_ORIG
);
350 if (ctnetlink_dump_tuples(skb
, tuple(ct
, IP_CT_DIR_ORIGINAL
)) < 0)
352 NFA_NEST_END(skb
, nest_parms
);
354 nest_parms
= NFA_NEST(skb
, CTA_TUPLE_REPLY
);
355 if (ctnetlink_dump_tuples(skb
, tuple(ct
, IP_CT_DIR_REPLY
)) < 0)
357 NFA_NEST_END(skb
, nest_parms
);
359 /* NAT stuff is now a status flag */
360 if ((events
& IPCT_STATUS
|| events
& IPCT_NATINFO
)
361 && ctnetlink_dump_status(skb
, ct
) < 0)
363 if (events
& IPCT_REFRESH
364 && ctnetlink_dump_timeout(skb
, ct
) < 0)
366 if (events
& IPCT_PROTOINFO
367 && ctnetlink_dump_protoinfo(skb
, ct
) < 0)
369 if (events
& IPCT_HELPINFO
370 && ctnetlink_dump_helpinfo(skb
, ct
) < 0)
373 if (ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_ORIGINAL
) < 0 ||
374 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_REPLY
) < 0)
377 nlh
->nlmsg_len
= skb
->tail
- b
;
378 nfnetlink_send(skb
, 0, group
, 0);
386 #endif /* CONFIG_IP_NF_CONNTRACK_EVENTS */
388 static int ctnetlink_done(struct netlink_callback
*cb
)
390 DEBUGP("entered %s\n", __FUNCTION__
);
395 ctnetlink_dump_table(struct sk_buff
*skb
, struct netlink_callback
*cb
)
397 struct ip_conntrack
*ct
= NULL
;
398 struct ip_conntrack_tuple_hash
*h
;
400 u_int32_t
*id
= (u_int32_t
*) &cb
->args
[1];
402 DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__
,
405 read_lock_bh(&ip_conntrack_lock
);
406 for (; cb
->args
[0] < ip_conntrack_htable_size
; cb
->args
[0]++, *id
= 0) {
407 list_for_each_prev(i
, &ip_conntrack_hash
[cb
->args
[0]]) {
408 h
= (struct ip_conntrack_tuple_hash
*) i
;
409 if (DIRECTION(h
) != IP_CT_DIR_ORIGINAL
)
411 ct
= tuplehash_to_ctrack(h
);
414 if (ctnetlink_fill_info(skb
, NETLINK_CB(cb
->skb
).pid
,
423 read_unlock_bh(&ip_conntrack_lock
);
425 DEBUGP("leaving, last bucket=%lu id=%u\n", cb
->args
[0], *id
);
430 #ifdef CONFIG_IP_NF_CT_ACCT
432 ctnetlink_dump_table_w(struct sk_buff
*skb
, struct netlink_callback
*cb
)
434 struct ip_conntrack
*ct
= NULL
;
435 struct ip_conntrack_tuple_hash
*h
;
437 u_int32_t
*id
= (u_int32_t
*) &cb
->args
[1];
439 DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__
,
442 write_lock_bh(&ip_conntrack_lock
);
443 for (; cb
->args
[0] < ip_conntrack_htable_size
; cb
->args
[0]++, *id
= 0) {
444 list_for_each_prev(i
, &ip_conntrack_hash
[cb
->args
[0]]) {
445 h
= (struct ip_conntrack_tuple_hash
*) i
;
446 if (DIRECTION(h
) != IP_CT_DIR_ORIGINAL
)
448 ct
= tuplehash_to_ctrack(h
);
451 if (ctnetlink_fill_info(skb
, NETLINK_CB(cb
->skb
).pid
,
458 memset(&ct
->counters
, 0, sizeof(ct
->counters
));
462 write_unlock_bh(&ip_conntrack_lock
);
464 DEBUGP("leaving, last bucket=%lu id=%u\n", cb
->args
[0], *id
);
470 static const int cta_min_ip
[CTA_IP_MAX
] = {
471 [CTA_IP_V4_SRC
-1] = sizeof(u_int32_t
),
472 [CTA_IP_V4_DST
-1] = sizeof(u_int32_t
),
476 ctnetlink_parse_tuple_ip(struct nfattr
*attr
, struct ip_conntrack_tuple
*tuple
)
478 struct nfattr
*tb
[CTA_IP_MAX
];
480 DEBUGP("entered %s\n", __FUNCTION__
);
482 nfattr_parse_nested(tb
, CTA_IP_MAX
, attr
);
484 if (nfattr_bad_size(tb
, CTA_IP_MAX
, cta_min_ip
))
487 if (!tb
[CTA_IP_V4_SRC
-1])
489 tuple
->src
.ip
= *(u_int32_t
*)NFA_DATA(tb
[CTA_IP_V4_SRC
-1]);
491 if (!tb
[CTA_IP_V4_DST
-1])
493 tuple
->dst
.ip
= *(u_int32_t
*)NFA_DATA(tb
[CTA_IP_V4_DST
-1]);
500 static const int cta_min_proto
[CTA_PROTO_MAX
] = {
501 [CTA_PROTO_NUM
-1] = sizeof(u_int16_t
),
502 [CTA_PROTO_SRC_PORT
-1] = sizeof(u_int16_t
),
503 [CTA_PROTO_DST_PORT
-1] = sizeof(u_int16_t
),
504 [CTA_PROTO_ICMP_TYPE
-1] = sizeof(u_int8_t
),
505 [CTA_PROTO_ICMP_CODE
-1] = sizeof(u_int8_t
),
506 [CTA_PROTO_ICMP_ID
-1] = sizeof(u_int16_t
),
510 ctnetlink_parse_tuple_proto(struct nfattr
*attr
,
511 struct ip_conntrack_tuple
*tuple
)
513 struct nfattr
*tb
[CTA_PROTO_MAX
];
514 struct ip_conntrack_protocol
*proto
;
517 DEBUGP("entered %s\n", __FUNCTION__
);
519 nfattr_parse_nested(tb
, CTA_PROTO_MAX
, attr
);
521 if (nfattr_bad_size(tb
, CTA_PROTO_MAX
, cta_min_proto
))
524 if (!tb
[CTA_PROTO_NUM
-1])
526 tuple
->dst
.protonum
= *(u_int16_t
*)NFA_DATA(tb
[CTA_PROTO_NUM
-1]);
528 proto
= ip_conntrack_proto_find_get(tuple
->dst
.protonum
);
530 if (likely(proto
&& proto
->nfattr_to_tuple
)) {
531 ret
= proto
->nfattr_to_tuple(tb
, tuple
);
532 ip_conntrack_proto_put(proto
);
539 ctnetlink_parse_tuple(struct nfattr
*cda
[], struct ip_conntrack_tuple
*tuple
,
540 enum ctattr_tuple type
)
542 struct nfattr
*tb
[CTA_TUPLE_MAX
];
545 DEBUGP("entered %s\n", __FUNCTION__
);
547 memset(tuple
, 0, sizeof(*tuple
));
549 nfattr_parse_nested(tb
, CTA_TUPLE_MAX
, cda
[type
-1]);
551 if (!tb
[CTA_TUPLE_IP
-1])
554 err
= ctnetlink_parse_tuple_ip(tb
[CTA_TUPLE_IP
-1], tuple
);
558 if (!tb
[CTA_TUPLE_PROTO
-1])
561 err
= ctnetlink_parse_tuple_proto(tb
[CTA_TUPLE_PROTO
-1], tuple
);
565 /* orig and expect tuples get DIR_ORIGINAL */
566 if (type
== CTA_TUPLE_REPLY
)
567 tuple
->dst
.dir
= IP_CT_DIR_REPLY
;
569 tuple
->dst
.dir
= IP_CT_DIR_ORIGINAL
;
578 #ifdef CONFIG_IP_NF_NAT_NEEDED
579 static const int cta_min_protonat
[CTA_PROTONAT_MAX
] = {
580 [CTA_PROTONAT_PORT_MIN
-1] = sizeof(u_int16_t
),
581 [CTA_PROTONAT_PORT_MAX
-1] = sizeof(u_int16_t
),
584 static int ctnetlink_parse_nat_proto(struct nfattr
*attr
,
585 const struct ip_conntrack
*ct
,
586 struct ip_nat_range
*range
)
588 struct nfattr
*tb
[CTA_PROTONAT_MAX
];
589 struct ip_nat_protocol
*npt
;
591 DEBUGP("entered %s\n", __FUNCTION__
);
593 nfattr_parse_nested(tb
, CTA_PROTONAT_MAX
, attr
);
595 if (nfattr_bad_size(tb
, CTA_PROTONAT_MAX
, cta_min_protonat
))
598 npt
= ip_nat_proto_find_get(ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
);
602 if (!npt
->nfattr_to_range
) {
603 ip_nat_proto_put(npt
);
607 /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
608 if (npt
->nfattr_to_range(tb
, range
) > 0)
609 range
->flags
|= IP_NAT_RANGE_PROTO_SPECIFIED
;
611 ip_nat_proto_put(npt
);
618 ctnetlink_parse_nat(struct nfattr
*cda
[],
619 const struct ip_conntrack
*ct
, struct ip_nat_range
*range
)
621 struct nfattr
*tb
[CTA_NAT_MAX
];
624 DEBUGP("entered %s\n", __FUNCTION__
);
626 memset(range
, 0, sizeof(*range
));
628 nfattr_parse_nested(tb
, CTA_NAT_MAX
, cda
[CTA_NAT
-1]);
630 if (tb
[CTA_NAT_MINIP
-1])
631 range
->min_ip
= *(u_int32_t
*)NFA_DATA(tb
[CTA_NAT_MINIP
-1]);
633 if (!tb
[CTA_NAT_MAXIP
-1])
634 range
->max_ip
= range
->min_ip
;
636 range
->max_ip
= *(u_int32_t
*)NFA_DATA(tb
[CTA_NAT_MAXIP
-1]);
639 range
->flags
|= IP_NAT_RANGE_MAP_IPS
;
641 if (!tb
[CTA_NAT_PROTO
-1])
644 err
= ctnetlink_parse_nat_proto(tb
[CTA_NAT_PROTO
-1], ct
, range
);
654 ctnetlink_parse_help(struct nfattr
*attr
, char **helper_name
)
656 struct nfattr
*tb
[CTA_HELP_MAX
];
658 DEBUGP("entered %s\n", __FUNCTION__
);
660 nfattr_parse_nested(tb
, CTA_HELP_MAX
, attr
);
662 if (!tb
[CTA_HELP_NAME
-1])
665 *helper_name
= NFA_DATA(tb
[CTA_HELP_NAME
-1]);
671 ctnetlink_del_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
672 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
674 struct ip_conntrack_tuple_hash
*h
;
675 struct ip_conntrack_tuple tuple
;
676 struct ip_conntrack
*ct
;
679 DEBUGP("entered %s\n", __FUNCTION__
);
681 if (cda
[CTA_TUPLE_ORIG
-1])
682 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_ORIG
);
683 else if (cda
[CTA_TUPLE_REPLY
-1])
684 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_REPLY
);
686 /* Flush the whole table */
687 ip_conntrack_flush();
694 h
= ip_conntrack_find_get(&tuple
, NULL
);
696 DEBUGP("tuple not found in conntrack hash\n");
700 ct
= tuplehash_to_ctrack(h
);
703 u_int32_t id
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_ID
-1]));
705 ip_conntrack_put(ct
);
709 if (del_timer(&ct
->timeout
)) {
710 ip_conntrack_put(ct
);
711 ct
->timeout
.function((unsigned long)ct
);
714 ip_conntrack_put(ct
);
721 ctnetlink_get_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
722 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
724 struct ip_conntrack_tuple_hash
*h
;
725 struct ip_conntrack_tuple tuple
;
726 struct ip_conntrack
*ct
;
727 struct sk_buff
*skb2
= NULL
;
730 DEBUGP("entered %s\n", __FUNCTION__
);
732 if (nlh
->nlmsg_flags
& NLM_F_DUMP
) {
733 struct nfgenmsg
*msg
= NLMSG_DATA(nlh
);
736 if (msg
->nfgen_family
!= AF_INET
)
737 return -EAFNOSUPPORT
;
739 if (NFNL_MSG_TYPE(nlh
->nlmsg_type
) ==
740 IPCTNL_MSG_CT_GET_CTRZERO
) {
741 #ifdef CONFIG_IP_NF_CT_ACCT
742 if ((*errp
= netlink_dump_start(ctnl
, skb
, nlh
,
743 ctnetlink_dump_table_w
,
744 ctnetlink_done
)) != 0)
750 if ((*errp
= netlink_dump_start(ctnl
, skb
, nlh
,
751 ctnetlink_dump_table
,
752 ctnetlink_done
)) != 0)
756 rlen
= NLMSG_ALIGN(nlh
->nlmsg_len
);
763 if (cda
[CTA_TUPLE_ORIG
-1])
764 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_ORIG
);
765 else if (cda
[CTA_TUPLE_REPLY
-1])
766 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_REPLY
);
773 h
= ip_conntrack_find_get(&tuple
, NULL
);
775 DEBUGP("tuple not found in conntrack hash");
778 DEBUGP("tuple found\n");
779 ct
= tuplehash_to_ctrack(h
);
782 skb2
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
784 ip_conntrack_put(ct
);
787 NETLINK_CB(skb2
).dst_pid
= NETLINK_CB(skb
).pid
;
789 err
= ctnetlink_fill_info(skb2
, NETLINK_CB(skb
).pid
, nlh
->nlmsg_seq
,
790 IPCTNL_MSG_CT_NEW
, 1, ct
);
791 ip_conntrack_put(ct
);
795 err
= netlink_unicast(ctnl
, skb2
, NETLINK_CB(skb
).pid
, MSG_DONTWAIT
);
809 ctnetlink_change_status(struct ip_conntrack
*ct
, struct nfattr
*cda
[])
812 unsigned status
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_STATUS
-1]));
813 d
= ct
->status
^ status
;
815 if (d
& (IPS_EXPECTED
|IPS_CONFIRMED
|IPS_DYING
))
819 if (d
& IPS_SEEN_REPLY
&& !(status
& IPS_SEEN_REPLY
))
820 /* SEEN_REPLY bit can only be set */
824 if (d
& IPS_ASSURED
&& !(status
& IPS_ASSURED
))
825 /* ASSURED bit can only be set */
828 if (cda
[CTA_NAT
-1]) {
829 #ifndef CONFIG_IP_NF_NAT_NEEDED
832 unsigned int hooknum
;
833 struct ip_nat_range range
;
835 if (ctnetlink_parse_nat(cda
, ct
, &range
) < 0)
838 DEBUGP("NAT: %u.%u.%u.%u-%u.%u.%u.%u:%u-%u\n",
839 NIPQUAD(range
.min_ip
), NIPQUAD(range
.max_ip
),
840 htons(range
.min
.all
), htons(range
.max
.all
));
842 /* This is tricky but it works. ip_nat_setup_info needs the
843 * hook number as parameter, so let's do the correct
844 * conversion and run away */
845 if (status
& IPS_SRC_NAT_DONE
)
846 hooknum
= NF_IP_POST_ROUTING
; /* IP_NAT_MANIP_SRC */
847 else if (status
& IPS_DST_NAT_DONE
)
848 hooknum
= NF_IP_PRE_ROUTING
; /* IP_NAT_MANIP_DST */
850 return -EINVAL
; /* Missing NAT flags */
852 DEBUGP("NAT status: %lu\n",
853 status
& (IPS_NAT_MASK
| IPS_NAT_DONE_MASK
));
855 if (ip_nat_initialized(ct
, hooknum
))
857 ip_nat_setup_info(ct
, &range
, hooknum
);
859 DEBUGP("NAT status after setup_info: %lu\n",
860 ct
->status
& (IPS_NAT_MASK
| IPS_NAT_DONE_MASK
));
864 /* Be careful here, modifying NAT bits can screw up things,
865 * so don't let users modify them directly if they don't pass
867 ct
->status
|= status
& ~(IPS_NAT_DONE_MASK
| IPS_NAT_MASK
);
873 ctnetlink_change_helper(struct ip_conntrack
*ct
, struct nfattr
*cda
[])
875 struct ip_conntrack_helper
*helper
;
879 DEBUGP("entered %s\n", __FUNCTION__
);
881 /* don't change helper of sibling connections */
885 err
= ctnetlink_parse_help(cda
[CTA_HELP
-1], &helpname
);
889 helper
= __ip_conntrack_helper_find_byname(helpname
);
891 if (!strcmp(helpname
, ""))
899 /* we had a helper before ... */
900 ip_ct_remove_expectations(ct
);
903 /* need to zero data of old helper */
904 memset(&ct
->help
, 0, sizeof(ct
->help
));
914 ctnetlink_change_timeout(struct ip_conntrack
*ct
, struct nfattr
*cda
[])
916 u_int32_t timeout
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_TIMEOUT
-1]));
918 if (!del_timer(&ct
->timeout
))
921 ct
->timeout
.expires
= jiffies
+ timeout
* HZ
;
922 add_timer(&ct
->timeout
);
928 ctnetlink_change_protoinfo(struct ip_conntrack
*ct
, struct nfattr
*cda
[])
930 struct nfattr
*tb
[CTA_PROTOINFO_MAX
], *attr
= cda
[CTA_PROTOINFO
-1];
931 struct ip_conntrack_protocol
*proto
;
932 u_int16_t npt
= ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.protonum
;
935 nfattr_parse_nested(tb
, CTA_PROTOINFO_MAX
, attr
);
937 proto
= ip_conntrack_proto_find_get(npt
);
941 if (proto
->from_nfattr
)
942 err
= proto
->from_nfattr(tb
, ct
);
943 ip_conntrack_proto_put(proto
);
949 ctnetlink_change_conntrack(struct ip_conntrack
*ct
, struct nfattr
*cda
[])
953 DEBUGP("entered %s\n", __FUNCTION__
);
955 if (cda
[CTA_HELP
-1]) {
956 err
= ctnetlink_change_helper(ct
, cda
);
961 if (cda
[CTA_TIMEOUT
-1]) {
962 err
= ctnetlink_change_timeout(ct
, cda
);
967 if (cda
[CTA_STATUS
-1]) {
968 err
= ctnetlink_change_status(ct
, cda
);
973 if (cda
[CTA_PROTOINFO
-1]) {
974 err
= ctnetlink_change_protoinfo(ct
, cda
);
979 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
981 ct
->mark
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_MARK
-1]));
984 DEBUGP("all done\n");
989 ctnetlink_create_conntrack(struct nfattr
*cda
[],
990 struct ip_conntrack_tuple
*otuple
,
991 struct ip_conntrack_tuple
*rtuple
)
993 struct ip_conntrack
*ct
;
996 DEBUGP("entered %s\n", __FUNCTION__
);
998 ct
= ip_conntrack_alloc(otuple
, rtuple
);
999 if (ct
== NULL
|| IS_ERR(ct
))
1002 if (!cda
[CTA_TIMEOUT
-1])
1004 ct
->timeout
.expires
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_TIMEOUT
-1]));
1006 ct
->timeout
.expires
= jiffies
+ ct
->timeout
.expires
* HZ
;
1007 ct
->status
|= IPS_CONFIRMED
;
1009 err
= ctnetlink_change_status(ct
, cda
);
1013 if (cda
[CTA_PROTOINFO
-1]) {
1014 err
= ctnetlink_change_protoinfo(ct
, cda
);
1019 ct
->helper
= ip_conntrack_helper_find_get(rtuple
);
1021 add_timer(&ct
->timeout
);
1022 ip_conntrack_hash_insert(ct
);
1025 ip_conntrack_helper_put(ct
->helper
);
1027 #if defined(CONFIG_IP_NF_CONNTRACK_MARK)
1028 if (cda
[CTA_MARK
-1])
1029 ct
->mark
= ntohl(*(u_int32_t
*)NFA_DATA(cda
[CTA_MARK
-1]));
1032 DEBUGP("conntrack with id %u inserted\n", ct
->id
);
1036 ip_conntrack_free(ct
);
1041 ctnetlink_new_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
1042 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
1044 struct ip_conntrack_tuple otuple
, rtuple
;
1045 struct ip_conntrack_tuple_hash
*h
= NULL
;
1048 DEBUGP("entered %s\n", __FUNCTION__
);
1050 if (cda
[CTA_TUPLE_ORIG
-1]) {
1051 err
= ctnetlink_parse_tuple(cda
, &otuple
, CTA_TUPLE_ORIG
);
1056 if (cda
[CTA_TUPLE_REPLY
-1]) {
1057 err
= ctnetlink_parse_tuple(cda
, &rtuple
, CTA_TUPLE_REPLY
);
1062 write_lock_bh(&ip_conntrack_lock
);
1063 if (cda
[CTA_TUPLE_ORIG
-1])
1064 h
= __ip_conntrack_find(&otuple
, NULL
);
1065 else if (cda
[CTA_TUPLE_REPLY
-1])
1066 h
= __ip_conntrack_find(&rtuple
, NULL
);
1069 write_unlock_bh(&ip_conntrack_lock
);
1070 DEBUGP("no such conntrack, create new\n");
1072 if (nlh
->nlmsg_flags
& NLM_F_CREATE
)
1073 err
= ctnetlink_create_conntrack(cda
, &otuple
, &rtuple
);
1076 /* implicit 'else' */
1078 /* we only allow nat config for new conntracks */
1079 if (cda
[CTA_NAT
-1]) {
1084 /* We manipulate the conntrack inside the global conntrack table lock,
1085 * so there's no need to increase the refcount */
1086 DEBUGP("conntrack found\n");
1088 if (!(nlh
->nlmsg_flags
& NLM_F_EXCL
))
1089 err
= ctnetlink_change_conntrack(tuplehash_to_ctrack(h
), cda
);
1092 write_unlock_bh(&ip_conntrack_lock
);
1096 /***********************************************************************
1098 ***********************************************************************/
1101 ctnetlink_exp_dump_tuple(struct sk_buff
*skb
,
1102 const struct ip_conntrack_tuple
*tuple
,
1103 enum ctattr_expect type
)
1105 struct nfattr
*nest_parms
= NFA_NEST(skb
, type
);
1107 if (ctnetlink_dump_tuples(skb
, tuple
) < 0)
1108 goto nfattr_failure
;
1110 NFA_NEST_END(skb
, nest_parms
);
1119 ctnetlink_exp_dump_expect(struct sk_buff
*skb
,
1120 const struct ip_conntrack_expect
*exp
)
1122 struct ip_conntrack
*master
= exp
->master
;
1123 u_int32_t timeout
= htonl((exp
->timeout
.expires
- jiffies
) / HZ
);
1124 u_int32_t id
= htonl(exp
->id
);
1126 if (ctnetlink_exp_dump_tuple(skb
, &exp
->tuple
, CTA_EXPECT_TUPLE
) < 0)
1127 goto nfattr_failure
;
1128 if (ctnetlink_exp_dump_tuple(skb
, &exp
->mask
, CTA_EXPECT_MASK
) < 0)
1129 goto nfattr_failure
;
1130 if (ctnetlink_exp_dump_tuple(skb
,
1131 &master
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
,
1132 CTA_EXPECT_MASTER
) < 0)
1133 goto nfattr_failure
;
1135 NFA_PUT(skb
, CTA_EXPECT_TIMEOUT
, sizeof(timeout
), &timeout
);
1136 NFA_PUT(skb
, CTA_EXPECT_ID
, sizeof(u_int32_t
), &id
);
1145 ctnetlink_exp_fill_info(struct sk_buff
*skb
, u32 pid
, u32 seq
,
1148 const struct ip_conntrack_expect
*exp
)
1150 struct nlmsghdr
*nlh
;
1151 struct nfgenmsg
*nfmsg
;
1156 event
|= NFNL_SUBSYS_CTNETLINK_EXP
<< 8;
1157 nlh
= NLMSG_PUT(skb
, pid
, seq
, event
, sizeof(struct nfgenmsg
));
1158 nfmsg
= NLMSG_DATA(nlh
);
1160 nlh
->nlmsg_flags
= (nowait
&& pid
) ? NLM_F_MULTI
: 0;
1161 nfmsg
->nfgen_family
= AF_INET
;
1162 nfmsg
->version
= NFNETLINK_V0
;
1165 if (ctnetlink_exp_dump_expect(skb
, exp
) < 0)
1166 goto nfattr_failure
;
1168 nlh
->nlmsg_len
= skb
->tail
- b
;
1173 skb_trim(skb
, b
- skb
->data
);
1177 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1178 static int ctnetlink_expect_event(struct notifier_block
*this,
1179 unsigned long events
, void *ptr
)
1181 struct nlmsghdr
*nlh
;
1182 struct nfgenmsg
*nfmsg
;
1183 struct ip_conntrack_expect
*exp
= (struct ip_conntrack_expect
*)ptr
;
1184 struct sk_buff
*skb
;
1190 if (events
& IPEXP_NEW
) {
1191 type
= IPCTNL_MSG_EXP_NEW
;
1192 flags
= NLM_F_CREATE
|NLM_F_EXCL
;
1196 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_ATOMIC
);
1202 type
|= NFNL_SUBSYS_CTNETLINK
<< 8;
1203 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(struct nfgenmsg
));
1204 nfmsg
= NLMSG_DATA(nlh
);
1206 nlh
->nlmsg_flags
= flags
;
1207 nfmsg
->nfgen_family
= AF_INET
;
1208 nfmsg
->version
= NFNETLINK_V0
;
1211 if (ctnetlink_exp_dump_expect(skb
, exp
) < 0)
1212 goto nfattr_failure
;
1214 nlh
->nlmsg_len
= skb
->tail
- b
;
1215 proto
= exp
->tuple
.dst
.protonum
;
1216 nfnetlink_send(skb
, 0, NFNLGRP_CONNTRACK_EXP_NEW
, 0);
1227 ctnetlink_exp_dump_table(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1229 struct ip_conntrack_expect
*exp
= NULL
;
1230 struct list_head
*i
;
1231 u_int32_t
*id
= (u_int32_t
*) &cb
->args
[0];
1233 DEBUGP("entered %s, last id=%llu\n", __FUNCTION__
, *id
);
1235 read_lock_bh(&ip_conntrack_lock
);
1236 list_for_each_prev(i
, &ip_conntrack_expect_list
) {
1237 exp
= (struct ip_conntrack_expect
*) i
;
1240 if (ctnetlink_exp_fill_info(skb
, NETLINK_CB(cb
->skb
).pid
,
1248 read_unlock_bh(&ip_conntrack_lock
);
1250 DEBUGP("leaving, last id=%llu\n", *id
);
1256 ctnetlink_get_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
1257 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
1259 struct ip_conntrack_tuple tuple
;
1260 struct ip_conntrack_expect
*exp
;
1261 struct sk_buff
*skb2
;
1264 DEBUGP("entered %s\n", __FUNCTION__
);
1266 if (nlh
->nlmsg_flags
& NLM_F_DUMP
) {
1267 struct nfgenmsg
*msg
= NLMSG_DATA(nlh
);
1270 if (msg
->nfgen_family
!= AF_INET
)
1271 return -EAFNOSUPPORT
;
1273 if ((*errp
= netlink_dump_start(ctnl
, skb
, nlh
,
1274 ctnetlink_exp_dump_table
,
1275 ctnetlink_done
)) != 0)
1277 rlen
= NLMSG_ALIGN(nlh
->nlmsg_len
);
1278 if (rlen
> skb
->len
)
1280 skb_pull(skb
, rlen
);
1284 if (cda
[CTA_EXPECT_MASTER
-1])
1285 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_MASTER
);
1292 exp
= ip_conntrack_expect_find(&tuple
);
1296 if (cda
[CTA_EXPECT_ID
-1]) {
1297 u_int32_t id
= *(u_int32_t
*)NFA_DATA(cda
[CTA_EXPECT_ID
-1]);
1298 if (exp
->id
!= ntohl(id
)) {
1299 ip_conntrack_expect_put(exp
);
1305 skb2
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
1308 NETLINK_CB(skb2
).dst_pid
= NETLINK_CB(skb
).pid
;
1310 err
= ctnetlink_exp_fill_info(skb2
, NETLINK_CB(skb
).pid
,
1311 nlh
->nlmsg_seq
, IPCTNL_MSG_EXP_NEW
,
1316 ip_conntrack_expect_put(exp
);
1318 return netlink_unicast(ctnl
, skb2
, NETLINK_CB(skb
).pid
, MSG_DONTWAIT
);
1323 ip_conntrack_expect_put(exp
);
1328 ctnetlink_del_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
1329 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
1331 struct ip_conntrack_expect
*exp
, *tmp
;
1332 struct ip_conntrack_tuple tuple
;
1333 struct ip_conntrack_helper
*h
;
1336 if (cda
[CTA_EXPECT_TUPLE
-1]) {
1337 /* delete a single expect by tuple */
1338 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
);
1342 /* bump usage count to 2 */
1343 exp
= ip_conntrack_expect_find(&tuple
);
1347 if (cda
[CTA_EXPECT_ID
-1]) {
1349 *(u_int32_t
*)NFA_DATA(cda
[CTA_EXPECT_ID
-1]);
1350 if (exp
->id
!= ntohl(id
)) {
1351 ip_conntrack_expect_put(exp
);
1356 /* after list removal, usage count == 1 */
1357 ip_conntrack_unexpect_related(exp
);
1358 /* have to put what we 'get' above.
1359 * after this line usage count == 0 */
1360 ip_conntrack_expect_put(exp
);
1361 } else if (cda
[CTA_EXPECT_HELP_NAME
-1]) {
1362 char *name
= NFA_DATA(cda
[CTA_EXPECT_HELP_NAME
-1]);
1364 /* delete all expectations for this helper */
1365 write_lock_bh(&ip_conntrack_lock
);
1366 h
= __ip_conntrack_helper_find_byname(name
);
1368 write_unlock_bh(&ip_conntrack_lock
);
1371 list_for_each_entry_safe(exp
, tmp
, &ip_conntrack_expect_list
,
1373 if (exp
->master
->helper
== h
1374 && del_timer(&exp
->timeout
)) {
1375 ip_ct_unlink_expect(exp
);
1376 ip_conntrack_expect_put(exp
);
1379 write_unlock(&ip_conntrack_lock
);
1381 /* This basically means we have to flush everything*/
1382 write_lock_bh(&ip_conntrack_lock
);
1383 list_for_each_entry_safe(exp
, tmp
, &ip_conntrack_expect_list
,
1385 if (del_timer(&exp
->timeout
)) {
1386 ip_ct_unlink_expect(exp
);
1387 ip_conntrack_expect_put(exp
);
1390 write_unlock_bh(&ip_conntrack_lock
);
1396 ctnetlink_change_expect(struct ip_conntrack_expect
*x
, struct nfattr
*cda
[])
1402 ctnetlink_create_expect(struct nfattr
*cda
[])
1404 struct ip_conntrack_tuple tuple
, mask
, master_tuple
;
1405 struct ip_conntrack_tuple_hash
*h
= NULL
;
1406 struct ip_conntrack_expect
*exp
;
1407 struct ip_conntrack
*ct
;
1410 DEBUGP("entered %s\n", __FUNCTION__
);
1412 /* caller guarantees that those three CTA_EXPECT_* exist */
1413 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
);
1416 err
= ctnetlink_parse_tuple(cda
, &mask
, CTA_EXPECT_MASK
);
1419 err
= ctnetlink_parse_tuple(cda
, &master_tuple
, CTA_EXPECT_MASTER
);
1423 /* Look for master conntrack of this expectation */
1424 h
= ip_conntrack_find_get(&master_tuple
, NULL
);
1427 ct
= tuplehash_to_ctrack(h
);
1430 /* such conntrack hasn't got any helper, abort */
1435 exp
= ip_conntrack_expect_alloc(ct
);
1441 exp
->expectfn
= NULL
;
1444 memcpy(&exp
->tuple
, &tuple
, sizeof(struct ip_conntrack_tuple
));
1445 memcpy(&exp
->mask
, &mask
, sizeof(struct ip_conntrack_tuple
));
1447 err
= ip_conntrack_expect_related(exp
);
1448 ip_conntrack_expect_put(exp
);
1451 ip_conntrack_put(tuplehash_to_ctrack(h
));
1456 ctnetlink_new_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
1457 struct nlmsghdr
*nlh
, struct nfattr
*cda
[], int *errp
)
1459 struct ip_conntrack_tuple tuple
;
1460 struct ip_conntrack_expect
*exp
;
1463 DEBUGP("entered %s\n", __FUNCTION__
);
1465 if (!cda
[CTA_EXPECT_TUPLE
-1]
1466 || !cda
[CTA_EXPECT_MASK
-1]
1467 || !cda
[CTA_EXPECT_MASTER
-1])
1470 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
);
1474 write_lock_bh(&ip_conntrack_lock
);
1475 exp
= __ip_conntrack_expect_find(&tuple
);
1478 write_unlock_bh(&ip_conntrack_lock
);
1480 if (nlh
->nlmsg_flags
& NLM_F_CREATE
)
1481 err
= ctnetlink_create_expect(cda
);
1486 if (!(nlh
->nlmsg_flags
& NLM_F_EXCL
))
1487 err
= ctnetlink_change_expect(exp
, cda
);
1488 write_unlock_bh(&ip_conntrack_lock
);
1490 DEBUGP("leaving\n");
1495 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1496 static struct notifier_block ctnl_notifier
= {
1497 .notifier_call
= ctnetlink_conntrack_event
,
1500 static struct notifier_block ctnl_notifier_exp
= {
1501 .notifier_call
= ctnetlink_expect_event
,
1505 static struct nfnl_callback ctnl_cb
[IPCTNL_MSG_MAX
] = {
1506 [IPCTNL_MSG_CT_NEW
] = { .call
= ctnetlink_new_conntrack
,
1507 .attr_count
= CTA_MAX
,
1508 .cap_required
= CAP_NET_ADMIN
},
1509 [IPCTNL_MSG_CT_GET
] = { .call
= ctnetlink_get_conntrack
,
1510 .attr_count
= CTA_MAX
,
1511 .cap_required
= CAP_NET_ADMIN
},
1512 [IPCTNL_MSG_CT_DELETE
] = { .call
= ctnetlink_del_conntrack
,
1513 .attr_count
= CTA_MAX
,
1514 .cap_required
= CAP_NET_ADMIN
},
1515 [IPCTNL_MSG_CT_GET_CTRZERO
] = { .call
= ctnetlink_get_conntrack
,
1516 .attr_count
= CTA_MAX
,
1517 .cap_required
= CAP_NET_ADMIN
},
1520 static struct nfnl_callback ctnl_exp_cb
[IPCTNL_MSG_EXP_MAX
] = {
1521 [IPCTNL_MSG_EXP_GET
] = { .call
= ctnetlink_get_expect
,
1522 .attr_count
= CTA_EXPECT_MAX
,
1523 .cap_required
= CAP_NET_ADMIN
},
1524 [IPCTNL_MSG_EXP_NEW
] = { .call
= ctnetlink_new_expect
,
1525 .attr_count
= CTA_EXPECT_MAX
,
1526 .cap_required
= CAP_NET_ADMIN
},
1527 [IPCTNL_MSG_EXP_DELETE
] = { .call
= ctnetlink_del_expect
,
1528 .attr_count
= CTA_EXPECT_MAX
,
1529 .cap_required
= CAP_NET_ADMIN
},
1532 static struct nfnetlink_subsystem ctnl_subsys
= {
1533 .name
= "conntrack",
1534 .subsys_id
= NFNL_SUBSYS_CTNETLINK
,
1535 .cb_count
= IPCTNL_MSG_MAX
,
1539 static struct nfnetlink_subsystem ctnl_exp_subsys
= {
1540 .name
= "conntrack_expect",
1541 .subsys_id
= NFNL_SUBSYS_CTNETLINK_EXP
,
1542 .cb_count
= IPCTNL_MSG_EXP_MAX
,
1546 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK
);
1548 static int __init
ctnetlink_init(void)
1552 printk("ctnetlink v%s: registering with nfnetlink.\n", version
);
1553 ret
= nfnetlink_subsys_register(&ctnl_subsys
);
1555 printk("ctnetlink_init: cannot register with nfnetlink.\n");
1559 ret
= nfnetlink_subsys_register(&ctnl_exp_subsys
);
1561 printk("ctnetlink_init: cannot register exp with nfnetlink.\n");
1562 goto err_unreg_subsys
;
1565 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1566 ret
= ip_conntrack_register_notifier(&ctnl_notifier
);
1568 printk("ctnetlink_init: cannot register notifier.\n");
1569 goto err_unreg_exp_subsys
;
1572 ret
= ip_conntrack_expect_register_notifier(&ctnl_notifier_exp
);
1574 printk("ctnetlink_init: cannot expect register notifier.\n");
1575 goto err_unreg_notifier
;
1581 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1583 ip_conntrack_unregister_notifier(&ctnl_notifier
);
1584 err_unreg_exp_subsys
:
1585 nfnetlink_subsys_unregister(&ctnl_exp_subsys
);
1588 nfnetlink_subsys_unregister(&ctnl_subsys
);
1593 static void __exit
ctnetlink_exit(void)
1595 printk("ctnetlink: unregistering from nfnetlink.\n");
1597 #ifdef CONFIG_IP_NF_CONNTRACK_EVENTS
1598 ip_conntrack_unregister_notifier(&ctnl_notifier_exp
);
1599 ip_conntrack_unregister_notifier(&ctnl_notifier
);
1602 nfnetlink_subsys_unregister(&ctnl_exp_subsys
);
1603 nfnetlink_subsys_unregister(&ctnl_subsys
);
1607 module_init(ctnetlink_init
);
1608 module_exit(ctnetlink_exit
);