-
Notifications
You must be signed in to change notification settings - Fork 59
Change AddrGenMode into enum #149
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
Open
Toorero
wants to merge
1
commit into
rust-netlink:main
Choose a base branch
from
Toorero:feature/addr_gen_mode_enum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
use std::fmt::Display; | ||
|
||
const IN6_ADDR_GEN_MODE_EUI64: u8 = 0; | ||
const IN6_ADDR_GEN_MODE_NONE: u8 = 1; | ||
const IN6_ADDR_GEN_MODE_STABLE_PRIVACY: u8 = 2; | ||
const IN6_ADDR_GEN_MODE_RANDOM: u8 = 3; | ||
|
||
#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)] | ||
#[non_exhaustive] | ||
#[repr(u8)] | ||
pub enum In6AddrGenMode { | ||
#[default] | ||
Eui64, | ||
None, | ||
StablePrivacy, | ||
Random, | ||
Other(u8), | ||
} | ||
|
||
impl From<u8> for In6AddrGenMode { | ||
fn from(d: u8) -> Self { | ||
match d { | ||
IN6_ADDR_GEN_MODE_EUI64 => Self::Eui64, | ||
IN6_ADDR_GEN_MODE_NONE => Self::None, | ||
IN6_ADDR_GEN_MODE_STABLE_PRIVACY => Self::StablePrivacy, | ||
IN6_ADDR_GEN_MODE_RANDOM => Self::Random, | ||
_ => Self::Other(d), | ||
} | ||
} | ||
} | ||
impl From<&In6AddrGenMode> for u8 { | ||
fn from(v: &In6AddrGenMode) -> Self { | ||
match v { | ||
In6AddrGenMode::Eui64 => IN6_ADDR_GEN_MODE_EUI64, | ||
In6AddrGenMode::None => IN6_ADDR_GEN_MODE_NONE, | ||
In6AddrGenMode::StablePrivacy => IN6_ADDR_GEN_MODE_STABLE_PRIVACY, | ||
In6AddrGenMode::Random => IN6_ADDR_GEN_MODE_RANDOM, | ||
In6AddrGenMode::Other(d) => *d, | ||
} | ||
} | ||
} | ||
|
||
impl Display for In6AddrGenMode { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Eui64 => write!(f, "eui64"), | ||
Self::None => write!(f, "none"), | ||
// https://github.com/iproute2/iproute2/blob/afbfd2f2b0a633d068990775f8e1b73b8ee83733/ip/ipaddress.c#L325-L329 | ||
Self::StablePrivacy => write!(f, "stable_secret"), | ||
Self::Random => write!(f, "random"), | ||
Self::Other(d) => write!(f, "other({d})"), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stable_privacy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was weirdly confused too but this is how it is implemented in iproute2 [1], [2]. I'm happy to change this though if you feel the need. Alternatively I could attach one of the links as a code comment to make thinks more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if "stable_secret" is used in iproute, I am more in favor of "stable_privacy". But if @cathay4t agrees on "stable_secret" that is 2 vs 1, so ignore the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your call @cathay4t. I just outlined why I choose
stable_secret
. I'm fine either way.