2 * Copyright (c) 2012-2014 Patrick McHardy <kaber@trash.net>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/init.h>
10 #include <linux/module.h>
12 #include <linux/netfilter_ipv4.h>
13 #include <linux/netfilter_ipv6.h>
14 #include <net/netfilter/nf_tables.h>
15 #include <net/netfilter/nf_tables_ipv4.h>
16 #include <net/netfilter/nf_tables_ipv6.h>
19 static void nft_inet_hook_ops_init(struct nf_hook_ops
*ops
, unsigned int n
)
21 struct nft_af_info
*afi
;
28 ops
->pf
= afi
->family
;
29 if (afi
->hooks
[ops
->hooknum
])
30 ops
->hook
= afi
->hooks
[ops
->hooknum
];
33 static struct nft_af_info nft_af_inet __read_mostly
= {
34 .family
= NFPROTO_INET
,
35 .nhooks
= NF_INET_NUMHOOKS
,
38 .hook_ops_init
= nft_inet_hook_ops_init
,
41 static int __net_init
nf_tables_inet_init_net(struct net
*net
)
43 net
->nft
.inet
= kmalloc(sizeof(struct nft_af_info
), GFP_KERNEL
);
44 if (net
->nft
.inet
== NULL
)
46 memcpy(net
->nft
.inet
, &nft_af_inet
, sizeof(nft_af_inet
));
48 if (nft_register_afinfo(net
, net
->nft
.inet
) < 0)
58 static void __net_exit
nf_tables_inet_exit_net(struct net
*net
)
60 nft_unregister_afinfo(net
, net
->nft
.inet
);
64 static struct pernet_operations nf_tables_inet_net_ops
= {
65 .init
= nf_tables_inet_init_net
,
66 .exit
= nf_tables_inet_exit_net
,
69 static const struct nf_chain_type filter_inet
= {
71 .type
= NFT_CHAIN_T_DEFAULT
,
72 .family
= NFPROTO_INET
,
74 .hook_mask
= (1 << NF_INET_LOCAL_IN
) |
75 (1 << NF_INET_LOCAL_OUT
) |
76 (1 << NF_INET_FORWARD
) |
77 (1 << NF_INET_PRE_ROUTING
) |
78 (1 << NF_INET_POST_ROUTING
),
81 static int __init
nf_tables_inet_init(void)
85 ret
= nft_register_chain_type(&filter_inet
);
89 ret
= register_pernet_subsys(&nf_tables_inet_net_ops
);
91 nft_unregister_chain_type(&filter_inet
);
96 static void __exit
nf_tables_inet_exit(void)
98 unregister_pernet_subsys(&nf_tables_inet_net_ops
);
99 nft_unregister_chain_type(&filter_inet
);
102 module_init(nf_tables_inet_init
);
103 module_exit(nf_tables_inet_exit
);
105 MODULE_LICENSE("GPL");
106 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
107 MODULE_ALIAS_NFT_FAMILY(1);