From 07cf9d5895404b1a4e04fd8de17918d5c0edf8ce Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Sat, 8 Nov 2025 10:54:37 +0100 Subject: [PATCH] [client] Create networkd.conf.d if it doesn't exist (#4764) --- client/cmd/service_installer.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/cmd/service_installer.go b/client/cmd/service_installer.go index 2a87e538d..f6828d96a 100644 --- a/client/cmd/service_installer.go +++ b/client/cmd/service_installer.go @@ -259,6 +259,7 @@ func isServiceRunning() (bool, error) { } const ( + networkdConf = "/etc/systemd/networkd.conf" networkdConfDir = "/etc/systemd/networkd.conf.d" networkdConfFile = "/etc/systemd/networkd.conf.d/99-netbird.conf" networkdConfContent = `# Created by NetBird to prevent systemd-networkd from removing @@ -273,12 +274,16 @@ ManageForeignRoutingPolicyRules=no // configureSystemdNetworkd creates a drop-in configuration file to prevent // systemd-networkd from removing NetBird's routes and policy rules. func configureSystemdNetworkd() error { - parentDir := filepath.Dir(networkdConfDir) - if _, err := os.Stat(parentDir); os.IsNotExist(err) { - log.Debug("systemd networkd.conf.d parent directory does not exist, skipping configuration") + if _, err := os.Stat(networkdConf); os.IsNotExist(err) { + log.Debug("systemd-networkd not in use, skipping configuration") return nil } + // nolint:gosec // standard networkd permissions + if err := os.MkdirAll(networkdConfDir, 0755); err != nil { + return fmt.Errorf("create networkd.conf.d directory: %w", err) + } + // nolint:gosec // standard networkd permissions if err := os.WriteFile(networkdConfFile, []byte(networkdConfContent), 0644); err != nil { return fmt.Errorf("write networkd configuration: %w", err)