mirror of
https://github.com/vishvananda/netlink
synced 2024-12-29 02:02:21 +00:00
support vlan protocol
This commit is contained in:
parent
fd97bf4e47
commit
fafc1e7b60
46
link.go
46
link.go
@ -251,7 +251,8 @@ func (bridge *Bridge) Type() string {
|
||||
// Vlan links have ParentIndex set in their Attrs()
|
||||
type Vlan struct {
|
||||
LinkAttrs
|
||||
VlanId int
|
||||
VlanId int
|
||||
VlanProtocol VlanProtocol
|
||||
}
|
||||
|
||||
func (vlan *Vlan) Attrs() *LinkAttrs {
|
||||
@ -405,6 +406,43 @@ func (ipvlan *IPVlan) Type() string {
|
||||
return "ipvlan"
|
||||
}
|
||||
|
||||
// VlanProtocol type
|
||||
type VlanProtocol int
|
||||
|
||||
func (p VlanProtocol) String() string {
|
||||
s, ok := VlanProtocolToString[p]
|
||||
if !ok {
|
||||
return fmt.Sprintf("VlanProtocol(%d)", p)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// StringToVlanProtocol returns vlan protocol, or unknown is the s is invalid.
|
||||
func StringToVlanProtocol(s string) VlanProtocol {
|
||||
mode, ok := StringToVlanProtocolMap[s]
|
||||
if !ok {
|
||||
return VLAN_PROTOCOL_UNKNOWN
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
// VlanProtocol possible values
|
||||
const (
|
||||
VLAN_PROTOCOL_UNKNOWN VlanProtocol = 0
|
||||
VLAN_PROTOCOL_8021Q VlanProtocol = 0x8100
|
||||
VLAN_PROTOCOL_8021AD VlanProtocol = 0x88A8
|
||||
)
|
||||
|
||||
var VlanProtocolToString = map[VlanProtocol]string{
|
||||
VLAN_PROTOCOL_8021Q: "802.1q",
|
||||
VLAN_PROTOCOL_8021AD: "802.1ad",
|
||||
}
|
||||
|
||||
var StringToVlanProtocolMap = map[string]VlanProtocol{
|
||||
"802.1q": VLAN_PROTOCOL_8021Q,
|
||||
"802.1ad": VLAN_PROTOCOL_8021AD,
|
||||
}
|
||||
|
||||
// BondMode type
|
||||
type BondMode int
|
||||
|
||||
@ -416,7 +454,7 @@ func (b BondMode) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
// StringToBondMode returns bond mode, or uknonw is the s is invalid.
|
||||
// StringToBondMode returns bond mode, or unknown is the s is invalid.
|
||||
func StringToBondMode(s string) BondMode {
|
||||
mode, ok := StringToBondModeMap[s]
|
||||
if !ok {
|
||||
@ -507,7 +545,7 @@ func (b BondXmitHashPolicy) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
// StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid.
|
||||
// StringToBondXmitHashPolicy returns bond lacp arte, or unknown is the s is invalid.
|
||||
func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
|
||||
lacp, ok := StringToBondXmitHashPolicyMap[s]
|
||||
if !ok {
|
||||
@ -552,7 +590,7 @@ func (b BondLacpRate) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
// StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid.
|
||||
// StringToBondLacpRate returns bond lacp arte, or unknown is the s is invalid.
|
||||
func StringToBondLacpRate(s string) BondLacpRate {
|
||||
lacp, ok := StringToBondLacpRateMap[s]
|
||||
if !ok {
|
||||
|
@ -1155,6 +1155,10 @@ func (h *Handle) linkModify(link Link, flags int) error {
|
||||
native.PutUint16(b, uint16(link.VlanId))
|
||||
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
|
||||
data.AddRtAttr(nl.IFLA_VLAN_ID, b)
|
||||
|
||||
if link.VlanProtocol != VLAN_PROTOCOL_UNKNOWN {
|
||||
data.AddRtAttr(nl.IFLA_VLAN_PROTOCOL, htons(uint16(link.VlanProtocol)))
|
||||
}
|
||||
case *Veth:
|
||||
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
|
||||
peer := data.AddRtAttr(nl.VETH_INFO_PEER, nil)
|
||||
@ -1830,6 +1834,8 @@ func parseVlanData(link Link, data []syscall.NetlinkRouteAttr) {
|
||||
switch datum.Attr.Type {
|
||||
case nl.IFLA_VLAN_ID:
|
||||
vlan.VlanId = int(native.Uint16(datum.Value[0:2]))
|
||||
case nl.IFLA_VLAN_PROTOCOL:
|
||||
vlan.VlanProtocol = VlanProtocol(int(ntohs(datum.Value[0:2])))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ func TestLinkAddDelVlan(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testLinkAddDel(t, &Vlan{LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, 900})
|
||||
testLinkAddDel(t, &Vlan{LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, 900, VLAN_PROTOCOL_8021Q})
|
||||
|
||||
if err := LinkDel(parent); err != nil {
|
||||
t.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user