Skip to content

Commit

Permalink
Log current available routes on error (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaitanyaKulkarni28 authored May 1, 2024
1 parent 997df9e commit 1a428fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions google_guest_agent/accounts_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 "", ""
}
6 changes: 4 additions & 2 deletions google_guest_agent/instance_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1a428fc

Please sign in to comment.