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 Apr 23, 2021
1 parent e838b0f commit 2a6fecc
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 @@ -1150,6 +1150,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 @@ -1207,6 +1208,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 2a6fecc

Please sign in to comment.