refactor: improve network interface validation

Add context parameter to validInterfacesMap for better error handling and
logging. Move Windows-specific network adapter validation logic to the
ctrld package. Key changes include:

- Add context parameter to validInterfacesMap across all platforms
- Move Windows validInterfaces to ctrld.ValidInterfaces
- Improve error handling for virtual interface detection on Linux
- Update all callers to pass appropriate context

This change improves error reporting and makes the interface validation
code more maintainable across different platforms.
This commit is contained in:
Cuong Manh Le
2025-06-19 16:38:03 +07:00
committed by Cuong Manh Le
parent 627eb23ed6
commit eaa6ccc356
8 changed files with 38 additions and 89 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
package cli
import (
"context"
"net"
"tailscale.com/net/netmon"
@@ -13,7 +14,7 @@ func patchNetIfaceName(iface *net.Interface) (bool, error) { return true, nil }
func validInterface(iface *net.Interface, validIfacesMap map[string]struct{}) bool { return true }
// validInterfacesMap returns a set containing only default route interfaces.
func validInterfacesMap() map[string]struct{} {
func validInterfacesMap(ctx context.Context) map[string]struct{} {
defaultRoute, err := netmon.DefaultRoute()
if err != nil {
return nil