From 1a428fc113392ccea6a8e704c25788d2da9454d8 Mon Sep 17 00:00:00 2001 From: Chaitanya Kulkarni Date: Wed, 1 May 2024 12:10:50 -0700 Subject: [PATCH] Log current available routes on error (#388) --- google_guest_agent/accounts_windows.go | 6 +++--- google_guest_agent/instance_setup.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/google_guest_agent/accounts_windows.go b/google_guest_agent/accounts_windows.go index db258fb6..891cb72b 100644 --- a/google_guest_agent/accounts_windows.go +++ b/google_guest_agent/accounts_windows.go @@ -111,7 +111,7 @@ func resetPwd(username, pwd string) error { return nil } -func addUserToGroup(ctx context.Context, username, group string) error { +func addUserToGroup(_ context.Context, username, group string) error { gPtr, err := syscall.UTF16PtrFromString(group) if err != nil { return fmt.Errorf("error encoding group to UTF16: %v", err) @@ -138,7 +138,7 @@ func addUserToGroup(ctx context.Context, username, group string) error { return nil } -func createUser(ctx context.Context, username, pwd, _ string) error { +func createUser(_ context.Context, username, pwd, _ string) error { uPtr, err := syscall.UTF16PtrFromString(username) if err != nil { return fmt.Errorf("error encoding username to UTF16: %v", err) @@ -189,6 +189,6 @@ func userExists(name string) (bool, error) { return true, nil } -func getUIDAndGID(path string) (string, string) { +func getUIDAndGID(_ string) (string, string) { return "", "" } diff --git a/google_guest_agent/instance_setup.go b/google_guest_agent/instance_setup.go index f2b08dd0..26873b94 100644 --- a/google_guest_agent/instance_setup.go +++ b/google_guest_agent/instance_setup.go @@ -37,13 +37,15 @@ import ( func getDefaultAdapter(fes []ipForwardEntry) (*ipForwardEntry, error) { // Choose the first adapter index that has the default route setup. // This is equivalent to how route.exe works when interface is not provided. + defaultRoute := net.ParseIP("0.0.0.0") sort.Slice(fes, func(i, j int) bool { return fes[i].ipForwardIfIndex < fes[j].ipForwardIfIndex }) for _, fe := range fes { - if fe.ipForwardDest.Equal(net.ParseIP("0.0.0.0")) { + if fe.ipForwardDest.Equal(defaultRoute) { return &fe, nil } } - return nil, fmt.Errorf("could not find default route") + + return nil, fmt.Errorf("no default route to %s found in %+v forward entries", defaultRoute.String(), fes) } func addMetadataRoute() error {