diff -uNr systemd-228/src/network/networkd-conf.c systemd-228-duid/src/network/networkd-conf.c
--- systemd-228/src/network/networkd-conf.c 2016-06-21 21:08:43.975661002 +0000
+++ systemd-228-duid/src/network/networkd-conf.c 2016-06-23 13:46:08.990634508 +0000
@@ -21,9 +21,11 @@
#include <ctype.h>
+#include "alloc-util.h"
#include "conf-parser.h"
#include "def.h"
#include "dhcp-identifier.h"
+#include "hexdecoct.h"
#include "networkd-conf.h"
#include "string-table.h"
@@ -32,7 +34,7 @@
return config_parse_many(PKGSYSCONFDIR "/networkd.conf",
CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
- "DUID\0",
+ "DHCP\0",
config_item_perf_lookup, networkd_gperf_lookup,
false, m);
}
@@ -58,17 +60,13 @@
const char *rvalue,
void *data,
void *userdata) {
- int r;
- long byte;
- char *cbyte, *pnext;
- 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;
+ size_t count = 0;
assert(filename);
assert(lvalue);
@@ -90,66 +88,50 @@
dhcp_duid = n->dhcp_duid;
}
- if (*duid_type == _DUID_TYPE_INVALID)
- *duid_type = DUID_TYPE_RAW;
-
- switch (*duid_type) {
- case DUID_TYPE_LLT:
- /* RawData contains DUID-LLT link-layer address (offset 6) */
- duid_index = 6;
- break;
- case DUID_TYPE_EN:
- /* RawData contains DUID-EN identifier (offset 4) */
- duid_index = 4;
- break;
- case DUID_TYPE_LL:
- /* RawData contains DUID-LL link-layer address (offset 2) */
- duid_index = 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 ((*duid_type < DUID_TYPE_LLT) || (*duid_type > DUID_TYPE_UUID)) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID type, ignoring assignment: %s.", rvalue);
+ return 0;
}
+ *dhcp_duid_type = (uint16_t)(*duid_type);
- if (*duid_type != DUID_TYPE_RAW)
- *dhcp_duid_type = (uint16_t)(*duid_type);
+ /* RawData contains DUID in format "NN:NN:NN..." */
+ for (;;) {
+ int n1, n2, len, r;
+ uint32_t byte;
+ _cleanup_free_ char *cbyte = NULL;
- /* RawData contains DUID in format " NN:NN:NN... " */
- while (true) {
- r = extract_first_word(&pduid, &cbyte, ":", 0);
+ r = extract_first_word(&rvalue, &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);
+ return 0;
}
if (r == 0)
break;
- if (duid_index >= MAX_DUID_LEN) {
- log_error("DUID length exceeds maximum length.");
- return -EINVAL;
+ if (count >= MAX_DUID_LEN) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
+ return 0;
}
- 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 != 1 && len != 2) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
+ return 0;
}
-
- /* 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;
+ n1 = unhexchar(cbyte[0]);
+ if (len == 2)
+ n2 = unhexchar(cbyte[1]);
+ else
+ n2 = 0;
+
+ if (n1 < 0 || n2 < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
+ return 0;
}
- dhcp_duid[duid_index++] = byte;
+ byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
+ dhcp_duid[count++] = byte;
}
- *dhcp_duid_len = duid_index;
-
+ *dhcp_duid_len = count;
return 0;
}
diff -uNr systemd-228/src/network/networkd-gperf.gperf systemd-228-duid/src/network/networkd-gperf.gperf
--- systemd-228/src/network/networkd-gperf.gperf 2016-06-21 21:08:43.975661002 +0000
+++ systemd-228-duid/src/network/networkd-gperf.gperf 2016-06-21 21:17:18.179685521 +0000
@@ -14,5 +14,5 @@
%struct-type
%includes
%%
-DUID.Type, config_parse_duid_type, 0, offsetof(Manager, duid_type)
-DUID.RawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_GLOBAL, offsetof(Manager, dhcp_duid)
+DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Manager, duid_type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_GLOBAL, offsetof(Manager, dhcp_duid)
diff -uNr systemd-228/src/network/networkd-network-gperf.gperf systemd-228-duid/src/network/networkd-network-gperf.gperf
--- systemd-228/src/network/networkd-network-gperf.gperf 2016-06-21 21:08:43.975661002 +0000
+++ systemd-228-duid/src/network/networkd-network-gperf.gperf 2016-06-21 21:16:14.571682488 +0000
@@ -27,9 +27,6 @@
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(Network, match_arch)
Link.MACAddress, config_parse_hwaddr, 0, offsetof(Network, mac)
Link.MTUBytes, config_parse_iec_size, 0, offsetof(Network, mtu)
-Link.IAID, config_parse_iaid, 0, offsetof(Network, iaid)
-DUID.Type, config_parse_duid_type, 0, offsetof(Network, duid_type)
-DUID.RawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_NETWORK, offsetof(Network, dhcp_duid)
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
@@ -82,6 +79,9 @@
DHCP.VendorClassIdentifier, config_parse_string, 0, offsetof(Network, dhcp_vendor_class_identifier)
DHCP.RouteMetric, config_parse_unsigned, 0, offsetof(Network, dhcp_route_metric)
DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_timezone)
+DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Network, duid_type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_NETWORK, offsetof(Network, dhcp_duid)
+DHCP.IAID, config_parse_iaid, 0, offsetof(Network, iaid)
DHCPServer.MaxLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_max_lease_time_usec)
DHCPServer.DefaultLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_default_lease_time_usec)
DHCPServer.EmitDNS, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_dns)
diff -uNr systemd-228/src/network/networkd-network.c systemd-228-duid/src/network/networkd-network.c
--- systemd-228/src/network/networkd-network.c 2016-06-21 21:08:43.975661002 +0000
+++ systemd-228-duid/src/network/networkd-network.c 2016-06-23 13:46:37.878635885 +0000
@@ -133,7 +133,6 @@
r = config_parse(NULL, filename, file,
"Match\0"
"Link\0"
- "DUID\0"
"Network\0"
"Address\0"
"Route\0"