From 87909c6dada5cba3aa659144a40b1e575d79d625 Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Mon, 22 Aug 2016 02:40:27 +0000 Subject: [PATCH] Add Flags in NexthopInfo Signed-off-by: Wataru Ishida --- route.go | 3 ++- route_linux.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/route.go b/route.go index 61cf5ec..335d703 100644 --- a/route.go +++ b/route.go @@ -59,8 +59,9 @@ type NexthopInfo struct { LinkIndex int Hops int Gw net.IP + Flags int } func (n *NexthopInfo) String() string { - return fmt.Sprintf("{Ifindex: %d Weight: %d, Gw: %s}", n.LinkIndex, n.Hops+1, n.Gw) + return fmt.Sprintf("{Ifindex: %d Weight: %d Gw: %s Flags: %s}", n.LinkIndex, n.Hops+1, n.Gw, n.ListFlags()) } diff --git a/route_linux.go b/route_linux.go index d049838..c9b1fec 100644 --- a/route_linux.go +++ b/route_linux.go @@ -42,16 +42,24 @@ var testFlags = []flagString{ {f: FLAG_PERVASIVE, s: "pervasive"}, } -func (r *Route) ListFlags() []string { +func listFlags(flag int) []string { var flags []string for _, tf := range testFlags { - if r.Flags&int(tf.f) != 0 { + if flag&int(tf.f) != 0 { flags = append(flags, tf.s) } } return flags } +func (r *Route) ListFlags() []string { + return listFlags(r.Flags) +} + +func (n *NexthopInfo) ListFlags() []string { + return listFlags(n.Flags) +} + // RouteAdd will add a route to the system. // Equivalent to: `ip route add $route` func RouteAdd(route *Route) error { @@ -154,6 +162,7 @@ func (h *Handle) routeHandle(route *Route, req *nl.NetlinkRequest, msg *nl.RtMsg Hops: uint8(nh.Hops), Ifindex: int32(nh.LinkIndex), Len: uint16(syscall.SizeofRtNexthop), + Flags: uint8(nh.Flags), }, } var gwData []byte @@ -368,6 +377,7 @@ func deserializeRoute(m []byte) (Route, error) { info := &NexthopInfo{ LinkIndex: int(nh.RtNexthop.Ifindex), Hops: int(nh.RtNexthop.Hops), + Flags: int(nh.RtNexthop.Flags), } attrs, err := nl.ParseRouteAttr(value[syscall.SizeofRtNexthop:int(nh.RtNexthop.Len)]) if err != nil {