summaryrefslogtreecommitdiff
path: root/src/dhcp/nm-dhcp-nettools.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dhcp/nm-dhcp-nettools.c')
-rw-r--r--src/dhcp/nm-dhcp-nettools.c164
1 files changed, 81 insertions, 83 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 8d7d021710..7b95f89556 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -18,6 +18,7 @@
#include "nm-glib-aux/nm-dedup-multi.h"
#include "nm-std-aux/unaligned.h"
+#include "nm-l3-config-data.h"
#include "nm-utils.h"
#include "nm-config.h"
#include "nm-dhcp-utils.h"
@@ -351,7 +352,7 @@ lease_get_u16 (NDhcp4ClientLease *lease,
static gboolean
lease_parse_address (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
GError **error)
{
@@ -453,23 +454,23 @@ lease_parse_address (NDhcp4ClientLease *lease,
addr_str);
}
- nm_ip4_config_add_address (ip4_config,
- &((const NMPlatformIP4Address) {
- .address = a_address.s_addr,
- .peer_address = a_address.s_addr,
- .plen = a_plen,
- .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
- .timestamp = a_timestamp,
- .lifetime = a_lifetime,
- .preferred = a_lifetime,
- }));
+ nm_l3_config_data_add_address_4 (l3cd,
+ &((const NMPlatformIP4Address) {
+ .address = a_address.s_addr,
+ .peer_address = a_address.s_addr,
+ .plen = a_plen,
+ .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .timestamp = a_timestamp,
+ .lifetime = a_lifetime,
+ .preferred = a_lifetime,
+ }));
return TRUE;
}
static void
lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -496,7 +497,8 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
* See https://github.com/systemd/systemd/issues/4524. */
continue;
}
- nm_ip4_config_add_nameserver (ip4_config, addr.s_addr);
+
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET, &addr);
}
nm_dhcp_option_add_option (options,
@@ -507,7 +509,7 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
static void
lease_parse_routes (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
guint32 route_table,
guint32 route_metric)
@@ -550,20 +552,18 @@ lease_parse_routes (NDhcp4ClientLease *lease,
default_route_metric++;
has_router_from_classless = TRUE;
- } else {
+ } else
m = route_metric;
- }
-
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .network = dest.s_addr,
- .plen = plen,
- .gateway = gateway.s_addr,
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .metric = m,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- }),
- NULL);
+
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .network = dest.s_addr,
+ .plen = plen,
+ .gateway = gateway.s_addr,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = m,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -601,16 +601,15 @@ lease_parse_routes (NDhcp4ClientLease *lease,
continue;
}
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .network = dest.s_addr,
- .plen = plen,
- .gateway = gateway.s_addr,
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .metric = route_metric,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .network = dest.s_addr,
+ .plen = plen,
+ .gateway = gateway.s_addr,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = route_metric,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -647,14 +646,13 @@ lease_parse_routes (NDhcp4ClientLease *lease,
if (default_route_metric < G_MAXUINT32)
default_route_metric++;
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .gateway = gateway.s_addr,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- .metric = m,
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .gateway = gateway.s_addr,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ .metric = m,
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -665,7 +663,7 @@ lease_parse_routes (NDhcp4ClientLease *lease,
static void
lease_parse_mtu (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
uint16_t mtu;
@@ -680,27 +678,25 @@ lease_parse_mtu (NDhcp4ClientLease *lease,
_nm_dhcp_option_dhcp4_options,
NM_DHCP_OPTION_DHCP4_INTERFACE_MTU,
mtu);
- nm_ip4_config_set_mtu (ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP);
+ nm_l3_config_data_set_mtu (l3cd, mtu);
}
static void
lease_parse_metered (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
- gboolean metered = FALSE;
uint8_t *data;
size_t n_data;
int r;
r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_VENDOR_SPECIFIC, &data, &n_data);
- if (r)
- metered = FALSE;
- else
- metered = !!memmem (data, n_data, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED"));
+ if (r == 0) {
+ if (!!memmem (data, n_data, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED")))
+ nm_l3_config_data_set_metered (l3cd, TRUE);
+ }
/* TODO: expose the vendor specific option when present */
- nm_ip4_config_set_metered (ip4_config, metered);
}
static void
@@ -757,7 +753,7 @@ lease_parse_hostname (NDhcp4ClientLease *lease,
static void
lease_parse_domainname (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -781,7 +777,7 @@ lease_parse_domainname (NDhcp4ClientLease *lease,
return;
g_string_append (nm_gstring_add_space_delimiter (str), *d);
- nm_ip4_config_add_domain (ip4_config, *d);
+ nm_l3_config_data_add_domain (l3cd, AF_INET, *d);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -820,7 +816,7 @@ nm_dhcp_parse_search_list (guint8 *data, size_t n_data)
static void
lease_parse_search_domains (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -839,7 +835,7 @@ lease_parse_search_domains (NDhcp4ClientLease *lease,
for (i = 0; domains && domains[i]; i++) {
g_string_append (nm_gstring_add_space_delimiter (str), domains[i]);
- nm_ip4_config_add_search (ip4_config, domains[i]);
+ nm_l3_config_data_add_search (l3cd, AF_INET, domains[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -920,7 +916,7 @@ lease_parse_private_options (NDhcp4ClientLease *lease,
}
}
-static NMIP4Config *
+static NML3ConfigData *
lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
@@ -930,23 +926,26 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
GHashTable **out_options,
GError **error)
{
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
g_return_val_if_fail (lease != NULL, NULL);
- ip4_config = nm_ip4_config_new (multi_idx, ifindex);
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
+
options = nm_dhcp_option_create_options_dict ();
- if (!lease_parse_address (lease, ip4_config, options, error))
+ if (!lease_parse_address (lease, l3cd, options, error))
return NULL;
- lease_parse_routes (lease, ip4_config, options, route_table, route_metric);
- lease_parse_domain_name_servers (lease, ip4_config, options);
- lease_parse_domainname (lease, ip4_config, options);
- lease_parse_search_domains (lease, ip4_config, options);
- lease_parse_mtu (lease, ip4_config, options);
- lease_parse_metered (lease, ip4_config, options);
+ lease_parse_routes (lease, l3cd, options, route_table, route_metric);
+ lease_parse_domain_name_servers (lease, l3cd, options);
+ lease_parse_domainname (lease, l3cd, options);
+ lease_parse_search_domains (lease, l3cd, options);
+ lease_parse_mtu (lease, l3cd, options);
+ lease_parse_metered (lease, l3cd, options);
lease_parse_hostname (lease, options);
lease_parse_ntps (lease, options);
@@ -955,7 +954,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
lease_parse_private_options (lease, options);
NM_SET_OUT (out_options, g_steal_pointer (&options));
- return g_steal_pointer (&ip4_config);
+ return g_steal_pointer (&l3cd);
}
/*****************************************************************************/
@@ -992,22 +991,22 @@ bound4_handle (NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended
{
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE (self);
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
GError *error = NULL;
_LOGT ("lease available (%s)", extended ? "extended" : "new");
- ip4_config = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
- iface,
- nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
- lease,
- nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
- nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
- &options,
- &error);
- if (!ip4_config) {
- _LOGW ("%s", error->message);
+ l3cd = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
+ iface,
+ nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
+ lease,
+ nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
+ nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
+ &options,
+ &error);
+ if (!l3cd) {
+ _LOGW ("failure to parse lease: %s", error->message);
g_clear_error (&error);
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
return;
@@ -1018,7 +1017,7 @@ bound4_handle (NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND,
- NM_IP_CONFIG_CAST (ip4_config),
+ l3cd,
options);
}
@@ -1100,9 +1099,8 @@ dhcp4_event_cb (int fd,
return G_SOURCE_REMOVE;
}
- while (!n_dhcp4_client_pop_event (priv->client, &event) && event) {
+ while (!n_dhcp4_client_pop_event (priv->client, &event) && event)
dhcp4_event_handle (self, event);
- }
return G_SOURCE_CONTINUE;
}