2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2012-2013 Pablo Neira Ayuso <pablo@netfilter.org>
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.
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
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>
17 #include <net/netfilter/nf_tables_ipv6.h>
19 static unsigned int nft_do_chain_ipv6(void *priv
,
21 const struct nf_hook_state
*state
)
23 struct nft_pktinfo pkt
;
25 /* malformed packet, drop it */
26 if (nft_set_pktinfo_ipv6(&pkt
, skb
, state
) < 0)
29 return nft_do_chain(&pkt
, priv
);
32 static unsigned int nft_ipv6_output(void *priv
,
34 const struct nf_hook_state
*state
)
36 if (unlikely(skb
->len
< sizeof(struct ipv6hdr
))) {
38 pr_info("nf_tables_ipv6: ignoring short SOCK_RAW "
43 return nft_do_chain_ipv6(priv
, skb
, state
);
46 struct nft_af_info nft_af_ipv6 __read_mostly
= {
47 .family
= NFPROTO_IPV6
,
48 .nhooks
= NF_INET_NUMHOOKS
,
52 [NF_INET_LOCAL_IN
] = nft_do_chain_ipv6
,
53 [NF_INET_LOCAL_OUT
] = nft_ipv6_output
,
54 [NF_INET_FORWARD
] = nft_do_chain_ipv6
,
55 [NF_INET_PRE_ROUTING
] = nft_do_chain_ipv6
,
56 [NF_INET_POST_ROUTING
] = nft_do_chain_ipv6
,
59 EXPORT_SYMBOL_GPL(nft_af_ipv6
);
61 static int nf_tables_ipv6_init_net(struct net
*net
)
63 net
->nft
.ipv6
= kmalloc(sizeof(struct nft_af_info
), GFP_KERNEL
);
64 if (net
->nft
.ipv6
== NULL
)
67 memcpy(net
->nft
.ipv6
, &nft_af_ipv6
, sizeof(nft_af_ipv6
));
69 if (nft_register_afinfo(net
, net
->nft
.ipv6
) < 0)
78 static void nf_tables_ipv6_exit_net(struct net
*net
)
80 nft_unregister_afinfo(net
, net
->nft
.ipv6
);
84 static struct pernet_operations nf_tables_ipv6_net_ops
= {
85 .init
= nf_tables_ipv6_init_net
,
86 .exit
= nf_tables_ipv6_exit_net
,
89 static const struct nf_chain_type filter_ipv6
= {
91 .type
= NFT_CHAIN_T_DEFAULT
,
92 .family
= NFPROTO_IPV6
,
94 .hook_mask
= (1 << NF_INET_LOCAL_IN
) |
95 (1 << NF_INET_LOCAL_OUT
) |
96 (1 << NF_INET_FORWARD
) |
97 (1 << NF_INET_PRE_ROUTING
) |
98 (1 << NF_INET_POST_ROUTING
),
101 static int __init
nf_tables_ipv6_init(void)
105 nft_register_chain_type(&filter_ipv6
);
106 ret
= register_pernet_subsys(&nf_tables_ipv6_net_ops
);
108 nft_unregister_chain_type(&filter_ipv6
);
113 static void __exit
nf_tables_ipv6_exit(void)
115 unregister_pernet_subsys(&nf_tables_ipv6_net_ops
);
116 nft_unregister_chain_type(&filter_ipv6
);
119 module_init(nf_tables_ipv6_init
);
120 module_exit(nf_tables_ipv6_exit
);
122 MODULE_LICENSE("GPL");
123 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
124 MODULE_ALIAS_NFT_FAMILY(AF_INET6
);