From patchwork Wed Jul 17 17:47:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13735671 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 1425C184F; Wed, 17 Jul 2024 17:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238464; cv=none; b=prGebNdTVWZzAGJJapA+Vo9qga5+lyCrS4IM+qvDbWvSlPGUsNrYib7Cnrr9OP8h08G3r4xJX03qL3v5jzmsQ5J19pm2s7k4bEQ1z6be8/9Mqle6QgnjyLqVeodLKTQsjq2nA5Z3bFS9Ln5jI//afXxxkeEjjEJVJ093U4RU48A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238464; c=relaxed/simple; bh=d3NJz4jUuX7oE3096k7n7iS0SLoh6rburN9DwWrzyO4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=s11d/NzdANz3m+xRz7CVP2qgxabZt3Wfp0qprHLpF7VXpll1Z8ozE6xEZ4tjBPGow2fkBQ5IFpuo9F3hTrMIEdaXIXLMkAF523PGE01Ogxm15TxyRebrGAOlSMlLflVnHDF14QnK9G93fWoObTtXKehU3LTVOz8A0+hTn0gL3tE= 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=P8+99ssZ; arc=none smtp.client-ip=209.85.210.182 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="P8+99ssZ" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70af22a9c19so5235954b3a.2; Wed, 17 Jul 2024 10:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721238462; x=1721843262; 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=1Hk1vOhEtpNT8o6McHb9O6PZJBmCTMgCBX1nWzjTxVE=; b=P8+99ssZPr0lwoSKGltNyhqGE6BIEur33GPIRD0/Q58yQYqi2rVOZpgTtnIx26sLqv 8hizPdecfrnMSMoW72FE3xLPfrcG5ySTnNCuhKZ7EENfSaLQLQuBbt0wvHCeUgQvax8a CbPvcT0PDA/G69oohapFOkZkqhe2zs6wo/c1TZoDu+6h1++ZJFNJJ0DbHYXrkf20DZRq l4qO0D9JluouJuudQH83HadTIepfdWfRIy+8rJVQI406p0uAjcy9R11KIfzGKAIhLzGQ x6uNSJaaAYJzt2x2mRaEFh8GVCVjFvx3iDkVo2QigO43+h7fkiOQeeyCH95qLgw/tQTi Ek6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721238462; x=1721843262; 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=1Hk1vOhEtpNT8o6McHb9O6PZJBmCTMgCBX1nWzjTxVE=; b=YkmeyXjKB/8Ec34rZ5Kjufe32xIdyQf/rfsOhwfONfQbWNKBVPNUv268opkfJRJHPu sg795+hYef1xpT8H1Pkr8vGQCXFa3kCEJhZKRqPiKGovdRSa5nxbVGlIPL86C14DNsw2 mqNG/m/EVjHXcwNooDTJJxy4MZCMJ34cAjNaWLxLO7HD3CakuM9z5PWRboMtr3xzTnsW QYcGLvSxhMxEkNcwMp++V0PIDNWPFmaqAFevrOJLbi6SEDcnz4v2NIDdL3txlRGgJ0gb LYt6/SXrOLo7/8YS9kWRUJBvhYyCS+jzcBoKStm1ssPCrGDRBb4EVn9jHQZuZ/d6GVBe 914A== X-Forwarded-Encrypted: i=1; AJvYcCUqacUj1iPd79RxUrM9Yw54PuBR6w/x+0rWU2JKz8TZ9XMUZyogMwo/LF8oJdVUiv4W39MOfYcQBHwXh0n4ILJPfyrq9ss96WSTW2eWCnL7gnW0xdcmvMTwatvRzTIHtMeD X-Gm-Message-State: AOJu0YzYsi+ruZBffuvi8GVQ78X25Zc73xj397VBTOr9vinhCCwBF44i cInorQAQviyWVqpDxxjIbCHrh7IG1Bu75KXawA8mwf1epFhdrOdG X-Google-Smtp-Source: AGHT+IG2v9n5WK0JXwdEu98eZ50zz69zNuje+Regv6AkbfgeTzXByBFuU/KN/LO9gbET4Y3CWmGEAg== X-Received: by 2002:a05:6a21:6d94:b0:1c3:b239:83e2 with SMTP id adf61e73a8af0-1c3fdcbffa5mr3387724637.12.1721238462032; Wed, 17 Jul 2024 10:47:42 -0700 (PDT) Received: from localhost ([116.198.225.81]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ec7e4bcsm8398596b3a.117.2024.07.17.10.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 10:47:41 -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: [v2 PATCH bpf-next 1/4] bpftool: refactor xdp attach/detach type judgment Date: Thu, 18 Jul 2024 01:47:36 +0800 Message-Id: <20240717174736.1511339-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 no logical changed, just increases code readability and facilitates TCX prog expansion, which will be implemented in the next patch. 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 Wed Jul 17 17:47:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13735672 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.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 CC53C183080; Wed, 17 Jul 2024 17:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238475; cv=none; b=bRKsGvmN635AnwOAbs6LWbYkH93V2dDhQjY5Rf1KlsfW0me10PYVLRfL+RwdvlgVXk4MHfnxUZ/kuHeZ/l1Q5sKMJl0ogjb7mbLkQ3nRq6609RQcLYCu4zuIi6F1qU+c6Lj9E2U+7uUAnW/GsLisyShG653tmbQ0PXEw+OvytKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238475; c=relaxed/simple; bh=hlw8mQSVUmKVKhzFLnEybQ+LNvuuiXl75EnFgGgdVXA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=UmYKD+HPGYLGyOpviumjEDdBop4sdrlUXhKfw2jivtDZfLfjf0CJCvteVd8Is1I2EeB5DugQ3eH9BssXUFWbGILDrrEXxWQK0I29za48MIowWdSI1Xjf1IqXIjWW+LNfnShV82vHvgcRwzf5AjQDOm2MxdmJ9PTY8VCXlFIHP8o= 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=SrV80G4j; arc=none smtp.client-ip=209.85.216.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="SrV80G4j" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2caaae31799so5095613a91.0; Wed, 17 Jul 2024 10:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721238473; x=1721843273; 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=u0sh2Qx0QKHKW9EVnBg4PhiJlHbuvx8m1ke9g+ElCrk=; b=SrV80G4jhEiubSCv4i9krR+1AeNhD3f8aSTGLDTyjQPkfbqyojjsAldkFIjYfHKlcC pT4SF0cnUgflhGFdpHTCe1gc3TMYSPQfH3s95tx8LverH7L2x5N/W6nlzjRcuoR3AlC9 lfQ8cP6AxaF0wm1eYPbPvlBMyEVj4jlq5FG2o6AyI1VS1YUyeRYJPj0hOTITczbiL6zh 21W1L0UeozWPZnOFRZSbPOQ6K64YhfIQVUDDpii7Q8NIRyBzBdOd0Gu3uZBOaSpjW0A0 WgZJuxdQJmNr5VEHBbJKAMx5eAUlosEz7IQRdENd5Wo4b27/38KZR2t478saSbViKgUu VQBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721238473; x=1721843273; 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=u0sh2Qx0QKHKW9EVnBg4PhiJlHbuvx8m1ke9g+ElCrk=; b=FoFEtQQJIxKDQA8gTftSBmh//htxMZcZMrS5dKymKHCzUFkw3JYseTN/1P0y9+WdfI HSycqAKRclMksSrWh+S/3gHMShj1RFhf0XFD7alrvC6GMC5fi1I1nkepGMumaqoRy6SG 5V/7oXt847Hna66XPs4pgKBDhrGbyzCPc0SX5YdtAFtzZlsK44L4E/k4aXUBiwuSg0Dh R1cj5aWH4HeoHF+lT1zqr36z6FF2LoDKBh98HAUfGQ2hLWQ3gu+fcOM90wElhmLjV7ra hH7u1c8zWSUrpTvkbL+zUR7CVFd/6Vdz6pEbTKETTImHwWoQqQaBYLb1O2wnijQ1eTyF eV8w== X-Forwarded-Encrypted: i=1; AJvYcCW8on7LbysGvrFVvAz8dmxkfKqD0wANpC6VEfT6/qBu6J70XJTx3d3dfFgAsuAYWfJPH4rHna3ntX53hy3F3qJgraUBhH16yzyb2ejWRaPC3ZrZq8fczXKmg9sUQyrT4j5t X-Gm-Message-State: AOJu0Ywn/zDJjecuXR85+ekvZAkSwiANYyyxUoTXNEjIBSnak2BW9FSi 8eK/xTYZIYD5tyd+A6G1LZfY5NFsVhDxAL0U1CWCTCJ5T/AsL16B X-Google-Smtp-Source: AGHT+IFNpZSwxKYCjKtdzPxrBLb/WA0ob6ivkZ0SDSsRQkxtL212u4LOI9S4TGdzA6qgOIaGGf8CsA== X-Received: by 2002:a17:90a:fd04:b0:2cb:4f14:2a70 with SMTP id 98e67ed59e1d1-2cb529327f7mr1951043a91.30.1721238472901; Wed, 17 Jul 2024 10:47:52 -0700 (PDT) Received: from localhost ([116.198.225.81]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cb601ec946sm217440a91.37.2024.07.17.10.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 10:47:52 -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: [v2 PATCH bpf-next 2/4] bpftool: add net attach/detach command to tcx prog Date: Thu, 18 Jul 2024 01:47:49 +0800 Message-Id: <20240717174749.1511366-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 --- 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..60b0af40109a 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 __MAX_BPF_ATTACH_TYPE; + } +} + +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 Wed Jul 17 17:55:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13735679 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 C763C183060; Wed, 17 Jul 2024 17:55:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238943; cv=none; b=k9vg+LINPcYeEScLjd2rAKdQTCK5XrC12H7zzxvs2hTHIVTEuz+FKsXCCPqRgbuGIKyCC6mtGZYxVj10RohW9lXi94fc94aZlzabyVHgIeCVKk2R9dmpu9doGPCdufYJt5HfPi+ADL/tkVynPmRIvOMgMDM3ZYaaX08CiirzoUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238943; c=relaxed/simple; bh=M9OsTrgIij8MNnlp4KGeXx1ahLgmNYh0GN+taKPlyWc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=sLxIc6hYUvlQID4VdkoG9CfU9uCckeD8T5Szq0twYiOUJ2PIv8bUpRfe1PcAKsOllMWXqZxD3h43vrx8VIYK+KJ3tpou55GFLPf8lzAjXwHVPYjCSP8z3zMpHFONDD71pXgwgD7xcG1FaAT0h1gryuEbEYbQbb5y8jo1Nl4w1DE= 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=LWo+NXr7; arc=none smtp.client-ip=209.85.215.169 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="LWo+NXr7" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-793a3a79a83so2432617a12.3; Wed, 17 Jul 2024 10:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721238941; x=1721843741; 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=9355sAQbA+Cma2PeN44/4qCQn2hLsRjzFaO5Nrb9YNg=; b=LWo+NXr7dNIdEEvwTtMQNvfz0V6JdxcYhDA2GakPM6Pqr1moCpRO2z6t/VYEWt3apn 2N9MoGb4iJ/Z4+Doo0K2sV8jFugK+rizKPknyI/OlEhKRgo7l0DtPJAtRhp/l6FWGNld aJgz7x9jpuL9/yTQMIgZ4Di0zGb/awuTUv7HPVuzfux6tstlpqxSdltvFeb1G6hcVunp 3f+9xld7ccdpLdDTehkqfVMo+kDmBmNDiX6nZWvFdvl/LJTBJeWCU5mDvQD2b0pOlzsX +9RIGC+zUavrf5z4h+RCOTCJZKutBLQS+5ArTWqmxiAzwN5Ewl0+M0JhXQ3K2kZY6GFU saQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721238941; x=1721843741; 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=9355sAQbA+Cma2PeN44/4qCQn2hLsRjzFaO5Nrb9YNg=; b=KG/z4FwTJ353i5cAehTtGmk0vLILfVK2fZHCSZKNtXAFe6fUjDYSsBDXm0GDKVZaTf ISPktHXF9LerOxQQ/2QGyXvqmbGeH6zj9b1pbv5hq+uC86FctihauiqmpmqjAtm1Dtfy fNUZc6XG4nR2Uv7WjYz+fjfLMusofgZyQ/lWnSyhwdEEDhaLdRFOakev3uA/IfX3jTQj I6DfqKB1U8vHRBeZA1RCRB9ZkA6MacblykPjWc8MFJM2Pvc0ld5u51jcmUSrA5an5u1S l+KpqYEowengYIW4UIa8K3GWDr20xOzIfC7ODsY0lzZZaSZbtEawPS7betPu4jDtal2u 87mw== X-Forwarded-Encrypted: i=1; AJvYcCUqoYmN0InKqjiIEvF6niONkSYx04cyGbPzNATKIsr2IwACK3toIn1+Fg6J/FQwvcClrPzFHZrWA6bPSE3uhJ2wrv+EelY/DEhYfAHIzmIhQ9cqcpOWqK6mzqyw165vwJp/ X-Gm-Message-State: AOJu0YxNoceZAXkaZ8NbWXWmTVi18bXTmK3BN0naftE+kESBwgtF+Vrd thdiYi2RJ1m8Bx9cJexW3UyTMBMx5oqqoqmDuTY+Y8hpVMAwslxkzqL33PN6 X-Google-Smtp-Source: AGHT+IEVd779bNMnUtx1/OMIvo5qp3aoCngTN8uY1OR91wFQY/7+POeCcsMRP7dHdGcrpABgC1jugw== X-Received: by 2002:a05:6a20:a10f:b0:1c2:9487:ee90 with SMTP id adf61e73a8af0-1c3fdd6b4aamr3336113637.44.1721238940775; Wed, 17 Jul 2024 10:55:40 -0700 (PDT) Received: from localhost ([116.198.225.81]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ebb69e6sm8429664b3a.74.2024.07.17.10.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 10:55:40 -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: [v2 PATCH bpf-next 3/4] bpftool: add bash-completion for tcx subcommand Date: Thu, 18 Jul 2024 01:55:35 +0800 Message-Id: <20240717175535.1512054-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. 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 Wed Jul 17 17:55:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Chen X-Patchwork-Id: 13735680 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 2D8CE183068; Wed, 17 Jul 2024 17:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238955; cv=none; b=DewEUpyeyDtYDvC5pp+vb4eRk6ZIa8/UTkGPvPX75mff7z+p22uD6pFPc5BzzD4MgnzH24kzX5g8lycpx6qZUD0kOgYNPGTUHCNp4ZNDnP1Bo5sSbm7FLc7L0p9R0/XiyI4mzABA92D96pTAUUFkil7Zi7y4otGw6SIkmIx9Ut4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721238955; c=relaxed/simple; bh=nWpNdRmuS4vCP5i+Yp+KKH6GI8MxgME7esnrEhssBzU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=odN1C3TdeDd/qDeJGhp5oW50O4kB6KGKjezwZ8lJxdtwvpUaOykHRjGvhlDAdQDvZ87kvIW+K21acNsQrxAWCgwS99hUfwsrPaG5HEt9IA+C5p00DigQVkxcIFJxd+js5rMS7dcd+jNPJ4sMu8PETwHgOAhOZ4kJfTB6AAwpYzA= 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=j9sYsLqu; arc=none smtp.client-ip=209.85.214.173 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="j9sYsLqu" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fb05b0be01so49136385ad.2; Wed, 17 Jul 2024 10:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721238953; x=1721843753; 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=KEbbdd9YNwTR1oy8pR+LUVTk58PGi94R+NS2hMzG6PE=; b=j9sYsLqu4f94gyXcoa3wneDFr5wxN2KABUQUeK3pWaJb1OMadh0LQB443NHnjn5Hdp jdt+75qO9cNH0zkpv6YCUlRtClvSxykjy/5gqryAY1ERgOIr6NqdsLhZzirkkY1X5NMG Zx/te1DNH+o8lDykOYahbC0U62+zVP3To9meWEWbVVyYE6ixgEon786SW7eiqLono3gW RZc4ad62JoqujmXt7wAhuyyYcJyhi+jYpek0p0VrlcLpCnGfYBLNJkdg5zvKAolM8PaK ujGVDbh/RiEdcCqv/nyKhBHP9svLbge7jEZb0eAVbzK9qGhve8PVlhRjlIQ9tSaJKV7Y x/Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721238953; x=1721843753; 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=KEbbdd9YNwTR1oy8pR+LUVTk58PGi94R+NS2hMzG6PE=; b=amT7rJi9cRGWif/bNrWIfExxyxKo1X+om2uBhMQ5JqKdu24YEP5nG0tgUJEby2/set jQzVR98OCRV/ux1r6VG1gkuF7yfSeM8SpUrJScGHdohOKw1BQgUN0azyTQTrQc/oRvlZ FbdB2zQWfrbN3yzgDdleFiEKOxh1FvlbpRNVnRJvVMyAhzPatUi8n9+/HiHJrr3Pcx3O TSZ4vbhwMjoWG03Qe92nOzKkYzrynl10mVKlKQnnVidIhLl7pjfyfvJw/MzC00bhWyD2 g96LlO5xcF+CiZhqtp1achYKilPpdZu8/3Q59myfw8Cnk9TC7VeCU0l+FAM0fqy6krnm vYpA== X-Forwarded-Encrypted: i=1; AJvYcCXYe2pvgY04z/cgVKrM7n5ZZOW5pRbRGRuAK9/p4v99uPidadsZVq0D17p2gLvoceeYQ1D8oLTMyUfXqq01cTI6bjyPJaEsMjbE/Kys8goZHSTu5LHnSHxY59+O+aqhTm7T X-Gm-Message-State: AOJu0YyUiGe92vE1nWNvYdyzATdqRGaQ2diEbfqu0KOgytZPUSAtyoYA oogb3sZtO4vlmQUcACVYYN87PTAYwzgyNUm5kM48RZ4Oi1shgEvt X-Google-Smtp-Source: AGHT+IEM1QTt/AmeIZwgPmUP7/OY4FU6pDZ3agAqoBTQuzmAYwJI4Tkl21VbmbbuJ/MVa9uKS8xm0w== X-Received: by 2002:a17:902:db07:b0:1f7:2293:1886 with SMTP id d9443c01a7336-1fc4e165dffmr22434765ad.12.1721238953366; Wed, 17 Jul 2024 10:55:53 -0700 (PDT) Received: from localhost ([116.198.225.81]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bc53fc6sm77926575ad.294.2024.07.17.10.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 10:55:53 -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: [v2 PATCH bpf-next 4/4] bpftool: add document for net attach/detach on tcx subcommand Date: Thu, 18 Jul 2024 01:55:48 +0800 Message-Id: <20240717175548.1512076-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. 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: