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_ipv6_output(const struct nf_hook_ops
*ops
,
21 const struct net_device
*in
,
22 const struct net_device
*out
,
23 int (*okfn
)(struct sk_buff
*))
25 struct nft_pktinfo pkt
;
27 if (unlikely(skb
->len
< sizeof(struct ipv6hdr
))) {
29 pr_info("nf_tables_ipv6: ignoring short SOCK_RAW "
33 if (nft_set_pktinfo_ipv6(&pkt
, ops
, skb
, in
, out
) < 0)
36 return nft_do_chain_pktinfo(&pkt
, ops
);
39 static struct nft_af_info nft_af_ipv6 __read_mostly
= {
40 .family
= NFPROTO_IPV6
,
41 .nhooks
= NF_INET_NUMHOOKS
,
44 [NF_INET_LOCAL_OUT
] = nft_ipv6_output
,
48 static int nf_tables_ipv6_init_net(struct net
*net
)
50 net
->nft
.ipv6
= kmalloc(sizeof(struct nft_af_info
), GFP_KERNEL
);
51 if (net
->nft
.ipv6
== NULL
)
54 memcpy(net
->nft
.ipv6
, &nft_af_ipv6
, sizeof(nft_af_ipv6
));
56 if (nft_register_afinfo(net
, net
->nft
.ipv6
) < 0)
65 static void nf_tables_ipv6_exit_net(struct net
*net
)
67 nft_unregister_afinfo(net
->nft
.ipv6
);
71 static struct pernet_operations nf_tables_ipv6_net_ops
= {
72 .init
= nf_tables_ipv6_init_net
,
73 .exit
= nf_tables_ipv6_exit_net
,
77 nft_do_chain_ipv6(const struct nf_hook_ops
*ops
,
79 const struct net_device
*in
,
80 const struct net_device
*out
,
81 int (*okfn
)(struct sk_buff
*))
83 struct nft_pktinfo pkt
;
85 /* malformed packet, drop it */
86 if (nft_set_pktinfo_ipv6(&pkt
, ops
, skb
, in
, out
) < 0)
89 return nft_do_chain_pktinfo(&pkt
, ops
);
92 static struct nf_chain_type filter_ipv6
= {
93 .family
= NFPROTO_IPV6
,
95 .type
= NFT_CHAIN_T_DEFAULT
,
96 .hook_mask
= (1 << NF_INET_LOCAL_IN
) |
97 (1 << NF_INET_LOCAL_OUT
) |
98 (1 << NF_INET_FORWARD
) |
99 (1 << NF_INET_PRE_ROUTING
) |
100 (1 << NF_INET_POST_ROUTING
),
102 [NF_INET_LOCAL_IN
] = nft_do_chain_ipv6
,
103 [NF_INET_LOCAL_OUT
] = nft_ipv6_output
,
104 [NF_INET_FORWARD
] = nft_do_chain_ipv6
,
105 [NF_INET_PRE_ROUTING
] = nft_do_chain_ipv6
,
106 [NF_INET_POST_ROUTING
] = nft_do_chain_ipv6
,
110 static int __init
nf_tables_ipv6_init(void)
112 nft_register_chain_type(&filter_ipv6
);
113 return register_pernet_subsys(&nf_tables_ipv6_net_ops
);
116 static void __exit
nf_tables_ipv6_exit(void)
118 unregister_pernet_subsys(&nf_tables_ipv6_net_ops
);
119 nft_unregister_chain_type(&filter_ipv6
);
122 module_init(nf_tables_ipv6_init
);
123 module_exit(nf_tables_ipv6_exit
);
125 MODULE_LICENSE("GPL");
126 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
127 MODULE_ALIAS_NFT_FAMILY(AF_INET6
);