Commit 26461905 authored by Jarno Rajahalme's avatar Jarno Rajahalme Committed by Pablo Neira Ayuso

netfilter: Allow calling into nat helper without skb_dst.

NAT checksum recalculation code assumes existence of skb_dst, which
becomes a problem for a later patch in the series ("openvswitch:
Interface with NAT.").  Simplify this by removing the check on
skb_dst, as the checksum will be dealt with later in the stack.
Suggested-by: default avatarPravin Shelar <pshelar@nicira.com>
Signed-off-by: default avatarJarno Rajahalme <jarno@ovn.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent bfa3f9d7
...@@ -127,29 +127,15 @@ static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb, ...@@ -127,29 +127,15 @@ static void nf_nat_ipv4_csum_recalc(struct sk_buff *skb,
u8 proto, void *data, __sum16 *check, u8 proto, void *data, __sum16 *check,
int datalen, int oldlen) int datalen, int oldlen)
{ {
const struct iphdr *iph = ip_hdr(skb);
struct rtable *rt = skb_rtable(skb);
if (skb->ip_summed != CHECKSUM_PARTIAL) { if (skb->ip_summed != CHECKSUM_PARTIAL) {
if (!(rt->rt_flags & RTCF_LOCAL) && const struct iphdr *iph = ip_hdr(skb);
(!skb->dev || skb->dev->features &
(NETIF_F_IP_CSUM | NETIF_F_HW_CSUM))) { skb->ip_summed = CHECKSUM_PARTIAL;
skb->ip_summed = CHECKSUM_PARTIAL; skb->csum_start = skb_headroom(skb) + skb_network_offset(skb) +
skb->csum_start = skb_headroom(skb) + ip_hdrlen(skb);
skb_network_offset(skb) + skb->csum_offset = (void *)check - data;
ip_hdrlen(skb); *check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, datalen,
skb->csum_offset = (void *)check - data; proto, 0);
*check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
datalen, proto, 0);
} else {
*check = 0;
*check = csum_tcpudp_magic(iph->saddr, iph->daddr,
datalen, proto,
csum_partial(data, datalen,
0));
if (proto == IPPROTO_UDP && !*check)
*check = CSUM_MANGLED_0;
}
} else } else
inet_proto_csum_replace2(check, skb, inet_proto_csum_replace2(check, skb,
htons(oldlen), htons(datalen), true); htons(oldlen), htons(datalen), true);
......
...@@ -131,29 +131,15 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb, ...@@ -131,29 +131,15 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb,
u8 proto, void *data, __sum16 *check, u8 proto, void *data, __sum16 *check,
int datalen, int oldlen) int datalen, int oldlen)
{ {
const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
if (skb->ip_summed != CHECKSUM_PARTIAL) { if (skb->ip_summed != CHECKSUM_PARTIAL) {
if (!(rt->rt6i_flags & RTF_LOCAL) && const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
(!skb->dev || skb->dev->features &
(NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))) { skb->ip_summed = CHECKSUM_PARTIAL;
skb->ip_summed = CHECKSUM_PARTIAL; skb->csum_start = skb_headroom(skb) + skb_network_offset(skb) +
skb->csum_start = skb_headroom(skb) + (data - (void *)skb->data);
skb_network_offset(skb) + skb->csum_offset = (void *)check - data;
(data - (void *)skb->data); *check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
skb->csum_offset = (void *)check - data; datalen, proto, 0);
*check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
datalen, proto, 0);
} else {
*check = 0;
*check = csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
datalen, proto,
csum_partial(data, datalen,
0));
if (proto == IPPROTO_UDP && !*check)
*check = CSUM_MANGLED_0;
}
} else } else
inet_proto_csum_replace2(check, skb, inet_proto_csum_replace2(check, skb,
htons(oldlen), htons(datalen), true); htons(oldlen), htons(datalen), true);
......
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