From patchwork Mon Feb 5 21:35:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 869586 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EKRJOOWX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zb19c6pYqz9t2c for ; Tue, 6 Feb 2018 08:36:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752171AbeBEVgD (ORCPT ); Mon, 5 Feb 2018 16:36:03 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:35305 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752060AbeBEVfu (ORCPT ); Mon, 5 Feb 2018 16:35:50 -0500 Received: by mail-pl0-f65.google.com with SMTP id j19so12673611pll.2 for ; Mon, 05 Feb 2018 13:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=uUHF+B7PAl+oLxn7utX/gBTeTMqAMyk0p+oh5Sqi/sk=; b=EKRJOOWXntE4J8HrpA6M4N4f+k8YWE9zTcT34C4AB2GmDWk8ySlGDgi7X40/v046mN F9OBn20hvkxq9EP/QK/hyF17yv+CN5l8bF5hyaHCntZjQpPZFb8o6ZhBxrVVHesaCTzn M2SbA/ssTEor9EW66xUCDddst5jB3hlMcVk+W7LMuhp3ngLio3rE1gwKG/bKhpP1gM+p a++aMUgzCswdoqmM79X7u1uXaNC/9G4RogQeLOxWRc6zTlMS6yA1DKXj6EP1SaS3NJMO 9xfa321H/5CTA4hbmsxwDM7f0hkw+liqC5dbKrd+tZ0ucITN09kW8lHZFmtytSioPnww LqhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uUHF+B7PAl+oLxn7utX/gBTeTMqAMyk0p+oh5Sqi/sk=; b=GM1ETqoZNEWwT3XM8/wIWFJux2T/h/SSywIIezefws8kBWE7Xp4TzOUkTOfIAN3lqc gl1jj8uT3/n1FBFgc1BhCP82CAumNxLp7BJJ+T4qD1Suus26f7j3KuzoUxiiSEgEGzkj zPn8H7ubcUDgG1U5jBhWvewlNbfyHpHlsiFhunuzVhvaC3JL1j++6fnox6yO8ZeuNrUY fGZLtoIF3Wv+VwQ2z/H8AUT8/1HJFNeyKiJ8v2kFrXJVO4zRFXngkR5btaejIxSFUVSJ M8sVBSIpcGruW7HFIuUg07IVkV7D8TPy3vbRCywfX6s2N8PY0ncy93i90bgGIEDlnFwP YckA== X-Gm-Message-State: APf1xPDQqfvJOKxFvRg91qGnkFfhw7HZLCb0gYT2Fa9jgBP2VTlmeZzP pH9Z/y6APXmveGo6SnCOyS31BNJD X-Google-Smtp-Source: AH8x226J1ckjys+B1oNcR0jNfyoSwJ+qaG1kHR/RWXq8Y2XOSv9qUqM+n6NxSW9rmMXkCIV0fNCsrg== X-Received: by 2002:a17:902:3083:: with SMTP id v3-v6mr186663plb.426.1517866549725; Mon, 05 Feb 2018 13:35:49 -0800 (PST) Received: from sc9-mailhost3.vmware.com ([208.91.2.2]) by smtp.gmail.com with ESMTPSA id z19sm20136110pff.3.2018.02.05.13.35.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Feb 2018 13:35:49 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH net 1/3] net: erspan: fix metadata extraction Date: Mon, 5 Feb 2018 13:35:34 -0800 Message-Id: <1517866536-69908-2-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517866536-69908-1-git-send-email-u9012063@gmail.com> References: <1517866536-69908-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit d350a823020e ("net: erspan: create erspan metadata uapi header") moves the erspan 'version' in front of the 'struct erspan_md2' for later extensibility reason. This breaks the existing erspan metadata extraction code because the erspan_md2 then has a 4-byte offset to between the erspan_metadata and erspan_base_hdr. This patch fixes it. Fixes: 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel") Fixes: ef7baf5e083c ("ip6_gre: add ip6 erspan collect_md mode") Fixes: 1d7e2ed22f8d ("net: erspan: refactor existing erspan code") Signed-off-by: William Tu --- include/net/erspan.h | 26 +++++++++++++------------- net/ipv4/ip_gre.c | 5 ++++- net/ipv6/ip6_gre.c | 6 ++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/net/erspan.h b/include/net/erspan.h index 5daa4866412b..d044aa60cc76 100644 --- a/include/net/erspan.h +++ b/include/net/erspan.h @@ -159,13 +159,13 @@ static inline void erspan_build_header(struct sk_buff *skb, struct ethhdr *eth = (struct ethhdr *)skb->data; enum erspan_encap_type enc_type; struct erspan_base_hdr *ershdr; - struct erspan_metadata *ersmd; struct qtag_prefix { __be16 eth_type; __be16 tci; } *qp; u16 vlan_tci = 0; u8 tos; + __be32 *idx; tos = is_ipv4 ? ip_hdr(skb)->tos : (ipv6_hdr(skb)->priority << 4) + @@ -195,8 +195,8 @@ static inline void erspan_build_header(struct sk_buff *skb, set_session_id(ershdr, id); /* Build metadata */ - ersmd = (struct erspan_metadata *)(ershdr + 1); - ersmd->u.index = htonl(index & INDEX_MASK); + idx = (__be32 *)(ershdr + 1); + *idx = htonl(index & INDEX_MASK); } /* ERSPAN GRA: timestamp granularity @@ -225,7 +225,7 @@ static inline void erspan_build_header_v2(struct sk_buff *skb, { struct ethhdr *eth = (struct ethhdr *)skb->data; struct erspan_base_hdr *ershdr; - struct erspan_metadata *md; + struct erspan_md2 *md2; struct qtag_prefix { __be16 eth_type; __be16 tci; @@ -261,15 +261,15 @@ static inline void erspan_build_header_v2(struct sk_buff *skb, set_session_id(ershdr, id); /* Build metadata */ - md = (struct erspan_metadata *)(ershdr + 1); - md->u.md2.timestamp = erspan_get_timestamp(); - md->u.md2.sgt = htons(sgt); - md->u.md2.p = 1; - md->u.md2.ft = 0; - md->u.md2.dir = direction; - md->u.md2.gra = gra; - md->u.md2.o = 0; - set_hwid(&md->u.md2, hwid); + md2 = (struct erspan_md2 *)(ershdr + 1); + md2->timestamp = erspan_get_timestamp(); + md2->sgt = htons(sgt); + md2->p = 1; + md2->ft = 0; + md2->dir = direction; + md2->gra = gra; + md2->o = 0; + set_hwid(md2, hwid); } #endif diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 6ec670fbbbdd..9b50eddd1882 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -261,6 +261,7 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, struct ip_tunnel_net *itn; struct ip_tunnel *tunnel; const struct iphdr *iph; + struct erspan_md2 *md2; int ver; int len; @@ -313,8 +314,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, return PACKET_REJECT; md = ip_tunnel_info_opts(&tun_dst->u.tun_info); - memcpy(md, pkt_md, sizeof(*md)); md->version = ver; + md2 = &md->u.md2; + memcpy(md2, pkt_md, ver == 1 ? ERSPAN_V1_MDSIZE : + ERSPAN_V2_MDSIZE); info = &tun_dst->u.tun_info; info->key.tun_flags |= TUNNEL_ERSPAN_OPT; diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 05f070e123e4..50913dbd0612 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -505,6 +505,7 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, struct erspan_base_hdr *ershdr; struct erspan_metadata *pkt_md; const struct ipv6hdr *ipv6h; + struct erspan_md2 *md2; struct ip6_tnl *tunnel; u8 ver; @@ -551,9 +552,10 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, info = &tun_dst->u.tun_info; md = ip_tunnel_info_opts(info); - - memcpy(md, pkt_md, sizeof(*md)); md->version = ver; + md2 = &md->u.md2; + memcpy(md2, pkt_md, ver == 1 ? ERSPAN_V1_MDSIZE : + ERSPAN_V2_MDSIZE); info->key.tun_flags |= TUNNEL_ERSPAN_OPT; info->options_len = sizeof(*md); From patchwork Mon Feb 5 21:35:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 869588 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fLpQyWaH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zb19q3Ty6z9sR8 for ; Tue, 6 Feb 2018 08:36:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752183AbeBEVgM (ORCPT ); Mon, 5 Feb 2018 16:36:12 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:44927 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752068AbeBEVfv (ORCPT ); Mon, 5 Feb 2018 16:35:51 -0500 Received: by mail-pl0-f68.google.com with SMTP id f8so12662748plk.11 for ; Mon, 05 Feb 2018 13:35:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=tdeAY1cAQdGqVgVLahWFmUtZuToAW0cZOS5yrL6RZG4=; b=fLpQyWaHs7eR4I9XKGvWZBCZ6+r9vDfM1kEt9WiZs/44rYmMYWdByGwTz5p8iZsw8a 8DNCEDCuRwyrBf8pKHXtAOiXl6+60DeDlpYOB8rdr54b9BSClnXBZYLHSByHPR5IQuu9 t3pAeSetZmKw77qEgxtIry9p2NRiXarPt3wCP1AyqQjvsDcVj9bqagQtu9pSKxI9ZyBx mWAdN+2H7saLz/lOhXOtsVaC3mcNKs/yUkx88n/oY0dCbpCs2BVIGBeybPRoV3duPGqY HwDDs1QKf7ElIei201E1fi82SWN6NToCU9Bo9e192h2L5zm3x7A7EIY33LV5IJzB4d2d C5yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=tdeAY1cAQdGqVgVLahWFmUtZuToAW0cZOS5yrL6RZG4=; b=WhZl01vr27JFefPe0om+7x0KfTqMNizBy68y97yJdewag5l4zUIur/Fxig+KHlMVgM uKX+xWEHgwWYcXr2rbeukmsabJjjpYi5pm/qLQIyCO/VMSC4qXTJfRwEqBfenM9sVLe2 nGf0KyDzAq2OS3DV8ls37xdEMMLuovmCRtadWuXQ96sr73ThdNpjQichhMKKeFYxGFge XXMAH23V6VVZJnB5tmtqJ/QT0JYsH+HoQ5KCYk2fP3Cc3o8GnEL1gjznYsSBSGyd09Ln Hv/i72FhXR0j/j4/ilcwEOCWoi86iIcC+v8JV02pAJpyDthnl/Tgz/HKECH1bgwdXMBJ T9lg== X-Gm-Message-State: APf1xPBSS4SoUF9s4Gl3dmOrE/2BDoD6e27+2Roxm60gGz26J1dIVWHW Hckew2218LCKryEr6nD/fnIfAE1G X-Google-Smtp-Source: AH8x224yl8I8x84ND3qyYwLjvq3Pu2ZBIWk7HdHDb25fg7TUP8EzSNpgDr3zKcVMqNiSKOqCHIHCYw== X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr214142plr.16.1517866550590; Mon, 05 Feb 2018 13:35:50 -0800 (PST) Received: from sc9-mailhost3.vmware.com ([208.91.2.2]) by smtp.gmail.com with ESMTPSA id z19sm20136110pff.3.2018.02.05.13.35.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Feb 2018 13:35:50 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH net 2/3] net: erspan: fix erspan config overwrite Date: Mon, 5 Feb 2018 13:35:35 -0800 Message-Id: <1517866536-69908-3-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517866536-69908-1-git-send-email-u9012063@gmail.com> References: <1517866536-69908-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When an erspan tunnel device receives an erpsan packet with different tunnel metadata (ex: version, index, hwid, direction), existing code overwrites the tunnel device's erspan configuration with the received packet's metadata. The patch fixes it. Fixes: 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel") Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre") Fixes: ef7baf5e083c ("ip6_gre: add ip6 erspan collect_md mode") Fixes: 94d7d8f29287 ("ip6_gre: add erspan v2 support") Signed-off-by: William Tu --- net/ipv4/ip_gre.c | 9 --------- net/ipv6/ip6_gre.c | 9 --------- 2 files changed, 18 deletions(-) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 9b50eddd1882..45d97e9b2759 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -322,15 +322,6 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, info = &tun_dst->u.tun_info; info->key.tun_flags |= TUNNEL_ERSPAN_OPT; info->options_len = sizeof(*md); - } else { - tunnel->erspan_ver = ver; - if (ver == 1) { - tunnel->index = ntohl(pkt_md->u.index); - } else { - tunnel->dir = pkt_md->u.md2.dir; - tunnel->hwid = get_hwid(&pkt_md->u.md2); - } - } skb_reset_mac_header(skb); diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 50913dbd0612..3c353125546d 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -562,15 +562,6 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error); } else { - tunnel->parms.erspan_ver = ver; - - if (ver == 1) { - tunnel->parms.index = ntohl(pkt_md->u.index); - } else { - tunnel->parms.dir = pkt_md->u.md2.dir; - tunnel->parms.hwid = get_hwid(&pkt_md->u.md2); - } - ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error); } From patchwork Mon Feb 5 21:35:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 869589 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R3StIf7x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zb1BC4l5dz9sRV for ; Tue, 6 Feb 2018 08:36:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752230AbeBEVgT (ORCPT ); Mon, 5 Feb 2018 16:36:19 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37761 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752065AbeBEVfw (ORCPT ); Mon, 5 Feb 2018 16:35:52 -0500 Received: by mail-pl0-f67.google.com with SMTP id ay8so12662186plb.4 for ; Mon, 05 Feb 2018 13:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ILc+T9XLifUJQ81XN/uzTvP29ZNpVT2GeoByS7tXVpQ=; b=R3StIf7xzdVytRO/EmB/8qMMInQcQcamhX/MqLxpnLUFrk9bjcfah4HllWIPsx7JGL fEL0BXrLNYGifr/26QuAcAo2xzIy5wxRhOFaL9EKzhYny1BtPVdSpEKqKAdFWhJwQoCA I6iqRE7bURoZ3GnIljKzC2JM+HWoxM3JnY7V63XvfB1nlsaOOw6L5vXDQ+EqWSRVeBaJ Jxgt7PBwPa+5AFSdob6F/C+zFm8UdunDYSVN99jYGwsRDSNt+BOZMAWKvaGZEXKpfyND TybTgdE8de6QqETroyGq1GOb1wYKcEmGOvy2Tte5bjOJVj1E0V484ec8y+7DiyPXMbIs 7T5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ILc+T9XLifUJQ81XN/uzTvP29ZNpVT2GeoByS7tXVpQ=; b=CukTw/PLSNqujCxT8LeRHScgySn26pNfkJRLlKzOIyK4TnveHSPbc8Z5KgvQdQUpBJ Ssm8BYvUx1xOhZeHlr24Lc8VjXIBpym5HUXbgM2uKViWAMwhcJAXCPo0gG6gZ+t3eVv/ 70dKkhP4ztQ1KkqlXH20+6Yxay+pqWba3PvmcNQ+rxe9RK8AfyFR06f6KzZ17rPjzKNU UJDgsuRoo0NGhIW+mcPxObM5aId4yPPCN7m9k34n5NqxzVulsugpOMgYJA6cMHjXpmnf PSvEjWfl8sRMYTEFrQiM4b/c/AV1gJrDovAyao9LaA6nSVaMmF+U7nkjIHoLNzO1GxME +pYw== X-Gm-Message-State: APf1xPCrUZS/GDnCGAdt51v0Ez82OI7jfzHD5OlDw2bwt2i2uzl49zmu sgWaNGdkPLMOeLEfad/J2/g2vrdW X-Google-Smtp-Source: AH8x227oWu3xGONEJoeJJc1uPAJFjWMVmdTWWgkoTgKTlAg1XRK1VBcvnw6wLNbH66+/+1GDHEYEEQ== X-Received: by 2002:a17:902:9a8b:: with SMTP id w11-v6mr206312plp.118.1517866551548; Mon, 05 Feb 2018 13:35:51 -0800 (PST) Received: from sc9-mailhost3.vmware.com ([208.91.2.2]) by smtp.gmail.com with ESMTPSA id z19sm20136110pff.3.2018.02.05.13.35.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Feb 2018 13:35:51 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH net 3/3] sample/bpf: fix erspan metadata Date: Mon, 5 Feb 2018 13:35:36 -0800 Message-Id: <1517866536-69908-4-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517866536-69908-1-git-send-email-u9012063@gmail.com> References: <1517866536-69908-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The commit c69de58ba84f ("net: erspan: use bitfield instead of mask and offset") changes the erspan header to use bitfield, and commit d350a823020e ("net: erspan: create erspan metadata uapi header") creates a uapi header file. The above two commit breaks the current erspan test. This patch fixes it by adapting the above two changes. Fixes: ac80c2a165af ("samples/bpf: add erspan v2 sample code") Fixes: ef88f89c830f ("samples/bpf: extend test_tunnel_bpf.sh with ERSPAN") Signed-off-by: William Tu --- samples/bpf/tcbpf2_kern.c | 41 ++++++++++++++++------------------------- samples/bpf/test_tunnel_bpf.sh | 4 ++-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/samples/bpf/tcbpf2_kern.c b/samples/bpf/tcbpf2_kern.c index f6bbf8f50da3..efdc16d195ff 100644 --- a/samples/bpf/tcbpf2_kern.c +++ b/samples/bpf/tcbpf2_kern.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "bpf_helpers.h" #include "bpf_endian.h" @@ -35,24 +36,10 @@ struct geneve_opt { u8 opt_data[8]; /* hard-coded to 8 byte */ }; -struct erspan_md2 { - __be32 timestamp; - __be16 sgt; - __be16 flags; -}; - struct vxlan_metadata { u32 gbp; }; -struct erspan_metadata { - union { - __be32 index; - struct erspan_md2 md2; - } u; - int version; -}; - SEC("gre_set_tunnel") int _gre_set_tunnel(struct __sk_buff *skb) { @@ -156,13 +143,15 @@ int _erspan_set_tunnel(struct __sk_buff *skb) __builtin_memset(&md, 0, sizeof(md)); #ifdef ERSPAN_V1 md.version = 1; - md.u.index = htonl(123); + md.u.index = bpf_htonl(123); #else u8 direction = 1; - u16 hwid = 7; + u8 hwid = 7; md.version = 2; - md.u.md2.flags = htons((direction << 3) | (hwid << 4)); + md.u.md2.dir = direction; + md.u.md2.hwid = hwid & 0xf; + md.u.md2.hwid_upper = (hwid >> 4) & 0x3; #endif ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md)); @@ -207,9 +196,9 @@ int _erspan_get_tunnel(struct __sk_buff *skb) char fmt2[] = "\tdirection %d hwid %x timestamp %u\n"; bpf_trace_printk(fmt2, sizeof(fmt2), - (ntohs(md.u.md2.flags) >> 3) & 0x1, - (ntohs(md.u.md2.flags) >> 4) & 0x3f, - bpf_ntohl(md.u.md2.timestamp)); + md.u.md2.dir, + (md.u.md2.hwid_upper << 4) + md.u.md2.hwid, + bpf_ntohl(md.u.md2.timestamp)); #endif return TC_ACT_OK; @@ -242,10 +231,12 @@ int _ip4ip6erspan_set_tunnel(struct __sk_buff *skb) md.version = 1; #else u8 direction = 0; - u16 hwid = 17; + u8 hwid = 17; md.version = 2; - md.u.md2.flags = htons((direction << 3) | (hwid << 4)); + md.u.md2.dir = direction; + md.u.md2.hwid = hwid & 0xf; + md.u.md2.hwid_upper = (hwid >> 4) & 0x3; #endif ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md)); @@ -290,9 +281,9 @@ int _ip4ip6erspan_get_tunnel(struct __sk_buff *skb) char fmt2[] = "\tdirection %d hwid %x timestamp %u\n"; bpf_trace_printk(fmt2, sizeof(fmt2), - (ntohs(md.u.md2.flags) >> 3) & 0x1, - (ntohs(md.u.md2.flags) >> 4) & 0x3f, - bpf_ntohl(md.u.md2.timestamp)); + md.u.md2.dir, + (md.u.md2.hwid_upper << 4) + md.u.md2.hwid, + bpf_ntohl(md.u.md2.timestamp)); #endif return TC_ACT_OK; diff --git a/samples/bpf/test_tunnel_bpf.sh b/samples/bpf/test_tunnel_bpf.sh index ae7f7c38309b..43ce049996ee 100755 --- a/samples/bpf/test_tunnel_bpf.sh +++ b/samples/bpf/test_tunnel_bpf.sh @@ -68,7 +68,7 @@ function add_erspan_tunnel { ip netns exec at_ns0 \ ip link add dev $DEV_NS type $TYPE seq key 2 \ local 172.16.1.100 remote 172.16.1.200 \ - erspan_ver 2 erspan_dir 1 erspan_hwid 3 + erspan_ver 2 erspan_dir egress erspan_hwid 3 fi ip netns exec at_ns0 ip link set dev $DEV_NS up ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24 @@ -97,7 +97,7 @@ function add_ip6erspan_tunnel { ip netns exec at_ns0 \ ip link add dev $DEV_NS type $TYPE seq key 2 \ local ::11 remote ::22 \ - erspan_ver 2 erspan_dir 1 erspan_hwid 7 + erspan_ver 2 erspan_dir egress erspan_hwid 7 fi ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24 ip netns exec at_ns0 ip link set dev $DEV_NS up