From 2a6feccc042d710847074c74c2b75de51d055abf Mon Sep 17 00:00:00 2001 From: Hasan Mahmood Date: Mon, 8 Mar 2021 12:14:18 -0600 Subject: [PATCH] Add route get iif option --- route_linux.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/route_linux.go b/route_linux.go index 7e68fe20..a0d70d18 100644 --- a/route_linux.go +++ b/route_linux.go @@ -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 } @@ -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 {