Merge tag 'armsoc-drivers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[linux-2.6-microblaze.git] / net / netfilter / nf_tables_inet.c
1 /*
2  * Copyright (c) 2012-2014 Patrick McHardy <kaber@trash.net>
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/init.h>
10 #include <linux/module.h>
11 #include <linux/ip.h>
12 #include <linux/ipv6.h>
13 #include <linux/netfilter_ipv4.h>
14 #include <linux/netfilter_ipv6.h>
15 #include <net/netfilter/nf_tables.h>
16 #include <net/netfilter/nf_tables_ipv4.h>
17 #include <net/netfilter/nf_tables_ipv6.h>
18 #include <net/ip.h>
19
20 static unsigned int nft_do_chain_inet(void *priv, struct sk_buff *skb,
21                                       const struct nf_hook_state *state)
22 {
23         struct nft_pktinfo pkt;
24
25         nft_set_pktinfo(&pkt, skb, state);
26
27         switch (state->pf) {
28         case NFPROTO_IPV4:
29                 nft_set_pktinfo_ipv4(&pkt, skb);
30                 break;
31         case NFPROTO_IPV6:
32                 nft_set_pktinfo_ipv6(&pkt, skb);
33                 break;
34         default:
35                 break;
36         }
37
38         return nft_do_chain(&pkt, priv);
39 }
40
41 static const struct nf_chain_type filter_inet = {
42         .name           = "filter",
43         .type           = NFT_CHAIN_T_DEFAULT,
44         .family         = NFPROTO_INET,
45         .owner          = THIS_MODULE,
46         .hook_mask      = (1 << NF_INET_LOCAL_IN) |
47                           (1 << NF_INET_LOCAL_OUT) |
48                           (1 << NF_INET_FORWARD) |
49                           (1 << NF_INET_PRE_ROUTING) |
50                           (1 << NF_INET_POST_ROUTING),
51         .hooks          = {
52                 [NF_INET_LOCAL_IN]      = nft_do_chain_inet,
53                 [NF_INET_LOCAL_OUT]     = nft_do_chain_inet,
54                 [NF_INET_FORWARD]       = nft_do_chain_inet,
55                 [NF_INET_PRE_ROUTING]   = nft_do_chain_inet,
56                 [NF_INET_POST_ROUTING]  = nft_do_chain_inet,
57         },
58 };
59
60 static int __init nf_tables_inet_init(void)
61 {
62         return nft_register_chain_type(&filter_inet);
63 }
64
65 static void __exit nf_tables_inet_exit(void)
66 {
67         nft_unregister_chain_type(&filter_inet);
68 }
69
70 module_init(nf_tables_inet_init);
71 module_exit(nf_tables_inet_exit);
72
73 MODULE_LICENSE("GPL");
74 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
75 MODULE_ALIAS_NFT_CHAIN(1, "filter");