Skip to contentSkip to conversation

bpftool: add tcx subcommand in net

RFC PATCH Superseded Tao Chen 2 participants 7 messages Jul 15, 2024 – Jul 17, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tao Chen

author
#0 lore raw

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

Tao Chen (3):
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

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

RFC PATCH 1/3 bpftool: add net attach/detach command to tcx prog

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 tcxingress name tc_prog dev lo
 # bpftool net
	...
	tc:
	lo(1) tcx/ingress tc_prog prog_id 29
 # bpftool net detach tcxingress dev lo
 # bpftool net
	...
	tc:
 # bpftool net attach tcxingress 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

---
 tools/bpf/bpftool/net.c | 52 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
tools/bpf/bpftool/net.c +51 -1
index 968714b4c3d4..be7fd76202f1 100644
@@ -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]	= "tcxingress",
+	[NET_ATTACH_TYPE_TCX_EGRESS]	= "tcxegress",
 };
 
 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)
+{
+	int type = 0;
+
+	if (attach_type == NET_ATTACH_TYPE_TCX_INGRESS)
+		type |= BPF_TCX_INGRESS;
+	else if (attach_type == NET_ATTACH_TYPE_TCX_EGRESS)
+		type |= BPF_TCX_EGRESS;
+
+	return 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;
@@ -694,6 +724,15 @@ static int do_attach(int argc, char **argv)
 		goto cleanup;
 	}
 
