2015-05-07 00:09:12 +00:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Scope is an enum representing a route scope.
|
|
|
|
type Scope uint8
|
|
|
|
|
2015-12-07 15:46:14 -08:00
|
|
|
type NextHopFlag int
|
|
|
|
|
2016-01-08 13:56:01 -08:00
|
|
|
// Route represents a netlink route.
|
2015-05-07 00:09:12 +00:00
|
|
|
type Route struct {
|
2016-01-08 13:56:01 -08:00
|
|
|
LinkIndex int
|
|
|
|
ILinkIndex int
|
|
|
|
Scope Scope
|
|
|
|
Dst *net.IPNet
|
|
|
|
Src net.IP
|
|
|
|
Gw net.IP
|
2016-06-22 09:31:55 -07:00
|
|
|
MultiPath []*NexthopInfo
|
2016-01-08 13:56:01 -08:00
|
|
|
Protocol int
|
|
|
|
Priority int
|
|
|
|
Table int
|
|
|
|
Type int
|
|
|
|
Tos int
|
|
|
|
Flags int
|
2015-05-07 00:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r Route) String() string {
|
2016-06-22 09:31:55 -07:00
|
|
|
if len(r.MultiPath) > 0 {
|
|
|
|
return fmt.Sprintf("{Dst: %s Src: %s Gw: %s Flags: %s Table: %d}", r.Dst,
|
|
|
|
r.Src, r.MultiPath, r.ListFlags(), r.Table)
|
|
|
|
}
|
2016-06-07 14:28:28 -07:00
|
|
|
return fmt.Sprintf("{Ifindex: %d Dst: %s Src: %s Gw: %s Flags: %s Table: %d}", r.LinkIndex, r.Dst,
|
|
|
|
r.Src, r.Gw, r.ListFlags(), r.Table)
|
2015-12-07 15:46:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Route) SetFlag(flag NextHopFlag) {
|
|
|
|
r.Flags |= int(flag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Route) ClearFlag(flag NextHopFlag) {
|
|
|
|
r.Flags &^= int(flag)
|
|
|
|
}
|
|
|
|
|
|
|
|
type flagString struct {
|
|
|
|
f NextHopFlag
|
|
|
|
s string
|
|
|
|
}
|
|
|
|
|
|
|
|
// RouteUpdate is sent when a route changes - type is RTM_NEWROUTE or RTM_DELROUTE
|
|
|
|
type RouteUpdate struct {
|
|
|
|
Type uint16
|
|
|
|
Route
|
2015-05-07 00:09:12 +00:00
|
|
|
}
|
2016-06-22 09:31:55 -07:00
|
|
|
|
|
|
|
type NexthopInfo struct {
|
|
|
|
LinkIndex int
|
|
|
|
Hops int
|
|
|
|
Gw net.IP
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NexthopInfo) String() string {
|
|
|
|
return fmt.Sprintf("{Ifindex: %d Weight: %d, Gw: %s}", n.LinkIndex, n.Hops+1, n.Gw)
|
|
|
|
}
|