Commit 8844e010 authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: iptables: allow use of ipt_do_table as hookfn

This is possible now that the xt_table structure is passed in via *priv.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 0d7308c0
...@@ -63,9 +63,9 @@ struct ipt_error { ...@@ -63,9 +63,9 @@ struct ipt_error {
} }
extern void *ipt_alloc_initial_table(const struct xt_table *); extern void *ipt_alloc_initial_table(const struct xt_table *);
extern unsigned int ipt_do_table(struct sk_buff *skb, extern unsigned int ipt_do_table(void *priv,
const struct nf_hook_state *state, struct sk_buff *skb,
struct xt_table *table); const struct nf_hook_state *state);
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
#include <net/compat.h> #include <net/compat.h>
......
...@@ -222,10 +222,11 @@ struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry) ...@@ -222,10 +222,11 @@ struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
/* Returns one of the generic firewall policies, like NF_ACCEPT. */ /* Returns one of the generic firewall policies, like NF_ACCEPT. */
unsigned int unsigned int
ipt_do_table(struct sk_buff *skb, ipt_do_table(void *priv,
const struct nf_hook_state *state, struct sk_buff *skb,
struct xt_table *table) const struct nf_hook_state *state)
{ {
const struct xt_table *table = priv;
unsigned int hook = state->hook; unsigned int hook = state->hook;
static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long)))); static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
const struct iphdr *ip; const struct iphdr *ip;
......
...@@ -28,13 +28,6 @@ static const struct xt_table packet_filter = { ...@@ -28,13 +28,6 @@ static const struct xt_table packet_filter = {
.priority = NF_IP_PRI_FILTER, .priority = NF_IP_PRI_FILTER,
}; };
static unsigned int
iptable_filter_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
}
static struct nf_hook_ops *filter_ops __read_mostly; static struct nf_hook_ops *filter_ops __read_mostly;
/* Default to forward because I got too much mail already. */ /* Default to forward because I got too much mail already. */
...@@ -90,7 +83,7 @@ static int __init iptable_filter_init(void) ...@@ -90,7 +83,7 @@ static int __init iptable_filter_init(void)
if (ret < 0) if (ret < 0)
return ret; return ret;
filter_ops = xt_hook_ops_alloc(&packet_filter, iptable_filter_hook); filter_ops = xt_hook_ops_alloc(&packet_filter, ipt_do_table);
if (IS_ERR(filter_ops)) { if (IS_ERR(filter_ops)) {
xt_unregister_template(&packet_filter); xt_unregister_template(&packet_filter);
return PTR_ERR(filter_ops); return PTR_ERR(filter_ops);
......
...@@ -34,7 +34,7 @@ static const struct xt_table packet_mangler = { ...@@ -34,7 +34,7 @@ static const struct xt_table packet_mangler = {
}; };
static unsigned int static unsigned int
ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state, void *priv) ipt_mangle_out(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{ {
unsigned int ret; unsigned int ret;
const struct iphdr *iph; const struct iphdr *iph;
...@@ -50,7 +50,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state, void *pri ...@@ -50,7 +50,7 @@ ipt_mangle_out(struct sk_buff *skb, const struct nf_hook_state *state, void *pri
daddr = iph->daddr; daddr = iph->daddr;
tos = iph->tos; tos = iph->tos;
ret = ipt_do_table(skb, state, priv); ret = ipt_do_table(priv, skb, state);
/* Reroute for ANY change. */ /* Reroute for ANY change. */
if (ret != NF_DROP && ret != NF_STOLEN) { if (ret != NF_DROP && ret != NF_STOLEN) {
iph = ip_hdr(skb); iph = ip_hdr(skb);
...@@ -75,8 +75,8 @@ iptable_mangle_hook(void *priv, ...@@ -75,8 +75,8 @@ iptable_mangle_hook(void *priv,
const struct nf_hook_state *state) const struct nf_hook_state *state)
{ {
if (state->hook == NF_INET_LOCAL_OUT) if (state->hook == NF_INET_LOCAL_OUT)
return ipt_mangle_out(skb, state, priv); return ipt_mangle_out(priv, skb, state);
return ipt_do_table(skb, state, priv); return ipt_do_table(priv, skb, state);
} }
static struct nf_hook_ops *mangle_ops __read_mostly; static struct nf_hook_ops *mangle_ops __read_mostly;
......
...@@ -29,34 +29,27 @@ static const struct xt_table nf_nat_ipv4_table = { ...@@ -29,34 +29,27 @@ static const struct xt_table nf_nat_ipv4_table = {
.af = NFPROTO_IPV4, .af = NFPROTO_IPV4,
}; };
static unsigned int iptable_nat_do_chain(void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
}
static const struct nf_hook_ops nf_nat_ipv4_ops[] = { static const struct nf_hook_ops nf_nat_ipv4_ops[] = {
{ {
.hook = iptable_nat_do_chain, .hook = ipt_do_table,
.pf = NFPROTO_IPV4, .pf = NFPROTO_IPV4,
.hooknum = NF_INET_PRE_ROUTING, .hooknum = NF_INET_PRE_ROUTING,
.priority = NF_IP_PRI_NAT_DST, .priority = NF_IP_PRI_NAT_DST,
}, },
{ {
.hook = iptable_nat_do_chain, .hook = ipt_do_table,
.pf = NFPROTO_IPV4, .pf = NFPROTO_IPV4,
.hooknum = NF_INET_POST_ROUTING, .hooknum = NF_INET_POST_ROUTING,
.priority = NF_IP_PRI_NAT_SRC, .priority = NF_IP_PRI_NAT_SRC,
}, },
{ {
.hook = iptable_nat_do_chain, .hook = ipt_do_table,
.pf = NFPROTO_IPV4, .pf = NFPROTO_IPV4,
.hooknum = NF_INET_LOCAL_OUT, .hooknum = NF_INET_LOCAL_OUT,
.priority = NF_IP_PRI_NAT_DST, .priority = NF_IP_PRI_NAT_DST,
}, },
{ {
.hook = iptable_nat_do_chain, .hook = ipt_do_table,
.pf = NFPROTO_IPV4, .pf = NFPROTO_IPV4,
.hooknum = NF_INET_LOCAL_IN, .hooknum = NF_INET_LOCAL_IN,
.priority = NF_IP_PRI_NAT_SRC, .priority = NF_IP_PRI_NAT_SRC,
......
...@@ -32,14 +32,6 @@ static const struct xt_table packet_raw_before_defrag = { ...@@ -32,14 +32,6 @@ static const struct xt_table packet_raw_before_defrag = {
.priority = NF_IP_PRI_RAW_BEFORE_DEFRAG, .priority = NF_IP_PRI_RAW_BEFORE_DEFRAG,
}; };
/* The work comes in here from netfilter.c. */
static unsigned int
iptable_raw_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
}
static struct nf_hook_ops *rawtable_ops __read_mostly; static struct nf_hook_ops *rawtable_ops __read_mostly;
static int iptable_raw_table_init(struct net *net) static int iptable_raw_table_init(struct net *net)
...@@ -90,7 +82,7 @@ static int __init iptable_raw_init(void) ...@@ -90,7 +82,7 @@ static int __init iptable_raw_init(void)
if (ret < 0) if (ret < 0)
return ret; return ret;
rawtable_ops = xt_hook_ops_alloc(table, iptable_raw_hook); rawtable_ops = xt_hook_ops_alloc(table, ipt_do_table);
if (IS_ERR(rawtable_ops)) { if (IS_ERR(rawtable_ops)) {
xt_unregister_template(table); xt_unregister_template(table);
return PTR_ERR(rawtable_ops); return PTR_ERR(rawtable_ops);
......
...@@ -33,13 +33,6 @@ static const struct xt_table security_table = { ...@@ -33,13 +33,6 @@ static const struct xt_table security_table = {
.priority = NF_IP_PRI_SECURITY, .priority = NF_IP_PRI_SECURITY,
}; };
static unsigned int
iptable_security_hook(void *priv, struct sk_buff *skb,
const struct nf_hook_state *state)
{
return ipt_do_table(skb, state, priv);
}
static struct nf_hook_ops *sectbl_ops __read_mostly; static struct nf_hook_ops *sectbl_ops __read_mostly;
static int iptable_security_table_init(struct net *net) static int iptable_security_table_init(struct net *net)
...@@ -78,7 +71,7 @@ static int __init iptable_security_init(void) ...@@ -78,7 +71,7 @@ static int __init iptable_security_init(void)
if (ret < 0) if (ret < 0)
return ret; return ret;
sectbl_ops = xt_hook_ops_alloc(&security_table, iptable_security_hook); sectbl_ops = xt_hook_ops_alloc(&security_table, ipt_do_table);
if (IS_ERR(sectbl_ops)) { if (IS_ERR(sectbl_ops)) {
xt_unregister_template(&security_table); xt_unregister_template(&security_table);
return PTR_ERR(sectbl_ops); return PTR_ERR(sectbl_ops);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment