Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bridge: add/del vlan range #863

Merged
merged 1 commit into from
Mar 4, 2024
Merged

bridge: add/del vlan range #863

merged 1 commit into from
Mar 4, 2024

Conversation

tjjh89017
Copy link
Contributor

Allow user to add vlan range in one rtnetlink call.
Usually, users will want to allow all vlans (2~4094) for some ports via iproute2 command (as below)

bridge vlan add vid 2-4094 dev dum0

Avoid to call rtnetlink 4000 times.
We should invlove vlan range to the modify function.

NOTE: original function didn't check if the vlan value is valid, so I didn't add validation.

@tjjh89017
Copy link
Contributor Author

@vishvananda @aboch please take a look
thanks a lot

@aboch
Copy link
Collaborator

aboch commented Mar 1, 2024

Thanks @tjjh89017
Can you please address the minor comments, then we merge this.

@tjjh89017
Copy link
Contributor Author

Thanks @tjjh89017 Can you please address the minor comments, then we merge this.

Hi @aboch
I didn't see any comment in the review?
Did you send the review already?
Thank you!

vlanEndInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_END
br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanEndInfo.Serialize())
} else {
br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the else and have only one instance of

br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())

invoked after the if block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the testing.
We can not add "vlanInfo" after the "vlanEndInfo".
It will cause that only the last vlan will be added into the bridge.
e.g. add vlan 4~6, but only vlan6 is added.

Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for checking.

bridge_linux.go Show resolved Hide resolved
bridge_linux.go Show resolved Hide resolved
@aboch
Copy link
Collaborator

aboch commented Mar 2, 2024

sorry, I published the comments now

@tjjh89017
Copy link
Contributor Author

tjjh89017 commented Mar 3, 2024

Hi @aboch
I updated the code with your comment.
But Test is failed.
So I rollback to the original commit.

Signed-off-by: Date Huang <tjjh89017@hotmail.com>
@tjjh89017
Copy link
Contributor Author

tjjh89017 commented Mar 3, 2024

@aboch
If we added BRIDGE_VLAN_INFO_RANGE_BEGIN after BRIDGE_VLAN_INFO_RANGE_END.
It will only add the last vlan into the bridge.
That is not our purpose.
So I have to rollback it.
Please check the orginal code.
Thank you!

=== RUN   TestBridgeVlan
    bridge_linux_test.go:76: unexpected result [{Flags:4 Vid:1} {Flags:0 Vid:2} {Flags:6 Vid:3} {Flags:0 Vid:6}]

It should be vlan4,5,6.
But only vlan6 is here.

Failed Code

diff --git a/bridge_linux.go b/bridge_linux.go
index 6c340b0..9f0903b 100644
--- a/bridge_linux.go
+++ b/bridge_linux.go
@@ -134,14 +134,12 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid, vidEnd uint16, pvid,
                vlanEndInfo := &nl.BridgeVlanInfo{Vid: vidEnd}
                vlanEndInfo.Flags = vlanInfo.Flags

-               vlanInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_BEGIN
-               br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())

                vlanEndInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_END
                br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanEndInfo.Serialize())
-       } else {
-               br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())
+               vlanInfo.Flags |= nl.BRIDGE_VLAN_INFO_RANGE_BEGIN
        }
+       br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())

        req.AddData(br)
        _, err := req.Execute(unix.NETLINK_ROUTE, 0)

@aboch
Copy link
Collaborator

aboch commented Mar 4, 2024

LGTM

@aboch aboch merged commit 0cd15d9 into vishvananda:main Mar 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants