Skip to content

Commit

Permalink
Patch to allow for 'ip route add table XXX unreachable default metric…
Browse files Browse the repository at this point in the history
… XXX' type constructions
  • Loading branch information
lasselj committed Mar 30, 2022
1 parent facc790 commit 71f1c79
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,9 @@ func (h *Handle) routeHandle(route *Route, req *nl.NetlinkRequest, msg *nl.RtMsg
} else {
dstData = route.Dst.IP.To16()
}
rtAttrs = append(rtAttrs, nl.NewRtAttr(unix.RTA_DST, dstData))
if route.Type != unix.RTN_UNREACHABLE && route.Type != unix.RTN_BLACKHOLE && route.Type != unix.RTN_PROHIBIT {
rtAttrs = append(rtAttrs, nl.NewRtAttr(unix.RTA_DST, dstData))
}
} else if route.MPLSDst != nil {
family = nl.FAMILY_MPLS
msg.Dst_len = uint8(20)
Expand Down Expand Up @@ -991,10 +993,11 @@ func (h *Handle) routeHandle(route *Route, req *nl.NetlinkRequest, msg *nl.RtMsg
req.AddData(attr)
}

b := make([]byte, 4)
native.PutUint32(b, uint32(route.LinkIndex))

req.AddData(nl.NewRtAttr(unix.RTA_OIF, b))
if route.LinkIndex != 0 {
b := make([]byte, 4)
native.PutUint32(b, uint32(route.LinkIndex))
req.AddData(nl.NewRtAttr(unix.RTA_OIF, b))
}

_, err := req.Execute(unix.NETLINK_ROUTE, 0)
return err
Expand Down

0 comments on commit 71f1c79

Please sign in to comment.