mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 21:00:16 +01:00
dhcp: merge branch 'th/dhcp-factory-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/896
This commit is contained in:
commit
acd1a54d8f
8 changed files with 43 additions and 55 deletions
|
|
@ -217,11 +217,13 @@ gboolean nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer
|
|||
*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
GType (*get_type)(void);
|
||||
GType (*get_type_per_addr_family)(int addr_family);
|
||||
GType (*get_type_4)(void);
|
||||
GType (*get_type_6)(void);
|
||||
const char *name;
|
||||
const char *(*get_path)(void);
|
||||
bool experimental : 1;
|
||||
|
||||
/* whether this plugin is an undocumented, internal plugin. */
|
||||
bool undocumented : 1;
|
||||
} NMDhcpClientFactory;
|
||||
|
||||
GType nm_dhcp_nettools_get_type(void);
|
||||
|
|
|
|||
|
|
@ -731,9 +731,10 @@ nm_dhcp_dhclient_class_init(NMDhcpDhclientClass *dhclient_class)
|
|||
}
|
||||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient = {
|
||||
.name = "dhclient",
|
||||
.get_type = nm_dhcp_dhclient_get_type,
|
||||
.get_path = nm_dhcp_dhclient_get_path,
|
||||
.name = "dhclient",
|
||||
.get_type_4 = nm_dhcp_dhclient_get_type,
|
||||
.get_type_6 = nm_dhcp_dhclient_get_type,
|
||||
.get_path = nm_dhcp_dhclient_get_path,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCLIENT */
|
||||
|
|
|
|||
|
|
@ -232,9 +232,9 @@ nm_dhcp_dhcpcanon_class_init(NMDhcpDhcpcanonClass *dhcpcanon_class)
|
|||
}
|
||||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon = {
|
||||
.name = "dhcpcanon",
|
||||
.get_type = nm_dhcp_dhcpcanon_get_type,
|
||||
.get_path = nm_dhcp_dhcpcanon_get_path,
|
||||
.name = "dhcpcanon",
|
||||
.get_type_4 = nm_dhcp_dhcpcanon_get_type,
|
||||
.get_path = nm_dhcp_dhcpcanon_get_path,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCPCANON */
|
||||
|
|
|
|||
|
|
@ -233,9 +233,9 @@ nm_dhcp_dhcpcd_class_init(NMDhcpDhcpcdClass *dhcpcd_class)
|
|||
}
|
||||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd = {
|
||||
.name = "dhcpcd",
|
||||
.get_type = nm_dhcp_dhcpcd_get_type,
|
||||
.get_path = nm_dhcp_dhcpcd_get_path,
|
||||
.name = "dhcpcd",
|
||||
.get_type_4 = nm_dhcp_dhcpcd_get_type,
|
||||
.get_path = nm_dhcp_dhcpcd_get_path,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCPCD */
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
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. */
|
||||
* the first available plugin. */
|
||||
|
||||
#if WITH_DHCPCANON
|
||||
&_nm_dhcp_client_factory_dhcpcanon,
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ _client_factory_find_by_name(const char *name)
|
|||
{
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail(name, NULL);
|
||||
nm_assert(name);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
const NMDhcpClientFactory *f = _nm_dhcp_manager_factories[i];
|
||||
|
||||
if (f && nm_streq(f->name, name))
|
||||
|
|
@ -85,11 +85,10 @@ _client_factory_available(const NMDhcpClientFactory *client_factory)
|
|||
static GType
|
||||
_client_factory_get_gtype(const NMDhcpClientFactory *client_factory, int addr_family)
|
||||
{
|
||||
GType gtype;
|
||||
nm_auto_unref_gtypeclass NMDhcpClientClass *klass = NULL;
|
||||
GType gtype;
|
||||
GType (*get_type_fcn)(void);
|
||||
|
||||
nm_assert(client_factory);
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
/* currently, the chosen DHCP plugin for IPv4 and IPv6 is configured in NetworkManager.conf
|
||||
* and cannot be reloaded. It would be nice to configure the plugin per address family
|
||||
|
|
@ -111,29 +110,22 @@ _client_factory_get_gtype(const NMDhcpClientFactory *client_factory, int addr_fa
|
|||
* to those plugins. But we don't intend to do so. The internal plugin is the way forward and
|
||||
* not extending other plugins. */
|
||||
|
||||
if (client_factory->get_type_per_addr_family)
|
||||
gtype = client_factory->get_type_per_addr_family(addr_family);
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
get_type_fcn = client_factory->get_type_4;
|
||||
else
|
||||
gtype = client_factory->get_type();
|
||||
get_type_fcn = client_factory->get_type_6;
|
||||
|
||||
if (client_factory == &_nm_dhcp_client_factory_internal) {
|
||||
/* we are already using the internal plugin. Nothing to do. */
|
||||
goto out;
|
||||
if (!get_type_fcn) {
|
||||
/* If the factory does not support the address family, we always
|
||||
* fallback to the internal. */
|
||||
if (NM_IS_IPv4(addr_family))
|
||||
get_type_fcn = _nm_dhcp_client_factory_internal.get_type_4;
|
||||
else
|
||||
get_type_fcn = _nm_dhcp_client_factory_internal.get_type_6;
|
||||
}
|
||||
|
||||
klass = g_type_class_ref(gtype);
|
||||
gtype = get_type_fcn();
|
||||
|
||||
nm_assert(NM_IS_DHCP_CLIENT_CLASS(klass));
|
||||
|
||||
if (addr_family == AF_INET6) {
|
||||
if (!klass->ip6_start)
|
||||
gtype = _client_factory_get_gtype(&_nm_dhcp_client_factory_internal, addr_family);
|
||||
} else {
|
||||
if (!klass->ip4_start)
|
||||
gtype = _client_factory_get_gtype(&_nm_dhcp_client_factory_internal, addr_family);
|
||||
}
|
||||
|
||||
out:
|
||||
nm_assert(g_type_is_a(gtype, NM_TYPE_DHCP_CLIENT));
|
||||
nm_assert(({
|
||||
nm_auto_unref_gtypeclass NMDhcpClientClass *k = g_type_class_ref(gtype);
|
||||
|
|
@ -598,7 +590,7 @@ nm_dhcp_manager_init(NMDhcpManager *self)
|
|||
|
||||
c_list_init(&priv->dhcp_client_lst_head);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
const NMDhcpClientFactory *f = _nm_dhcp_manager_factories[i];
|
||||
|
||||
if (!f)
|
||||
|
|
@ -608,7 +600,7 @@ nm_dhcp_manager_init(NMDhcpManager *self)
|
|||
"dhcp-init: enabled DHCP client '%s'%s%s",
|
||||
f->name,
|
||||
_client_factory_available(f) ? "" : " (not available)",
|
||||
f->experimental ? " (undocumented internal plugin)" : "");
|
||||
f->undocumented ? " (undocumented internal plugin)" : "");
|
||||
}
|
||||
|
||||
/* Client-specific setup */
|
||||
|
|
@ -644,7 +636,7 @@ nm_dhcp_manager_init(NMDhcpManager *self)
|
|||
}
|
||||
}
|
||||
if (!client_factory) {
|
||||
for (i = 0; i < G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
|
||||
client_factory = _client_factory_available(_nm_dhcp_manager_factories[i]);
|
||||
if (client_factory)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1248,6 +1248,6 @@ nm_dhcp_nettools_class_init(NMDhcpNettoolsClass *class)
|
|||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_nettools = {
|
||||
.name = "nettools",
|
||||
.get_type = nm_dhcp_nettools_get_type,
|
||||
.experimental = TRUE,
|
||||
.get_type_4 = nm_dhcp_nettools_get_type,
|
||||
.undocumented = TRUE,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1124,23 +1124,15 @@ nm_dhcp_systemd_class_init(NMDhcpSystemdClass *sdhcp_class)
|
|||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_systemd = {
|
||||
.name = "systemd",
|
||||
.get_type = nm_dhcp_systemd_get_type,
|
||||
.experimental = TRUE,
|
||||
.get_type_4 = nm_dhcp_systemd_get_type,
|
||||
.get_type_6 = nm_dhcp_systemd_get_type,
|
||||
.undocumented = TRUE,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static GType
|
||||
_get_type_per_addr_family(int addr_family)
|
||||
{
|
||||
nm_assert_addr_family(addr_family);
|
||||
|
||||
if (addr_family == AF_INET)
|
||||
return nm_dhcp_nettools_get_type();
|
||||
return nm_dhcp_systemd_get_type();
|
||||
}
|
||||
|
||||
const NMDhcpClientFactory _nm_dhcp_client_factory_internal = {
|
||||
.name = "internal",
|
||||
.get_type_per_addr_family = _get_type_per_addr_family,
|
||||
.name = "internal",
|
||||
.get_type_4 = nm_dhcp_nettools_get_type,
|
||||
.get_type_6 = nm_dhcp_systemd_get_type,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue