mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
netfilter: nf_tables: make chain types override the default AF functions
Currently the AF-specific hook functions override the chain-type specific hook functions. That doesn't make too much sense since the chain types are a special case of the AF-specific hooks. Make the AF-specific hook functions the default and make the optional chain type hooks override them. As a side effect, the necessary code restructuring reduces the code size, f.i. in case of nf_tables_ipv4.o: nf_tables_ipv4_init_net | -24 nft_do_chain_ipv4 | -113 2 functions changed, 137 bytes removed, diff: -137 Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
This commit is contained in:
parent
688d18636f
commit
3b088c4bc0
5 changed files with 81 additions and 96 deletions
|
|
@ -16,24 +16,35 @@
|
|||
#include <net/netfilter/nf_tables.h>
|
||||
#include <net/netfilter/nf_tables_ipv6.h>
|
||||
|
||||
static unsigned int nft_do_chain_ipv6(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
/* malformed packet, drop it */
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
|
||||
return NF_DROP;
|
||||
|
||||
return nft_do_chain_pktinfo(&pkt, ops);
|
||||
}
|
||||
|
||||
static unsigned int nft_ipv6_output(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
if (unlikely(skb->len < sizeof(struct ipv6hdr))) {
|
||||
if (net_ratelimit())
|
||||
pr_info("nf_tables_ipv6: ignoring short SOCK_RAW "
|
||||
"packet\n");
|
||||
return NF_ACCEPT;
|
||||
}
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
|
||||
return NF_DROP;
|
||||
|
||||
return nft_do_chain_pktinfo(&pkt, ops);
|
||||
return nft_do_chain_ipv6(ops, skb, in, out, okfn);
|
||||
}
|
||||
|
||||
static struct nft_af_info nft_af_ipv6 __read_mostly = {
|
||||
|
|
@ -41,7 +52,11 @@ static struct nft_af_info nft_af_ipv6 __read_mostly = {
|
|||
.nhooks = NF_INET_NUMHOOKS,
|
||||
.owner = THIS_MODULE,
|
||||
.hooks = {
|
||||
[NF_INET_LOCAL_IN] = nft_do_chain_ipv6,
|
||||
[NF_INET_LOCAL_OUT] = nft_ipv6_output,
|
||||
[NF_INET_FORWARD] = nft_do_chain_ipv6,
|
||||
[NF_INET_PRE_ROUTING] = nft_do_chain_ipv6,
|
||||
[NF_INET_POST_ROUTING] = nft_do_chain_ipv6,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -73,22 +88,6 @@ static struct pernet_operations nf_tables_ipv6_net_ops = {
|
|||
.exit = nf_tables_ipv6_exit_net,
|
||||
};
|
||||
|
||||
static unsigned int
|
||||
nft_do_chain_ipv6(const struct nf_hook_ops *ops,
|
||||
struct sk_buff *skb,
|
||||
const struct net_device *in,
|
||||
const struct net_device *out,
|
||||
int (*okfn)(struct sk_buff *))
|
||||
{
|
||||
struct nft_pktinfo pkt;
|
||||
|
||||
/* malformed packet, drop it */
|
||||
if (nft_set_pktinfo_ipv6(&pkt, ops, skb, in, out) < 0)
|
||||
return NF_DROP;
|
||||
|
||||
return nft_do_chain_pktinfo(&pkt, ops);
|
||||
}
|
||||
|
||||
static struct nf_chain_type filter_ipv6 = {
|
||||
.family = NFPROTO_IPV6,
|
||||
.name = "filter",
|
||||
|
|
@ -98,13 +97,6 @@ static struct nf_chain_type filter_ipv6 = {
|
|||
(1 << NF_INET_FORWARD) |
|
||||
(1 << NF_INET_PRE_ROUTING) |
|
||||
(1 << NF_INET_POST_ROUTING),
|
||||
.fn = {
|
||||
[NF_INET_LOCAL_IN] = nft_do_chain_ipv6,
|
||||
[NF_INET_LOCAL_OUT] = nft_ipv6_output,
|
||||
[NF_INET_FORWARD] = nft_do_chain_ipv6,
|
||||
[NF_INET_PRE_ROUTING] = nft_do_chain_ipv6,
|
||||
[NF_INET_POST_ROUTING] = nft_do_chain_ipv6,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init nf_tables_ipv6_init(void)
|
||||
|
|
|
|||
Loading…
Reference in a new issue