Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix route deletion when replacing route in hostgw backend #803

Merged
merged 2 commits into from
Sep 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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