Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0b9952

Browse files
Marcelosqueed
authored andcommitted
Allow vlan parameter to set native vlan on trunk ports
This allows to set the native vlan on trunk ports via the vlan parameter. It removes all previous limitations set on the vlan trunk implementation. Signed-off-by: Marcelo <[email protected]>
1 parent f0eb519 commit e0b9952

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

plugins/main/bridge/bridge.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ func loadNetConf(bytes []byte, envArgs string) (*NetConf, string, error) {
123123
return nil, "", err
124124
}
125125

126-
// Currently bridge CNI only support access port(untagged only) or trunk port(tagged only)
127-
if n.Vlan > 0 && n.vlans != nil {
128-
return nil, "", errors.New("cannot set vlan and vlanTrunk at the same time")
129-
}
130-
131126
if envArgs != "" {
132127
e := MacEnvArgs{}
133128
if err := types.LoadArgs(envArgs, &e); err != nil {
@@ -468,7 +463,6 @@ func setupVeth(
468463
}
469464
}
470465

471-
// Currently bridge CNI only support access port(untagged only) or trunk port(tagged only)
472466
if vlanID != 0 {
473467
err = netlink.BridgeVlanAdd(hostVeth, uint16(vlanID), true, true, false, true)
474468
if err != nil {
@@ -483,6 +477,15 @@ func setupVeth(
483477
}
484478
}
485479

480+
// Backwards compatibility with users that did not specify a vlanID
481+
if vlanID == 0 && len(vlans) > 0 {
482+
// If no vlan is specified, we set the native vlan on the trunk equal to 1
483+
err = netlink.BridgeVlanAdd(hostVeth, 1, true, true, false, true)
484+
if err != nil {
485+
return nil, nil, fmt.Errorf("failed to setup default native vlan tag on interface %q: %v", hostIface.Name, err)
486+
}
487+
}
488+
486489
return hostIface, contIface, nil
487490
}
488491

plugins/main/bridge/bridge_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,13 @@ func (tester *testerV10x) cmdAddTest(tc testCase, dataDir string) (types.Result,
691691
}
692692
}
693693
}
694+
695+
// Check native vlan
696+
nativeVlan := tc.vlan
697+
if tc.vlan == 0 {
698+
nativeVlan = 1
699+
}
700+
Expect(checkVlan(nativeVlan, vlans)).To(BeTrue())
694701
}
695702

696703
// Check that the bridge has a different mac from the veth
@@ -1032,6 +1039,13 @@ func (tester *testerV04x) cmdAddTest(tc testCase, dataDir string) (types.Result,
10321039
}
10331040
}
10341041
}
1042+
1043+
// Check native vlan
1044+
nativeVlan := tc.vlan
1045+
if tc.vlan == 0 {
1046+
nativeVlan = 1
1047+
}
1048+
Expect(checkVlan(nativeVlan, vlans)).To(BeTrue())
10351049
}
10361050

10371051
// Check that the bridge has a different mac from the veth
@@ -1366,6 +1380,13 @@ func (tester *testerV03x) cmdAddTest(tc testCase, dataDir string) (types.Result,
13661380
}
13671381
}
13681382
}
1383+
1384+
// Check native vlan
1385+
nativeVlan := tc.vlan
1386+
if tc.vlan == 0 {
1387+
nativeVlan = 1
1388+
}
1389+
Expect(checkVlan(nativeVlan, vlans)).To(BeTrue())
13691390
}
13701391

13711392
// Check that the bridge has a different mac from the veth
@@ -2021,11 +2042,31 @@ var _ = Describe("bridge Operations", func() {
20212042
})
20222043

20232044
// TODO find some way to put pointer
2024-
It(fmt.Sprintf("[%s] configures and deconfigures a l2 bridge with vlan id 100, vlanTrunk 101,200~210 using ADD/DEL", ver), func() {
2045+
It(fmt.Sprintf("[%s] configures and deconfigures a l2 bridge with vlanTrunk 101,200~210 using ADD/DEL", ver), func() {
2046+
id, minID, maxID := 101, 200, 210
2047+
tc := testCase{
2048+
cniVersion: ver,
2049+
isLayer2: true,
2050+
vlanTrunk: []*VlanTrunk{
2051+
{ID: &id},
2052+
{
2053+
MinID: &minID,
2054+
MaxID: &maxID,
2055+
},
2056+
},
2057+
AddErr020: "cannot convert: no valid IP addresses",
2058+
AddErr010: "cannot convert: no valid IP addresses",
2059+
}
2060+
cmdAddDelTest(originalNS, targetNS, tc, dataDir)
2061+
})
2062+
2063+
It(fmt.Sprintf("[%s] configures and deconfigures a l2 bridge with vlan 100, and vlanTrunk 101,200~210 using ADD/DEL", ver), func() {
2064+
nativeVlan := 100
20252065
id, minID, maxID := 101, 200, 210
20262066
tc := testCase{
20272067
cniVersion: ver,
20282068
isLayer2: true,
2069+
vlan: nativeVlan,
20292070
vlanTrunk: []*VlanTrunk{
20302071
{ID: &id},
20312072
{

0 commit comments

Comments
 (0)