summaryrefslogtreecommitdiff
path: root/src/network/networkd-conf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-conf.c')
-rw-r--r--src/network/networkd-conf.c86
1 files changed, 54 insertions, 32 deletions
diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c
index 4bc92b8171..8b149124b3 100644
--- a/src/network/networkd-conf.c
+++ b/src/network/networkd-conf.c
@@ -3,7 +3,7 @@
/***
This file is part of systemd.
- Copyright 2014 Tom Gundersen <teg@jklm.no>
+ Copyright 2014 Vinay Kulkarni <kulkarniv@vmware.com>
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
@@ -37,17 +37,17 @@ int manager_parse_config_file(Manager *m) {
false, m);
}
-static const char* const dhcp_duid_type_table[_DHCP_DUID_TYPE_MAX] = {
- [DHCP_DUID_TYPE_RAW] = "raw",
- [DHCP_DUID_TYPE_LLT] = "link-layer-time",
- [DHCP_DUID_TYPE_EN] = "vendor",
- [DHCP_DUID_TYPE_LL] = "link-layer",
- [DHCP_DUID_TYPE_UUID] = "uuid"
+static const char* const duid_type_table[_DUID_TYPE_MAX] = {
+ [DUID_TYPE_RAW] = "raw",
+ [DUID_TYPE_LLT] = "link-layer-time",
+ [DUID_TYPE_EN] = "vendor",
+ [DUID_TYPE_LL] = "link-layer",
+ [DUID_TYPE_UUID] = "uuid"
};
-DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_duid_type, DHCPDUIDType);
-DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_duid_type, dhcp_duid_type, DHCPDUIDType, "Failed to parse DHCP DUID type");
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_duid_type, duid_type, DUIDType, "Failed to parse DUID type");
-int config_parse_dhcp_duid_raw(
+int config_parse_duid_rawdata(
const char *unit,
const char *filename,
unsigned line,
@@ -61,39 +61,61 @@ int config_parse_dhcp_duid_raw(
int r;
long byte;
char *cbyte, *pnext;
- const char *pduid = (const char *)rvalue;
- size_t count = 0, duid_len = 0;
- Manager *m = userdata;
+ const char *pduid = rvalue;
+ size_t count = 0, duid_index = 0;
+ Manager *m;
+ Network *n;
+ DUIDType *duid_type;
+ uint16_t *dhcp_duid_type;
+ size_t *dhcp_duid_len;
+ uint8_t *dhcp_duid;
assert(filename);
assert(lvalue);
assert(rvalue);
- assert(m);
- assert(m->dhcp_duid_type != _DHCP_DUID_TYPE_INVALID);
+ assert(userdata);
+
+ if (ltype == DUID_CONFIG_SOURCE_GLOBAL) {
+ m = userdata;
+ duid_type = &m->duid_type;
+ dhcp_duid_type = &m->dhcp_duid_type;
+ dhcp_duid_len = &m->dhcp_duid_len;
+ dhcp_duid = m->dhcp_duid;
+ } else {
+ /* DUID_CONFIG_SOURCE_NETWORK */
+ n = userdata;
+ duid_type = &n->duid_type;
+ dhcp_duid_type = &n->dhcp_duid_type;
+ dhcp_duid_len = &n->dhcp_duid_len;
+ dhcp_duid = n->dhcp_duid;
+ }
+
+ if (*duid_type == _DUID_TYPE_INVALID)
+ *duid_type = DUID_TYPE_RAW;
- switch (m->dhcp_duid_type) {
- case DHCP_DUID_TYPE_LLT:
+ switch (*duid_type) {
+ case DUID_TYPE_LLT:
/* RawData contains DUID-LLT link-layer address (offset 6) */
- duid_len = 6;
+ duid_index = 6;
break;
- case DHCP_DUID_TYPE_EN:
+ case DUID_TYPE_EN:
/* RawData contains DUID-EN identifier (offset 4) */
- duid_len = 4;
+ duid_index = 4;
break;
- case DHCP_DUID_TYPE_LL:
+ case DUID_TYPE_LL:
/* RawData contains DUID-LL link-layer address (offset 2) */
- duid_len = 2;
+ duid_index = 2;
break;
- case DHCP_DUID_TYPE_UUID:
+ case DUID_TYPE_UUID:
/* RawData specifies UUID (offset 0) - fall thru */
- case DHCP_DUID_TYPE_RAW:
+ case DUID_TYPE_RAW:
/* First two bytes of RawData is DUID Type - fall thru */
default:
break;
}
- if (m->dhcp_duid_type != DHCP_DUID_TYPE_RAW)
- m->dhcp_duid.type = htobe16(m->dhcp_duid_type);
+ if (*duid_type != DUID_TYPE_RAW)
+ *dhcp_duid_type = (uint16_t)(*duid_type);
/* RawData contains DUID in format " NN:NN:NN... " */
while (true) {
@@ -104,7 +126,7 @@ int config_parse_dhcp_duid_raw(
}
if (r == 0)
break;
- if (duid_len >= MAX_DUID_LEN) {
+ if (duid_index >= MAX_DUID_LEN) {
log_error("DUID length exceeds maximum length.");
return -EINVAL;
}
@@ -117,17 +139,17 @@ int config_parse_dhcp_duid_raw(
return -EINVAL;
}
- /* If DHCP_DUID_TYPE_RAW, first two bytes holds DUID Type */
- if ((m->dhcp_duid_type == DHCP_DUID_TYPE_RAW) && (count < 2)) {
- m->dhcp_duid.type |= (byte << (8 * count));
+ /* If DUID_TYPE_RAW, first two bytes hold DHCP DUID type code */
+ if ((*duid_type == DUID_TYPE_RAW) && (count < 2)) {
+ *dhcp_duid_type |= (byte << (8 * (1 - count)));
count++;
continue;
}
- m->dhcp_duid.raw.data[duid_len++] = byte;
+ dhcp_duid[duid_index++] = byte;
}
- m->dhcp_duid_len = sizeof(m->dhcp_duid.type) + duid_len;
+ *dhcp_duid_len = duid_index;
return 0;
}