]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-conf.c
network: ignore requested ipv6 fdb entry when ipv6 is disabled by sysctl
[thirdparty/systemd.git] / src / network / networkd-conf.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
413708d1 2/***
96b2fb93 3 Copyright © 2014 Vinay Kulkarni <kulkarniv@vmware.com>
413708d1
VK
4 ***/
5
6#include <ctype.h>
7
8#include "conf-parser.h"
9#include "def.h"
10#include "dhcp-identifier.h"
23f53b99 11#include "extract-word.h"
b7f71444 12#include "hexdecoct.h"
413708d1 13#include "networkd-conf.h"
a879e1a4 14#include "networkd-manager.h"
23f53b99 15#include "networkd-network.h"
a879e1a4 16#include "networkd-speed-meter.h"
413708d1
VK
17#include "string-table.h"
18
19int manager_parse_config_file(Manager *m) {
a879e1a4
YW
20 int r;
21
413708d1
VK
22 assert(m);
23
a879e1a4
YW
24 r = config_parse_many_nulstr(PKGSYSCONFDIR "/networkd.conf",
25 CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
26 "Network\0DHCP\0",
27 config_item_perf_lookup, networkd_gperf_lookup,
28 CONFIG_PARSE_WARN, m);
29 if (r < 0)
30 return r;
31
32 if (m->use_speed_meter && m->speed_meter_interval_usec < SPEED_METER_MINIMUM_TIME_INTERVAL) {
33 char buf[FORMAT_TIMESPAN_MAX];
34
35 log_warning("SpeedMeterIntervalSec= is too small, using %s.",
36 format_timespan(buf, sizeof buf, SPEED_METER_MINIMUM_TIME_INTERVAL, USEC_PER_SEC));
37 m->speed_meter_interval_usec = SPEED_METER_MINIMUM_TIME_INTERVAL;
38 }
39
40 return 0;
413708d1
VK
41}
42
43static const char* const duid_type_table[_DUID_TYPE_MAX] = {
413708d1
VK
44 [DUID_TYPE_LLT] = "link-layer-time",
45 [DUID_TYPE_EN] = "vendor",
46 [DUID_TYPE_LL] = "link-layer",
8341a5c3 47 [DUID_TYPE_UUID] = "uuid",
413708d1
VK
48};
49DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
0cf7c3fd
YW
50
51int config_parse_duid_type(
52 const char *unit,
53 const char *filename,
54 unsigned line,
55 const char *section,
56 unsigned section_line,
57 const char *lvalue,
58 int ltype,
59 const char *rvalue,
60 void *data,
61 void *userdata) {
62
63 _cleanup_free_ char *type_string = NULL;
64 const char *p = rvalue;
65 DUID *duid = data;
66 DUIDType type;
67 int r;
68
69 assert(filename);
70 assert(lvalue);
71 assert(rvalue);
72 assert(duid);
73
74 r = extract_first_word(&p, &type_string, ":", 0);
75 if (r == -ENOMEM)
76 return log_oom();
77 if (r < 0) {
78 log_syntax(unit, LOG_WARNING, filename, line, r,
79 "Invalid syntax, ignoring: %s", rvalue);
80 return 0;
81 }
82 if (r == 0) {
83 log_syntax(unit, LOG_WARNING, filename, line, 0,
84 "Failed to extract DUID type from '%s', ignoring.", rvalue);
85 return 0;
86 }
87
88 type = duid_type_from_string(type_string);
89 if (type < 0) {
90 log_syntax(unit, LOG_WARNING, filename, line, 0,
91 "Failed to parse DUID type '%s', ignoring.", type_string);
92 return 0;
93 }
94
95 if (!isempty(p)) {
96 usec_t u;
97
98 if (type != DUID_TYPE_LLT) {
99 log_syntax(unit, LOG_WARNING, filename, line, r,
100 "Invalid syntax, ignoring: %s", rvalue);
101 return 0;
102 }
103
104 r = parse_timestamp(p, &u);
105 if (r < 0) {
106 log_syntax(unit, LOG_WARNING, filename, line, r,
107 "Failed to parse timestamp, ignoring: %s", p);
108 return 0;
109 }
110
111 duid->llt_time = u;
112 }
113
114 duid->type = type;
115
116 return 0;
117}
413708d1
VK
118
119int config_parse_duid_rawdata(
120 const char *unit,
121 const char *filename,
122 unsigned line,
123 const char *section,
124 unsigned section_line,
125 const char *lvalue,
126 int ltype,
127 const char *rvalue,
128 void *data,
129 void *userdata) {
076ea6f6 130
8341a5c3
ZJS
131 DUID *ret = data;
132 uint8_t raw_data[MAX_DUID_LEN];
133 unsigned count = 0;
413708d1
VK
134
135 assert(filename);
136 assert(lvalue);
137 assert(rvalue);
8341a5c3 138 assert(ret);
413708d1 139
8341a5c3 140 /* RawData contains DUID in format "NN:NN:NN..." */
b7f71444 141 for (;;) {
8341a5c3 142 int n1, n2, len, r;
076ea6f6 143 uint32_t byte;
82edec54 144 _cleanup_free_ char *cbyte = NULL;
076ea6f6 145
8341a5c3 146 r = extract_first_word(&rvalue, &cbyte, ":", 0);
413708d1 147 if (r < 0) {
076ea6f6
LP
148 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
149 return 0;
413708d1
VK
150 }
151 if (r == 0)
152 break;
8341a5c3 153 if (count >= MAX_DUID_LEN) {
076ea6f6
LP
154 log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
155 return 0;
413708d1
VK
156 }
157
b7f71444 158 len = strlen(cbyte);
4c701096 159 if (!IN_SET(len, 1, 2)) {
076ea6f6
LP
160 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
161 return 0;
413708d1 162 }
b7f71444
VK
163 n1 = unhexchar(cbyte[0]);
164 if (len == 2)
165 n2 = unhexchar(cbyte[1]);
076ea6f6
LP
166 else
167 n2 = 0;
168
169 if (n1 < 0 || n2 < 0) {
170 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
171 return 0;
b7f71444 172 }
076ea6f6
LP
173
174 byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
8341a5c3 175 raw_data[count++] = byte;
b7f71444 176 }
413708d1 177
8341a5c3
ZJS
178 assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
179 memcpy(ret->raw_data, raw_data, count);
180 ret->raw_data_len = count;
413708d1
VK
181 return 0;
182}