+	/* attach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_attach_tcx(progfd, attach_type, ifindex);
+	if (err) {
+		p_err("interface %s attach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		goto cleanup;
+	}
+
 	if (json_output)
 		jsonw_null(json_wtr);
 cleanup:
@@ -732,6 +771,16 @@ static int do_detach(int argc, char **argv)
 		return err;
 	}
 
+	/* detach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_detach_tcx(ifindex, attach_type);
+
+	if (err < 0) {
+		p_err("interface %s detach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		return err;
+	}
+
 	if (json_output)
 		jsonw_null(json_wtr);
 
@@ -928,7 +977,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 | tcxingress\n"
+		"			| tcxegress}\n"
 		"       " HELP_SPEC_OPTIONS " }\n"
 		"\n"
 		"Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n"
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [RFC PATCH bpf-next 1/3] bpftool: add net attach/detach command to tcx prog

2024-07-15 12:37 UTC+0100 ~ Tao Chen <[email protected]>

Quoted 47 lines

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 tcxingress name tc_prog dev lo
 # bpftool net
	...
	tc:
	lo(1) tcx/ingress tc_prog prog_id 29
 # bpftool net detach tcxingress dev lo
 # bpftool net
	...
	tc:
 # bpftool net attach tcxingress 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

---
 tools/bpf/bpftool/net.c | 52 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
tools/bpf/bpftool/net.c +2 -0
index 968714b4c3d4..be7fd76202f1 100644
@@ -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[] = {

tools/bpf/bpftool/net.c static const char * const attach_type_strings[] = { · line 80

Quoted 5 lines
tools/bpf/bpftool/net.c +2 -0
@@ -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]	= "tcxingress",
+	[NET_ATTACH_TYPE_TCX_EGRESS]	= "tcxegress",

Hi, thanks for this work!

I wonder whether "tcx_ingress" and "tcx_egress" might be more readable? I know we don't have underscores for XDP types but I'd be tempted to add it for the tcx types, what do you think?

Quoted 5 lines
tools/bpf/bpftool/net.c +0 -0
 };
 
 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);

tools/bpf/bpftool/net.c static int do_attach_detach_xdp(int progfd, enum net_attach_type attach_type, · line 661

Quoted 10 lines
tools/bpf/bpftool/net.c +8 -0
 }
 
+static int get_tcx_type(enum net_attach_type attach_type)
+{
+	int type = 0;
+
+	if (attach_type == NET_ATTACH_TYPE_TCX_INGRESS)
+		type |= BPF_TCX_INGRESS;
+	else if (attach_type == NET_ATTACH_TYPE_TCX_EGRESS)
+		type |= BPF_TCX_EGRESS;

Why the logical OR in this function? This seems to be copied from the XDP code, where we need to set flags. Here we just need the type, if I remember correctly, so we could have:

	switch (attach_type) {
	case (NET_ATTACH_TYPE_TCX_INGRESS):
		return BPF_TXC_INGRESS;
	case (NET_ATTACH_TYPE_TCX_EGRESS):
		return BPF_TCX_EGRESS;
	}

(or if/else, works as well) which would be easier to understand in my opinion.

Quoted 23 lines
tools/bpf/bpftool/net.c +18 -0
+
+	return 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;
@@ -694,6 +724,15 @@ static int do_attach(int argc, char **argv)
 		goto cleanup;

tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 734

Quoted 10 lines
tools/bpf/bpftool/net.c +8 -0
 	}
 
+	/* attach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_attach_tcx(progfd, attach_type, ifindex);
+	if (err) {
+		p_err("interface %s attach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		goto cleanup;
+	}

This introduces a second check on "err" in the function: if we attach an XDP program we'll try to attach then check "err" twice. Same for a TCX program, we'll check "err" before even trying to attach.

I understand this replicates what we do for XDP, but I'm not sure the sequential calls to 'is_prefix("...")' is the cleanest approach. We should probably change the XDP case a bit and integrate with TCX better. Expanding the different attach types is more verbose, but remains the most straightforward way in my opinion.

	switch (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:
		err = do_attach_xdp(...);
		break;
	case NET_ATTACH_TYPE_TCX_INGRESS:
	case NET_ATTACH_TYPE_TCX_EGRESS:
		err = do_attach_tcx(...);
		break;
	}

	// Single check on "err" for both XDP and TCX here;
	// Or moving it to the switch statement if checks/error messages
	// needed to be different, but that's not the case in your patch
	if (err) {
		p_err(...);
		goto cleanup;
	}
Quoted 7 lines
tools/bpf/bpftool/net.c +1 -0
+
 	if (json_output)
 		jsonw_null(json_wtr);
 cleanup:
@@ -732,6 +771,16 @@ static int do_detach(int argc, char **argv)
 		return err;
 	}

tools/bpf/bpftool/net.c static int do_detach(int argc, char **argv) · line 782

Quoted 10 lines
tools/bpf/bpftool/net.c +9 -0
 
+	/* detach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_detach_tcx(ifindex, attach_type);
+
+	if (err < 0) {
+		p_err("interface %s detach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		return err;
+	}

Same here.

tools/bpf/bpftool/net.c static int do_help(int argc, char **argv) · line 981

Quoted 11 lines
tools/bpf/bpftool/net.c +3 -1
+
 	if (json_output)
 		jsonw_null(json_wtr);
 
@@ -928,7 +977,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 | tcxingress\n"
+		"			| tcxegress}\n"

Please use spaces only for indent inside of the string, and add a space before the ending '}'.

Quoted 3 lines
tools/bpf/bpftool/net.c +0 -0
 		"       " HELP_SPEC_OPTIONS " }\n"
 		"\n"
 		"Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n"
author
#3 lore raw

Re: [RFC PATCH bpf-next 1/3] bpftool: add net attach/detach command to tcx prog

Quoted 57 lines · Quentin Monnet

2024-07-15 12:37 UTC+0100 ~ Tao Chen <[email protected]>

Quoted 47 lines

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 tcxingress name tc_prog dev lo
  # bpftool net
	...
	tc:
	lo(1) tcx/ingress tc_prog prog_id 29
  # bpftool net detach tcxingress dev lo
  # bpftool net
	...
	tc:
  # bpftool net attach tcxingress 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

---
  tools/bpf/bpftool/net.c | 52 ++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 51 insertions(+), 1 deletion(-)
tools/bpf/bpftool/net.c +2 -0
index 968714b4c3d4..be7fd76202f1 100644
@@ -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[] = {

tools/bpf/bpftool/net.c static const char * const attach_type_strings[] = { · line 80

Quoted 5 lines
tools/bpf/bpftool/net.c +2 -0
@@ -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]	= "tcxingress",
+	[NET_ATTACH_TYPE_TCX_EGRESS]	= "tcxegress",

Hi, thanks for this work!

Quoted 5 lines

I wonder whether "tcx_ingress" and "tcx_egress" might be more readable? I know we don't have underscores for XDP types but I'd be tempted to add it for the tcx types, what do you think?

Hi,Quentin,thanks for your reply!
You are right, tcx_* looks more readable, i will change it in v2.

Quoted 28 lines
Quoted 5 lines
tools/bpf/bpftool/net.c +0 -0
  };
 
  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);

tools/bpf/bpftool/net.c static int do_attach_detach_xdp(int progfd, enum net_attach_type attach_type, · line 661

Quoted 10 lines
tools/bpf/bpftool/net.c +8 -0
  }
 
+static int get_tcx_type(enum net_attach_type attach_type)
+{
+	int type = 0;
+
+	if (attach_type == NET_ATTACH_TYPE_TCX_INGRESS)
+		type |= BPF_TCX_INGRESS;
+	else if (attach_type == NET_ATTACH_TYPE_TCX_EGRESS)
+		type |= BPF_TCX_EGRESS;

Why the logical OR in this function? This seems to be copied from the XDP code, where we need to set flags. Here we just need the type, if I remember correctly, so we could have:

	switch (attach_type) {
	case (NET_ATTACH_TYPE_TCX_INGRESS):
		return BPF_TXC_INGRESS;
	case (NET_ATTACH_TYPE_TCX_EGRESS):
		return BPF_TCX_EGRESS;
	}
Quoted 3 lines

(or if/else, works as well) which would be easier to understand in my opinion.

It seems more reasonable, i will change it in v2.

Quoted 58 lines
Quoted 23 lines
tools/bpf/bpftool/net.c +18 -0
+
+	return 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;
@@ -694,6 +724,15 @@ static int do_attach(int argc, char **argv)
  		goto cleanup;

tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 734

Quoted 10 lines
tools/bpf/bpftool/net.c +8 -0
  	}
 
+	/* attach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_attach_tcx(progfd, attach_type, ifindex);
+	if (err) {
+		p_err("interface %s attach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		goto cleanup;
+	}

This introduces a second check on "err" in the function: if we attach an XDP program we'll try to attach then check "err" twice. Same for a TCX program, we'll check "err" before even trying to attach.

I understand this replicates what we do for XDP, but I'm not sure the sequential calls to 'is_prefix("...")' is the cleanest approach. We should probably change the XDP case a bit and integrate with TCX better. Expanding the different attach types is more verbose, but remains the most straightforward way in my opinion.

	switch (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:
		err = do_attach_xdp(...);
		break;
	case NET_ATTACH_TYPE_TCX_INGRESS:
	case NET_ATTACH_TYPE_TCX_EGRESS:
		err = do_attach_tcx(...);
		break;
	}
Quoted 9 lines
	// Single check on "err" for both XDP and TCX here;
	// Or moving it to the switch statement if checks/error messages
	// needed to be different, but that's not the case in your patch
	if (err) {
		p_err(...);
		goto cleanup;
	}

My bad, i will add another patch to refactor this as you say.

Quoted 26 lines
Quoted 7 lines
tools/bpf/bpftool/net.c +1 -0
+
  	if (json_output)
  		jsonw_null(json_wtr);
  cleanup:
@@ -732,6 +771,16 @@ static int do_detach(int argc, char **argv)
  		return err;
  	}

tools/bpf/bpftool/net.c static int do_detach(int argc, char **argv) · line 782

Quoted 10 lines
tools/bpf/bpftool/net.c +9 -0
 
+	/* detach tcx prog */
+	if (is_prefix("tcx", attach_type_strings[attach_type]))
+		err = do_detach_tcx(ifindex, attach_type);
+
+	if (err < 0) {
+		p_err("interface %s detach failed: %s",
+		      attach_type_strings[attach_type], strerror(-err));
+		return err;
+	}

