diff options
Diffstat (limited to 'libnm-core/nm-setting-ip-config.c')
| -rw-r--r-- | libnm-core/nm-setting-ip-config.c | 98 |
1 files changed, 40 insertions, 58 deletions
diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 7f1690ac..55cec35f 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -50,19 +50,6 @@ const NMUtilsDNSOptionDesc _nm_utils_dns_option_descs[] = { { NULL, FALSE, FALSE } }; -static int -_addr_size (int family) -{ - switch (family) { - case AF_INET: - return sizeof (in_addr_t); - case AF_INET6: - return sizeof (struct in6_addr); - default: - g_return_val_if_reached (0); - } -} - static char * canonicalize_ip (int family, const char *ip, gboolean null_any) { @@ -84,7 +71,7 @@ canonicalize_ip (int family, const char *ip, gboolean null_any) g_return_val_if_fail (ret == 1, NULL); if (null_any) { - if (!memcmp (addr_bytes, &in6addr_any, _addr_size (family))) + if (!memcmp (addr_bytes, &in6addr_any, nm_utils_addr_family_to_size (family))) return NULL; } @@ -106,7 +93,7 @@ canonicalize_ip_binary (int family, gconstpointer ip, gboolean null_any) g_return_val_if_reached (NULL); } if (null_any) { - if (!memcmp (ip, &in6addr_any, _addr_size (family))) + if (!memcmp (ip, &in6addr_any, nm_utils_addr_family_to_size (family))) return NULL; } return g_strdup (inet_ntop (family, ip, string, sizeof (string))); @@ -120,7 +107,7 @@ valid_ip (int family, const char *ip, GError **error) family == AF_INET ? _("Missing IPv4 address") : _("Missing IPv6 address")); return FALSE; } - if (!nm_utils_ipaddr_valid (family, ip)) { + if (!nm_utils_ipaddr_is_valid (family, ip)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, family == AF_INET ? _("Invalid IPv4 address '%s'") : _("Invalid IPv6 address '%s'"), ip); @@ -446,7 +433,7 @@ nm_ip_address_set_address (NMIPAddress *address, { g_return_if_fail (address != NULL); g_return_if_fail (addr != NULL); - g_return_if_fail (nm_utils_ipaddr_valid (address->family, addr)); + g_return_if_fail (nm_utils_ipaddr_is_valid (address->family, addr)); g_free (address->address); address->address = canonicalize_ip (address->family, addr, FALSE); @@ -900,14 +887,14 @@ nm_ip_route_get_dest (NMIPRoute *route) * Sets the destination property of this route object. * * @dest must be a valid address of @route's family. If you aren't sure you - * have a valid address, use nm_utils_ipaddr_valid() to check it. + * have a valid address, use nm_utils_ipaddr_is_valid() to check it. **/ void nm_ip_route_set_dest (NMIPRoute *route, const char *dest) { g_return_if_fail (route != NULL); - g_return_if_fail (nm_utils_ipaddr_valid (route->family, dest)); + g_return_if_fail (nm_utils_ipaddr_is_valid (route->family, dest)); g_free (route->dest); route->dest = canonicalize_ip (route->family, dest, FALSE); @@ -1022,7 +1009,7 @@ nm_ip_route_set_next_hop (NMIPRoute *route, const char *next_hop) { g_return_if_fail (route != NULL); - g_return_if_fail (!next_hop || nm_utils_ipaddr_valid (route->family, next_hop)); + g_return_if_fail (!next_hop || nm_utils_ipaddr_is_valid (route->family, next_hop)); g_free (route->next_hop); route->next_hop = canonicalize_ip (route->family, next_hop, TRUE); @@ -1051,7 +1038,7 @@ nm_ip_route_get_next_hop_binary (NMIPRoute *route, inet_pton (route->family, route->next_hop, next_hop); return TRUE; } else { - memset (next_hop, 0, _addr_size (route->family)); + memset (next_hop, 0, nm_utils_addr_family_to_size (route->family)); return FALSE; } } @@ -1310,7 +1297,7 @@ nm_ip_route_attribute_validate (const char *name, switch (spec->str_type) { case 'a': /* IP address */ - if (!nm_utils_ipaddr_valid (family, string)) { + if (!nm_utils_ipaddr_is_valid (family, string)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -1338,7 +1325,7 @@ nm_ip_route_attribute_validate (const char *name, return FALSE; } } - if (!nm_utils_ipaddr_valid (family, addr)) { + if (!nm_utils_ipaddr_is_valid (family, addr)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, @@ -3598,27 +3585,27 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMSettingIPConfig, ); typedef struct { - char *method; - GPtrArray *dns; /* array of IP address strings */ - GPtrArray *dns_search; /* array of domain name strings */ - GPtrArray *dns_options;/* array of DNS options */ - int dns_priority; - GPtrArray *addresses; /* array of NMIPAddress */ - GPtrArray *routes; /* array of NMIPRoute */ + GPtrArray *dns; /* array of IP address strings */ + GPtrArray *dns_search; /* array of domain name strings */ + GPtrArray *dns_options; /* array of DNS options */ + GPtrArray *addresses; /* array of NMIPAddress */ + GPtrArray *routes; /* array of NMIPRoute */ GPtrArray *routing_rules; - gint64 route_metric; - guint32 route_table; + char *method; char *gateway; - gboolean ignore_auto_routes; - gboolean ignore_auto_dns; char *dhcp_hostname; - gboolean dhcp_send_hostname; - gboolean never_default; - gboolean may_fail; - int dad_timeout; - int dhcp_timeout; char *dhcp_iaid; + gint64 route_metric; guint dhcp_hostname_flags; + int dns_priority; + int dad_timeout; + int dhcp_timeout; + guint32 route_table; + bool ignore_auto_routes:1; + bool ignore_auto_dns:1; + bool dhcp_send_hostname:1; + bool never_default:1; + bool may_fail:1; } NMSettingIPConfigPrivate; G_DEFINE_ABSTRACT_TYPE (NMSettingIPConfig, nm_setting_ip_config, NM_TYPE_SETTING) @@ -3698,7 +3685,7 @@ nm_setting_ip_config_add_dns (NMSettingIPConfig *setting, const char *dns) g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE); g_return_val_if_fail (dns != NULL, FALSE); - g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE); + g_return_val_if_fail (nm_utils_ipaddr_is_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE); priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting); @@ -3754,7 +3741,7 @@ nm_setting_ip_config_remove_dns_by_value (NMSettingIPConfig *setting, const char g_return_val_if_fail (NM_IS_SETTING_IP_CONFIG (setting), FALSE); g_return_val_if_fail (dns != NULL, FALSE); - g_return_val_if_fail (nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE); + g_return_val_if_fail (nm_utils_ipaddr_is_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns), FALSE); priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting); @@ -4959,7 +4946,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) for (i = 0; i < priv->dns->len; i++) { const char *dns = priv->dns->pdata[i]; - if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns)) { + if (!nm_utils_ipaddr_is_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), dns)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -5019,7 +5006,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (!nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), priv->gateway)) { + if (!nm_utils_ipaddr_is_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), priv->gateway)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, @@ -5441,7 +5428,7 @@ set_property (GObject *object, guint prop_id, break; case PROP_GATEWAY: gateway = g_value_get_string (value); - g_return_if_fail (!gateway || nm_utils_ipaddr_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway)); + g_return_if_fail (!gateway || nm_utils_ipaddr_is_valid (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway)); g_free (priv->gateway); priv->gateway = canonicalize_ip (NM_SETTING_IP_CONFIG_GET_FAMILY (setting), gateway, TRUE); break; @@ -5501,11 +5488,14 @@ nm_setting_ip_config_init (NMSettingIPConfig *setting) { NMSettingIPConfigPrivate *priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting); - priv->dns = g_ptr_array_new_with_free_func (g_free); - priv->dns_search = g_ptr_array_new_with_free_func (g_free); - priv->dns_options = NULL; - priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); - priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); + priv->dns = g_ptr_array_new_with_free_func (g_free); + priv->dns_search = g_ptr_array_new_with_free_func (g_free); + priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref); + priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref); + priv->route_metric = -1; + priv->dhcp_send_hostname = TRUE; + priv->may_fail = TRUE; + priv->dad_timeout = -1; } static void @@ -5628,7 +5618,7 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) * The relative priority for DNS servers specified by this setting. A lower * value is better (higher priority). Zero selects a globally configured * default value. If the latter is missing or zero too, it defaults to - * 50 for VPNs and 100 for other connections. + * 50 for VPNs (including WireGuard) and 100 for other connections. * * Note that the priority is to order DNS settings for multiple active * connections. It does not disambiguate multiple DNS servers within the @@ -5660,7 +5650,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_int (NM_SETTING_IP_CONFIG_DNS_PRIORITY, "", "", G_MININT32, G_MAXINT32, 0, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5725,7 +5714,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_int64 (NM_SETTING_IP_CONFIG_ROUTE_METRIC, "", "", -1, G_MAXUINT32, -1, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5766,7 +5754,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, "", "", FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5782,7 +5769,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_boolean (NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, "", "", FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5812,7 +5798,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_boolean (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, "", "", TRUE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5826,7 +5811,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_boolean (NM_SETTING_IP_CONFIG_NEVER_DEFAULT, "", "", FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5844,7 +5828,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_boolean (NM_SETTING_IP_CONFIG_MAY_FAIL, "", "", TRUE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** @@ -5865,7 +5848,6 @@ nm_setting_ip_config_class_init (NMSettingIPConfigClass *klass) g_param_spec_int (NM_SETTING_IP_CONFIG_DAD_TIMEOUT, "", "", -1, NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX, -1, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS); |