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