diff --git a/routing/update_linux.go b/routing/update_linux.go index 016fe8f4..4ee71151 100644 --- a/routing/update_linux.go +++ b/routing/update_linux.go @@ -9,6 +9,8 @@ import ( var parser = regexp.MustCompile(`^(.+)\sdev\s([^\s]+)\s(.+)$`) + + func update() ([]Route, error) { table = make([]Route, 0) @@ -17,7 +19,13 @@ func update() ([]Route, error) { if err != nil { return nil, err } - + if len(regexp.MustCompile(`(default)`).FindStringSubmatch(output))!=2 { + gwline, err := find_gateway_android7(inet) + if err != nil { + return nil, err + } + output = gwline + "\n" + output + } for _, line := range strings.Split(output, "\n") { if line = str.Trim(line); len(line) > 0 { matches := parser.FindStringSubmatch(line) @@ -34,12 +42,21 @@ func update() ([]Route, error) { route.Gateway = route.Destination[idx + len(" via "):] route.Destination = route.Destination[:idx] } - table = append(table, route) } } } } - return table, nil } + +func find_gateway_android7(inet string) (string, error) { + output, err := core.Exec("ip", []string{"-f", inet, "route", "get", "8.8.8.8"}) + if err != nil { + return "", err + } + parser3 := regexp.MustCompile(`8.8.8.8`) + first_line := strings.Split(output, "\n")[0] + replaced := parser3.ReplaceAllString(first_line, "default") + return replaced, nil +}