From cd45f2b55c1338595050bf8c656193651fc00005 Mon Sep 17 00:00:00 2001 From: Julia Evans Date: Thu, 31 Aug 2017 14:16:49 -0700 Subject: [PATCH 1/2] Set link index correctly on netlink messages --- backend/hostgw/hostgw_network.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/hostgw/hostgw_network.go b/backend/hostgw/hostgw_network.go index 09ad0f1012..98243847c9 100644 --- a/backend/hostgw/hostgw_network.go +++ b/backend/hostgw/hostgw_network.go @@ -29,12 +29,11 @@ import ( ) type network struct { - name string - extIface *backend.ExternalInterface - linkIndex int - rl []netlink.Route - lease *subnet.Lease - sm subnet.Manager + name string + extIface *backend.ExternalInterface + rl []netlink.Route + lease *subnet.Lease + sm subnet.Manager } func (n *network) Lease() *subnet.Lease { @@ -45,6 +44,10 @@ func (n *network) MTU() int { return n.extIface.Iface.MTU } +func (n *network) LinkIndex() int { + return n.extIface.Iface.Index +} + func (n *network) Run(ctx context.Context) { wg := sync.WaitGroup{} @@ -90,7 +93,7 @@ func (n *network) handleSubnetEvents(batch []subnet.Event) { route := netlink.Route{ Dst: evt.Lease.Subnet.ToIPNet(), Gw: evt.Lease.Attrs.PublicIP.ToIP(), - LinkIndex: n.linkIndex, + LinkIndex: n.LinkIndex(), } // Check if route exists before attempting to add it @@ -129,7 +132,7 @@ func (n *network) handleSubnetEvents(batch []subnet.Event) { route := netlink.Route{ Dst: evt.Lease.Subnet.ToIPNet(), Gw: evt.Lease.Attrs.PublicIP.ToIP(), - LinkIndex: n.linkIndex, + LinkIndex: n.LinkIndex(), } if err := netlink.RouteDel(&route); err != nil { log.Errorf("Error deleting route to %v: %v", evt.Lease.Subnet, err) From aa7ae2bee3bce3bebc7c791c7ff23660202e8b23 Mon Sep 17 00:00:00 2001 From: Julia Evans Date: Thu, 31 Aug 2017 14:17:22 -0700 Subject: [PATCH 2/2] Pass old route instead of new route to RouteDel --- backend/hostgw/hostgw_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/hostgw/hostgw_network.go b/backend/hostgw/hostgw_network.go index 98243847c9..335e3ddc76 100644 --- a/backend/hostgw/hostgw_network.go +++ b/backend/hostgw/hostgw_network.go @@ -107,7 +107,7 @@ func (n *network) handleSubnetEvents(batch []subnet.Event) { if len(routeList) > 0 && !routeList[0].Gw.Equal(route.Gw) { // Same Dst different Gw. Remove it, correct route will be added below. log.Warningf("Replacing existing route to %v via %v with %v via %v.", evt.Lease.Subnet, routeList[0].Gw, evt.Lease.Subnet, evt.Lease.Attrs.PublicIP) - if err := netlink.RouteDel(&route); err != nil { + if err := netlink.RouteDel(&routeList[0]); err != nil { log.Errorf("Error deleting route to %v: %v", evt.Lease.Subnet, err) continue }