Same here.

Got it.

Quoted 4 lines
tools/bpf/bpftool/net.c +1 -0
+
  	if (json_output)
  		jsonw_null(json_wtr);
 
Quoted 13 lines

tools/bpf/bpftool/net.c static int do_help(int argc, char **argv) · line 981

Quoted 7 lines
tools/bpf/bpftool/net.c +2 -1
@@ -928,7 +977,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 | tcxingress\n"
+		"			| tcxegress}\n"

Please use spaces only for indent inside of the string, and add a space before the ending '}'.

ok, i will fix this.

Quoted 4 lines
Quoted 3 lines
tools/bpf/bpftool/net.c +0 -0
  		"       " HELP_SPEC_OPTIONS " }\n"
  		"\n"
  		"Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n"
Signature · 2 lines
Best Regards
Dylane Chen
author
#4 lore raw

RFC PATCH 2/3 bpftool: add bash-completion for tcx subcommand

In reply to Tao Chen

This commit adds bash-completion for attaching tcx program on interface.

---
 tools/bpf/bpftool/bash-completion/bpftool | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/bash-completion/bpftool +1 -1
index be99d49b8714..eb36f5305945 100644
@@ -1079,7 +1079,7 @@ _bpftool()
             esac
             ;;
         net)
-            local ATTACH_TYPES='xdp xdpgeneric xdpdrv xdpoffload'
+            local ATTACH_TYPES='xdp xdpgeneric xdpdrv xdpoffload tcxingress tcxegress'
             case $command in
                 show|list)
                     [[ $prev != "$command" ]] && return 0
