netfilter: nf_tables: add compatibility layer for x_tables
[deliverable/linux.git] / net / ipv4 / netfilter / nf_tables_ipv4.c
1 /*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2012-2013 Pablo Neira Ayuso <pablo@netfilter.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
10 */
11
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/ip.h>
15 #include <linux/netfilter_ipv4.h>
16 #include <net/netfilter/nf_tables.h>
17 #include <net/ip.h>
18 #include <net/net_namespace.h>
19 #include <net/netfilter/nf_tables_ipv4.h>
20
21 static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops,
22 struct sk_buff *skb,
23 const struct net_device *in,
24 const struct net_device *out,
25 int (*okfn)(struct sk_buff *))
26 {
27 struct nft_pktinfo pkt;
28
29 if (unlikely(skb->len < sizeof(struct iphdr) ||
30 ip_hdr(skb)->ihl < sizeof(struct iphdr) / 4)) {
31 if (net_ratelimit())
32 pr_info("nf_tables_ipv4: ignoring short SOCK_RAW "
33 "packet\n");
34 return NF_ACCEPT;
35 }
36 nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
37
38 return nft_do_chain_pktinfo(&pkt, ops);
39 }
40
41 static struct nft_af_info nft_af_ipv4 __read_mostly = {
42 .family = NFPROTO_IPV4,
43 .nhooks = NF_INET_NUMHOOKS,
44 .owner = THIS_MODULE,
45 .hooks = {
46 [NF_INET_LOCAL_OUT] = nft_ipv4_output,
47 },
48 };
49
50
51 static unsigned int
52 nft_do_chain_ipv4(const struct nf_hook_ops *ops,
53 struct sk_buff *skb,
54 const struct net_device *in,
55 const struct net_device *out,
56 int (*okfn)(struct sk_buff *))
57 {
58 struct nft_pktinfo pkt;
59
60 nft_set_pktinfo_ipv4(&pkt, ops, skb, in, out);
61
62 return nft_do_chain_pktinfo(&pkt, ops);
63 }
64
65 static struct nf_chain_type filter_ipv4 = {
66 .family = NFPROTO_IPV4,
67 .name = "filter",
68 .type = NFT_CHAIN_T_DEFAULT,
69 .hook_mask = (1 << NF_INET_LOCAL_IN) |
70 (1 << NF_INET_LOCAL_OUT) |
71 (1 << NF_INET_FORWARD) |
72 (1 << NF_INET_PRE_ROUTING) |
73 (1 << NF_INET_POST_ROUTING),
74 .fn = {
75 [NF_INET_LOCAL_IN] = nft_do_chain_ipv4,
76 [NF_INET_LOCAL_OUT] = nft_ipv4_output,
77 [NF_INET_FORWARD] = nft_do_chain_ipv4,
78 [NF_INET_PRE_ROUTING] = nft_do_chain_ipv4,
79 [NF_INET_POST_ROUTING] = nft_do_chain_ipv4,
80 },
81 };
82
83 static int __init nf_tables_ipv4_init(void)
84 {
85 nft_register_chain_type(&filter_ipv4);
86 return nft_register_afinfo(&nft_af_ipv4);
87 }
88
89 static void __exit nf_tables_ipv4_exit(void)
90 {
91 nft_unregister_afinfo(&nft_af_ipv4);
92 nft_unregister_chain_type(&filter_ipv4);
93 }
94
95 module_init(nf_tables_ipv4_init);
96 module_exit(nf_tables_ipv4_exit);
97
98 MODULE_LICENSE("GPL");
99 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
100 MODULE_ALIAS_NFT_FAMILY(AF_INET);
This page took 0.032611 seconds and 5 git commands to generate.