Skip to content

Commit

Permalink
Fix delete default with no explicit dst
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmcguire committed Apr 21, 2023
1 parent 8c562ce commit 9c2af7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gateway-mon
Git LFS file not shown
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,21 @@ func delIfDefault(r *netlink.Route) {
// Checks if route is default
func isDefault(r *netlink.Route) bool {
var isDefault bool
if r.Src == nil && r.Dst == nil && r.Gw.IsPrivate() {
if r.Src == nil && r.Dst == nil && (r.Gw.IsPrivate() || r.Gw == nil) {
isDefault = true
} else {
log.Debugf("%+v is not default route", r)
}
return isDefault
}

// Deletes a route
func delRoute(r *netlink.Route) {
// Can't delete a route with no dest net, so explicitly set to all if nil
if isDefault(r) && r.Dst == nil {
_, defaultDest, _ := net.ParseCIDR("0.0.0.0/0")
r.Dst = defaultDest
}
err := netlink.RouteDel(r)
if err != nil {
log.Errorf("Failed to delete route on %s: %+v", linkName, err)
Expand Down

0 comments on commit 9c2af7b

Please sign in to comment.