Signature · 1 line
2.34.1
author
#5 lore raw

RFC PATCH 3/3 bpftool: add document for net attach/detach on tcx subcommand

In reply to Tao Chen

This commit adds sample output for net attach/detach on tcx subcommand.

---
 .../bpf/bpftool/Documentation/bpftool-net.rst | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Documentation/bpftool-net.rst +21 -1
index 348812881297..64de7a33f176 100644
@@ -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** | **tcxingress** | **tcxegress** }
 
 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;
+    **tcxingress** - Ingress TC. runs on ingress net traffic;
+    **tcxegress** - Egress TC. 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:
+
+|
+| **# bpf net attach tcxingress name tc_prog dev lo**
+| **# bpf net**
+|
+
+::
+      tc:
+      lo(1) tcx/ingress tc_prog prog_id 29
+
+|
+| **# bpf net attach tcxingress name tc_prog dev lo**
+| **# bpf net detach tcxingress dev lo**
+| **# bpf net**
+|
+
+::
+      tc:
Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [RFC PATCH bpf-next 3/3] bpftool: add document for net attach/detach on tcx subcommand

2024-07-15 12:37 UTC+0100 ~ Tao Chen <[email protected]>

Quoted 22 lines

This commit adds sample output for net attach/detach on tcx subcommand.

---
 .../bpf/bpftool/Documentation/bpftool-net.rst | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Documentation/bpftool-net.rst +1 -1
index 348812881297..64de7a33f176 100644
@@ -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** | **tcxingress** | **tcxegress** }
 
 DESCRIPTION
 ===========

tools/bpf/bpftool/Documentation/bpftool-net.rst bpftool net attach *ATTACH_TYPE* *PROG* dev *NAME* [ overwrite ] · line 73

Quoted 5 lines
tools/bpf/bpftool/Documentation/bpftool-net.rst +2 -0
@@ -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;
+    **tcxingress** - Ingress TC. runs on ingress net traffic;
+    **tcxegress** - Egress TC. runs on egress net traffic;

I'd keep "TCX" rather than "TC" in the docs, please, to avoid confusion with programs attached to clsact qdiscs, for example.