Handle missing routing tables (#865)

The behavior of iproute2 changed in 5.0 as described in #750: now if a
table has not been created, `ip route list table <table>` will produce a
non-zero exit code.

It's not really needed to check tables via `list` anyway, since they
will be created by iproute2 when needed on first use. So relax error
handling for `ip route list table`, and remove it completely when a
table might be missing.

This fixes #750
This commit is contained in:
Vilmos Nebehaj 2020-04-23 12:13:08 -07:00 committed by GitHub
parent f5db29e36d
commit ffad3388a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1808,11 +1808,7 @@ func (ln *linuxNetworking) setupPolicyRoutingForDSR() error {
} }
} }
out, err := exec.Command("ip", "route", "list", "table", customDSRRouteTableID).Output() out, err := exec.Command("ip", "route", "list", "table", customDSRRouteTableID).Output()
if err != nil { if err != nil || !strings.Contains(string(out), " lo ") {
return errors.New("Failed to verify required default route exists. " +
"Failed to setup policy routing required for DSR due to " + err.Error())
}
if !strings.Contains(string(out), " lo ") {
if err = exec.Command("ip", "route", "add", "local", "default", "dev", "lo", "table", if err = exec.Command("ip", "route", "add", "local", "default", "dev", "lo", "table",
customDSRRouteTableID).Run(); err != nil { customDSRRouteTableID).Run(); err != nil {
return errors.New("Failed to add route in custom route table due to: " + err.Error()) return errors.New("Failed to add route in custom route table due to: " + err.Error())
@ -1843,12 +1839,6 @@ func (ln *linuxNetworking) setupRoutesForExternalIPForDSR(serviceInfoMap service
} }
} }
_, err = exec.Command("ip", "route", "list", "table", externalIPRouteTableId).Output()
if err != nil {
return errors.New("Failed to verify required routing table for external IP's exists. " +
"Failed to setup policy routing required for DSR due to " + err.Error())
}
out, err := exec.Command("ip", "rule", "list").Output() out, err := exec.Command("ip", "rule", "list").Output()
if err != nil { if err != nil {
return errors.New("Failed to verify if `ip rule add prio 32765 from all lookup external_ip` exists due to: " + err.Error()) return errors.New("Failed to verify if `ip rule add prio 32765 from all lookup external_ip` exists due to: " + err.Error())
@ -1862,10 +1852,7 @@ func (ln *linuxNetworking) setupRoutesForExternalIPForDSR(serviceInfoMap service
} }
} }
out, err = exec.Command("ip", "route", "list", "table", externalIPRouteTableId).Output() out, _ = exec.Command("ip", "route", "list", "table", externalIPRouteTableId).Output()
if err != nil {
return errors.New("Failed to get routes in external_ip table due to: " + err.Error())
}
outStr := string(out) outStr := string(out)
activeExternalIPs := make(map[string]bool) activeExternalIPs := make(map[string]bool)
for _, svc := range serviceInfoMap { for _, svc := range serviceInfoMap {