From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E34F6C4360F for ; Wed, 20 Mar 2019 14:49:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B59C82146E for ; Wed, 20 Mar 2019 14:49:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aMdriKlq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728120AbfCTOt4 (ORCPT ); Wed, 20 Mar 2019 10:49:56 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:43543 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728054AbfCTOty (ORCPT ); Wed, 20 Mar 2019 10:49:54 -0400 Received: by mail-qt1-f195.google.com with SMTP id v32so2783978qtc.10 for ; Wed, 20 Mar 2019 07:49:54 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=/nmec+GYuRB+1FYbBFUIeWupMYZu5rBNq/WI5++txPE=; b=aMdriKlqQIoPndiq9lDPJNoJQ1NKWbRKrb7iICy3+CsHS6OSYMl/PSWCNj+GdsBg/L yFgEx7eCq9qhw/Evp3Tt5paVY4KF4wPLFXhnhbP5DXfFWrCJ+RmfH/2KuUez9ec7Qdpb rwTua2PJ2KweqBShYUVZfIB54lkusGLYU8wTsBTtzU7VkyqcICGOvG94rYpiIyfPCXlH gPKFAQVVLl6jOl4rjmq3fcQUeTYPufVOQ5MRinn+UJ6W60rVcM48UFH+DhndHe8pL36W +rWZrV3X37O4TvmhIgYgeyHF3GQ18i+fyFiREwsGn+LM612quto9TTKYh6boxCppBfra cYEw== 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:mime-version:content-transfer-encoding; bh=/nmec+GYuRB+1FYbBFUIeWupMYZu5rBNq/WI5++txPE=; b=Z6FPXGnCWT6wKlsYU3EXSWmHzKojp127O3lpbxK+QbWyIC5qj0JOgq2h9X1sFc7ILx GrZZAGoBUmXHq1FCImiKKlDai7ietNianxY16haTi0wgpU8gSoGz9/YQ9gy+//r9rIHv ue8t+dJFEMn6jdT2+UcVBMC6SqVlNU+g8eAUmy3unTzjcf7y2C3irJlAMM5KK4KtWMth OqodRPJhA6HdQNPGk4Yit64Dt7qDvzuGSIdYRIFODWPO/VMJlrn+fvAWrah6KlXT9uhk XBYVlKwdVBilAtXdxfVUKuV4ZboSkXzvtZt4vnCoFyWQpptIVukZamr9KQ8SAwUnAnSF Eozw== X-Gm-Message-State: APjAAAVx5gNG4rUmZEVGc+Y62hYHKzP5IcvIJnQTfVC6Ey/prZoI4PwT +CguY4fV1ZyWgZzkPw4vKPqCLMna X-Google-Smtp-Source: APXvYqylTgCxcMiAf34E7LL6yoR52JshN86DI0YR2gziHu6IIBYjYnxCYtsV+R3KwhNnsfKLIL/RnQ== X-Received: by 2002:ac8:2c93:: with SMTP id 19mr7419566qtw.126.1553093393215; Wed, 20 Mar 2019 07:49:53 -0700 (PDT) Received: from willemb1.nyc.corp.google.com ([2620:0:1003:315:3fa1:a34c:1128:1d39]) by smtp.gmail.com with ESMTPSA id x201sm1142257qkb.92.2019.03.20.07.49.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 07:49:52 -0700 (PDT) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, sdf@google.com, posk@google.com, Willem de Bruijn Subject: [PATCH bpf-next 03/13] selftests/bpf: expand bpf tunnel test with decap Date: Wed, 20 Mar 2019 10:49:34 -0400 Message-Id: <20190320144944.147862-4-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog In-Reply-To: <20190320144944.147862-1-willemdebruijn.kernel@gmail.com> References: <20190320144944.147862-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Willem de Bruijn The bpf tunnel test encapsulates using bpf, then decapsulates using a standard tunnel device to verify correctness. Once encap is verified, also test decap, by replacing the tunnel device on decap with another bpf program. Signed-off-by: Willem de Bruijn --- .../selftests/bpf/progs/test_tc_tunnel.c | 31 +++++++++++++++++++ tools/testing/selftests/bpf/test_tc_tunnel.sh | 9 ++++++ 2 files changed, 40 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c index 8223e4347be8f..25db148635ab7 100644 --- a/tools/testing/selftests/bpf/progs/test_tc_tunnel.c +++ b/tools/testing/selftests/bpf/progs/test_tc_tunnel.c @@ -80,4 +80,35 @@ int encap_f(struct __sk_buff *skb) return TC_ACT_OK; } +SEC("decap") +int decap_f(struct __sk_buff *skb) +{ + struct iphdr iph_outer, iph_inner; + + if (skb->protocol != __bpf_constant_htons(ETH_P_IP)) + return TC_ACT_OK; + + if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph_outer, + sizeof(iph_outer)) < 0) + return TC_ACT_OK; + + if (iph_outer.ihl != 5 || iph_outer.protocol != IPPROTO_IPIP) + return TC_ACT_OK; + + if (bpf_skb_load_bytes(skb, ETH_HLEN + sizeof(iph_outer), + &iph_inner, sizeof(iph_inner)) < 0) + return TC_ACT_OK; + + if (bpf_skb_adjust_room(skb, -(int)sizeof(iph_outer), + BPF_ADJ_ROOM_NET, 0)) + return TC_ACT_SHOT; + + /* bpf_skb_adjust_room has moved outer over inner header: restore */ + if (bpf_skb_store_bytes(skb, ETH_HLEN, &iph_inner, sizeof(iph_inner), + BPF_F_INVALIDATE_HASH) < 0) + return TC_ACT_SHOT; + + return TC_ACT_OK; +} + char __license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/test_tc_tunnel.sh b/tools/testing/selftests/bpf/test_tc_tunnel.sh index 6ebb288a3afc7..91151d91e5a1b 100755 --- a/tools/testing/selftests/bpf/test_tc_tunnel.sh +++ b/tools/testing/selftests/bpf/test_tc_tunnel.sh @@ -72,4 +72,13 @@ ip netns exec "${ns2}" ip link set dev testtun0 up echo "test bpf encap with tunnel device decap" client_connect +# serverside, use BPF for decap +ip netns exec "${ns2}" ip link del dev testtun0 +ip netns exec "${ns2}" tc qdisc add dev veth2 clsact +ip netns exec "${ns2}" tc filter add dev veth2 ingress \ + bpf direct-action object-file ./test_tc_tunnel.o section decap +server_listen +echo "test bpf encap with bpf decap" +client_connect + echo OK -- 2.21.0.225.g810b269d1ac-goog