summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-05-21 08:40:02 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2015-06-04 17:32:01 +0200
commit22eb15ba83ca90b46bbcead84f276ba6ecfcf0a5 (patch)
tree69e18fdc2496a21204bc9ab6e531161b4a8f8c1c
parent366da20bf486bf2dbba092d9edcda050490e0d8a (diff)
downloadNetworkManager-22eb15ba83ca90b46bbcead84f276ba6ecfcf0a5.tar.gz
systemd/dhcp: add support for vendor specific DHCP option
This adds support for DHCP option 43 (Vendor Specific Information) to the internal DHCP client. The option carries an opaque object of n octets, interpreted by vendor-specific code on the clients and servers.
-rw-r--r--src/systemd/src/libsystemd-network/dhcp-lease-internal.h2
-rw-r--r--src/systemd/src/libsystemd-network/dhcp-protocol.h1
-rw-r--r--src/systemd/src/libsystemd-network/sd-dhcp-lease.c52
-rw-r--r--src/systemd/src/systemd/sd-dhcp-lease.h1
4 files changed, 56 insertions, 0 deletions
diff --git a/src/systemd/src/libsystemd-network/dhcp-lease-internal.h b/src/systemd/src/libsystemd-network/dhcp-lease-internal.h
index 2d7bf03bab..91843beae5 100644
--- a/src/systemd/src/libsystemd-network/dhcp-lease-internal.h
+++ b/src/systemd/src/libsystemd-network/dhcp-lease-internal.h
@@ -74,6 +74,8 @@ struct sd_dhcp_lease {
char *root_path;
uint8_t *client_id;
size_t client_id_len;
+ uint8_t *vendor_specific;
+ size_t vendor_specific_size;
};
int dhcp_lease_new(sd_dhcp_lease **ret);
diff --git a/src/systemd/src/libsystemd-network/dhcp-protocol.h b/src/systemd/src/libsystemd-network/dhcp-protocol.h
index da483feadf..3a1e473afa 100644
--- a/src/systemd/src/libsystemd-network/dhcp-protocol.h
+++ b/src/systemd/src/libsystemd-network/dhcp-protocol.h
@@ -127,6 +127,7 @@ enum {
DHCP_OPTION_BROADCAST = 28,
DHCP_OPTION_STATIC_ROUTE = 33,
DHCP_OPTION_NTP_SERVER = 42,
+ DHCP_OPTION_VENDOR_SPECIFIC = 43,
DHCP_OPTION_REQUESTED_IP_ADDRESS = 50,
DHCP_OPTION_IP_ADDRESS_LEASE_TIME = 51,
DHCP_OPTION_OVERLOAD = 52,
diff --git a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c
index ee6d72dffc..ae44415df2 100644
--- a/src/systemd/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/systemd/src/libsystemd-network/sd-dhcp-lease.c
@@ -180,6 +180,19 @@ int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routes
return 0;
}
+int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, uint8_t **data) {
+ assert_return(lease, -EINVAL);
+ assert_return(data, -EINVAL);
+
+ if (lease->vendor_specific) {
+ *data = lease->vendor_specific;
+ return lease->vendor_specific_size;
+ } else
+ return -ENOENT;
+
+ return 0;
+}
+
sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease) {
if (lease)
assert_se(REFCNT_INC(lease->n_ref) >= 2);
@@ -275,6 +288,24 @@ static int lease_parse_string(const uint8_t *option, size_t len, char **ret) {
return 0;
}
+static int lease_parse_binary(const uint8_t *option, size_t len, uint8_t **ret) {
+ assert (option);
+ assert (ret);
+
+ if (len >= 1) {
+ uint8_t *data;
+
+ data = memdup(option, len);
+ if (!data)
+ return -errno;
+
+ free(*ret);
+ *ret = data;
+ }
+
+ return 0;
+}
+
static int lease_parse_in_addrs_aux(const uint8_t *option, size_t len, struct in_addr **ret, size_t *ret_size, size_t mult) {
assert(option);
assert(ret);
@@ -571,6 +602,14 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
return r;
break;
+
+ case DHCP_OPTION_VENDOR_SPECIFIC:
+ r = lease_parse_binary(option, len, &lease->vendor_specific);
+ if (r < 0)
+ return r;
+ lease->vendor_specific_size = len;
+
+ break;
}
return 0;
@@ -598,6 +637,7 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
const uint8_t *client_id;
size_t client_id_len;
const char *string;
+ uint8_t *data;
uint16_t mtu;
struct sd_dhcp_route *routes;
int r;
@@ -670,6 +710,18 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
if (r >= 0)
serialize_dhcp_routes(f, "ROUTES", routes, r);
+ r = sd_dhcp_lease_get_vendor_specific(lease, &data);
+ if (r >= 0) {
+ _cleanup_free_ char *option_hex = NULL;
+
+ option_hex = hexmem(data, r);
+ if (!option_hex) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ fprintf(f, "VENDOR_SPECIFIC=%s\n", option_hex);
+ }
+
r = sd_dhcp_lease_get_client_id(lease, &client_id, &client_id_len);
if (r >= 0) {
_cleanup_free_ char *client_id_hex = NULL;
diff --git a/src/systemd/src/systemd/sd-dhcp-lease.h b/src/systemd/src/systemd/sd-dhcp-lease.h
index 80d32134b1..28ee120bcb 100644
--- a/src/systemd/src/systemd/sd-dhcp-lease.h
+++ b/src/systemd/src/systemd/sd-dhcp-lease.h
@@ -47,6 +47,7 @@ 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);
int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routesgn);
+int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, uint8_t **data);
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
size_t *client_id_len);