Add scope parameter to route

This commit is contained in:
Vishvananda Ishaya 2014-09-14 17:44:56 -07:00
parent 0e7e6d493a
commit 950b852cad
2 changed files with 15 additions and 1 deletions

View File

@ -3,6 +3,18 @@ package netlink
import (
"fmt"
"net"
"syscall"
)
// Scope is an enum representing a route scope.
type Scope uint8
const (
SCOPE_UNIVERSE Scope = syscall.RT_SCOPE_UNIVERSE
SCOPE_SITE Scope = syscall.RT_SCOPE_SITE
SCOPE_LINK Scope = syscall.RT_SCOPE_LINK
SCOPE_HOST Scope = syscall.RT_SCOPE_HOST
SCOPE_NOWHERE Scope = syscall.RT_SCOPE_NOWHERE
)
// Route represents a netlink route. A route is associated with a link,
@ -11,6 +23,7 @@ import (
// currently not supported.
type Route struct {
Link *Link
Scope Scope
Dst *net.IPNet
Src net.IP
Gw net.IP

View File

@ -56,6 +56,7 @@ func routeHandle(route *Route, req *NetlinkRequest) error {
}
msg := newRtMsg()
msg.Scope = uint8(route.Scope)
family := -1
var rtAttrs []*RtAttr
@ -156,7 +157,7 @@ func RouteList(link *Link, family int) ([]Route, error) {
return nil, err
}
var route Route
route := Route{Scope: Scope(msg.Scope)}
for _, attr := range attrs {
switch attr.Attr.Type {
case syscall.RTA_GATEWAY: