]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: can: refuse too large restart sec earlier
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 15 Aug 2021 15:45:23 +0000 (00:45 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 16 Aug 2021 09:42:45 +0000 (18:42 +0900)
src/network/networkd-can.c
src/network/networkd-can.h
src/network/networkd-network-gperf.gperf

index 4ff56a168b0e2b578bc855649779cad06f516787..a8347acaab662278afb383904a8ffb606575a2cc 100644 (file)
@@ -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;
+}
index 781494ed3c9a925db147e90e89a6c5a81578d490..89e65aabca13887fb8becc621e2c0c2ce44ec399 100644 (file)
@@ -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);
index 9166376aaa872a6045c586f778b7429c96d33809..e11807f181999f06f5aebee15432d5f0c70519bf 100644 (file)
@@ -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)