2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2012 Pablo Neira Ayuso <pablo@netfilter.org>
4 * Copyright (c) 2012 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Development of this code funded by Astaro AG (http://www.astaro.com/)
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/list.h>
16 #include <linux/skbuff.h>
18 #include <linux/netfilter.h>
19 #include <linux/netfilter_ipv4.h>
20 #include <linux/netfilter/nf_tables.h>
21 #include <net/netfilter/nf_conntrack.h>
22 #include <net/netfilter/nf_nat.h>
23 #include <net/netfilter/nf_nat_core.h>
24 #include <net/netfilter/nf_tables.h>
25 #include <net/netfilter/nf_tables_ipv4.h>
26 #include <net/netfilter/nf_nat_l3proto.h>
29 static unsigned int nft_nat_do_chain(void *priv,
31 const struct nf_hook_state *state)
33 struct nft_pktinfo pkt;
35 nft_set_pktinfo(&pkt, skb, state);
36 nft_set_pktinfo_ipv4(&pkt, skb);
38 return nft_do_chain(&pkt, priv);
41 static int nft_nat_ipv4_reg(struct net *net, const struct nf_hook_ops *ops)
43 return nf_nat_l3proto_ipv4_register_fn(net, ops);
46 static void nft_nat_ipv4_unreg(struct net *net, const struct nf_hook_ops *ops)
48 nf_nat_l3proto_ipv4_unregister_fn(net, ops);
51 static const struct nft_chain_type nft_chain_nat_ipv4 = {
53 .type = NFT_CHAIN_T_NAT,
54 .family = NFPROTO_IPV4,
56 .hook_mask = (1 << NF_INET_PRE_ROUTING) |
57 (1 << NF_INET_POST_ROUTING) |
58 (1 << NF_INET_LOCAL_OUT) |
59 (1 << NF_INET_LOCAL_IN),
61 [NF_INET_PRE_ROUTING] = nft_nat_do_chain,
62 [NF_INET_POST_ROUTING] = nft_nat_do_chain,
63 [NF_INET_LOCAL_OUT] = nft_nat_do_chain,
64 [NF_INET_LOCAL_IN] = nft_nat_do_chain,
66 .ops_register = nft_nat_ipv4_reg,
67 .ops_unregister = nft_nat_ipv4_unreg,
70 static int __init nft_chain_nat_init(void)
72 nft_register_chain_type(&nft_chain_nat_ipv4);
77 static void __exit nft_chain_nat_exit(void)
79 nft_unregister_chain_type(&nft_chain_nat_ipv4);
82 module_init(nft_chain_nat_init);
83 module_exit(nft_chain_nat_exit);
85 MODULE_LICENSE("GPL");
86 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
87 MODULE_ALIAS_NFT_CHAIN(AF_INET, "nat");