From patchwork Fri Dec 1 23:26:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 843809 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="A0eRkQ5Z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ypVlX52m0z9sNc for ; Sat, 2 Dec 2017 10:26:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751828AbdLAX0b (ORCPT ); Fri, 1 Dec 2017 18:26:31 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36615 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751675AbdLAX0X (ORCPT ); Fri, 1 Dec 2017 18:26:23 -0500 Received: by mail-pf0-f196.google.com with SMTP id p84so5293827pfd.3 for ; Fri, 01 Dec 2017 15:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D0RLQ6rOPU0MLv+MYYuudKpAkLD6SMJ99ZTDj5fsbXc=; b=A0eRkQ5ZVfylvWO/JW9TTfS3fVVIJRa61NhuH8KMxssyoqbF1R6Pig3nr4Q3uQpuXA YdPPGpQcsb+bDx48JI864fFp54jrujTB2evCXkMpNQkKa1ifXONSEwIVP48qqrLw7VP9 Fzod3PBmxV33Ecklk2IdKmFxqVQM0UnC2YT8ETMlIwKmG3t0oszvTRRNkqtkeBoT3TKU zbobasbfaSoOeT2lhiSRNGrHIag7YNrZfe9kZIxuJd5QQEEZGkNLa1AxZ3/IMBbO349p Vs//MsYblTJE2+xOGMC1jggs9PYjHRnvLZTFx/g1f8kKeStk8VB0MtH7CKk7lNwWY4HG 7JEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D0RLQ6rOPU0MLv+MYYuudKpAkLD6SMJ99ZTDj5fsbXc=; b=jNPs7D+pdwBwz+YmA9ZkbFTTrCWrIPjcefE3M7XJv9XiBDCa3+KblBpg++GDvge+Ek kmqXdLX5YkN8u7uYHcR1JZ8LylfshKOZhEA4i7BQyd7Fm4AKZN+JJjQi3RnBTd01daeD yYahuxI8RbzKowHglJX2+eUb1U6RUoEyqf095wOYvNjDshKlfOcsZuLDyo74UwXNyWAh kgmn1Aa7WyNe8QXbfRXjkx9KhV7+f03nXNdpu9YKiFZuvL8CI9JLpovzbupPLr5FKfnY u9ABZUiOje335fFOYXJ9oNT7G/X11o9ZCRrkFwuFL/rxLaatQ/mDMquKmkMvb3GSDCU3 MaGw== X-Gm-Message-State: AJaThX4sQve7AVQA3y0TcHtkoDuTCNHywarFBC136HoRniItRtUql/lo TYRDKIu7gFbWp1eGdoQCO6u70pNp X-Google-Smtp-Source: AGs4zMbt05pRIG44F4fqBsuVoDgdG1V9r+57MACdZsMOhAQXm9cwE9FdLv3fdqKPDy+hCmkVti7BAw== X-Received: by 10.101.73.203 with SMTP id t11mr7400187pgs.446.1512170783107; Fri, 01 Dec 2017 15:26:23 -0800 (PST) Received: from sc9-mailhost3.vmware.com ([208.91.2.1]) by smtp.gmail.com with ESMTPSA id s66sm15408632pfd.74.2017.12.01.15.26.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Dec 2017 15:26:22 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Cc: Alexei Starovoitov Subject: [PATCH net-next 3/3] samples/bpf: extend test_tunnel_bpf.sh with ip6gre Date: Fri, 1 Dec 2017 15:26:10 -0800 Message-Id: <1512170770-7866-4-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512170770-7866-1-git-send-email-u9012063@gmail.com> References: <1512170770-7866-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 existing tests for vxlan, gre, geneve, ipip, erspan, to include ip6 gre and gretap tunnel. Signed-off-by: William Tu Cc: Alexei Starovoitov --- samples/bpf/tcbpf2_kern.c | 43 ++++++++++++++++++++++++++++ samples/bpf/test_tunnel_bpf.sh | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/samples/bpf/tcbpf2_kern.c b/samples/bpf/tcbpf2_kern.c index 370b749f5ee6..15a469220e19 100644 --- a/samples/bpf/tcbpf2_kern.c +++ b/samples/bpf/tcbpf2_kern.c @@ -81,6 +81,49 @@ int _gre_get_tunnel(struct __sk_buff *skb) return TC_ACT_OK; } +SEC("ip6gretap_set_tunnel") +int _ip6gretap_set_tunnel(struct __sk_buff *skb) +{ + struct bpf_tunnel_key key; + int ret; + + __builtin_memset(&key, 0x0, sizeof(key)); + key.remote_ipv6[3] = _htonl(0x11); /* ::11 */ + key.tunnel_id = 2; + key.tunnel_tos = 0; + key.tunnel_ttl = 64; + key.tunnel_label = 0xabcde; + + ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), + BPF_F_TUNINFO_IPV6 | BPF_F_ZERO_CSUM_TX); + if (ret < 0) { + ERROR(ret); + return TC_ACT_SHOT; + } + + return TC_ACT_OK; +} + +SEC("ip6gretap_get_tunnel") +int _ip6gretap_get_tunnel(struct __sk_buff *skb) +{ + char fmt[] = "key %d remote ip6 ::%x label %x\n"; + struct bpf_tunnel_key key; + 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; + } + + bpf_trace_printk(fmt, sizeof(fmt), + key.tunnel_id, key.remote_ipv6[3], key.tunnel_label); + + return TC_ACT_OK; +} + SEC("erspan_set_tunnel") int _erspan_set_tunnel(struct __sk_buff *skb) { diff --git a/samples/bpf/test_tunnel_bpf.sh b/samples/bpf/test_tunnel_bpf.sh index 312e1722a39f..226f45381b76 100755 --- a/samples/bpf/test_tunnel_bpf.sh +++ b/samples/bpf/test_tunnel_bpf.sh @@ -33,6 +33,30 @@ function add_gre_tunnel { ip addr add dev $DEV 10.1.1.200/24 } +function add_ip6gretap_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 flowlabel 0xbcdef key 2 \ + 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 addr add dev $DEV_NS fc80::100/96 + 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 addr add dev $DEV fc80::200/24 + ip link set dev $DEV up +} + function add_erspan_tunnel { # in namespace ip netns exec at_ns0 \ @@ -113,6 +137,41 @@ function test_gre { cleanup } +function test_ip6gre { + TYPE=ip6gre + DEV_NS=ip6gre00 + DEV=ip6gre11 + config_device + # reuse the ip6gretap function + add_ip6gretap_tunnel + attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel + # underlay + ping6 -c 4 ::11 + # overlay: ipv4 over ipv6 + ip netns exec at_ns0 ping -c 1 10.1.1.200 + ping -c 1 10.1.1.100 + # overlay: ipv6 over ipv6 + ip netns exec at_ns0 ping6 -c 1 fc80::200 + cleanup +} + +function test_ip6gretap { + TYPE=ip6gretap + DEV_NS=ip6gretap00 + DEV=ip6gretap11 + config_device + add_ip6gretap_tunnel + attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel + # underlay + ping6 -c 4 ::11 + # overlay: ipv4 over ipv6 + ip netns exec at_ns0 ping -i .2 -c 1 10.1.1.200 + ping -c 1 10.1.1.100 + # overlay: ipv6 over ipv6 + ip netns exec at_ns0 ping6 -c 1 fc80::200 + cleanup +} + function test_erspan { TYPE=erspan DEV_NS=erspan00 @@ -175,6 +234,8 @@ function cleanup { ip link del veth1 ip link del ipip11 ip link del gretap11 + ip link del ip6gre11 + ip link del ip6gretap11 ip link del vxlan11 ip link del geneve11 ip link del erspan11 @@ -187,6 +248,10 @@ trap cleanup 0 2 3 6 9 cleanup echo "Testing GRE tunnel..." test_gre +echo "Testing IP6GRE tunnel..." +test_ip6gre +echo "Testing IP6GRETAP tunnel..." +test_ip6gretap echo "Testing ERSPAN tunnel..." test_erspan echo "Testing VXLAN tunnel..."