Merge remote-tracking branch 'omap_dss2/for-next'
[deliverable/linux.git] / net / ipv6 / netfilter / nf_tables_ipv6.c
CommitLineData
96518518
PM
1/*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
9370761c 3 * Copyright (c) 2012-2013 Pablo Neira Ayuso <pablo@netfilter.org>
96518518
PM
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/ipv6.h>
15#include <linux/netfilter_ipv6.h>
16#include <net/netfilter/nf_tables.h>
0ca743a5 17#include <net/netfilter/nf_tables_ipv6.h>
96518518 18
06198b34 19static unsigned int nft_do_chain_ipv6(void *priv,
3b088c4b 20 struct sk_buff *skb,
238e54c9 21 const struct nf_hook_state *state)
3b088c4b
PM
22{
23 struct nft_pktinfo pkt;
24
71212c9b 25 nft_set_pktinfo_ipv6(&pkt, skb, state);
3b088c4b 26
06198b34 27 return nft_do_chain(&pkt, priv);
3b088c4b
PM
28}
29
06198b34 30static unsigned int nft_ipv6_output(void *priv,
96518518 31 struct sk_buff *skb,
238e54c9 32 const struct nf_hook_state *state)
96518518
PM
33{
34 if (unlikely(skb->len < sizeof(struct ipv6hdr))) {
35 if (net_ratelimit())
36 pr_info("nf_tables_ipv6: ignoring short SOCK_RAW "
37 "packet\n");
38 return NF_ACCEPT;
39 }
40
06198b34 41 return nft_do_chain_ipv6(priv, skb, state);
96518518
PM
42}
43
1d49144c 44struct nft_af_info nft_af_ipv6 __read_mostly = {
96518518
PM
45 .family = NFPROTO_IPV6,
46 .nhooks = NF_INET_NUMHOOKS,
47 .owner = THIS_MODULE,
115a60b1 48 .nops = 1,
96518518 49 .hooks = {
3b088c4b 50 [NF_INET_LOCAL_IN] = nft_do_chain_ipv6,
96518518 51 [NF_INET_LOCAL_OUT] = nft_ipv6_output,
3b088c4b
PM
52 [NF_INET_FORWARD] = nft_do_chain_ipv6,
53 [NF_INET_PRE_ROUTING] = nft_do_chain_ipv6,
54 [NF_INET_POST_ROUTING] = nft_do_chain_ipv6,
96518518
PM
55 },
56};
1d49144c 57EXPORT_SYMBOL_GPL(nft_af_ipv6);
96518518 58
99633ab2
PNA
59static int nf_tables_ipv6_init_net(struct net *net)
60{
61 net->nft.ipv6 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
62 if (net->nft.ipv6 == NULL)
63 return -ENOMEM;
64
65 memcpy(net->nft.ipv6, &nft_af_ipv6, sizeof(nft_af_ipv6));
66
67 if (nft_register_afinfo(net, net->nft.ipv6) < 0)
68 goto err;
69
70 return 0;
71err:
72 kfree(net->nft.ipv6);
73 return -ENOMEM;
74}
75
76static void nf_tables_ipv6_exit_net(struct net *net)
77{
df05ef87 78 nft_unregister_afinfo(net, net->nft.ipv6);
99633ab2
PNA
79 kfree(net->nft.ipv6);
80}
81
82static struct pernet_operations nf_tables_ipv6_net_ops = {
83 .init = nf_tables_ipv6_init_net,
84 .exit = nf_tables_ipv6_exit_net,
85};
86
2a37d755 87static const struct nf_chain_type filter_ipv6 = {
9370761c
PNA
88 .name = "filter",
89 .type = NFT_CHAIN_T_DEFAULT,
fa2c1de0
PM
90 .family = NFPROTO_IPV6,
91 .owner = THIS_MODULE,
9370761c
PNA
92 .hook_mask = (1 << NF_INET_LOCAL_IN) |
93 (1 << NF_INET_LOCAL_OUT) |
94 (1 << NF_INET_FORWARD) |
95 (1 << NF_INET_PRE_ROUTING) |
96 (1 << NF_INET_POST_ROUTING),
9370761c
PNA
97};
98
96518518
PM
99static int __init nf_tables_ipv6_init(void)
100{
cf4dfa85
PNA
101 int ret;
102
23d07508
GF
103 ret = nft_register_chain_type(&filter_ipv6);
104 if (ret < 0)
105 return ret;
106
cf4dfa85
PNA
107 ret = register_pernet_subsys(&nf_tables_ipv6_net_ops);
108 if (ret < 0)
109 nft_unregister_chain_type(&filter_ipv6);
110
111 return ret;
96518518 112}
99633ab2 113
96518518
PM
114static void __exit nf_tables_ipv6_exit(void)
115{
99633ab2 116 unregister_pernet_subsys(&nf_tables_ipv6_net_ops);
9370761c 117 nft_unregister_chain_type(&filter_ipv6);
96518518
PM
118}
119
120module_init(nf_tables_ipv6_init);
121module_exit(nf_tables_ipv6_exit);
122
123MODULE_LICENSE("GPL");
124MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
125MODULE_ALIAS_NFT_FAMILY(AF_INET6);
This page took 0.166339 seconds and 5 git commands to generate.