sd-dhcp-relay: reimplement DHCP relay agent and drop legacy DHCP relay mode from sd-dhcp-server (#42130)

This commit is contained in:
Daan De Meyer
2026-05-21 16:23:44 +02:00
committed by GitHub
53 changed files with 2674 additions and 470 deletions
+28
View File
@@ -10,6 +10,7 @@
#include "sd-bus.h"
#include "sd-dhcp-client.h"
#include "sd-dhcp-relay.h"
#include "sd-dhcp-server.h"
#include "sd-dhcp6-client.h"
#include "sd-dhcp6-lease.h"
@@ -41,6 +42,7 @@
#include "networkd-bridge-mdb.h"
#include "networkd-bridge-vlan.h"
#include "networkd-dhcp-prefix-delegation.h"
#include "networkd-dhcp-relay.h"
#include "networkd-dhcp-server.h"
#include "networkd-dhcp4.h"
#include "networkd-dhcp6.h"
@@ -240,6 +242,8 @@ static void link_free_engines(Link *link) {
if (!link)
return;
link->dhcp_relay_interface = sd_dhcp_relay_interface_unref(link->dhcp_relay_interface);
link->dhcp_relay_interface_compat = sd_dhcp_relay_interface_unref(link->dhcp_relay_interface_compat);
link->dhcp_server = sd_dhcp_server_unref(link->dhcp_server);
link->dhcp_client = sd_dhcp_client_unref(link->dhcp_client);
@@ -424,6 +428,14 @@ int link_stop_engines(Link *link, bool may_keep_dynamic) {
ndisc_flush(link);
}
r = sd_dhcp_relay_interface_stop(link->dhcp_relay_interface);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCP relay agent: %m"));
r = sd_dhcp_relay_interface_stop(link->dhcp_relay_interface_compat);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCP relay agent (compat): %m"));
r = sd_dhcp_server_stop(link->dhcp_server);
if (r < 0)
RET_GATHER(ret, log_link_warning_errno(link, r, "Could not stop DHCPv4 server: %m"));
@@ -739,6 +751,10 @@ static int link_acquire_dynamic_ipv4_conf(Link *link) {
log_link_debug(link, "Acquiring IPv4 link-local address.");
}
r = link_start_dhcp_relay(link);
if (r < 0)
return log_link_warning_errno(link, r, "Could not start DHCP relay agent: %m");
r = link_start_dhcp4_server(link);
if (r < 0)
return log_link_warning_errno(link, r, "Could not start DHCP server: %m");
@@ -1196,6 +1212,8 @@ static int link_drop_dynamic_config(Link *link, Network *network) {
RET_GATHER(r, link_drop_dhcp4_config(link, network));
RET_GATHER(r, link_drop_dhcp6_config(link, network));
RET_GATHER(r, link_drop_dhcp_pd_config(link, network));
link->dhcp_relay_interface = sd_dhcp_relay_interface_unref(link->dhcp_relay_interface);
link->dhcp_relay_interface_compat = sd_dhcp_relay_interface_unref(link->dhcp_relay_interface_compat);
link->dhcp_server = sd_dhcp_server_unref(link->dhcp_server);
link->lldp_rx = sd_lldp_rx_unref(link->lldp_rx); /* TODO: keep the received neighbors. */
link->lldp_tx = sd_lldp_tx_unref(link->lldp_tx);
@@ -1314,6 +1332,10 @@ static int link_configure(Link *link) {
if (r < 0)
return r;
r = link_request_dhcp_relay(link);
if (r < 0)
return r;
r = link_request_dhcp_server(link);
if (r < 0)
return r;
@@ -2645,6 +2667,12 @@ static int link_update_name(Link *link, sd_netlink_message *message) {
return log_link_debug_errno(link, r, "Failed to update interface name in NDisc: %m");
}
if (link->dhcp_relay_interface) {
r = sd_dhcp_relay_interface_set_ifname(link->dhcp_relay_interface, link->ifname);
if (r < 0)
return log_link_debug_errno(link, r, "Failed to update interface name in DHCP relay interface: %m");
}
if (link->dhcp_server) {
r = sd_dhcp_server_set_ifname(link->dhcp_server, link->ifname);
if (r < 0)