From patchwork Sun Jul 21 14:33:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13738012 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7B4150980; Sun, 21 Jul 2024 14:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572467; cv=none; b=uuvDSqt8skUAmLsU0s+cgoPEwQbOjz4Kxt82AzKZyoZ13fQebbXGTWn/Tocjc4R6cLZ//SyisoV9I35FuhLJQzGFIa413pexkqPU+rnt5h78NEHLEoF0VErXiQ177YWaEsgC4+ngjwsZYrru1aFHvP420paHx4ZwxNhCYb6ew70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572467; c=relaxed/simple; bh=3Wqd8DnWTw3/yvGmd99tidm+18F0caRu421PpqBqslc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mk4scZh1r6I9lRplNuGjoRF1nhn0xcNXG0Y4/Aulwm6E8oVwsRcj5gXJRncL9dSeYq3NjaMbk+fHMdVMCb5xgnIEGPt2XgNexmQ6RI7tWBGuyj1uYaAgga9ehfdiJ+ZdQU7ejjmV6kkk3Ljv9y7qrSJFi6mKCE1rtpyR4GCOazA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vk9c6Dkt; arc=none smtp.client-ip=209.85.166.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vk9c6Dkt" Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-3992f09efa7so5766765ab.2; Sun, 21 Jul 2024 07:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721572465; x=1722177265; darn=vger.kernel.org; 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=XGAJWfp7/xOOMmZFct4BfOvzv2JnXADRkl1E3DONea0=; b=Vk9c6DktrXPmZcD5RbUPZIT8ZxHSBMEpT93llBxcWZolNDGsTQGSGbIyQvreqc304Q yUbQAW7msq3iNfpR0q5te4QwtCE9EK/acJhjhsDhEt9C5gFxxFZ47Zd4K4gCedBXT8+Z 3dx6Hh/JuXcau9MFiHg48LUbypvT1Wsvx+c9IWzHCEyk3/D+WdkdWAQLX3H1ex2ICRfv YzSGfqvGHLwyBrQgYjW+9iGiHBo2Pq+PZpnhmvW0ystQwmv7Sv9B+cSorTGNMD0j1uM6 LUzalj9fOM0JFZc/ZfCmEY1z/qqoftDQeJ4CEVfZlu9If26GypFSRdW7UvsqYbueeJ0D ks/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721572465; x=1722177265; 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=XGAJWfp7/xOOMmZFct4BfOvzv2JnXADRkl1E3DONea0=; b=rrF7WYjFJNdpJjL5hTSBrTJFPpJxP5BXx/OoPtdStDEZBWGNKtUbAEGtb9m0v3Faac /BET54qjMcwl0zEIL/bL1cQmMPd2bQXLAN8KxqZPMdem1/u7MhxOkEtj7lqyOiWXVEmq iXBffAxbB6bRkxrhCc2fUiKJVEa7lEpXroN/FTSXxMst4tjvZHV9BtV0RGpqujA0QPSC idaAuBuIKfyf6WcOr8g0/iM1CT2eAgORHAlmVE0mIhDIL1at6wfcIDu1GgifzPpmyjPa U5SgsWNUK5Rl91zkWmkE6sNi4/6Eza9MOUg4WOXTpk/sVWSHu2TC78CPg6TF+OdRruHG GvJg== X-Forwarded-Encrypted: i=1; AJvYcCXysF4r1qC2wOmcrXTw/n14CpI09sF4tjymGv6tq1JEujdlCKrC2VptW4XSmzJYgMkyEcEz0AoPcsH6fJsukCqUWJ6FZyIyhFOqsPOFfO9czZtKea7GkeXqAP/nN5Yttwsl X-Gm-Message-State: AOJu0Yy7pxVcyFHUEGlJSTYue3Ax29Swiie8nGgmDNj9DEmXtci1Dcnx AGf4NbT187POEXJWmvGec6hnKHzB8hWsvn/IYHTEKMp3v8o3ZMPG X-Google-Smtp-Source: AGHT+IEjb9XMEGtagKQYnR1JriMds7jZC/GeK1ui0ZrwDy49zby0nhfycjAQXkekoPIVVPxJDr9Evg== X-Received: by 2002:a92:c262:0:b0:398:3b82:4ac8 with SMTP id e9e14a558f8ab-399403e65a9mr53491205ab.24.1721572464569; Sun, 21 Jul 2024 07:34:24 -0700 (PDT) Received: from localhost ([117.147.31.23]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-79f0f5448desm3209048a12.81.2024.07.21.07.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 07:34:24 -0700 (PDT) From: Tao Chen To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , chen.dylane@gmail.com Cc: Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH bpf-next 1/4] bpftool: refactor xdp attach/detach type judgment Date: Sun, 21 Jul 2024 22:33:50 +0800 Message-Id: <20240721143353.95980-2-chen.dylane@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240721143353.95980-1-chen.dylane@gmail.com> References: <20240721143353.95980-1-chen.dylane@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This commit no logical changed, just increases code readability and facilitates TCX prog expansion, which will be implemented in the next patch. Acked-by: Quentin Monnet Signed-off-by: Tao Chen --- tools/bpf/bpftool/net.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 968714b4c3d4..1b9f4225b394 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -684,10 +684,18 @@ static int do_attach(int argc, char **argv) } } + switch (attach_type) { /* attach xdp prog */ - if (is_prefix("xdp", attach_type_strings[attach_type])) - err = do_attach_detach_xdp(progfd, attach_type, ifindex, - overwrite); + case NET_ATTACH_TYPE_XDP: + case NET_ATTACH_TYPE_XDP_GENERIC: + case NET_ATTACH_TYPE_XDP_DRIVER: + case NET_ATTACH_TYPE_XDP_OFFLOAD: + err = do_attach_detach_xdp(progfd, attach_type, ifindex, overwrite); + break; + default: + break; + } + if (err) { p_err("interface %s attach failed: %s", attach_type_strings[attach_type], strerror(-err)); @@ -721,10 +729,18 @@ static int do_detach(int argc, char **argv) if (ifindex < 1) return -EINVAL; + switch (attach_type) { /* detach xdp prog */ - progfd = -1; - if (is_prefix("xdp", attach_type_strings[attach_type])) + case NET_ATTACH_TYPE_XDP: + case NET_ATTACH_TYPE_XDP_GENERIC: + case NET_ATTACH_TYPE_XDP_DRIVER: + case NET_ATTACH_TYPE_XDP_OFFLOAD: + progfd = -1; err = do_attach_detach_xdp(progfd, attach_type, ifindex, NULL); + break; + default: + break; + } if (err < 0) { p_err("interface %s detach failed: %s", From patchwork Sun Jul 21 14:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13738013 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC92A8F66; Sun, 21 Jul 2024 14:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572951; cv=none; b=KQw+NvBspr2l98BVUNdFOmzDgaWp9sAfGr0WXXHwkN+yLmJr82nS6ptPFTPlF9NCP8C/cdtHWLRkuu/PJdWipK0GMQq78zMKFn9z3sgL+BkO5HHsF8RQRIGgLw5HlPCwHJr+kK3aQksMOEXRYMexNpGwxER15AqLDmt6g7hEkP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572951; c=relaxed/simple; bh=guTMrBNWCCj3x3CBZP4CXoEn+Wy/dse1eYwuyj4IxNg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Env+wayDVE3hul6/L28JNy5nn2xHKnWc5yqO+1Htpa4DBPLZO5RNxPk+TFc9LRhGakGFcr9R8T7WuMN+2u0eTtDqB7NJJn6p5RxmXpEcoB7w4j710uLHrAkBaThGedC1U6Wym3u0LBnKSlRqOjubmOhYdhHqKX6FC/ICMvbaig4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TTkw67hu; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TTkw67hu" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2cb674b48ccso1592312a91.2; Sun, 21 Jul 2024 07:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721572949; x=1722177749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WvvkNmauGXe467uoPM8a1FFpY63QozPxGUOvyMzBA+U=; b=TTkw67hu/YncMePIKhxsRVwbhNv5/2a7UXOAdw1baFwIE5POHAxjW2OccePD0y6CG6 Eau81k6MRXb6ZhOHgZU+E3IbW5g8kg5+ZN4Hh4b/jmmd6cKliYvqABfChJHntykMBdnX PjnJmfYc0RQZmUM99vkhx1Kqkowx2pJSzp/YA9SUp56y+NXmQIHEpSsmun1JNSkGocV1 GNWhWm+/fNYZExDrEi8KjH7aUUncHbmKWN/FAs2ihHkjSw+h1rP4JnpWbam6rfT18pJj 1+Dc+AdAhmttAbu6GYxu25wXV2rcOC+fck7lAAsOzRur4py08AJRPNBsHmu5mNQ8hm6g /LZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721572949; x=1722177749; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WvvkNmauGXe467uoPM8a1FFpY63QozPxGUOvyMzBA+U=; b=rPkm0WcHR0d3KeS2wyObNvvGQkxRqnG0PYTVbi9aam9iPdszTf2SH7Qwunvb1uL+SA 3h5L9bHCr2j/mJ1nCiZd5B1Ft1PtQa7pscL9MpQbUu9tQwGSvSEh1kji6Vzh6to9WfWF c6WDmu+gUqQ713kA1Qi5kJfaF3YDe6lc/pc6ho/9gbOTjbbAvjH21RO1ObfVcbV9Uifc RZbIQgfAIV3iPpIe9GpVFi5LHm0DisPPnBeDZ8ZX70+jxwLzrGxL6hWIL6pcHXdMT4Gj ni/+f2+wT+HblDxS0Z+V27tyyl4Xl6TDiG7e5+jQ/2QXHYxenMF/Va0eY5oRBsJJsalX jXdQ== X-Forwarded-Encrypted: i=1; AJvYcCVnwEnk81MjlVItMezIKKJPaukmeJFLBbQjP9puyb1jjq0QEMp1w3AtRJDzrN5aa+C6P/rGqqVDXOKDvnBZvwNkCU03FC43I8XYZUGspXHhUBENcPYAMEfducGAh7KJUbX/ X-Gm-Message-State: AOJu0YwlnU6WRqdY9ZwyuanTyWlPGeM8hur1YL/KZA1qpbYe5hg/nZSo vYlgprVHh4iaDhqetuSn37aVjYw0NSoarXLCdm+lsVDsiAvfpUgX X-Google-Smtp-Source: AGHT+IHuJbNhmcrB2AfJVeX2K4UsZsGkxV5B06qNfzVq5kwuLSB7WBdkAw+EpSjTirL04fw4YzCWKw== X-Received: by 2002:a17:90b:28e:b0:2c9:73ff:6a0c with SMTP id 98e67ed59e1d1-2cd15ee7214mr2502612a91.20.1721572948786; Sun, 21 Jul 2024 07:42:28 -0700 (PDT) Received: from localhost ([117.147.31.23]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cb775416fasm6264683a91.53.2024.07.21.07.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 07:42:28 -0700 (PDT) From: Tao Chen To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , chen.dylane@gmail.com Cc: Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH bpf-next 2/4] bpftool: add net attach/detach command to tcx prog Date: Sun, 21 Jul 2024 22:42:21 +0800 Message-Id: <20240721144221.96228-1-chen.dylane@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Now, attach/detach tcx prog supported in libbpf, so we can add new command 'bpftool attach/detach tcx' to attach tcx prog with bpftool for user. # bpftool prog load tc_prog.bpf.o /sys/fs/bpf/tc_prog # bpftool prog show ... 192: sched_cls name tc_prog tag 187aeb611ad00cfc gpl loaded_at 2024-07-11T15:58:16+0800 uid 0 xlated 152B jited 97B memlock 4096B map_ids 100,99,97 btf_id 260 # bpftool net attach tcx_ingress name tc_prog dev lo # bpftool net ... tc: lo(1) tcx/ingress tc_prog prog_id 29 # bpftool net detach tcx_ingress dev lo # bpftool net ... tc: # bpftool net attach tcx_ingress name tc_prog dev lo # bpftool net tc: lo(1) tcx/ingress tc_prog prog_id 29 Test environment: ubuntu_22_04, 6.7.0-060700-generic Signed-off-by: Tao Chen Acked-by: Quentin Monnet --- tools/bpf/bpftool/net.c | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 1b9f4225b394..2a51f1c25732 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -67,6 +67,8 @@ enum net_attach_type { NET_ATTACH_TYPE_XDP_GENERIC, NET_ATTACH_TYPE_XDP_DRIVER, NET_ATTACH_TYPE_XDP_OFFLOAD, + NET_ATTACH_TYPE_TCX_INGRESS, + NET_ATTACH_TYPE_TCX_EGRESS, }; static const char * const attach_type_strings[] = { @@ -74,6 +76,8 @@ static const char * const attach_type_strings[] = { [NET_ATTACH_TYPE_XDP_GENERIC] = "xdpgeneric", [NET_ATTACH_TYPE_XDP_DRIVER] = "xdpdrv", [NET_ATTACH_TYPE_XDP_OFFLOAD] = "xdpoffload", + [NET_ATTACH_TYPE_TCX_INGRESS] = "tcx_ingress", + [NET_ATTACH_TYPE_TCX_EGRESS] = "tcx_egress", }; static const char * const attach_loc_strings[] = { @@ -647,6 +651,32 @@ static int do_attach_detach_xdp(int progfd, enum net_attach_type attach_type, return bpf_xdp_attach(ifindex, progfd, flags, NULL); } +static int get_tcx_type(enum net_attach_type attach_type) +{ + switch (attach_type) { + case NET_ATTACH_TYPE_TCX_INGRESS: + return BPF_TCX_INGRESS; + case NET_ATTACH_TYPE_TCX_EGRESS: + return BPF_TCX_EGRESS; + default: + return -1; + } +} + +static int do_attach_tcx(int progfd, enum net_attach_type attach_type, int ifindex) +{ + int type = get_tcx_type(attach_type); + + return bpf_prog_attach(progfd, ifindex, type, 0); +} + +static int do_detach_tcx(int targetfd, enum net_attach_type attach_type) +{ + int type = get_tcx_type(attach_type); + + return bpf_prog_detach(targetfd, type); +} + static int do_attach(int argc, char **argv) { enum net_attach_type attach_type; @@ -692,6 +722,11 @@ static int do_attach(int argc, char **argv) case NET_ATTACH_TYPE_XDP_OFFLOAD: err = do_attach_detach_xdp(progfd, attach_type, ifindex, overwrite); break; + /* attach tcx prog */ + case NET_ATTACH_TYPE_TCX_INGRESS: + case NET_ATTACH_TYPE_TCX_EGRESS: + err = do_attach_tcx(progfd, attach_type, ifindex); + break; default: break; } @@ -738,6 +773,11 @@ static int do_detach(int argc, char **argv) progfd = -1; err = do_attach_detach_xdp(progfd, attach_type, ifindex, NULL); break; + /* detach tcx prog */ + case NET_ATTACH_TYPE_TCX_INGRESS: + case NET_ATTACH_TYPE_TCX_EGRESS: + err = do_detach_tcx(ifindex, attach_type); + break; default: break; } @@ -944,7 +984,8 @@ static int do_help(int argc, char **argv) " %1$s %2$s help\n" "\n" " " HELP_SPEC_PROGRAM "\n" - " ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload }\n" + " ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload | tcx_ingress\n" + " | tcx_egress }\n" " " HELP_SPEC_OPTIONS " }\n" "\n" "Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n" From patchwork Sun Jul 21 14:42:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13738014 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7462116130C; Sun, 21 Jul 2024 14:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572967; cv=none; b=osH57JOkFxNdh5eWHKyporBV8wEKcKmiUkow/G1jEL//RSJu6w3hxwifimAfxAke0iB2fEGFyMCPoVA+DhufiL1OkdNGkxV/my8vmhKKp3zLPBbMG5TTykVs8imti7DxXu7jR2C8LBV5IWDz1TkTtHezjIn0cfvoY8J2DbB6W2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572967; c=relaxed/simple; bh=m9OV2vyggZf3v8X/HMlM1/4Z1zG2UYAHfwtwc2Ooc+0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=W1UC1p7gWfLcgWXyHDgGtkSq1TBHSUO1HLgROkhBCNAUaPw2L0TAWiei55wSsNmGjr9+CKGoLZbbsHYFdBGB2875WxYNyisy3e8PSxTUte87vzZojYgD2K069dfjDvLy5I4avQWdBVnc7wSuSaSg3aXVijjOH2l4YuaXnFJG7Fs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m+vdjDKX; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m+vdjDKX" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-2642cfb2f6aso672845fac.2; Sun, 21 Jul 2024 07:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721572965; x=1722177765; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=B7PG2kYxfNyD8rSP7TLL6VX9svrQ8K/M9h3Idt3Jgyc=; b=m+vdjDKXu3rWnzDHCrKCQz0vjD+w7ggkrQDcVGfv6uQbbyyq36EMHutvAf44qVKRsm TPP0MoGk5thxX/OEvLmzMAN7WcEtwMD3W2I8n51flRJ4kIEnpo6Y7sV/XvI/MwuoK0mQ gK1ounA1FF7fQKN5RUmASQMemmnKI37kVTYaYkb3j50rgGOEw46Y0G0bEpzeyzk4kowX o4nedQoiqeKO5dPuNwScWx8j/kK67pnUDDcTgVmhWkeQBT+9rQc/gOT8XNFsgIVdz4te bQhLw6JZV02SLQ1mxfmtrwjb5Y0sPhlT6pMUHbnmlTFcLjIhI7zMIKolrzEZsvafahun 3wTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721572965; x=1722177765; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=B7PG2kYxfNyD8rSP7TLL6VX9svrQ8K/M9h3Idt3Jgyc=; b=S2c7nJ+MZrB8jOqkL70X5ID6yaV1fAYBYw1+82q3DuxQ+vxY/ggSqMJ8i5IVW0pNsS E5iT8HQzUHsKAENqtVzjgKmKFVLqjyRaoWgVHLmt01be/Dd0U5KuWUuWPhq61GTNktIt HaLwfNx8z8d64qV1pQmz/WbWei2aW8sj1RJeo2plehOL2Hbto9ekHEKOPQXjnu6ncj8b pzL+dMJw++UmRFWYDQGB1Z4VVofLR4iVGnT7xvniicORBlIyei9esBM1UfjF63KGaO0p 5Vfwdn3/0qJ1hk+R910qPtQg7LGl2Z1kMoL2zb1FnJpOoN+wEv/I6BZxbBD1oZQMNpao J5/g== X-Forwarded-Encrypted: i=1; AJvYcCU8fb98y7KBapjpm+axRkSmLREe70kSVQcNsG2vXDoqH78wmUHlm9+fhFTf9OMmImSx9LjFriR8E2G3C82hqsqkWT/fhAnV4GruBXu0WFLIisQEaJRlSO1N3SetbrPPkE8t X-Gm-Message-State: AOJu0YwgaWHdK5axOa+0zxSaX4ifyzScL7Ya6yDYj6w3mVh30+Ll4U6J grhPLO3wg8szx34umYtIYNRPHTgs7bEqPfFmKpvljAal7ABBPBDoZnU2rg5O X-Google-Smtp-Source: AGHT+IFFO3KIlp8gr5C98CjzWTw8lsWS74u3GLAtK6elf5cfBvtGipZeFO+3wgSBZ1jeXkPTtWCqaw== X-Received: by 2002:a05:6870:5254:b0:25d:7cc4:caa8 with SMTP id 586e51a60fabf-26121321cedmr4799504fac.10.1721572965172; Sun, 21 Jul 2024 07:42:45 -0700 (PDT) Received: from localhost ([117.147.31.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70d17f9a11fsm1617555b3a.204.2024.07.21.07.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 07:42:44 -0700 (PDT) From: Tao Chen To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , chen.dylane@gmail.com Cc: Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH bpf-next 3/4] bpftool: add bash-completion for tcx subcommand Date: Sun, 21 Jul 2024 22:42:38 +0800 Message-Id: <20240721144238.96246-1-chen.dylane@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This commit adds bash-completion for attaching tcx program on interface. Acked-by: Quentin Monnet Signed-off-by: Tao Chen --- tools/bpf/bpftool/bash-completion/bpftool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index be99d49b8714..0c541498c301 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -1079,7 +1079,7 @@ _bpftool() esac ;; net) - local ATTACH_TYPES='xdp xdpgeneric xdpdrv xdpoffload' + local ATTACH_TYPES='xdp xdpgeneric xdpdrv xdpoffload tcx_ingress tcx_egress' case $command in show|list) [[ $prev != "$command" ]] && return 0 From patchwork Sun Jul 21 14:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13738015 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CFF7150980; Sun, 21 Jul 2024 14:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572981; cv=none; b=Fcbd8x4bIQL0ioHG8OwaoJ8SZ3R6zYNA7lesdSRmJO9PbC+PzkZKQU3HnKvayScl6QTdF/bF/dIlzS7qGIvMLYpsmQkUDAgkskm/r2YuXpb4cfNUzzev9sy4ACp7Yo29iyhG4jzFPhvsw4cFihLNKec2sZPgnmnlOcYZUDBROok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721572981; c=relaxed/simple; bh=KsRZIIVF2mFFBV6NuuLYyif7cLH41blk3r28EuCSS68=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=myCD7BZaoD6gvH4Zpoxm7UHIXLjae3peJNhVHBGf9+Y2jCRmCbfK+vRoYsJ+H4jVQVJS12IZbIXBxIVEgAa4im6fgBbVbRwoZgVzYXYAahxNPenPecZMePRyW4U8QREVUTn0tWpPnWLValFgo3qLA6qRCvQ2qBMaaE35MQqvTfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kx/mX6zI; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kx/mX6zI" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fd66cddd4dso18393275ad.2; Sun, 21 Jul 2024 07:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721572980; x=1722177780; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3ZiPga6tr64DZh3sYOPyVgg9p0KRzGrR3EpmGO9QyTA=; b=kx/mX6zIlpO+bPwGrrJaBX3UWGp7H0lkH/31/L+DJQnXzTOOHG716mxJw8LmnMAzhA GrLFwoUAvkEFxF5dWobSIgJQTLkXFl+mylOZXTjPxySgem1KrcniQCWaWF8dZo0W9hLx m6Ihng20ETlPk3JKydBeu1gjzZ+Edt/Qrt7yJzYTQK0hHTQckbwywOjezvkRWoM8tEHQ gzz30hugWMNJvvXQ5LCdq7amlhX6i/9l3g2v9p1XmDK+YPo7bVEcQu7FKqBJhQSK6qco FD09CBmk+tPG96aBT+Xf3hUpvIc7ShUXL9PfyPrWl7SyHmCUDbJMBu3Ye56r8OjPO3Ih RyLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721572980; x=1722177780; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3ZiPga6tr64DZh3sYOPyVgg9p0KRzGrR3EpmGO9QyTA=; b=oSV5gulUsTDixMEUUQQdpfWmDgEbgTIJu+rq9nyCoN4083redLmgf2VSTCnLkeYzP/ Up23ndi11rEs0VT6L91DNejuLS6O035+ol9hC3kPd6ccov2fGn5aCbT1Gfr66TzbAK/r qtcrETMC+ySSrGiKQRaXqegtnsoY6Mt1ISX3eOY10sEBveEL/IZcVkJd3tRkurVB16gY 7GDzyGVdtZ+1BbRk2FpSBeGhO6istfvt0Jup768tuaCtdl8YZAr3gGln9Ha3KLlhC6vq sxdVG491hgFipKohNtWCt7HcxtuhPEdt3yzsnOvJ2BBB3+pC0OTZ7czdsdi0PLiKIMxx qwwA== X-Forwarded-Encrypted: i=1; AJvYcCXpdz9brF7PYZgV1/RwTXRnJggcV5Ey+5t+oU1IWt2afDW9L3AC5KUGAQaKgyf4cdWfC2uC6LcPRaV6WO8wZJkxw8n054ihsXJJ+NCNpCmBKzFBwapTdsrv6vACoCAYeaW3 X-Gm-Message-State: AOJu0YyoqeMXXiW4JCJK5/wvHJmjwfQk5b1RVe/Rt7yArSeNuJ6Hy3Cb C7DYiv8rO9+ZUBIuPJaCSrRlx47hEc5gKhZZNX0cZtymhtJm0qarki5kjldi X-Google-Smtp-Source: AGHT+IEY7ZgHgWh0N17tPo6horrpfd4ym2tY+CBJDm1vcSbUVeURBXpoUxBI7ISoaFkTkyckpLhucw== X-Received: by 2002:a17:902:ecc5:b0:1fa:221b:a7ef with SMTP id d9443c01a7336-1fd7461f2e1mr57264835ad.41.1721572978145; Sun, 21 Jul 2024 07:42:58 -0700 (PDT) Received: from localhost ([117.147.31.23]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f457c6asm37162725ad.242.2024.07.21.07.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 07:42:57 -0700 (PDT) From: Tao Chen To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , chen.dylane@gmail.com Cc: Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH bpf-next 4/4] bpftool: add document for net attach/detach on tcx subcommand Date: Sun, 21 Jul 2024 22:42:52 +0800 Message-Id: <20240721144252.96264-1-chen.dylane@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This commit adds sample output for net attach/detach on tcx subcommand. Acked-by: Quentin Monnet Signed-off-by: Tao Chen --- .../bpf/bpftool/Documentation/bpftool-net.rst | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-net.rst b/tools/bpf/bpftool/Documentation/bpftool-net.rst index 348812881297..4a8cb5e0d94b 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-net.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-net.rst @@ -29,7 +29,7 @@ NET COMMANDS | **bpftool** **net help** | | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* } -| *ATTACH_TYPE* := { **xdp** | **xdpgeneric** | **xdpdrv** | **xdpoffload** } +| *ATTACH_TYPE* := { **xdp** | **xdpgeneric** | **xdpdrv** | **xdpoffload** | **tcx_ingress** | **tcx_egress** } DESCRIPTION =========== @@ -69,6 +69,8 @@ bpftool net attach *ATTACH_TYPE* *PROG* dev *NAME* [ overwrite ] **xdpgeneric** - Generic XDP. runs at generic XDP hook when packet already enters receive path as skb; **xdpdrv** - Native XDP. runs earliest point in driver's receive path; **xdpoffload** - Offload XDP. runs directly on NIC on each packet reception; + **tcx_ingress** - Ingress TCX. runs on ingress net traffic; + **tcx_egress** - Egress TCX. runs on egress net traffic; bpftool net detach *ATTACH_TYPE* dev *NAME* Detach bpf program attached to network interface *NAME* with type specified @@ -178,3 +180,21 @@ EXAMPLES :: xdp: + +| +| **# bpftool net attach tcx_ingress name tc_prog dev lo** +| **# bpftool net** +| + +:: + tc: + lo(1) tcx/ingress tc_prog prog_id 29 + +| +| **# bpftool net attach tcx_ingress name tc_prog dev lo** +| **# bpftool net detach tcx_ingress dev lo** +| **# bpftool net** +| + +:: + tc: