1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org>
4 */
5
6 #include <linux/module.h>
7 #include <linux/spinlock.h>
8 #include <linux/skbuff.h>
9 #include <linux/if_bridge.h>
10 #include <linux/ip.h>
11 #include <net/route.h>
12
13 #include <linux/netfilter.h>
14 #include <net/netfilter/nf_log.h>
15
nf_log_bridge_packet(struct net * net,u_int8_t pf,unsigned int hooknum,const struct sk_buff * skb,const struct net_device * in,const struct net_device * out,const struct nf_loginfo * loginfo,const char * prefix)16 static void nf_log_bridge_packet(struct net *net, u_int8_t pf,
17 unsigned int hooknum,
18 const struct sk_buff *skb,
19 const struct net_device *in,
20 const struct net_device *out,
21 const struct nf_loginfo *loginfo,
22 const char *prefix)
23 {
24 nf_log_l2packet(net, pf, eth_hdr(skb)->h_proto, hooknum, skb,
25 in, out, loginfo, prefix);
26 }
27
28 static struct nf_logger nf_bridge_logger __read_mostly = {
29 .name = "nf_log_bridge",
30 .type = NF_LOG_TYPE_LOG,
31 .logfn = nf_log_bridge_packet,
32 .me = THIS_MODULE,
33 };
34
nf_log_bridge_net_init(struct net * net)35 static int __net_init nf_log_bridge_net_init(struct net *net)
36 {
37 return nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger);
38 }
39
nf_log_bridge_net_exit(struct net * net)40 static void __net_exit nf_log_bridge_net_exit(struct net *net)
41 {
42 nf_log_unset(net, &nf_bridge_logger);
43 }
44
45 static struct pernet_operations nf_log_bridge_net_ops = {
46 .init = nf_log_bridge_net_init,
47 .exit = nf_log_bridge_net_exit,
48 };
49
nf_log_bridge_init(void)50 static int __init nf_log_bridge_init(void)
51 {
52 int ret;
53
54 /* Request to load the real packet loggers. */
55 nf_logger_request_module(NFPROTO_IPV4, NF_LOG_TYPE_LOG);
56 nf_logger_request_module(NFPROTO_IPV6, NF_LOG_TYPE_LOG);
57 nf_logger_request_module(NFPROTO_ARP, NF_LOG_TYPE_LOG);
58
59 ret = register_pernet_subsys(&nf_log_bridge_net_ops);
60 if (ret < 0)
61 return ret;
62
63 nf_log_register(NFPROTO_BRIDGE, &nf_bridge_logger);
64 return 0;
65 }
66
nf_log_bridge_exit(void)67 static void __exit nf_log_bridge_exit(void)
68 {
69 unregister_pernet_subsys(&nf_log_bridge_net_ops);
70 nf_log_unregister(&nf_bridge_logger);
71 }
72
73 module_init(nf_log_bridge_init);
74 module_exit(nf_log_bridge_exit);
75
76 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
77 MODULE_DESCRIPTION("Netfilter bridge packet logging");
78 MODULE_LICENSE("GPL");
79 MODULE_ALIAS_NF_LOGGER(AF_BRIDGE, 0);
80