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

netdog: Add write-primary-interface-status for networkd #2984

Merged
merged 1 commit into from
Apr 27, 2023

Conversation

yeazelm
Copy link
Contributor

@yeazelm yeazelm commented Apr 6, 2023

Issue number:

Related to #2449

Description of changes:
systemd-networkd does not have the same hook that wicked has so new functionality is needed to accomplish the same tasks. For now, the code is parallel to install.rs but adds a new cli command write-primary-interface-status for netdog. This command is intended to be called when the primary network interface moves to configured, at that point networkctl is called to fetch the required info and written to the desired places. This cli argument is only built in if the variant has systemd-networkd as a backend.

Testing done:
Built with additional logic to hard code systemd-networkd functionality enabled with the default interface, then called manually to setup dns.

The full branch can be found at develop...yeazelm:bottlerocket:update-resolver which covers the additional hardcoding. From that - unit tests and clippy also pass:

Note: this testing output uses the previous cli argument update-responder instead of write-primary-interface-status and I will run some additional tests now to ensure the new CLI (and all the updates of the code since then are still working as intended).

Bottlerocket OS 1.14.0 (metal-dev)
Kernel 5.15.102 on an x86_64 (console)

    ╱╲
   ╱┄┄╲
   │▗▖│
  ╱│  │╲
  │╰╮╭╯│
    ╹╹

localhost login: root
bash-5.1# 
bash-5.1# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=37 time=7.76 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 7.759/7.759/7.759/0.000 ms

bash-5.1# ping  amazon.com
ping: amazon.com: Temporary failure in name resolution

bash-5.1# netdog write-primary-interface-status
No DNS configuration exists in /etc/netdog.toml

bash-5.1# ping amazon.com
PING amazon.com (52.94.236.248) 56(84) bytes of data.
64 bytes from 52.94.236.248 (52.94.236.248): icmp_seq=1 ttl=220 time=62.7 ms

--- amazon.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 62.727/62.727/62.727/0.000 ms

bash-5.1# cat /etc/resolv.conf 
nameserver 172.31.0.2

bash-5.1# cat /var/lib/netdog/current_ip 
172.31.3.163

bash-5.1# 

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.

@yeazelm yeazelm force-pushed the update-responder-cli branch 2 times, most recently from de94a82 to 4158877 Compare April 6, 2023 03:36
@yeazelm yeazelm requested a review from zmrow April 6, 2023 04:08
@yeazelm yeazelm marked this pull request as ready for review April 6, 2023 04:09
sources/api/netdog/src/cli/update_responder.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/cli/mod.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/cli/update_responder.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/main.rs Show resolved Hide resolved
sources/api/netdog/src/main.rs Show resolved Hide resolved
sources/api/netdog/src/cli/update_responder.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
@zmrow
Copy link
Contributor

zmrow commented Apr 6, 2023

Could we expand on the commit message a little bit? What is this wicked hook, and why do we need something similar in networkd? Also, who is meant to call this new CLI command?

@yeazelm yeazelm force-pushed the update-responder-cli branch 3 times, most recently from 540e6b7 to 686ecb9 Compare April 8, 2023 18:26
sources/api/netdog/src/cli/write_resolv_conf.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/dns.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
@yeazelm yeazelm changed the title netdog: Add update-responder for networkd netdog: Add write-primary-interface-status for networkd Apr 17, 2023
sources/api/netdog/src/cli/mod.rs Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/cli/mod.rs Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
sources/api/netdog/src/networkd_status.rs Outdated Show resolved Hide resolved
@zmrow
Copy link
Contributor

zmrow commented Apr 20, 2023

Before this gets merged - be sure to rustfmt it and ensure clippy is happy!

@zmrow zmrow requested review from zmrow and bcressey April 20, 2023 19:42
wicked provides a hook when interfaces are configured to run extra
actions. These actions are used to write additional configuration needed
by other services and tools in the system. systemd-networkd does not
have the same hook so new functionality is needed to accomplish the same
tasks. For now, the code is parallel to the wicked-specific install.rs
but adds a new cli argument write-primary-interface-status to netdog.
This command is intended to be called when the primary network interface
moves to configured, at that point networkctl status is called for that
configured interface to fetch the required info and IP Address and DNS
configuration is written to the desired files like /etc/resolv.conf.

This cli argument is only built in if the variant has systemd-networkd
as a backend. It will be called by a yet to be built daemon that will
watch for these configured events on D-Bus and replicate the same
functionality wicked currently provides with its install hooks.

Signed-off-by: Matthew Yeazel <[email protected]>
Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

I think we've gotten this to a good spot!

🫕

Comment on lines +36 to +40
/// Persist the current IP address to file
fn write_current_ip(ip: &IpAddr) -> Result<()> {
fs::write(CURRENT_IP, ip.to_string())
.context(error::CurrentIpWriteFailedSnafu { path: CURRENT_IP })
}
Copy link
Contributor

Choose a reason for hiding this comment

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

write_current_ip could also be turned into a shared function, and potentially write_resolv_conf too if it took a DnsSettings parameter instead of the more specialized inputs.

@yeazelm yeazelm merged commit 07e5046 into bottlerocket-os:develop Apr 27, 2023
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.

5 participants