Skip to content

Commit

Permalink
Make route scope relevant for IPv4 only
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
  • Loading branch information
VladoLavor committed Dec 15, 2021
1 parent df3326a commit 2578712
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
5 changes: 1 addition & 4 deletions examples/localclient_linux/route/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (p *RouteExamplePlugin) resync(ctx context.Context, timeout int) {
LinuxInterface(linuxTap()).
LinuxInterface(linuxTapIpv6()).
LinuxRoute(routeResync()). // recreate
LinuxRoute(routeResyncIPv6()). // update
LinuxRoute(routeResyncIPv6()). // no action
Send().ReceiveReply()
if err != nil {
p.Log.Errorf("Resync failed: %v", err)
Expand Down Expand Up @@ -321,7 +321,6 @@ func routeIPv6() *linux_l3.Route {
return &linux_l3.Route{
OutgoingInterface: "linux-tap2",
DstNetwork: "aaa1::/64",
Scope: linux_l3.Route_GLOBAL,
Metric: 0,
}
}
Expand All @@ -330,7 +329,6 @@ func routeResyncIPv6() *linux_l3.Route {
return &linux_l3.Route{
OutgoingInterface: "linux-tap2",
DstNetwork: "aaa1::/64",
Scope: linux_l3.Route_LINK,
Metric: 1024,
}
}
Expand All @@ -339,7 +337,6 @@ func routeModifiedIPv6() *linux_l3.Route {
return &linux_l3.Route{
OutgoingInterface: "linux-tap2",
DstNetwork: "aaa1::/64",
Scope: linux_l3.Route_LINK,
Metric: 500,
}
}
37 changes: 24 additions & 13 deletions plugins/linux/l3plugin/descriptor/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ func NewRouteDescriptor(
// EquivalentRoutes is case-insensitive comparison function for l3.LinuxRoute.
func (d *RouteDescriptor) EquivalentRoutes(key string, oldRoute, newRoute *linux_l3.Route) bool {
// attributes compared as usually:
if oldRoute.OutgoingInterface != newRoute.OutgoingInterface ||
oldRoute.Scope != newRoute.Scope {
if oldRoute.OutgoingInterface != newRoute.OutgoingInterface {
return false
}
// compare scopes for IPv4 routes
if ip := net.ParseIP(newRoute.DstNetwork); ip != nil && ip.To4() != nil {
if oldRoute.Scope != newRoute.Scope {
return false
}
}
// compare metrics
if !isRouteMetricEqual(oldRoute, newRoute) {
return false
Expand Down Expand Up @@ -230,13 +235,15 @@ func (d *RouteDescriptor) updateRoute(route *linux_l3.Route, actionName string,
netlinkRoute.Gw = gwAddr.IP
}

// set route scope
scope, err := rtScopeFromNBToNetlink(route.Scope)
if err != nil {
d.log.Error(err)
return err
// set route scope for IPv4
if ip := net.ParseIP(route.DstNetwork); ip != nil && ip.To4() != nil {
scope, err := rtScopeFromNBToNetlink(route.Scope)
if err != nil {
d.log.Error(err)
return err
}
netlinkRoute.Scope = scope
}
netlinkRoute.Scope = scope

// set route metric
netlinkRoute.Priority = int(route.Metric)
Expand Down Expand Up @@ -397,11 +404,15 @@ func (d *RouteDescriptor) Retrieve(correlate []adapter.RouteKVWithMetadata) ([]a

// correlate with the expected configuration
for _, routeDetails := range routeDetails {
// Convert to key-value object with metadata
scope, err := rtScopeFromNetlinkToNB(routeDetails.Meta.NetlinkScope)
if err != nil {
// route not configured by the agent
continue
// convert to key-value object with metadata
// resolve scope for IPv6. Note that IPv6 route scope always returns zero value.
var scope linux_l3.Route_Scope
if ip := net.ParseIP(routeDetails.Route.DstNetwork); ip != nil && ip.To4() != nil {
scope, err = rtScopeFromNetlinkToNB(routeDetails.Meta.NetlinkScope)
if err != nil {
// route not configured by the agent
continue
}
}
route := adapter.RouteKVWithMetadata{
Key: linux_l3.RouteKey(routeDetails.Route.DstNetwork, routeDetails.Route.OutgoingInterface),
Expand Down

0 comments on commit 2578712

Please sign in to comment.