1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-06 00:58:29 +03:00

network: can: refuse too large restart sec earlier

This commit is contained in:
Yu Watanabe 2021-08-16 00:45:23 +09:00
parent 952508abda
commit 0fa2984dad
3 changed files with 40 additions and 6 deletions

@ -74,12 +74,7 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) {
else
restart_ms = DIV_ROUND_UP(link->network->can_restart_us, USEC_PER_MSEC);
if (restart_ms > UINT32_MAX)
return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.",
FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
log_link_debug(link, "Setting restart = %s", FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC));
r = sd_netlink_message_append_u32(m, IFLA_CAN_RESTART_MS, restart_ms);
if (r < 0)
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(
return 0;
}
int config_parse_can_restart_usec(
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) {
usec_t usec, *restart_usec = data;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = parse_sec(rvalue, &usec);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse CAN restart sec '%s', ignoring: %m", rvalue);
return 0;
}
if (usec != USEC_INFINITY &&
DIV_ROUND_UP(usec, USEC_PER_MSEC) > UINT32_MAX) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"CAN RestartSec= must be in the range 0...%"PRIu32"ms, ignoring: %s", UINT32_MAX, rvalue);
return 0;
}
*restart_usec = usec;
return 0;
}

@ -10,3 +10,4 @@ typedef struct Link Link;
int can_set_netlink_message(Link *link, sd_netlink_message *m);
CONFIG_PARSER_PROTOTYPE(config_parse_can_bitrate);
CONFIG_PARSER_PROTOTYPE(config_parse_can_restart_usec);

@ -350,7 +350,7 @@ CAN.DataBitRate, config_parse_can_bitrate,
CAN.DataSamplePoint, config_parse_permille, 0, offsetof(Network, can_data_sample_point)
CAN.FDMode, config_parse_tristate, 0, offsetof(Network, can_fd_mode)
CAN.FDNonISO, config_parse_tristate, 0, offsetof(Network, can_non_iso)
CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us)
CAN.RestartSec, config_parse_can_restart_usec, 0, offsetof(Network, can_restart_us)
CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling)
CAN.BusErrorReporting, config_parse_tristate, 0, offsetof(Network, can_berr_reporting)
CAN.Termination, config_parse_tristate, 0, offsetof(Network, can_termination)