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

Fix generate_static_mac #781

Merged
merged 5 commits into from
Jan 5, 2025
Merged

Conversation

tschettervictor
Copy link
Collaborator

@tschettervictor tschettervictor commented Dec 29, 2024

I've updated the generate_static_mac function to hash the MAC of the host for the prefix. This is helpful when using interfaces such as bridge0, bridge1 etc.. which all have the same prefix.

This ensures that the MAC will always be unique for each IF/JAIL combo

@tschettervictor tschettervictor changed the title bugfix for cloneing new mac Fix generate_static_mac Dec 30, 2024
@bmac2
Copy link
Collaborator

bmac2 commented Dec 31, 2024

@yaazkal this one now tests fine for me. Test it too please.

@tschettervictor

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 4, 2025

I've tested and nothing seems broken. Just for documentation, can you please explain with examples what is the behavior before and after the patch @tschettervictor ?

@tschettervictor
Copy link
Collaborator Author

tschettervictor commented Jan 4, 2025

Before the patch there is no option for a jail
To have a statically assigned MAC address.

with the patch, the jail will be assigned a static mac based on the interface Mac and jail name.

the Mac should always be the same for the same combo of interface/jailname pair per server.

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 4, 2025

ok, but why the PR says fix? Is it fixing PR #725 ?

@tschettervictor
Copy link
Collaborator Author

tschettervictor commented Jan 4, 2025

Oh sorry. Yes it does expand from #725

The old version would generate it but it would not hash the interface MAC meaning that the MAC prefix would always be the same for interfaces like bridge0 bridge1 bridge2 which is unacceptable.

This PR hashes the full MAC of the interface resulting in a different one for every interface.

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 4, 2025

Ok, thanks for the clarification. To put it on an example and to understand the logic behind this:

If I have my host interface vtnet0 and its MAC address is 9a:0d:7c:a3:03:d5; I have a bridge called vtnet0bridge and its MAC address is 58:9c:fc:10:9f:07, what should be the prefix for the jails then?

@tschettervictor
Copy link
Collaborator Author

tschettervictor commented Jan 4, 2025

The prefix will be a result of the following code.
The external interface mac also gets sed'd to remove the : character
echo -n "${external_interface_mac}" | sha256 | cut -b -6 | sed 's/\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F]\)/\1:\2:\3/'

Which result in
vtnet0 = 47:8d:e1 (you left the last character out so i just assumed it is a "d")
vtnet0bridge= 6b:06:0e

And the suffix is the same as above, only instead of the interface, the jail name is hashed.
The suffix forms xx:xx:x and the last character is an "a" for the host side of the epair and a "b" for the jail side.

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 4, 2025

sorry for missing then last character of the vtnet0 MAC, does that change the result? (I've just edited the missing part)

@tschettervictor
Copy link
Collaborator Author

sorry for missing then last character of the vtnet0 MAC, does that change the result? (I've just edited the missing part)

Yes it will change. if it is a "b" for example, the MAC would then be 14:0a:46

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 4, 2025

I'm getting this 77:6f:4c as a prefix for all the jails. Given that explanation, can't tell then when that value is comming.

@tschettervictor
Copy link
Collaborator Author

That is the correct prefix for the corrected MAC above.

@tschettervictor
Copy link
Collaborator Author

tschettervictor commented Jan 4, 2025

root@bastille:~ # echo -n 9a0d7ca303d5 | sha256 | cut -b -6 | sed 's/\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F][0-9a-fA-F]\\)([0-9a-fA-F]\)/\1:\2:\3/'
77:6f:4c

@tschettervictor
Copy link
Collaborator Author

I think it's fairly random, as each server (if bridges are created) creates them with unique MACs. Also, each servers MAC is unique so the hashed value is also unique.

@yaazkal
Copy link
Collaborator

yaazkal commented Jan 5, 2025

root@bastille:~ # echo -n 9a0d7ca303d5 | sha256 | cut -b -6 | sed 's/\([0-9a-fA-F][0-9a-fA-F]\)\([0-9a-fA-F][0-9a-fA-F]\\)([0-9a-fA-F]\)/\1:\2:\3/'
77:6f:4c

ok, that makes sense now. Thanks for the clarification. I'll merge.

@yaazkal yaazkal merged commit 16bc90a into BastilleBSD:master Jan 5, 2025
1 check passed
@tschettervictor tschettervictor deleted the patch-2 branch January 5, 2025 01:29
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