diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 48fd53b98972..b786997a892e 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1098,7 +1098,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, unsigned int max_headroom = psh_hlen; __be16 payload_protocol; bool use_cache = false; - u8 hop_limit; + u8 hop_limit = 0; int err = -1; payload_protocol = skb_protocol(skb, true); @@ -1215,6 +1215,16 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev))); + if (hop_limit == 0) { + if (payload_protocol == htons(ETH_P_IP)) + hop_limit = ip_hdr(skb)->ttl; + else if (payload_protocol == htons(ETH_P_IPV6)) + hop_limit = ipv6_hdr(skb)->hop_limit; + else + hop_limit = ip6_dst_hoplimit(dst); + } + + /* * Okay, now see if we can stuff it in the buffer as-is. */ @@ -1243,15 +1253,6 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, } skb_dst_set(skb, dst); - if (hop_limit == 0) { - if (payload_protocol == htons(ETH_P_IP)) - hop_limit = ip_hdr(skb)->ttl; - else if (payload_protocol == htons(ETH_P_IPV6)) - hop_limit = ipv6_hdr(skb)->hop_limit; - else - hop_limit = ip6_dst_hoplimit(dst); - } - /* Calculate max headroom for all the headers and adjust * needed_headroom if necessary. */