support ipvlan flag

Signed-off-by: bingshen.wbs <bingshen.wbs@alibaba-inc.com>
This commit is contained in:
bingshen.wbs 2019-06-20 19:41:49 +08:00 committed by Alessandro Boch
parent b1e9859792
commit 14bd2e6fd2
4 changed files with 40 additions and 3 deletions

View File

@ -397,9 +397,18 @@ const (
IPVLAN_MODE_MAX
)
type IPVlanFlag uint16
const (
IPVLAN_FLAG_BRIDGE IPVlanFlag = iota
IPVLAN_FLAG_PRIVATE
IPVLAN_FLAG_VEPA
)
type IPVlan struct {
LinkAttrs
Mode IPVlanMode
Flag IPVlanFlag
}
func (ipvlan *IPVlan) Attrs() *LinkAttrs {

View File

@ -1218,6 +1218,7 @@ func (h *Handle) linkModify(link Link, flags int) error {
case *IPVlan:
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
data.AddRtAttr(nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(link.Mode)))
data.AddRtAttr(nl.IFLA_IPVLAN_FLAG, nl.Uint16Attr(uint16(link.Flag)))
case *Macvlan:
if link.Mode != MACVLAN_MODE_DEFAULT {
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
@ -2096,9 +2097,11 @@ func parseBondData(link Link, data []syscall.NetlinkRouteAttr) {
func parseIPVlanData(link Link, data []syscall.NetlinkRouteAttr) {
ipv := link.(*IPVlan)
for _, datum := range data {
if datum.Attr.Type == nl.IFLA_IPVLAN_MODE {
switch datum.Attr.Type {
case nl.IFLA_IPVLAN_MODE:
ipv.Mode = IPVlanMode(native.Uint32(datum.Value[0:4]))
return
case nl.IFLA_IPVLAN_FLAG:
ipv.Flag = IPVlanFlag(native.Uint32(datum.Value[0:4]))
}
}
}

View File

@ -127,6 +127,9 @@ func testLinkAddDel(t *testing.T, link Link) {
if ipv.Mode != other.Mode {
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, ipv.Mode)
}
if ipv.Flag != other.Flag {
t.Fatalf("Got unexpected flag: %d, expected: %d", other.Flag, ipv.Flag)
}
}
if macv, ok := link.(*Macvlan); ok {
@ -1114,6 +1117,27 @@ func TestLinkAddDelIPVlanL3(t *testing.T) {
testLinkAddDel(t, &ipv)
}
func TestLinkAddDelIPVlanVepa(t *testing.T) {
minKernelRequired(t, 4, 15)
tearDown := setUpNetlinkTest(t)
defer tearDown()
parent := &Dummy{LinkAttrs{Name: "foo"}}
if err := LinkAdd(parent); err != nil {
t.Fatal(err)
}
ipv := IPVlan{
LinkAttrs: LinkAttrs{
Name: "bar",
ParentIndex: parent.Index,
},
Mode: IPVLAN_MODE_L3,
Flag: IPVLAN_FLAG_VEPA,
}
testLinkAddDel(t, &ipv)
}
func TestLinkAddDelIPVlanNoParent(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()

View File

@ -87,7 +87,8 @@ const (
const (
IFLA_IPVLAN_UNSPEC = iota
IFLA_IPVLAN_MODE
IFLA_IPVLAN_MAX = IFLA_IPVLAN_MODE
IFLA_IPVLAN_FLAG
IFLA_IPVLAN_MAX = IFLA_IPVLAN_FLAG
)
const (