summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2019-11-18 13:34:38 +0100
committerLubomir Rintel <lkundrak@v3.sk>2019-11-18 13:34:38 +0100
commit8a35b7ed8640be850975fd07efd0f7b3fd10ded1 (patch)
treefad3ff7dbae1883252c0285f5d9bedf641a8220f
parente475ac75673a6e7fe70574932e0800e1ac54b15d (diff)
parentc1104a5cc2ff2fce9831e7ccc9286e91bd48120d (diff)
downloadNetworkManager-8a35b7ed8640be850975fd07efd0f7b3fd10ded1.tar.gz
merge; branch 'lr/nettools-siaddr'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/334
-rw-r--r--shared/n-dhcp4/src/libndhcp4.sym1
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-lease.c14
-rw-r--r--shared/n-dhcp4/src/n-dhcp4.h1
-rw-r--r--shared/n-dhcp4/src/test-api.c1
-rw-r--r--src/dhcp/nm-dhcp-nettools.c11
5 files changed, 28 insertions, 0 deletions
diff --git a/shared/n-dhcp4/src/libndhcp4.sym b/shared/n-dhcp4/src/libndhcp4.sym
index b9ba800a3b..0659926bec 100644
--- a/shared/n-dhcp4/src/libndhcp4.sym
+++ b/shared/n-dhcp4/src/libndhcp4.sym
@@ -34,6 +34,7 @@ global:
n_dhcp4_client_lease_ref;
n_dhcp4_client_lease_unref;
n_dhcp4_client_lease_get_yiaddr;
+ n_dhcp4_client_lease_get_siaddr;
n_dhcp4_client_lease_get_lifetime;
n_dhcp4_client_lease_query;
n_dhcp4_client_lease_select;
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-lease.c b/shared/n-dhcp4/src/n-dhcp4-c-lease.c
index 208ad92a6a..c14a9daf0a 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-lease.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-lease.c
@@ -204,6 +204,20 @@ _c_public_ void n_dhcp4_client_lease_get_yiaddr(NDhcp4ClientLease *lease, struct
}
/**
+ * n_dhcp4_client_lease_get_siaddr() - get the server IP address
+ * @lease: the lease to operate on
+ * @siaddr: return argument for the IP address
+ *
+ * Gets the server IP address cotained in the lease. Or INADDR_ANY if the
+ * lease does not contain an IP address.
+ */
+_c_public_ void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *siaddr) {
+ NDhcp4Header *header = n_dhcp4_incoming_get_header(lease->message);
+
+ siaddr->s_addr = header->siaddr;
+}
+
+/**
* n_dhcp4_client_lease_get_lifetime() - get the lifetime
* @lease: the lease to operate on
* @ns_lifetimep: return argument for the lifetime in nano seconds
diff --git a/shared/n-dhcp4/src/n-dhcp4.h b/shared/n-dhcp4/src/n-dhcp4.h
index 58a3cb803a..ef75eca7c8 100644
--- a/shared/n-dhcp4/src/n-dhcp4.h
+++ b/shared/n-dhcp4/src/n-dhcp4.h
@@ -156,6 +156,7 @@ NDhcp4ClientLease *n_dhcp4_client_lease_ref(NDhcp4ClientLease *lease);
NDhcp4ClientLease *n_dhcp4_client_lease_unref(NDhcp4ClientLease *lease);
void n_dhcp4_client_lease_get_yiaddr(NDhcp4ClientLease *lease, struct in_addr *yiaddr);
+void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *siaddr);
void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint64_t *ns_lifetimep);
int n_dhcp4_client_lease_query(NDhcp4ClientLease *lease, uint8_t option, uint8_t **datap, size_t *n_datap);
diff --git a/shared/n-dhcp4/src/test-api.c b/shared/n-dhcp4/src/test-api.c
index 9e7b6bcaa7..be2d7b36a0 100644
--- a/shared/n-dhcp4/src/test-api.c
+++ b/shared/n-dhcp4/src/test-api.c
@@ -104,6 +104,7 @@ static void test_api_functions(void) {
(void *)n_dhcp4_client_lease_unrefp,
(void *)n_dhcp4_client_lease_unrefv,
(void *)n_dhcp4_client_lease_get_yiaddr,
+ (void *)n_dhcp4_client_lease_get_siaddr,
(void *)n_dhcp4_client_lease_get_lifetime,
(void *)n_dhcp4_client_lease_query,
(void *)n_dhcp4_client_lease_select,
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 49743eb148..e2719f8557 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -352,6 +352,7 @@ lease_parse_address (NDhcp4ClientLease *lease,
const gint64 ts_clock_boottime = nm_utils_monotonic_timestamp_as_boottime (ts, 1);
struct in_addr a_address;
struct in_addr a_netmask;
+ struct in_addr a_next_server;
guint32 a_plen;
guint64 nettools_lifetime;
gint64 a_lifetime;
@@ -415,6 +416,16 @@ lease_parse_address (NDhcp4ClientLease *lease,
NM_DHCP_OPTION_DHCP4_NM_EXPIRY,
(guint64) a_expiry);
+
+ 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_ip4_config_add_address (ip4_config,
&((const NMPlatformIP4Address) {
.address = a_address.s_addr,