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

net: support multiple interfaces #12

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Conversation

matttbe
Copy link
Collaborator

@matttbe matttbe commented Nov 27, 2024

virtme-run supports multiple --net arguments to setup virtio-net devices, but the init program was only starting the DHCP client for one of them: the first one it discovered (which here in rust was not necessarily the first one by alphabetical order).

Now, the DHCP client is started for each interface, so each of them can have an assigned IP address.

Technically, instead of returning one network device, a vector of devices is returned. Same for the threads to start the DHCP clients.

While at it, the loopback interface is also setup in a thread: it is fine if nothing else is depending on it. (Or maybe Snap depends on it? I didn't check with my current setup not having Snap. But if it does, I guess the modifications in the main() function are not correct: lo should be setup, then the vector should be created.)

Please note that I still need to learn Rust, and it is the first time I'm writing "useful" code. Do not hesitate to tell me if there are stuff to improve :)

virtme-run supports multiple --net arguments to setup virtio-net
devices, but the init program was only starting the DHCP client for one
of them: the first one it discovered, which was not necessarily the
first one by alphabetical order.

Now, the DHCP client is started for each interface, so each of them can
have an assigned IP address.

Technically, instead of returning one network device, a vector of
devices is returned. Same for the threads to start the DHCP clients.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Now that setup_network() returns a vector of threads, it is easy to add
an extra one.

Setting up the loopback interface should be quick. Still, it can be done
in parallel if there is nothing else depending on it.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
This fixes the following warning:

  warning: irrefutable `if let` pattern
     --> src/main.rs:206:8
      |
  206 |     if let Err(err) = reboot::reboot(reboot::RebootMode::RB_POWER_OFF) {
      |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: this pattern will always match, so the `if let` is useless
      = help: consider replacing the `if let` with a `let`
      = note: `#[warn(irrefutable_let_patterns)]` on by default

  warning: `virtme-ng-init` (bin "virtme-ng-init") generated 1 warning

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
@matttbe
Copy link
Collaborator Author

matttbe commented Nov 27, 2024

While at it, I also just fixed a warning that was present before my modifications:

  warning: irrefutable `if let` pattern
     --> src/main.rs:206:8
      |
  206 |     if let Err(err) = reboot::reboot(reboot::RebootMode::RB_POWER_OFF) {
      |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: this pattern will always match, so the `if let` is useless
      = help: consider replacing the `if let` with a `let`
      = note: `#[warn(irrefutable_let_patterns)]` on by default
      
  warning: `virtme-ng-init` (bin "virtme-ng-init") generated 1 warning

Copy link
Owner

@arighi arighi left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@arighi arighi merged commit f9d3c4a into arighi:main Nov 27, 2024
1 check passed
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.

2 participants