mirror of https://github.com/vishvananda/netlink
Add Flags in NexthopInfo
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
This commit is contained in:
parent
c19091b1c6
commit
87909c6dad
3
route.go
3
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())
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue