ip6erspan_tunnel_xmit() uses skb->protocol to select the inner header for traffic class and flow label inheritance, length checks and ICMP errors. ip6_tnl_xmit() uses it to select the minimum MTU. When the protocol is a VLAN EtherType, a tagged IPv4 packet can lose its traffic class and take the ICMPv6 error path on -EMSGSIZE. Use the payload protocol classified on entry to the tunnel. For IPv4 and IPv6 the classifier has pulled the header and set or preserved the network header offset. On -EMSGSIZE, send Fragmentation Needed for IPv4 and Packet Too Big for IPv6. Other payloads have no inner IP source to notify, so let them take the usual transmit error path. An AI review of an earlier version identified the traffic class issue. In VM tests with tclass inherit, a tagged IPv4 packet with TOS 0xb8 had outer traffic class 0 on ip6erspan v1 and v2. With this change it has traffic class 0xb8, as it does without a tag. On native ip6erspan v1, an oversized ARP frame took the ICMPv6 error path with the old unconditional else, both with and without an 802.1Q tag. With the IPv6 check both frames were dropped without calling either ICMP handler. For both tag layouts the IPv4 sender received Fragmentation Needed and the IPv6 sender received Packet Too Big. Each error quoted the original Echo Request and advertised MTU 1338. Signed-off-by: Anton Danilov --- net/ipv6/ip6_gre.c | 10 +++++----- net/ipv6/ip6_tunnel.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index c413e47c6ceb..0ecee2271bbd 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -1021,11 +1021,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, } nhoff = skb_network_offset(skb); - if (skb->protocol == htons(ETH_P_IP) && + if (payload_protocol == htons(ETH_P_IP) && (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff)) truncate = true; - if (skb->protocol == htons(ETH_P_IPV6)) { + if (payload_protocol == htons(ETH_P_IPV6)) { int thoff; if (skb_transport_header_was_set(skb)) @@ -1087,7 +1087,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, goto tx_err; } } else { - switch (skb->protocol) { + switch (payload_protocol) { case htons(ETH_P_IP): memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); prepare_ip6gre_xmit_ipv4(skb, dev, &fl6, @@ -1132,10 +1132,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, if (err != 0) { /* XXX: send ICMP error even if DF is not set. */ if (err == -EMSGSIZE) { - if (skb->protocol == htons(ETH_P_IP)) + if (payload_protocol == htons(ETH_P_IP)) icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); - else + else if (payload_protocol == htons(ETH_P_IPV6)) icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); } diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 931911b5e8a8..3d8b2d5851ef 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1227,7 +1227,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, max_headroom += 8; mtu -= 8; } - mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ? + mtu = max(mtu, payload_protocol == htons(ETH_P_IPV6) ? IPV6_MIN_MTU : IPV4_MIN_MTU); skb_dst_update_pmtu_no_confirm(skb, mtu); -- 2.47.3