summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorVinay Kulkarni <vskibum@gmail.com>2016-03-09 21:58:44 -0800
committerVinay Kulkarni <vskibum@gmail.com>2016-03-09 21:58:44 -0800
commitc83321e6d40b294e73e2881e4a98172c4244323b (patch)
tree631e97f505c07f8ece1141e2cac66dbc1fe52cd3 /src/network
parentbd7e03af007c4e857ed0370eba9e903d6b561937 (diff)
DHCP DUID and IAID configurability
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-conf.c133
-rw-r--r--src/network/networkd-conf.h32
-rw-r--r--src/network/networkd-dhcp4.c8
-rw-r--r--src/network/networkd-dhcp6.c10
-rw-r--r--src/network/networkd-gperf.gperf18
-rw-r--r--src/network/networkd-link.c18
-rw-r--r--src/network/networkd-manager.c2
-rw-r--r--src/network/networkd-network-gperf.gperf1
-rw-r--r--src/network/networkd-network.h2
-rw-r--r--src/network/networkd.c5
-rw-r--r--src/network/networkd.h5
11 files changed, 233 insertions, 1 deletions
diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c
new file mode 100644
index 0000000000..4bc92b8171
--- /dev/null
+++ b/src/network/networkd-conf.c
@@ -0,0 +1,133 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Tom Gundersen <teg@jklm.no>
+
+ 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
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+ ***/
+
+#include <ctype.h>
+
+#include "conf-parser.h"
+#include "def.h"
+#include "dhcp-identifier.h"
+#include "networkd-conf.h"
+#include "string-table.h"
+
+int manager_parse_config_file(Manager *m) {
+ assert(m);
+
+ return config_parse_many(PKGSYSCONFDIR "/networkd.conf",
+ CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
+ "DUID\0",
+ config_item_perf_lookup, networkd_gperf_lookup,
+ 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"
+};
+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");
+
+int config_parse_dhcp_duid_raw(
+ 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 r;
+ long byte;
+ char *cbyte, *pnext;
+ const char *pduid = (const char *)rvalue;
+ size_t count = 0, duid_len = 0;
+ Manager *m = userdata;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(m);
+ assert(m->dhcp_duid_type != _DHCP_DUID_TYPE_INVALID);
+
+ switch (m->dhcp_duid_type) {
+ case DHCP_DUID_TYPE_LLT:
+ /* RawData contains DUID-LLT link-layer address (offset 6) */
+ duid_len = 6;
+ break;
+ case DHCP_DUID_TYPE_EN:
+ /* RawData contains DUID-EN identifier (offset 4) */
+ duid_len = 4;
+ break;
+ case DHCP_DUID_TYPE_LL:
+ /* RawData contains DUID-LL link-layer address (offset 2) */
+ duid_len = 2;
+ break;
+ case DHCP_DUID_TYPE_UUID:
+ /* RawData specifies UUID (offset 0) - fall thru */
+ case DHCP_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);
+
+ /* RawData contains DUID in format " NN:NN:NN... " */
+ while (true) {
+ r = extract_first_word(&pduid, &cbyte, ":", 0);
+ if (r < 0) {
+ log_error("Failed to read DUID.");
+ return -EINVAL;
+ }
+ if (r == 0)
+ break;
+ if (duid_len >= MAX_DUID_LEN) {
+ log_error("DUID length exceeds maximum length.");
+ return -EINVAL;
+ }
+
+ 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;
+ }
+
+ /* 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));
+ count++;
+ continue;
+ }
+
+ m->dhcp_duid.raw.data[duid_len++] = byte;
+ }
+
+ m->dhcp_duid_len = sizeof(m->dhcp_duid.type) + duid_len;
+
+ return 0;
+}
diff --git a/src/network/networkd-conf.h b/src/network/networkd-conf.h
new file mode 100644
index 0000000000..6d9ce010e3
--- /dev/null
+++ b/src/network/networkd-conf.h
@@ -0,0 +1,32 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Tom Gundersen <teg@jklm.no>
+
+ 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
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "networkd.h"
+
+
+int manager_parse_config_file(Manager *m);
+
+const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, unsigned length);
+
+int config_parse_dhcp_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_dhcp_duid_raw(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 68998eabf2..3bbb21295c 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -625,7 +625,13 @@ int dhcp4_configure(Link *link) {
switch (link->network->dhcp_client_identifier) {
case DHCP_CLIENT_ID_DUID:
- /* Library defaults to this. */
+ /* If configured, apply user specified DUID and/or IAID */
+ r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
+ link->network->iaid_value,
+ link->manager->dhcp_duid_len,
+ &link->manager->dhcp_duid);
+ if (r < 0)
+ return r;
break;
case DHCP_CLIENT_ID_MAC:
r = sd_dhcp_client_set_client_id(link->dhcp_client,
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index 5f7a005c36..9f59cb3f8a 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -230,6 +230,16 @@ int dhcp6_configure(Link *link) {
if (r < 0)
goto error;
+ r = sd_dhcp6_client_set_iaid(client, link->network->iaid_value);
+ if (r < 0)
+ goto error;
+
+ r = sd_dhcp6_client_set_duid(client,
+ link->manager->dhcp_duid_len,
+ &link->manager->dhcp_duid);
+ if (r < 0)
+ goto error;
+
r = sd_dhcp6_client_set_index(client, link->ifindex);
if (r < 0)
goto error;
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
new file mode 100644
index 0000000000..3ef4155476
--- /dev/null
+++ b/src/network/networkd-gperf.gperf
@@ -0,0 +1,18 @@
+%{
+#include <stddef.h>
+#include "conf-parser.h"
+#include "networkd-conf.h"
+%}
+struct ConfigPerfItem;
+%null_strings
+%language=ANSI-C
+%define slot-name section_and_lvalue
+%define hash-function-name networkd_gperf_hash
+%define lookup-function-name networkd_gperf_lookup
+%readonly-tables
+%omit-struct-type
+%struct-type
+%includes
+%%
+DUID.Type, config_parse_dhcp_duid_type, 0, offsetof(Manager, dhcp_duid_type)
+DUID.RawData, config_parse_dhcp_duid_raw, 0, offsetof(Manager, dhcp_duid)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ff4bd76554..67b04560cd 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2781,6 +2781,13 @@ int link_update(Link *link, sd_netlink_message *m) {
ARPHRD_ETHER);
if (r < 0)
return log_link_warning_errno(link, r, "Could not update MAC address in DHCP client: %m");
+
+ r = sd_dhcp_client_set_iaid_duid(link->dhcp_client,
+ link->network->iaid_value,
+ link->manager->dhcp_duid_len,
+ &link->manager->dhcp_duid);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not update DUID/IAID in DHCP client: %m");
}
if (link->dhcp6_client) {
@@ -2790,6 +2797,17 @@ int link_update(Link *link, sd_netlink_message *m) {
ARPHRD_ETHER);
if (r < 0)
return log_link_warning_errno(link, r, "Could not update MAC address in DHCPv6 client: %m");
+
+ r = sd_dhcp6_client_set_iaid(link->dhcp6_client,
+ link->network->iaid_value);
+ if (r < 0)
+ return log_link_warning_errno(link, r, "Could not update DHCPv6 IAID: %m");
+
+ r = sd_dhcp6_client_set_duid(link->dhcp6_client,
+ link->manager->dhcp_duid_len,
+ &link->manager->dhcp_duid);
+ 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 b8cb7f875d..8d443f7b0f 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -1037,6 +1037,8 @@ int manager_new(Manager **ret) {
if (r < 0)
return r;
+ m->dhcp_duid_type = _DHCP_DUID_TYPE_INVALID;
+
*ret = m;
m = NULL;
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index a5d1714293..7a9a136d5b 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -26,6 +26,7 @@ Match.KernelCommandLine, config_parse_net_condition,
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.IAIDValue, config_parse_iaid_value, 0, offsetof(Network, iaid_value)
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)
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index 4a13e2b574..c5530cdfba 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -30,6 +30,7 @@ typedef struct Network Network;
#include "networkd-route.h"
#include "networkd-util.h"
#include "networkd.h"
+#include "sparse-endian.h"
#define DHCP_ROUTE_METRIC 1024
#define IPV4LL_ROUTE_METRIC 2048
@@ -144,6 +145,7 @@ struct Network {
struct ether_addr *mac;
unsigned mtu;
+ be32_t iaid_value;
LLDPMode lldp_mode; /* LLDP reception */
bool lldp_emit; /* LLDP transmission */
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 3a2615e6fd..c8f81a2ca6 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -21,6 +21,7 @@
#include "capability-util.h"
#include "networkd.h"
+#include "networkd-conf.h"
#include "signal-util.h"
#include "user-util.h"
@@ -89,6 +90,10 @@ int main(int argc, char *argv[]) {
goto out;
}
+ r = manager_parse_config_file(m);
+ if (r < 0)
+ log_warning_errno(r, "Failed to parse configuration file: %m");
+
r = manager_load_config(m);
if (r < 0) {
log_error_errno(r, "Could not load configuration files: %m");
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 6bdd8302a0..d815f30610 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -35,6 +35,7 @@ typedef struct Manager Manager;
#include "networkd-link.h"
#include "networkd-network.h"
#include "networkd-util.h"
+#include "dhcp-identifier.h"
struct Manager {
sd_netlink *rtnl;
@@ -61,6 +62,10 @@ struct Manager {
LIST_HEAD(AddressPool, address_pools);
usec_t network_dirs_ts_usec;
+
+ DHCPDUIDType dhcp_duid_type;
+ size_t dhcp_duid_len;
+ struct duid dhcp_duid;
};
extern const char* const network_dirs[];