-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add mac assigning to network base connection #893
Add mac assigning to network base connection #893
Conversation
Hi @jcronenberg. First of all, thanks! And now, let's review the approach. I prefer using some MAC address type. @teclator suggested using macaddr, which looks simple enough, but we are open to other options. However, using a However, if the value is not mandatory, I would go with an |
Alright I tend to agree, so I'll look into using that crate for the mac address type.
When going the |
IMHO the |
73d07af
to
c960eac
Compare
I think for pretty much all backends this would be the case, but anyway it doesn't really matter. |
c960eac
to
f7b86b5
Compare
I have updated the PR with how I would envision it to work with a dedicated MAC type. |
f7b86b5
to
b767cc7
Compare
Value::new(match &conn.base.mac_address { | ||
Some(mac) => mac.to_string(), | ||
None => "".to_string(), |
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.
because of this, maybe we could place mac_address_string()
into BaseConnection
b767cc7
to
e3b3305
Compare
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.
LGTM
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.
When I proposed an Option
I was not aware that it was not a simple address, but that you were defining your own enum. Sorry if I overlooked something.
In that case, the None
variant could be part of your enum, so you would not need to cope with that case anymore and you could simplify the code.
And that _string
method would not be needed at all.
/// Custom mac-address | ||
#[dbus_interface(property)] | ||
pub async fn mac_address(&self) -> String { | ||
self.get_connection().await.base().mac_address_string() |
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.
For better encapsulation, please do not call base()
from outside the struct. Actually, I think base()
should be private.
I would implement mac_address()
in Connection
directly.
} | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub struct BaseConnection { | ||
pub id: String, | ||
pub uuid: Uuid, | ||
pub mac_address: Option<MacAddress>, |
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.
When I proposed using an Option
, I thought you would have the macaddr::MacAddr
struct inside. But I see that it is more complex as you are defining an enum (MacAddress
). To make things easier, why not just add a MacAddress::None
(feel free to find a better name, please)? So you do not need to cope with the Option
anymore.
Actually, you could convert that value to an empty string.
} | ||
} | ||
|
||
pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { |
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.
This one looks counter-intuitive to me. Why do I need to convert a MacAddress to a string? Not to mention the fact that an empty string means None
. If you add the None
variant to the MacAddress
enum, well, problem solved.
If you continue with the Option
approach, I would 1) pass an option or 2) have a set_mac_address
and a unset_mac_address
.
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"preserve" => Ok(Self::Preserve), | ||
"permanent" => Ok(Self::Preserve), |
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.
Why is "permanent"
converted to Preserve
?
match s { | ||
"preserve" => Ok(Self::Preserve), | ||
"permanent" => Ok(Self::Preserve), | ||
"random" => Ok(Self::Permanent), |
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.
Why are "random"
and "stable"
converted to Permanent
?
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.
Oops must have been some lazy copy pasting 😄
28dc327
to
aa0d1b4
Compare
self.base().mac_address.to_string() | ||
} | ||
|
||
pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { |
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.
pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { | |
pub fn set_mac_address(&mut self, mac_address: MacAddress) { |
} | ||
|
||
pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { | ||
self.base_mut().mac_address = MacAddress::from_str(mac_address)?; |
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.
self.base_mut().mac_address = MacAddress::from_str(mac_address)?; | |
self.base_mut().mac_address = mac_address; |
|
||
pub fn set_mac_address(&mut self, mac_address: &str) -> Result<(), InvalidMacAddress> { | ||
self.base_mut().mac_address = MacAddress::from_str(mac_address)?; | ||
Ok(()) |
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.
Ok(()) |
b4c798b
to
4fefbe6
Compare
4fefbe6
to
b27645f
Compare
Problem
It's not possible to assign a mac address to network connections
Solution
Add a property
mac_address
to base connection and also toNetworkConnection
inside settings to allow setting of custom mac addresses.Note: Currently for simplicity sake it just stores it as
String
all around, but with this draft I also wanted to start a discussion on what agama should use to store the mac address insideBaseConnection
.String
is of course the simplest, but doesn't perform any validation before sending it to NetworkManager, so the result is a pretty non explanatory error that the connection couldn't be added, because NetworkManager rejects any invalid macs of course. Let me know what you would prefer 🙂 (adjustments to the type shouldn't be to much work so no worries if I should change it)Testing