diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index 0d8f00106c..5166e05cbc 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -91,27 +91,6 @@ - - Type= - The type of DUID specified in this section. The following values are - supported: - raw : If Type=raw, then RawData= specifies - the entire DUID. For e.g: RawData=00:02:00:00:ab:11:f9:2a:c2:77:29:f9:5c:00 - specifies a 14 byte long DUID-EN ("00:02"), with enterprise number 43793 ("00:00:ab:11"), - and identifier value "f9:2a:c2:77:29:f9:5c:00".If Type is not specified and - RawData is specified, Type defaults to 'raw'. - Type will support the following values in the future: - link-layer-and-time : If Type=link-layer-and-time, then - MACAddress= and TimeStamp= specify the hardware - address and time-stamp for DUID-LLT. - vendor : If Type=vendor, then EnterpriseNumber= - and RawData= specify the enterprise number and identifier for DUID-EN. - link-layer : If Type=link-layer, then MACAddress= - specifies the hardware address for DUID-LL. - uuid : If Type=uuid, then UUID= specifies DUID-UUID. - - - RawData= Specifies the DUID bytes as a single newline-terminated, hexadecimal @@ -120,33 +99,6 @@ - - The following options will be supported in the future: - - - - MACAddress= - Specifies the link-layer address for DUID Type or . - - - TimeStamp= - Specifies the DUID generation time for DUID Type . - - - EnterpriseNumber= - Specifies the enterprise number for DUID Type - . - - - UUID= - Specifies the UUID for DUID Type . - - - - - See Also diff --git a/man/systemd.network.xml b/man/systemd.network.xml index c14d3770e2..c9ef041004 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -852,27 +852,6 @@ - - Type= - The type of DUID specified in this section. The following values are - supported: - raw : If Type=raw, then RawData= specifies - the entire DUID. For e.g: RawData=00:02:00:00:ab:11:f9:2a:c2:77:29:f9:5c:00 - specifies a 14 byte long DUID-EN ("00:02"), with enterprise number 43793 ("00:00:ab:11"), - and identifier value "f9:2a:c2:77:29:f9:5c:00".If Type is not specified and - RawData is specified, Type defaults to 'raw'. - Type will support the following values in the future: - link-layer-and-time : If Type=link-layer-and-time, then - MACAddress= and TimeStamp= specify the hardware - address and time-stamp for DUID-LLT. - vendor : If Type=vendor, then EnterpriseNumber= - and RawData= specify the enterprise number and identifier for DUID-EN. - link-layer : If Type=link-layer, then MACAddress= - specifies the hardware address for DUID-LL. - uuid : If Type=uuid, then UUID= specifies DUID-UUID. - - - RawData= Specifies the DUID bytes as a single newline-terminated, hexadecimal @@ -882,33 +861,6 @@ - - The following options will be supported in the future: - - - - MACAddress= - Specifies the link-layer address for DUID Type or . - - - TimeStamp= - Specifies the DUID generation time for DUID Type . - - - EnterpriseNumber= - Specifies the enterprise number for DUID Type . - - - UUID= - Specifies the UUID for DUID Type . - - - - - [DHCPServer] Section Options The [DHCPServer] section contains diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 0e2d757b2b..99b3a1d01f 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -355,8 +355,9 @@ int config_parse_iaid(const char *unit, r = safe_atou32(rvalue, &iaid); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Unable to read IAID: %s", rvalue); - return r; + log_syntax(unit, LOG_ERR, filename, line, r, + "Unable to read IAID, ignoring assignment: %s", rvalue); + return 0; } *((uint32_t *)data) = iaid; diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c index 8b149124b3..73a8d16b58 100644 --- a/src/network/networkd-conf.c +++ b/src/network/networkd-conf.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -24,6 +22,7 @@ #include "conf-parser.h" #include "def.h" #include "dhcp-identifier.h" +#include "hexdecoct.h" #include "networkd-conf.h" #include "string-table.h" @@ -58,53 +57,39 @@ int config_parse_duid_rawdata( const char *rvalue, void *data, void *userdata) { - int r; - long byte; - char *cbyte, *pnext; + int r, n1, n2, byte; + char *cbyte; 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; + 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; assert(filename); assert(lvalue); assert(rvalue); 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; - } + duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type + : n->duid_type; - if (*duid_type == _DUID_TYPE_INVALID) - *duid_type = DUID_TYPE_RAW; + if (duidtype == _DUID_TYPE_INVALID) + duidtype = DUID_TYPE_RAW; - switch (*duid_type) { + switch (duidtype) { case DUID_TYPE_LLT: /* RawData contains DUID-LLT link-layer address (offset 6) */ - duid_index = 6; + duid_start_offset = 6; break; case DUID_TYPE_EN: /* RawData contains DUID-EN identifier (offset 4) */ - duid_index = 4; + duid_start_offset = 4; break; case DUID_TYPE_LL: /* RawData contains DUID-LL link-layer address (offset 2) */ - duid_index = 2; + duid_start_offset = 2; break; case DUID_TYPE_UUID: /* RawData specifies UUID (offset 0) - fall thru */ @@ -114,42 +99,66 @@ int config_parse_duid_rawdata( break; } - if (*duid_type != DUID_TYPE_RAW) - *dhcp_duid_type = (uint16_t)(*duid_type); + if (duidtype != DUID_TYPE_RAW) + dhcp_duid_type = (uint16_t)duidtype; /* RawData contains DUID in format " NN:NN:NN... " */ - while (true) { + for (;;) { r = extract_first_word(&pduid, &cbyte, ":", 0); if (r < 0) { - log_error("Failed to read DUID."); - return -EINVAL; + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to read DUID, ignoring assignment: %s.", rvalue); + goto exit; } if (r == 0) break; - if (duid_index >= MAX_DUID_LEN) { - log_error("DUID length exceeds maximum length."); - return -EINVAL; + if ((duid_start_offset + dhcp_duid_len) >= MAX_DUID_LEN) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Max DUID length exceeded, ignoring assignment: %s.", rvalue); + goto exit; } - errno = 0; - byte = strtol(cbyte, &pnext, 16); - if ((errno == ERANGE && (byte == LONG_MAX || byte == LONG_MIN)) - || (errno != 0 && byte == 0) || (cbyte == pnext)) { - log_error("Invalid DUID byte: %s.", cbyte); - return -EINVAL; + len = strlen(cbyte); + if ((len == 0) || (len > 2)) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue); + goto exit; } + n2 = 0; + n1 = unhexchar(cbyte[0]); + if (len == 2) + n2 = unhexchar(cbyte[1]); + if ((n1 < 0) || (n2 < 0)) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue); + goto exit; + } + byte = (n1 << (4 * (len-1))) | n2; /* 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))); + if ((duidtype == DUID_TYPE_RAW) && (count < 2)) { + dhcp_duid_type |= (byte << (8 * (1 - count))); count++; continue; } - dhcp_duid[duid_index++] = byte; + dhcp_duid[duid_start_offset + dhcp_duid_len] = byte; + dhcp_duid_len++; } - *dhcp_duid_len = duid_index; + 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); + } +exit: return 0; } diff --git a/src/network/networkd-conf.h b/src/network/networkd-conf.h index efc370f839..671e656d7b 100644 --- a/src/network/networkd-conf.h +++ b/src/network/networkd-conf.h @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - #pragma once /***