2 * (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/module.h>
10 #include <linux/spinlock.h>
11 #include <linux/skbuff.h>
12 #include <linux/if_bridge.h>
14 #include <net/route.h>
16 #include <linux/netfilter.h>
17 #include <net/netfilter/nf_log.h>
19 static void nf_log_bridge_packet(struct net
*net
, u_int8_t pf
,
21 const struct sk_buff
*skb
,
22 const struct net_device
*in
,
23 const struct net_device
*out
,
24 const struct nf_loginfo
*loginfo
,
27 switch (eth_hdr(skb
)->h_proto
) {
29 nf_log_packet(net
, NFPROTO_IPV4
, hooknum
, skb
, in
, out
,
30 loginfo
, "%s", prefix
);
32 case htons(ETH_P_IPV6
):
33 nf_log_packet(net
, NFPROTO_IPV6
, hooknum
, skb
, in
, out
,
34 loginfo
, "%s", prefix
);
36 case htons(ETH_P_ARP
):
37 case htons(ETH_P_RARP
):
38 nf_log_packet(net
, NFPROTO_ARP
, hooknum
, skb
, in
, out
,
39 loginfo
, "%s", prefix
);
44 static struct nf_logger nf_bridge_logger __read_mostly
= {
45 .name
= "nf_log_bridge",
46 .type
= NF_LOG_TYPE_LOG
,
47 .logfn
= nf_log_bridge_packet
,
51 static int __net_init
nf_log_bridge_net_init(struct net
*net
)
53 nf_log_set(net
, NFPROTO_BRIDGE
, &nf_bridge_logger
);
57 static void __net_exit
nf_log_bridge_net_exit(struct net
*net
)
59 nf_log_unset(net
, &nf_bridge_logger
);
62 static struct pernet_operations nf_log_bridge_net_ops
= {
63 .init
= nf_log_bridge_net_init
,
64 .exit
= nf_log_bridge_net_exit
,
67 static int __init
nf_log_bridge_init(void)
71 /* Request to load the real packet loggers. */
72 nf_logger_request_module(NFPROTO_IPV4
, NF_LOG_TYPE_LOG
);
73 nf_logger_request_module(NFPROTO_IPV6
, NF_LOG_TYPE_LOG
);
74 nf_logger_request_module(NFPROTO_ARP
, NF_LOG_TYPE_LOG
);
76 ret
= register_pernet_subsys(&nf_log_bridge_net_ops
);
80 nf_log_register(NFPROTO_BRIDGE
, &nf_bridge_logger
);
84 static void __exit
nf_log_bridge_exit(void)
86 unregister_pernet_subsys(&nf_log_bridge_net_ops
);
87 nf_log_unregister(&nf_bridge_logger
);
90 module_init(nf_log_bridge_init
);
91 module_exit(nf_log_bridge_exit
);
93 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
94 MODULE_DESCRIPTION("Netfilter bridge packet logging");
95 MODULE_LICENSE("GPL");
96 MODULE_ALIAS_NF_LOGGER(AF_BRIDGE
, 0);