bottlerocket icon indicating copy to clipboard operation
bottlerocket copied to clipboard

Support static addressing via `net.toml`

Open zmrow opened this issue 3 years ago • 1 comments

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, and route. These settings are deserialized in net_config/v2 into the structures defined in net_config/static_addressing. They are then converted to the associated structures defined in wicked/static_addressing. The Wicked* 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 in wicked have also been updated to include various configurations. The wicked e2e test now iterates through the network configuration versions, validating both of them.

The wicked helper netdog install has been updated to handle static, 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 the addresses 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:

version = 2

[eno1.static4]
addresses = ["192.168.86.200/24"]

[[eno1.route]]
to = "default"
via "192.168.86.1"

along with the corresponding DNS API settings (user-data.toml):

[settings.dns]
name-servers = ["192.168.86.1"]

Testing done:

  • All new and old unit tests pass.
  • Manually validate (using aws-dev VM) that all of the config setups defined in test_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.
  • Boot aws-k8s-1.21 and ensure the simple network defined in the kernel cmdline continues to work.
  • Boot 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.

zmrow avatar Sep 20 '22 20:09 zmrow

^ Add an additional comment regarding the link scope when a route's gateway (via) is omitted.

zmrow avatar Sep 20 '22 20:09 zmrow

^ Addresses all of @bcressey 's comments! Thanks!

zmrow avatar Sep 27 '22 17:09 zmrow