Merge pull request #104 from mzahorik/master

Append default route and process route options in compliance with RFC 3442
This commit is contained in:
Casey Callendrello 2018-01-31 15:08:57 +01:00 committed by GitHub
commit 9e5836047c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -292,8 +292,26 @@ func (l *DHCPLease) Gateway() net.IP {
}
func (l *DHCPLease) Routes() []*types.Route {
routes := parseRoutes(l.opts)
return append(routes, parseCIDRRoutes(l.opts)...)
routes := []*types.Route{}
// RFC 3442 states that if Classless Static Routes (option 121)
// exist, we ignore Static Routes (option 33) and the Router/Gateway.
opt121_routes := parseCIDRRoutes(l.opts)
if len(opt121_routes) > 0 {
return append(routes, opt121_routes...)
}
// Append Static Routes
routes = append(routes, parseRoutes(l.opts)...)
// The CNI spec says even if there is a gateway specified, we must
// add a default route in the routes section.
if gw := l.Gateway(); gw != nil {
_, defaultRoute, _ := net.ParseCIDR("0.0.0.0/0")
routes = append(routes, &types.Route{Dst: *defaultRoute, GW: gw})
}
return routes
}
// jitter returns a random value within [-span, span) range