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-2011 by Pablo Neira Ayuso <pablo@netfilter.org>
9 * Initial connection tracking via netlink development funded and
10 * generally made possible by Network Robots, Inc. (www.networkrobots.com)
12 * Further development of this code funded by Astaro AG (http://www.astaro.com)
14 * This software may be used and distributed according to the terms
15 * of the GNU General Public License, incorporated herein by reference.
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/rculist.h>
22 #include <linux/rculist_nulls.h>
23 #include <linux/types.h>
24 #include <linux/timer.h>
25 #include <linux/security.h>
26 #include <linux/skbuff.h>
27 #include <linux/errno.h>
28 #include <linux/netlink.h>
29 #include <linux/spinlock.h>
30 #include <linux/interrupt.h>
31 #include <linux/slab.h>
33 #include <linux/netfilter.h>
34 #include <net/netlink.h>
36 #include <net/netfilter/nf_conntrack.h>
37 #include <net/netfilter/nf_conntrack_core.h>
38 #include <net/netfilter/nf_conntrack_expect.h>
39 #include <net/netfilter/nf_conntrack_helper.h>
40 #include <net/netfilter/nf_conntrack_l3proto.h>
41 #include <net/netfilter/nf_conntrack_l4proto.h>
42 #include <net/netfilter/nf_conntrack_tuple.h>
43 #include <net/netfilter/nf_conntrack_acct.h>
44 #include <net/netfilter/nf_conntrack_zones.h>
45 #include <net/netfilter/nf_conntrack_timestamp.h>
46 #ifdef CONFIG_NF_NAT_NEEDED
47 #include <net/netfilter/nf_nat_core.h>
48 #include <net/netfilter/nf_nat_protocol.h>
51 #include <linux/netfilter/nfnetlink.h>
52 #include <linux/netfilter/nfnetlink_conntrack.h>
54 MODULE_LICENSE("GPL");
56 static char __initdata version
[] = "0.93";
59 ctnetlink_dump_tuples_proto(struct sk_buff
*skb
,
60 const struct nf_conntrack_tuple
*tuple
,
61 struct nf_conntrack_l4proto
*l4proto
)
64 struct nlattr
*nest_parms
;
66 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_PROTO
| NLA_F_NESTED
);
69 NLA_PUT_U8(skb
, CTA_PROTO_NUM
, tuple
->dst
.protonum
);
71 if (likely(l4proto
->tuple_to_nlattr
))
72 ret
= l4proto
->tuple_to_nlattr(skb
, tuple
);
74 nla_nest_end(skb
, nest_parms
);
83 ctnetlink_dump_tuples_ip(struct sk_buff
*skb
,
84 const struct nf_conntrack_tuple
*tuple
,
85 struct nf_conntrack_l3proto
*l3proto
)
88 struct nlattr
*nest_parms
;
90 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_IP
| NLA_F_NESTED
);
94 if (likely(l3proto
->tuple_to_nlattr
))
95 ret
= l3proto
->tuple_to_nlattr(skb
, tuple
);
97 nla_nest_end(skb
, nest_parms
);
106 ctnetlink_dump_tuples(struct sk_buff
*skb
,
107 const struct nf_conntrack_tuple
*tuple
)
110 struct nf_conntrack_l3proto
*l3proto
;
111 struct nf_conntrack_l4proto
*l4proto
;
113 l3proto
= __nf_ct_l3proto_find(tuple
->src
.l3num
);
114 ret
= ctnetlink_dump_tuples_ip(skb
, tuple
, l3proto
);
116 if (unlikely(ret
< 0))
119 l4proto
= __nf_ct_l4proto_find(tuple
->src
.l3num
, tuple
->dst
.protonum
);
120 ret
= ctnetlink_dump_tuples_proto(skb
, tuple
, l4proto
);
126 ctnetlink_dump_status(struct sk_buff
*skb
, const struct nf_conn
*ct
)
128 NLA_PUT_BE32(skb
, CTA_STATUS
, htonl(ct
->status
));
136 ctnetlink_dump_timeout(struct sk_buff
*skb
, const struct nf_conn
*ct
)
138 long timeout
= (ct
->timeout
.expires
- jiffies
) / HZ
;
143 NLA_PUT_BE32(skb
, CTA_TIMEOUT
, htonl(timeout
));
151 ctnetlink_dump_protoinfo(struct sk_buff
*skb
, struct nf_conn
*ct
)
153 struct nf_conntrack_l4proto
*l4proto
;
154 struct nlattr
*nest_proto
;
157 l4proto
= __nf_ct_l4proto_find(nf_ct_l3num(ct
), nf_ct_protonum(ct
));
158 if (!l4proto
->to_nlattr
)
161 nest_proto
= nla_nest_start(skb
, CTA_PROTOINFO
| NLA_F_NESTED
);
163 goto nla_put_failure
;
165 ret
= l4proto
->to_nlattr(skb
, nest_proto
, ct
);
167 nla_nest_end(skb
, nest_proto
);
176 ctnetlink_dump_helpinfo(struct sk_buff
*skb
, const struct nf_conn
*ct
)
178 struct nlattr
*nest_helper
;
179 const struct nf_conn_help
*help
= nfct_help(ct
);
180 struct nf_conntrack_helper
*helper
;
185 helper
= rcu_dereference(help
->helper
);
189 nest_helper
= nla_nest_start(skb
, CTA_HELP
| NLA_F_NESTED
);
191 goto nla_put_failure
;
192 NLA_PUT_STRING(skb
, CTA_HELP_NAME
, helper
->name
);
194 if (helper
->to_nlattr
)
195 helper
->to_nlattr(skb
, ct
);
197 nla_nest_end(skb
, nest_helper
);
206 ctnetlink_dump_counters(struct sk_buff
*skb
, const struct nf_conn
*ct
,
207 enum ip_conntrack_dir dir
)
209 enum ctattr_type type
= dir
? CTA_COUNTERS_REPLY
: CTA_COUNTERS_ORIG
;
210 struct nlattr
*nest_count
;
211 const struct nf_conn_counter
*acct
;
213 acct
= nf_conn_acct_find(ct
);
217 nest_count
= nla_nest_start(skb
, type
| NLA_F_NESTED
);
219 goto nla_put_failure
;
221 NLA_PUT_BE64(skb
, CTA_COUNTERS_PACKETS
,
222 cpu_to_be64(atomic64_read(&acct
[dir
].packets
)));
223 NLA_PUT_BE64(skb
, CTA_COUNTERS_BYTES
,
224 cpu_to_be64(atomic64_read(&acct
[dir
].bytes
)));
226 nla_nest_end(skb
, nest_count
);
235 ctnetlink_dump_timestamp(struct sk_buff
*skb
, const struct nf_conn
*ct
)
237 struct nlattr
*nest_count
;
238 const struct nf_conn_tstamp
*tstamp
;
240 tstamp
= nf_conn_tstamp_find(ct
);
244 nest_count
= nla_nest_start(skb
, CTA_TIMESTAMP
| NLA_F_NESTED
);
246 goto nla_put_failure
;
248 NLA_PUT_BE64(skb
, CTA_TIMESTAMP_START
, cpu_to_be64(tstamp
->start
));
249 if (tstamp
->stop
!= 0) {
250 NLA_PUT_BE64(skb
, CTA_TIMESTAMP_STOP
,
251 cpu_to_be64(tstamp
->stop
));
253 nla_nest_end(skb
, nest_count
);
261 #ifdef CONFIG_NF_CONNTRACK_MARK
263 ctnetlink_dump_mark(struct sk_buff
*skb
, const struct nf_conn
*ct
)
265 NLA_PUT_BE32(skb
, CTA_MARK
, htonl(ct
->mark
));
272 #define ctnetlink_dump_mark(a, b) (0)
275 #ifdef CONFIG_NF_CONNTRACK_SECMARK
277 ctnetlink_dump_secctx(struct sk_buff
*skb
, const struct nf_conn
*ct
)
279 struct nlattr
*nest_secctx
;
283 ret
= security_secid_to_secctx(ct
->secmark
, &secctx
, &len
);
288 nest_secctx
= nla_nest_start(skb
, CTA_SECCTX
| NLA_F_NESTED
);
290 goto nla_put_failure
;
292 NLA_PUT_STRING(skb
, CTA_SECCTX_NAME
, secctx
);
293 nla_nest_end(skb
, nest_secctx
);
297 security_release_secctx(secctx
, len
);
301 #define ctnetlink_dump_secctx(a, b) (0)
304 #define master_tuple(ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
307 ctnetlink_dump_master(struct sk_buff
*skb
, const struct nf_conn
*ct
)
309 struct nlattr
*nest_parms
;
311 if (!(ct
->status
& IPS_EXPECTED
))
314 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_MASTER
| NLA_F_NESTED
);
316 goto nla_put_failure
;
317 if (ctnetlink_dump_tuples(skb
, master_tuple(ct
)) < 0)
318 goto nla_put_failure
;
319 nla_nest_end(skb
, nest_parms
);
327 #ifdef CONFIG_NF_NAT_NEEDED
329 dump_nat_seq_adj(struct sk_buff
*skb
, const struct nf_nat_seq
*natseq
, int type
)
331 struct nlattr
*nest_parms
;
333 nest_parms
= nla_nest_start(skb
, type
| NLA_F_NESTED
);
335 goto nla_put_failure
;
337 NLA_PUT_BE32(skb
, CTA_NAT_SEQ_CORRECTION_POS
,
338 htonl(natseq
->correction_pos
));
339 NLA_PUT_BE32(skb
, CTA_NAT_SEQ_OFFSET_BEFORE
,
340 htonl(natseq
->offset_before
));
341 NLA_PUT_BE32(skb
, CTA_NAT_SEQ_OFFSET_AFTER
,
342 htonl(natseq
->offset_after
));
344 nla_nest_end(skb
, nest_parms
);
353 ctnetlink_dump_nat_seq_adj(struct sk_buff
*skb
, const struct nf_conn
*ct
)
355 struct nf_nat_seq
*natseq
;
356 struct nf_conn_nat
*nat
= nfct_nat(ct
);
358 if (!(ct
->status
& IPS_SEQ_ADJUST
) || !nat
)
361 natseq
= &nat
->seq
[IP_CT_DIR_ORIGINAL
];
362 if (dump_nat_seq_adj(skb
, natseq
, CTA_NAT_SEQ_ADJ_ORIG
) == -1)
365 natseq
= &nat
->seq
[IP_CT_DIR_REPLY
];
366 if (dump_nat_seq_adj(skb
, natseq
, CTA_NAT_SEQ_ADJ_REPLY
) == -1)
372 #define ctnetlink_dump_nat_seq_adj(a, b) (0)
376 ctnetlink_dump_id(struct sk_buff
*skb
, const struct nf_conn
*ct
)
378 NLA_PUT_BE32(skb
, CTA_ID
, htonl((unsigned long)ct
));
386 ctnetlink_dump_use(struct sk_buff
*skb
, const struct nf_conn
*ct
)
388 NLA_PUT_BE32(skb
, CTA_USE
, htonl(atomic_read(&ct
->ct_general
.use
)));
396 ctnetlink_fill_info(struct sk_buff
*skb
, u32 pid
, u32 seq
,
397 int event
, struct nf_conn
*ct
)
399 struct nlmsghdr
*nlh
;
400 struct nfgenmsg
*nfmsg
;
401 struct nlattr
*nest_parms
;
402 unsigned int flags
= pid
? NLM_F_MULTI
: 0;
404 event
|= NFNL_SUBSYS_CTNETLINK
<< 8;
405 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*nfmsg
), flags
);
409 nfmsg
= nlmsg_data(nlh
);
410 nfmsg
->nfgen_family
= nf_ct_l3num(ct
);
411 nfmsg
->version
= NFNETLINK_V0
;
414 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_ORIG
| NLA_F_NESTED
);
416 goto nla_put_failure
;
417 if (ctnetlink_dump_tuples(skb
, nf_ct_tuple(ct
, IP_CT_DIR_ORIGINAL
)) < 0)
418 goto nla_put_failure
;
419 nla_nest_end(skb
, nest_parms
);
421 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_REPLY
| NLA_F_NESTED
);
423 goto nla_put_failure
;
424 if (ctnetlink_dump_tuples(skb
, nf_ct_tuple(ct
, IP_CT_DIR_REPLY
)) < 0)
425 goto nla_put_failure
;
426 nla_nest_end(skb
, nest_parms
);
429 NLA_PUT_BE16(skb
, CTA_ZONE
, htons(nf_ct_zone(ct
)));
431 if (ctnetlink_dump_status(skb
, ct
) < 0 ||
432 ctnetlink_dump_timeout(skb
, ct
) < 0 ||
433 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_ORIGINAL
) < 0 ||
434 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_REPLY
) < 0 ||
435 ctnetlink_dump_timestamp(skb
, ct
) < 0 ||
436 ctnetlink_dump_protoinfo(skb
, ct
) < 0 ||
437 ctnetlink_dump_helpinfo(skb
, ct
) < 0 ||
438 ctnetlink_dump_mark(skb
, ct
) < 0 ||
439 ctnetlink_dump_secctx(skb
, ct
) < 0 ||
440 ctnetlink_dump_id(skb
, ct
) < 0 ||
441 ctnetlink_dump_use(skb
, ct
) < 0 ||
442 ctnetlink_dump_master(skb
, ct
) < 0 ||
443 ctnetlink_dump_nat_seq_adj(skb
, ct
) < 0)
444 goto nla_put_failure
;
451 nlmsg_cancel(skb
, nlh
);
455 #ifdef CONFIG_NF_CONNTRACK_EVENTS
457 ctnetlink_proto_size(const struct nf_conn
*ct
)
459 struct nf_conntrack_l3proto
*l3proto
;
460 struct nf_conntrack_l4proto
*l4proto
;
464 l3proto
= __nf_ct_l3proto_find(nf_ct_l3num(ct
));
465 len
+= l3proto
->nla_size
;
467 l4proto
= __nf_ct_l4proto_find(nf_ct_l3num(ct
), nf_ct_protonum(ct
));
468 len
+= l4proto
->nla_size
;
475 ctnetlink_counters_size(const struct nf_conn
*ct
)
477 if (!nf_ct_ext_exist(ct
, NF_CT_EXT_ACCT
))
479 return 2 * nla_total_size(0) /* CTA_COUNTERS_ORIG|REPL */
480 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_PACKETS */
481 + 2 * nla_total_size(sizeof(uint64_t)) /* CTA_COUNTERS_BYTES */
486 ctnetlink_secctx_size(const struct nf_conn
*ct
)
488 #ifdef CONFIG_NF_CONNTRACK_SECMARK
491 ret
= security_secid_to_secctx(ct
->secmark
, NULL
, &len
);
495 return nla_total_size(0) /* CTA_SECCTX */
496 + nla_total_size(sizeof(char) * len
); /* CTA_SECCTX_NAME */
503 ctnetlink_timestamp_size(const struct nf_conn
*ct
)
505 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
506 if (!nf_ct_ext_exist(ct
, NF_CT_EXT_TSTAMP
))
508 return nla_total_size(0) + 2 * nla_total_size(sizeof(uint64_t));
515 ctnetlink_nlmsg_size(const struct nf_conn
*ct
)
517 return NLMSG_ALIGN(sizeof(struct nfgenmsg
))
518 + 3 * nla_total_size(0) /* CTA_TUPLE_ORIG|REPL|MASTER */
519 + 3 * nla_total_size(0) /* CTA_TUPLE_IP */
520 + 3 * nla_total_size(0) /* CTA_TUPLE_PROTO */
521 + 3 * nla_total_size(sizeof(u_int8_t
)) /* CTA_PROTO_NUM */
522 + nla_total_size(sizeof(u_int32_t
)) /* CTA_ID */
523 + nla_total_size(sizeof(u_int32_t
)) /* CTA_STATUS */
524 + ctnetlink_counters_size(ct
)
525 + ctnetlink_timestamp_size(ct
)
526 + nla_total_size(sizeof(u_int32_t
)) /* CTA_TIMEOUT */
527 + nla_total_size(0) /* CTA_PROTOINFO */
528 + nla_total_size(0) /* CTA_HELP */
529 + nla_total_size(NF_CT_HELPER_NAME_LEN
) /* CTA_HELP_NAME */
530 + ctnetlink_secctx_size(ct
)
531 #ifdef CONFIG_NF_NAT_NEEDED
532 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
533 + 6 * nla_total_size(sizeof(u_int32_t
)) /* CTA_NAT_SEQ_OFFSET */
535 #ifdef CONFIG_NF_CONNTRACK_MARK
536 + nla_total_size(sizeof(u_int32_t
)) /* CTA_MARK */
538 + ctnetlink_proto_size(ct
)
543 ctnetlink_conntrack_event(unsigned int events
, struct nf_ct_event
*item
)
546 struct nlmsghdr
*nlh
;
547 struct nfgenmsg
*nfmsg
;
548 struct nlattr
*nest_parms
;
549 struct nf_conn
*ct
= item
->ct
;
552 unsigned int flags
= 0, group
;
555 /* ignore our fake conntrack entry */
556 if (nf_ct_is_untracked(ct
))
559 if (events
& (1 << IPCT_DESTROY
)) {
560 type
= IPCTNL_MSG_CT_DELETE
;
561 group
= NFNLGRP_CONNTRACK_DESTROY
;
562 } else if (events
& ((1 << IPCT_NEW
) | (1 << IPCT_RELATED
))) {
563 type
= IPCTNL_MSG_CT_NEW
;
564 flags
= NLM_F_CREATE
|NLM_F_EXCL
;
565 group
= NFNLGRP_CONNTRACK_NEW
;
567 type
= IPCTNL_MSG_CT_NEW
;
568 group
= NFNLGRP_CONNTRACK_UPDATE
;
573 if (!item
->report
&& !nfnetlink_has_listeners(net
, group
))
576 skb
= nlmsg_new(ctnetlink_nlmsg_size(ct
), GFP_ATOMIC
);
580 type
|= NFNL_SUBSYS_CTNETLINK
<< 8;
581 nlh
= nlmsg_put(skb
, item
->pid
, 0, type
, sizeof(*nfmsg
), flags
);
585 nfmsg
= nlmsg_data(nlh
);
586 nfmsg
->nfgen_family
= nf_ct_l3num(ct
);
587 nfmsg
->version
= NFNETLINK_V0
;
591 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_ORIG
| NLA_F_NESTED
);
593 goto nla_put_failure
;
594 if (ctnetlink_dump_tuples(skb
, nf_ct_tuple(ct
, IP_CT_DIR_ORIGINAL
)) < 0)
595 goto nla_put_failure
;
596 nla_nest_end(skb
, nest_parms
);
598 nest_parms
= nla_nest_start(skb
, CTA_TUPLE_REPLY
| NLA_F_NESTED
);
600 goto nla_put_failure
;
601 if (ctnetlink_dump_tuples(skb
, nf_ct_tuple(ct
, IP_CT_DIR_REPLY
)) < 0)
602 goto nla_put_failure
;
603 nla_nest_end(skb
, nest_parms
);
606 NLA_PUT_BE16(skb
, CTA_ZONE
, htons(nf_ct_zone(ct
)));
608 if (ctnetlink_dump_id(skb
, ct
) < 0)
609 goto nla_put_failure
;
611 if (ctnetlink_dump_status(skb
, ct
) < 0)
612 goto nla_put_failure
;
614 if (events
& (1 << IPCT_DESTROY
)) {
615 if (ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_ORIGINAL
) < 0 ||
616 ctnetlink_dump_counters(skb
, ct
, IP_CT_DIR_REPLY
) < 0 ||
617 ctnetlink_dump_timestamp(skb
, ct
) < 0)
618 goto nla_put_failure
;
620 if (ctnetlink_dump_timeout(skb
, ct
) < 0)
621 goto nla_put_failure
;
623 if (events
& (1 << IPCT_PROTOINFO
)
624 && ctnetlink_dump_protoinfo(skb
, ct
) < 0)
625 goto nla_put_failure
;
627 if ((events
& (1 << IPCT_HELPER
) || nfct_help(ct
))
628 && ctnetlink_dump_helpinfo(skb
, ct
) < 0)
629 goto nla_put_failure
;
631 #ifdef CONFIG_NF_CONNTRACK_SECMARK
632 if ((events
& (1 << IPCT_SECMARK
) || ct
->secmark
)
633 && ctnetlink_dump_secctx(skb
, ct
) < 0)
634 goto nla_put_failure
;
637 if (events
& (1 << IPCT_RELATED
) &&
638 ctnetlink_dump_master(skb
, ct
) < 0)
639 goto nla_put_failure
;
641 if (events
& (1 << IPCT_NATSEQADJ
) &&
642 ctnetlink_dump_nat_seq_adj(skb
, ct
) < 0)
643 goto nla_put_failure
;
646 #ifdef CONFIG_NF_CONNTRACK_MARK
647 if ((events
& (1 << IPCT_MARK
) || ct
->mark
)
648 && ctnetlink_dump_mark(skb
, ct
) < 0)
649 goto nla_put_failure
;
654 err
= nfnetlink_send(skb
, net
, item
->pid
, group
, item
->report
,
656 if (err
== -ENOBUFS
|| err
== -EAGAIN
)
663 nlmsg_cancel(skb
, nlh
);
667 if (nfnetlink_set_err(net
, 0, group
, -ENOBUFS
) > 0)
672 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
674 static int ctnetlink_done(struct netlink_callback
*cb
)
677 nf_ct_put((struct nf_conn
*)cb
->args
[1]);
682 ctnetlink_dump_table(struct sk_buff
*skb
, struct netlink_callback
*cb
)
684 struct net
*net
= sock_net(skb
->sk
);
685 struct nf_conn
*ct
, *last
;
686 struct nf_conntrack_tuple_hash
*h
;
687 struct hlist_nulls_node
*n
;
688 struct nfgenmsg
*nfmsg
= nlmsg_data(cb
->nlh
);
689 u_int8_t l3proto
= nfmsg
->nfgen_family
;
691 spin_lock_bh(&nf_conntrack_lock
);
692 last
= (struct nf_conn
*)cb
->args
[1];
693 for (; cb
->args
[0] < net
->ct
.htable_size
; cb
->args
[0]++) {
695 hlist_nulls_for_each_entry(h
, n
, &net
->ct
.hash
[cb
->args
[0]],
697 if (NF_CT_DIRECTION(h
) != IP_CT_DIR_ORIGINAL
)
699 ct
= nf_ct_tuplehash_to_ctrack(h
);
700 /* Dump entries of a given L3 protocol number.
701 * If it is not specified, ie. l3proto == 0,
702 * then dump everything. */
703 if (l3proto
&& nf_ct_l3num(ct
) != l3proto
)
710 if (ctnetlink_fill_info(skb
, NETLINK_CB(cb
->skb
).pid
,
712 IPCTNL_MSG_CT_NEW
, ct
) < 0) {
713 nf_conntrack_get(&ct
->ct_general
);
714 cb
->args
[1] = (unsigned long)ct
;
718 if (NFNL_MSG_TYPE(cb
->nlh
->nlmsg_type
) ==
719 IPCTNL_MSG_CT_GET_CTRZERO
) {
720 struct nf_conn_counter
*acct
;
722 acct
= nf_conn_acct_find(ct
);
724 atomic64_set(&acct
[IP_CT_DIR_ORIGINAL
].bytes
, 0);
725 atomic64_set(&acct
[IP_CT_DIR_ORIGINAL
].packets
, 0);
726 atomic64_set(&acct
[IP_CT_DIR_REPLY
].bytes
, 0);
727 atomic64_set(&acct
[IP_CT_DIR_REPLY
].packets
, 0);
737 spin_unlock_bh(&nf_conntrack_lock
);
745 ctnetlink_parse_tuple_ip(struct nlattr
*attr
, struct nf_conntrack_tuple
*tuple
)
747 struct nlattr
*tb
[CTA_IP_MAX
+1];
748 struct nf_conntrack_l3proto
*l3proto
;
751 nla_parse_nested(tb
, CTA_IP_MAX
, attr
, NULL
);
754 l3proto
= __nf_ct_l3proto_find(tuple
->src
.l3num
);
756 if (likely(l3proto
->nlattr_to_tuple
)) {
757 ret
= nla_validate_nested(attr
, CTA_IP_MAX
,
758 l3proto
->nla_policy
);
760 ret
= l3proto
->nlattr_to_tuple(tb
, tuple
);
768 static const struct nla_policy proto_nla_policy
[CTA_PROTO_MAX
+1] = {
769 [CTA_PROTO_NUM
] = { .type
= NLA_U8
},
773 ctnetlink_parse_tuple_proto(struct nlattr
*attr
,
774 struct nf_conntrack_tuple
*tuple
)
776 struct nlattr
*tb
[CTA_PROTO_MAX
+1];
777 struct nf_conntrack_l4proto
*l4proto
;
780 ret
= nla_parse_nested(tb
, CTA_PROTO_MAX
, attr
, proto_nla_policy
);
784 if (!tb
[CTA_PROTO_NUM
])
786 tuple
->dst
.protonum
= nla_get_u8(tb
[CTA_PROTO_NUM
]);
789 l4proto
= __nf_ct_l4proto_find(tuple
->src
.l3num
, tuple
->dst
.protonum
);
791 if (likely(l4proto
->nlattr_to_tuple
)) {
792 ret
= nla_validate_nested(attr
, CTA_PROTO_MAX
,
793 l4proto
->nla_policy
);
795 ret
= l4proto
->nlattr_to_tuple(tb
, tuple
);
803 static const struct nla_policy tuple_nla_policy
[CTA_TUPLE_MAX
+1] = {
804 [CTA_TUPLE_IP
] = { .type
= NLA_NESTED
},
805 [CTA_TUPLE_PROTO
] = { .type
= NLA_NESTED
},
809 ctnetlink_parse_tuple(const struct nlattr
* const cda
[],
810 struct nf_conntrack_tuple
*tuple
,
811 enum ctattr_type type
, u_int8_t l3num
)
813 struct nlattr
*tb
[CTA_TUPLE_MAX
+1];
816 memset(tuple
, 0, sizeof(*tuple
));
818 nla_parse_nested(tb
, CTA_TUPLE_MAX
, cda
[type
], tuple_nla_policy
);
820 if (!tb
[CTA_TUPLE_IP
])
823 tuple
->src
.l3num
= l3num
;
825 err
= ctnetlink_parse_tuple_ip(tb
[CTA_TUPLE_IP
], tuple
);
829 if (!tb
[CTA_TUPLE_PROTO
])
832 err
= ctnetlink_parse_tuple_proto(tb
[CTA_TUPLE_PROTO
], tuple
);
836 /* orig and expect tuples get DIR_ORIGINAL */
837 if (type
== CTA_TUPLE_REPLY
)
838 tuple
->dst
.dir
= IP_CT_DIR_REPLY
;
840 tuple
->dst
.dir
= IP_CT_DIR_ORIGINAL
;
846 ctnetlink_parse_zone(const struct nlattr
*attr
, u16
*zone
)
849 #ifdef CONFIG_NF_CONNTRACK_ZONES
850 *zone
= ntohs(nla_get_be16(attr
));
860 static const struct nla_policy help_nla_policy
[CTA_HELP_MAX
+1] = {
861 [CTA_HELP_NAME
] = { .type
= NLA_NUL_STRING
},
865 ctnetlink_parse_help(const struct nlattr
*attr
, char **helper_name
)
867 struct nlattr
*tb
[CTA_HELP_MAX
+1];
869 nla_parse_nested(tb
, CTA_HELP_MAX
, attr
, help_nla_policy
);
871 if (!tb
[CTA_HELP_NAME
])
874 *helper_name
= nla_data(tb
[CTA_HELP_NAME
]);
879 static const struct nla_policy ct_nla_policy
[CTA_MAX
+1] = {
880 [CTA_TUPLE_ORIG
] = { .type
= NLA_NESTED
},
881 [CTA_TUPLE_REPLY
] = { .type
= NLA_NESTED
},
882 [CTA_STATUS
] = { .type
= NLA_U32
},
883 [CTA_PROTOINFO
] = { .type
= NLA_NESTED
},
884 [CTA_HELP
] = { .type
= NLA_NESTED
},
885 [CTA_NAT_SRC
] = { .type
= NLA_NESTED
},
886 [CTA_TIMEOUT
] = { .type
= NLA_U32
},
887 [CTA_MARK
] = { .type
= NLA_U32
},
888 [CTA_ID
] = { .type
= NLA_U32
},
889 [CTA_NAT_DST
] = { .type
= NLA_NESTED
},
890 [CTA_TUPLE_MASTER
] = { .type
= NLA_NESTED
},
891 [CTA_ZONE
] = { .type
= NLA_U16
},
895 ctnetlink_del_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
896 const struct nlmsghdr
*nlh
,
897 const struct nlattr
* const cda
[])
899 struct net
*net
= sock_net(ctnl
);
900 struct nf_conntrack_tuple_hash
*h
;
901 struct nf_conntrack_tuple tuple
;
903 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
904 u_int8_t u3
= nfmsg
->nfgen_family
;
908 err
= ctnetlink_parse_zone(cda
[CTA_ZONE
], &zone
);
912 if (cda
[CTA_TUPLE_ORIG
])
913 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_ORIG
, u3
);
914 else if (cda
[CTA_TUPLE_REPLY
])
915 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_REPLY
, u3
);
917 /* Flush the whole table */
918 nf_conntrack_flush_report(net
,
927 h
= nf_conntrack_find_get(net
, zone
, &tuple
);
931 ct
= nf_ct_tuplehash_to_ctrack(h
);
934 u_int32_t id
= ntohl(nla_get_be32(cda
[CTA_ID
]));
935 if (id
!= (u32
)(unsigned long)ct
) {
941 if (nf_conntrack_event_report(IPCT_DESTROY
, ct
,
943 nlmsg_report(nlh
)) < 0) {
944 nf_ct_delete_from_lists(ct
);
945 /* we failed to report the event, try later */
946 nf_ct_insert_dying_list(ct
);
951 /* death_by_timeout would report the event again */
952 set_bit(IPS_DYING_BIT
, &ct
->status
);
961 ctnetlink_get_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
962 const struct nlmsghdr
*nlh
,
963 const struct nlattr
* const cda
[])
965 struct net
*net
= sock_net(ctnl
);
966 struct nf_conntrack_tuple_hash
*h
;
967 struct nf_conntrack_tuple tuple
;
969 struct sk_buff
*skb2
= NULL
;
970 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
971 u_int8_t u3
= nfmsg
->nfgen_family
;
975 if (nlh
->nlmsg_flags
& NLM_F_DUMP
)
976 return netlink_dump_start(ctnl
, skb
, nlh
, ctnetlink_dump_table
,
979 err
= ctnetlink_parse_zone(cda
[CTA_ZONE
], &zone
);
983 if (cda
[CTA_TUPLE_ORIG
])
984 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_ORIG
, u3
);
985 else if (cda
[CTA_TUPLE_REPLY
])
986 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_TUPLE_REPLY
, u3
);
993 h
= nf_conntrack_find_get(net
, zone
, &tuple
);
997 ct
= nf_ct_tuplehash_to_ctrack(h
);
1000 skb2
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1007 err
= ctnetlink_fill_info(skb2
, NETLINK_CB(skb
).pid
, nlh
->nlmsg_seq
,
1008 IPCTNL_MSG_CT_NEW
, ct
);
1014 err
= netlink_unicast(ctnl
, skb2
, NETLINK_CB(skb
).pid
, MSG_DONTWAIT
);
1023 /* this avoids a loop in nfnetlink. */
1024 return err
== -EAGAIN
? -ENOBUFS
: err
;
1027 #ifdef CONFIG_NF_NAT_NEEDED
1029 ctnetlink_parse_nat_setup(struct nf_conn
*ct
,
1030 enum nf_nat_manip_type manip
,
1031 const struct nlattr
*attr
)
1033 typeof(nfnetlink_parse_nat_setup_hook
) parse_nat_setup
;
1035 parse_nat_setup
= rcu_dereference(nfnetlink_parse_nat_setup_hook
);
1036 if (!parse_nat_setup
) {
1037 #ifdef CONFIG_MODULES
1039 spin_unlock_bh(&nf_conntrack_lock
);
1041 if (request_module("nf-nat-ipv4") < 0) {
1043 spin_lock_bh(&nf_conntrack_lock
);
1048 spin_lock_bh(&nf_conntrack_lock
);
1050 if (nfnetlink_parse_nat_setup_hook
)
1056 return parse_nat_setup(ct
, manip
, attr
);
1061 ctnetlink_change_status(struct nf_conn
*ct
, const struct nlattr
* const cda
[])
1064 unsigned int status
= ntohl(nla_get_be32(cda
[CTA_STATUS
]));
1065 d
= ct
->status
^ status
;
1067 if (d
& (IPS_EXPECTED
|IPS_CONFIRMED
|IPS_DYING
))
1071 if (d
& IPS_SEEN_REPLY
&& !(status
& IPS_SEEN_REPLY
))
1072 /* SEEN_REPLY bit can only be set */
1075 if (d
& IPS_ASSURED
&& !(status
& IPS_ASSURED
))
1076 /* ASSURED bit can only be set */
1079 /* Be careful here, modifying NAT bits can screw up things,
1080 * so don't let users modify them directly if they don't pass
1082 ct
->status
|= status
& ~(IPS_NAT_DONE_MASK
| IPS_NAT_MASK
);
1087 ctnetlink_change_nat(struct nf_conn
*ct
, const struct nlattr
* const cda
[])
1089 #ifdef CONFIG_NF_NAT_NEEDED
1092 if (cda
[CTA_NAT_DST
]) {
1093 ret
= ctnetlink_parse_nat_setup(ct
,
1099 if (cda
[CTA_NAT_SRC
]) {
1100 ret
= ctnetlink_parse_nat_setup(ct
,
1113 ctnetlink_change_helper(struct nf_conn
*ct
, const struct nlattr
* const cda
[])
1115 struct nf_conntrack_helper
*helper
;
1116 struct nf_conn_help
*help
= nfct_help(ct
);
1117 char *helpname
= NULL
;
1120 /* don't change helper of sibling connections */
1124 err
= ctnetlink_parse_help(cda
[CTA_HELP
], &helpname
);
1128 if (!strcmp(helpname
, "")) {
1129 if (help
&& help
->helper
) {
1130 /* we had a helper before ... */
1131 nf_ct_remove_expectations(ct
);
1132 RCU_INIT_POINTER(help
->helper
, NULL
);
1138 helper
= __nf_conntrack_helper_find(helpname
, nf_ct_l3num(ct
),
1139 nf_ct_protonum(ct
));
1140 if (helper
== NULL
) {
1141 #ifdef CONFIG_MODULES
1142 spin_unlock_bh(&nf_conntrack_lock
);
1144 if (request_module("nfct-helper-%s", helpname
) < 0) {
1145 spin_lock_bh(&nf_conntrack_lock
);
1149 spin_lock_bh(&nf_conntrack_lock
);
1150 helper
= __nf_conntrack_helper_find(helpname
, nf_ct_l3num(ct
),
1151 nf_ct_protonum(ct
));
1159 if (help
->helper
== helper
)
1163 /* need to zero data of old helper */
1164 memset(&help
->help
, 0, sizeof(help
->help
));
1166 /* we cannot set a helper for an existing conntrack */
1170 RCU_INIT_POINTER(help
->helper
, helper
);
1176 ctnetlink_change_timeout(struct nf_conn
*ct
, const struct nlattr
* const cda
[])
1178 u_int32_t timeout
= ntohl(nla_get_be32(cda
[CTA_TIMEOUT
]));
1180 if (!del_timer(&ct
->timeout
))
1183 ct
->timeout
.expires
= jiffies
+ timeout
* HZ
;
1184 add_timer(&ct
->timeout
);
1189 static const struct nla_policy protoinfo_policy
[CTA_PROTOINFO_MAX
+1] = {
1190 [CTA_PROTOINFO_TCP
] = { .type
= NLA_NESTED
},
1191 [CTA_PROTOINFO_DCCP
] = { .type
= NLA_NESTED
},
1192 [CTA_PROTOINFO_SCTP
] = { .type
= NLA_NESTED
},
1196 ctnetlink_change_protoinfo(struct nf_conn
*ct
, const struct nlattr
* const cda
[])
1198 const struct nlattr
*attr
= cda
[CTA_PROTOINFO
];
1199 struct nlattr
*tb
[CTA_PROTOINFO_MAX
+1];
1200 struct nf_conntrack_l4proto
*l4proto
;
1203 nla_parse_nested(tb
, CTA_PROTOINFO_MAX
, attr
, protoinfo_policy
);
1206 l4proto
= __nf_ct_l4proto_find(nf_ct_l3num(ct
), nf_ct_protonum(ct
));
1207 if (l4proto
->from_nlattr
)
1208 err
= l4proto
->from_nlattr(tb
, ct
);
1214 #ifdef CONFIG_NF_NAT_NEEDED
1215 static const struct nla_policy nat_seq_policy
[CTA_NAT_SEQ_MAX
+1] = {
1216 [CTA_NAT_SEQ_CORRECTION_POS
] = { .type
= NLA_U32
},
1217 [CTA_NAT_SEQ_OFFSET_BEFORE
] = { .type
= NLA_U32
},
1218 [CTA_NAT_SEQ_OFFSET_AFTER
] = { .type
= NLA_U32
},
1222 change_nat_seq_adj(struct nf_nat_seq
*natseq
, const struct nlattr
* const attr
)
1224 struct nlattr
*cda
[CTA_NAT_SEQ_MAX
+1];
1226 nla_parse_nested(cda
, CTA_NAT_SEQ_MAX
, attr
, nat_seq_policy
);
1228 if (!cda
[CTA_NAT_SEQ_CORRECTION_POS
])
1231 natseq
->correction_pos
=
1232 ntohl(nla_get_be32(cda
[CTA_NAT_SEQ_CORRECTION_POS
]));
1234 if (!cda
[CTA_NAT_SEQ_OFFSET_BEFORE
])
1237 natseq
->offset_before
=
1238 ntohl(nla_get_be32(cda
[CTA_NAT_SEQ_OFFSET_BEFORE
]));
1240 if (!cda
[CTA_NAT_SEQ_OFFSET_AFTER
])
1243 natseq
->offset_after
=
1244 ntohl(nla_get_be32(cda
[CTA_NAT_SEQ_OFFSET_AFTER
]));
1250 ctnetlink_change_nat_seq_adj(struct nf_conn
*ct
,
1251 const struct nlattr
* const cda
[])
1254 struct nf_conn_nat
*nat
= nfct_nat(ct
);
1259 if (cda
[CTA_NAT_SEQ_ADJ_ORIG
]) {
1260 ret
= change_nat_seq_adj(&nat
->seq
[IP_CT_DIR_ORIGINAL
],
1261 cda
[CTA_NAT_SEQ_ADJ_ORIG
]);
1265 ct
->status
|= IPS_SEQ_ADJUST
;
1268 if (cda
[CTA_NAT_SEQ_ADJ_REPLY
]) {
1269 ret
= change_nat_seq_adj(&nat
->seq
[IP_CT_DIR_REPLY
],
1270 cda
[CTA_NAT_SEQ_ADJ_REPLY
]);
1274 ct
->status
|= IPS_SEQ_ADJUST
;
1282 ctnetlink_change_conntrack(struct nf_conn
*ct
,
1283 const struct nlattr
* const cda
[])
1287 /* only allow NAT changes and master assignation for new conntracks */
1288 if (cda
[CTA_NAT_SRC
] || cda
[CTA_NAT_DST
] || cda
[CTA_TUPLE_MASTER
])
1291 if (cda
[CTA_HELP
]) {
1292 err
= ctnetlink_change_helper(ct
, cda
);
1297 if (cda
[CTA_TIMEOUT
]) {
1298 err
= ctnetlink_change_timeout(ct
, cda
);
1303 if (cda
[CTA_STATUS
]) {
1304 err
= ctnetlink_change_status(ct
, cda
);
1309 if (cda
[CTA_PROTOINFO
]) {
1310 err
= ctnetlink_change_protoinfo(ct
, cda
);
1315 #if defined(CONFIG_NF_CONNTRACK_MARK)
1317 ct
->mark
= ntohl(nla_get_be32(cda
[CTA_MARK
]));
1320 #ifdef CONFIG_NF_NAT_NEEDED
1321 if (cda
[CTA_NAT_SEQ_ADJ_ORIG
] || cda
[CTA_NAT_SEQ_ADJ_REPLY
]) {
1322 err
= ctnetlink_change_nat_seq_adj(ct
, cda
);
1331 static struct nf_conn
*
1332 ctnetlink_create_conntrack(struct net
*net
, u16 zone
,
1333 const struct nlattr
* const cda
[],
1334 struct nf_conntrack_tuple
*otuple
,
1335 struct nf_conntrack_tuple
*rtuple
,
1340 struct nf_conntrack_helper
*helper
;
1341 struct nf_conn_tstamp
*tstamp
;
1343 ct
= nf_conntrack_alloc(net
, zone
, otuple
, rtuple
, GFP_ATOMIC
);
1345 return ERR_PTR(-ENOMEM
);
1347 if (!cda
[CTA_TIMEOUT
])
1349 ct
->timeout
.expires
= ntohl(nla_get_be32(cda
[CTA_TIMEOUT
]));
1351 ct
->timeout
.expires
= jiffies
+ ct
->timeout
.expires
* HZ
;
1354 if (cda
[CTA_HELP
]) {
1355 char *helpname
= NULL
;
1357 err
= ctnetlink_parse_help(cda
[CTA_HELP
], &helpname
);
1361 helper
= __nf_conntrack_helper_find(helpname
, nf_ct_l3num(ct
),
1362 nf_ct_protonum(ct
));
1363 if (helper
== NULL
) {
1365 #ifdef CONFIG_MODULES
1366 if (request_module("nfct-helper-%s", helpname
) < 0) {
1372 helper
= __nf_conntrack_helper_find(helpname
,
1374 nf_ct_protonum(ct
));
1384 struct nf_conn_help
*help
;
1386 help
= nf_ct_helper_ext_add(ct
, GFP_ATOMIC
);
1392 /* not in hash table yet so not strictly necessary */
1393 RCU_INIT_POINTER(help
->helper
, helper
);
1396 /* try an implicit helper assignation */
1397 err
= __nf_ct_try_assign_helper(ct
, NULL
, GFP_ATOMIC
);
1402 if (cda
[CTA_NAT_SRC
] || cda
[CTA_NAT_DST
]) {
1403 err
= ctnetlink_change_nat(ct
, cda
);
1408 nf_ct_acct_ext_add(ct
, GFP_ATOMIC
);
1409 nf_ct_tstamp_ext_add(ct
, GFP_ATOMIC
);
1410 nf_ct_ecache_ext_add(ct
, 0, 0, GFP_ATOMIC
);
1411 /* we must add conntrack extensions before confirmation. */
1412 ct
->status
|= IPS_CONFIRMED
;
1414 if (cda
[CTA_STATUS
]) {
1415 err
= ctnetlink_change_status(ct
, cda
);
1420 #ifdef CONFIG_NF_NAT_NEEDED
1421 if (cda
[CTA_NAT_SEQ_ADJ_ORIG
] || cda
[CTA_NAT_SEQ_ADJ_REPLY
]) {
1422 err
= ctnetlink_change_nat_seq_adj(ct
, cda
);
1428 memset(&ct
->proto
, 0, sizeof(ct
->proto
));
1429 if (cda
[CTA_PROTOINFO
]) {
1430 err
= ctnetlink_change_protoinfo(ct
, cda
);
1435 #if defined(CONFIG_NF_CONNTRACK_MARK)
1437 ct
->mark
= ntohl(nla_get_be32(cda
[CTA_MARK
]));
1440 /* setup master conntrack: this is a confirmed expectation */
1441 if (cda
[CTA_TUPLE_MASTER
]) {
1442 struct nf_conntrack_tuple master
;
1443 struct nf_conntrack_tuple_hash
*master_h
;
1444 struct nf_conn
*master_ct
;
1446 err
= ctnetlink_parse_tuple(cda
, &master
, CTA_TUPLE_MASTER
, u3
);
1450 master_h
= nf_conntrack_find_get(net
, zone
, &master
);
1451 if (master_h
== NULL
) {
1455 master_ct
= nf_ct_tuplehash_to_ctrack(master_h
);
1456 __set_bit(IPS_EXPECTED_BIT
, &ct
->status
);
1457 ct
->master
= master_ct
;
1459 tstamp
= nf_conn_tstamp_find(ct
);
1461 tstamp
->start
= ktime_to_ns(ktime_get_real());
1463 add_timer(&ct
->timeout
);
1464 nf_conntrack_hash_insert(ct
);
1472 nf_conntrack_free(ct
);
1473 return ERR_PTR(err
);
1477 ctnetlink_new_conntrack(struct sock
*ctnl
, struct sk_buff
*skb
,
1478 const struct nlmsghdr
*nlh
,
1479 const struct nlattr
* const cda
[])
1481 struct net
*net
= sock_net(ctnl
);
1482 struct nf_conntrack_tuple otuple
, rtuple
;
1483 struct nf_conntrack_tuple_hash
*h
= NULL
;
1484 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
1485 u_int8_t u3
= nfmsg
->nfgen_family
;
1489 err
= ctnetlink_parse_zone(cda
[CTA_ZONE
], &zone
);
1493 if (cda
[CTA_TUPLE_ORIG
]) {
1494 err
= ctnetlink_parse_tuple(cda
, &otuple
, CTA_TUPLE_ORIG
, u3
);
1499 if (cda
[CTA_TUPLE_REPLY
]) {
1500 err
= ctnetlink_parse_tuple(cda
, &rtuple
, CTA_TUPLE_REPLY
, u3
);
1505 spin_lock_bh(&nf_conntrack_lock
);
1506 if (cda
[CTA_TUPLE_ORIG
])
1507 h
= __nf_conntrack_find(net
, zone
, &otuple
);
1508 else if (cda
[CTA_TUPLE_REPLY
])
1509 h
= __nf_conntrack_find(net
, zone
, &rtuple
);
1513 if (nlh
->nlmsg_flags
& NLM_F_CREATE
) {
1515 enum ip_conntrack_events events
;
1517 ct
= ctnetlink_create_conntrack(net
, zone
, cda
, &otuple
,
1524 nf_conntrack_get(&ct
->ct_general
);
1525 spin_unlock_bh(&nf_conntrack_lock
);
1526 if (test_bit(IPS_EXPECTED_BIT
, &ct
->status
))
1527 events
= IPCT_RELATED
;
1531 nf_conntrack_eventmask_report((1 << IPCT_REPLY
) |
1532 (1 << IPCT_ASSURED
) |
1533 (1 << IPCT_HELPER
) |
1534 (1 << IPCT_PROTOINFO
) |
1535 (1 << IPCT_NATSEQADJ
) |
1536 (1 << IPCT_MARK
) | events
,
1537 ct
, NETLINK_CB(skb
).pid
,
1541 spin_unlock_bh(&nf_conntrack_lock
);
1545 /* implicit 'else' */
1547 /* We manipulate the conntrack inside the global conntrack table lock,
1548 * so there's no need to increase the refcount */
1550 if (!(nlh
->nlmsg_flags
& NLM_F_EXCL
)) {
1551 struct nf_conn
*ct
= nf_ct_tuplehash_to_ctrack(h
);
1553 err
= ctnetlink_change_conntrack(ct
, cda
);
1555 nf_conntrack_get(&ct
->ct_general
);
1556 spin_unlock_bh(&nf_conntrack_lock
);
1557 nf_conntrack_eventmask_report((1 << IPCT_REPLY
) |
1558 (1 << IPCT_ASSURED
) |
1559 (1 << IPCT_HELPER
) |
1560 (1 << IPCT_PROTOINFO
) |
1561 (1 << IPCT_NATSEQADJ
) |
1563 ct
, NETLINK_CB(skb
).pid
,
1567 spin_unlock_bh(&nf_conntrack_lock
);
1573 spin_unlock_bh(&nf_conntrack_lock
);
1577 /***********************************************************************
1579 ***********************************************************************/
1582 ctnetlink_exp_dump_tuple(struct sk_buff
*skb
,
1583 const struct nf_conntrack_tuple
*tuple
,
1584 enum ctattr_expect type
)
1586 struct nlattr
*nest_parms
;
1588 nest_parms
= nla_nest_start(skb
, type
| NLA_F_NESTED
);
1590 goto nla_put_failure
;
1591 if (ctnetlink_dump_tuples(skb
, tuple
) < 0)
1592 goto nla_put_failure
;
1593 nla_nest_end(skb
, nest_parms
);
1602 ctnetlink_exp_dump_mask(struct sk_buff
*skb
,
1603 const struct nf_conntrack_tuple
*tuple
,
1604 const struct nf_conntrack_tuple_mask
*mask
)
1607 struct nf_conntrack_l3proto
*l3proto
;
1608 struct nf_conntrack_l4proto
*l4proto
;
1609 struct nf_conntrack_tuple m
;
1610 struct nlattr
*nest_parms
;
1612 memset(&m
, 0xFF, sizeof(m
));
1613 memcpy(&m
.src
.u3
, &mask
->src
.u3
, sizeof(m
.src
.u3
));
1614 m
.src
.u
.all
= mask
->src
.u
.all
;
1615 m
.dst
.protonum
= tuple
->dst
.protonum
;
1617 nest_parms
= nla_nest_start(skb
, CTA_EXPECT_MASK
| NLA_F_NESTED
);
1619 goto nla_put_failure
;
1621 l3proto
= __nf_ct_l3proto_find(tuple
->src
.l3num
);
1622 ret
= ctnetlink_dump_tuples_ip(skb
, &m
, l3proto
);
1624 if (unlikely(ret
< 0))
1625 goto nla_put_failure
;
1627 l4proto
= __nf_ct_l4proto_find(tuple
->src
.l3num
, tuple
->dst
.protonum
);
1628 ret
= ctnetlink_dump_tuples_proto(skb
, &m
, l4proto
);
1629 if (unlikely(ret
< 0))
1630 goto nla_put_failure
;
1632 nla_nest_end(skb
, nest_parms
);
1641 ctnetlink_exp_dump_expect(struct sk_buff
*skb
,
1642 const struct nf_conntrack_expect
*exp
)
1644 struct nf_conn
*master
= exp
->master
;
1645 long timeout
= (exp
->timeout
.expires
- jiffies
) / HZ
;
1646 struct nf_conn_help
*help
;
1651 if (ctnetlink_exp_dump_tuple(skb
, &exp
->tuple
, CTA_EXPECT_TUPLE
) < 0)
1652 goto nla_put_failure
;
1653 if (ctnetlink_exp_dump_mask(skb
, &exp
->tuple
, &exp
->mask
) < 0)
1654 goto nla_put_failure
;
1655 if (ctnetlink_exp_dump_tuple(skb
,
1656 &master
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
,
1657 CTA_EXPECT_MASTER
) < 0)
1658 goto nla_put_failure
;
1660 NLA_PUT_BE32(skb
, CTA_EXPECT_TIMEOUT
, htonl(timeout
));
1661 NLA_PUT_BE32(skb
, CTA_EXPECT_ID
, htonl((unsigned long)exp
));
1662 NLA_PUT_BE32(skb
, CTA_EXPECT_FLAGS
, htonl(exp
->flags
));
1663 help
= nfct_help(master
);
1665 struct nf_conntrack_helper
*helper
;
1667 helper
= rcu_dereference(help
->helper
);
1669 NLA_PUT_STRING(skb
, CTA_EXPECT_HELP_NAME
, helper
->name
);
1679 ctnetlink_exp_fill_info(struct sk_buff
*skb
, u32 pid
, u32 seq
,
1680 int event
, const struct nf_conntrack_expect
*exp
)
1682 struct nlmsghdr
*nlh
;
1683 struct nfgenmsg
*nfmsg
;
1684 unsigned int flags
= pid
? NLM_F_MULTI
: 0;
1686 event
|= NFNL_SUBSYS_CTNETLINK_EXP
<< 8;
1687 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*nfmsg
), flags
);
1691 nfmsg
= nlmsg_data(nlh
);
1692 nfmsg
->nfgen_family
= exp
->tuple
.src
.l3num
;
1693 nfmsg
->version
= NFNETLINK_V0
;
1696 if (ctnetlink_exp_dump_expect(skb
, exp
) < 0)
1697 goto nla_put_failure
;
1699 nlmsg_end(skb
, nlh
);
1704 nlmsg_cancel(skb
, nlh
);
1708 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1710 ctnetlink_expect_event(unsigned int events
, struct nf_exp_event
*item
)
1712 struct nf_conntrack_expect
*exp
= item
->exp
;
1713 struct net
*net
= nf_ct_exp_net(exp
);
1714 struct nlmsghdr
*nlh
;
1715 struct nfgenmsg
*nfmsg
;
1716 struct sk_buff
*skb
;
1717 unsigned int type
, group
;
1720 if (events
& (1 << IPEXP_DESTROY
)) {
1721 type
= IPCTNL_MSG_EXP_DELETE
;
1722 group
= NFNLGRP_CONNTRACK_EXP_DESTROY
;
1723 } else if (events
& (1 << IPEXP_NEW
)) {
1724 type
= IPCTNL_MSG_EXP_NEW
;
1725 flags
= NLM_F_CREATE
|NLM_F_EXCL
;
1726 group
= NFNLGRP_CONNTRACK_EXP_NEW
;
1730 if (!item
->report
&& !nfnetlink_has_listeners(net
, group
))
1733 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
1737 type
|= NFNL_SUBSYS_CTNETLINK_EXP
<< 8;
1738 nlh
= nlmsg_put(skb
, item
->pid
, 0, type
, sizeof(*nfmsg
), flags
);
1742 nfmsg
= nlmsg_data(nlh
);
1743 nfmsg
->nfgen_family
= exp
->tuple
.src
.l3num
;
1744 nfmsg
->version
= NFNETLINK_V0
;
1748 if (ctnetlink_exp_dump_expect(skb
, exp
) < 0)
1749 goto nla_put_failure
;
1752 nlmsg_end(skb
, nlh
);
1753 nfnetlink_send(skb
, net
, item
->pid
, group
, item
->report
, GFP_ATOMIC
);
1758 nlmsg_cancel(skb
, nlh
);
1762 nfnetlink_set_err(net
, 0, 0, -ENOBUFS
);
1766 static int ctnetlink_exp_done(struct netlink_callback
*cb
)
1769 nf_ct_expect_put((struct nf_conntrack_expect
*)cb
->args
[1]);
1774 ctnetlink_exp_dump_table(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1776 struct net
*net
= sock_net(skb
->sk
);
1777 struct nf_conntrack_expect
*exp
, *last
;
1778 struct nfgenmsg
*nfmsg
= nlmsg_data(cb
->nlh
);
1779 struct hlist_node
*n
;
1780 u_int8_t l3proto
= nfmsg
->nfgen_family
;
1783 last
= (struct nf_conntrack_expect
*)cb
->args
[1];
1784 for (; cb
->args
[0] < nf_ct_expect_hsize
; cb
->args
[0]++) {
1786 hlist_for_each_entry(exp
, n
, &net
->ct
.expect_hash
[cb
->args
[0]],
1788 if (l3proto
&& exp
->tuple
.src
.l3num
!= l3proto
)
1795 if (ctnetlink_exp_fill_info(skb
,
1796 NETLINK_CB(cb
->skb
).pid
,
1800 if (!atomic_inc_not_zero(&exp
->use
))
1802 cb
->args
[1] = (unsigned long)exp
;
1814 nf_ct_expect_put(last
);
1819 static const struct nla_policy exp_nla_policy
[CTA_EXPECT_MAX
+1] = {
1820 [CTA_EXPECT_MASTER
] = { .type
= NLA_NESTED
},
1821 [CTA_EXPECT_TUPLE
] = { .type
= NLA_NESTED
},
1822 [CTA_EXPECT_MASK
] = { .type
= NLA_NESTED
},
1823 [CTA_EXPECT_TIMEOUT
] = { .type
= NLA_U32
},
1824 [CTA_EXPECT_ID
] = { .type
= NLA_U32
},
1825 [CTA_EXPECT_HELP_NAME
] = { .type
= NLA_NUL_STRING
},
1826 [CTA_EXPECT_ZONE
] = { .type
= NLA_U16
},
1827 [CTA_EXPECT_FLAGS
] = { .type
= NLA_U32
},
1831 ctnetlink_get_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
1832 const struct nlmsghdr
*nlh
,
1833 const struct nlattr
* const cda
[])
1835 struct net
*net
= sock_net(ctnl
);
1836 struct nf_conntrack_tuple tuple
;
1837 struct nf_conntrack_expect
*exp
;
1838 struct sk_buff
*skb2
;
1839 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
1840 u_int8_t u3
= nfmsg
->nfgen_family
;
1844 if (nlh
->nlmsg_flags
& NLM_F_DUMP
) {
1845 return netlink_dump_start(ctnl
, skb
, nlh
,
1846 ctnetlink_exp_dump_table
,
1847 ctnetlink_exp_done
, 0);
1850 err
= ctnetlink_parse_zone(cda
[CTA_EXPECT_ZONE
], &zone
);
1854 if (cda
[CTA_EXPECT_TUPLE
])
1855 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
, u3
);
1856 else if (cda
[CTA_EXPECT_MASTER
])
1857 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_MASTER
, u3
);
1864 exp
= nf_ct_expect_find_get(net
, zone
, &tuple
);
1868 if (cda
[CTA_EXPECT_ID
]) {
1869 __be32 id
= nla_get_be32(cda
[CTA_EXPECT_ID
]);
1870 if (ntohl(id
) != (u32
)(unsigned long)exp
) {
1871 nf_ct_expect_put(exp
);
1877 skb2
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1882 err
= ctnetlink_exp_fill_info(skb2
, NETLINK_CB(skb
).pid
,
1883 nlh
->nlmsg_seq
, IPCTNL_MSG_EXP_NEW
, exp
);
1888 nf_ct_expect_put(exp
);
1890 return netlink_unicast(ctnl
, skb2
, NETLINK_CB(skb
).pid
, MSG_DONTWAIT
);
1895 nf_ct_expect_put(exp
);
1900 ctnetlink_del_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
1901 const struct nlmsghdr
*nlh
,
1902 const struct nlattr
* const cda
[])
1904 struct net
*net
= sock_net(ctnl
);
1905 struct nf_conntrack_expect
*exp
;
1906 struct nf_conntrack_tuple tuple
;
1907 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
1908 struct hlist_node
*n
, *next
;
1909 u_int8_t u3
= nfmsg
->nfgen_family
;
1914 if (cda
[CTA_EXPECT_TUPLE
]) {
1915 /* delete a single expect by tuple */
1916 err
= ctnetlink_parse_zone(cda
[CTA_EXPECT_ZONE
], &zone
);
1920 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
, u3
);
1924 /* bump usage count to 2 */
1925 exp
= nf_ct_expect_find_get(net
, zone
, &tuple
);
1929 if (cda
[CTA_EXPECT_ID
]) {
1930 __be32 id
= nla_get_be32(cda
[CTA_EXPECT_ID
]);
1931 if (ntohl(id
) != (u32
)(unsigned long)exp
) {
1932 nf_ct_expect_put(exp
);
1937 /* after list removal, usage count == 1 */
1938 spin_lock_bh(&nf_conntrack_lock
);
1939 if (del_timer(&exp
->timeout
)) {
1940 nf_ct_unlink_expect_report(exp
, NETLINK_CB(skb
).pid
,
1942 nf_ct_expect_put(exp
);
1944 spin_unlock_bh(&nf_conntrack_lock
);
1945 /* have to put what we 'get' above.
1946 * after this line usage count == 0 */
1947 nf_ct_expect_put(exp
);
1948 } else if (cda
[CTA_EXPECT_HELP_NAME
]) {
1949 char *name
= nla_data(cda
[CTA_EXPECT_HELP_NAME
]);
1950 struct nf_conn_help
*m_help
;
1952 /* delete all expectations for this helper */
1953 spin_lock_bh(&nf_conntrack_lock
);
1954 for (i
= 0; i
< nf_ct_expect_hsize
; i
++) {
1955 hlist_for_each_entry_safe(exp
, n
, next
,
1956 &net
->ct
.expect_hash
[i
],
1958 m_help
= nfct_help(exp
->master
);
1959 if (!strcmp(m_help
->helper
->name
, name
) &&
1960 del_timer(&exp
->timeout
)) {
1961 nf_ct_unlink_expect_report(exp
,
1962 NETLINK_CB(skb
).pid
,
1964 nf_ct_expect_put(exp
);
1968 spin_unlock_bh(&nf_conntrack_lock
);
1970 /* This basically means we have to flush everything*/
1971 spin_lock_bh(&nf_conntrack_lock
);
1972 for (i
= 0; i
< nf_ct_expect_hsize
; i
++) {
1973 hlist_for_each_entry_safe(exp
, n
, next
,
1974 &net
->ct
.expect_hash
[i
],
1976 if (del_timer(&exp
->timeout
)) {
1977 nf_ct_unlink_expect_report(exp
,
1978 NETLINK_CB(skb
).pid
,
1980 nf_ct_expect_put(exp
);
1984 spin_unlock_bh(&nf_conntrack_lock
);
1990 ctnetlink_change_expect(struct nf_conntrack_expect
*x
,
1991 const struct nlattr
* const cda
[])
1997 ctnetlink_create_expect(struct net
*net
, u16 zone
,
1998 const struct nlattr
* const cda
[],
2000 u32 pid
, int report
)
2002 struct nf_conntrack_tuple tuple
, mask
, master_tuple
;
2003 struct nf_conntrack_tuple_hash
*h
= NULL
;
2004 struct nf_conntrack_expect
*exp
;
2006 struct nf_conn_help
*help
;
2009 /* caller guarantees that those three CTA_EXPECT_* exist */
2010 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
, u3
);
2013 err
= ctnetlink_parse_tuple(cda
, &mask
, CTA_EXPECT_MASK
, u3
);
2016 err
= ctnetlink_parse_tuple(cda
, &master_tuple
, CTA_EXPECT_MASTER
, u3
);
2020 /* Look for master conntrack of this expectation */
2021 h
= nf_conntrack_find_get(net
, zone
, &master_tuple
);
2024 ct
= nf_ct_tuplehash_to_ctrack(h
);
2025 exp
= nf_ct_expect_alloc(ct
);
2030 help
= nfct_help(ct
);
2032 if (!cda
[CTA_EXPECT_TIMEOUT
]) {
2036 exp
->timeout
.expires
=
2037 jiffies
+ ntohl(nla_get_be32(cda
[CTA_EXPECT_TIMEOUT
])) * HZ
;
2039 exp
->flags
= NF_CT_EXPECT_USERSPACE
;
2040 if (cda
[CTA_EXPECT_FLAGS
]) {
2042 ntohl(nla_get_be32(cda
[CTA_EXPECT_FLAGS
]));
2045 if (cda
[CTA_EXPECT_FLAGS
]) {
2046 exp
->flags
= ntohl(nla_get_be32(cda
[CTA_EXPECT_FLAGS
]));
2047 exp
->flags
&= ~NF_CT_EXPECT_USERSPACE
;
2053 exp
->expectfn
= NULL
;
2056 memcpy(&exp
->tuple
, &tuple
, sizeof(struct nf_conntrack_tuple
));
2057 memcpy(&exp
->mask
.src
.u3
, &mask
.src
.u3
, sizeof(exp
->mask
.src
.u3
));
2058 exp
->mask
.src
.u
.all
= mask
.src
.u
.all
;
2060 err
= nf_ct_expect_related_report(exp
, pid
, report
);
2061 nf_ct_expect_put(exp
);
2064 nf_ct_put(nf_ct_tuplehash_to_ctrack(h
));
2069 ctnetlink_new_expect(struct sock
*ctnl
, struct sk_buff
*skb
,
2070 const struct nlmsghdr
*nlh
,
2071 const struct nlattr
* const cda
[])
2073 struct net
*net
= sock_net(ctnl
);
2074 struct nf_conntrack_tuple tuple
;
2075 struct nf_conntrack_expect
*exp
;
2076 struct nfgenmsg
*nfmsg
= nlmsg_data(nlh
);
2077 u_int8_t u3
= nfmsg
->nfgen_family
;
2081 if (!cda
[CTA_EXPECT_TUPLE
]
2082 || !cda
[CTA_EXPECT_MASK
]
2083 || !cda
[CTA_EXPECT_MASTER
])
2086 err
= ctnetlink_parse_zone(cda
[CTA_EXPECT_ZONE
], &zone
);
2090 err
= ctnetlink_parse_tuple(cda
, &tuple
, CTA_EXPECT_TUPLE
, u3
);
2094 spin_lock_bh(&nf_conntrack_lock
);
2095 exp
= __nf_ct_expect_find(net
, zone
, &tuple
);
2098 spin_unlock_bh(&nf_conntrack_lock
);
2100 if (nlh
->nlmsg_flags
& NLM_F_CREATE
) {
2101 err
= ctnetlink_create_expect(net
, zone
, cda
,
2103 NETLINK_CB(skb
).pid
,
2110 if (!(nlh
->nlmsg_flags
& NLM_F_EXCL
))
2111 err
= ctnetlink_change_expect(exp
, cda
);
2112 spin_unlock_bh(&nf_conntrack_lock
);
2117 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2118 static struct nf_ct_event_notifier ctnl_notifier
= {
2119 .fcn
= ctnetlink_conntrack_event
,
2122 static struct nf_exp_event_notifier ctnl_notifier_exp
= {
2123 .fcn
= ctnetlink_expect_event
,
2127 static const struct nfnl_callback ctnl_cb
[IPCTNL_MSG_MAX
] = {
2128 [IPCTNL_MSG_CT_NEW
] = { .call
= ctnetlink_new_conntrack
,
2129 .attr_count
= CTA_MAX
,
2130 .policy
= ct_nla_policy
},
2131 [IPCTNL_MSG_CT_GET
] = { .call
= ctnetlink_get_conntrack
,
2132 .attr_count
= CTA_MAX
,
2133 .policy
= ct_nla_policy
},
2134 [IPCTNL_MSG_CT_DELETE
] = { .call
= ctnetlink_del_conntrack
,
2135 .attr_count
= CTA_MAX
,
2136 .policy
= ct_nla_policy
},
2137 [IPCTNL_MSG_CT_GET_CTRZERO
] = { .call
= ctnetlink_get_conntrack
,
2138 .attr_count
= CTA_MAX
,
2139 .policy
= ct_nla_policy
},
2142 static const struct nfnl_callback ctnl_exp_cb
[IPCTNL_MSG_EXP_MAX
] = {
2143 [IPCTNL_MSG_EXP_GET
] = { .call
= ctnetlink_get_expect
,
2144 .attr_count
= CTA_EXPECT_MAX
,
2145 .policy
= exp_nla_policy
},
2146 [IPCTNL_MSG_EXP_NEW
] = { .call
= ctnetlink_new_expect
,
2147 .attr_count
= CTA_EXPECT_MAX
,
2148 .policy
= exp_nla_policy
},
2149 [IPCTNL_MSG_EXP_DELETE
] = { .call
= ctnetlink_del_expect
,
2150 .attr_count
= CTA_EXPECT_MAX
,
2151 .policy
= exp_nla_policy
},
2154 static const struct nfnetlink_subsystem ctnl_subsys
= {
2155 .name
= "conntrack",
2156 .subsys_id
= NFNL_SUBSYS_CTNETLINK
,
2157 .cb_count
= IPCTNL_MSG_MAX
,
2161 static const struct nfnetlink_subsystem ctnl_exp_subsys
= {
2162 .name
= "conntrack_expect",
2163 .subsys_id
= NFNL_SUBSYS_CTNETLINK_EXP
,
2164 .cb_count
= IPCTNL_MSG_EXP_MAX
,
2168 MODULE_ALIAS("ip_conntrack_netlink");
2169 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK
);
2170 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_EXP
);
2172 static int __net_init
ctnetlink_net_init(struct net
*net
)
2174 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2177 ret
= nf_conntrack_register_notifier(net
, &ctnl_notifier
);
2179 pr_err("ctnetlink_init: cannot register notifier.\n");
2183 ret
= nf_ct_expect_register_notifier(net
, &ctnl_notifier_exp
);
2185 pr_err("ctnetlink_init: cannot expect register notifier.\n");
2186 goto err_unreg_notifier
;
2191 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2193 nf_conntrack_unregister_notifier(net
, &ctnl_notifier
);
2199 static void ctnetlink_net_exit(struct net
*net
)
2201 #ifdef CONFIG_NF_CONNTRACK_EVENTS
2202 nf_ct_expect_unregister_notifier(net
, &ctnl_notifier_exp
);
2203 nf_conntrack_unregister_notifier(net
, &ctnl_notifier
);
2207 static void __net_exit
ctnetlink_net_exit_batch(struct list_head
*net_exit_list
)
2211 list_for_each_entry(net
, net_exit_list
, exit_list
)
2212 ctnetlink_net_exit(net
);
2215 static struct pernet_operations ctnetlink_net_ops
= {
2216 .init
= ctnetlink_net_init
,
2217 .exit_batch
= ctnetlink_net_exit_batch
,
2220 static int __init
ctnetlink_init(void)
2224 pr_info("ctnetlink v%s: registering with nfnetlink.\n", version
);
2225 ret
= nfnetlink_subsys_register(&ctnl_subsys
);
2227 pr_err("ctnetlink_init: cannot register with nfnetlink.\n");
2231 ret
= nfnetlink_subsys_register(&ctnl_exp_subsys
);
2233 pr_err("ctnetlink_init: cannot register exp with nfnetlink.\n");
2234 goto err_unreg_subsys
;
2237 if (register_pernet_subsys(&ctnetlink_net_ops
)) {
2238 pr_err("ctnetlink_init: cannot register pernet operations\n");
2239 goto err_unreg_exp_subsys
;
2244 err_unreg_exp_subsys
:
2245 nfnetlink_subsys_unregister(&ctnl_exp_subsys
);
2247 nfnetlink_subsys_unregister(&ctnl_subsys
);
2252 static void __exit
ctnetlink_exit(void)
2254 pr_info("ctnetlink: unregistering from nfnetlink.\n");
2256 nf_ct_remove_userspace_expectations();
2257 unregister_pernet_subsys(&ctnetlink_net_ops
);
2258 nfnetlink_subsys_unregister(&ctnl_exp_subsys
);
2259 nfnetlink_subsys_unregister(&ctnl_subsys
);
2262 module_init(ctnetlink_init
);
2263 module_exit(ctnetlink_exit
);