Skip to content

Commit

Permalink
Merge pull request #803 from julia-stripe/set-link-index
Browse files Browse the repository at this point in the history
Fix route deletion when replacing route in hostgw backend
  • Loading branch information
tomdee authored Sep 6, 2017
2 parents 17d8cfb + aa7ae2b commit e1b22bc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions backend/hostgw/hostgw_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}

Expand Down Expand Up @@ -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
Expand All @@ -104,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
}
Expand All @@ -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)
Expand Down

0 comments on commit e1b22bc

Please sign in to comment.