add tc filter example
Subsystems (3)
v3 cover add tc filter example
The patch in this series introduces an example tool that creates, shows and deletes flower filter with two VLAN actions. The example inserts a dummy action at index 0 to work around the tc actions array oddity.
---
v3:
- Dropped the patch that ignored index zero for indexed arrays.
- Extended the example to work around tc action array indexing oddity.
- Move to the example CFLAGS to samples/Makefile.
- Enhanced attribute dumping.
v2: https://lore.kernel.org/netdev/[email protected]/
- extend the sampe tool to show and delete the filter
- drop fix for ynl_attr_put_str as already fixed by:
- make indexed-arrays to start from index 1.
v1: https://lore.kernel.org/netdev/[email protected]/
Zahari Doychev (1):
ynl: samples: add tc filter example
tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/Makefile | 1 + tools/net/ynl/samples/tc-filter-add.c | 327 ++++++++++++++++++++++++++ 3 files changed, 329 insertions(+) create mode 100644 tools/net/ynl/samples/tc-filter-add.c
Signature · 1 line
2.51.2
PATCH v3 1/1 ynl: samples: add tc filter example
Add a sample tool demonstrating how to add, dump, and delete a flower filter with two VLAN push actions. The example can be invoked as:
# samples/tc-filter-add p2
flower pref 1 proto: 0x8100
flower:
vlan_id: 100
vlan_prio: 5
num_of_vlans: 3
action order: 1 vlan push id 200 protocol 0x8100 priority 0
action order: 2 vlan push id 300 protocol 0x8100 priority 0This verifies correct handling of tc action attributes for multiple VLAN push actions. The tc action indexed arrays start from index 1, and the index defines the action order. This behavior differs from the YNL specification, which expects arrays to be zero-based. To accommodate this, the example adds a dummy action at index 0, which is ignored by the kernel.
--- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/Makefile | 1 + tools/net/ynl/samples/tc-filter-add.c | 327 ++++++++++++++++++++++++++ 3 files changed, 329 insertions(+) create mode 100644 tools/net/ynl/samples/tc-filter-add.c
tools/net/ynl/samples/.gitignore +1 -0
@@ -7,3 +7,4 @@ rt-addr rt-link rt-route tc +tc-filter-add
tools/net/ynl/samples/Makefile +1 -0
@@ -19,6 +19,7 @@ include $(wildcard *.d) all: $(BINS) CFLAGS_page-pool=$(CFLAGS_netdev) +CFLAGS_tc-filter-add:=$(CFLAGS_tc) $(BINS): ../lib/ynl.a ../generated/protos.a $(SRCS) @echo -e '\tCC sample $@'
tools/net/ynl/samples/tc-filter-add.c new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
2.51.2
Jakub Kicinski
maintainerRe: [PATCH v3 1/1] ynl: samples: add tc filter example
tools/net/ynl/samples/tc-filter-add.c line 326
Quoted 10 lines · On Mon, 17 Nov 2025 11:57:08 +0100 Zahari Doychev wrote:
tools/net/ynl/samples/tc-filter-add.c new file +10
-0+if (tc_clsact_add (ys, ifi)) + goto err_destroy; + +tc_filter_config (ys, ifi); + +tc_clsact_del (ys, ifi); + +err_destroy: +ynl_sock_destroy (ys); +return 2 ;
Let's return 0 if nothing failed? Maybe:
if (tc_clsact_add(ys, ifi)) {
ret = 2;
goto err_destroy;
}
ret = 0;
if (tc_filter_config(ys, ifi))
ret = 3;
if (tc_clsact_del(ys, ifi))
ret = 4;err_destroy:
ynl_sock_destroy(ys); return ret; }
Signature · 1 line
pw-bot: cr