mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Capitalize the first letter of all log messages throughout the codebase to improve readability and consistency in logging output. Key improvements: - All log messages now start with capital letters - Consistent formatting across all logging statements - Improved readability for debugging and monitoring - Enhanced user experience with better formatted messages Files updated: - CLI commands and service management - Internal client information discovery - Network operations and configuration - DNS resolver and proxy operations - Platform-specific implementations This completes the final phase of the logging improvement project, ensuring all log messages follow consistent capitalization standards for better readability and professional appearance.
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
"os"
|
|
"strings"
|
|
|
|
"tailscale.com/net/netmon"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
// patchNetIfaceName patches network interface names on Linux
|
|
// This is a no-op on Linux as interface names don't need special handling
|
|
func patchNetIfaceName(iface *net.Interface) (bool, error) { return true, nil }
|
|
|
|
// validInterface reports whether the *net.Interface is a valid one.
|
|
// Only non-virtual interfaces are considered valid.
|
|
// This prevents DNS configuration on virtual interfaces like docker, veth, etc.
|
|
func validInterface(iface *net.Interface, validIfacesMap map[string]struct{}) bool {
|
|
_, ok := validIfacesMap[iface.Name]
|
|
return ok
|
|
}
|
|
|
|
// validInterfacesMap returns a set containing non virtual interfaces.
|
|
// This filters out virtual interfaces to ensure DNS is only configured on physical interfaces
|
|
func validInterfacesMap(ctx context.Context) map[string]struct{} {
|
|
m := make(map[string]struct{})
|
|
vis := virtualInterfaces(ctx)
|
|
netmon.ForeachInterface(func(i netmon.Interface, prefixes []netip.Prefix) {
|
|
if _, existed := vis[i.Name]; existed {
|
|
return
|
|
}
|
|
m[i.Name] = struct{}{}
|
|
})
|
|
// Fallback to the default route interface if found nothing.
|
|
// This ensures we always have at least one interface to configure
|
|
if len(m) == 0 {
|
|
defaultRoute, err := netmon.DefaultRoute()
|
|
if err != nil {
|
|
return m
|
|
}
|
|
m[defaultRoute.InterfaceName] = struct{}{}
|
|
}
|
|
return m
|
|
}
|
|
|
|
// virtualInterfaces returns a map of virtual interfaces on the current machine.
|
|
// This reads from /sys/devices/virtual/net to identify virtual network interfaces
|
|
// Virtual interfaces should not have DNS configured as they don't represent physical network connections
|
|
func virtualInterfaces(ctx context.Context) map[string]struct{} {
|
|
logger := ctrld.LoggerFromCtx(ctx)
|
|
s := make(map[string]struct{})
|
|
entries, err := os.ReadDir("/sys/devices/virtual/net")
|
|
if err != nil {
|
|
logger.Error().Err(err).Msg("Failed to read /sys/devices/virtual/net")
|
|
return nil
|
|
}
|
|
for _, entry := range entries {
|
|
if entry.IsDir() {
|
|
s[strings.TrimSpace(entry.Name())] = struct{}{}
|
|
}
|
|
}
|
|
return s
|
|
}
|