diff options
author | Francesco Giudici <fgiudici@redhat.com> | 2019-05-10 10:47:29 +0200 |
---|---|---|
committer | Francesco Giudici <fgiudici@redhat.com> | 2019-07-05 14:12:21 +0200 |
commit | 5008a25f62cec328ed9571051bc33b577bdb9f53 (patch) | |
tree | e7a12acac8cd4ca73ce20ca87acbc3df5358d7ed | |
parent | 3775f31cb9ecb5993ce5631ad0f805b2215ca0e3 (diff) | |
download | NetworkManager-5008a25f62cec328ed9571051bc33b577bdb9f53.tar.gz |
dhcp/internal: expose on D-Bus some more dhcp options
When using the internal dhcp client we skip exporting on D-Bus many of
the dhcp options received from the dhcp server. We instead export almost
all of them when using the dhclient dhcp client, using the variable
names passed by dhclient itself.
Map more DHCP options to dhclient variable names in order to allow the
internal client to retrieve them easily, namely: the server identifier,
the broadcast address, the renewal time, the rebinding time and the timezone.
Note that not all the DHCP options can be exported at this time because
systemd-networkd code drops many it won't process, so we have no way to
retrieve them without changing core systemd-networkd code.
-rw-r--r-- | src/dhcp/nm-dhcp-systemd.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index 31a10bfb08..671fe0be6a 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -79,8 +79,8 @@ G_DEFINE_TYPE (NMDhcpSystemd, nm_dhcp_systemd, NM_TYPE_DHCP_CLIENT) /*****************************************************************************/ -#define DHCP_OPTION_NIS_DOMAIN 40 -#define DHCP_OPTION_NIS_SERVERS 41 +#define DHCP_OPTION_NIS_DOMAIN 40 +#define DHCP_OPTION_NIS_SERVERS 41 /* Internal values */ #define DHCP_OPTION_IP_ADDRESS 1024 @@ -135,6 +135,9 @@ static const ReqOption dhcp4_requests[] = { REQ (SD_DHCP_OPTION_PRIVATE_PROXY_AUTODISCOVERY, "wpad", TRUE ), REQ (SD_DHCP_OPTION_ROOT_PATH, "root_path", TRUE ), REQ (SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME, "dhcp_lease_time", FALSE ), + REQ (SD_DHCP_OPTION_RENEWAL_T1_TIME, "dhcp_renewal_time", FALSE ), + REQ (SD_DHCP_OPTION_REBINDING_T2_TIME, "dhcp_rebinding_time", FALSE ), + REQ (SD_DHCP_OPTION_NEW_TZDB_TIMEZONE, "tcode", FALSE ), /* Internal values */ REQ (DHCP_OPTION_IP_ADDRESS, "ip_address", FALSE ), @@ -272,9 +275,13 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx, gint64 ts_time = time (NULL); struct in_addr a_address; struct in_addr a_netmask; + struct in_addr server_id; + struct in_addr broadcast; const struct in_addr *a_router; guint32 a_plen; guint32 a_lifetime; + guint32 renewal; + guint32 rebinding; g_return_val_if_fail (lease != NULL, NULL); @@ -333,6 +340,22 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx, .preferred = a_lifetime, })); + if (sd_dhcp_lease_get_server_identifier (lease, &server_id) >= 0) { + nm_utils_inet4_ntop (server_id.s_addr, addr_str); + LOG_LEASE (LOGD_DHCP4, "%s '%s'", + request_string (dhcp4_requests, SD_DHCP_OPTION_SERVER_IDENTIFIER), + addr_str); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_SERVER_IDENTIFIER, addr_str); + } + + if (sd_dhcp_lease_get_broadcast (lease, &broadcast) >= 0) { + nm_utils_inet4_ntop (broadcast.s_addr, addr_str); + LOG_LEASE (LOGD_DHCP4, "%s '%s'", + request_string (dhcp4_requests, SD_DHCP_OPTION_BROADCAST), + addr_str); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_BROADCAST, addr_str); + } + num = sd_dhcp_lease_get_dns (lease, &addr_list); if (num > 0) { nm_gstring_prepare (&str); @@ -578,6 +601,27 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx, add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROOT_PATH, s); } + if (sd_dhcp_lease_get_t1 (lease, &renewal) >= 0) { + LOG_LEASE (LOGD_DHCP4, "%s '%u'", + request_string (dhcp4_requests, SD_DHCP_OPTION_RENEWAL_T1_TIME), + renewal); + add_option_u64 (options, dhcp4_requests, SD_DHCP_OPTION_RENEWAL_T1_TIME, renewal); + } + + if (sd_dhcp_lease_get_t2 (lease, &rebinding) >= 0) { + LOG_LEASE (LOGD_DHCP4, "%s '%u'", + request_string (dhcp4_requests, SD_DHCP_OPTION_REBINDING_T2_TIME), + rebinding); + add_option_u64 (options, dhcp4_requests, SD_DHCP_OPTION_REBINDING_T2_TIME, rebinding); + } + + if (sd_dhcp_lease_get_timezone (lease, &s) >= 0) { + LOG_LEASE (LOGD_DHCP4, "%s '%s'", + request_string (dhcp4_requests, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE), + s); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE, s); + } + if (sd_dhcp_lease_get_vendor_specific (lease, &data, &data_len) >= 0) metered = !!memmem (data, data_len, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED")); nm_ip4_config_set_metered (ip4_config, metered); |