Skip to contentSkip to conversation

bpftool: add tcx subcommand in net

PATCH Applied Tao Chen 3 participants 4 messages Jul 21, 2024 – Jul 22, 2024

Subsystems (2)
lore
Share & tools
lore

Tao Chen

author
#0 lore raw

v3 cover bpftool: add tcx subcommand in net

XDP prog has already realised with net attach/detach subcommand. As Qmonnet said [0], tcx prog may also can be added. So this patch set adds tcx subcommand in net attach/detach.

[0] https://github.com/libbpf/bpftool/issues/124

Change list:
- v2 -> v3:
- fix return value in patch2
- replace tabs with spaces patch2
- v1 -> v2:
- As suggested by Quentin, modification as fellows:
- refactor xdp attach/detach type judgment in patch1
- err handle fix for xdp in patch2
- change command tcx* to tcx_* in patch2
- some code modification for readable in patch2
- document modification for readable in patch4

Revisions:
- v1 https://lore.kernel.org/bpf/[email protected]
- v2 https://lore.kernel.org/bpf/[email protected]

Tao Chen (4):
bpftool: refactor xdp attach/detach type judgment
bpftool: add net attach/detach command to tcx prog
bpftool: add bash-completion for tcx subcommand
bpftool: add document for net attach/detach on tcx subcommand

 .../bpf/bpftool/Documentation/bpftool-net.rst | 22 +++++-
 tools/bpf/bpftool/bash-completion/bpftool     |  2 +-
 tools/bpf/bpftool/net.c                       | 69 +++++++++++++++++--
 3 files changed, 85 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/4 bpftool: refactor xdp attach/detach type judgment

This commit no logical changed, just increases code readability and facilitates TCX prog expansion, which will be implemented in the next patch.

---
 tools/bpf/bpftool/net.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
tools/bpf/bpftool/net.c +21 -5
index 968714b4c3d4..1b9f4225b394 100644
@@ -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",
Signature · 1 line
2.34.1
#2 lore raw
In reply to Tao Chen
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [v3,bpf-next,0/4] bpftool: add tcx subcommand in net
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=872760&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10029201939

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#3 lore raw
In reply to Tao Chen
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 18 lines · On Sun, 21 Jul 2024 22:33:49 +0800 you wrote:

XDP prog has already realised with net attach/detach subcommand. As Qmonnet said [0], tcx prog may also can be added. So this patch set adds tcx subcommand in net attach/detach.

[0] https://github.com/libbpf/bpftool/issues/124

Change list:
- v2 -> v3:
- fix return value in patch2
- replace tabs with spaces patch2
- v1 -> v2:
- As suggested by Quentin, modification as fellows:
- refactor xdp attach/detach type judgment in patch1
- err handle fix for xdp in patch2
- change command tcx* to tcx_* in patch2
- some code modification for readable in patch2
- document modification for readable in patch4

Quoted 1 line

[...]

Here is the summary with links:
- [v3,bpf-next,1/4] bpftool: refactor xdp attach/detach type judgment

    https://git.kernel.org/bpf/bpf-next/c/f408126f7b33
  - [v3,bpf-next,2/4] bpftool: add net attach/detach command to tcx prog
    https://git.kernel.org/bpf/bpf-next/c/7f1cfa6b64c6
  - [v3,bpf-next,3/4] bpftool: add bash-completion for tcx subcommand
    https://git.kernel.org/bpf/bpf-next/c/0445e0c5c2e1
  - [v3,bpf-next,4/4] bpftool: add document for net attach/detach on tcx subcommand
    https://git.kernel.org/bpf/bpf-next/c/6d5848d4fe98

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html