Skip to content

Commit

Permalink
Add route get iif option
Browse files Browse the repository at this point in the history
  • Loading branch information
hmahmood committed Mar 29, 2021
1 parent 0a32cff commit 4573f73
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ func deserializeRoute(m []byte) (Route, error) {
// RouteGetOptions contains a set of options to use with
// RouteGetWithOptions
type RouteGetOptions struct {
Iif string
VrfName string
SrcAddr net.IP
}
Expand Down Expand Up @@ -1208,6 +1209,21 @@ func (h *Handle) RouteGetWithOptions(destination net.IP, options *RouteGetOption
req.AddData(nl.NewRtAttr(unix.RTA_OIF, b))
}

if len(options.Iif) > 0 {
link, err := LinkByName(options.Iif)
if err != nil {
return nil, err
}

var (
b = make([]byte, 4)
native = nl.NativeEndian()
)
native.PutUint32(b, uint32(link.Attrs().Index))

req.AddData(nl.NewRtAttr(unix.RTA_IIF, b))
}

if options.SrcAddr != nil {
var srcAddr []byte
if family == FAMILY_V4 {
Expand Down

0 comments on commit 4573f73

Please sign in to comment.