diff options
| author | Michael Biebl <biebl@debian.org> | 2023-02-10 11:50:34 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2023-02-10 11:50:34 +0100 |
| commit | 1372848511cb896b80b51ed1a3e9606bd9816631 (patch) | |
| tree | 674792b9385bdef935988894b45f06b2af39f88c /src/libnm-core-impl/nm-setting-ip4-config.c | |
| parent | 40ec077ea305994c1fc2130add6787ca0c73e2c6 (diff) | |
New upstream version 1.42.0 upstream/1.42.0
Diffstat (limited to 'src/libnm-core-impl/nm-setting-ip4-config.c')
| -rw-r--r-- | src/libnm-core-impl/nm-setting-ip4-config.c | 191 |
1 files changed, 117 insertions, 74 deletions
diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index d991152c..f847918e 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -138,7 +138,7 @@ nm_setting_ip4_config_get_dhcp_vendor_class_identifier(NMSettingIP4Config *setti * * Returns: the link-local configuration * - * Since: 1.42, 1.40.4 + * Since: 1.42 **/ NMSettingIP4LinkLocal nm_setting_ip4_config_get_link_local(NMSettingIP4Config *setting) @@ -388,21 +388,29 @@ ip4_dns_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) GPtrArray *dns; dns = _nm_setting_ip_config_get_dns_array(NM_SETTING_IP_CONFIG(setting)); - if (nm_g_ptr_array_len(dns) == 0) return NULL; - return _nm_utils_ip4_dns_to_variant((const char *const *) dns->pdata, dns->len); + return nm_utils_dns_to_variant(AF_INET, (const char *const *) dns->pdata, dns->len); } -static void -ip4_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_GPROP_FCN_ARGS _nm_nil) +static gboolean +ip4_dns_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - g_value_take_boxed(to, nm_utils_ip4_dns_from_variant(from)); + gs_strfreev char **strv = NULL; + + if (!_nm_setting_use_legacy_property(setting, connection_dict, "dns", "dns-data")) { + *out_is_modified = FALSE; + return TRUE; + } + + strv = nm_utils_ip4_dns_from_variant(value); + g_object_set(setting, NM_SETTING_IP_CONFIG_DNS, strv, NULL); + return TRUE; } static GVariant * -ip4_addresses_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) +ip4_addresses_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *addrs = NULL; const char *gateway; @@ -413,12 +421,13 @@ ip4_addresses_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) } static gboolean -ip4_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) +ip4_addresses_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - GPtrArray *addrs; - GVariant *s_ip4; - char **labels, *gateway = NULL; - int i; + gs_unref_ptrarray GPtrArray *addrs = NULL; + gs_unref_variant GVariant *s_ip4 = NULL; + gs_free const char **labels = NULL; + gs_free char *gateway = NULL; + guint i; /* FIXME: properly handle errors */ @@ -432,15 +441,15 @@ ip4_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) s_ip4 = g_variant_lookup_value(connection_dict, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_VARIANT_TYPE_SETTING); - if (g_variant_lookup(s_ip4, "address-labels", "^as", &labels)) { - for (i = 0; i < addrs->len && labels[i]; i++) - if (*labels[i]) + if (g_variant_lookup(s_ip4, "address-labels", "^a&s", &labels)) { + for (i = 0; i < addrs->len && labels[i]; i++) { + if (*labels[i]) { nm_ip_address_set_attribute(addrs->pdata[i], NM_IP_ADDRESS_ATTRIBUTE_LABEL, g_variant_new_string(labels[i])); - g_strfreev(labels); + } + } } - g_variant_unref(s_ip4); g_object_set(setting, NM_SETTING_IP_CONFIG_ADDRESSES, @@ -448,52 +457,50 @@ ip4_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); - g_ptr_array_unref(addrs); - g_free(gateway); return TRUE; } static GVariant * -ip4_address_labels_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) +ip4_address_labels_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { NMSettingIPConfig *s_ip = NM_SETTING_IP_CONFIG(setting); gboolean have_labels = FALSE; - GPtrArray *labels; - GVariant *ret; - int num_addrs, i; + gs_free GVariant **labels_free = NULL; + GVariant *s_empty; + GVariant **labels; + guint num_addrs; + guint i; if (!_nm_connection_serialize_non_secret(flags)) return NULL; num_addrs = nm_setting_ip_config_get_num_addresses(s_ip); + if (num_addrs == 0) + return NULL; + + labels = nm_malloc_maybe_a(500, sizeof(gpointer) * num_addrs, &labels_free); + + s_empty = nm_g_variant_singleton_s_empty(); + for (i = 0; i < num_addrs; i++) { NMIPAddress *addr = nm_setting_ip_config_get_address(s_ip, i); GVariant *label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); if (label) { have_labels = TRUE; - break; - } + labels[i] = label; + } else + labels[i] = s_empty; } + if (!have_labels) return NULL; - labels = g_ptr_array_sized_new(num_addrs); - for (i = 0; i < num_addrs; i++) { - NMIPAddress *addr = nm_setting_ip_config_get_address(s_ip, i); - GVariant *label = nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); - - g_ptr_array_add(labels, (char *) (label ? g_variant_get_string(label, NULL) : "")); - } - - ret = g_variant_new_strv((const char *const *) labels->pdata, labels->len); - g_ptr_array_unref(labels); - - return ret; + return g_variant_new_array(G_VARIANT_TYPE_STRING, labels, num_addrs); } static GVariant * -ip4_address_data_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) +ip4_address_data_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *addrs = NULL; @@ -505,9 +512,9 @@ ip4_address_data_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) } static gboolean -ip4_address_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) +ip4_address_data_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - GPtrArray *addrs; + gs_unref_ptrarray GPtrArray *addrs = NULL; /* FIXME: properly handle errors */ @@ -519,12 +526,11 @@ ip4_address_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) addrs = nm_utils_ip_addresses_from_variant(value, AF_INET); g_object_set(setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL); - g_ptr_array_unref(addrs); return TRUE; } static GVariant * -ip4_routes_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) +ip4_routes_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *routes = NULL; @@ -533,9 +539,9 @@ ip4_routes_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) } static gboolean -ip4_routes_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) +ip4_routes_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - GPtrArray *routes; + gs_unref_ptrarray GPtrArray *routes = NULL; /* FIXME: properly handle errors */ @@ -546,12 +552,11 @@ ip4_routes_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) routes = nm_utils_ip4_routes_from_variant(value); g_object_set(setting, property_info->name, routes, NULL); - g_ptr_array_unref(routes); return TRUE; } static GVariant * -ip4_route_data_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) +ip4_route_data_to_dbus(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) { gs_unref_ptrarray GPtrArray *routes = NULL; @@ -563,9 +568,9 @@ ip4_route_data_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil) } static gboolean -ip4_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) +ip4_route_data_from_dbus(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) { - GPtrArray *routes; + gs_unref_ptrarray GPtrArray *routes = NULL; /* FIXME: properly handle errors */ @@ -577,7 +582,6 @@ ip4_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil) routes = nm_utils_ip_routes_from_variant(value, AF_INET); g_object_set(setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL); - g_ptr_array_unref(routes); return TRUE; } @@ -620,13 +624,15 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) setting_class->verify = verify; setting_ip_config_class->private_offset = g_type_class_get_instance_private_offset(klass); + setting_ip_config_class->is_ipv4 = TRUE; + setting_ip_config_class->addr_family = AF_INET; /* ---ifcfg-rh--- * property: method * variable: BOOTPROTO - * format: string - * values: none, dhcp (bootp), static, ibft, autoip, shared - * default: none + * format: string + * values: none, dhcp (bootp), static, ibft, autoip, shared + * default: none * description: Method used for IPv4 protocol configuration. * ---end--- */ @@ -637,10 +643,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * description: List of DNS servers. * example: dns=1.2.3.4;8.8.8.8;8.8.4.4; * ---end--- - * ---ifcfg-rh--- + */ + /* ---ifcfg-rh--- * property: dns * variable: DNS1, DNS2, ... - * format: string + * format: string * description: List of DNS servers. Even if NetworkManager supports many DNS * servers, initscripts and resolver only care about the first three, usually. * example: DNS1=1.2.3.4 DNS2=10.0.0.254 DNS3=8.8.8.8 @@ -650,7 +657,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) /* ---ifcfg-rh--- * property: dns-search * variable: DOMAIN - * format: string (space-separated domains) + * format: string (space-separated domains) * description: List of DNS search domains. * ---end--- */ @@ -662,7 +669,8 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * description: List of static IP addresses. * example: address1=192.168.100.100/24 address2=10.1.1.5/24 * ---end--- - * ---ifcfg-rh--- + */ + /* ---ifcfg-rh--- * property: addresses * variable: IPADDR, PREFIX (NETMASK), IPADDR1, PREFIX1 (NETMASK1), ... * description: List of static IP addresses. @@ -677,7 +685,8 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * description: Gateway IP addresses as a string. * example: gateway=192.168.100.1 * ---end--- - * ---ifcfg-rh--- + */ + /* ---ifcfg-rh--- * property: gateway * variable: GATEWAY * description: Gateway IP address. @@ -693,7 +702,8 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * example: route1=8.8.8.0/24,10.1.1.1,77 * route2=7.7.0.0/16 * ---end--- - * ---ifcfg-rh--- + */ + /* ---ifcfg-rh--- * property: routes * variable: ADDRESS1, NETMASK1, GATEWAY1, METRIC1, OPTIONS1, ... * description: List of static routes. They are not stored in ifcfg-* file, @@ -787,6 +797,17 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * ---end--- */ + /* ---ifcfg-rh--- + * property: auto-route-ext-gw + * variable: IPV4_AUTO_ROUTE_EXT_GW(+) + * default: yes + * description: VPN connections will default to add the route automatically unless this + * setting is set to %FALSE. + * For other connection types, adding such an automatic route is currently + * not supported and setting this to %TRUE has no effect. + * ---end--- + */ + /** * NMSettingIP4Config:dhcp-client-id: * @@ -860,6 +881,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * variable: DHCP_HOSTNAME_FLAGS * description: flags for the DHCP hostname and FQDN properties * example: DHCP_HOSTNAME_FLAGS=5 + * ---end--- */ /** @@ -961,11 +983,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("au"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = ip4_dns_to_dbus, - .typdata_from_dbus.gprop_fcn = ip4_dns_from_dbus, - .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, - .from_dbus_is_full = TRUE), ); + .compare_fcn = _nm_setting_ip_config_compare_fcn_dns, + .to_dbus_fcn = ip4_dns_to_dbus, + .from_dbus_fcn = ip4_dns_from_dbus, ), + .to_dbus_only_in_manager_process = TRUE, + .dbus_deprecated = TRUE, ); /* ---dbus--- * property: addresses @@ -995,15 +1017,19 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), - .to_dbus_fcn = ip4_addresses_get, + .to_dbus_fcn = ip4_addresses_to_dbus, .compare_fcn = _nm_setting_ip_config_compare_fcn_addresses, - .from_dbus_fcn = ip4_addresses_set, )); + .from_dbus_fcn = ip4_addresses_from_dbus, ), + .to_dbus_only_in_manager_process = TRUE, + .dbus_deprecated = TRUE, ); _nm_properties_override_dbus( properties_override, "address-labels", NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, - .to_dbus_fcn = ip4_address_labels_get, - .compare_fcn = _nm_setting_property_compare_fcn_ignore, )); + .to_dbus_fcn = ip4_address_labels_to_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_ignore, + /* from_dbus() is handled by ip4_addresses_from_dbus(). */), + .dbus_deprecated = TRUE, ); /* ---dbus--- * property: address-data @@ -1018,9 +1044,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, "address-data", NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = ip4_address_data_get, + .to_dbus_fcn = ip4_address_data_to_dbus, .compare_fcn = _nm_setting_property_compare_fcn_ignore, - .from_dbus_fcn = ip4_address_data_set, )); + .from_dbus_fcn = ip4_address_data_from_dbus, )); /* ---dbus--- * property: routes @@ -1090,7 +1116,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * <para><literal>"mtu"</literal> - an unsigned 32 bit integer.</para> * </listitem> * <listitem> - * <para><literal>"onlink"</literal> - a boolean value.</para> + * <para><literal>"onlink"</literal> - a boolean value. The onlink flag + * is ignored for IPv4 routes without a gateway. That also means, + * with a positive "weight" the route cannot merge with ECMP routes + * which are onlink and have a gateway. + * </para> * </listitem> * <listitem> * <para><literal>"quickack"</literal> - a boolean value.</para> @@ -1117,6 +1147,17 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) * The default is <literal>unicast</literal>.</para> * </listitem> * <listitem> + * <para><literal>"weight"</literal> - an unsigned 32 bit integer + * ranging from 0 to 256. A non-zero weight indicates that the IPv4 + * route is an ECMP IPv4 route. NetworkManager will automatically + * merge compatible ECMP routes into multi-hop routes. Setting to + * zero or omitting the attribute configures single hop routes that + * won't get merged. If the route finds no merge partner, it is + * configured as single hop route.</para> <para>Note that in + * NetworkManager, currently all nexthops of a ECMP route must share + * the same "onlink" flag in order to be mergable.</para> + * </listitem> + * <listitem> * <para><literal>"window"</literal> - an unsigned 32 bit integer.</para> * </listitem> * </itemizedlist> @@ -1130,9 +1171,11 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), - .to_dbus_fcn = ip4_routes_get, + .to_dbus_fcn = ip4_routes_to_dbus, .compare_fcn = _nm_setting_ip_config_compare_fcn_routes, - .from_dbus_fcn = ip4_routes_set, )); + .from_dbus_fcn = ip4_routes_from_dbus, ), + .to_dbus_only_in_manager_process = TRUE, + .dbus_deprecated = TRUE, ); /* ---dbus--- * property: route-data @@ -1151,9 +1194,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, "route-data", NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = ip4_route_data_get, + .to_dbus_fcn = ip4_route_data_to_dbus, .compare_fcn = _nm_setting_property_compare_fcn_ignore, - .from_dbus_fcn = ip4_route_data_set, )); + .from_dbus_fcn = ip4_route_data_from_dbus, )); /* ---nmcli--- * property: routing-rules |