summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-09-20 21:37:18 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-09-22 18:38:21 +0200
commitdb849df5a109ed2d6b96b0a70e25da150cb4a726 (patch)
treede3e64681658a1b1528cb9615ceeeaf71c2c30ab /src
parentsd-dhcp-client: do not set fallback subnet mask if it is already set (diff)
downloadsystemd-db849df5a109ed2d6b96b0a70e25da150cb4a726.tar.xz
systemd-db849df5a109ed2d6b96b0a70e25da150cb4a726.zip
sd-dhcp-client: introduce dhcp_lease_unref_and_replace()
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/dhcp-lease-internal.h4
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c22
2 files changed, 12 insertions, 14 deletions
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h
index 04a9893876..7c20e52209 100644
--- a/src/libsystemd-network/dhcp-lease-internal.h
+++ b/src/libsystemd-network/dhcp-lease-internal.h
@@ -7,6 +7,7 @@
#include "sd-dhcp-client.h"
+#include "alloc-util.h"
#include "dhcp-internal.h"
#include "dhcp-protocol.h"
#include "list.h"
@@ -90,3 +91,6 @@ int dhcp_lease_insert_private_option(sd_dhcp_lease *lease, uint8_t tag, const vo
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t client_id_len);
+
+#define dhcp_lease_unref_and_replace(a, b) \
+ unref_and_replace_full(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 9490db9c97..e3f637736e 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -1584,14 +1584,12 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer, size_
return log_dhcp_client_errno(client, SYNTHETIC_ERRNO(ENOMSG),
"received lease lacks subnet mask, and a fallback one cannot be generated, ignoring.");
- sd_dhcp_lease_unref(client->lease);
- client->lease = TAKE_PTR(lease);
+ dhcp_lease_unref_and_replace(client->lease, lease);
if (client_notify(client, SD_DHCP_CLIENT_EVENT_SELECTING) < 0)
return -ENOMSG;
log_dhcp_client(client, "OFFER");
-
return 0;
}
@@ -1686,20 +1684,16 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack, size_t le
return log_dhcp_client_errno(client, SYNTHETIC_ERRNO(ENOMSG),
"received lease lacks subnet mask, and a fallback one cannot be generated, ignoring.");
- r = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE;
- if (client->lease) {
- if (lease_equal(client->lease, lease))
- r = SD_DHCP_CLIENT_EVENT_RENEW;
- else
- r = SD_DHCP_CLIENT_EVENT_IP_CHANGE;
-
- client->lease = sd_dhcp_lease_unref(client->lease);
- }
+ if (!client->lease)
+ r = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE;
+ else if (lease_equal(client->lease, lease))
+ r = SD_DHCP_CLIENT_EVENT_RENEW;
+ else
+ r = SD_DHCP_CLIENT_EVENT_IP_CHANGE;
- client->lease = TAKE_PTR(lease);
+ dhcp_lease_unref_and_replace(client->lease, lease);
log_dhcp_client(client, "ACK");
-
return r;
}