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

Generate unique MAC for bridges used for external networking #34

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fnordahl
Copy link
Contributor

When creating a bridge in Open vSwitch, a interface representing
that bridge will appear in the system. Open vSwitch will use the
lowest MAC address of the interfaces added to the bridge as MAC
address of the bridge representor interface.

Since the advent of predictable interface naming in Linux it has
become common for network configuration renderers and backends
to express network configuration in such a way that users will
use the MAC address of an interface to match where a certain
network config belongs.

These two factors together creates a situation where the backend
Netplan.io configures may choose to rename and use the Open
vSwitch bridge representor interface and apply network config to
it instead of using the real interface.

To work around this issue we generate an unique MAC address for
the bridges we add physical network interfaces to.

Related-Bug: #1912643

@fnordahl fnordahl marked this pull request as draft January 21, 2021 22:44
:raises: OSError
"""
with open('/etc/machine-id', 'r') as fin:
return bytearray.fromhex(fin.read().rstrip())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

:rtype: str
"""
# initialize with 'fa:16:3e' prefix
generated = bytearray.fromhex('fa163e')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matches what is typically used for virtual machines etc. We should probably use a different prefix

# initialize with 'fa:16:3e' prefix
generated = bytearray.fromhex('fa163e')
# append last byte of bridge name
generated.append(ord(bridge_name[-1:]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may easily collide, make this byte from some sort of checksum of the bridge name

When creating a bridge in Open vSwitch, a interface representing
that bridge will appear in the system. Open vSwitch will use the
lowest MAC address of the interfaces added to the bridge as MAC
address of the bridge representor interface.

Since the advent of predictable interface naming in Linux it has
become common for network configuration renderers and backends
to express network configuration in such a way that users will
use the MAC address of an interface to match where a certain
network config belongs.

These two factors together creates a situation where the backend
Netplan.io configures may choose to rename and use the Open
vSwitch bridge representor interface and apply network config to
it instead of using the real interface.

To work around this issue we generate an unique MAC address for
the bridges we add physical network interfaces to.

Related-Bug: #1912643
:rtype: str
"""
# prefix from the IANA 64-bit MAC Unassigned range
generated = bytearray.fromhex('b61d9e')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to review if this OUI makes sense to use, we also must make sure we set the unicast/multicast and universal/local bits correctly.

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.

1 participant