Skip to content

Add support for IFLA_MIN_MTU and IFLA_MAX_MTU in LinkAttrs #1102

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type (
type LinkAttrs struct {
Index int
MTU int
MinMTU int
MaxMTU int
TxQLen int // Transmit Queue Length
Name string
HardwareAddr net.HardwareAddr
Expand Down
4 changes: 4 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,10 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
base.Name = string(attr.Value[:len(attr.Value)-1])
case unix.IFLA_MTU:
base.MTU = int(native.Uint32(attr.Value[0:4]))
case unix.IFLA_MIN_MTU:
Copy link
Contributor

Choose a reason for hiding this comment

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

@AlekseyMamedoff
Shouldn't you also add a corresponding method LinkSetMinMTU

If you are adding functionality to parse this attribute via netlink, we should also be able to add it to Links

Copy link
Contributor

@lazysegtree lazysegtree Jul 23, 2025

Choose a reason for hiding this comment

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

Also a unit test would be great. Something like

func TestLinkMinMaxMTU(t *testing.T) {
	tearDown := setUpNetlinkTest(t)
	defer tearDown()

	iface := &Dummy{LinkAttrs{
		Name: "foo",
	}}
	if err := LinkAdd(iface); err != nil {
		t.Fatal(err)
	}

	link, err := LinkByName("foo")
	err = LinkSetMinMTU(link, 1000)
	if link.Attrs().MinMTU != 1000 {
		t.Fatal("MinMTU not correct")
	}
}

base.MinMTU = int(native.Uint32(attr.Value[0:4]))
case unix.IFLA_MAX_MTU:
base.MaxMTU = int(native.Uint32(attr.Value[0:4]))
case unix.IFLA_PROMISCUITY:
base.Promisc = int(native.Uint32(attr.Value[0:4]))
case unix.IFLA_LINK:
Expand Down
Loading