{"id":805963,"url":"http://patchwork.ozlabs.org/api/1.2/patches/805963/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1503678089-27131-4-git-send-email-u9012063@gmail.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1503678089-27131-4-git-send-email-u9012063@gmail.com>","list_archive_url":null,"date":"2017-08-25T16:21:29","name":"[net-next,3/3] samples/bpf: extend test_tunnel_bpf.sh with ERSPAN","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"9132cd6e8677e57d195c9e40d11a95d6c4f8c4b3","submitter":{"id":67856,"url":"http://patchwork.ozlabs.org/api/1.2/people/67856/?format=json","name":"William Tu","email":"u9012063@gmail.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.2/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1503678089-27131-4-git-send-email-u9012063@gmail.com/mbox/","series":[],"comments":"http://patchwork.ozlabs.org/api/patches/805963/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/805963/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"rmCJUv8O\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xf5yj0CL0z9rxm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat, 26 Aug 2017 02:21:49 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S934401AbdHYQVq (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 25 Aug 2017 12:21:46 -0400","from mail-pg0-f67.google.com ([74.125.83.67]:33182 \"EHLO\n\tmail-pg0-f67.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S934394AbdHYQVn (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Fri, 25 Aug 2017 12:21:43 -0400","by mail-pg0-f67.google.com with SMTP id q16so391179pgc.0\n\tfor <netdev@vger.kernel.org>; Fri, 25 Aug 2017 09:21:43 -0700 (PDT)","from sc9-mailhost2.vmware.com ([208.91.1.34])\n\tby smtp.gmail.com with ESMTPSA id\n\tk197sm1051155pga.78.2017.08.25.09.21.41\n\tfor <netdev@vger.kernel.org>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tFri, 25 Aug 2017 09:21:42 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20161025;\n\th=from:to:subject:date:message-id:in-reply-to:references;\n\tbh=c/QFeB8b6cZDxQQyNgNfXlc8pv1pjEaa4Rg6KoO36Eo=;\n\tb=rmCJUv8O/U1PQiRcETABb2Rbh3zVqi6gAWMRqzOdN30XHFSdrG8czf9K2LLFzIWlNJ\n\ty97oAqTJp7szCS6Hm6WJzcGshtn77XHx3Ucm3LPKYFP676r8VV5l5Bz1IbAM0JCNLlv2\n\tfCtxcwLk8HEQWQ0w/QBWglphmfcHpcV9dVLZPsz12CTMP3+u9QGhSWsS4uXmRKQn0edm\n\tmwqCgkTEWRvtNp9e5heEE03SerbklfU5+f6hYF+SFe/ry02zhfqdBqfU2rrVG3jpUwQH\n\tS7tILFX9sejFywORa2KycYT4qp3Uem858bfMkdACEiP1WZjbHWbYUkHvRH219Yu3KfN9\n\tVCnw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=c/QFeB8b6cZDxQQyNgNfXlc8pv1pjEaa4Rg6KoO36Eo=;\n\tb=qUu8uCPTeCCMKeyV8bpUg0Wdaa0rTktIgVUguxnBt5UUCEZ5u0PGQGbxpqRjMJ9xGX\n\tNQFIdx880p2Zs/E9RL111tumlKd3LTLcQ/VqzaBYcFrWpA5cOFZcgw3Y7mvpeKdLkKd/\n\tkzPSsVr3hiTIuj+0QVMZBKnfiSkLQDCpAuDhAV9McuaNYjLvPUCPnSdHQnkRQJlCbC49\n\tfHc5PkhfKgdQ1YSWKKOLsf7oRqbO9r6dcrRlsGT9Yvb22Tc20ly1joYTMsUMynuewAAn\n\teYGVhu/KIuqQaFPPxBjth7Ax1zMjdiByOWPF5G3wI2HHY4NWaJl6HIrOw7rux24iPwK3\n\tSogA==","X-Gm-Message-State":"AHYfb5iG8AXOsoSMj7EfD5ayOQJg7YxS7fVoeafibefLnMgpqc4zEDLV\n\tfKuVALu1oCKEwnhtMYU=","X-Received":"by 10.101.76.139 with SMTP id m11mr3175604pgt.160.1503678102751; \n\tFri, 25 Aug 2017 09:21:42 -0700 (PDT)","From":"William Tu <u9012063@gmail.com>","To":"netdev@vger.kernel.org","Subject":"[PATCH net-next 3/3] samples/bpf: extend test_tunnel_bpf.sh with\n\tERSPAN","Date":"Fri, 25 Aug 2017 09:21:29 -0700","Message-Id":"<1503678089-27131-4-git-send-email-u9012063@gmail.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1503678089-27131-1-git-send-email-u9012063@gmail.com>","References":"<1503678089-27131-1-git-send-email-u9012063@gmail.com>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Extend existing tests for vxlan, gre, geneve, ipip to\ninclude ERSPAN tunnel.\n\nSigned-off-by: William Tu <u9012063@gmail.com>\nAcked-by: Alexei Starovoitov <ast@kernel.org>\n---\n samples/bpf/tcbpf2_kern.c      | 63 +++++++++++++++++++++++++++++++++++++++++-\n samples/bpf/test_tunnel_bpf.sh | 29 +++++++++++++++++++\n 2 files changed, 91 insertions(+), 1 deletion(-)","diff":"diff --git a/samples/bpf/tcbpf2_kern.c b/samples/bpf/tcbpf2_kern.c\nindex 270edcc149a1..370b749f5ee6 100644\n--- a/samples/bpf/tcbpf2_kern.c\n+++ b/samples/bpf/tcbpf2_kern.c\n@@ -17,6 +17,7 @@\n #include <uapi/linux/pkt_cls.h>\n #include <net/ipv6.h>\n #include \"bpf_helpers.h\"\n+#include \"bpf_endian.h\"\n \n #define _htonl __builtin_bswap32\n #define ERROR(ret) do {\\\n@@ -38,6 +39,10 @@ struct vxlan_metadata {\n \tu32     gbp;\n };\n \n+struct erspan_metadata {\n+\t__be32 index;\n+};\n+\n SEC(\"gre_set_tunnel\")\n int _gre_set_tunnel(struct __sk_buff *skb)\n {\n@@ -76,6 +81,63 @@ int _gre_get_tunnel(struct __sk_buff *skb)\n \treturn TC_ACT_OK;\n }\n \n+SEC(\"erspan_set_tunnel\")\n+int _erspan_set_tunnel(struct __sk_buff *skb)\n+{\n+\tstruct bpf_tunnel_key key;\n+\tstruct erspan_metadata md;\n+\tint ret;\n+\n+\t__builtin_memset(&key, 0x0, sizeof(key));\n+\tkey.remote_ipv4 = 0xac100164; /* 172.16.1.100 */\n+\tkey.tunnel_id = 2;\n+\tkey.tunnel_tos = 0;\n+\tkey.tunnel_ttl = 64;\n+\n+\tret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), BPF_F_ZERO_CSUM_TX);\n+\tif (ret < 0) {\n+\t\tERROR(ret);\n+\t\treturn TC_ACT_SHOT;\n+\t}\n+\n+\tmd.index = htonl(123);\n+\tret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));\n+\tif (ret < 0) {\n+\t\tERROR(ret);\n+\t\treturn TC_ACT_SHOT;\n+\t}\n+\n+\treturn TC_ACT_OK;\n+}\n+\n+SEC(\"erspan_get_tunnel\")\n+int _erspan_get_tunnel(struct __sk_buff *skb)\n+{\n+\tchar fmt[] = \"key %d remote ip 0x%x erspan index 0x%x\\n\";\n+\tstruct bpf_tunnel_key key;\n+\tstruct erspan_metadata md;\n+\tu32 index;\n+\tint ret;\n+\n+\tret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);\n+\tif (ret < 0) {\n+\t\tERROR(ret);\n+\t\treturn TC_ACT_SHOT;\n+\t}\n+\n+\tret = bpf_skb_get_tunnel_opt(skb, &md, sizeof(md));\n+\tif (ret < 0) {\n+\t\tERROR(ret);\n+\t\treturn TC_ACT_SHOT;\n+\t}\n+\n+\tindex = bpf_ntohl(md.index);\n+\tbpf_trace_printk(fmt, sizeof(fmt),\n+\t\t\tkey.tunnel_id, key.remote_ipv4, index);\n+\n+\treturn TC_ACT_OK;\n+}\n+\n SEC(\"vxlan_set_tunnel\")\n int _vxlan_set_tunnel(struct __sk_buff *skb)\n {\n@@ -378,5 +440,4 @@ int _ip6ip6_get_tunnel(struct __sk_buff *skb)\n \treturn TC_ACT_OK;\n }\n \n-\n char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/samples/bpf/test_tunnel_bpf.sh b/samples/bpf/test_tunnel_bpf.sh\nindex a70d2ea90313..410052d9fc37 100755\n--- a/samples/bpf/test_tunnel_bpf.sh\n+++ b/samples/bpf/test_tunnel_bpf.sh\n@@ -32,6 +32,19 @@ function add_gre_tunnel {\n \tip addr add dev $DEV 10.1.1.200/24\n }\n \n+function add_erspan_tunnel {\n+\t# in namespace\n+\tip netns exec at_ns0 \\\n+\t\tip link add dev $DEV_NS type $TYPE seq key 2 local 172.16.1.100 remote 172.16.1.200 erspan 123\n+\tip netns exec at_ns0 ip link set dev $DEV_NS up\n+\tip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24\n+\n+\t# out of namespace\n+\tip link add dev $DEV type $TYPE external\n+\tip link set dev $DEV up\n+\tip addr add dev $DEV 10.1.1.200/24\n+}\n+\n function add_vxlan_tunnel {\n \t# Set static ARP entry here because iptables set-mark works\n \t# on L3 packet, as a result not applying to ARP packets,\n@@ -99,6 +112,18 @@ function test_gre {\n \tcleanup\n }\n \n+function test_erspan {\n+\tTYPE=erspan\n+\tDEV_NS=erspan00\n+\tDEV=erspan11\n+\tconfig_device\n+\tadd_erspan_tunnel\n+\tattach_bpf $DEV erspan_set_tunnel erspan_get_tunnel\n+\tping -c 1 10.1.1.100\n+\tip netns exec at_ns0 ping -c 1 10.1.1.200\n+\tcleanup\n+}\n+\n function test_vxlan {\n \tTYPE=vxlan\n \tDEV_NS=vxlan00\n@@ -151,14 +176,18 @@ function cleanup {\n \tip link del gretap11\n \tip link del vxlan11\n \tip link del geneve11\n+\tip link del erspan11\n \tpkill tcpdump\n \tpkill cat\n \tset -ex\n }\n \n+trap cleanup 0 2 3 6 9\n cleanup\n echo \"Testing GRE tunnel...\"\n test_gre\n+echo \"Testing ERSPAN tunnel...\"\n+test_erspan\n echo \"Testing VXLAN tunnel...\"\n test_vxlan\n echo \"Testing GENEVE tunnel...\"\n","prefixes":["net-next","3/3"]}