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

wicked: allow interface configuration via Ethernet permanent address #2519

Conversation

markusboehme
Copy link
Member

Issue number: #2293

Description of changes: Add support for identifying Ethernet interfaces to configure via their permanent/hardware/MAC address to wicked. For example, allow the following:

<interface>
    <name namespace="ethernet">
        <permanent-address>52:54:00:12:34:56</permanent-address>
    </name>
    <ipv4:dhcp>
        <enabled>true</enabled>
    </ipv4:dhcp>
</interface>

to configure the Ethernet interface with MAC address 52:54:00:12:34:56 via DHCP.

Note that:

  1. These are downstream patches to wicked, eventually also to be proposed to the upstream project.
  2. These only prepare being able to configure interfaces via other means than interface name. Components like netdog will still need to be adapted.

Testing done: In a local VM, I successfully configured interfaces both via interface name and MAC address (at first by modifying /etc/wicked/ifconfig/ and restarting wicked components, later by just having netdog write the above XML snippet on boot).

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Comment on lines +52 to +61
unsigned int value;
char name_buf[IF_NAMESIZE+1];

+ if (ni_string_empty(nnode->cdata)) {
+ ni_debug_ifconfig("config is missing an interface name in <name> node");
+ goto error;
+ }
+ ifname = nnode->cdata;
+
if (ni_parse_uint(ifname, &value, 10) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the interface "name" for the ifindex namespace is actually an integer, would it be more consistent with the other two branches to use the MAC address as the "name" for the ethernet namespace?

It looks like using the permanent-address field is suggested by the original docs, so what you have makes sense to me.

Copy link
Member Author

@markusboehme markusboehme Nov 4, 2022

Choose a reason for hiding this comment

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

I think I know what you mean, but am not 100% sure, so to clarify: Is what you're suggesting to store the MAC address in ifname when handling the ethernet namespace, similar to how the interface index is stored in ifname when handling the ifindex namespace?

If so, no, ifname needs to be the actual interface name in both cases. The diff is hiding the part of the code handling the ifindex namespace where the index temporarily stored in ifname is used to look up the actual interface name (edit: https://github.com/openSUSE/wicked/blob/a5762e9f372b9f8da3be4a7803f0a6d81c6dda6a/client/read-config.c#L356,L364). Unfortunately, the variable reuse doesn't help to make this clear either.

+ addrnode = xml_node_get_child(nnode, "permanent-address");
+ if (!addrnode || ni_string_empty(addrnode->cdata)) {
+ ni_debug_ifconfig("cannot get interface name - "
+ "config has no valid <ethernet> node");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: isn't it a <name> node still, rather than an <ethernet> node?

Comment on lines 80 to 82
+ if (ni_scandir("/sys/class/net", NULL, &all_ifnames) <= 0)
+ goto error;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a debug message indicating the read failure?

@zmrow
Copy link
Contributor

zmrow commented Nov 3, 2022

I like @bcressey 's suggestions for changes - other than that this looks great!

Add support for identifying Ethernet interfaces to configure via their
permanent/hardware/MAC address. For example, allow the following:

    <interface>
        <name namespace="ethernet">
            <permanent-address>52:54:00:12:34:56</permanent-address>
        </name>
        <ipv4:dhcp>
            <enabled>true</enabled>
        </ipv4:dhcp>
    </interface>

to configure the Ethernet interface with MAC address 52:54:00:12:34:56
via DHCP.

Signed-off-by: Markus Boehme <[email protected]>
@markusboehme markusboehme force-pushed the feature/wicked-mac-based-config branch from f2617af to a09b8b4 Compare November 9, 2022 22:40
@markusboehme
Copy link
Member Author

In the force push:

  • Improving debug message for invalid <name> node in ethernet namespace in config
  • Adding extra debug logging for failure to enumerate network interfaces

Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

🌮

Thanks!

@markusboehme markusboehme merged commit 64be2f2 into bottlerocket-os:develop Nov 11, 2022
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.

5 participants