Skip to content

Commit

Permalink
fix: 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 17, 2021
1 parent df3326a commit f7b0a36
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 61 deletions.
93 changes: 45 additions & 48 deletions examples/localclient_linux/route/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main

import (
"context"
linux_l3 "go.ligato.io/vpp-agent/v3/proto/ligato/linux/l3"
linuxL3 "go.ligato.io/vpp-agent/v3/proto/ligato/linux/l3"
"log"
"sync"
"time"
Expand All @@ -28,12 +28,12 @@ import (

"go.ligato.io/vpp-agent/v3/clientv2/linux/localclient"
"go.ligato.io/vpp-agent/v3/cmd/vpp-agent/app"
linux_ifplugin "go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin"
linux_nsplugin "go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
linuxIf "go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin"
linuxNs "go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
"go.ligato.io/vpp-agent/v3/plugins/orchestrator"
vpp_ifplugin "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
linux_intf "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
vpp_intf "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
vppIf "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
linuxIntf "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
vppIntf "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
)

var (
Expand All @@ -45,9 +45,9 @@ var (
// Start Agent plugins selected for this example.
func main() {
// Set inter-dependency between VPP & Linux plugins
vpp_ifplugin.DefaultPlugin.LinuxIfPlugin = &linux_ifplugin.DefaultPlugin
vpp_ifplugin.DefaultPlugin.NsPlugin = &linux_nsplugin.DefaultPlugin
linux_ifplugin.DefaultPlugin.VppIfPlugin = &vpp_ifplugin.DefaultPlugin
vppIf.DefaultPlugin.LinuxIfPlugin = &linuxIf.DefaultPlugin
vppIf.DefaultPlugin.NsPlugin = &linuxNs.DefaultPlugin
linuxIf.DefaultPlugin.VppIfPlugin = &vppIf.DefaultPlugin

// Init close channel to stop the example.
exampleFinished := make(chan struct{})
Expand Down 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 @@ -222,124 +222,121 @@ func (p *RouteExamplePlugin) putModifiedData(ctx context.Context, timeout int) {

/* Example Data */

func tap() *vpp_intf.Interface {
return &vpp_intf.Interface{
func tap() *vppIntf.Interface {
return &vppIntf.Interface{
Name: "tap1",
Type: vpp_intf.Interface_TAP,
Type: vppIntf.Interface_TAP,
Enabled: true,
PhysAddress: "d5:bc:dc:12:e4:0e",
IpAddresses: []string{
"10.0.0.10/24",
},
Link: &vpp_intf.Interface_Tap{
Tap: &vpp_intf.TapLink{
Link: &vppIntf.Interface_Tap{
Tap: &vppIntf.TapLink{
Version: 2,
},
},
}
}

func tapIPv6() *vpp_intf.Interface {
return &vpp_intf.Interface{
func tapIPv6() *vppIntf.Interface {
return &vppIntf.Interface{
Name: "tap2",
Type: vpp_intf.Interface_TAP,
Type: vppIntf.Interface_TAP,
Enabled: true,
PhysAddress: "d5:bc:dc:12:e4:0d",
IpAddresses: []string{
"abc1::10/64",
},
Link: &vpp_intf.Interface_Tap{
Tap: &vpp_intf.TapLink{
Link: &vppIntf.Interface_Tap{
Tap: &vppIntf.TapLink{
Version: 2,
},
},
}
}

func linuxTap() *linux_intf.Interface {
return &linux_intf.Interface{
func linuxTap() *linuxIntf.Interface {
return &linuxIntf.Interface{
Name: "linux-tap1",
Type: linux_intf.Interface_TAP_TO_VPP,
Type: linuxIntf.Interface_TAP_TO_VPP,
Enabled: true,
PhysAddress: "12:e4:0e:d5:bc:dc",
IpAddresses: []string{
"11.0.0.20/24",
},
Link: &linux_intf.Interface_Tap{
Tap: &linux_intf.TapLink{
Link: &linuxIntf.Interface_Tap{
Tap: &linuxIntf.TapLink{
VppTapIfName: "tap1",
},
},
}
}

func linuxTapIpv6() *linux_intf.Interface {
return &linux_intf.Interface{
func linuxTapIpv6() *linuxIntf.Interface {
return &linuxIntf.Interface{
Name: "linux-tap2",
Type: linux_intf.Interface_TAP_TO_VPP,
Type: linuxIntf.Interface_TAP_TO_VPP,
Enabled: true,
PhysAddress: "44:bc:12:e4:0e:aa",
IpAddresses: []string{
"abc2::20/64",
},
Link: &linux_intf.Interface_Tap{
Tap: &linux_intf.TapLink{
Link: &linuxIntf.Interface_Tap{
Tap: &linuxIntf.TapLink{
VppTapIfName: "tap2",
},
},
}
}

func route() *linux_l3.Route {
return &linux_l3.Route{
func route() *linuxL3.Route {
return &linuxL3.Route{
OutgoingInterface: "linux-tap1",
DstNetwork: "100.10.0.0/24",
Scope: linux_l3.Route_GLOBAL,
Scope: linuxL3.Route_GLOBAL,
Metric: 0,
}
}

func routeResync() *linux_l3.Route {
return &linux_l3.Route{
func routeResync() *linuxL3.Route {
return &linuxL3.Route{
OutgoingInterface: "linux-tap1",
DstNetwork: "100.10.0.0/24",
Scope: linux_l3.Route_GLOBAL,
Scope: linuxL3.Route_GLOBAL,
Metric: 500,
}
}

func routeModified() *linux_l3.Route {
return &linux_l3.Route{
func routeModified() *linuxL3.Route {
return &linuxL3.Route{
OutgoingInterface: "linux-tap1",
DstNetwork: "100.10.0.0/24",
Scope: linux_l3.Route_LINK,
Scope: linuxL3.Route_LINK,
Metric: 500,
}
}

func routeIPv6() *linux_l3.Route {
return &linux_l3.Route{
func routeIPv6() *linuxL3.Route {
return &linuxL3.Route{
OutgoingInterface: "linux-tap2",
DstNetwork: "aaa1::/64",
Scope: linux_l3.Route_GLOBAL,
Metric: 0,
}
}

func routeResyncIPv6() *linux_l3.Route {
return &linux_l3.Route{
func routeResyncIPv6() *linuxL3.Route {
return &linuxL3.Route{
OutgoingInterface: "linux-tap2",
DstNetwork: "aaa1::/64",
Scope: linux_l3.Route_LINK,
Metric: 1024,
}
}

func routeModifiedIPv6() *linux_l3.Route {
return &linux_l3.Route{
func routeModifiedIPv6() *linuxL3.Route {
return &linuxL3.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 f7b0a36

Please sign in to comment.