Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / net / bridge / netfilter / nf_log_bridge.c
1 /*
2  * (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org>
3  *
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.
7  */
8
9 #include <linux/module.h>
10 #include <linux/spinlock.h>
11 #include <linux/skbuff.h>
12 #include <linux/if_bridge.h>
13 #include <linux/ip.h>
14 #include <net/route.h>
15
16 #include <linux/netfilter.h>
17 #include <net/netfilter/nf_log.h>
18
19 static void nf_log_bridge_packet(struct net *net, u_int8_t pf,
20                                  unsigned int hooknum,
21                                  const struct sk_buff *skb,
22                                  const struct net_device *in,
23                                  const struct net_device *out,
24                                  const struct nf_loginfo *loginfo,
25                                  const char *prefix)
26 {
27         switch (eth_hdr(skb)->h_proto) {
28         case htons(ETH_P_IP):
29                 nf_log_packet(net, NFPROTO_IPV4, hooknum, skb, in, out,
30                               loginfo, "%s", prefix);
31                 break;
32         case htons(ETH_P_IPV6):
33                 nf_log_packet(net, NFPROTO_IPV6, hooknum, skb, in, out,
34                               loginfo, "%s", prefix);
35                 break;
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);
40                 break;
41         }
42 }
43
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,
48         .me             = THIS_MODULE,
49 };
50
51 static int __net_init nf_log_bridge_net_init(struct net *net)
52 {
53         nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger);
54         return 0;
55 }
56
57 static void __net_exit nf_log_bridge_net_exit(struct net *net)
58 {
59         nf_log_unset(net, &nf_bridge_logger);
60 }
61
62 static struct pernet_operations nf_log_bridge_net_ops = {
63         .init = nf_log_bridge_net_init,
64         .exit = nf_log_bridge_net_exit,
65 };
66
67 static int __init nf_log_bridge_init(void)
68 {
69         int ret;
70
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);
75
76         ret = register_pernet_subsys(&nf_log_bridge_net_ops);
77         if (ret < 0)
78                 return ret;
79
80         nf_log_register(NFPROTO_BRIDGE, &nf_bridge_logger);
81         return 0;
82 }
83
84 static void __exit nf_log_bridge_exit(void)
85 {
86         unregister_pernet_subsys(&nf_log_bridge_net_ops);
87         nf_log_unregister(&nf_bridge_logger);
88 }
89
90 module_init(nf_log_bridge_init);
91 module_exit(nf_log_bridge_exit);
92
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);