From patchwork Tue Dec 5 23:15:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 844960 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="gG6Yuoah"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yryKf5pYdz9sPm for ; Wed, 6 Dec 2017 10:16:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753007AbdLEXQD (ORCPT ); Tue, 5 Dec 2017 18:16:03 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:43513 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752841AbdLEXP5 (ORCPT ); Tue, 5 Dec 2017 18:15:57 -0500 Received: by mail-pg0-f67.google.com with SMTP id b18so1267612pgv.10 for ; Tue, 05 Dec 2017 15:15:57 -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=XThQyHKNZIc+hY7a2g0QmQSvMNxuRMhNs7FV6dMujuI=; b=gG6YuoahNOJI7o1EhXJC7t54XZkVCIy8UbNkD/rVEMSsRc6uUg4vgtt+87V7HRcSXg ZI1d2BdqOsF4kbZ/l2o0lH05mWNBxJO5gWr9R4Uxy36A24AQBpmYg3VLccpIN08OqdQW ljtND8Crj1mGEhTJ7R9UPlMK847sO4GDbwBc5EShM7e9A9crdYLVpl3Fq55eCe0zQUPI 9dRxioiuO1OInsPp+xdaD0JTLuZL1/004beEld4wbBqVSXUoKpUtem+5fwYGIkDlzeg3 UHk7e8L4IXdktEYPy3p0H5iiHx6VuLu2uwoc9NjDYlMd4GE1XXSF0np8UNuyX6wtopsH PwkA== 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=XThQyHKNZIc+hY7a2g0QmQSvMNxuRMhNs7FV6dMujuI=; b=IqOPAI+gQFuSWMziRmEG1diESEQVeB8LKOnjH/Yv9TxPxYNMqyfklndwIsOcnaYoAJ lP/LOc1m9AYIZRo5xgRESzdSD6FPllqj2zT/l/wbV+ykhaHrYkM7/cH1A2t0GVAIbBcP x0cBm5jvcvOblRM1d+ykCI3Jqvt7ldsVV5V8MHVoacjSSpMkAa2Xj/z4kgu4SQjYCZNP vxs/tGQ8/RHcw2bsGyh5VjFU0N2SXVKMXDjt77FqFtItjUS9fPNT2sSSgp8bdUGp4qkM GYarGDkoUn8YAuTReezxvIAuxlOLTDZEq+KkZQasIKiUHvt/zabt8s7tjK86bogqDe7E FkHg== X-Gm-Message-State: AJaThX4J5a+1Up7Ac3ivb+p/nl8FjYr4eIVNC/ynXnNK1e9HSAWn4y8A TMRL5hzW193qWWrDYbh/r/2+f6o+ X-Google-Smtp-Source: AGs4zMZcmkurw7RsEIaAqNm39MdsA/TA79eVXSPA1WUzcFC7TPVhdFbCc/IX/5HSiLMa1dqA+WoC9w== X-Received: by 10.99.95.70 with SMTP id t67mr19262729pgb.49.1512515756514; Tue, 05 Dec 2017 15:15:56 -0800 (PST) Received: from sc9-mailhost2.vmware.com ([208.91.2.1]) by smtp.gmail.com with ESMTPSA id t202sm1298227pgb.75.2017.12.05.15.15.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Dec 2017 15:15:55 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH net-next 2/2] samples/bpf: add ip6erspan sample code Date: Tue, 5 Dec 2017 15:15:45 -0800 Message-Id: <1512515745-21003-3-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512515745-21003-1-git-send-email-u9012063@gmail.com> References: <1512515745-21003-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Extend the existing tests for ip6erspan. Signed-off-by: William Tu --- samples/bpf/tcbpf2_kern.c | 58 ++++++++++++++++++++++++++++++++++++++++++ samples/bpf/test_tunnel_bpf.sh | 37 +++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/samples/bpf/tcbpf2_kern.c b/samples/bpf/tcbpf2_kern.c index 15a469220e19..79ad061079dd 100644 --- a/samples/bpf/tcbpf2_kern.c +++ b/samples/bpf/tcbpf2_kern.c @@ -181,6 +181,64 @@ int _erspan_get_tunnel(struct __sk_buff *skb) return TC_ACT_OK; } +SEC("ip4ip6erspan_set_tunnel") +int _ip4ip6erspan_set_tunnel(struct __sk_buff *skb) +{ + struct bpf_tunnel_key key; + struct erspan_metadata md; + int ret; + + __builtin_memset(&key, 0x0, sizeof(key)); + key.remote_ipv6[3] = _htonl(0x11); + key.tunnel_id = 2; + key.tunnel_tos = 0; + key.tunnel_ttl = 64; + + ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), + BPF_F_TUNINFO_IPV6); + if (ret < 0) { + ERROR(ret); + return TC_ACT_SHOT; + } + + md.index = htonl(123); + ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md)); + if (ret < 0) { + ERROR(ret); + return TC_ACT_SHOT; + } + + return TC_ACT_OK; +} + +SEC("ip4ip6erspan_get_tunnel") +int _ip4ip6erspan_get_tunnel(struct __sk_buff *skb) +{ + char fmt[] = "key %d remote ip6 ::%x erspan index 0x%x\n"; + struct bpf_tunnel_key key; + struct erspan_metadata md; + u32 index; + int ret; + + ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), BPF_F_TUNINFO_IPV6); + if (ret < 0) { + ERROR(ret); + return TC_ACT_SHOT; + } + + ret = bpf_skb_get_tunnel_opt(skb, &md, sizeof(md)); + if (ret < 0) { + ERROR(ret); + return TC_ACT_SHOT; + } + + index = bpf_ntohl(md.index); + bpf_trace_printk(fmt, sizeof(fmt), + key.tunnel_id, key.remote_ipv6[0], index); + + return TC_ACT_OK; +} + SEC("vxlan_set_tunnel") int _vxlan_set_tunnel(struct __sk_buff *skb) { diff --git a/samples/bpf/test_tunnel_bpf.sh b/samples/bpf/test_tunnel_bpf.sh index 226f45381b76..f53efb62f699 100755 --- a/samples/bpf/test_tunnel_bpf.sh +++ b/samples/bpf/test_tunnel_bpf.sh @@ -70,6 +70,28 @@ function add_erspan_tunnel { ip addr add dev $DEV 10.1.1.200/24 } +function add_ip6erspan_tunnel { + + # assign ipv6 address + ip netns exec at_ns0 ip addr add ::11/96 dev veth0 + ip netns exec at_ns0 ip link set dev veth0 up + ip addr add dev veth1 ::22/96 + ip link set dev veth1 up + + # in namespace + ip netns exec at_ns0 \ + ip link add dev $DEV_NS type $TYPE seq key 2 erspan 123 \ + local ::11 remote ::22 + + 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 + + # out of namespace + ip link add dev $DEV type $TYPE external + ip addr add dev $DEV 10.1.1.200/24 + ip link set dev $DEV up +} + function add_vxlan_tunnel { # Set static ARP entry here because iptables set-mark works # on L3 packet, as a result not applying to ARP packets, @@ -184,6 +206,18 @@ function test_erspan { cleanup } +function test_ip6erspan { + TYPE=ip6erspan + DEV_NS=ip6erspan00 + DEV=ip6erspan11 + config_device + add_ip6erspan_tunnel + attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel + ping6 -c 3 ::11 + ip netns exec at_ns0 ping -c 1 10.1.1.200 + cleanup +} + function test_vxlan { TYPE=vxlan DEV_NS=vxlan00 @@ -239,6 +273,7 @@ function cleanup { ip link del vxlan11 ip link del geneve11 ip link del erspan11 + ip link del ip6erspan11 pkill tcpdump pkill cat set -ex @@ -254,6 +289,8 @@ echo "Testing IP6GRETAP tunnel..." test_ip6gretap echo "Testing ERSPAN tunnel..." test_erspan +echo "Testing IP6ERSPAN tunnel..." +test_ip6erspan echo "Testing VXLAN tunnel..." test_vxlan echo "Testing GENEVE tunnel..."