summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-02-10 15:08:00 +0100
committerThomas Haller <thaller@redhat.com>2021-02-11 09:23:13 +0100
commit30911a305f957f1795ca1f65d04d5076adaef974 (patch)
tree8b7583c5b5874dddc16f84dc9672df23d680b641
parent58b3b7ec3c064363a879e4e835974b75886cb8ed (diff)
downloadNetworkManager-30911a305f957f1795ca1f65d04d5076adaef974.tar.gz
dhcp/nettools: cleanup lease_parse_address()
-rw-r--r--src/core/dhcp/nm-dhcp-nettools.c59
-rw-r--r--src/core/dhcp/nm-dhcp-utils.c3
2 files changed, 21 insertions, 41 deletions
diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c
index c2bb164244..5f0a385386 100644
--- a/src/core/dhcp/nm-dhcp-nettools.c
+++ b/src/core/dhcp/nm-dhcp-nettools.c
@@ -306,42 +306,22 @@ lease_option_print_domain_name(GString * str,
}
static gboolean
-lease_get_in_addr(NDhcp4ClientLease *lease, guint8 option, struct in_addr *addrp)
-{
- struct in_addr addr;
- uint8_t * data;
- size_t n_data;
- int r;
-
- r = n_dhcp4_client_lease_query(lease, option, &data, &n_data);
- if (r)
- return FALSE;
-
- if (!lease_option_next_in_addr(&addr, &data, &n_data))
- return FALSE;
-
- if (n_data != 0)
- return FALSE;
-
- *addrp = addr;
- return TRUE;
-}
-
-static gboolean
lease_parse_address(NDhcp4ClientLease *lease,
NMIP4Config * ip4_config,
GHashTable * options,
GError ** error)
{
- char addr_str[NM_UTILS_INET_ADDRSTRLEN];
struct in_addr a_address;
- struct in_addr a_netmask;
+ in_addr_t a_netmask;
struct in_addr a_next_server;
guint32 a_plen;
guint64 nettools_lifetime;
guint32 a_lifetime;
guint32 a_timestamp;
guint64 a_expiry;
+ guint8 * l_data;
+ gsize l_data_len;
+ int r;
n_dhcp4_client_lease_get_yiaddr(lease, &a_address);
if (a_address.s_addr == INADDR_ANY) {
@@ -396,24 +376,24 @@ lease_parse_address(NDhcp4ClientLease *lease,
/ NM_UTILS_NSEC_PER_SEC);
}
- if (!lease_get_in_addr(lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &a_netmask)) {
+ r = n_dhcp4_client_lease_query(lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &l_data, &l_data_len);
+ if (r != 0 || !nm_dhcp_lease_data_parse_in_addr(l_data, l_data_len, &a_netmask)) {
nm_utils_error_set_literal(error,
NM_UTILS_ERROR_UNKNOWN,
"could not get netmask from lease");
return FALSE;
}
- _nm_utils_inet4_ntop(a_address.s_addr, addr_str);
- a_plen = nm_utils_ip4_netmask_to_prefix(a_netmask.s_addr);
+ a_plen = nm_utils_ip4_netmask_to_prefix(a_netmask);
- nm_dhcp_option_add_option(options,
- _nm_dhcp_option_dhcp4_options,
- NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS,
- addr_str);
- nm_dhcp_option_add_option(options,
- _nm_dhcp_option_dhcp4_options,
- NM_DHCP_OPTION_DHCP4_SUBNET_MASK,
- _nm_utils_inet4_ntop(a_netmask.s_addr, addr_str));
+ nm_dhcp_option_add_option_in_addr(options,
+ _nm_dhcp_option_dhcp4_options,
+ NM_DHCP_OPTION_DHCP4_NM_IP_ADDRESS,
+ a_address.s_addr);
+ nm_dhcp_option_add_option_in_addr(options,
+ _nm_dhcp_option_dhcp4_options,
+ NM_DHCP_OPTION_DHCP4_SUBNET_MASK,
+ a_netmask);
nm_dhcp_option_add_option_u64(options,
_nm_dhcp_option_dhcp4_options,
@@ -429,11 +409,10 @@ lease_parse_address(NDhcp4ClientLease *lease,
n_dhcp4_client_lease_get_siaddr(lease, &a_next_server);
if (a_next_server.s_addr != INADDR_ANY) {
- _nm_utils_inet4_ntop(a_next_server.s_addr, addr_str);
- nm_dhcp_option_add_option(options,
- _nm_dhcp_option_dhcp4_options,
- NM_DHCP_OPTION_DHCP4_NM_NEXT_SERVER,
- addr_str);
+ nm_dhcp_option_add_option_in_addr(options,
+ _nm_dhcp_option_dhcp4_options,
+ NM_DHCP_OPTION_DHCP4_NM_NEXT_SERVER,
+ a_next_server.s_addr);
}
nm_ip4_config_add_address(ip4_config,
diff --git a/src/core/dhcp/nm-dhcp-utils.c b/src/core/dhcp/nm-dhcp-utils.c
index b2064153d5..b3b0678dc8 100644
--- a/src/core/dhcp/nm-dhcp-utils.c
+++ b/src/core/dhcp/nm-dhcp-utils.c
@@ -954,7 +954,8 @@ nm_dhcp_lease_data_parse_domain(const guint8 *data, gsize n_data, char **out_val
gboolean
nm_dhcp_lease_data_parse_in_addr(const guint8 *data, gsize n_data, in_addr_t *out_val)
{
- /* - option 28, https://tools.ietf.org/html/rfc2132#section-5.3
+ /* - option 1, https://tools.ietf.org/html/rfc2132#section-3.3
+ * - option 28, https://tools.ietf.org/html/rfc2132#section-5.3
*/
if (n_data != 4)