mirror of
https://github.com/vishvananda/netlink
synced 2025-04-04 23:39:43 +00:00
Adds strings translation methods
RTPROT_KEEPALIVED is commented to interop with earlier go versions (1.13, 1.14)
This commit is contained in:
parent
9de6d08565
commit
ec93726159
99
link.go
99
link.go
@ -555,6 +555,27 @@ const (
|
|||||||
BOND_ARP_VALIDATE_ALL
|
BOND_ARP_VALIDATE_ALL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bondArpValidateToString = map[BondArpValidate]string{
|
||||||
|
BOND_ARP_VALIDATE_NONE: "none",
|
||||||
|
BOND_ARP_VALIDATE_ACTIVE: "active",
|
||||||
|
BOND_ARP_VALIDATE_BACKUP: "backup",
|
||||||
|
BOND_ARP_VALIDATE_ALL: "none",
|
||||||
|
}
|
||||||
|
var StringToBondArpValidateMap = map[string]BondArpValidate{
|
||||||
|
"none": BOND_ARP_VALIDATE_NONE,
|
||||||
|
"active": BOND_ARP_VALIDATE_ACTIVE,
|
||||||
|
"backup": BOND_ARP_VALIDATE_BACKUP,
|
||||||
|
"all": BOND_ARP_VALIDATE_ALL,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BondArpValidate) String() string {
|
||||||
|
s, ok := bondArpValidateToString[b]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf("BondArpValidate(%d)", b)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// BondPrimaryReselect type
|
// BondPrimaryReselect type
|
||||||
type BondPrimaryReselect int
|
type BondPrimaryReselect int
|
||||||
|
|
||||||
@ -565,6 +586,25 @@ const (
|
|||||||
BOND_PRIMARY_RESELECT_FAILURE
|
BOND_PRIMARY_RESELECT_FAILURE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bondPrimaryReselectToString = map[BondPrimaryReselect]string{
|
||||||
|
BOND_PRIMARY_RESELECT_ALWAYS: "always",
|
||||||
|
BOND_PRIMARY_RESELECT_BETTER: "better",
|
||||||
|
BOND_PRIMARY_RESELECT_FAILURE: "failure",
|
||||||
|
}
|
||||||
|
var StringToBondPrimaryReselectMap = map[string]BondPrimaryReselect{
|
||||||
|
"always": BOND_PRIMARY_RESELECT_ALWAYS,
|
||||||
|
"better": BOND_PRIMARY_RESELECT_BETTER,
|
||||||
|
"failure": BOND_PRIMARY_RESELECT_FAILURE,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BondPrimaryReselect) String() string {
|
||||||
|
s, ok := bondPrimaryReselectToString[b]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf("BondPrimaryReselect(%d)", b)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// BondArpAllTargets type
|
// BondArpAllTargets type
|
||||||
type BondArpAllTargets int
|
type BondArpAllTargets int
|
||||||
|
|
||||||
@ -574,6 +614,23 @@ const (
|
|||||||
BOND_ARP_ALL_TARGETS_ALL
|
BOND_ARP_ALL_TARGETS_ALL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bondArpAllTargetsToString = map[BondArpAllTargets]string{
|
||||||
|
BOND_ARP_ALL_TARGETS_ANY: "any",
|
||||||
|
BOND_ARP_ALL_TARGETS_ALL: "all",
|
||||||
|
}
|
||||||
|
var StringToBondArpAllTargetsMap = map[string]BondArpAllTargets{
|
||||||
|
"any": BOND_ARP_ALL_TARGETS_ANY,
|
||||||
|
"all": BOND_ARP_ALL_TARGETS_ALL,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BondArpAllTargets) String() string {
|
||||||
|
s, ok := bondArpAllTargetsToString[b]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf("BondArpAllTargets(%d)", b)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// BondFailOverMac type
|
// BondFailOverMac type
|
||||||
type BondFailOverMac int
|
type BondFailOverMac int
|
||||||
|
|
||||||
@ -584,6 +641,25 @@ const (
|
|||||||
BOND_FAIL_OVER_MAC_FOLLOW
|
BOND_FAIL_OVER_MAC_FOLLOW
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bondFailOverMacToString = map[BondFailOverMac]string{
|
||||||
|
BOND_FAIL_OVER_MAC_NONE: "none",
|
||||||
|
BOND_FAIL_OVER_MAC_ACTIVE: "active",
|
||||||
|
BOND_FAIL_OVER_MAC_FOLLOW: "follow",
|
||||||
|
}
|
||||||
|
var StringToBondFailOverMacMap = map[string]BondFailOverMac{
|
||||||
|
"none": BOND_FAIL_OVER_MAC_NONE,
|
||||||
|
"active": BOND_FAIL_OVER_MAC_ACTIVE,
|
||||||
|
"follow": BOND_FAIL_OVER_MAC_FOLLOW,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BondFailOverMac) String() string {
|
||||||
|
s, ok := bondFailOverMacToString[b]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf("BondFailOverMac(%d)", b)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// BondXmitHashPolicy type
|
// BondXmitHashPolicy type
|
||||||
type BondXmitHashPolicy int
|
type BondXmitHashPolicy int
|
||||||
|
|
||||||
@ -675,6 +751,25 @@ const (
|
|||||||
BOND_AD_SELECT_COUNT
|
BOND_AD_SELECT_COUNT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var bondAdSelectToString = map[BondAdSelect]string{
|
||||||
|
BOND_AD_SELECT_STABLE: "stable",
|
||||||
|
BOND_AD_SELECT_BANDWIDTH: "bandwidth",
|
||||||
|
BOND_AD_SELECT_COUNT: "count",
|
||||||
|
}
|
||||||
|
var StringToBondAdSelectMap = map[string]BondAdSelect{
|
||||||
|
"stable": BOND_AD_SELECT_STABLE,
|
||||||
|
"bandwidth": BOND_AD_SELECT_BANDWIDTH,
|
||||||
|
"count": BOND_AD_SELECT_COUNT,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b BondAdSelect) String() string {
|
||||||
|
s, ok := bondAdSelectToString[b]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf("BondAdSelect(%d)", b)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// BondAdInfo represents ad info for bond
|
// BondAdInfo represents ad info for bond
|
||||||
type BondAdInfo struct {
|
type BondAdInfo struct {
|
||||||
AggregatorId int
|
AggregatorId int
|
||||||
@ -706,7 +801,7 @@ type Bond struct {
|
|||||||
AllSlavesActive int
|
AllSlavesActive int
|
||||||
MinLinks int
|
MinLinks int
|
||||||
LpInterval int
|
LpInterval int
|
||||||
PackersPerSlave int
|
PacketsPerSlave int
|
||||||
LacpRate BondLacpRate
|
LacpRate BondLacpRate
|
||||||
AdSelect BondAdSelect
|
AdSelect BondAdSelect
|
||||||
// looking at iproute tool AdInfo can only be retrived. It can't be set.
|
// looking at iproute tool AdInfo can only be retrived. It can't be set.
|
||||||
@ -739,7 +834,7 @@ func NewLinkBond(atr LinkAttrs) *Bond {
|
|||||||
AllSlavesActive: -1,
|
AllSlavesActive: -1,
|
||||||
MinLinks: -1,
|
MinLinks: -1,
|
||||||
LpInterval: -1,
|
LpInterval: -1,
|
||||||
PackersPerSlave: -1,
|
PacketsPerSlave: -1,
|
||||||
LacpRate: -1,
|
LacpRate: -1,
|
||||||
AdSelect: -1,
|
AdSelect: -1,
|
||||||
AdActorSysPrio: -1,
|
AdActorSysPrio: -1,
|
||||||
|
@ -34,6 +34,21 @@ const (
|
|||||||
TUNTAP_MULTI_QUEUE_DEFAULTS TuntapFlag = TUNTAP_MULTI_QUEUE | TUNTAP_NO_PI
|
TUNTAP_MULTI_QUEUE_DEFAULTS TuntapFlag = TUNTAP_MULTI_QUEUE | TUNTAP_NO_PI
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var StringToTuntapModeMap = map[string]TuntapMode{
|
||||||
|
"tun": TUNTAP_MODE_TUN,
|
||||||
|
"tap": TUNTAP_MODE_TAP,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ttm TuntapMode) String() string {
|
||||||
|
switch ttm {
|
||||||
|
case TUNTAP_MODE_TUN:
|
||||||
|
return "tun"
|
||||||
|
case TUNTAP_MODE_TAP:
|
||||||
|
return "tap"
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VF_LINK_STATE_AUTO uint32 = 0
|
VF_LINK_STATE_AUTO uint32 = 0
|
||||||
VF_LINK_STATE_ENABLE uint32 = 1
|
VF_LINK_STATE_ENABLE uint32 = 1
|
||||||
@ -1046,8 +1061,8 @@ func addBondAttrs(bond *Bond, linkInfo *nl.RtAttr) {
|
|||||||
if bond.LpInterval >= 0 {
|
if bond.LpInterval >= 0 {
|
||||||
data.AddRtAttr(nl.IFLA_BOND_LP_INTERVAL, nl.Uint32Attr(uint32(bond.LpInterval)))
|
data.AddRtAttr(nl.IFLA_BOND_LP_INTERVAL, nl.Uint32Attr(uint32(bond.LpInterval)))
|
||||||
}
|
}
|
||||||
if bond.PackersPerSlave >= 0 {
|
if bond.PacketsPerSlave >= 0 {
|
||||||
data.AddRtAttr(nl.IFLA_BOND_PACKETS_PER_SLAVE, nl.Uint32Attr(uint32(bond.PackersPerSlave)))
|
data.AddRtAttr(nl.IFLA_BOND_PACKETS_PER_SLAVE, nl.Uint32Attr(uint32(bond.PacketsPerSlave)))
|
||||||
}
|
}
|
||||||
if bond.LacpRate >= 0 {
|
if bond.LacpRate >= 0 {
|
||||||
data.AddRtAttr(nl.IFLA_BOND_AD_LACP_RATE, nl.Uint8Attr(uint8(bond.LacpRate)))
|
data.AddRtAttr(nl.IFLA_BOND_AD_LACP_RATE, nl.Uint8Attr(uint8(bond.LacpRate)))
|
||||||
@ -2309,7 +2324,7 @@ func parseBondData(link Link, data []syscall.NetlinkRouteAttr) {
|
|||||||
case nl.IFLA_BOND_LP_INTERVAL:
|
case nl.IFLA_BOND_LP_INTERVAL:
|
||||||
bond.LpInterval = int(native.Uint32(data[i].Value[0:4]))
|
bond.LpInterval = int(native.Uint32(data[i].Value[0:4]))
|
||||||
case nl.IFLA_BOND_PACKETS_PER_SLAVE:
|
case nl.IFLA_BOND_PACKETS_PER_SLAVE:
|
||||||
bond.PackersPerSlave = int(native.Uint32(data[i].Value[0:4]))
|
bond.PacketsPerSlave = int(native.Uint32(data[i].Value[0:4]))
|
||||||
case nl.IFLA_BOND_AD_LACP_RATE:
|
case nl.IFLA_BOND_AD_LACP_RATE:
|
||||||
bond.LacpRate = BondLacpRate(data[i].Value[0])
|
bond.LacpRate = BondLacpRate(data[i].Value[0])
|
||||||
case nl.IFLA_BOND_AD_SELECT:
|
case nl.IFLA_BOND_AD_SELECT:
|
||||||
|
76
route.go
76
route.go
@ -3,12 +3,32 @@ package netlink
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Scope is an enum representing a route scope.
|
// Scope is an enum representing a route scope.
|
||||||
type Scope uint8
|
type Scope uint8
|
||||||
|
|
||||||
|
func (s Scope) String() string {
|
||||||
|
switch s {
|
||||||
|
case SCOPE_UNIVERSE:
|
||||||
|
return "universe"
|
||||||
|
case SCOPE_SITE:
|
||||||
|
return "site"
|
||||||
|
case SCOPE_LINK:
|
||||||
|
return "link"
|
||||||
|
case SCOPE_HOST:
|
||||||
|
return "host"
|
||||||
|
case SCOPE_NOWHERE:
|
||||||
|
return "nowhere"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type NextHopFlag int
|
type NextHopFlag int
|
||||||
|
|
||||||
type Destination interface {
|
type Destination interface {
|
||||||
@ -27,6 +47,60 @@ type Encap interface {
|
|||||||
Equal(Encap) bool
|
Equal(Encap) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Protocol describe what was the originator of the route
|
||||||
|
type RouteProtocol int
|
||||||
|
|
||||||
|
func (p RouteProtocol) String() string {
|
||||||
|
switch int(p) {
|
||||||
|
case unix.RTPROT_BABEL:
|
||||||
|
return "babel"
|
||||||
|
case unix.RTPROT_BGP:
|
||||||
|
return "bgp"
|
||||||
|
case unix.RTPROT_BIRD:
|
||||||
|
return "bird"
|
||||||
|
case unix.RTPROT_BOOT:
|
||||||
|
return "boot"
|
||||||
|
case unix.RTPROT_DHCP:
|
||||||
|
return "dhcp"
|
||||||
|
case unix.RTPROT_DNROUTED:
|
||||||
|
return "dnrouted"
|
||||||
|
case unix.RTPROT_EIGRP:
|
||||||
|
return "eigrp"
|
||||||
|
case unix.RTPROT_GATED:
|
||||||
|
return "gated"
|
||||||
|
case unix.RTPROT_ISIS:
|
||||||
|
return "isis"
|
||||||
|
//case unix.RTPROT_KEEPALIVED:
|
||||||
|
// return "keepalived"
|
||||||
|
case unix.RTPROT_KERNEL:
|
||||||
|
return "kernel"
|
||||||
|
case unix.RTPROT_MROUTED:
|
||||||
|
return "mrouted"
|
||||||
|
case unix.RTPROT_MRT:
|
||||||
|
return "mrt"
|
||||||
|
case unix.RTPROT_NTK:
|
||||||
|
return "ntk"
|
||||||
|
case unix.RTPROT_OSPF:
|
||||||
|
return "ospf"
|
||||||
|
case unix.RTPROT_RA:
|
||||||
|
return "ra"
|
||||||
|
case unix.RTPROT_REDIRECT:
|
||||||
|
return "redirect"
|
||||||
|
case unix.RTPROT_RIP:
|
||||||
|
return "rip"
|
||||||
|
case unix.RTPROT_STATIC:
|
||||||
|
return "static"
|
||||||
|
case unix.RTPROT_UNSPEC:
|
||||||
|
return "unspec"
|
||||||
|
case unix.RTPROT_XORP:
|
||||||
|
return "xorp"
|
||||||
|
case unix.RTPROT_ZEBRA:
|
||||||
|
return "zebra"
|
||||||
|
default:
|
||||||
|
return strconv.Itoa(int(p))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Route represents a netlink route.
|
// Route represents a netlink route.
|
||||||
type Route struct {
|
type Route struct {
|
||||||
LinkIndex int
|
LinkIndex int
|
||||||
@ -36,7 +110,7 @@ type Route struct {
|
|||||||
Src net.IP
|
Src net.IP
|
||||||
Gw net.IP
|
Gw net.IP
|
||||||
MultiPath []*NexthopInfo
|
MultiPath []*NexthopInfo
|
||||||
Protocol int
|
Protocol RouteProtocol
|
||||||
Priority int
|
Priority int
|
||||||
Table int
|
Table int
|
||||||
Type int
|
Type int
|
||||||
|
@ -907,7 +907,7 @@ func deserializeRoute(m []byte) (Route, error) {
|
|||||||
}
|
}
|
||||||
route := Route{
|
route := Route{
|
||||||
Scope: Scope(msg.Scope),
|
Scope: Scope(msg.Scope),
|
||||||
Protocol: int(msg.Protocol),
|
Protocol: RouteProtocol(int(msg.Protocol)),
|
||||||
Table: int(msg.Table),
|
Table: int(msg.Table),
|
||||||
Type: int(msg.Type),
|
Type: int(msg.Type),
|
||||||
Tos: int(msg.Tos),
|
Tos: int(msg.Tos),
|
||||||
|
Loading…
Reference in New Issue
Block a user