Commit b53e2614 authored by Thomas Haller's avatar Thomas Haller

dhcp: make "systemd" DHCP plugin configurable

We have the "internal" DHCP plugin. That's our preferred plugin,
and eventually we may drop all other plugins.

Currently, the "internal" plugin is based on code from systemd-networkd
and implemented in "src/dhcp/nm-dhcp-systemd.c". As this code is forked
we eventually want to switch to nettools' n-dhcp4 library (for IPv4).
For that reason we already have "src/dhcp/nm-dhcp-nettools.c".

Note that "nettools" can be configured as a DHCP plugin, but this configuration
is only experimental and for testing. There is never supposed to be a
"nettools" plugin, but eventually the "internal" plugin will switch
implementation.

We don't want to replace systemd-based implementation right away. Not until
we are sure that nettools works well. For that reason we keep them
both in parallel for a while.

This commit makes "systemd" DHCP plugin explicitly configurable
in NetworkManager.conf. Like "nettools" this is an undocumented option,
only for testing.

If you choose "internal" (the default), you get one of the
implementations (currently the "systemd" one). But by selecting
"systemd" or "nettools" explicitly, you can select the exact plugin.
parent 8d8cc0da
......@@ -207,15 +207,18 @@ void nm_dhcp_client_set_client_id_bin (NMDhcpClient *self,
*****************************************************************************/
typedef struct {
GType (*get_type)(void);
GType (*get_type) (void);
GType (*get_type_per_addr_family) (int addr_family);
const char *name;
const char *(*get_path) (void);
bool experimental:1;
} NMDhcpClientFactory;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_internal;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_systemd;
extern const NMDhcpClientFactory _nm_dhcp_client_factory_nettools;
#endif /* __NETWORKMANAGER_DHCP_CLIENT_H__ */
......@@ -723,7 +723,7 @@ nm_dhcp_dhclient_class_init (NMDhcpDhclientClass *dhclient_class)
}
const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient = {
.name = "dhclient",
.name = "dhclient",
.get_type = nm_dhcp_dhclient_get_type,
.get_path = nm_dhcp_dhclient_get_path,
};
......
......@@ -248,7 +248,7 @@ nm_dhcp_dhcpcanon_class_init (NMDhcpDhcpcanonClass *dhcpcanon_class)
}
const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon = {
.name = "dhcpcanon",
.name = "dhcpcanon",
.get_type = nm_dhcp_dhcpcanon_get_type,
.get_path = nm_dhcp_dhcpcanon_get_path,
};
......
......@@ -242,7 +242,7 @@ nm_dhcp_dhcpcd_class_init (NMDhcpDhcpcdClass *dhcpcd_class)
}
const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd = {
.name = "dhcpcd",
.name = "dhcpcd",
.get_type = nm_dhcp_dhcpcd_get_type,
.get_path = nm_dhcp_dhcpcd_get_path,
};
......
......@@ -38,7 +38,7 @@
/*****************************************************************************/
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5] = {
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[6] = {
/* the order here matters, as we will try the plugins in this order to find
* the first available plugin. */
......@@ -52,6 +52,7 @@ const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5] = {
&_nm_dhcp_client_factory_dhcpcd,
#endif
&_nm_dhcp_client_factory_internal,
&_nm_dhcp_client_factory_systemd,
&_nm_dhcp_client_factory_nettools,
};
......
......@@ -119,7 +119,10 @@ _client_factory_get_gtype (const NMDhcpClientFactory *client_factory,
* to those plugins. But we don't intend to do so. The internal plugin is the way forward and
* not extending other plugins. */
gtype = client_factory->get_type ();
if (client_factory->get_type_per_addr_family)
gtype = client_factory->get_type_per_addr_family (addr_family);
else
gtype = client_factory->get_type ();
if (client_factory == &_nm_dhcp_client_factory_internal) {
/* we are already using the internal plugin. Nothing to do. */
......@@ -547,9 +550,10 @@ nm_dhcp_manager_init (NMDhcpManager *self)
if (!f)
continue;
nm_log_dbg (LOGD_DHCP, "dhcp-init: enabled DHCP client '%s' (%s)%s",
f->name, g_type_name (f->get_type ()),
_client_factory_available (f) ? "" : " (not available)");
nm_log_dbg (LOGD_DHCP, "dhcp-init: enabled DHCP client '%s'%s%s",
f->name,
_client_factory_available (f) ? "" : " (not available)",
f->experimental ? " (undocumented internal plugin)" : "");
}
/* Client-specific setup */
......
......@@ -86,7 +86,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
/* For testing only */
extern const char* nm_dhcp_helper_path;
extern const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5];
extern const NMDhcpClientFactory *const _nm_dhcp_manager_factories[6];
void nmtst_dhcp_manager_unget (gpointer singleton_instance);
......
......@@ -1272,7 +1272,7 @@ nm_dhcp_nettools_class_init (NMDhcpNettoolsClass *class)
}
const NMDhcpClientFactory _nm_dhcp_client_factory_nettools = {
.name = "nettools",
.get_type = nm_dhcp_nettools_get_type,
.get_path = NULL,
.name = "nettools",
.get_type = nm_dhcp_nettools_get_type,
.experimental = TRUE,
};
......@@ -1173,8 +1173,23 @@ nm_dhcp_systemd_class_init (NMDhcpSystemdClass *sdhcp_class)
client_class->stop = stop;
}
const NMDhcpClientFactory _nm_dhcp_client_factory_systemd = {
.name = "systemd",
.get_type = nm_dhcp_systemd_get_type,
.experimental = TRUE,
};
/*****************************************************************************/
static GType
_get_type_per_addr_family (int addr_family)
{
nm_assert_addr_family (addr_family);
return nm_dhcp_systemd_get_type ();
}
const NMDhcpClientFactory _nm_dhcp_client_factory_internal = {
.name = "internal",
.get_type = nm_dhcp_systemd_get_type,
.get_path = NULL,
.name = "internal",
.get_type_per_addr_family = _get_type_per_addr_family,
};
......@@ -596,9 +596,10 @@ main (int argc, char *argv[])
/*****************************************************************************/
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[5] = {
const NMDhcpClientFactory *const _nm_dhcp_manager_factories[6] = {
/* For nm-iface-helper there is no option to choose a DHCP plugin.
* It just uses the "internal" one. */
&_nm_dhcp_client_factory_internal,
&_nm_dhcp_client_factory_nettools,
};
/*****************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment