summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-23 13:14:39 +0200
committerThomas Haller <thaller@redhat.com>2021-06-23 13:14:39 +0200
commitacd1a54d8f14680fc3bcd79f7fff55e6700d1d10 (patch)
tree9a2423a32d94ac8ba776df9cb8298527c8c0f2ce
parent3aad301003f2a623119d5a126ca1b150e24e8ac5 (diff)
parentc5e7e2f69403e59dbc7676ff60ecc1d36a703207 (diff)
dhcp: merge branch 'th/dhcp-factory-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/896
-rw-r--r--src/core/dhcp/nm-dhcp-client.h8
-rw-r--r--src/core/dhcp/nm-dhcp-dhclient.c7
-rw-r--r--src/core/dhcp/nm-dhcp-dhcpcanon.c6
-rw-r--r--src/core/dhcp/nm-dhcp-dhcpcd.c6
-rw-r--r--src/core/dhcp/nm-dhcp-listener.c3
-rw-r--r--src/core/dhcp/nm-dhcp-manager.c46
-rw-r--r--src/core/dhcp/nm-dhcp-nettools.c4
-rw-r--r--src/core/dhcp/nm-dhcp-systemd.c20
8 files changed, 44 insertions, 56 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h
index 3fe1b34ec9..601225ecd6 100644
--- a/src/core/dhcp/nm-dhcp-client.h
+++ b/src/core/dhcp/nm-dhcp-client.h
@@ -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);
diff --git a/src/core/dhcp/nm-dhcp-dhclient.c b/src/core/dhcp/nm-dhcp-dhclient.c
index 4a11250f9b..5077407f0e 100644
--- a/src/core/dhcp/nm-dhcp-dhclient.c
+++ b/src/core/dhcp/nm-dhcp-dhclient.c
@@ -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 */
diff --git a/src/core/dhcp/nm-dhcp-dhcpcanon.c b/src/core/dhcp/nm-dhcp-dhcpcanon.c
index f3a52ea959..2be64c09f2 100644
--- a/src/core/dhcp/nm-dhcp-dhcpcanon.c
+++ b/src/core/dhcp/nm-dhcp-dhcpcanon.c
@@ -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 */
diff --git a/src/core/dhcp/nm-dhcp-dhcpcd.c b/src/core/dhcp/nm-dhcp-dhcpcd.c
index 605fb84df4..86269f9306 100644
--- a/src/core/dhcp/nm-dhcp-dhcpcd.c
+++ b/src/core/dhcp/nm-dhcp-dhcpcd.c
@@ -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 */
diff --git a/src/core/dhcp/nm-dhcp-listener.c b/src/core/dhcp/nm-dhcp-listener.c
index b8bb3c33a0..ae2c40f10f 100644
--- a/src/core/dhcp/nm-dhcp-listener.c
+++ b/src/core/dhcp/nm-dhcp-listener.c
@@ -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,
diff --git a/src/core/dhcp/nm-dhcp-manager.c b/src/core/dhcp/nm-dhcp-manager.c
index 44b8ede2c0..c3328b010b 100644
--- a/src/core/dhcp/nm-dhcp-manager.c
+++ b/src/core/dhcp/nm-dhcp-manager.c
@@ -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();
-
- if (client_factory == &_nm_dhcp_client_factory_internal) {
- /* we are already using the internal plugin. Nothing to do. */
- goto out;
+ get_type_fcn = client_factory->get_type_6;
+
+ 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);
-
- 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);
- }
+ gtype = get_type_fcn();
-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;
diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c
index fe71f587a4..f755eebca3 100644
--- a/src/core/dhcp/nm-dhcp-nettools.c
+++ b/src/core/dhcp/nm-dhcp-nettools.c
@@ -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,
};
diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c
index c789aaee0f..4bb58ee354 100644
--- a/src/core/dhcp/nm-dhcp-systemd.c
+++ b/src/core/dhcp/nm-dhcp-systemd.c
@@ -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,
};