Skip to content

Commit

Permalink
normalize Route.Gateway to IPv4 format, not ::ffff:...
Browse files Browse the repository at this point in the history
  • Loading branch information
Tero Marttila committed May 9, 2016
1 parent ed8e8d8 commit 44a132b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ func (route *Route) config(configRoute config.Route) error {
route.Gateway = nil
} else if ip := net.ParseIP(configRoute.Gateway); ip == nil {
return fmt.Errorf("Invalid Gateway: %s", configRoute.Gateway)
} else if ip4 := ip.To4(); ip4 != nil {
// normalize from v4-in-v6 form
route.Gateway = ip4
} else {
route.Gateway = ip

}

if configRoute.IPVSMethod == "" {
Expand Down
7 changes: 7 additions & 0 deletions route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
var testIpvsFwdMethodMasq = ipvs.FwdMethod(ipvs.IP_VS_CONN_F_MASQ)
var testIpvsFwdMethodDroute = ipvs.FwdMethod(ipvs.IP_VS_CONN_F_DROUTE)
var testRoutes = Routes{
"test2": Route{
Prefix: &net.IPNet{net.IP{10, 2, 0, 0}, net.IPMask{255, 255, 255, 0}},
Gateway: net.IP{10, 255, 0, 2},
IPVSMethod: &testIpvsFwdMethodMasq,
},

"test1": Route{
Prefix: &net.IPNet{net.IP{10, 1, 0, 0}, net.IPMask{255, 255, 255, 0}},
Gateway: nil,
Expand All @@ -25,6 +31,7 @@ var testRoutes = Routes{
// Test multiple NewConfig for Routes from multiple config sources
func TestConfigRoute(t *testing.T) {
routeConfig := map[string]config.Route{
"test2": config.Route{Prefix: "10.2.0.0/24", Gateway: "10.255.0.2", IPVSMethod: "masq"},
"test1": config.Route{Prefix: "10.1.0.0/24", IPVSMethod: "masq"},
"internal": config.Route{Prefix: "10.0.0.0/8", IPVSMethod: ""},
}
Expand Down

0 comments on commit 44a132b

Please sign in to comment.