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

Ignore type when device was removed in devmon #96

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/devmon/devmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ func (d *DevMon) handleLink(add bool, link netlink.Link) {
typ = "loopback"
}

// use special type for device that is actually virtual, e.g., vboxnet
if typ == "device" {
// use special type for device that is actually virtual, e.g., vboxnet.
// this check only works when device was added. when device was
// removed, the symlink does not exist anymore. thus, we cannot be sure
// device is really a "device" when it was removed.
if add && typ == "device" {
sysfs := filepath.Join("/sys/class/net", attrs.Name)
path, err := filepath.EvalSymlinks(sysfs)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions internal/trafpol/trafpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ type TrafPol struct {

// handleDeviceUpdate handles a device update.
func (t *TrafPol) handleDeviceUpdate(ctx context.Context, u *devmon.Update) {
// skip physical devices and only allow virtual devices
if u.Type == "device" {
return
}

// add or remove virtual device to/from allowed devices
if u.Add {
// skip adding physical devices and only allow adding virtual devices.
// we cannot be sure about the type when removing devices, so do not
// skip when removing devices.
if u.Add && u.Type != "device" {
t.allowDevs.Add(ctx, u.Device)
return
}
Expand Down
Loading