Skip to content

Conversation

@thaJeztah
Copy link
Member

libnetwork/drivers/ipvlan: move truncating ID to getDummyName

The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

libnetwork/drivers/ipvlan: getDummyName don't use stringid.TruncateID

The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

libnetwork/drivers/macvlan: move truncating ID to getDummyName

The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

libnetwork/drivers/macvlan: getDummyName don't use stringid.TruncateID

The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

- A picture of a cute animal (not mandatory but encouraged)

The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the simplify_getDummyName branch from 357fa61 to f741ca8 Compare June 18, 2024 17:41
Comment on lines -66 to +65
stringid.TruncateID(nw.config.ID),
nw.config.ID,
Copy link
Member Author

Choose a reason for hiding this comment

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

Rebased, and (as discussed on slack) removing the TruncateID here, as it was just to keep a shorter error.

@thaJeztah
Copy link
Member Author

thaJeztah commented Jun 18, 2024

Discussing on Slack for a follow-up PR, I'll add some comments about these getDummyName functions (and the related consts); the interface-names must be <= 15 characters long (which is why the short-ID (12) and prefix (di-)) have this length, but it's not documented that that's the reason.

While things will likely fail loud if someone would ever change those, it doesn't hurt to add that information in a comment; I'll do that in a follow-up.

related: here's where the limit is defined in the kernel: https://github.com/torvalds/linux/blob/46d1907d1caaaaa422ae814c52065f243caa010a/include/uapi/linux/if.h#L33
And here's where the interface name is validated: https://github.com/torvalds/linux/blob/46d1907d1caaaaa422ae814c52065f243caa010a/net/core/dev.c#L1062

@thaJeztah thaJeztah merged commit 59b119f into moby:master Jun 18, 2024
@thaJeztah thaJeztah deleted the simplify_getDummyName branch June 18, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants