Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 2 | /* This is a module which is used to mark packets for tracing. |
| 3 | */ |
| 4 | #include <linux/module.h> |
| 5 | #include <linux/skbuff.h> |
| 6 | |
| 7 | #include <linux/netfilter/x_tables.h> |
Liping Zhang | 36f959c | 2016-06-08 20:43:19 +0800 | [diff] [blame] | 8 | #include <net/netfilter/nf_log.h> |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 9 | |
Jan Engelhardt | 2ae15b6 | 2008-01-14 23:42:28 -0800 | [diff] [blame] | 10 | MODULE_DESCRIPTION("Xtables: packet flow tracing"); |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 11 | MODULE_LICENSE("GPL"); |
| 12 | MODULE_ALIAS("ipt_TRACE"); |
| 13 | MODULE_ALIAS("ip6t_TRACE"); |
| 14 | |
Liping Zhang | 36f959c | 2016-06-08 20:43:19 +0800 | [diff] [blame] | 15 | static int trace_tg_check(const struct xt_tgchk_param *par) |
| 16 | { |
| 17 | return nf_logger_find_get(par->family, NF_LOG_TYPE_LOG); |
| 18 | } |
| 19 | |
| 20 | static void trace_tg_destroy(const struct xt_tgdtor_param *par) |
| 21 | { |
| 22 | nf_logger_put(par->family, NF_LOG_TYPE_LOG); |
| 23 | } |
| 24 | |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 25 | static unsigned int |
Jan Engelhardt | 4b560b4 | 2009-07-05 19:43:26 +0200 | [diff] [blame] | 26 | trace_tg(struct sk_buff *skb, const struct xt_action_param *par) |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 27 | { |
Herbert Xu | 3db05fea | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 28 | skb->nf_trace = 1; |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 29 | return XT_CONTINUE; |
| 30 | } |
| 31 | |
Jan Engelhardt | 55b69e9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 32 | static struct xt_target trace_tg_reg __read_mostly = { |
Liping Zhang | 36f959c | 2016-06-08 20:43:19 +0800 | [diff] [blame] | 33 | .name = "TRACE", |
| 34 | .revision = 0, |
| 35 | .family = NFPROTO_UNSPEC, |
| 36 | .table = "raw", |
| 37 | .target = trace_tg, |
| 38 | .checkentry = trace_tg_check, |
| 39 | .destroy = trace_tg_destroy, |
| 40 | .me = THIS_MODULE, |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 43 | static int __init trace_tg_init(void) |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 44 | { |
Jan Engelhardt | 55b69e9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 45 | return xt_register_target(&trace_tg_reg); |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 48 | static void __exit trace_tg_exit(void) |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 49 | { |
Jan Engelhardt | 55b69e9 | 2008-10-08 11:35:01 +0200 | [diff] [blame] | 50 | xt_unregister_target(&trace_tg_reg); |
Jozsef Kadlecsik | ba9dda3 | 2007-07-07 22:21:23 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 53 | module_init(trace_tg_init); |
| 54 | module_exit(trace_tg_exit); |