summaryrefslogtreecommitdiff
path: root/src/network/networkd-conf.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-28 23:23:45 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-05-03 12:23:01 -0400
commit8341a5c381a72d504768fe296f8e30a324eeff77 (patch)
tree70dc29a424eafc5d533e2b4af2c1fcf04326ab27 /src/network/networkd-conf.c
parentd7df2fd317bb24d4d194dbd0d391f4dfa64d6924 (diff)
networkd: rework duid_{type,duid_type,duid,duid_len} setting
Separate fields are replaced with a struct. Second second duid type field is removed. The first field was used to carry the result of DUIDType= configuration, and the second was either a copy of this, or contained the type extracted from DuidRawData. The semantics are changed so that the type specified in DUIDType is always used. DUIDRawData= no longer overrides the type setting. The networkd code is now more constrained than the sd-dhcp code: DUIDRawData cannot have 0 length, length 0 is treated the same as unsetting. Likewise, it is not possible to set a DUIDType=0. If it ever becomes necessary to set type=0 or a zero-length duid, the code can be changed to support that. Nevertheless, I think that's unlikely. This addresses #3127 § 1 and 3. v2: - rename DUID.duid, DUID.duid_len to DUID.raw_data, DUID.raw_data_len
Diffstat (limited to 'src/network/networkd-conf.c')
-rw-r--r--src/network/networkd-conf.c87
1 files changed, 14 insertions, 73 deletions
diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c
index 70f0121d6d..1b2047f8f4 100644
--- a/src/network/networkd-conf.c
+++ b/src/network/networkd-conf.c
@@ -41,7 +41,7 @@ static const char* const duid_type_table[_DUID_TYPE_MAX] = {
[DUID_TYPE_LLT] = "link-layer-time",
[DUID_TYPE_EN] = "vendor",
[DUID_TYPE_LL] = "link-layer",
- [DUID_TYPE_UUID] = "uuid"
+ [DUID_TYPE_UUID] = "uuid",
};
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");
@@ -58,69 +58,29 @@ int config_parse_duid_rawdata(
void *data,
void *userdata) {
- int r;
- char *cbyte;
- const char *pduid = rvalue;
- Manager *m = userdata;
- Network *n = userdata;
- DUIDType duidtype;
- uint16_t dhcp_duid_type = 0;
- uint8_t dhcp_duid[MAX_DUID_LEN];
- size_t len, count = 0, duid_start_offset = 0, dhcp_duid_len = 0;
+ DUID *ret = data;
+ uint8_t raw_data[MAX_DUID_LEN];
+ unsigned count = 0;
assert(filename);
assert(lvalue);
assert(rvalue);
- assert(userdata);
+ assert(ret);
- duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type : n->duid_type;
-
- if (duidtype == _DUID_TYPE_INVALID)
- duidtype = DUID_TYPE_RAW;
-
- switch (duidtype) {
-
- case DUID_TYPE_LLT:
- /* RawData contains DUID-LLT link-layer address (offset 6) */
- duid_start_offset = 6;
- break;
-
- case DUID_TYPE_EN:
- /* RawData contains DUID-EN identifier (offset 4) */
- duid_start_offset = 4;
- break;
-
- case DUID_TYPE_LL:
- /* RawData contains DUID-LL link-layer address (offset 2) */
- duid_start_offset = 2;
- break;
-
- case DUID_TYPE_UUID:
- /* RawData specifies UUID (offset 0) - fall thru */
-
- case DUID_TYPE_RAW:
- /* First two bytes of RawData is DUID Type - fall thru */
-
- default:
- break;
- }
-
- if (duidtype != DUID_TYPE_RAW)
- dhcp_duid_type = (uint16_t) duidtype;
-
- /* RawData contains DUID in format " NN:NN:NN... " */
+ /* RawData contains DUID in format "NN:NN:NN..." */
for (;;) {
- int n1, n2;
+ int n1, n2, len, r;
uint32_t byte;
+ char *cbyte;
- r = extract_first_word(&pduid, &cbyte, ":", 0);
+ r = extract_first_word(&rvalue, &cbyte, ":", 0);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
return 0;
}
if (r == 0)
break;
- if (duid_start_offset + dhcp_duid_len >= MAX_DUID_LEN) {
+ if (count >= MAX_DUID_LEN) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
return 0;
}
@@ -142,30 +102,11 @@ int config_parse_duid_rawdata(
}
byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
-
- /* If DUID_TYPE_RAW, first two bytes hold DHCP DUID type code */
- if (duidtype == DUID_TYPE_RAW && count < 2) {
- dhcp_duid_type |= (byte << (8 * (1 - count)));
- count++;
- continue;
- }
-
- dhcp_duid[duid_start_offset + dhcp_duid_len] = byte;
- dhcp_duid_len++;
- }
-
- if (ltype == DUID_CONFIG_SOURCE_GLOBAL) {
- m->duid_type = duidtype;
- m->dhcp_duid_type = dhcp_duid_type;
- m->dhcp_duid_len = dhcp_duid_len;
- memcpy(&m->dhcp_duid[duid_start_offset], dhcp_duid, dhcp_duid_len);
- } else {
- /* DUID_CONFIG_SOURCE_NETWORK */
- n->duid_type = duidtype;
- n->dhcp_duid_type = dhcp_duid_type;
- n->dhcp_duid_len = dhcp_duid_len;
- memcpy(&n->dhcp_duid[duid_start_offset], dhcp_duid, dhcp_duid_len);
+ raw_data[count++] = byte;
}
+ assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
+ memcpy(ret->raw_data, raw_data, count);
+ ret->raw_data_len = count;
return 0;
}