From bf518c5fba3c12d6d6289e586596b591ba0f8051 Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:41:15 +0200 Subject: [PATCH] Remove interface network monitor checks (#2223) --- client/internal/networkmonitor/monitor_bsd.go | 36 ------------------- .../internal/networkmonitor/monitor_linux.go | 24 ------------- 2 files changed, 60 deletions(-) diff --git a/client/internal/networkmonitor/monitor_bsd.go b/client/internal/networkmonitor/monitor_bsd.go index 253fd68ff..8d6ccd51b 100644 --- a/client/internal/networkmonitor/monitor_bsd.go +++ b/client/internal/networkmonitor/monitor_bsd.go @@ -45,24 +45,6 @@ func checkChange(ctx context.Context, nexthopv4, nexthopv6 systemops.Nexthop, ca msg := (*unix.RtMsghdr)(unsafe.Pointer(&buf[0])) switch msg.Type { - - // handle interface state changes - case unix.RTM_IFINFO: - ifinfo, err := parseInterfaceMessage(buf[:n]) - if err != nil { - log.Errorf("Network monitor: error parsing interface message: %v", err) - continue - } - if msg.Flags&unix.IFF_UP != 0 { - continue - } - if (nexthopv4.Intf == nil || ifinfo.Index != nexthopv4.Intf.Index) && (nexthopv6.Intf == nil || ifinfo.Index != nexthopv6.Intf.Index) { - continue - } - - log.Infof("Network monitor: monitored interface (%s) is down.", ifinfo.Name) - go callback() - // handle route changes case unix.RTM_ADD, syscall.RTM_DELETE: route, err := parseRouteMessage(buf[:n]) @@ -94,24 +76,6 @@ func checkChange(ctx context.Context, nexthopv4, nexthopv6 systemops.Nexthop, ca } } -func parseInterfaceMessage(buf []byte) (*route.InterfaceMessage, error) { - msgs, err := route.ParseRIB(route.RIBTypeInterface, buf) - if err != nil { - return nil, fmt.Errorf("parse RIB: %v", err) - } - - if len(msgs) != 1 { - return nil, fmt.Errorf("unexpected RIB message msgs: %v", msgs) - } - - msg, ok := msgs[0].(*route.InterfaceMessage) - if !ok { - return nil, fmt.Errorf("unexpected RIB message type: %T", msgs[0]) - } - - return msg, nil -} - func parseRouteMessage(buf []byte) (*systemops.Route, error) { msgs, err := route.ParseRIB(route.RIBTypeRoute, buf) if err != nil { diff --git a/client/internal/networkmonitor/monitor_linux.go b/client/internal/networkmonitor/monitor_linux.go index de5e29b38..035be1f09 100644 --- a/client/internal/networkmonitor/monitor_linux.go +++ b/client/internal/networkmonitor/monitor_linux.go @@ -19,14 +19,9 @@ func checkChange(ctx context.Context, nexthopv4, nexthopv6 systemops.Nexthop, ca return errors.New("no interfaces available") } - linkChan := make(chan netlink.LinkUpdate) done := make(chan struct{}) defer close(done) - if err := netlink.LinkSubscribe(linkChan, done); err != nil { - return fmt.Errorf("subscribe to link updates: %v", err) - } - routeChan := make(chan netlink.RouteUpdate) if err := netlink.RouteSubscribe(routeChan, done); err != nil { return fmt.Errorf("subscribe to route updates: %v", err) @@ -38,25 +33,6 @@ func checkChange(ctx context.Context, nexthopv4, nexthopv6 systemops.Nexthop, ca case <-ctx.Done(): return ErrStopped - // handle interface state changes - case update := <-linkChan: - if (nexthopv4.Intf == nil || update.Index != int32(nexthopv4.Intf.Index)) && (nexthopv6.Intf == nil || update.Index != int32(nexthopv6.Intf.Index)) { - continue - } - - switch update.Header.Type { - case syscall.RTM_DELLINK: - log.Infof("Network monitor: monitored interface (%s) is gone", update.Link.Attrs().Name) - go callback() - return nil - case syscall.RTM_NEWLINK: - if (update.IfInfomsg.Flags&syscall.IFF_RUNNING) == 0 && update.Link.Attrs().OperState == netlink.OperDown { - log.Infof("Network monitor: monitored interface (%s) is down.", update.Link.Attrs().Name) - go callback() - return nil - } - } - // handle route changes case route := <-routeChan: // default route and main table