-
Notifications
You must be signed in to change notification settings - Fork 510
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
Support static addressing via net.toml
#2445
Conversation
This commit begins the process of modularizing the `wicked` code to prepare for future additions. The structure will largely follow the structure in `net_config` to make the code easy to correlate. Currently only the DHCP-related wicked code is split out; more to come.
1a19d04
to
2a02a46
Compare
^ Add an additional comment regarding the link scope when a route's gateway ( |
net.toml
net.toml
@@ -0,0 +1,119 @@ | |||
use crate::net_config::{Dhcp4ConfigV1, Dhcp4OptionsV1, Dhcp6ConfigV1, Dhcp6OptionsV1}; |
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.
Nothing in this file is new code, all of it was moved out of wicked.rs
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.
The code changes look great to me. I'd like to try this out under QEMU just to see what it looks like on a running system, but otherwise I don't see any blockers. Nice work.
primary_count <= 1, | ||
error::InvalidNetConfigSnafu { | ||
reason: "multiple primary interfaces defined, expected 1" | ||
} |
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.
Do we expect 1
or 0 or 1
?
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.
We expect 0 or 1. In the case a user does not tell us which interface is primary, we document that we choose the first interface in the file.
@@ -1,12 +1,12 @@ | |||
use super::{error, InterfaceFamily, InterfaceType, Result}; | |||
use crate::dns::DnsSettings; | |||
use crate::lease::{lease_path, LeaseInfo}; | |||
use crate::lease::{dhcp_lease_path, static_lease_path, LeaseInfo}; |
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.
nit: commit says "we use similar log" where I think "logic" is meant
Adds the corresponding static address modules to both `net_config` and `wicked`. The `net_config` module contains the structs that `net.toml` deserializes into. The `wicked` module contains the structs that are serialized into interface configuration files, as well as the code to convert the `net_config` structs into `wicked*` structs.
2a02a46
to
b86b6dc
Compare
This commit adds a `new()` constructor for `WickedInterface`. This constructor helps to hide defaults for `WickedControl`, and provides a base on which to build out the structure (in lieu of a full on builder). As we add additional struct members, we can add them to this method rather than to all the callers/users of `WickedInterface`.
This change adds v2 of network config, which supports setting static addresses and routes. An additional test macro and associated test files have also been added to validate the functionality.
This change adds an additional public function to the `lease` module that allows the user to fetch the path for a given interface's static lease if it exists. It renames the original `lease_path` function to `dhcp_lease_path` to be a bit more descriptive, and moves the shared functionality to a private function.
This change ensures that when `netdog install` is called when setting up a static address, the proper lease file is used to write the current IP. When writing the `resolv.conf` file at this time, we use similar logic as before, getting settings from DNS config or from the DHCP lease, since static addresses don't contain DNS info. This change also unifies the logic of gathering the lease, writing the resolv.conf and current IP into shared functions.
This commit updates the wicked e2e testing. It templates the `net_config.toml` and adds additional config to said file to ensure that the static address configuration renders properly. The wicked testing function has been updated to loop through existing net config versions.
This adds the docs for v2 of network configuration, which supports adding static addresses and simple routes to an interface.
b86b6dc
to
f50bbbd
Compare
^ Addresses all of @bcressey 's comments! Thanks! |
* `to` (`"default"` or IP address with prefix, required): Destination address. | ||
* `from` (IP address): Source IP address. | ||
* `via` (IP address): Gateway IP address. If no gateway is provided, a scope of `link` is assumed. | ||
* `route-metric` (integer): Relative route priority. |
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.
nit: I do not know if we need to be that specific but this should probably be unsigned integer
.
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.
Hm. I don't think we need to get that specific, but we'll definitely change this if we get reports of folks having issues with it!
Issue number:
Closes #2204
Description of changes:
It's probably best to review this PR by commit to follow the chain of changes!
Adds support for setting ipv4/6 static addresses and simple routes in
net.toml
. Using the DNS API settings added in #2353 , a user can configure a complete and working simple static addressing setup.In order to add this support, a new version of network config has been created that adds a few additional settings:
static4
,static6
, androute
. These settings are deserialized innet_config/v2
into the structures defined innet_config/static_addressing
. They are then converted to the associated structures defined inwicked/static_addressing
. TheWicked*
structures are then serialized to file.An additional test macro has been defined in
net_config
containing unit tests for the static addressing validation and deserialization. The e2e tests defined inwicked
have also been updated to include various configurations. Thewicked
e2e test now iterates through the network configuration versions, validating both of them.The
wicked
helpernetdog install
has been updated to handle static addressses, reading from the correct lease file and ensuring that the current IP is always written. In the case multiple IPs exist, the first IP in theaddresses
list is uses as the primary. If ipv4 and ipv6 addresses are set, the first ipv4 addresses is used as the primary.An example valid net config from my home setup:
along with the corresponding DNS API settings (
user-data.toml
):Testing done:
aws-dev
VM) that all of the config setups defined intest_data/wicked/net_config.toml
are properly parsed and addresses are properly set. I did this by writing the resulting XML config directly to/etc/wicked/ifconfig/eth0
and restarting the network. Since my network is simple, the kernel chokes on trying to reach some of the defined routes and therefore doesn't set them, but at least we know the configuration is properly parsed.aws-k8s-1.21
and ensure the simple network defined in the kernel cmdline continues to work.metal-dev
with a few different static IP configurations, DNS settings, and a default route that would work on my network. Successfully reaches the internet and run containers.Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.