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

networking: main-config: introduce NETWORKING_STACK to control network exts; allow "none"; fix typo #6786

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions extensions/network/net-network-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# Extension to manage network interfaces with NetworkManager + Netplan
#
function extension_prepare_config__install_network_manager() {
# Sanity check
if [[ "${NETWORKING_STACK}" != "network-manager" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sanity check might be couterproductive, since its perfectly valid to use both networking extensions at the same time if one wishes to.

exit_with_error "Extension: ${EXTENSION}: requires NETWORKING_STACK='network-manager', currently set to '${NETWORKING_STACK}'"
fi

display_alert "Extension: ${EXTENSION}: Installing additional packages" "network-manager network-manager-openvpn netplan.io" "info"
add_packages_to_image network-manager network-manager-openvpn netplan.io

Expand Down Expand Up @@ -39,9 +44,9 @@ function pre_install_kernel_debs__configure_network_manager() {
local network_manager_config_src_folder="${EXTENSION_DIR}/config-nm/NetworkManager/"
local network_manager_config_dst_folder="${SDCARD}/etc/NetworkManager/conf.d/"

run_host_command_logged cp "${netplan_config_src_folder}"* "${netplan_config_dst_folder}"
run_host_command_logged cp "${network_manager_config_src_folder}"* "${network_manager_config_dst_folder}"
run_host_command_logged cp -v "${netplan_config_src_folder}"* "${netplan_config_dst_folder}"
run_host_command_logged cp -v "${network_manager_config_src_folder}"* "${network_manager_config_dst_folder}"

# Change the file permissions according to https://netplan.readthedocs.io/en/stable/security/
chmod 600 "${SDCARD}"/etc/netplan/*
chmod -v 600 "${SDCARD}"/etc/netplan/*
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# Extension to manage network interfaces with systemd-networkd + Netplan
#
function extension_prepare_config__install_systemd_networkd() {
# Sanity check
if [[ "${NETWORKING_STACK}" != "systemd-networkd" ]]; then
exit_with_error "Extension: ${EXTENSION}: requires NETWORKING_STACK='systemd-networkd', currently set to '${NETWORKING_STACK}'"
fi

display_alert "Extension: ${EXTENSION}: Installing additional packages" "netplan.io" "info"
add_packages_to_image netplan.io
}
Expand All @@ -22,9 +27,9 @@ function pre_install_kernel_debs__configure_systemd_networkd() {
local networkd_config_src_folder="${EXTENSION_DIR}/config-networkd/systemd/network/"
local networkd_config_dst_folder="${SDCARD}/etc/systemd/network/"

run_host_command_logged cp "${netplan_config_src_folder}"* "${netplan_config_dst_folder}"
run_host_command_logged cp "${networkd_config_src_folder}"* "${networkd_config_dst_folder}"
run_host_command_logged cp -v "${netplan_config_src_folder}"* "${netplan_config_dst_folder}"
run_host_command_logged cp -v "${networkd_config_src_folder}"* "${networkd_config_dst_folder}"

# Change the file permissions according to https://netplan.readthedocs.io/en/stable/security/
chmod 600 "${SDCARD}"/etc/netplan/*
chmod -v 600 "${SDCARD}"/etc/netplan/*
}
1 change: 1 addition & 0 deletions lib/functions/configuration/change-tracking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ function track_general_config_variables() {
array_values="yes" track_config_variables "${1}" KERNEL_DRIVERS_SKIP
track_config_variables "${1}" BOOTSOURCE BOOTSOURCEDIR BOOTBRANCH BOOTPATCHDIR BOOTDIR BOOTCONFIG BOOTBRANCH_BOARD BOOTPATCHDIR_BOARD
track_config_variables "${1}" ATFSOURCEDIR ATFDIR ATFBRANCH CRUSTSOURCEDIR CRUSTDIR CRUSTBRANCH LINUXSOURCEDIR
track_config_variables "${1}" NETWORKING_STACK
}
43 changes: 36 additions & 7 deletions lib/functions/configuration/main-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,44 @@ function do_main_configuration() {

declare -g SKIP_EXTERNAL_TOOLCHAINS="${SKIP_EXTERNAL_TOOLCHAINS:-yes}" # don't use any external toolchains, by default.

# Network-manager and Chrony for standard CLI and desktop, systemd-networkd and systemd-timesyncd for minimal
# systemd-timesyncd is slimmer and less resource intensive than Chrony, see https://unix.stackexchange.com/questions/504381/chrony-vs-systemd-timesyncd-what-are-the-differences-and-use-cases-as-ntp-cli
if [[ ${BUILD_MINIMAL} == yes ]]; then
enable_extension "net-systemd-neworkd"
enable_extension "net-systemd-timesyncd"
# Network stack to use, default to network-manager; configuration can override this.
declare -g NETWORKING_STACK="${NETWORKING_STACK}"
# If empty, default depending on BUILD_MINIMAL; if yes, use systemd-networkd; if no, use network-manager.
if [[ -z "${NETWORKING_STACK}" ]]; then
igorpecovnik marked this conversation as resolved.
Show resolved Hide resolved
display_alert "NETWORKING_STACK not set" "Calculating defaults" "debug"
# Network-manager and Chrony for standard CLI and desktop, systemd-networkd and systemd-timesyncd for minimal
# systemd-timesyncd is slimmer and less resource intensive than Chrony, see https://unix.stackexchange.com/questions/504381/chrony-vs-systemd-timesyncd-what-are-the-differences-and-use-cases-as-ntp-cli
if [[ "${BUILD_MINIMAL}" == "yes" ]]; then
display_alert "BUILD_MINIMAL is set to yes" "Using systemd-networkd" "debug"
NETWORKING_STACK="systemd-networkd"
else
display_alert "BUILD_MINIMAL not set to yes" "Using network-manager" "debug"
NETWORKING_STACK="network-manager"
fi
else
enable_extension "net-network-manager"
enable_extension "net-chrony"
display_alert "NETWORKING_STACK is preset during configuration" "NETWORKING_STACK: ${NETWORKING_STACK}" "debug"
fi
# Now make it read-only, as further changes would make the whole thing inconsistent.
# Individual networking extensions should _check_ this to make there's no spurious enablement.
display_alert "Using NETWORKING_STACK" "NETWORKING_STACK: ${NETWORKING_STACK}" "info"
declare -g -r NETWORKING_STACK="${NETWORKING_STACK}"

# Now enable extensions according to the configuration.
case "${NETWORKING_STACK}" in
"network-manager")
display_alert "Adding networking extensions" "net-network-manager, net-chrony" "info"
enable_extension "net-network-manager"
enable_extension "net-chrony"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I specifically separated networking from time synching to make it more modular 😅

;;
"systemd-networkd")
display_alert "Adding networking extensions" "net-systemd-networkd, net-systemd-timesyncd" "info"
enable_extension "net-systemd-networkd"
enable_extension "net-systemd-timesyncd"
;;
"none" | *)
display_alert "NETWORKING_STACK=${NETWORKING_STACK}" "Not adding networking extensions" "info"
;;
esac

# Timezone
if [[ -f /etc/timezone ]]; then # Timezone for target is taken from host, if it exists.
Expand Down