Skip to content

Commit

Permalink
[NETFILTER]: Use conntrack information to determine if packet was NATed
Browse files Browse the repository at this point in the history
Preparation for IPsec support for NAT:
Use conntrack information instead of saving the saving and comparing the
addresses to determine if a packet was NATed and needs to be rerouted to
make it easier to extend the key.

Signed-off-by: Patrick McHardy <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
kaber authored and David S. Miller committed Jan 7, 2006
1 parent 3e3850e commit 4e8e9de
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions net/ipv4/netfilter/ip_nat_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,20 @@ ip_nat_in(unsigned int hooknum,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
u_int32_t saddr, daddr;
struct ip_conntrack *ct;
enum ip_conntrack_info ctinfo;
unsigned int ret;

saddr = (*pskb)->nh.iph->saddr;
daddr = (*pskb)->nh.iph->daddr;

ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
if (ret != NF_DROP && ret != NF_STOLEN
&& ((*pskb)->nh.iph->saddr != saddr
|| (*pskb)->nh.iph->daddr != daddr)) {
dst_release((*pskb)->dst);
(*pskb)->dst = NULL;
&& (ct = ip_conntrack_get(*pskb, &ctinfo)) != NULL) {
enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);

if (ct->tuplehash[dir].tuple.src.ip !=
ct->tuplehash[!dir].tuple.dst.ip) {
dst_release((*pskb)->dst);
(*pskb)->dst = NULL;
}
}
return ret;
}
Expand All @@ -200,22 +202,24 @@ ip_nat_local_fn(unsigned int hooknum,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
u_int32_t saddr, daddr;
struct ip_conntrack *ct;
enum ip_conntrack_info ctinfo;
unsigned int ret;

/* root is playing with raw sockets. */
if ((*pskb)->len < sizeof(struct iphdr)
|| (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
return NF_ACCEPT;

saddr = (*pskb)->nh.iph->saddr;
daddr = (*pskb)->nh.iph->daddr;

ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
if (ret != NF_DROP && ret != NF_STOLEN
&& ((*pskb)->nh.iph->saddr != saddr
|| (*pskb)->nh.iph->daddr != daddr))
return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
&& (ct = ip_conntrack_get(*pskb, &ctinfo)) != NULL) {
enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);

if (ct->tuplehash[dir].tuple.dst.ip !=
ct->tuplehash[!dir].tuple.src.ip)
return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
}
return ret;
}

Expand Down

0 comments on commit 4e8e9de

Please sign in to comment.