X Tutup
Skip to content

Commit 0fa2984

Browse files
committed
network: can: refuse too large restart sec earlier
1 parent 952508a commit 0fa2984

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/network/networkd-can.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) {
7474
else
7575
restart_ms = DIV_ROUND_UP(link->network->can_restart_us, USEC_PER_MSEC);
7676

77-
if (restart_ms > UINT32_MAX)
78-
return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.",
79-
FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
80-
8177
log_link_debug(link, "Setting restart = %s", FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
82-
8378
r = sd_netlink_message_append_u32(m, IFLA_CAN_RESTART_MS, restart_ms);
8479
if (r < 0)
8580
return log_link_debug_errno(link, r, "Could not append IFLA_CAN_RESTART_MS attribute: %m");
@@ -180,3 +175,41 @@ int config_parse_can_bitrate(
180175

181176
return 0;
182177
}
178+
179+
int config_parse_can_restart_usec(
180+
const char* unit,
181+
const char *filename,
182+
unsigned line,
183+
const char *section,
184+
unsigned section_line,
185+
const char *lvalue,
186+
int ltype,
187+
const char *rvalue,
188+
void *data,
189+
void *userdata) {
190+
191+
usec_t usec, *restart_usec = data;
192+
int r;
193+
194+
assert(filename);
195+
assert(lvalue);
196+
assert(rvalue);
197+
assert(data);
198+
199+
r = parse_sec(rvalue, &usec);
200+
if (r < 0) {
201+
log_syntax(unit, LOG_WARNING, filename, line, r,
202+
"Failed to parse CAN restart sec '%s', ignoring: %m", rvalue);
203+
return 0;
204+
}
205+
206+
if (usec != USEC_INFINITY &&
207+
DIV_ROUND_UP(usec, USEC_PER_MSEC) > UINT32_MAX) {
208+
log_syntax(unit, LOG_WARNING, filename, line, 0,
209+
"CAN RestartSec= must be in the range 0...%"PRIu32"ms, ignoring: %s", UINT32_MAX, rvalue);
210+
return 0;
211+
}
212+
213+
*restart_usec = usec;
214+
return 0;
215+
}

src/network/networkd-can.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ typedef struct Link Link;
1010
int can_set_netlink_message(Link *link, sd_netlink_message *m);
1111

1212
CONFIG_PARSER_PROTOTYPE(config_parse_can_bitrate);
13+
CONFIG_PARSER_PROTOTYPE(config_parse_can_restart_usec);

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ CAN.DataBitRate, config_parse_can_bitrate,
350350
CAN.DataSamplePoint, config_parse_permille, 0, offsetof(Network, can_data_sample_point)
351351
CAN.FDMode, config_parse_tristate, 0, offsetof(Network, can_fd_mode)
352352
CAN.FDNonISO, config_parse_tristate, 0, offsetof(Network, can_non_iso)
353-
CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us)
353+
CAN.RestartSec, config_parse_can_restart_usec, 0, offsetof(Network, can_restart_us)
354354
CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling)
355355
CAN.BusErrorReporting, config_parse_tristate, 0, offsetof(Network, can_berr_reporting)
356356
CAN.Termination, config_parse_tristate, 0, offsetof(Network, can_termination)

0 commit comments

Comments
 (0)
X Tutup