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

Fix determination of the promiscuity counter for links #1001

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

DresslerFrank
Copy link
Contributor

Function LinkDeserialize checked for presence of IFF_PROMISC in the link's flags to determine whether it was in promiscuous mode.

This flag only tracks what is set with commands such as

ip set <link> promisc on

but is not set when you run tcpdump or wireshark for example, which also put the device in promiscuous mode.

There is a counter that tracks the number of times promiscuous mode has been requested. It reacts to all the ways, ip set, and also tcpdump and co.

With this change this counter is used instead of checking the flag. This makes the library reflect what

ip -d link show <link>

would show in its promiscuity field.

To test this change, start some processes of tcpdump or similar and see the counter increase in ip -d link show <link> as well as in the patched version of this netlink library. With the unpatched version the counter remains 0. Then enable promiscuous mode globally for the interface. This will increase the count in all variants, ip link, the old unpatched and the patched version of this netlink library.

Simple test program for reference:

package main

import "fmt"
import "github.com/vishvananda/netlink"

func main() {
	handle, _ := netlink.NewHandle()
	links, _ := handle.LinkList()
	for _, link := range links {
		attrs := link.Attrs()
		fmt.Printf("dev=%v promisc=%v\n",
			attrs.Name, attrs.Promisc)
	}
}

Function `LinkDeserialize` checked for presence of `IFF_PROMISC` in
the link's flags to determine whether it was in promiscuous mode.

This flag only tracks what is set with commands such as

	ip set <link> promisc on

but is not set when you run `tcpdump` or `wireshark` for example,
which also put the device in promiscuous mode.

There is a counter that tracks the number of times promiscuous mode
has been requested. It reacts to all the ways, `ip set`, and also
`tcpdump` and co.

With this change this counter is used instead of checking the flag.
This makes the library reflect what

	ip -d link show <link>

would show in its `promiscuity` field.

To test this change, start some processes of `tcpdump` or similar
and see the counter increase in `ip -d link show <link>` as well
as in the patched version of this netlink library. With the
unpatched version the counter remains 0. Then enable promiscuous
mode globally for the interface. This will increase the count in
all variants, `ip link`, the old unpatched and the patched version
of this netlink library.

Simple test program for reference:

	package main

	import "fmt"
	import "github.com/vishvananda/netlink"

	func main() {
		handle, _ := netlink.NewHandle()
		links, _ := handle.LinkList()
		for _, link := range links {
			attrs := link.Attrs()
			fmt.Printf("dev=%v promisc=%v\n",
				attrs.Name, attrs.Promisc)
		}
	}
@DresslerFrank
Copy link
Contributor Author

Fixes #1002

@aboch
Copy link
Collaborator

aboch commented Aug 6, 2024

LGTM

@aboch aboch merged commit aaf4f98 into vishvananda:main Aug 6, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants