summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-04-23 11:49:45 +0200
committerThomas Haller <thaller@redhat.com>2021-04-27 08:03:40 +0200
commit234ee217aca08326694dee23cf9c7867f6429d01 (patch)
tree5b3a876bb0660f7ada6f86f54f16205bc88eaeb3
parentde706a21139e54644e516886427564dce8357a69 (diff)
downloadNetworkManager-234ee217aca08326694dee23cf9c7867f6429d01.tar.gz
dhcp: add client_flags argument to nm_dhcp_manager_start_ip[46]()
-rw-r--r--src/core/devices/nm-device.c4
-rw-r--r--src/core/dhcp/nm-dhcp-client.c21
-rw-r--r--src/core/dhcp/nm-dhcp-manager.c122
-rw-r--r--src/core/dhcp/nm-dhcp-manager.h3
-rw-r--r--src/core/nm-iface-helper.c1
5 files changed, 92 insertions, 59 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index 73480bce0c..a5714f1f74 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -9482,6 +9482,7 @@ dhcp4_start(NMDevice *self)
nm_connection_get_uuid(connection),
nm_device_get_route_table(self, AF_INET),
nm_device_get_route_metric(self, AF_INET),
+ NM_DHCP_CLIENT_FLAGS_NONE,
nm_setting_ip_config_get_dhcp_send_hostname(s_ip4),
nm_setting_ip_config_get_dhcp_hostname(s_ip4),
nm_setting_ip4_config_get_dhcp_fqdn(NM_SETTING_IP4_CONFIG(s_ip4)),
@@ -9931,6 +9932,8 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection)
nm_connection_get_uuid(connection),
nm_device_get_route_table(self, AF_INET6),
nm_device_get_route_metric(self, AF_INET6),
+ (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) ? NM_DHCP_CLIENT_FLAGS_INFO_ONLY
+ : NM_DHCP_CLIENT_FLAGS_NONE,
nm_setting_ip_config_get_dhcp_send_hostname(s_ip6),
nm_setting_ip_config_get_dhcp_hostname(s_ip6),
_prop_get_ipvx_dhcp_hostname_flags(self, AF_INET6),
@@ -9941,7 +9944,6 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection)
iaid_explicit,
_prop_get_ipvx_dhcp_timeout(self, AF_INET6),
priv->dhcp_anycast_address,
- (priv->dhcp6.mode == NM_NDISC_DHCP_LEVEL_OTHERCONF) ? TRUE : FALSE,
nm_setting_ip6_config_get_ip6_privacy(NM_SETTING_IP6_CONFIG(s_ip6)),
priv->dhcp6.needed_prefixes,
&error);
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index 00e84d1008..ab0ce4f9b6 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -1141,6 +1141,24 @@ nm_dhcp_client_init(NMDhcpClient *self)
priv->pid = -1;
}
+#if NM_MORE_ASSERTS
+static void
+constructed(GObject *object)
+{
+ NMDhcpClient * self = NM_DHCP_CLIENT(object);
+ NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
+
+ /* certain flags only make sense with certain address family. Assert
+ * for that. */
+ if (NM_IS_IPv4(priv->addr_family))
+ nm_assert(!NM_FLAGS_ANY(priv->client_flags, NM_DHCP_CLIENT_FLAGS_INFO_ONLY));
+ else
+ nm_assert(NM_FLAGS_HAS(priv->client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN));
+
+ G_OBJECT_CLASS(nm_dhcp_client_parent_class)->constructed(object);
+}
+#endif
+
static void
dispose(GObject *object)
{
@@ -1179,6 +1197,9 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class)
g_type_class_add_private(client_class, sizeof(NMDhcpClientPrivate));
+#if NM_MORE_ASSERTS
+ object_class->constructed = constructed;
+#endif
object_class->dispose = dispose;
object_class->get_property = get_property;
object_class->set_property = set_property;
diff --git a/src/core/dhcp/nm-dhcp-manager.c b/src/core/dhcp/nm-dhcp-manager.c
index 0725a6666b..2a59571cf3 100644
--- a/src/core/dhcp/nm-dhcp-manager.c
+++ b/src/core/dhcp/nm-dhcp-manager.c
@@ -240,6 +240,7 @@ client_start(NMDhcpManager * self,
|| g_bytes_get_size(vendor_class_identifier) <= 255,
NULL);
g_return_val_if_fail(!error || !*error, NULL);
+ nm_assert(!NM_FLAGS_ANY(client_flags, ~NM_DHCP_CLIENT_FLAGS_ALL));
if (addr_family == AF_INET) {
if (!hwaddr || !bcast_hwaddr) {
@@ -406,6 +407,7 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self,
const char * uuid,
guint32 route_table,
guint32 route_metric,
+ NMDhcpClientFlags client_flags,
gboolean send_hostname,
const char * dhcp_hostname,
const char * dhcp_fqdn,
@@ -425,6 +427,10 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self,
gboolean use_fqdn = FALSE;
char * dot;
+ /* these flags are set automatically/prohibited, and not free to set to the caller. */
+ nm_assert(!NM_FLAGS_ANY(client_flags,
+ NM_DHCP_CLIENT_FLAGS_USE_FQDN | NM_DHCP_CLIENT_FLAGS_INFO_ONLY));
+
g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE(self);
@@ -451,33 +457,34 @@ nm_dhcp_manager_start_ip4(NMDhcpManager * self,
}
}
- return client_start(self,
- AF_INET,
- multi_idx,
- iface,
- ifindex,
- hwaddr,
- bcast_hwaddr,
- uuid,
- route_table,
- route_metric,
- NULL,
- dhcp_client_id,
- FALSE,
- 0,
- FALSE,
- timeout,
- (use_fqdn ? NM_DHCP_CLIENT_FLAGS_USE_FQDN : NM_DHCP_CLIENT_FLAGS_NONE),
- dhcp_anycast_addr,
- hostname,
- hostname_flags,
- mud_url,
- 0,
- last_ip_address,
- 0,
- vendor_class_identifier,
- reject_servers,
- error);
+ return client_start(
+ self,
+ AF_INET,
+ multi_idx,
+ iface,
+ ifindex,
+ hwaddr,
+ bcast_hwaddr,
+ uuid,
+ route_table,
+ route_metric,
+ NULL,
+ dhcp_client_id,
+ FALSE,
+ 0,
+ FALSE,
+ timeout,
+ client_flags | (use_fqdn ? NM_DHCP_CLIENT_FLAGS_USE_FQDN : NM_DHCP_CLIENT_FLAGS_NONE),
+ dhcp_anycast_addr,
+ hostname,
+ hostname_flags,
+ mud_url,
+ 0,
+ last_ip_address,
+ 0,
+ vendor_class_identifier,
+ reject_servers,
+ error);
}
/* Caller owns a reference to the NMDhcpClient on return */
@@ -490,6 +497,7 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self,
const char * uuid,
guint32 route_table,
guint32 route_metric,
+ NMDhcpClientFlags client_flags,
gboolean send_hostname,
const char * dhcp_hostname,
NMDhcpHostnameFlags hostname_flags,
@@ -500,7 +508,6 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self,
gboolean iaid_explicit,
guint32 timeout,
const char * dhcp_anycast_addr,
- gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
guint needed_prefixes,
GError ** error)
@@ -508,6 +515,9 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self,
NMDhcpManagerPrivate *priv;
const char * hostname = NULL;
+ /* this flag is set automatically, and not free to set to the caller. */
+ nm_assert(!NM_FLAGS_ANY(client_flags, NM_DHCP_CLIENT_FLAGS_USE_FQDN));
+
g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE(self);
@@ -515,35 +525,33 @@ nm_dhcp_manager_start_ip6(NMDhcpManager * self,
/* Always prefer the explicit dhcp-hostname if given */
hostname = dhcp_hostname ?: priv->default_hostname;
}
- return client_start(
- self,
- AF_INET6,
- multi_idx,
- iface,
- ifindex,
- NULL,
- NULL,
- uuid,
- route_table,
- route_metric,
- ll_addr,
- duid,
- enforce_duid,
- iaid,
- iaid_explicit,
- timeout,
- NM_DHCP_CLIENT_FLAGS_USE_FQDN
- | (info_only ? NM_DHCP_CLIENT_FLAGS_INFO_ONLY : NM_DHCP_CLIENT_FLAGS_NONE),
- dhcp_anycast_addr,
- hostname,
- hostname_flags,
- mud_url,
- privacy,
- NULL,
- needed_prefixes,
- NULL,
- NULL,
- error);
+ return client_start(self,
+ AF_INET6,
+ multi_idx,
+ iface,
+ ifindex,
+ NULL,
+ NULL,
+ uuid,
+ route_table,
+ route_metric,
+ ll_addr,
+ duid,
+ enforce_duid,
+ iaid,
+ iaid_explicit,
+ timeout,
+ client_flags | NM_DHCP_CLIENT_FLAGS_USE_FQDN,
+ dhcp_anycast_addr,
+ hostname,
+ hostname_flags,
+ mud_url,
+ privacy,
+ NULL,
+ needed_prefixes,
+ NULL,
+ NULL,
+ error);
}
void
diff --git a/src/core/dhcp/nm-dhcp-manager.h b/src/core/dhcp/nm-dhcp-manager.h
index f7aba8a023..8f6c62afec 100644
--- a/src/core/dhcp/nm-dhcp-manager.h
+++ b/src/core/dhcp/nm-dhcp-manager.h
@@ -41,6 +41,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip4(NMDhcpManager * manager,
const char * uuid,
guint32 route_table,
guint32 route_metric,
+ NMDhcpClientFlags client_flags,
gboolean send_hostname,
const char * dhcp_hostname,
const char * dhcp_fqdn,
@@ -62,6 +63,7 @@ NMDhcpClient *nm_dhcp_manager_start_ip6(NMDhcpManager * manager,
const char * uuid,
guint32 route_table,
guint32 route_metric,
+ NMDhcpClientFlags client_flags,
gboolean send_hostname,
const char * dhcp_hostname,
NMDhcpHostnameFlags hostname_flags,
@@ -72,7 +74,6 @@ NMDhcpClient *nm_dhcp_manager_start_ip6(NMDhcpManager * manager,
gboolean iaid_explicit,
guint32 timeout,
const char * dhcp_anycast_addr,
- gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
guint needed_prefixes,
GError ** error);
diff --git a/src/core/nm-iface-helper.c b/src/core/nm-iface-helper.c
index c4d87b96e4..227363deac 100644
--- a/src/core/nm-iface-helper.c
+++ b/src/core/nm-iface-helper.c
@@ -668,6 +668,7 @@ main(int argc, char *argv[])
global_opt.uuid,
RT_TABLE_MAIN,
global_opt.priority_v4,
+ NM_DHCP_CLIENT_FLAGS_NONE,
!!global_opt.dhcp4_hostname,
global_opt.dhcp4_hostname,
global_opt.dhcp4_fqdn,