xref: /linux/net/bridge/netfilter/ebt_nflog.c (revision 0be3ff0c)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ebt_nflog
4  *
5  *	Author:
6  *	Peter Warasin <peter@endian.com>
7  *
8  *  February, 2008
9  *
10  * Based on:
11  *  xt_NFLOG.c, (C) 2006 by Patrick McHardy <kaber@trash.net>
12  *  ebt_ulog.c, (C) 2004 by Bart De Schuymer <bdschuym@pandora.be>
13  *
14  */
15 
16 #include <linux/module.h>
17 #include <linux/spinlock.h>
18 #include <linux/netfilter/x_tables.h>
19 #include <linux/netfilter_bridge/ebtables.h>
20 #include <linux/netfilter_bridge/ebt_nflog.h>
21 #include <net/netfilter/nf_log.h>
22 
23 static unsigned int
24 ebt_nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
25 {
26 	const struct ebt_nflog_info *info = par->targinfo;
27 	struct net *net = xt_net(par);
28 	struct nf_loginfo li;
29 
30 	li.type = NF_LOG_TYPE_ULOG;
31 	li.u.ulog.copy_len = info->len;
32 	li.u.ulog.group = info->group;
33 	li.u.ulog.qthreshold = info->threshold;
34 	li.u.ulog.flags = 0;
35 
36 	nf_log_packet(net, PF_BRIDGE, xt_hooknum(par), skb, xt_in(par),
37 		      xt_out(par), &li, "%s", info->prefix);
38 	return EBT_CONTINUE;
39 }
40 
41 static int ebt_nflog_tg_check(const struct xt_tgchk_param *par)
42 {
43 	struct ebt_nflog_info *info = par->targinfo;
44 
45 	if (info->flags & ~EBT_NFLOG_MASK)
46 		return -EINVAL;
47 	info->prefix[EBT_NFLOG_PREFIX_SIZE - 1] = '\0';
48 	return 0;
49 }
50 
51 static struct xt_target ebt_nflog_tg_reg __read_mostly = {
52 	.name       = "nflog",
53 	.revision   = 0,
54 	.family     = NFPROTO_BRIDGE,
55 	.target     = ebt_nflog_tg,
56 	.checkentry = ebt_nflog_tg_check,
57 	.targetsize = sizeof(struct ebt_nflog_info),
58 	.me         = THIS_MODULE,
59 };
60 
61 static int __init ebt_nflog_init(void)
62 {
63 	return xt_register_target(&ebt_nflog_tg_reg);
64 }
65 
66 static void __exit ebt_nflog_fini(void)
67 {
68 	xt_unregister_target(&ebt_nflog_tg_reg);
69 }
70 
71 module_init(ebt_nflog_init);
72 module_exit(ebt_nflog_fini);
73 MODULE_LICENSE("GPL");
74 MODULE_AUTHOR("Peter Warasin <peter@endian.com>");
75 MODULE_DESCRIPTION("ebtables NFLOG netfilter logging module");
76