From: Thomas Lamprecht Date: Thu, 23 Nov 2023 10:46:45 +0000 (+0100) Subject: dhcp dnsmasq: guard die with zone having enabled dhcp X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=bed9fbc246bc4e65874ac9fb4953396f5bbab9f3;p=matthieu%2Fpve-network.git dhcp dnsmasq: guard die with zone having enabled dhcp as stop-gap Signed-off-by: Thomas Lamprecht Acked-by: Wolfgang Bumiller --- diff --git a/src/PVE/Network/SDN/Dhcp.pm b/src/PVE/Network/SDN/Dhcp.pm index 2c2d019..7876c08 100644 --- a/src/PVE/Network/SDN/Dhcp.pm +++ b/src/PVE/Network/SDN/Dhcp.pm @@ -67,9 +67,11 @@ sub regenerate_config { my $plugins = PVE::Network::SDN::Dhcp::Plugin->lookup_types(); + my $any_zone_needs_dhcp = grep { $_->{dhcp} } values $zone_cfg->{ids}->%*; + foreach my $plugin_name (@$plugins) { my $plugin = PVE::Network::SDN::Dhcp::Plugin->lookup($plugin_name); - eval { $plugin->before_regenerate() }; + eval { $plugin->before_regenerate(!$any_zone_needs_dhcp) }; die "Could not run before_regenerate for DHCP plugin $plugin_name $@\n" if $@; } @@ -113,7 +115,7 @@ sub regenerate_config { warn "Could not configure vnet $vnetid: $@\n" if $@; } - eval { $dhcp_plugin->after_configure($zoneid) }; + eval { $dhcp_plugin->after_configure($zoneid, !$any_zone_needs_dhcp) }; warn "Could not run after_configure for DHCP server $zoneid $@\n" if $@; } diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index a9843bf..6dd9d9e 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -21,6 +21,18 @@ sub type { return 'dnsmasq'; } +my sub assert_dnsmasq_installed { + my ($noerr) = @_; + + my $bin_path = "/usr/sbin/dnsmasq"; + if (!-e $bin_path) { + log_warn("please install the 'dnsmasq' package in order to use the DHCP feature!"); + return if $noerr; # just ignore, e.g., in case zone doesn't use DHCP at all + die "cannot reload with missing 'dnsmasq' package\n"; + } + return 1; +} + sub add_ip_mapping { my ($class, $dhcpid, $macdb, $mac, $ip4, $ip6) = @_; @@ -226,7 +238,9 @@ CFG } sub after_configure { - my ($class, $dhcpid) = @_; + my ($class, $dhcpid, $noerr) = @_; + + return if !assert_dnsmasq_installed($noerr); my $service_name = "dnsmasq\@$dhcpid"; @@ -236,13 +250,9 @@ sub after_configure { } sub before_regenerate { - my ($class) = @_; + my ($class, $noerr) = @_; - my $bin_path = "/usr/sbin/dnsmasq"; - if (!-e $bin_path) { - log_warn("Please install dnsmasq in order to use the DHCP feature!"); - die; - } + return if !assert_dnsmasq_installed($noerr); PVE::Tools::run_command(['systemctl', 'stop', "dnsmasq@*"]); PVE::Tools::run_command(['systemctl', 'disable', 'dnsmasq@']);