提交 cc01dcbd 编写于 作者: P Patrick McHardy 提交者: David S. Miller

[NETFILTER]: nf_nat: pass manip type instead of hook to nf_nat_setup_info

nf_nat_setup_info gets the hook number and translates that to the
manip type to perform. This is a relict from the time when one
manip per hook could exist, the exact hook number doesn't matter
anymore, its converted to the manip type. Most callers already
know what kind of NAT they want to perform, so pass the maniptype
in directly.
Signed-off-by: NPatrick McHardy <kaber@trash.net>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 ce4b1ceb
...@@ -80,7 +80,7 @@ struct nf_conn_nat ...@@ -80,7 +80,7 @@ struct nf_conn_nat
/* Set up the info structure to map into this range. */ /* Set up the info structure to map into this range. */
extern unsigned int nf_nat_setup_info(struct nf_conn *ct, extern unsigned int nf_nat_setup_info(struct nf_conn *ct,
const struct nf_nat_range *range, const struct nf_nat_range *range,
unsigned int hooknum); enum nf_nat_manip_type maniptype);
/* Is this tuple already taken? (not by us)*/ /* Is this tuple already taken? (not by us)*/
extern int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple, extern int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
......
...@@ -95,7 +95,7 @@ masquerade_tg(struct sk_buff *skb, const struct net_device *in, ...@@ -95,7 +95,7 @@ masquerade_tg(struct sk_buff *skb, const struct net_device *in,
mr->range[0].min, mr->range[0].max }); mr->range[0].min, mr->range[0].max });
/* Hand modified range to generic setup. */ /* Hand modified range to generic setup. */
return nf_nat_setup_info(ct, &newrange, hooknum); return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_SRC);
} }
static int static int
......
...@@ -70,7 +70,7 @@ netmap_tg(struct sk_buff *skb, const struct net_device *in, ...@@ -70,7 +70,7 @@ netmap_tg(struct sk_buff *skb, const struct net_device *in,
mr->range[0].min, mr->range[0].max }); mr->range[0].min, mr->range[0].max });
/* Hand modified range to generic setup. */ /* Hand modified range to generic setup. */
return nf_nat_setup_info(ct, &newrange, hooknum); return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(hooknum));
} }
static struct xt_target netmap_tg_reg __read_mostly = { static struct xt_target netmap_tg_reg __read_mostly = {
......
...@@ -87,7 +87,7 @@ redirect_tg(struct sk_buff *skb, const struct net_device *in, ...@@ -87,7 +87,7 @@ redirect_tg(struct sk_buff *skb, const struct net_device *in,
mr->range[0].min, mr->range[0].max }); mr->range[0].min, mr->range[0].max });
/* Hand modified range to generic setup. */ /* Hand modified range to generic setup. */
return nf_nat_setup_info(ct, &newrange, hooknum); return nf_nat_setup_info(ct, &newrange, IP_NAT_MANIP_DST);
} }
static struct xt_target redirect_tg_reg __read_mostly = { static struct xt_target redirect_tg_reg __read_mostly = {
......
...@@ -277,12 +277,11 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, ...@@ -277,12 +277,11 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
unsigned int unsigned int
nf_nat_setup_info(struct nf_conn *ct, nf_nat_setup_info(struct nf_conn *ct,
const struct nf_nat_range *range, const struct nf_nat_range *range,
unsigned int hooknum) enum nf_nat_manip_type maniptype)
{ {
struct nf_conntrack_tuple curr_tuple, new_tuple; struct nf_conntrack_tuple curr_tuple, new_tuple;
struct nf_conn_nat *nat; struct nf_conn_nat *nat;
int have_to_hash = !(ct->status & IPS_NAT_DONE_MASK); int have_to_hash = !(ct->status & IPS_NAT_DONE_MASK);
enum nf_nat_manip_type maniptype = HOOK2MANIP(hooknum);
/* nat helper or nfctnetlink also setup binding */ /* nat helper or nfctnetlink also setup binding */
nat = nfct_nat(ct); nat = nfct_nat(ct);
...@@ -294,10 +293,8 @@ nf_nat_setup_info(struct nf_conn *ct, ...@@ -294,10 +293,8 @@ nf_nat_setup_info(struct nf_conn *ct,
} }
} }
NF_CT_ASSERT(hooknum == NF_INET_PRE_ROUTING || NF_CT_ASSERT(maniptype == IP_NAT_MANIP_SRC ||
hooknum == NF_INET_POST_ROUTING || maniptype == IP_NAT_MANIP_DST);
hooknum == NF_INET_LOCAL_IN ||
hooknum == NF_INET_LOCAL_OUT);
BUG_ON(nf_nat_initialized(ct, maniptype)); BUG_ON(nf_nat_initialized(ct, maniptype));
/* What we've got will look like inverse of reply. Normally /* What we've got will look like inverse of reply. Normally
......
...@@ -389,18 +389,14 @@ static void ip_nat_q931_expect(struct nf_conn *new, ...@@ -389,18 +389,14 @@ static void ip_nat_q931_expect(struct nf_conn *new,
/* Change src to where master sends to */ /* Change src to where master sends to */
range.flags = IP_NAT_RANGE_MAP_IPS; range.flags = IP_NAT_RANGE_MAP_IPS;
range.min_ip = range.max_ip = new->tuplehash[!this->dir].tuple.src.u3.ip; range.min_ip = range.max_ip = new->tuplehash[!this->dir].tuple.src.u3.ip;
nf_nat_setup_info(new, &range, IP_NAT_MANIP_SRC);
/* hook doesn't matter, but it has to do source manip */
nf_nat_setup_info(new, &range, NF_INET_POST_ROUTING);
/* For DST manip, map port here to where it's expected. */ /* For DST manip, map port here to where it's expected. */
range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED); range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
range.min = range.max = this->saved_proto; range.min = range.max = this->saved_proto;
range.min_ip = range.max_ip = range.min_ip = range.max_ip =
new->master->tuplehash[!this->dir].tuple.src.u3.ip; new->master->tuplehash[!this->dir].tuple.src.u3.ip;
nf_nat_setup_info(new, &range, IP_NAT_MANIP_DST);
/* hook doesn't matter, but it has to do destination manip */
nf_nat_setup_info(new, &range, NF_INET_PRE_ROUTING);
} }
/****************************************************************************/ /****************************************************************************/
...@@ -479,17 +475,13 @@ static void ip_nat_callforwarding_expect(struct nf_conn *new, ...@@ -479,17 +475,13 @@ static void ip_nat_callforwarding_expect(struct nf_conn *new,
/* Change src to where master sends to */ /* Change src to where master sends to */
range.flags = IP_NAT_RANGE_MAP_IPS; range.flags = IP_NAT_RANGE_MAP_IPS;
range.min_ip = range.max_ip = new->tuplehash[!this->dir].tuple.src.u3.ip; range.min_ip = range.max_ip = new->tuplehash[!this->dir].tuple.src.u3.ip;
nf_nat_setup_info(new, &range, IP_NAT_MANIP_SRC);
/* hook doesn't matter, but it has to do source manip */
nf_nat_setup_info(new, &range, NF_INET_POST_ROUTING);
/* For DST manip, map port here to where it's expected. */ /* For DST manip, map port here to where it's expected. */
range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED); range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
range.min = range.max = this->saved_proto; range.min = range.max = this->saved_proto;
range.min_ip = range.max_ip = this->saved_ip; range.min_ip = range.max_ip = this->saved_ip;
nf_nat_setup_info(new, &range, IP_NAT_MANIP_DST);
/* hook doesn't matter, but it has to do destination manip */
nf_nat_setup_info(new, &range, NF_INET_PRE_ROUTING);
} }
/****************************************************************************/ /****************************************************************************/
......
...@@ -433,15 +433,13 @@ void nf_nat_follow_master(struct nf_conn *ct, ...@@ -433,15 +433,13 @@ void nf_nat_follow_master(struct nf_conn *ct,
range.flags = IP_NAT_RANGE_MAP_IPS; range.flags = IP_NAT_RANGE_MAP_IPS;
range.min_ip = range.max_ip range.min_ip = range.max_ip
= ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip; = ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip;
/* hook doesn't matter, but it has to do source manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
nf_nat_setup_info(ct, &range, NF_INET_POST_ROUTING);
/* For DST manip, map port here to where it's expected. */ /* For DST manip, map port here to where it's expected. */
range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED); range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
range.min = range.max = exp->saved_proto; range.min = range.max = exp->saved_proto;
range.min_ip = range.max_ip range.min_ip = range.max_ip
= ct->master->tuplehash[!exp->dir].tuple.src.u3.ip; = ct->master->tuplehash[!exp->dir].tuple.src.u3.ip;
/* hook doesn't matter, but it has to do destination manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
nf_nat_setup_info(ct, &range, NF_INET_PRE_ROUTING);
} }
EXPORT_SYMBOL(nf_nat_follow_master); EXPORT_SYMBOL(nf_nat_follow_master);
...@@ -93,8 +93,7 @@ static void pptp_nat_expected(struct nf_conn *ct, ...@@ -93,8 +93,7 @@ static void pptp_nat_expected(struct nf_conn *ct,
range.flags |= IP_NAT_RANGE_PROTO_SPECIFIED; range.flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
range.min = range.max = exp->saved_proto; range.min = range.max = exp->saved_proto;
} }
/* hook doesn't matter, but it has to do source manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
nf_nat_setup_info(ct, &range, NF_INET_POST_ROUTING);
/* For DST manip, map port here to where it's expected. */ /* For DST manip, map port here to where it's expected. */
range.flags = IP_NAT_RANGE_MAP_IPS; range.flags = IP_NAT_RANGE_MAP_IPS;
...@@ -104,8 +103,7 @@ static void pptp_nat_expected(struct nf_conn *ct, ...@@ -104,8 +103,7 @@ static void pptp_nat_expected(struct nf_conn *ct,
range.flags |= IP_NAT_RANGE_PROTO_SPECIFIED; range.flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
range.min = range.max = exp->saved_proto; range.min = range.max = exp->saved_proto;
} }
/* hook doesn't matter, but it has to do destination manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
nf_nat_setup_info(ct, &range, NF_INET_PRE_ROUTING);
} }
/* outbound packets == from PNS to PAC */ /* outbound packets == from PNS to PAC */
......
...@@ -87,7 +87,7 @@ static unsigned int ipt_snat_target(struct sk_buff *skb, ...@@ -87,7 +87,7 @@ static unsigned int ipt_snat_target(struct sk_buff *skb,
ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY));
NF_CT_ASSERT(out); NF_CT_ASSERT(out);
return nf_nat_setup_info(ct, &mr->range[0], hooknum); return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_SRC);
} }
/* Before 2.6.11 we did implicit source NAT if required. Warn about change. */ /* Before 2.6.11 we did implicit source NAT if required. Warn about change. */
...@@ -133,7 +133,7 @@ static unsigned int ipt_dnat_target(struct sk_buff *skb, ...@@ -133,7 +133,7 @@ static unsigned int ipt_dnat_target(struct sk_buff *skb,
warn_if_extra_mangle(ip_hdr(skb)->daddr, warn_if_extra_mangle(ip_hdr(skb)->daddr,
mr->range[0].min_ip); mr->range[0].min_ip);
return nf_nat_setup_info(ct, &mr->range[0], hooknum); return nf_nat_setup_info(ct, &mr->range[0], IP_NAT_MANIP_DST);
} }
static bool ipt_snat_checkentry(const char *tablename, static bool ipt_snat_checkentry(const char *tablename,
...@@ -184,7 +184,7 @@ alloc_null_binding(struct nf_conn *ct, unsigned int hooknum) ...@@ -184,7 +184,7 @@ alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)
pr_debug("Allocating NULL binding for %p (%u.%u.%u.%u)\n", pr_debug("Allocating NULL binding for %p (%u.%u.%u.%u)\n",
ct, NIPQUAD(ip)); ct, NIPQUAD(ip));
return nf_nat_setup_info(ct, &range, hooknum); return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum));
} }
unsigned int unsigned int
...@@ -203,7 +203,7 @@ alloc_null_binding_confirmed(struct nf_conn *ct, unsigned int hooknum) ...@@ -203,7 +203,7 @@ alloc_null_binding_confirmed(struct nf_conn *ct, unsigned int hooknum)
pr_debug("Allocating NULL binding for confirmed %p (%u.%u.%u.%u)\n", pr_debug("Allocating NULL binding for confirmed %p (%u.%u.%u.%u)\n",
ct, NIPQUAD(ip)); ct, NIPQUAD(ip));
return nf_nat_setup_info(ct, &range, hooknum); return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum));
} }
int nf_nat_rule_find(struct sk_buff *skb, int nf_nat_rule_find(struct sk_buff *skb,
......
...@@ -228,15 +228,13 @@ static void ip_nat_sdp_expect(struct nf_conn *ct, ...@@ -228,15 +228,13 @@ static void ip_nat_sdp_expect(struct nf_conn *ct,
range.flags = IP_NAT_RANGE_MAP_IPS; range.flags = IP_NAT_RANGE_MAP_IPS;
range.min_ip = range.max_ip range.min_ip = range.max_ip
= ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip; = ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip;
/* hook doesn't matter, but it has to do source manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
nf_nat_setup_info(ct, &range, NF_INET_POST_ROUTING);
/* For DST manip, map port here to where it's expected. */ /* For DST manip, map port here to where it's expected. */
range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED); range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
range.min = range.max = exp->saved_proto; range.min = range.max = exp->saved_proto;
range.min_ip = range.max_ip = exp->saved_ip; range.min_ip = range.max_ip = exp->saved_ip;
/* hook doesn't matter, but it has to do destination manip */ nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
nf_nat_setup_info(ct, &range, NF_INET_PRE_ROUTING);
} }
/* So, this packet has hit the connection tracking matching code. /* So, this packet has hit the connection tracking matching code.
......
...@@ -918,19 +918,17 @@ ctnetlink_change_status(struct nf_conn *ct, struct nlattr *cda[]) ...@@ -918,19 +918,17 @@ ctnetlink_change_status(struct nf_conn *ct, struct nlattr *cda[])
if (nfnetlink_parse_nat(cda[CTA_NAT_DST], ct, if (nfnetlink_parse_nat(cda[CTA_NAT_DST], ct,
&range) < 0) &range) < 0)
return -EINVAL; return -EINVAL;
if (nf_nat_initialized(ct, if (nf_nat_initialized(ct, IP_NAT_MANIP_DST))
HOOK2MANIP(NF_INET_PRE_ROUTING)))
return -EEXIST; return -EEXIST;
nf_nat_setup_info(ct, &range, NF_INET_PRE_ROUTING); nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
} }
if (cda[CTA_NAT_SRC]) { if (cda[CTA_NAT_SRC]) {
if (nfnetlink_parse_nat(cda[CTA_NAT_SRC], ct, if (nfnetlink_parse_nat(cda[CTA_NAT_SRC], ct,
&range) < 0) &range) < 0)
return -EINVAL; return -EINVAL;
if (nf_nat_initialized(ct, if (nf_nat_initialized(ct, IP_NAT_MANIP_SRC))
HOOK2MANIP(NF_INET_POST_ROUTING)))
return -EEXIST; return -EEXIST;
nf_nat_setup_info(ct, &range, NF_INET_POST_ROUTING); nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
} }
#endif #endif
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册