From patchwork Sun Jan 15 07:16:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102153 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE196C677F1 for ; Sun, 15 Jan 2023 07:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230286AbjAOHQy (ORCPT ); Sun, 15 Jan 2023 02:16:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjAOHQc (ORCPT ); Sun, 15 Jan 2023 02:16:32 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C071FCDC1; Sat, 14 Jan 2023 23:16:23 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id s13-20020a17090a6e4d00b0022900843652so9496623pjm.1; Sat, 14 Jan 2023 23:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2pBBA/Ht2M9hrjp8K0+TAAr/in6NVCRMPTM9sEcsGTI=; b=TY29OTqQECMOlR/zS6uHrCnyuLbhI6U629I5wSrhbqmPy/qdZMSf8uc7lwZIXtxlfV Fwj//6L5O8VdY9fKCKuXu/FFs4VG8KV0Uf5vZpPACSJbCawh8XQ19+ShIURy1+BsDRS3 3V9R5xxn9rsoFO+FOr1B8GQEAtQdZvX/t4ktgyYjYoIYBG7bp4AGzI+ODDCMC0YTZmnM XEYU8zjXzAvNEWzsXLUwECa2/PF2GuqbdT5QFGv2G/Ieiax7gcuLEQ25ZPLla3xsgpdl w4uYn9Vyxl/tvJs1u/ux1KvULz5G6A5NoVuQJyrrHJ/HqP3qe9ko0Lv8YZ1I75N0xqjT 40gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2pBBA/Ht2M9hrjp8K0+TAAr/in6NVCRMPTM9sEcsGTI=; b=P6VYJfelmVryS4MD3ShmNWV9Z3wnF1X1stYBHOe1I5pSnp4uQtRgw1eiCTfsMK7BGJ Ww102z+otZlHygrw0a5CyGkzi495fJZw6xHmSGyg1RZtJNa7tBEY5eGYLyA0o23ax/Rl BMou1u+CwBu4FoCD53MJJr9Nr/7LL5TEeny/HBSrSszr3Lb28E9Ebze3Z8+b8cBfeqiF BDgyZxpyU0vYD6U3C9jLKhH7813pTuHayufQNEN9jDq3xJB3zQJPUyTTt6SH4zj1CXXp U40xk6dg3m+DhCw8wYPA5tuTHYVHzA128H0LLVHbB1z44Napi9a5yFQdSrxfYNrhRHqL wH9A== X-Gm-Message-State: AFqh2kqU1RVsBslXNDRaJWjt8saVWw79OzZfmxUo+ceQVsJoZ1FOc6Il WUkTi6xyRZexZv3OSJyENw== X-Google-Smtp-Source: AMrXdXtzmo4m2cUEYPwfgS0qvgxnGMjTJS/9W3B/Raka4RCyzbPYiZe4IrggsnQCc5Rb2qbbMkye1A== X-Received: by 2002:a05:6a20:9497:b0:a4:486c:568f with SMTP id hs23-20020a056a20949700b000a4486c568fmr83748236pzb.59.1673766983249; Sat, 14 Jan 2023 23:16:23 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:22 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 01/10] samples/bpf: ensure ipv6 is enabled before running tests Date: Sun, 15 Jan 2023 16:16:04 +0900 Message-Id: <20230115071613.125791-2-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently, a few of BPF tests use ipv6 functionality. The problem here is that if ipv6 is disabled, these tests will fail, and even if the test fails, it will not tell you why it failed. $ sudo ./test_cgrp2_sock2.sh RTNETLINK answers: Permission denied In order to fix this, this commit ensures ipv6 is enabled prior to running tests. Signed-off-by: Daniel T. Lee --- samples/bpf/tc_l2_redirect.sh | 3 +++ samples/bpf/test_cgrp2_sock2.sh | 4 +++- samples/bpf/test_cgrp2_tc.sh | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/samples/bpf/tc_l2_redirect.sh b/samples/bpf/tc_l2_redirect.sh index 37d95ef3c20f..a28a8fc99dbe 100755 --- a/samples/bpf/tc_l2_redirect.sh +++ b/samples/bpf/tc_l2_redirect.sh @@ -8,6 +8,7 @@ REDIRECT_USER='./tc_l2_redirect' REDIRECT_BPF='./tc_l2_redirect_kern.o' RP_FILTER=$(< /proc/sys/net/ipv4/conf/all/rp_filter) +IPV6_DISABLED=$(< /proc/sys/net/ipv6/conf/all/disable_ipv6) IPV6_FORWARDING=$(< /proc/sys/net/ipv6/conf/all/forwarding) function config_common { @@ -64,6 +65,7 @@ function config_common { sysctl -q -w net.ipv4.conf.all.rp_filter=0 sysctl -q -w net.ipv6.conf.all.forwarding=1 + sysctl -q -w net.ipv6.conf.all.disable_ipv6=0 } function cleanup { @@ -77,6 +79,7 @@ function cleanup { $IP link del ip6t >& /dev/null sysctl -q -w net.ipv4.conf.all.rp_filter=$RP_FILTER sysctl -q -w net.ipv6.conf.all.forwarding=$IPV6_FORWARDING + sysctl -q -w net.ipv6.conf.all.disable_ipv6=$IPV6_DISABLED rm -f /sys/fs/bpf/tc/globals/tun_iface [[ -z $DEBUG ]] || set -x set -e diff --git a/samples/bpf/test_cgrp2_sock2.sh b/samples/bpf/test_cgrp2_sock2.sh index 6a3dbe642b2b..ac45828ed2bd 100755 --- a/samples/bpf/test_cgrp2_sock2.sh +++ b/samples/bpf/test_cgrp2_sock2.sh @@ -7,13 +7,15 @@ LINK_PIN=$BPFFS/test_cgrp2_sock2 function config_device { ip netns add at_ns0 ip link add veth0 type veth peer name veth0b - ip link set veth0b up ip link set veth0 netns at_ns0 + ip netns exec at_ns0 sysctl -q net.ipv6.conf.veth0.disable_ipv6=0 ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0 ip netns exec at_ns0 ip addr add 2401:db00::1/64 dev veth0 nodad ip netns exec at_ns0 ip link set dev veth0 up + sysctl -q net.ipv6.conf.veth0b.disable_ipv6=0 ip addr add 172.16.1.101/24 dev veth0b ip addr add 2401:db00::2/64 dev veth0b nodad + ip link set veth0b up } function config_cgroup { diff --git a/samples/bpf/test_cgrp2_tc.sh b/samples/bpf/test_cgrp2_tc.sh index 395573be6ae8..a6f1ed03ddf6 100755 --- a/samples/bpf/test_cgrp2_tc.sh +++ b/samples/bpf/test_cgrp2_tc.sh @@ -73,11 +73,13 @@ setup_net() { start) $IP link add $HOST_IFC type veth peer name $NS_IFC || return $? $IP link set dev $HOST_IFC up || return $? + sysctl -q net.ipv6.conf.$HOST_IFC.disable_ipv6=0 sysctl -q net.ipv6.conf.$HOST_IFC.accept_dad=0 $IP netns add ns || return $? $IP link set dev $NS_IFC netns ns || return $? $IP -n $NS link set dev $NS_IFC up || return $? + $IP netns exec $NS sysctl -q net.ipv6.conf.$NS_IFC.disable_ipv6=0 $IP netns exec $NS sysctl -q net.ipv6.conf.$NS_IFC.accept_dad=0 $TC qdisc add dev $HOST_IFC clsact || return $? $TC filter add dev $HOST_IFC egress bpf da obj $BPF_PROG sec $BPF_SECTION || return $? From patchwork Sun Jan 15 07:16:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102154 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B33C9C677F1 for ; Sun, 15 Jan 2023 07:17:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230420AbjAOHRJ (ORCPT ); Sun, 15 Jan 2023 02:17:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbjAOHQg (ORCPT ); Sun, 15 Jan 2023 02:16:36 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75EE9B46C; Sat, 14 Jan 2023 23:16:27 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id 141so17650402pgc.0; Sat, 14 Jan 2023 23:16:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4I4IUYD2iUsel0bQWxcWEZ0X528rvr4lKqvUrGey0z4=; b=gsIUMdxCZ3YBLETWAp/bgHB/ej7qfLcbPkqlrklttjIg4r9fMF8VvSgZcqR6U/M1bu O9jSXCwbXQc9jp8bwJggqMS0GzKfFFAaiC1hnLmraa8w0S6ZdnUVHFbPTonAulkL5YEd 0fySb/+hhhymkgoOurlsHSuPx+bfRbyFsKw03nb1EMcIVJgrKcI3b4Q1TdrfD8pk2f9u 9PfGQTX6YCZmCIaTueuCdviqkEKrarMBusVWWLhwjrACoTh/lF2/KxXM/3Qd4vZawiyc 6LodKm3V/YLw7B8c9LMgQbrt8HZR0iNJacL4s2j9mfn7AaWjsWv0neFzmcs9oEA+Vxkb rT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4I4IUYD2iUsel0bQWxcWEZ0X528rvr4lKqvUrGey0z4=; b=qQwPJpGo/K59Iw1llwlQc/7sLol7TO2mDhpiPSJZP3zMZ7lr1B+8rktlkhtooDmMgI CP49eRXsK4As30ad7jmzIJOiCbA5Vm3czLtjCNo2ejRAXz0ondi4aE/NZmC9ukfzrCQZ oTtKgFs8HhK80tdMz/vxFUO1SfMSjPp6CvwD2QmEdXvyUIjQVK0YZi/JVD+YWLgU9PWE Ok4YUAxzEnBhw5YuZ9Jpk0QNMOVo2lUrqnxK+O1+wNhna/+ORuX/n+cs69+fEuFHuKFH tUikOL36oyEMzKQYCKcK7EQ35ZhZotGwggkTUDVbFxWpfEBu+DON04GgU9MBlPuSzhHM Wsdw== X-Gm-Message-State: AFqh2kq/SOFq9VQF2oTa7FltR9+w6GUTZyQl5XGVZ9M5kgI9RvzKxkP/ 4EFhPwANCXm3hPoeMuM5aw== X-Google-Smtp-Source: AMrXdXubzKttbngkWL7N9qBggK46A7Q73hVWTw1G5sM+FvtwF6Wh89SuB5qipnPB0Ex6FejF/tRxCw== X-Received: by 2002:aa7:8d4a:0:b0:578:333d:d6ab with SMTP id s10-20020aa78d4a000000b00578333dd6abmr83634589pfe.21.1673766986925; Sat, 14 Jan 2023 23:16:26 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:26 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 02/10] samples/bpf: refactor BPF functionality testing scripts Date: Sun, 15 Jan 2023 16:16:05 +0900 Message-Id: <20230115071613.125791-3-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently, some test scripts are experiencing minor errors related to executing tests. $ sudo ./test_cgrp2_sock.sh ./test_cgrp2_sock.sh: 22: test_cgrp2_sock: not found This problem occurs because the path to the execution target is not properly specified. Therefore, this commit solves this problem by specifying a relative path to its executables. This commit also makes a concise refactoring of hard-coded BPF program names. Signed-off-by: Daniel T. Lee --- samples/bpf/lwt_len_hist.sh | 4 ++-- samples/bpf/test_cgrp2_sock.sh | 16 +++++++++------- samples/bpf/test_cgrp2_sock2.sh | 5 ++++- samples/bpf/test_cgrp2_tc.sh | 4 ++-- samples/bpf/test_lwt_bpf.sh | 8 +++++--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/samples/bpf/lwt_len_hist.sh b/samples/bpf/lwt_len_hist.sh index 0eda9754f50b..ff7d1ba0f7ed 100755 --- a/samples/bpf/lwt_len_hist.sh +++ b/samples/bpf/lwt_len_hist.sh @@ -4,7 +4,7 @@ NS1=lwt_ns1 VETH0=tst_lwt1a VETH1=tst_lwt1b - +BPF_PROG=lwt_len_hist_kern.o TRACE_ROOT=/sys/kernel/debug/tracing function cleanup { @@ -30,7 +30,7 @@ ip netns exec $NS1 netserver echo 1 > ${TRACE_ROOT}/tracing_on cp /dev/null ${TRACE_ROOT}/trace -ip route add 192.168.253.2/32 encap bpf out obj lwt_len_hist_kern.o section len_hist dev $VETH0 +ip route add 192.168.253.2/32 encap bpf out obj $BPF_PROG section len_hist dev $VETH0 netperf -H 192.168.253.2 -t TCP_STREAM cat ${TRACE_ROOT}/trace | grep -v '^#' ./lwt_len_hist diff --git a/samples/bpf/test_cgrp2_sock.sh b/samples/bpf/test_cgrp2_sock.sh index 9f6174236856..36bd7cb46f06 100755 --- a/samples/bpf/test_cgrp2_sock.sh +++ b/samples/bpf/test_cgrp2_sock.sh @@ -3,6 +3,8 @@ # Test various socket options that can be set by attaching programs to cgroups. +MY_DIR=$(dirname $0) +TEST=$MY_DIR/test_cgrp2_sock CGRP_MNT="/tmp/cgroupv2-test_cgrp2_sock" ################################################################################ @@ -19,7 +21,7 @@ print_result() check_sock() { - out=$(test_cgrp2_sock) + out=$($TEST) echo $out | grep -q "$1" if [ $? -ne 0 ]; then print_result 1 "IPv4: $2" @@ -33,7 +35,7 @@ check_sock() check_sock6() { - out=$(test_cgrp2_sock -6) + out=$($TEST -6) echo $out | grep -q "$1" if [ $? -ne 0 ]; then print_result 1 "IPv6: $2" @@ -61,7 +63,7 @@ cleanup_and_exit() [ -n "$msg" ] && echo "ERROR: $msg" - test_cgrp2_sock -d ${CGRP_MNT}/sockopts + $TEST -d ${CGRP_MNT}/sockopts ip li del cgrp2_sock umount ${CGRP_MNT} @@ -98,7 +100,7 @@ check_sock6 "dev , mark 0, priority 0" "No programs attached" # verify device is set # -test_cgrp2_sock -b cgrp2_sock ${CGRP_MNT}/sockopts +$TEST -b cgrp2_sock ${CGRP_MNT}/sockopts if [ $? -ne 0 ]; then cleanup_and_exit 1 "Failed to install program to set device" fi @@ -107,7 +109,7 @@ check_sock6 "dev cgrp2_sock, mark 0, priority 0" "Device set" # verify mark is set # -test_cgrp2_sock -m 666 ${CGRP_MNT}/sockopts +$TEST -m 666 ${CGRP_MNT}/sockopts if [ $? -ne 0 ]; then cleanup_and_exit 1 "Failed to install program to set mark" fi @@ -116,7 +118,7 @@ check_sock6 "dev , mark 666, priority 0" "Mark set" # verify priority is set # -test_cgrp2_sock -p 123 ${CGRP_MNT}/sockopts +$TEST -p 123 ${CGRP_MNT}/sockopts if [ $? -ne 0 ]; then cleanup_and_exit 1 "Failed to install program to set priority" fi @@ -125,7 +127,7 @@ check_sock6 "dev , mark 0, priority 123" "Priority set" # all 3 at once # -test_cgrp2_sock -b cgrp2_sock -m 666 -p 123 ${CGRP_MNT}/sockopts +$TEST -b cgrp2_sock -m 666 -p 123 ${CGRP_MNT}/sockopts if [ $? -ne 0 ]; then cleanup_and_exit 1 "Failed to install program to set device, mark and priority" fi diff --git a/samples/bpf/test_cgrp2_sock2.sh b/samples/bpf/test_cgrp2_sock2.sh index ac45828ed2bd..00cc8d15373c 100755 --- a/samples/bpf/test_cgrp2_sock2.sh +++ b/samples/bpf/test_cgrp2_sock2.sh @@ -2,7 +2,10 @@ # SPDX-License-Identifier: GPL-2.0 BPFFS=/sys/fs/bpf +MY_DIR=$(dirname $0) +TEST=$MY_DIR/test_cgrp2_sock2 LINK_PIN=$BPFFS/test_cgrp2_sock2 +BPF_PROG=$MY_DIR/sock_flags_kern.o function config_device { ip netns add at_ns0 @@ -36,7 +39,7 @@ function config_bpffs { } function attach_bpf { - ./test_cgrp2_sock2 /tmp/cgroupv2/foo sock_flags_kern.o $1 + $TEST /tmp/cgroupv2/foo $BPF_PROG $1 [ $? -ne 0 ] && exit 1 } diff --git a/samples/bpf/test_cgrp2_tc.sh b/samples/bpf/test_cgrp2_tc.sh index a6f1ed03ddf6..37a2c9cba6d0 100755 --- a/samples/bpf/test_cgrp2_tc.sh +++ b/samples/bpf/test_cgrp2_tc.sh @@ -76,8 +76,8 @@ setup_net() { sysctl -q net.ipv6.conf.$HOST_IFC.disable_ipv6=0 sysctl -q net.ipv6.conf.$HOST_IFC.accept_dad=0 - $IP netns add ns || return $? - $IP link set dev $NS_IFC netns ns || return $? + $IP netns add $NS || return $? + $IP link set dev $NS_IFC netns $NS || return $? $IP -n $NS link set dev $NS_IFC up || return $? $IP netns exec $NS sysctl -q net.ipv6.conf.$NS_IFC.disable_ipv6=0 $IP netns exec $NS sysctl -q net.ipv6.conf.$NS_IFC.accept_dad=0 diff --git a/samples/bpf/test_lwt_bpf.sh b/samples/bpf/test_lwt_bpf.sh index 65a976058dd3..8fc9356545d8 100755 --- a/samples/bpf/test_lwt_bpf.sh +++ b/samples/bpf/test_lwt_bpf.sh @@ -19,6 +19,8 @@ IPVETH3="192.168.111.2" IP_LOCAL="192.168.99.1" +PROG_SRC="test_lwt_bpf.c" +BPF_PROG="test_lwt_bpf.o" TRACE_ROOT=/sys/kernel/debug/tracing function lookup_mac() @@ -36,7 +38,7 @@ function lookup_mac() function cleanup { set +ex - rm test_lwt_bpf.o 2> /dev/null + rm $BPF_PROG 2> /dev/null ip link del $VETH0 2> /dev/null ip link del $VETH1 2> /dev/null ip link del $VETH2 2> /dev/null @@ -76,7 +78,7 @@ function install_test { cleanup_routes cp /dev/null ${TRACE_ROOT}/trace - OPTS="encap bpf headroom 14 $1 obj test_lwt_bpf.o section $2 $VERBOSE" + OPTS="encap bpf headroom 14 $1 obj $BPF_PROG section $2 $VERBOSE" if [ "$1" == "in" ]; then ip route add table local local ${IP_LOCAL}/32 $OPTS dev lo @@ -374,7 +376,7 @@ DST_IFINDEX=$(cat /sys/class/net/$VETH0/ifindex) CLANG_OPTS="-O2 -target bpf -I ../include/" CLANG_OPTS+=" -DSRC_MAC=$SRC_MAC -DDST_MAC=$DST_MAC -DDST_IFINDEX=$DST_IFINDEX" -clang $CLANG_OPTS -c test_lwt_bpf.c -o test_lwt_bpf.o +clang $CLANG_OPTS -c $PROG_SRC -o $BPF_PROG test_ctx_xmit test_ctx_out From patchwork Sun Jan 15 07:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102155 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B7E1C3DA78 for ; Sun, 15 Jan 2023 07:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjAOHRd (ORCPT ); Sun, 15 Jan 2023 02:17:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbjAOHQq (ORCPT ); Sun, 15 Jan 2023 02:16:46 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DDC79007; Sat, 14 Jan 2023 23:16:31 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id p24so27362528plw.11; Sat, 14 Jan 2023 23:16:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2M5wk3Ez9XgQJyntZJtJSNbfjxm2vkTKIKYAZNk8Mp8=; b=avI0vMeV8DQ5yGUfbJrt8m6isIKf5bEGKjfE9xC8WpPfn9awUiLEl9cBUfKLcgR5Go SoVz9dUome6IOHstMbwnZJ9KFkemFahgbJheGEHQ+Xkcaych5TqxclOh8AQh6t/5i4mW fU4YDWrS/CA7wpywoSQ4IhuTCq3in5CuDvuiL+XddB8HNXl3HPUekR8hUWUAK00/d/Bu KpqqPhhczBoUWjKlm+HJrZ645y/ZbUJyzBSoPh5U350XcVA0hEEYbhvsBIsDmNu6dsDW honyxJydyKR5hndA6D3G6pdPbz+QR7Vk5ANIeE066nDXhCcTSTyyQoY+nvbx18cIN/Py +Ubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2M5wk3Ez9XgQJyntZJtJSNbfjxm2vkTKIKYAZNk8Mp8=; b=UuqH8HzA3dKiKZePo3l0jbFedVuPy5BDsFJTNDJEk9VNWVJ/QA7MGhdyHnMLbUgvVN hRgXWNNnjOaLaHQMty6gEG/5PN6KdmaLwGqJb6pwiIL56Af+8hxhBtb6u8HF357HASEg Bxdfv6x6XKHFtMQGYCFcd6NDXwJFRQhJdta8GKkhJpkUAVDv/oWKf1lI1JmwCbEbCs+K MVaX5VeG+GTSL7/UHKFkBX4FVZocIN1VvVqtNlVs8X1IWeDghmsl7xvkfo3BSbf5yEQ6 C5n4xqoR5WNNv0G0hyxUS3Wp5bCy3/yW1iFAn+csLChbV/BQBIerHyaTANLI70N1+xqi OBjw== X-Gm-Message-State: AFqh2kqeyj4CeBTjHcoRala8ee9Cr5/jY3Grtq21K8shDxW7hD9zSsEL aKBuPevxMLi26fCcfK4pKXG3DjUOIRQgfB4= X-Google-Smtp-Source: AMrXdXtRbxjnZJ1gJyGuugTfd6DfH+wyBvQ2sLMl2n/XljsNtNIBzL6y69kMl13XuxDeNa4TezMAnQ== X-Received: by 2002:a05:6a20:9398:b0:b6:8c0b:7146 with SMTP id x24-20020a056a20939800b000b68c0b7146mr14248309pzh.59.1673766990648; Sat, 14 Jan 2023 23:16:30 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:30 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 03/10] samples/bpf: fix broken lightweight tunnel testing Date: Sun, 15 Jan 2023 16:16:06 +0900 Message-Id: <20230115071613.125791-4-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The test_lwt_bpf is a script that tests the functionality of BPF through the output of the ftrace with bpf_trace_printk. Currently, this program is not operating normally for several reasons. First of all, this test script can't parse the ftrace results properly. GNU sed tries to be as greedy as possible when attempting pattern matching. Due to this, cutting metadata (such as timestamp) from the log entry of ftrace doesn't work properly, and also desired log isn't extracted properly. To make sed stripping clearer, 'nocontext-info' option with the ftrace has been used to remove metadata from the log. Also, instead of using unclear pattern matching, this commit specifies an explicit parse pattern. Also, unlike before when this test was introduced, the way bpf_trace_printk behaves has changed[1]. The previous bpf_trace_printk had to always have '\n' in order to print newline, but now that the bpf_trace_printk call includes newline by default, so '\n' is no longer needed. Lastly with the lwt ENCAP_BPF out, the context information with the sk_buff protocol is preserved. Therefore, this commit changes the previous test result from 'protocol 0' to 'protocol 8', which means ETH_P_IP. [1]: commit ac5a72ea5c89 ("bpf: Use dedicated bpf_trace_printk event instead of trace_printk()") Signed-off-by: Daniel T. Lee --- samples/bpf/test_lwt_bpf.c | 36 ++++++++++++++++++------------------ samples/bpf/test_lwt_bpf.sh | 11 +++++++---- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/samples/bpf/test_lwt_bpf.c b/samples/bpf/test_lwt_bpf.c index 1b568575ad11..f53dab88d231 100644 --- a/samples/bpf/test_lwt_bpf.c +++ b/samples/bpf/test_lwt_bpf.c @@ -44,9 +44,9 @@ SEC("test_ctx") int do_test_ctx(struct __sk_buff *skb) { skb->cb[0] = CB_MAGIC; - printk("len %d hash %d protocol %d\n", skb->len, skb->hash, + printk("len %d hash %d protocol %d", skb->len, skb->hash, skb->protocol); - printk("cb %d ingress_ifindex %d ifindex %d\n", skb->cb[0], + printk("cb %d ingress_ifindex %d ifindex %d", skb->cb[0], skb->ingress_ifindex, skb->ifindex); return BPF_OK; @@ -56,9 +56,9 @@ int do_test_ctx(struct __sk_buff *skb) SEC("test_cb") int do_test_cb(struct __sk_buff *skb) { - printk("cb0: %x cb1: %x cb2: %x\n", skb->cb[0], skb->cb[1], + printk("cb0: %x cb1: %x cb2: %x", skb->cb[0], skb->cb[1], skb->cb[2]); - printk("cb3: %x cb4: %x\n", skb->cb[3], skb->cb[4]); + printk("cb3: %x cb4: %x", skb->cb[3], skb->cb[4]); return BPF_OK; } @@ -72,11 +72,11 @@ int do_test_data(struct __sk_buff *skb) struct iphdr *iph = data; if (data + sizeof(*iph) > data_end) { - printk("packet truncated\n"); + printk("packet truncated"); return BPF_DROP; } - printk("src: %x dst: %x\n", iph->saddr, iph->daddr); + printk("src: %x dst: %x", iph->saddr, iph->daddr); return BPF_OK; } @@ -97,7 +97,7 @@ static inline int rewrite(struct __sk_buff *skb, uint32_t old_ip, ret = bpf_skb_load_bytes(skb, IP_PROTO_OFF, &proto, 1); if (ret < 0) { - printk("bpf_l4_csum_replace failed: %d\n", ret); + printk("bpf_l4_csum_replace failed: %d", ret); return BPF_DROP; } @@ -120,14 +120,14 @@ static inline int rewrite(struct __sk_buff *skb, uint32_t old_ip, ret = bpf_l4_csum_replace(skb, off, old_ip, new_ip, flags | sizeof(new_ip)); if (ret < 0) { - printk("bpf_l4_csum_replace failed: %d\n"); + printk("bpf_l4_csum_replace failed: %d"); return BPF_DROP; } } ret = bpf_l3_csum_replace(skb, IP_CSUM_OFF, old_ip, new_ip, sizeof(new_ip)); if (ret < 0) { - printk("bpf_l3_csum_replace failed: %d\n", ret); + printk("bpf_l3_csum_replace failed: %d", ret); return BPF_DROP; } @@ -137,7 +137,7 @@ static inline int rewrite(struct __sk_buff *skb, uint32_t old_ip, ret = bpf_skb_store_bytes(skb, IP_SRC_OFF, &new_ip, sizeof(new_ip), 0); if (ret < 0) { - printk("bpf_skb_store_bytes() failed: %d\n", ret); + printk("bpf_skb_store_bytes() failed: %d", ret); return BPF_DROP; } @@ -153,12 +153,12 @@ int do_test_rewrite(struct __sk_buff *skb) ret = bpf_skb_load_bytes(skb, IP_DST_OFF, &old_ip, 4); if (ret < 0) { - printk("bpf_skb_load_bytes failed: %d\n", ret); + printk("bpf_skb_load_bytes failed: %d", ret); return BPF_DROP; } if (old_ip == 0x2fea8c0) { - printk("out: rewriting from %x to %x\n", old_ip, new_ip); + printk("out: rewriting from %x to %x", old_ip, new_ip); return rewrite(skb, old_ip, new_ip, 1); } @@ -173,7 +173,7 @@ static inline int __do_push_ll_and_redirect(struct __sk_buff *skb) ret = bpf_skb_change_head(skb, 14, 0); if (ret < 0) { - printk("skb_change_head() failed: %d\n", ret); + printk("skb_change_head() failed: %d", ret); } ehdr.h_proto = __constant_htons(ETH_P_IP); @@ -182,7 +182,7 @@ static inline int __do_push_ll_and_redirect(struct __sk_buff *skb) ret = bpf_skb_store_bytes(skb, 0, &ehdr, sizeof(ehdr), 0); if (ret < 0) { - printk("skb_store_bytes() failed: %d\n", ret); + printk("skb_store_bytes() failed: %d", ret); return BPF_DROP; } @@ -202,7 +202,7 @@ int do_push_ll_and_redirect(struct __sk_buff *skb) ret = __do_push_ll_and_redirect(skb); if (ret >= 0) - printk("redirected to %d\n", ifindex); + printk("redirected to %d", ifindex); return ret; } @@ -229,7 +229,7 @@ SEC("fill_garbage") int do_fill_garbage(struct __sk_buff *skb) { __fill_garbage(skb); - printk("Set initial 96 bytes of header to FF\n"); + printk("Set initial 96 bytes of header to FF"); return BPF_OK; } @@ -238,7 +238,7 @@ int do_fill_garbage_and_redirect(struct __sk_buff *skb) { int ifindex = DST_IFINDEX; __fill_garbage(skb); - printk("redirected to %d\n", ifindex); + printk("redirected to %d", ifindex); return bpf_redirect(ifindex, 0); } @@ -246,7 +246,7 @@ int do_fill_garbage_and_redirect(struct __sk_buff *skb) SEC("drop_all") int do_drop_all(struct __sk_buff *skb) { - printk("dropping with: %d\n", BPF_DROP); + printk("dropping with: %d", BPF_DROP); return BPF_DROP; } diff --git a/samples/bpf/test_lwt_bpf.sh b/samples/bpf/test_lwt_bpf.sh index 8fc9356545d8..2e9f5126963b 100755 --- a/samples/bpf/test_lwt_bpf.sh +++ b/samples/bpf/test_lwt_bpf.sh @@ -22,6 +22,7 @@ IP_LOCAL="192.168.99.1" PROG_SRC="test_lwt_bpf.c" BPF_PROG="test_lwt_bpf.o" TRACE_ROOT=/sys/kernel/debug/tracing +CONTEXT_INFO=$(cat ${TRACE_ROOT}/trace_options | grep context) function lookup_mac() { @@ -98,7 +99,7 @@ function remove_prog { function filter_trace { # Add newline to allow starting EXPECT= variables on newline NL=$'\n' - echo "${NL}$*" | sed -e 's/^.*: : //g' + echo "${NL}$*" | sed -e 's/bpf_trace_printk: //g' } function expect_fail { @@ -162,11 +163,11 @@ function test_ctx_out { failure "test_ctx out: packets are dropped" } match_trace "$(get_trace)" " -len 84 hash 0 protocol 0 +len 84 hash 0 protocol 8 cb 1234 ingress_ifindex 0 ifindex 0 -len 84 hash 0 protocol 0 +len 84 hash 0 protocol 8 cb 1234 ingress_ifindex 0 ifindex 0 -len 84 hash 0 protocol 0 +len 84 hash 0 protocol 8 cb 1234 ingress_ifindex 0 ifindex 0" || exit 1 remove_prog out } @@ -369,6 +370,7 @@ setup_one_veth $NS1 $VETH0 $VETH1 $IPVETH0 $IPVETH1 $IPVETH1b setup_one_veth $NS2 $VETH2 $VETH3 $IPVETH2 $IPVETH3 ip netns exec $NS1 netserver echo 1 > ${TRACE_ROOT}/tracing_on +echo nocontext-info > ${TRACE_ROOT}/trace_options DST_MAC=$(lookup_mac $VETH1 $NS1) SRC_MAC=$(lookup_mac $VETH0) @@ -399,4 +401,5 @@ test_netperf_redirect cleanup echo 0 > ${TRACE_ROOT}/tracing_on +echo $CONTEXT_INFO > ${TRACE_ROOT}/trace_options exit 0 From patchwork Sun Jan 15 07:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102156 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82C31C63797 for ; Sun, 15 Jan 2023 07:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbjAOHRs (ORCPT ); Sun, 15 Jan 2023 02:17:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbjAOHQu (ORCPT ); Sun, 15 Jan 2023 02:16:50 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FE9B45B; Sat, 14 Jan 2023 23:16:34 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id d10so17594379pgm.13; Sat, 14 Jan 2023 23:16:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8kDnC+/cfUMMOFjYmAxLkFmwnVT0UDNBRF4bIPq83UM=; b=WJBB9wETNIDP9BCZ8yiYzbgE4gUzl/NBgPPpHtMTfcpfqit0N3GbiI8YvI41bpJgsJ I9xWAhVYU+9n5PeiKcxN/bFD5UTUSDQiOa1VODh815qQbOoXIA3fRgtln0TySVhXRC3p zaNFRpUPqKXx8BMN6bjtGc9oqpcH/cEydxE8xJbl+LtfKUa/QxmFOWiKjvqdHzX/PJmE B8Vqyk9PH3kJD2T3Gva4HJaTy/TEwCk8gmb/QUXppfcEOxI9RZ8r4P6+YcqIE/WbUn0R 0Rztbhz55NpkHgNfXqNf1Il9XavHUoCWYaAuJwJxqpOrRiMhF3Hybo0XxkKFkoNmalpw Dw5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8kDnC+/cfUMMOFjYmAxLkFmwnVT0UDNBRF4bIPq83UM=; b=MGf2NL/w+hWzzj5e0MNAFPdjDY0Ulo5eRs/sotCFGZtGH4AzeiKcmhJy9jtyoFg51j 3AL945h7OJkvdSDAjkMWnVUM9PZGCZKB3f+3yhIlkWgLekEYsxBhWhZ6jQEngohi0CiF N7vF2w2a4IjMoF2obEgRAI91o2PHurT7BuHyUBSKfWrgeKzH5N2EtEEBfd5bJ+jwrVBP mbAKZ4bPPvDBpakyC1iY/MDzPQbPmi5A1bjQUvyLI9+RI4Y0Ws4DZttFf0nl4TeKXEvM dBmsrLIRo16UdSHdxIBcAJi7BTf4x364nAhzZi+NGeyQEfBb0qOZPaTHmehbGUZisaqf CWqQ== X-Gm-Message-State: AFqh2krnKe4GS5nd1TEz2YErxnq//jPLpr8Xb8QMxf2lcHZyA9AFRfmR xH47fn94S9JggHFKkXUtQg== X-Google-Smtp-Source: AMrXdXvVXQbZbTni1a0PSp7fjVXAWGUbUYO/UC+BynA6En81L8SzbO9iG26ZdF41L7P7k0u1fei3jQ== X-Received: by 2002:a05:6a00:1a55:b0:58d:9791:44bc with SMTP id h21-20020a056a001a5500b0058d979144bcmr1773337pfv.9.1673766994350; Sat, 14 Jan 2023 23:16:34 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:33 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 04/10] samples/bpf: fix broken cgroup socket testing Date: Sun, 15 Jan 2023 16:16:07 +0900 Message-Id: <20230115071613.125791-5-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently, executing test_cgrp2_sock2 fails due to wrong section header. This 'cgroup/sock1' style section is previously used at 'samples/bpf_load' (deprecated) BPF loader. Because this style isn't supported in libbpf, this commit fixes this problem by correcting the section header. $ sudo ./test_cgrp2_sock2.sh libbpf: prog 'bpf_prog1': missing BPF prog type, check ELF section name 'cgroup/sock1' libbpf: prog 'bpf_prog1': failed to load: -22 libbpf: failed to load object './sock_flags_kern.o' ERROR: loading BPF object file failed In addition, this BPF program filters ping packets by comparing whether the socket type uses SOCK_RAW. However, after the ICMP socket[1] was developed, ping sends ICMP packets using SOCK_DGRAM. Therefore, in this commit, the packet filtering is changed to use SOCK_DGRAM instead of SOCK_RAW. $ strace --trace socket ping -6 -c1 -w1 ::1 socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6) = 3 [1]: https://lwn.net/Articles/422330/ Signed-off-by: Daniel T. Lee --- samples/bpf/sock_flags_kern.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/bpf/sock_flags_kern.c b/samples/bpf/sock_flags_kern.c index 6d0ac7569d6f..1d58cb9b6fa4 100644 --- a/samples/bpf/sock_flags_kern.c +++ b/samples/bpf/sock_flags_kern.c @@ -5,7 +5,7 @@ #include #include -SEC("cgroup/sock1") +SEC("cgroup/sock") int bpf_prog1(struct bpf_sock *sk) { char fmt[] = "socket: family %d type %d protocol %d\n"; @@ -17,29 +17,29 @@ int bpf_prog1(struct bpf_sock *sk) bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol); bpf_trace_printk(fmt2, sizeof(fmt2), uid, gid); - /* block PF_INET6, SOCK_RAW, IPPROTO_ICMPV6 sockets + /* block PF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6 sockets * ie., make ping6 fail */ if (sk->family == PF_INET6 && - sk->type == SOCK_RAW && + sk->type == SOCK_DGRAM && sk->protocol == IPPROTO_ICMPV6) return 0; return 1; } -SEC("cgroup/sock2") +SEC("cgroup/sock") int bpf_prog2(struct bpf_sock *sk) { char fmt[] = "socket: family %d type %d protocol %d\n"; bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol); - /* block PF_INET, SOCK_RAW, IPPROTO_ICMP sockets + /* block PF_INET, SOCK_DGRAM, IPPROTO_ICMP sockets * ie., make ping fail */ if (sk->family == PF_INET && - sk->type == SOCK_RAW && + sk->type == SOCK_DGRAM && sk->protocol == IPPROTO_ICMP) return 0; From patchwork Sun Jan 15 07:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102157 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAB40C3DA78 for ; Sun, 15 Jan 2023 07:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbjAOHSA (ORCPT ); Sun, 15 Jan 2023 02:18:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjAOHQy (ORCPT ); Sun, 15 Jan 2023 02:16:54 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952D3B472; Sat, 14 Jan 2023 23:16:38 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id s67so17625361pgs.3; Sat, 14 Jan 2023 23:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ocnqdzwpiFm+OPG+OonsFNnUBEnRsSpKIXYgKGCflvM=; b=avku4lgBI86PlqIWq2y/K7eXXy2PIl42YwD3nvVmwTYZZNs9TiqB7Rh4kzSq/j62yh r0XWG0Fb22GzgGE1Ng1s/dRlSHD7eKbsMJ8+B3pbZ9QEIPXyHaaJd25j79MsinPTQ2Tu L2p4ww7RByq34+eyFC4dXZsbfRLuduXRXh5pyn1LG/uWpqjK8Se/404erVYTKyqBWmqL xuXRX0+msqVkupYpLBrED8LFsFWNIeJvnVbZhjrkVZZHaEuYKBSZqIODdg1bfGwDZMaW ByIxI5wjJiBUJUP3b0EiQptnqw98r0twcXGYR5kZbvGNlXUcynCuNE6iI6faHWDc+dBk pHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ocnqdzwpiFm+OPG+OonsFNnUBEnRsSpKIXYgKGCflvM=; b=SJwD445wwcmnKT/ShlaDKstA58wQiwFd7sBwnMD2CAcTCt2hyoyk1xyVujhfXu2fHf sS2su2RCNay84gjaZec3EVr3MErURto14//uZ3tA4l/7jdJmpHzhPbGcneTLY7iWeYL5 Ma/P/h/NsvIVU47MxkjQ8GoH4NzERZGaRqcpRYz0vK0ad5a702uyhjdyW3YT5gb7W1Z0 uAvcTq+01uch/dhvw/OvGaovyjqZNAbG8rwB/UmvUMTjTOaBBgr8l2LficcqLxUbWqop axb4BuDKTqGXz3J3jJ1z+JywmrezBOauj8Mi+BMiuaUa/18Ib6JnIBphlLckr898VWBC Q6JQ== X-Gm-Message-State: AFqh2kp2luwEcNlajEUcWlrVWMTotVNpAFawf33toZ+8SF1eWs4e0AoV YQE3FJNEtgbglJDBKHy0jw== X-Google-Smtp-Source: AMrXdXvSYx/gnUhUc4jw5gULtOEwObzv6H6eMPXMjrqBkpO9MyisCKJH5Y43vpwhKmyGt632tW0ryw== X-Received: by 2002:a62:58c1:0:b0:573:f869:2115 with SMTP id m184-20020a6258c1000000b00573f8692115mr82117503pfb.9.1673766998054; Sat, 14 Jan 2023 23:16:38 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:37 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 05/10] samples/bpf: replace broken overhead microbenchmark with fib_table_lookup Date: Sun, 15 Jan 2023 16:16:08 +0900 Message-Id: <20230115071613.125791-6-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The test_overhead bpf program is designed to compare performance between tracepoint and kprobe. Initially it used task_rename and urandom_read tracepoint. However, commit 14c174633f34 ("random: remove unused tracepoints") removed urandom_read tracepoint, and for this reason the test_overhead got broken. This commit introduces new microbenchmark using fib_table_lookup. This microbenchmark sends UDP packets to localhost in order to invoke fib_table_lookup. In a nutshell: fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); addr.sin_addr.s_addr = inet_addr(DUMMY_IP); addr.sin_port = htons(DUMMY_PORT); for() { sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&addr, sizeof(addr)); } on 4 cpus in parallel: lookup per sec base (no tracepoints, no kprobes) 381k with kprobe at fib_table_lookup() 325k with tracepoint at fib:fib_table_lookup 330k with raw_tracepoint at fib:fib_table_lookup 365k Fixes: 14c174633f34 ("random: remove unused tracepoints") Signed-off-by: Daniel T. Lee --- samples/bpf/test_overhead_kprobe_kern.c | 2 +- samples/bpf/test_overhead_raw_tp_kern.c | 2 +- samples/bpf/test_overhead_tp_kern.c | 26 ++++++++++++++++------- samples/bpf/test_overhead_user.c | 28 +++++++++++++++++-------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c index 8fdd2c9c56b2..ba82949338c2 100644 --- a/samples/bpf/test_overhead_kprobe_kern.c +++ b/samples/bpf/test_overhead_kprobe_kern.c @@ -39,7 +39,7 @@ int prog(struct pt_regs *ctx) return 0; } -SEC("kprobe/urandom_read") +SEC("kprobe/fib_table_lookup") int prog2(struct pt_regs *ctx) { return 0; diff --git a/samples/bpf/test_overhead_raw_tp_kern.c b/samples/bpf/test_overhead_raw_tp_kern.c index 8763181a32f3..3e29de0eca98 100644 --- a/samples/bpf/test_overhead_raw_tp_kern.c +++ b/samples/bpf/test_overhead_raw_tp_kern.c @@ -9,7 +9,7 @@ int prog(struct bpf_raw_tracepoint_args *ctx) return 0; } -SEC("raw_tracepoint/urandom_read") +SEC("raw_tracepoint/fib_table_lookup") int prog2(struct bpf_raw_tracepoint_args *ctx) { return 0; diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c index 80edadacb692..f170e9b1ea21 100644 --- a/samples/bpf/test_overhead_tp_kern.c +++ b/samples/bpf/test_overhead_tp_kern.c @@ -22,15 +22,27 @@ int prog(struct task_rename *ctx) return 0; } -/* from /sys/kernel/debug/tracing/events/random/urandom_read/format */ -struct urandom_read { +/* from /sys/kernel/debug/tracing/events/fib/fib_table_lookup/format */ +struct fib_table_lookup { __u64 pad; - int got_bits; - int pool_left; - int input_left; + __u32 tb_id; + int err; + int oif; + int iif; + __u8 proto; + __u8 tos; + __u8 scope; + __u8 flags; + __u8 src[4]; + __u8 dst[4]; + __u8 gw4[4]; + __u8 gw6[16]; + __u16 sport; + __u16 dport; + char name[16]; }; -SEC("tracepoint/random/urandom_read") -int prog2(struct urandom_read *ctx) +SEC("tracepoint/fib/fib_table_lookup") +int prog2(struct fib_table_lookup *ctx) { return 0; } diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c index 88717f8ec6ac..ce28d30f852e 100644 --- a/samples/bpf/test_overhead_user.c +++ b/samples/bpf/test_overhead_user.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -20,6 +22,8 @@ #include #define MAX_CNT 1000000 +#define DUMMY_IP "127.0.0.1" +#define DUMMY_PORT 80 static struct bpf_link *links[2]; static struct bpf_object *obj; @@ -35,8 +39,8 @@ static __u64 time_get_ns(void) static void test_task_rename(int cpu) { - __u64 start_time; char buf[] = "test\n"; + __u64 start_time; int i, fd; fd = open("/proc/self/comm", O_WRONLY|O_TRUNC); @@ -57,26 +61,32 @@ static void test_task_rename(int cpu) close(fd); } -static void test_urandom_read(int cpu) +static void test_fib_table_lookup(int cpu) { + struct sockaddr_in addr; + char buf[] = "test\n"; __u64 start_time; - char buf[4]; int i, fd; - fd = open("/dev/urandom", O_RDONLY); + fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) { - printf("couldn't open /dev/urandom\n"); + printf("couldn't open socket\n"); exit(1); } + memset((char *)&addr, 0, sizeof(addr)); + addr.sin_addr.s_addr = inet_addr(DUMMY_IP); + addr.sin_port = htons(DUMMY_PORT); + addr.sin_family = AF_INET; start_time = time_get_ns(); for (i = 0; i < MAX_CNT; i++) { - if (read(fd, buf, sizeof(buf)) < 0) { - printf("failed to read from /dev/urandom: %s\n", strerror(errno)); + if (sendto(fd, buf, strlen(buf), 0, + (struct sockaddr *)&addr, sizeof(addr)) < 0) { + printf("failed to start ping: %s\n", strerror(errno)); close(fd); return; } } - printf("urandom_read:%d: %lld events per sec\n", + printf("fib_table_lookup:%d: %lld events per sec\n", cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); close(fd); } @@ -92,7 +102,7 @@ static void loop(int cpu, int flags) if (flags & 1) test_task_rename(cpu); if (flags & 2) - test_urandom_read(cpu); + test_fib_table_lookup(cpu); } static void run_perf_test(int tasks, int flags) From patchwork Sun Jan 15 07:16:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102158 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6D98C67871 for ; Sun, 15 Jan 2023 07:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjAOHSB (ORCPT ); Sun, 15 Jan 2023 02:18:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjAOHQz (ORCPT ); Sun, 15 Jan 2023 02:16:55 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4407FCDE2; Sat, 14 Jan 2023 23:16:42 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id q64so26310982pjq.4; Sat, 14 Jan 2023 23:16:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0fmkqPUWv3S5ReG8IilYKGmgBx5rYCR8nInPLJsrUdA=; b=JckQO82bMaW8AJrI+vTWUAL9lZhEC4wxvZXMRVmnkGdG8M8ReExIaHLtVGHq8OmBFj RcyOu8uCUgWi8SMAmV6Xkp8/NlsqFJ39hI63fKEp3AMLTIpcS1Te9mEIJ6BpMFv49S1y HwO/uVIAw7h+Xr+9eOfjRYbVAeTmecS6eeC8JCC7sQxEJtCW3+ehkhQXVWT3rOKA4yiq waRx+zRreaeI2uDF068Xe2Giz0kOx6bjANWYgZzOy0buFxAlvbwED7JATDY22JQYWuy8 OygjQhx9MBWHD7871tic2eSlu7LoXDuYCEnpTlfU0R/EhU/8IUlqF7JYsHFtVKr1we01 m41g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0fmkqPUWv3S5ReG8IilYKGmgBx5rYCR8nInPLJsrUdA=; b=wsPgwAnAvVymIBfqb++hu/J6I/dZulm3z7GId+t1niL+6ejWIPc7lwHn/nf79CF2nH 6+mHTzXU6v2toWeOIZlzvOamiPVos0QQULN01DkbFeBhj+WeTL5EDPY06BG18DoD72sV t2SBmQLlT83enzKV2egjgtQhl9RyGorcfaP1Ag1hul+QUmMajqhEj9AW32RVmtict4db DOl7L5CvPQjSvFgShVZMYsXHSvB3Phxu6ttWvO94d5P73g6HNGgzMPjJfENB6Qsxm/Bh 1cX2dBA90mcSpk6lFosVHKTCDa+jXvNEDcAdkbyJdD9P+F4/L2FUp0IwuLKiLN1S7ZvP jx7A== X-Gm-Message-State: AFqh2koEMkEOYcjQ60U3kPu7NUt2lC1QTbLdgYoLfMAJp5Mg8PIJpBQ8 LC/Jk87E6wV+LdK5uDUNswJd7rdW8SAGSf8= X-Google-Smtp-Source: AMrXdXsYxrj9wnq3uEG9mh9To8xNgk2FIcPF6nBG4DffLGDUaAdzZgQsUjwDGa9lnErgWosKKmCegg== X-Received: by 2002:a05:6a20:2a98:b0:b8:66d3:30b8 with SMTP id v24-20020a056a202a9800b000b866d330b8mr1799168pzh.20.1673767001751; Sat, 14 Jan 2023 23:16:41 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:41 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 06/10] samples/bpf: replace legacy map with the BTF-defined map Date: Sun, 15 Jan 2023 16:16:09 +0900 Message-Id: <20230115071613.125791-7-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net With libbpf 1.0 release, support for legacy BPF map declaration syntax had been dropped. If you run a program using legacy BPF in the latest libbpf, the following error will be output. libbpf: map 'lwt_len_hist_map' (legacy): legacy map definitions are deprecated, use BTF-defined maps instead libbpf: Use of BPF_ANNOTATE_KV_PAIR is deprecated, use BTF-defined maps in .maps section instead This commit replaces legacy map with the BTF-defined map. Signed-off-by: Daniel T. Lee --- samples/bpf/lwt_len_hist_kern.c | 24 +++++++----------------- samples/bpf/test_cgrp2_tc_kern.c | 25 +++++++------------------ 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_kern.c index 1fa14c54963a..44ea7b56760e 100644 --- a/samples/bpf/lwt_len_hist_kern.c +++ b/samples/bpf/lwt_len_hist_kern.c @@ -16,23 +16,13 @@ #include #include -struct bpf_elf_map { - __u32 type; - __u32 size_key; - __u32 size_value; - __u32 max_elem; - __u32 flags; - __u32 id; - __u32 pinning; -}; - -struct bpf_elf_map SEC("maps") lwt_len_hist_map = { - .type = BPF_MAP_TYPE_PERCPU_HASH, - .size_key = sizeof(__u64), - .size_value = sizeof(__u64), - .pinning = 2, - .max_elem = 1024, -}; +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_HASH); + __type(key, u64); + __type(value, u64); + __uint(pinning, LIBBPF_PIN_BY_NAME); + __uint(max_entries, 1024); +} lwt_len_hist_map SEC(".maps"); static unsigned int log2(unsigned int v) { diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc_kern.c index 4dd532a312b9..737ce3eb8944 100644 --- a/samples/bpf/test_cgrp2_tc_kern.c +++ b/samples/bpf/test_cgrp2_tc_kern.c @@ -19,24 +19,13 @@ struct eth_hdr { unsigned short h_proto; }; -#define PIN_GLOBAL_NS 2 -struct bpf_elf_map { - __u32 type; - __u32 size_key; - __u32 size_value; - __u32 max_elem; - __u32 flags; - __u32 id; - __u32 pinning; -}; - -struct bpf_elf_map SEC("maps") test_cgrp2_array_pin = { - .type = BPF_MAP_TYPE_CGROUP_ARRAY, - .size_key = sizeof(uint32_t), - .size_value = sizeof(uint32_t), - .pinning = PIN_GLOBAL_NS, - .max_elem = 1, -}; +struct { + __uint(type, BPF_MAP_TYPE_CGROUP_ARRAY); + __type(key, u32); + __type(value, u32); + __uint(pinning, LIBBPF_PIN_BY_NAME); + __uint(max_entries, 1); +} test_cgrp2_array_pin SEC(".maps"); SEC("filter") int handle_egress(struct __sk_buff *skb) From patchwork Sun Jan 15 07:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102159 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 518BDC678D7 for ; Sun, 15 Jan 2023 07:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbjAOHSD (ORCPT ); Sun, 15 Jan 2023 02:18:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230332AbjAOHRB (ORCPT ); Sun, 15 Jan 2023 02:17:01 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA928CDD5; Sat, 14 Jan 2023 23:16:45 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id i65so15442605pfc.0; Sat, 14 Jan 2023 23:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p84tYMZEQXh/QdeHoG0Y2waJnOExFznBjHemL6AX+5c=; b=PossRIwEacxLxawEt/KAP6YCxW+x8yiqDIOTxF6SWEqoouLh0NWxjY49m7RgDH/VGs Gg4OYJP1sgmuHaMun22Fu67+P1J8Jpgm9H9bQovC2WMHDB3EVJZMrAXFeyRk7OAnhR4H LZ9LMvX4h4IcdtUjaptBl0bOKB3dJt0K+U2D0HtXjtHFVU1i1s466prk1aUri1TvBzUd P/chZ23z5zu4EYuCMh/AcRHTnkyJoqJNL6ejG39o4ZsBdoxS3GTEqrTvHouw5IJWg0iN 13oaEkv5D2rqvwGhCD0rKVMPsT4koDXbSK4nxX55moCJrjPTOLt0/+RQsUoveSh9YmD0 Z8Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p84tYMZEQXh/QdeHoG0Y2waJnOExFznBjHemL6AX+5c=; b=c9gZFRudi51FfSPsI2qJDcRQnl4MgOH3oovgqqaIK6+HtvgDrl0uAvK2HAxpOadXoT HkJmUkUOQyTseIaGmvkcESDItfWhEJ6Cb3TleWzX/rOT7d/gOL6atJFQGqR47CePMWr8 Y8O5ZrxuyTlRsRJ8m1GItUcPkmNAykIOrXgo7br7rtIPeJTMSMFiDZbDCtHvAinPQ/hr oL9gQr6lc7I3QqbzR8iYh73/w++nS+J/D4L6sQUZ/vFTVfPHqliQ9h8mCQfRWo1GZ286 itHEkeVnSoDzBvHivC3uzNjrZA1W/FuG7SZQEinEpUYkZXFGnzTN9gXu4fVHBmc765bO KeYQ== X-Gm-Message-State: AFqh2kpnGwLj/LG6QY7vHOUg6Krw7+567jAZDoOYgCWPfXeDpknxb+w2 rLMqWAIrI279hZeVBARWtw== X-Google-Smtp-Source: AMrXdXvV0bQRSJ0I3nfBS+a6jD++ICoVTAFw+lXAeyk/dkNICkzWVy+5MxdoDTNf+7mFztM6xBooew== X-Received: by 2002:a62:1887:0:b0:582:5886:e1b7 with SMTP id 129-20020a621887000000b005825886e1b7mr45554548pfy.14.1673767005403; Sat, 14 Jan 2023 23:16:45 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:44 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 07/10] samples/bpf: split common macros to net_shared.h Date: Sun, 15 Jan 2023 16:16:10 +0900 Message-Id: <20230115071613.125791-8-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently, many programs under sample/bpf often include individual macros by directly including the header under "linux/" rather than using the "vmlinux.h" header. However, there are some problems with migrating to "vmlinux.h" because there is no definition for utility functions such as endianness conversion (ntohs/htons). Fortunately, the xdp_sample program already has a function that can be replaced to solve this problem. Therefore, this commit attempts to separate these functions into a file called net_shared.h to make them universally available. Additionally, this file includes network-related macros that are not defined in "vmlinux.h". (inspired by 'selftests' bpf_tracing_net.h) Signed-off-by: Daniel T. Lee --- samples/bpf/net_shared.h | 26 ++++++++++++++++++++++++++ samples/bpf/xdp_sample.bpf.h | 22 +--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 samples/bpf/net_shared.h diff --git a/samples/bpf/net_shared.h b/samples/bpf/net_shared.h new file mode 100644 index 000000000000..04b29b217d25 --- /dev/null +++ b/samples/bpf/net_shared.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef _NET_SHARED_H +#define _NET_SHARED_H + +#define ETH_ALEN 6 +#define ETH_P_802_3_MIN 0x0600 +#define ETH_P_8021Q 0x8100 +#define ETH_P_8021AD 0x88A8 +#define ETH_P_IP 0x0800 +#define ETH_P_IPV6 0x86DD +#define ETH_P_ARP 0x0806 +#define IPPROTO_ICMPV6 58 + +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ + __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define bpf_ntohs(x) __builtin_bswap16(x) +#define bpf_htons(x) __builtin_bswap16(x) +#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ + __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define bpf_ntohs(x) (x) +#define bpf_htons(x) (x) +#else +# error "Endianness detection needs to be set up for your compiler?!" +#endif + +#endif diff --git a/samples/bpf/xdp_sample.bpf.h b/samples/bpf/xdp_sample.bpf.h index 25b1dbe9b37b..fecc41c5df04 100644 --- a/samples/bpf/xdp_sample.bpf.h +++ b/samples/bpf/xdp_sample.bpf.h @@ -7,17 +7,9 @@ #include #include +#include "net_shared.h" #include "xdp_sample_shared.h" -#define ETH_ALEN 6 -#define ETH_P_802_3_MIN 0x0600 -#define ETH_P_8021Q 0x8100 -#define ETH_P_8021AD 0x88A8 -#define ETH_P_IP 0x0800 -#define ETH_P_IPV6 0x86DD -#define ETH_P_ARP 0x0806 -#define IPPROTO_ICMPV6 58 - #define EINVAL 22 #define ENETDOWN 100 #define EMSGSIZE 90 @@ -55,18 +47,6 @@ static __always_inline void swap_src_dst_mac(void *data) p[5] = dst[2]; } -#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define bpf_ntohs(x) __builtin_bswap16(x) -#define bpf_htons(x) __builtin_bswap16(x) -#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define bpf_ntohs(x) (x) -#define bpf_htons(x) (x) -#else -# error "Endianness detection needs to be set up for your compiler?!" -#endif - /* * Note: including linux/compiler.h or linux/kernel.h for the macros below * conflicts with vmlinux.h include in BPF files, so we define them here. From patchwork Sun Jan 15 07:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102160 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86ED9C3DA78 for ; Sun, 15 Jan 2023 07:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbjAOHSH (ORCPT ); Sun, 15 Jan 2023 02:18:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjAOHRE (ORCPT ); Sun, 15 Jan 2023 02:17:04 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA60B47F; Sat, 14 Jan 2023 23:16:49 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id 20so68754plo.3; Sat, 14 Jan 2023 23:16:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1Kn0HqKH1woDv5zNrRXar4SWzT3i9nml5kDUW9Kqf18=; b=SXd6WJj3uOl8pUbpCk3tCYfUCNcoO2k7cM07KjMCG6Uxe1v4lVFvt94/VR9lz4Cpdj 7M5/KwowqM4xuml+/CSfnlkJszEOvRC4ZRLD2IREylZqG2ZecXM2nlaWaoRw9A3tUfzQ oe1X2quyAEhz2mxmkU/fjpWecgOmFOrxyl/ax9Fkjn05pKuz9g9r1m4KUUmbEpvsbKIq y2fNJOtmy0XaHdPdMO8Ny/unuCE3ClLR/qbgrmXPaOmYqHPt34htioHuGRGbsxc+F1Fc OAKFQknwB6otIVBsA/ItLYfVpGz3FGDdhC78UbybNLocJ5KfekgqVfn3Fv355k96tCDi KAKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Kn0HqKH1woDv5zNrRXar4SWzT3i9nml5kDUW9Kqf18=; b=Y0T6DAW73lHErUlvBE1cGFqtEGaXfyRtS+XxbARqXK3nwWjLTrK9h+9hIzKcXx/0fk qalju8cgJq/CQcqQ+b58cKVTtOs2rLVNFaWL8bxEHUDukz1TCNHa4gooX3ZRYsECS7h8 ZocHiygO2SmFG+11YvGCXD98rzY7umgJqzrhJRTvX0aAAhHB2mpjTQQQd73r/XkgHAzG BmutR3oxtBlKi+mnqzRSlaZ50XfhcQU+HqiBLqpShfRWLeMtjx4AIJXcldwomEWpcSK1 GbScEuMVtaaxHcTFcIQpulfCcp09M4kcNsxRg0cc9aA4hdOpvA94+9OI5eJW6Y0Q3IFu ba2w== X-Gm-Message-State: AFqh2krMOmVm1NLGFNO0fOkwOgnoAGHOpHo+j5rb4rkd39C4uiCijH04 epNVBNJzfGxkXPB1eRRKYg== X-Google-Smtp-Source: AMrXdXvlnrhtceuZL/iqISGKSDBCb3L/8L7I63OT5O2jZntP+W29SiZTzRBi8N9kBhBFwrbJG8VCKA== X-Received: by 2002:a05:6a20:2d1f:b0:ac:9d6b:c1f0 with SMTP id g31-20020a056a202d1f00b000ac9d6bc1f0mr109316512pzl.40.1673767009058; Sat, 14 Jan 2023 23:16:49 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:48 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 08/10] samples/bpf: replace BPF programs header with net_shared.h Date: Sun, 15 Jan 2023 16:16:11 +0900 Message-Id: <20230115071613.125791-9-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This commit applies "net_shared.h" to BPF programs to remove existing network related header dependencies. Also, this commit removes unnecessary headers before applying "vmlinux.h" to the BPF programs. Mostly, endianness conversion function has been applied to the source. In addition, several macros have been defined to fulfill the INET, TC-related constants. Signed-off-by: Daniel T. Lee --- samples/bpf/net_shared.h | 6 ++++++ samples/bpf/sock_flags_kern.c | 10 +++++----- samples/bpf/test_cgrp2_tc_kern.c | 6 ++---- samples/bpf/test_lwt_bpf.c | 3 ++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/samples/bpf/net_shared.h b/samples/bpf/net_shared.h index 04b29b217d25..e9429af9aa44 100644 --- a/samples/bpf/net_shared.h +++ b/samples/bpf/net_shared.h @@ -2,6 +2,9 @@ #ifndef _NET_SHARED_H #define _NET_SHARED_H +#define AF_INET 2 +#define AF_INET6 10 + #define ETH_ALEN 6 #define ETH_P_802_3_MIN 0x0600 #define ETH_P_8021Q 0x8100 @@ -11,6 +14,9 @@ #define ETH_P_ARP 0x0806 #define IPPROTO_ICMPV6 58 +#define TC_ACT_OK 0 +#define TC_ACT_SHOT 2 + #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define bpf_ntohs(x) __builtin_bswap16(x) diff --git a/samples/bpf/sock_flags_kern.c b/samples/bpf/sock_flags_kern.c index 1d58cb9b6fa4..84837ed48eb3 100644 --- a/samples/bpf/sock_flags_kern.c +++ b/samples/bpf/sock_flags_kern.c @@ -1,5 +1,5 @@ +#include "net_shared.h" #include -#include #include #include #include @@ -17,10 +17,10 @@ int bpf_prog1(struct bpf_sock *sk) bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol); bpf_trace_printk(fmt2, sizeof(fmt2), uid, gid); - /* block PF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6 sockets + /* block AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6 sockets * ie., make ping6 fail */ - if (sk->family == PF_INET6 && + if (sk->family == AF_INET6 && sk->type == SOCK_DGRAM && sk->protocol == IPPROTO_ICMPV6) return 0; @@ -35,10 +35,10 @@ int bpf_prog2(struct bpf_sock *sk) bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol); - /* block PF_INET, SOCK_DGRAM, IPPROTO_ICMP sockets + /* block AF_INET, SOCK_DGRAM, IPPROTO_ICMP sockets * ie., make ping fail */ - if (sk->family == PF_INET && + if (sk->family == AF_INET && sk->type == SOCK_DGRAM && sk->protocol == IPPROTO_ICMP) return 0; diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc_kern.c index 737ce3eb8944..45a2f01d2029 100644 --- a/samples/bpf/test_cgrp2_tc_kern.c +++ b/samples/bpf/test_cgrp2_tc_kern.c @@ -5,10 +5,8 @@ * License as published by the Free Software Foundation. */ #define KBUILD_MODNAME "foo" -#include -#include +#include "net_shared.h" #include -#include #include #include @@ -42,7 +40,7 @@ int handle_egress(struct __sk_buff *skb) if (data + sizeof(*eth) + sizeof(*ip6h) > data_end) return TC_ACT_OK; - if (eth->h_proto != htons(ETH_P_IPV6) || + if (eth->h_proto != bpf_htons(ETH_P_IPV6) || ip6h->nexthdr != IPPROTO_ICMPV6) { bpf_trace_printk(dont_care_msg, sizeof(dont_care_msg), eth->h_proto, ip6h->nexthdr); diff --git a/samples/bpf/test_lwt_bpf.c b/samples/bpf/test_lwt_bpf.c index f53dab88d231..fc093fbc760a 100644 --- a/samples/bpf/test_lwt_bpf.c +++ b/samples/bpf/test_lwt_bpf.c @@ -10,6 +10,7 @@ * General Public License for more details. */ +#include "net_shared.h" #include #include #include @@ -176,7 +177,7 @@ static inline int __do_push_ll_and_redirect(struct __sk_buff *skb) printk("skb_change_head() failed: %d", ret); } - ehdr.h_proto = __constant_htons(ETH_P_IP); + ehdr.h_proto = bpf_htons(ETH_P_IP); memcpy(&ehdr.h_source, &smac, 6); memcpy(&ehdr.h_dest, &dmac, 6); From patchwork Sun Jan 15 07:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102161 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27911C3DA78 for ; Sun, 15 Jan 2023 07:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230512AbjAOHS3 (ORCPT ); Sun, 15 Jan 2023 02:18:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230112AbjAOHRF (ORCPT ); Sun, 15 Jan 2023 02:17:05 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49EBCB47E; Sat, 14 Jan 2023 23:16:53 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id r18so17603897pgr.12; Sat, 14 Jan 2023 23:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IXtBMdlxptD+rgtlXku5y/M/YWWbgrzqb1KWu60anSo=; b=BzmMU/twu97qKTkVkWbfv/IpCYI7V78IjtH988IqnzkiwIotFszjB/0iW4aaIh2PkQ xQe9B6Yx8zLJm9PsstCTVI2RIwr+UKI4bxo9ym22HOs1l/RyiI/59YX0Zp3yGioEtYEe Qu0gNltLlB1HXc11BHyTelg3OdzPMhFepJEosvg+0PATsqDbb4s+vk9Da7nYok9INw8x Oer/8+qoex1iwnMcdiRWxlEg17iB7d+RubnseD5WjQcNU2Jcvs3KghAhh5WGqXkDKmCr zXvczc4sy+RlwjQGGerTHnMrTyySdel0S6Ntrp/79hRz14LdUd9TdQ+IRJoVBhSto6bJ IRag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IXtBMdlxptD+rgtlXku5y/M/YWWbgrzqb1KWu60anSo=; b=KkMTz+65ewKEClUFOEG66F6fo/1hQiJF48z57hpRdTbbRftdk5DySBbVd6BtQ7MnfF jrN3VPucX+z7pwX6y7HlpVbkk2EQGywOvrFUfvE51CASqc7nEF8540Jic5p2EamSTvBR /l9yV5Oru5nN6Wd9rVy2AmK2voCRwVXEvu5P/mZzqo05zrM/2jR2LYxQBNs8jae7K/25 uCyccNoS8kDlHSKtuuNv7IkXxT9LJNOK9S5YdSsf6yhVOKDGSW1+1S5Ea3DM0aPt98KA ZpEqkgACUui9YmtT78YyGnP9NV3DRWzusc+Ca2aGz31kjLsXaeIe55y6l93aJBczMCpS shug== X-Gm-Message-State: AFqh2kp0b955/FFZpNLOj7uHaJIozH/qtSxy9szQ9wncMyoZollzng5A n3FUejGFvVTCHVjZ8fD1NA== X-Google-Smtp-Source: AMrXdXs56/WCCSSciGtUdzHeaGwrcYkmERKIE5bb4yigLmTgf5G8RRH6ADAjlzf9Yi93UhS1aN6deA== X-Received: by 2002:a05:6a00:198c:b0:582:d44f:3948 with SMTP id d12-20020a056a00198c00b00582d44f3948mr41081152pfl.18.1673767012723; Sat, 14 Jan 2023 23:16:52 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:52 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 09/10] samples/bpf: use vmlinux.h instead of implicit headers in BPF test program Date: Sun, 15 Jan 2023 16:16:12 +0900 Message-Id: <20230115071613.125791-10-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This commit applies vmlinux.h to BPF functionality testing program. Macros that were not defined despite migration to "vmlinux.h" were defined separately in individual files. Signed-off-by: Daniel T. Lee --- samples/bpf/lwt_len_hist_kern.c | 5 +---- samples/bpf/sock_flags_kern.c | 6 ++---- samples/bpf/test_cgrp2_tc_kern.c | 3 +-- samples/bpf/test_lwt_bpf.c | 11 +---------- samples/bpf/test_map_in_map_kern.c | 7 ++++--- samples/bpf/test_overhead_kprobe_kern.c | 4 +--- samples/bpf/test_overhead_raw_tp_kern.c | 2 +- samples/bpf/test_overhead_tp_kern.c | 3 +-- 8 files changed, 12 insertions(+), 29 deletions(-) diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_kern.c index 44ea7b56760e..dbab80e813fe 100644 --- a/samples/bpf/lwt_len_hist_kern.c +++ b/samples/bpf/lwt_len_hist_kern.c @@ -10,10 +10,7 @@ * General Public License for more details. */ -#include -#include -#include -#include +#include "vmlinux.h" #include struct { diff --git a/samples/bpf/sock_flags_kern.c b/samples/bpf/sock_flags_kern.c index 84837ed48eb3..0da749f6a9e1 100644 --- a/samples/bpf/sock_flags_kern.c +++ b/samples/bpf/sock_flags_kern.c @@ -1,8 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" #include "net_shared.h" -#include -#include -#include -#include #include SEC("cgroup/sock") diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc_kern.c index 45a2f01d2029..c7d2291d676f 100644 --- a/samples/bpf/test_cgrp2_tc_kern.c +++ b/samples/bpf/test_cgrp2_tc_kern.c @@ -5,9 +5,8 @@ * License as published by the Free Software Foundation. */ #define KBUILD_MODNAME "foo" +#include "vmlinux.h" #include "net_shared.h" -#include -#include #include /* copy of 'struct ethhdr' without __packed */ diff --git a/samples/bpf/test_lwt_bpf.c b/samples/bpf/test_lwt_bpf.c index fc093fbc760a..9a13dbb81847 100644 --- a/samples/bpf/test_lwt_bpf.c +++ b/samples/bpf/test_lwt_bpf.c @@ -10,17 +10,8 @@ * General Public License for more details. */ +#include "vmlinux.h" #include "net_shared.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include diff --git a/samples/bpf/test_map_in_map_kern.c b/samples/bpf/test_map_in_map_kern.c index 0e17f9ade5c5..1883559e5977 100644 --- a/samples/bpf/test_map_in_map_kern.c +++ b/samples/bpf/test_map_in_map_kern.c @@ -6,16 +6,17 @@ * License as published by the Free Software Foundation. */ #define KBUILD_MODNAME "foo" -#include +#include "vmlinux.h" #include -#include -#include #include #include #include #define MAX_NR_PORTS 65536 +#define EINVAL 22 +#define ENOENT 2 + /* map #0 */ struct inner_a { __uint(type, BPF_MAP_TYPE_ARRAY); diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c index ba82949338c2..c3528731e0e1 100644 --- a/samples/bpf/test_overhead_kprobe_kern.c +++ b/samples/bpf/test_overhead_kprobe_kern.c @@ -4,10 +4,8 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ +#include "vmlinux.h" #include -#include -#include -#include #include #include diff --git a/samples/bpf/test_overhead_raw_tp_kern.c b/samples/bpf/test_overhead_raw_tp_kern.c index 3e29de0eca98..6af39fe3f8dd 100644 --- a/samples/bpf/test_overhead_raw_tp_kern.c +++ b/samples/bpf/test_overhead_raw_tp_kern.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2018 Facebook */ -#include +#include "vmlinux.h" #include SEC("raw_tracepoint/task_rename") diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c index f170e9b1ea21..67cab3881969 100644 --- a/samples/bpf/test_overhead_tp_kern.c +++ b/samples/bpf/test_overhead_tp_kern.c @@ -4,8 +4,7 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include -#include +#include "vmlinux.h" #include /* from /sys/kernel/debug/tracing/events/task/task_rename/format */ From patchwork Sun Jan 15 07:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13102162 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2964FC63797 for ; Sun, 15 Jan 2023 07:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229921AbjAOHSa (ORCPT ); Sun, 15 Jan 2023 02:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbjAOHRG (ORCPT ); Sun, 15 Jan 2023 02:17:06 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCABECDCA; Sat, 14 Jan 2023 23:16:56 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id i65so15442731pfc.0; Sat, 14 Jan 2023 23:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vNXfcjpndi9wyIiNjD+j3biphdOzIRcH22L61plM07w=; b=gHVR2YI5UTS/cH5MRPogzxfem3dOg2N3RxcvnIYU/aWo3J25GvQWONCnEXxN8Z9cET ASme94ybWpKs0Qlc1dG9xChi9v1l4z7j5R8a6iifXz35Hz6mR/q3w0ZEn+E6RWjPVPUS Qn4bTBknZR6fFtRvn+kR+YBVJNk4jFuoh9QaWOXXQpawy6nLbUFjZ9GoqyLQXvAFRPIx 3hlu3cEKrLfFv13vux9atAs1MzrqSJcJMcBPxD5r8TyGVXd7HYNg7Qw7Mk871a7H74Ll Zf4l2Ow2bQTXuc8fzDXGTMiRUcEvB9sZg+JwDaja24vPHOlvofUIAncWNdMbXkhKEwNG wbMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vNXfcjpndi9wyIiNjD+j3biphdOzIRcH22L61plM07w=; b=7YM6yblYx9zXEr5QmzgHgBOkCdhMCBJZiSTXJRKtSFbqew5Uvj5b92XJZDmkx9mg1l nfP1ETcDED8v5CmuD4G/1L9jVeDgk2k4ErzNlzkKJmAit5IXuqn6CfcaEbX9FRxzn8Xy fElSui5peoYDp5dJLYAldaNSDGc3X3125rUtRnrHIgfqjlXFZ2xo0M9ot2bD6qTC61B2 LL19EgchIqVIAQFeTIZgotHEVfju8OJr/ga/KIzGB6/kN81i5vcnfd/CiLeoMfnN6OMl uS0O8Qq0e8HfK5Jkuw6oqWK/zFKJsZjep8w4o/Pp/RQuqtCQoHmpGOcDJNYQt1mcEb9G gZDw== X-Gm-Message-State: AFqh2kod797Yml+WDz8uS3PPizdUCH5p8rIAPjcAe5D4gekFXtzxRCwJ wqYWaXAIReFx8VUvQaCWMg== X-Google-Smtp-Source: AMrXdXtqqkNdeJGkDOxh0iLhZTaHoIckTCUnK1/1uyavkKn++YOTTrY9KM+n7OwgY3l/a3mdPohuXw== X-Received: by 2002:a05:6a00:4489:b0:58d:982a:f1e9 with SMTP id cu9-20020a056a00448900b0058d982af1e9mr1694905pfb.22.1673767016414; Sat, 14 Jan 2023 23:16:56 -0800 (PST) Received: from WDIR.. ([182.209.58.25]) by smtp.gmail.com with ESMTPSA id z13-20020aa7990d000000b0058a313f4e4esm10272796pff.149.2023.01.14.23.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 23:16:55 -0800 (PST) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Andrii Nakryiko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [bpf-next 10/10] samples/bpf: change _kern suffix to .bpf with BPF test programs Date: Sun, 15 Jan 2023 16:16:13 +0900 Message-Id: <20230115071613.125791-11-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230115071613.125791-1-danieltimlee@gmail.com> References: <20230115071613.125791-1-danieltimlee@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This commit changes the _kern suffix to .bpf with the BPF test programs. With this modification, test programs will inherit the benefit of the new CLANG-BPF compile target. Signed-off-by: Daniel T. Lee --- samples/bpf/Makefile | 14 +++++++------- .../{lwt_len_hist_kern.c => lwt_len_hist.bpf.c} | 0 samples/bpf/lwt_len_hist.sh | 2 +- .../bpf/{sock_flags_kern.c => sock_flags.bpf.c} | 0 samples/bpf/test_cgrp2_sock2.sh | 2 +- .../{test_cgrp2_tc_kern.c => test_cgrp2_tc.bpf.c} | 0 samples/bpf/test_cgrp2_tc.sh | 2 +- ...est_map_in_map_kern.c => test_map_in_map.bpf.c} | 0 samples/bpf/test_map_in_map_user.c | 2 +- ...ad_kprobe_kern.c => test_overhead_kprobe.bpf.c} | 0 ...ad_raw_tp_kern.c => test_overhead_raw_tp.bpf.c} | 0 ...t_overhead_tp_kern.c => test_overhead_tp.bpf.c} | 0 samples/bpf/test_overhead_user.c | 6 +++--- 13 files changed, 14 insertions(+), 14 deletions(-) rename samples/bpf/{lwt_len_hist_kern.c => lwt_len_hist.bpf.c} (100%) rename samples/bpf/{sock_flags_kern.c => sock_flags.bpf.c} (100%) rename samples/bpf/{test_cgrp2_tc_kern.c => test_cgrp2_tc.bpf.c} (100%) rename samples/bpf/{test_map_in_map_kern.c => test_map_in_map.bpf.c} (100%) rename samples/bpf/{test_overhead_kprobe_kern.c => test_overhead_kprobe.bpf.c} (100%) rename samples/bpf/{test_overhead_raw_tp_kern.c => test_overhead_raw_tp.bpf.c} (100%) rename samples/bpf/{test_overhead_tp_kern.c => test_overhead_tp.bpf.c} (100%) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 22039a0a5b35..615f24ebc49c 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -131,7 +131,7 @@ always-y += tracex4_kern.o always-y += tracex5_kern.o always-y += tracex6_kern.o always-y += tracex7_kern.o -always-y += sock_flags_kern.o +always-y += sock_flags.bpf.o always-y += test_probe_write_user.bpf.o always-y += trace_output.bpf.o always-y += tcbpf1_kern.o @@ -140,19 +140,19 @@ always-y += lathist_kern.o always-y += offwaketime_kern.o always-y += spintest_kern.o always-y += map_perf_test.bpf.o -always-y += test_overhead_tp_kern.o -always-y += test_overhead_raw_tp_kern.o -always-y += test_overhead_kprobe_kern.o +always-y += test_overhead_tp.bpf.o +always-y += test_overhead_raw_tp.bpf.o +always-y += test_overhead_kprobe.bpf.o always-y += parse_varlen.o parse_simple.o parse_ldabs.o -always-y += test_cgrp2_tc_kern.o +always-y += test_cgrp2_tc.bpf.o always-y += xdp1_kern.o always-y += xdp2_kern.o always-y += test_current_task_under_cgroup.bpf.o always-y += trace_event_kern.o always-y += sampleip_kern.o -always-y += lwt_len_hist_kern.o +always-y += lwt_len_hist.bpf.o always-y += xdp_tx_iptunnel_kern.o -always-y += test_map_in_map_kern.o +always-y += test_map_in_map.bpf.o always-y += tcp_synrto_kern.o always-y += tcp_rwnd_kern.o always-y += tcp_bufs_kern.o diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist.bpf.c similarity index 100% rename from samples/bpf/lwt_len_hist_kern.c rename to samples/bpf/lwt_len_hist.bpf.c diff --git a/samples/bpf/lwt_len_hist.sh b/samples/bpf/lwt_len_hist.sh index ff7d1ba0f7ed..7078bfcc4f4d 100755 --- a/samples/bpf/lwt_len_hist.sh +++ b/samples/bpf/lwt_len_hist.sh @@ -4,7 +4,7 @@ NS1=lwt_ns1 VETH0=tst_lwt1a VETH1=tst_lwt1b -BPF_PROG=lwt_len_hist_kern.o +BPF_PROG=lwt_len_hist.bpf.o TRACE_ROOT=/sys/kernel/debug/tracing function cleanup { diff --git a/samples/bpf/sock_flags_kern.c b/samples/bpf/sock_flags.bpf.c similarity index 100% rename from samples/bpf/sock_flags_kern.c rename to samples/bpf/sock_flags.bpf.c diff --git a/samples/bpf/test_cgrp2_sock2.sh b/samples/bpf/test_cgrp2_sock2.sh index 00cc8d15373c..82acff93d739 100755 --- a/samples/bpf/test_cgrp2_sock2.sh +++ b/samples/bpf/test_cgrp2_sock2.sh @@ -5,7 +5,7 @@ BPFFS=/sys/fs/bpf MY_DIR=$(dirname $0) TEST=$MY_DIR/test_cgrp2_sock2 LINK_PIN=$BPFFS/test_cgrp2_sock2 -BPF_PROG=$MY_DIR/sock_flags_kern.o +BPF_PROG=$MY_DIR/sock_flags.bpf.o function config_device { ip netns add at_ns0 diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc.bpf.c similarity index 100% rename from samples/bpf/test_cgrp2_tc_kern.c rename to samples/bpf/test_cgrp2_tc.bpf.c diff --git a/samples/bpf/test_cgrp2_tc.sh b/samples/bpf/test_cgrp2_tc.sh index 37a2c9cba6d0..38e8dbc9d16e 100755 --- a/samples/bpf/test_cgrp2_tc.sh +++ b/samples/bpf/test_cgrp2_tc.sh @@ -4,7 +4,7 @@ MY_DIR=$(dirname $0) # Details on the bpf prog BPF_CGRP2_ARRAY_NAME='test_cgrp2_array_pin' -BPF_PROG="$MY_DIR/test_cgrp2_tc_kern.o" +BPF_PROG="$MY_DIR/test_cgrp2_tc.bpf.o" BPF_SECTION='filter' [ -z "$TC" ] && TC='tc' diff --git a/samples/bpf/test_map_in_map_kern.c b/samples/bpf/test_map_in_map.bpf.c similarity index 100% rename from samples/bpf/test_map_in_map_kern.c rename to samples/bpf/test_map_in_map.bpf.c diff --git a/samples/bpf/test_map_in_map_user.c b/samples/bpf/test_map_in_map_user.c index 652ec720533d..9e79df4071f5 100644 --- a/samples/bpf/test_map_in_map_user.c +++ b/samples/bpf/test_map_in_map_user.c @@ -120,7 +120,7 @@ int main(int argc, char **argv) struct bpf_object *obj; char filename[256]; - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe.bpf.c similarity index 100% rename from samples/bpf/test_overhead_kprobe_kern.c rename to samples/bpf/test_overhead_kprobe.bpf.c diff --git a/samples/bpf/test_overhead_raw_tp_kern.c b/samples/bpf/test_overhead_raw_tp.bpf.c similarity index 100% rename from samples/bpf/test_overhead_raw_tp_kern.c rename to samples/bpf/test_overhead_raw_tp.bpf.c diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp.bpf.c similarity index 100% rename from samples/bpf/test_overhead_tp_kern.c rename to samples/bpf/test_overhead_tp.bpf.c diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c index ce28d30f852e..dbd86f7b1473 100644 --- a/samples/bpf/test_overhead_user.c +++ b/samples/bpf/test_overhead_user.c @@ -189,7 +189,7 @@ int main(int argc, char **argv) if (test_flags & 0xC) { snprintf(filename, sizeof(filename), - "%s_kprobe_kern.o", argv[0]); + "%s_kprobe.bpf.o", argv[0]); printf("w/KPROBE\n"); err = load_progs(filename); @@ -201,7 +201,7 @@ int main(int argc, char **argv) if (test_flags & 0x30) { snprintf(filename, sizeof(filename), - "%s_tp_kern.o", argv[0]); + "%s_tp.bpf.o", argv[0]); printf("w/TRACEPOINT\n"); err = load_progs(filename); if (!err) @@ -212,7 +212,7 @@ int main(int argc, char **argv) if (test_flags & 0xC0) { snprintf(filename, sizeof(filename), - "%s_raw_tp_kern.o", argv[0]); + "%s_raw_tp.bpf.o", argv[0]); printf("w/RAW_TRACEPOINT\n"); err = load_progs(filename); if (!err)