From nobody Sat Apr 18 21:01:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0B79CCA480 for ; Mon, 11 Jul 2022 09:34:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232727AbiGKJe4 (ORCPT ); Mon, 11 Jul 2022 05:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232894AbiGKJdY (ORCPT ); Mon, 11 Jul 2022 05:33:24 -0400 Received: from mx08-0057a101.pphosted.com (mx08-0057a101.pphosted.com [185.183.31.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAAFC48CAF; Mon, 11 Jul 2022 02:18:02 -0700 (PDT) Received: from pps.filterd (m0214196.ppops.net [127.0.0.1]) by mx07-0057a101.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26B7hBTa008991; Mon, 11 Jul 2022 11:17:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=westermo.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=12052020; bh=dOKOgT8uYEst4dpp+xBHWU6voFeMpKr78Y/1VjHo7z0=; b=ioAZ9/zRv1y59+VRk3agFw1oBVBK/hL5fLcCxppgmRqMmLUhLFyyrpK13NsX1H+NFFX2 Y44qPgVy/DHsPjF5KVH0JvgtaaN4+ZVKKO/h3a/hVRqSMGzuebLmwsXhObPrl8NvI2t7 VRAemqT3+YhRECdyNvWWVkpR0+eOTDLv8Es8ARFqJy5muulUazjO9IBGU0pQMlB6RD+N cSobmrbTSVO4Xp0YX/PlBAiWHPQGjQLJBFgNUNM9ntwrnnmLWxhC7+cU4Vtm+lmA8LkE Nvwat9O8S1L9pHIdUgkWHOkJOilQRrNR4m1udb5+E9D4yOh7I92pqXuBZioigudblYTw Vw== Received: from mail.beijerelectronics.com ([195.67.87.131]) by mx07-0057a101.pphosted.com (PPS) with ESMTPS id 3h6wp61x7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 11 Jul 2022 11:17:40 +0200 Received: from Orpheus.nch.westermo.com (172.29.100.2) by EX01GLOBAL.beijerelectronics.com (10.101.10.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.2375.17; Mon, 11 Jul 2022 11:17:39 +0200 From: Matthias May To: CC: , , , , , , , Matthias May Subject: [PATCH 1/4 v3 net-next] ip_tunnel: allow to inherit from VLAN encapsulated IP Date: Mon, 11 Jul 2022 11:17:19 +0200 Message-ID: <20220711091722.14485-2-matthias.may@westermo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220711091722.14485-1-matthias.may@westermo.com> References: <20220711091722.14485-1-matthias.may@westermo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.29.100.2] X-ClientProxiedBy: wsevst-s0023.westermo.com (192.168.130.120) To EX01GLOBAL.beijerelectronics.com (10.101.10.25) X-Proofpoint-ORIG-GUID: q9xWnP5NGaI7zblKRpbibQgsZYxlOt2M X-Proofpoint-GUID: q9xWnP5NGaI7zblKRpbibQgsZYxlOt2M Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code allows to inherit the TOS, TTL, DF from the payload when skb->protocol is ETH_P_IP or ETH_P_IPV6. However when the payload is VLAN encapsulated (e.g because the tunnel is of type GRETAP), then this inheriting does not work, because the visible skb->protocol is of type ETH_P_8021Q or ETH_P_8021AD. Instead of skb->protocol, use skb_protocol(). Signed-off-by: Matthias May --- v2 -> v3: - Instead of manual parsing, use skb_protocol() as suggested by Eyal Birger v1 -> v2: - Add support for ETH_P_8021AD as suggested by Jakub Kicinski. --- net/ipv4/ip_tunnel.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 94017a8c3994..dbe18c16b9f6 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -641,6 +641,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_dev= ice *dev, const struct iphdr *inner_iph; unsigned int max_headroom; /* The extra header space needed */ struct rtable *rt =3D NULL; /* Route to the other host */ + __be16 payload_protocol; bool use_cache =3D false; struct flowi4 fl4; bool md =3D false; @@ -651,6 +652,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_dev= ice *dev, =20 inner_iph =3D (const struct iphdr *)skb_inner_network_header(skb); connected =3D (tunnel->parms.iph.daddr !=3D 0); + payload_protocol =3D skb_protocol(skb, true); =20 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); =20 @@ -670,13 +672,12 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_d= evice *dev, dst =3D tun_info->key.u.ipv4.dst; md =3D true; connected =3D true; - } - else if (skb->protocol =3D=3D htons(ETH_P_IP)) { + } else if (payload_protocol =3D=3D htons(ETH_P_IP)) { rt =3D skb_rtable(skb); dst =3D rt_nexthop(rt, inner_iph->daddr); } #if IS_ENABLED(CONFIG_IPV6) - else if (skb->protocol =3D=3D htons(ETH_P_IPV6)) { + else if (payload_protocol =3D=3D htons(ETH_P_IPV6)) { const struct in6_addr *addr6; struct neighbour *neigh; bool do_tx_error_icmp; @@ -716,10 +717,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_d= evice *dev, tos =3D tnl_params->tos; if (tos & 0x1) { tos &=3D ~0x1; - if (skb->protocol =3D=3D htons(ETH_P_IP)) { + if (payload_protocol =3D=3D htons(ETH_P_IP)) { tos =3D inner_iph->tos; connected =3D false; - } else if (skb->protocol =3D=3D htons(ETH_P_IPV6)) { + } else if (payload_protocol =3D=3D htons(ETH_P_IPV6)) { tos =3D ipv6_get_dsfield((const struct ipv6hdr *)inner_iph); connected =3D false; } @@ -765,7 +766,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_dev= ice *dev, } =20 df =3D tnl_params->frag_off; - if (skb->protocol =3D=3D htons(ETH_P_IP) && !tunnel->ignore_df) + if (payload_protocol =3D=3D htons(ETH_P_IP) && !tunnel->ignore_df) df |=3D (inner_iph->frag_off & htons(IP_DF)); =20 if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, 0, 0, false)) { @@ -786,10 +787,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_d= evice *dev, tos =3D ip_tunnel_ecn_encap(tos, inner_iph, skb); ttl =3D tnl_params->ttl; if (ttl =3D=3D 0) { - if (skb->protocol =3D=3D htons(ETH_P_IP)) + if (payload_protocol =3D=3D htons(ETH_P_IP)) ttl =3D inner_iph->ttl; #if IS_ENABLED(CONFIG_IPV6) - else if (skb->protocol =3D=3D htons(ETH_P_IPV6)) + else if (payload_protocol =3D=3D htons(ETH_P_IPV6)) ttl =3D ((const struct ipv6hdr *)inner_iph)->hop_limit; #endif else --=20 2.35.1 From nobody Sat Apr 18 21:01:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E352C433EF for ; Mon, 11 Jul 2022 09:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbiGKJex (ORCPT ); Mon, 11 Jul 2022 05:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232897AbiGKJdY (ORCPT ); Mon, 11 Jul 2022 05:33:24 -0400 Received: from mx08-0057a101.pphosted.com (mx08-0057a101.pphosted.com [185.183.31.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DC47AC08; Mon, 11 Jul 2022 02:18:02 -0700 (PDT) Received: from pps.filterd (m0214196.ppops.net [127.0.0.1]) by mx07-0057a101.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26B5tOZi024300; Mon, 11 Jul 2022 11:17:42 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=westermo.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=12052020; bh=shaOQQbPhoHi9LUOr7y8jZFfkryYxuyVMRZCJiTHuj8=; b=uSxCHcol8BaecD5lwAL3r4OWekg2DUe+Yn9aeVgdI6EpjT7IABqx308JEIVN4RsYTDpP zBZovdMTSUSkt9ImSHA5TNR2PAXiMXVAgUYkix3gqbLT1b3JkoF6JjEbbX6Bl97/1CQg ziE6hdY+w5ajNE+RgYK6e6Ch+2nXMuCsEohHdoZRdO4t+mb10TU0ED10mYHQ1ZkdU5Pu N4Jv2ktigrNXrIx+diDZzZtRK6GSRp3i16PkmBJRC1+VTSxRHa0x972fMBNJqtxJKt2J S/mYmIhjDKcHmt1f97YEOAyJ3TpIZWEY4gnZuQIIMs0VVl0czgvZD+jAxbdSAu6449R4 IA== Received: from mail.beijerelectronics.com ([195.67.87.131]) by mx07-0057a101.pphosted.com (PPS) with ESMTPS id 3h6wp61x80-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 11 Jul 2022 11:17:42 +0200 Received: from Orpheus.nch.westermo.com (172.29.100.2) by EX01GLOBAL.beijerelectronics.com (10.101.10.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.2375.17; Mon, 11 Jul 2022 11:17:41 +0200 From: Matthias May To: CC: , , , , , , , Matthias May Subject: [PATCH 2/4 net-next] ip6_gre: set DSCP for non-IP Date: Mon, 11 Jul 2022 11:17:20 +0200 Message-ID: <20220711091722.14485-3-matthias.may@westermo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220711091722.14485-1-matthias.may@westermo.com> References: <20220711091722.14485-1-matthias.may@westermo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.29.100.2] X-ClientProxiedBy: wsevst-s0023.westermo.com (192.168.130.120) To EX01GLOBAL.beijerelectronics.com (10.101.10.25) X-Proofpoint-ORIG-GUID: scdlbC51bDbrNf4zylNAa2qtefHwz_ze X-Proofpoint-GUID: scdlbC51bDbrNf4zylNAa2qtefHwz_ze Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code always forces a dscp of 0 for all non-IP frames. However when setting a specific TOS with the command ip link add name tep0 type ip6gretap local fdd1:ced0:5d88:3fce::1 remote fdd1:ced0:5d88:3fce::2 tos 0xa0 one would expect all GRE encapsulated frames to have a TOS of 0xA0. and not only when the payload is IPv4/IPv6. Signed-off-by: Matthias May --- net/ipv6/ip6_gre.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index a9051df0625d..5fe0db88bea8 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -701,6 +701,33 @@ static int prepare_ip6gre_xmit_ipv6(struct sk_buff *sk= b, return 0; } =20 +static int prepare_ip6gre_xmit_other(struct sk_buff *skb, + struct net_device *dev, + struct flowi6 *fl6, __u8 *dsfield, + int *encap_limit) +{ + struct ip6_tnl *t =3D netdev_priv(dev); + + if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) + *encap_limit =3D t->parms.encap_limit; + + memcpy(fl6, &t->fl.u.ip6, sizeof(*fl6)); + + if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) + *dsfield =3D 0; + else + *dsfield =3D ip6_tclass(t->parms.flowinfo); + + if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) + fl6->flowi6_mark =3D skb->mark; + else + fl6->flowi6_mark =3D t->parms.fwmark; + + fl6->flowi6_uid =3D sock_net_uid(dev_net(dev), NULL); + + return 0; +} + static struct ip_tunnel_info *skb_tunnel_info_txcheck(struct sk_buff *skb) { struct ip_tunnel_info *tun_info; @@ -868,20 +895,18 @@ static int ip6gre_xmit_other(struct sk_buff *skb, str= uct net_device *dev) struct ip6_tnl *t =3D netdev_priv(dev); int encap_limit =3D -1; struct flowi6 fl6; + __u8 dsfield =3D 0; __u32 mtu; int err; =20 - if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) - encap_limit =3D t->parms.encap_limit; - - if (!t->parms.collect_md) - memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6)); + if (!t->parms.collect_md && + prepare_ip6gre_xmit_other(skb, dev, &fl6, &dsfield, &encap_limit)) + return -1; =20 err =3D gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM)); if (err) return err; - - err =3D __gre6_xmit(skb, dev, 0, &fl6, encap_limit, &mtu, skb->protocol); + err =3D __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, skb->prot= ocol); =20 return err; } --=20 2.35.1 From nobody Sat Apr 18 21:01:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6FFCCA47B for ; Mon, 11 Jul 2022 09:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbiGKJfd (ORCPT ); Mon, 11 Jul 2022 05:35:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232862AbiGKJeO (ORCPT ); Mon, 11 Jul 2022 05:34:14 -0400 Received: from mx08-0057a101.pphosted.com (mx08-0057a101.pphosted.com [185.183.31.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE8967B366; Mon, 11 Jul 2022 02:18:17 -0700 (PDT) Received: from pps.filterd (m0214196.ppops.net [127.0.0.1]) by mx07-0057a101.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26B7hBTb008991; Mon, 11 Jul 2022 11:17:44 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=westermo.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=12052020; bh=7Ds/3Nw74YKoBFgdlvZDEEeXInxctCEea0014hDr0xY=; b=U6Kay+LZRTCmoLFlyB1yvFLzlVTGFYhzNuAojEkvvruGQrQ+KxfnWh8mUkFvrle8Nz1R mNTx2YWoPzkBio/SdStExXwrnPZpULx4A+vXtKz2gXTF73dsPe0Bd9nxtQTGS5PWTQ4a 8mebtmthUI7wtNxo7PhFUVqsKW6nQ2HzdS7SfSB+Os35LvxstQJQIGoVJiDOmsM7LCvd hkkIoq5PvpptD9a+iT0w9tXz5gIY0pdNjQe3H4GGOFFD/AWemwiN5EQA2hNFKxLDBSZh p+3TU3Jpe4N5+1glFlZv90hf/zkN3cy9gFnGEUzbWmlermxPqd/Y4P1opHD0XvYleTv6 2g== Received: from mail.beijerelectronics.com ([195.67.87.131]) by mx07-0057a101.pphosted.com (PPS) with ESMTPS id 3h6wp61x82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 11 Jul 2022 11:17:44 +0200 Received: from Orpheus.nch.westermo.com (172.29.100.2) by EX01GLOBAL.beijerelectronics.com (10.101.10.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.2375.17; Mon, 11 Jul 2022 11:17:42 +0200 From: Matthias May To: CC: , , , , , , , Matthias May Subject: [PATCH 3/4 net-next] ip6_gre: use actual protocol to select xmit Date: Mon, 11 Jul 2022 11:17:21 +0200 Message-ID: <20220711091722.14485-4-matthias.may@westermo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220711091722.14485-1-matthias.may@westermo.com> References: <20220711091722.14485-1-matthias.may@westermo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.29.100.2] X-ClientProxiedBy: wsevst-s0023.westermo.com (192.168.130.120) To EX01GLOBAL.beijerelectronics.com (10.101.10.25) X-Proofpoint-ORIG-GUID: 1JTHKFW03YbrKZpkkecMxeYMU_T80i8q X-Proofpoint-GUID: 1JTHKFW03YbrKZpkkecMxeYMU_T80i8q Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When the payload is a VLAN encapsulated IPv6/IPv6 frame, we can skip the 802.1q/802.1ad ethertypes and jump to the actual protocol. This way we treat IPv4/IPv6 frames as IP instead of as "other". Signed-off-by: Matthias May --- net/ipv6/ip6_gre.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 5fe0db88bea8..cd0202016da0 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -916,6 +916,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *s= kb, { struct ip6_tnl *t =3D netdev_priv(dev); struct net_device_stats *stats =3D &t->dev->stats; + __be16 payload_protocol; int ret; =20 if (!pskb_inet_may_pull(skb)) @@ -924,7 +925,8 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *s= kb, if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr)) goto tx_err; =20 - switch (skb->protocol) { + payload_protocol =3D skb_protocol(skb, true); + switch (payload_protocol) { case htons(ETH_P_IP): ret =3D ip6gre_xmit_ipv4(skb, dev); break; --=20 2.35.1 From nobody Sat Apr 18 21:01:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42FC3C433EF for ; Mon, 11 Jul 2022 09:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232756AbiGKJe6 (ORCPT ); Mon, 11 Jul 2022 05:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbiGKJdY (ORCPT ); Mon, 11 Jul 2022 05:33:24 -0400 Received: from mx08-0057a101.pphosted.com (mx08-0057a101.pphosted.com [185.183.31.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B147AB1B; Mon, 11 Jul 2022 02:18:02 -0700 (PDT) Received: from pps.filterd (m0214196.ppops.net [127.0.0.1]) by mx07-0057a101.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26B5tOZk024300; Mon, 11 Jul 2022 11:17:45 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=westermo.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=12052020; bh=JO2c4R+K+0TD0LGMJsNYHX2sr7LZuUrrSsISr8n4sug=; b=g9YNUdiN5k5/MwegSPG6yODjoaF9kiC06EwzPiqlGa8U4y0zFr5mfxHWEprJdtrxI92H ULYQtgr3wO77EnlzzuNsSek8xrmuaiYfpUA9ta04lOGKkEaDIL6+yOPeM6FgdKJpd9i+ NuiSLoHYXVuZ6mYd2L0wmbsILBDJEycpIm+32ssqrDjy5PednvCU8ctdahgMl0hVudcm VnaDHIdtIbU2qrS7TOI955XjlG1rb/Ykl1kroLF8G7PrB2+oO1SFk0+F4+C/MpnShtG3 vf/GTCsgj0h6I07+TD6s27vEDXRCyjsIYqBCSsRVOPR5smeUgTPDSpcFtPEjfjWxUHuA sg== Received: from mail.beijerelectronics.com ([195.67.87.131]) by mx07-0057a101.pphosted.com (PPS) with ESMTPS id 3h6wp61x84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 11 Jul 2022 11:17:45 +0200 Received: from Orpheus.nch.westermo.com (172.29.100.2) by EX01GLOBAL.beijerelectronics.com (10.101.10.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.2375.17; Mon, 11 Jul 2022 11:17:44 +0200 From: Matthias May To: CC: , , , , , , , Matthias May Subject: [PATCH 4/4 net-next] ip6_tunnel: allow to inherit from VLAN encapsulated IP Date: Mon, 11 Jul 2022 11:17:22 +0200 Message-ID: <20220711091722.14485-5-matthias.may@westermo.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220711091722.14485-1-matthias.may@westermo.com> References: <20220711091722.14485-1-matthias.may@westermo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.29.100.2] X-ClientProxiedBy: wsevst-s0023.westermo.com (192.168.130.120) To EX01GLOBAL.beijerelectronics.com (10.101.10.25) X-Proofpoint-ORIG-GUID: zrC7kDlZOZ7Ml5Tf8mmwD52WVEqV1d8w X-Proofpoint-GUID: zrC7kDlZOZ7Ml5Tf8mmwD52WVEqV1d8w Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current code allows to inherit the TTL (hop_limit) from the payload when skb->protocol is ETH_P_IP or ETH_P_IPV6. However when the payload is VLAN encapsulated (e.g because the tunnel is of type GRETAP), then this inheriting does not work, because the visible skb->protocol is of type ETH_P_8021Q or ETH_P_8021AD. Instead of skb->protocol, use skb_protocol(). Signed-off-by: Matthias May --- net/ipv6/ip6_tunnel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 19325b7600bb..4244a66eb859 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1085,10 +1085,13 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_de= vice *dev, __u8 dsfield, unsigned int eth_hlen =3D t->dev->type =3D=3D ARPHRD_ETHER ? ETH_HLEN : 0; unsigned int psh_hlen =3D sizeof(struct ipv6hdr) + t->encap_hlen; unsigned int max_headroom =3D psh_hlen; + __be16 payload_protocol; bool use_cache =3D false; u8 hop_limit; int err =3D -1; =20 + payload_protocol =3D skb_protocol(skb, true); + if (t->parms.collect_md) { hop_limit =3D skb_tunnel_info(skb)->key.ttl; goto route_lookup; @@ -1098,7 +1101,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_devi= ce *dev, __u8 dsfield, =20 /* NBMA tunnel */ if (ipv6_addr_any(&t->parms.raddr)) { - if (skb->protocol =3D=3D htons(ETH_P_IPV6)) { + if (payload_protocol =3D=3D htons(ETH_P_IPV6)) { struct in6_addr *addr6; struct neighbour *neigh; int addr_type; @@ -1119,7 +1122,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_devi= ce *dev, __u8 dsfield, =20 memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr)); neigh_release(neigh); - } else if (skb->protocol =3D=3D htons(ETH_P_IP)) { + } else if (payload_protocol =3D=3D htons(ETH_P_IP)) { const struct rtable *rt =3D skb_rtable(skb); =20 if (!rt) @@ -1230,9 +1233,9 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_devi= ce *dev, __u8 dsfield, skb_dst_set(skb, dst); =20 if (hop_limit =3D=3D 0) { - if (skb->protocol =3D=3D htons(ETH_P_IP)) + if (payload_protocol =3D=3D htons(ETH_P_IP)) hop_limit =3D ip_hdr(skb)->ttl; - else if (skb->protocol =3D=3D htons(ETH_P_IPV6)) + else if (payload_protocol =3D=3D htons(ETH_P_IPV6)) hop_limit =3D ipv6_hdr(skb)->hop_limit; else hop_limit =3D ip6_dst_hoplimit(dst); --=20 2.35.1