Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle.FilterList() produces 0 results #922

Open
lorenzocipriani opened this issue Nov 3, 2023 · 0 comments
Open

Handle.FilterList() produces 0 results #922

lorenzocipriani opened this issue Nov 3, 2023 · 0 comments

Comments

@lorenzocipriani
Copy link

It looks like the FilterList() function doesn't return the expected results.

Given this snippet of sample code:

netlinkHandle, err := netlink.NewHandle()
if err != nil {
	fmt.Printf("HANDLE ERROR: %v", err)
}

fmt.Printf("\n\n[tc qdisc show]\n")
qdiscs, err := netlinkHandle.QdiscList(nil)
if err != nil {
	logger.Error().
		Err(err).
		Msg("cannot get the qdiscs list")
}

for _, qdisc := range qdiscs {

	if qdisc.Type() == "clsact" && qdisc.Attrs().Parent == netlink.HANDLE_INGRESS {
		fmt.Printf("\nQDISC:[%s]\n%s\n", qdisc.Type(), qdisc.Attrs().String())

		if link, err := netlinkHandle.LinkByIndex(qdisc.Attrs().LinkIndex); err == nil {
			fmt.Printf("[tc filter show %s dev %s]\n", netlink.HandleStr(qdisc.Attrs().Parent), link.Attrs().Name)
			fmt.Printf("LINK:\n%+v\n", link)

			filters, _ := netlinkHandle.FilterList(link, qdisc.Attrs().Parent)
			fmt.Printf("FILTERS: %d\n", len(filters))
			
			for _, filter := range filters {
				fmt.Printf("FILTER:[%s]\n%+v\n", filter.Type(), filter.Attrs())
			}
		}
	}
}

I expected to see a couple of entries for each link, but the result shows 0 filters defined for the given links:

[tc qdisc show]

QDISC:[clsact]
{LinkIndex: 3, Handle: ffff:0, Parent: ingress, Refcnt: 1}
[tc filter show ingress dev eno1]
LINK:
&{LinkAttrs:{Index:3 ... Name:eno1 ... }}
FILTERS: 0

QDISC:[clsact]
{LinkIndex: 4, Handle: ffff:0, Parent: ingress, Refcnt: 1}
[tc filter show ingress dev enp3s0f0]
LINK:
&{LinkAttrs:{Index:4 ... Name:enp3s0f0 ... }}
FILTERS: 0

If I use the tc commands that are shown in the square brackets, I obtain what I expected:

# tc qdisc show
...
qdisc clsact ffff: dev eno1 parent ffff:fff1
...
qdisc clsact ffff: dev enp3s0f0 parent ffff:fff1
# tc filter show ingress dev eno1
filter protocol all pref 49152 bpf chain 0
filter protocol all pref 49152 bpf chain 0 handle 0x1 ###.bpf.o:[classifier] direct-action not_in_hw id 3522 tag ### jited
# tc filter show ingress dev enp3s0f0
filter protocol all pref 49152 bpf chain 0
filter protocol all pref 49152 bpf chain 0 handle 0x1 ###.bpf.o:[classifier] direct-action not_in_hw id 3518 tag ### jited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant