summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-conf.c87
-rw-r--r--src/network/networkd-conf.h29
-rw-r--r--src/network/networkd-dhcp4.c24
-rw-r--r--src/network/networkd-dhcp6.c16
-rw-r--r--src/network/networkd-gperf.gperf4
-rw-r--r--src/network/networkd-link.c35
-rw-r--r--src/network/networkd-manager.c2
-rw-r--r--src/network/networkd-network-gperf.gperf4
-rw-r--r--src/network/networkd-network.c2
-rw-r--r--src/network/networkd-network.h15
-rw-r--r--src/network/networkd.h14
11 files changed, 88 insertions, 144 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;
}
diff --git a/src/network/networkd-conf.h b/src/network/networkd-conf.h
index 671e656d7b..c7bfb42a72 100644
--- a/src/network/networkd-conf.h
+++ b/src/network/networkd-conf.h
@@ -21,14 +21,29 @@
#include "networkd.h"
-typedef enum DuidConfigSource {
- DUID_CONFIG_SOURCE_GLOBAL = 0,
- DUID_CONFIG_SOURCE_NETWORK,
-} DuidConfigSource;
-
int manager_parse_config_file(Manager *m);
const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, unsigned length);
-int config_parse_duid_type(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-int config_parse_duid_rawdata(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_duid_type(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata);
+int config_parse_duid_rawdata(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata);
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index d31ea4d066..89926e8a7e 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -628,28 +628,24 @@ int dhcp4_configure(Link *link) {
}
switch (link->network->dhcp_client_identifier) {
- case DHCP_CLIENT_ID_DUID:
+ case DHCP_CLIENT_ID_DUID: {
/* If configured, apply user specified DUID and/or IAID */
- if (link->network->duid_type != _DUID_TYPE_INVALID)
- r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
- link->network->iaid,
- link->network->dhcp_duid_type,
- link->network->dhcp_duid,
- link->network->dhcp_duid_len);
- else
- r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
- link->network->iaid,
- link->manager->dhcp_duid_type,
- link->manager->dhcp_duid,
- link->manager->dhcp_duid_len);
+ const DUID *duid = link_duid(link);
+
+ r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
+ link->network->iaid,
+ duid->type,
+ duid->raw_data_len > 0 ? duid->raw_data : NULL,
+ duid->raw_data_len);
if (r < 0)
return r;
break;
+ }
case DHCP_CLIENT_ID_MAC:
r = sd_dhcp_client_set_client_id(link->dhcp_client,
ARPHRD_ETHER,
(const uint8_t *) &link->mac,
- sizeof (link->mac));
+ sizeof(link->mac));
if (r < 0)
return r;
break;
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index b9c4b8962c..ccca4e9522 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -206,6 +206,7 @@ int dhcp6_request_address(Link *link) {
int dhcp6_configure(Link *link) {
sd_dhcp6_client *client = NULL;
int r;
+ const DUID *duid;
assert(link);
@@ -234,16 +235,11 @@ int dhcp6_configure(Link *link) {
if (r < 0)
goto error;
- if (link->network->duid_type != _DUID_TYPE_INVALID)
- r = sd_dhcp6_client_set_duid(client,
- link->network->dhcp_duid_type,
- link->network->dhcp_duid,
- link->network->dhcp_duid_len);
- else
- r = sd_dhcp6_client_set_duid(client,
- link->manager->dhcp_duid_type,
- link->manager->dhcp_duid,
- link->manager->dhcp_duid_len);
+ duid = link_duid(link);
+ r = sd_dhcp6_client_set_duid(client,
+ duid->type,
+ duid->raw_data_len > 0 ? duid->raw_data : NULL,
+ duid->raw_data_len);
if (r < 0)
goto error;
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
index afc71b4cb8..3fdfe74955 100644
--- a/src/network/networkd-gperf.gperf
+++ b/src/network/networkd-gperf.gperf
@@ -14,5 +14,5 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
-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)
+DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Manager, duid.type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, duid)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a88e4c34ed..c646af1f1a 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2879,6 +2879,8 @@ int link_update(Link *link, sd_netlink_message *m) {
}
if (link->dhcp_client) {
+ const DUID *duid = link_duid(link);
+
r = sd_dhcp_client_set_mac(link->dhcp_client,
(const uint8_t *) &link->mac,
sizeof (link->mac),
@@ -2886,23 +2888,18 @@ int link_update(Link *link, sd_netlink_message *m) {
if (r < 0)
return log_link_warning_errno(link, r, "Could not update MAC address in DHCP client: %m");
- if (link->network->duid_type != _DUID_TYPE_INVALID)
- r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
- link->network->iaid,
- link->network->dhcp_duid_type,
- link->network->dhcp_duid,
- link->network->dhcp_duid_len);
- else
- r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
- link->network->iaid,
- link->manager->dhcp_duid_type,
- link->manager->dhcp_duid,
- link->manager->dhcp_duid_len);
+ r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
+ link->network->iaid,
+ duid->type,
+ duid->raw_data_len > 0 ? duid->raw_data : NULL,
+ duid->raw_data_len);
if (r < 0)
return log_link_warning_errno(link, r, "Could not update DUID/IAID in DHCP client: %m");
}
if (link->dhcp6_client) {
+ const DUID* duid = link_duid(link);
+
r = sd_dhcp6_client_set_mac(link->dhcp6_client,
(const uint8_t *) &link->mac,
sizeof (link->mac),
@@ -2915,16 +2912,10 @@ int link_update(Link *link, sd_netlink_message *m) {
if (r < 0)
return log_link_warning_errno(link, r, "Could not update DHCPv6 IAID: %m");
- if (link->network->duid_type != _DUID_TYPE_INVALID)
- r = sd_dhcp6_client_set_duid(link->dhcp6_client,
- link->network->dhcp_duid_type,
- link->network->dhcp_duid,
- link->network->dhcp_duid_len);
- else
- r = sd_dhcp6_client_set_duid(link->dhcp6_client,
- link->manager->dhcp_duid_type,
- link->manager->dhcp_duid,
- link->manager->dhcp_duid_len);
+ r = sd_dhcp6_client_set_duid(link->dhcp6_client,
+ duid->type,
+ duid->raw_data_len > 0 ? duid->raw_data : NULL,
+ duid->raw_data_len);
if (r < 0)
return log_link_warning_errno(link, r, "Could not update DHCPv6 DUID: %m");
}
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 0cb5781c71..5dcd4df536 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -1037,7 +1037,7 @@ int manager_new(Manager **ret) {
if (r < 0)
return r;
- m->duid_type = DUID_TYPE_EN;
+ m->duid.type = DUID_TYPE_EN;
*ret = m;
m = NULL;
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 654d6a0316..6bf57cdf99 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -83,8 +83,8 @@ DHCP.Hostname, config_parse_hostname,
DHCP.RequestBroadcast, config_parse_bool, 0, offsetof(Network, dhcp_broadcast)
DHCP.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
DHCP.VendorClassIdentifier, config_parse_string, 0, offsetof(Network, dhcp_vendor_class_identifier)
-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.DUIDType, config_parse_duid_type, 0, offsetof(Network, duid.type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, duid)
DHCP.RouteMetric, config_parse_unsigned, 0, offsetof(Network, dhcp_route_metric)
DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCPServer.MaxLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_max_lease_time_usec)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 2ebcdfa744..206c270e50 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -131,7 +131,7 @@ static int network_load_one(Manager *manager, const char *filename) {
network->ipv6_accept_ra = -1;
network->ipv6_dad_transmits = -1;
network->ipv6_hop_limit = -1;
- network->duid_type = _DUID_TYPE_INVALID;
+ network->duid.type = _DUID_TYPE_INVALID;
network->proxy_arp = -1;
r = config_parse(NULL, filename, file,
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index 9b8096f9ae..ff2414efdd 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -68,6 +68,14 @@ typedef enum LLDPMode {
_LLDP_MODE_INVALID = -1,
} LLDPMode;
+typedef struct DUID {
+ /* Value of Type in [DHCP] section */
+ DUIDType type;
+
+ uint8_t raw_data_len;
+ uint8_t raw_data[MAX_DUID_LEN];
+} DUID;
+
typedef struct Manager Manager;
struct Network {
@@ -150,12 +158,7 @@ struct Network {
struct ether_addr *mac;
unsigned mtu;
uint32_t iaid;
- /* Value of Type in [DUID] section */
- DUIDType duid_type;
- /* DUID type code - RFC 3315 */
- uint16_t dhcp_duid_type;
- size_t dhcp_duid_len;
- uint8_t dhcp_duid[MAX_DUID_LEN];
+ DUID duid;
LLDPMode lldp_mode; /* LLDP reception */
bool lldp_emit; /* LLDP transmission */
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 39826a440d..26d9e7d6e0 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -74,14 +74,16 @@ struct Manager {
usec_t network_dirs_ts_usec;
- /* Value of Type in [DUID] section */
- DUIDType duid_type;
- /* DUID type code - RFC 3315 */
- uint16_t dhcp_duid_type;
- size_t dhcp_duid_len;
- uint8_t dhcp_duid[MAX_DUID_LEN];
+ DUID duid;
};
+static inline const DUID* link_duid(const Link *link) {
+ if (link->network->duid.type != _DUID_TYPE_INVALID)
+ return &link->network->duid;
+ else
+ return &link->manager->duid;
+}
+
extern const sd_bus_vtable manager_vtable[];
int manager_new(Manager **ret);