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 return nf_log_set(net
, NFPROTO_BRIDGE
, &nf_bridge_logger
);
56 static void __net_exit
nf_log_bridge_net_exit(struct net
*net
)
58 nf_log_unset(net
, &nf_bridge_logger
);
61 static struct pernet_operations nf_log_bridge_net_ops
= {
62 .init
= nf_log_bridge_net_init
,
63 .exit
= nf_log_bridge_net_exit
,
66 static int __init
nf_log_bridge_init(void)
70 /* Request to load the real packet loggers. */
71 nf_logger_request_module(NFPROTO_IPV4
, NF_LOG_TYPE_LOG
);
72 nf_logger_request_module(NFPROTO_IPV6
, NF_LOG_TYPE_LOG
);
73 nf_logger_request_module(NFPROTO_ARP
, NF_LOG_TYPE_LOG
);
75 ret
= register_pernet_subsys(&nf_log_bridge_net_ops
);
79 nf_log_register(NFPROTO_BRIDGE
, &nf_bridge_logger
);
83 static void __exit
nf_log_bridge_exit(void)
85 unregister_pernet_subsys(&nf_log_bridge_net_ops
);
86 nf_log_unregister(&nf_bridge_logger
);
89 module_init(nf_log_bridge_init
);
90 module_exit(nf_log_bridge_exit
);
92 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
93 MODULE_DESCRIPTION("Netfilter bridge packet logging");
94 MODULE_LICENSE("GPL");
95 MODULE_ALIAS_NF_LOGGER(AF_BRIDGE
, 0);