dhcp: don't use systemd's dhcp_lease_load() in nettools' n-dhcp4 ip4_start()

This commit is contained in:
Thomas Haller
2022-04-11 12:07:44 +02:00
parent c44b49db6f
commit b1575e814f

View File

@@ -13,22 +13,24 @@
#include <ctype.h> #include <ctype.h>
#include <net/if_arp.h> #include <net/if_arp.h>
#include "libnm-glib-aux/nm-dedup-multi.h" #include "n-dhcp4/src/n-dhcp4.h"
#include "libnm-std-aux/unaligned.h"
#include "libnm-glib-aux/nm-str-buf.h" #include "libnm-glib-aux/nm-dedup-multi.h"
#include "libnm-glib-aux/nm-io-utils.h"
#include "libnm-glib-aux/nm-str-buf.h"
#include "libnm-std-aux/unaligned.h"
#include "nm-l3-config-data.h"
#include "nm-utils.h"
#include "nm-config.h"
#include "nm-dhcp-utils.h"
#include "nm-dhcp-options.h"
#include "nm-core-utils.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform.h"
#include "nm-config.h"
#include "nm-core-utils.h"
#include "nm-dhcp-client-logging.h" #include "nm-dhcp-client-logging.h"
#include "n-dhcp4/src/n-dhcp4.h" #include "nm-dhcp-options.h"
#include "nm-dhcp-utils.h"
#include "nm-l3-config-data.h"
#include "nm-utils.h"
#include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "libnm-systemd-shared/nm-sd-utils-shared.h"
#include "libnm-systemd-core/nm-sd-utils-dhcp.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -1110,18 +1112,20 @@ ip4_start(NMDhcpClient *client, GError **error)
if (client_config->v4.last_address) if (client_config->v4.last_address)
inet_pton(AF_INET, client_config->v4.last_address, &last_addr); inet_pton(AF_INET, client_config->v4.last_address, &last_addr);
else { else {
/* gs_free char *contents = NULL;
* TODO: we stick to the systemd-networkd lease file format. Quite easy for now to gs_free char *s_addr = NULL;
* just use the functions in systemd code. Anyway, as in the end we just use the
* ip address from all the options found in the lease, write a function that parses
* the lease file just for the assigned address and returns it in &last_address.
* Then drop reference to systemd-networkd structures and functions.
*/
nm_auto(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
dhcp_lease_load(&lease, lease_file); nm_utils_file_get_contents(-1,
if (lease) lease_file,
sd_dhcp_lease_get_address(lease, &last_addr); 64 * 1024,
NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
&contents,
NULL,
NULL,
NULL);
nm_parse_env_file(contents, "ADDRESS", &s_addr);
if (s_addr)
nm_utils_parse_inaddr_bin(AF_INET, s_addr, NULL, &last_addr);
} }
if (last_addr.s_addr) { if (last_addr.s_addr) {