Merge pull request #403 from mdlayher/digitalocean_anchor_gateway

network: do not assign gateway for DigitalOcean anchor IP address
This commit is contained in:
Alex Crawford 2015-10-27 09:10:34 -07:00
commit cd1994b007
2 changed files with 4 additions and 23 deletions

View File

@ -127,7 +127,7 @@ func parseInterface(iface digitalocean.Interface, nameservers []net.IP, useRoute
} }
} }
if iface.AnchorIPv4 != nil { if iface.AnchorIPv4 != nil {
var ip, mask, gateway net.IP var ip, mask net.IP
if ip = net.ParseIP(iface.AnchorIPv4.IPAddress); ip == nil { if ip = net.ParseIP(iface.AnchorIPv4.IPAddress); ip == nil {
return nil, fmt.Errorf("could not parse %q as anchor IPv4 address", iface.AnchorIPv4.IPAddress) return nil, fmt.Errorf("could not parse %q as anchor IPv4 address", iface.AnchorIPv4.IPAddress)
} }
@ -140,15 +140,11 @@ func parseInterface(iface digitalocean.Interface, nameservers []net.IP, useRoute
}) })
if useRoute { if useRoute {
if gateway = net.ParseIP(iface.AnchorIPv4.Gateway); gateway == nil {
return nil, fmt.Errorf("could not parse %q as anchor IPv4 gateway", iface.AnchorIPv4.Gateway)
}
routes = append(routes, route{ routes = append(routes, route{
destination: net.IPNet{ destination: net.IPNet{
IP: net.IPv4zero, IP: net.IPv4zero,
Mask: net.IPMask(net.IPv4zero), Mask: net.IPMask(net.IPv4zero),
}, },
gateway: gateway,
}) })
} }
} }

View File

@ -281,19 +281,6 @@ func TestParseInterface(t *testing.T) {
nss: []net.IP{}, nss: []net.IP{},
err: errors.New("could not parse \"bad\" as anchor IPv4 mask"), err: errors.New("could not parse \"bad\" as anchor IPv4 mask"),
}, },
{
cfg: digitalocean.Interface{
MAC: "01:23:45:67:89:AB",
AnchorIPv4: &digitalocean.Address{
IPAddress: "1.2.3.4",
Netmask: "255.255.0.0",
Gateway: "bad",
},
},
useRoute: true,
nss: []net.IP{},
err: errors.New("could not parse \"bad\" as anchor IPv4 gateway"),
},
{ {
cfg: digitalocean.Interface{ cfg: digitalocean.Interface{
MAC: "01:23:45:67:89:AB", MAC: "01:23:45:67:89:AB",
@ -305,7 +292,6 @@ func TestParseInterface(t *testing.T) {
AnchorIPv4: &digitalocean.Address{ AnchorIPv4: &digitalocean.Address{
IPAddress: "7.8.9.10", IPAddress: "7.8.9.10",
Netmask: "255.255.0.0", Netmask: "255.255.0.0",
Gateway: "11.12.13.14",
}, },
}, },
useRoute: true, useRoute: true,
@ -326,12 +312,11 @@ func TestParseInterface(t *testing.T) {
nameservers: []net.IP{}, nameservers: []net.IP{},
routes: []route{ routes: []route{
{ {
net.IPNet{IP: net.IPv4zero, Mask: net.IPMask(net.IPv4zero)}, destination: net.IPNet{IP: net.IPv4zero, Mask: net.IPMask(net.IPv4zero)},
net.ParseIP("5.6.7.8"), gateway: net.ParseIP("5.6.7.8"),
}, },
{ {
net.IPNet{IP: net.IPv4zero, Mask: net.IPMask(net.IPv4zero)}, destination: net.IPNet{IP: net.IPv4zero, Mask: net.IPMask(net.IPv4zero)},
net.ParseIP("11.12.13.14"),
}, },
}, },
}, },