Skip to content

Conversation

@AlekseyMamedoff
Copy link

Added attributes MinMTU, MaxMTU to LinkAttrs struct
Added cases for IFLA_MIN_MTU, IFLA_MAX_MTU
Signed-off-by: Aleksey Mamedov alekseymamedoff@gmail.com

@lazysegtree
Copy link
Contributor

@AlekseyMamedoff , Fix for TestXfrmStateWithPcpunumWithoutSADir, the test which is failing in your PR, was recently merged in main. Please rebase with main.

Signed-off-by: Aleksey Mamedov <alekseymamedoff@gmail.com>
@AlekseyMamedoff AlekseyMamedoff force-pushed the feature/add-mtu-limits branch from 8341ba3 to d4422e8 Compare July 23, 2025 10:13
@AlekseyMamedoff
Copy link
Author

@lazysegtree Done. Test passed. Thx.

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")
	}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

@AlekseyMamedoff AlekseyMamedoff Dec 9, 2025

Choose a reason for hiding this comment

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

Hello!
I believe we no need Set funcs and tests for min, max mtu params, cause netlink itself handle it like read-only fields. We can see it, if we dive a bit into netlink source code.

When we ask netlink set some params for dev it will call do_setlink() by the end.

There is handler for IFLA_MTU:

if (tb[IFLA_MTU]) {
		err = netif_set_mtu_ext(dev, nla_get_u32(tb[IFLA_MTU]), extack);
		if (err < 0)
			goto errout;
		status |= DO_SETLINK_MODIFIED;
}

But there is not for IFLA_MIN_MTU or IFLA_MAX_MTU attributes.

So do_setlink() will always fall through directly to the "errout" label and
return 0 (success) without applying any changes.

In your example:

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

We will never get an error from LinkSetMinMTU(), but always fail when we try check min MTU has changed. The same with max MTU.

P.s. Sorry for delaying with answer.

Choose a reason for hiding this comment

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

I agree. Adding Setters for MaxMTU and MinMTU sizes does not make sense because they can't be set from userspace. They are a read-only view of what the interface is telling the kernel its minimum or maximum accepted MTU is.

Copy link
Author

Choose a reason for hiding this comment

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

@aboch ping

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to extend existing UT to verify these fields are returned, are set?

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.

4 participants