summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-lease.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-03-03 17:13:59 +0100
committerTom Gundersen <teg@jklm.no>2014-03-03 17:18:22 +0100
commit8e34a618e2a67e22250247956697fe27c14c83c8 (patch)
treef61a736ace20206f2383aa6b723b598dec98842f /src/libsystemd-network/sd-dhcp-lease.c
parent0ad853bc06dea1db5740caf59f404d274fa5e3c9 (diff)
sd-dhcp-lease: add sd_dhcp_lease_get_next_server()
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 6bd9728377..f7a204af82 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -135,6 +135,15 @@ int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *ad
return 0;
}
+int sd_dhcp_lease_get_next_server(sd_dhcp_lease *lease, struct in_addr *addr) {
+ assert_return(lease, -EINVAL);
+ assert_return(addr, -EINVAL);
+
+ addr->s_addr = lease->next_server;
+
+ return 0;
+}
+
sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease) {
if (lease)
assert_se(REFCNT_INC(lease->n_ref) >= 2);
@@ -350,6 +359,18 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
"SERVER_ADDRESS=%s\n", string);
}
+ r = sd_dhcp_lease_get_next_server(lease, &address);
+ if (r >= 0) {
+ string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
+ if (!string) {
+ r = -errno;
+ goto finish;
+ }
+
+ fprintf(f,
+ "NEXT_SERVER=%s\n", string);
+ }
+
r = sd_dhcp_lease_get_mtu(lease, &mtu);
if (r >= 0)
fprintf(f, "MTU=%" PRIu16 "\n", mtu);
@@ -388,7 +409,8 @@ finish:
int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
_cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
_cleanup_free_ char *address = NULL, *router = NULL, *netmask = NULL,
- *server_address = NULL, *mtu = NULL;
+ *server_address = NULL, *next_server = NULL,
+ *mtu = NULL;
struct in_addr addr;
int r;
@@ -404,6 +426,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
"ROUTER", &router,
"NETMASK", &netmask,
"SERVER_IDENTIFIER", &server_address,
+ "NEXT_SERVER", &next_server,
"MTU", &mtu,
"DOMAINNAME", &lease->domainname,
"HOSTNAME", &lease->hostname,
@@ -443,6 +466,14 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
lease->server_address = addr.s_addr;
}
+ if (next_server) {
+ r = inet_pton(AF_INET, next_server, &addr);
+ if (r < 0)
+ return r;
+
+ lease->next_server = addr.s_addr;
+ }
+
if (mtu) {
uint16_t u;
if (sscanf(mtu, "%" SCNu16, &u) > 0)