[systemd-commits] 3 commits - src/libsystemd-network src/systemd
Tom Gundersen
tomegun at kemper.freedesktop.org
Mon Mar 3 08:17:54 PST 2014
src/libsystemd-network/dhcp-lease-internal.h | 2
src/libsystemd-network/dhcp-protocol.h | 1
src/libsystemd-network/sd-dhcp-client.c | 4 +
src/libsystemd-network/sd-dhcp-lease.c | 86 +++++++++++++++++++++++++++
src/systemd/sd-dhcp-lease.h | 3
5 files changed, 96 insertions(+)
New commits:
commit 8e34a618e2a67e22250247956697fe27c14c83c8
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Mar 3 17:13:59 2014 +0100
sd-dhcp-lease: add sd_dhcp_lease_get_next_server()
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h
index 1b157fd..70f1aa1 100644
--- a/src/libsystemd-network/dhcp-lease-internal.h
+++ b/src/libsystemd-network/dhcp-lease-internal.h
@@ -41,6 +41,7 @@ struct sd_dhcp_lease {
be32_t server_address;
be32_t subnet_mask;
be32_t router;
+ be32_t next_server;
struct in_addr *dns;
size_t dns_size;
uint16_t mtu;
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 1f676cc..b6810a9 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -587,6 +587,8 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
if (r != DHCP_OFFER)
return -ENOMSG;
+ lease->next_server = offer->siaddr;
+
lease->address = offer->yiaddr;
if (lease->address == INADDR_ANY ||
@@ -621,6 +623,8 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
if (r != DHCP_ACK)
return -ENOMSG;
+ lease->next_server = ack->siaddr;
+
lease->address = ack->yiaddr;
if (lease->address == INADDR_ANY ||
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 6bd9728..f7a204a 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)
diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h
index 7e737a9..f3595eb 100644
--- a/src/systemd/sd-dhcp-lease.h
+++ b/src/systemd/sd-dhcp-lease.h
@@ -33,6 +33,7 @@ sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease);
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr);
+int sd_dhcp_lease_get_next_server(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size);
int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
commit 0ad853bc06dea1db5740caf59f404d274fa5e3c9
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Mar 3 16:46:10 2014 +0100
sd-dhcp-lease: add sd_dhcp_lease_get_server_identifier()
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 722dd0a..6bd9728 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -126,6 +126,15 @@ int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr) {
return 0;
}
+int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr) {
+ assert_return(lease, -EINVAL);
+ assert_return(addr, -EINVAL);
+
+ addr->s_addr = lease->server_address;
+
+ return 0;
+}
+
sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease) {
if (lease)
assert_se(REFCNT_INC(lease->n_ref) >= 2);
@@ -329,6 +338,18 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
fprintf(f,
"NETMASK=%s\n", string);
+ r = sd_dhcp_lease_get_server_identifier(lease, &address);
+ if (r >= 0) {
+ string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
+ if (!string) {
+ r = -errno;
+ goto finish;
+ }
+
+ fprintf(f,
+ "SERVER_ADDRESS=%s\n", string);
+ }
+
r = sd_dhcp_lease_get_mtu(lease, &mtu);
if (r >= 0)
fprintf(f, "MTU=%" PRIu16 "\n", mtu);
@@ -367,7 +388,7 @@ 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,
- *mtu = NULL;
+ *server_address = NULL, *mtu = NULL;
struct in_addr addr;
int r;
@@ -382,6 +403,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
"ADDRESS", &address,
"ROUTER", &router,
"NETMASK", &netmask,
+ "SERVER_IDENTIFIER", &server_address,
"MTU", &mtu,
"DOMAINNAME", &lease->domainname,
"HOSTNAME", &lease->hostname,
@@ -413,6 +435,14 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
lease->subnet_mask = addr.s_addr;
+ if (server_address) {
+ r = inet_pton(AF_INET, server_address, &addr);
+ if (r < 0)
+ return r;
+
+ lease->server_address = addr.s_addr;
+ }
+
if (mtu) {
uint16_t u;
if (sscanf(mtu, "%" SCNu16, &u) > 0)
diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h
index 5b34b2a..7e737a9 100644
--- a/src/systemd/sd-dhcp-lease.h
+++ b/src/systemd/sd-dhcp-lease.h
@@ -33,6 +33,7 @@ sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease);
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr);
+int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size);
int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
commit ce78df79b88d02d36cbf9e39e70ecb871750e16d
Author: Tom Gundersen <teg at jklm.no>
Date: Mon Mar 3 15:43:02 2014 +0100
sd-dhcp-lease: add Root Path support
This is necessary when mounting /dev/nfs based on a DHCP lease.
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h
index d12bcac..1b157fd 100644
--- a/src/libsystemd-network/dhcp-lease-internal.h
+++ b/src/libsystemd-network/dhcp-lease-internal.h
@@ -46,6 +46,7 @@ struct sd_dhcp_lease {
uint16_t mtu;
char *domainname;
char *hostname;
+ char *root_path;
};
int dhcp_lease_new(sd_dhcp_lease **ret);
diff --git a/src/libsystemd-network/dhcp-protocol.h b/src/libsystemd-network/dhcp-protocol.h
index 81d36ce..9aa9618 100644
--- a/src/libsystemd-network/dhcp-protocol.h
+++ b/src/libsystemd-network/dhcp-protocol.h
@@ -105,6 +105,7 @@ enum {
DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
DHCP_OPTION_HOST_NAME = 12,
DHCP_OPTION_DOMAIN_NAME = 15,
+ DHCP_OPTION_ROOT_PATH = 17,
DHCP_OPTION_INTERFACE_MTU = 26,
DHCP_OPTION_NTP_SERVER = 42,
DHCP_OPTION_REQUESTED_IP_ADDRESS = 50,
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 0529b6d..722dd0a 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -96,6 +96,18 @@ int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname) {
return 0;
}
+int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path) {
+ assert_return(lease, -EINVAL);
+ assert_return(root_path, -EINVAL);
+
+ if (lease->root_path)
+ *root_path = lease->root_path;
+ else
+ return -ENOENT;
+
+ return 0;
+}
+
int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr) {
assert_return(lease, -EINVAL);
assert_return(addr, -EINVAL);
@@ -212,6 +224,14 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
break;
+ case DHCP_OPTION_ROOT_PATH:
+ if (len >= 1) {
+ free(lease->root_path);
+ lease->root_path = strndup((const char *)option, len);
+ }
+
+ break;
+
case DHCP_OPTION_RENEWAL_T1_TIME:
if (len == 4) {
memcpy(&val, option, 4);
@@ -323,6 +343,10 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
if (r >= 0)
fprintf(f, "HOSTNAME=%s\n", string);
+ r = sd_dhcp_lease_get_root_path(lease, &string);
+ if (r >= 0)
+ fprintf(f, "ROOT_PATH=%s\n", string);
+
r = 0;
fflush(f);
@@ -361,6 +385,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
"MTU", &mtu,
"DOMAINNAME", &lease->domainname,
"HOSTNAME", &lease->hostname,
+ "ROOT_PATH", &lease->root_path,
NULL);
if (r < 0) {
if (r == -ENOENT)
diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h
index af687a6..5b34b2a 100644
--- a/src/systemd/sd-dhcp-lease.h
+++ b/src/systemd/sd-dhcp-lease.h
@@ -37,5 +37,6 @@ int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *a
int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
+int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path);
#endif
More information about the systemd-commits
mailing list