]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network,udev: use uint64_t for bit rate
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 21 Jan 2020 11:06:40 +0000 (20:06 +0900)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Jan 2020 15:51:19 +0000 (16:51 +0100)
Fixes #14620.

13 files changed:
src/core/load-fragment.c
src/network/networkctl.c
src/network/networkd-can.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.h
src/shared/conf-parser.c
src/shared/conf-parser.h
src/shared/ethtool-util.c
src/shared/ethtool-util.h
src/test/test-conf-parser.c
src/udev/net/link-config-gperf.gperf
src/udev/net/link-config.c
src/udev/net/link-config.h

index 0de9adb6e56af8cf8ebbdb7179efa819ca718ed4..379be9c96b65d2435436ff468a944e33c9c9a7d3 100644 (file)
@@ -4771,7 +4771,7 @@ void unit_dump_config_items(FILE *f) {
                 { config_parse_unsigned,              "UNSIGNED" },
                 { config_parse_iec_size,              "SIZE" },
                 { config_parse_iec_uint64,            "SIZE" },
-                { config_parse_si_size,               "SIZE" },
+                { config_parse_si_uint64,             "SIZE" },
                 { config_parse_bool,                  "BOOLEAN" },
                 { config_parse_string,                "STRING" },
                 { config_parse_path,                  "PATH" },
index 629bce29b9c616072b334c10d31d76e762a5569d..a470488664b6bb4316647a2f05e4c2d96cc67b61 100644 (file)
@@ -170,7 +170,7 @@ typedef struct LinkInfo {
 
         /* ethtool info */
         int autonegotiation;
-        size_t speed;
+        uint64_t speed;
         Duplex duplex;
         NetDevPort port;
 
@@ -1495,7 +1495,7 @@ static int link_status_one(
                         r = table_add_many(table,
                                            TABLE_EMPTY,
                                            TABLE_STRING, "Speed:",
-                                           TABLE_BPS, (uint64_t) info->speed);
+                                           TABLE_BPS, info->speed);
                         if (r < 0)
                                 return table_log_add_error(r);
                 }
index bdd88659c5415f4c481ed457babdafb0e641d0e2..5087dbbc2ea1a7fb348c7fa5fbf921f5a1440f22 100644 (file)
@@ -101,7 +101,7 @@ static int link_set_can(Link *link) {
                 };
 
                 if (link->network->can_bitrate > UINT32_MAX) {
-                        log_link_error(link, "bitrate (%zu) too big.", link->network->can_bitrate);
+                        log_link_error(link, "bitrate (%" PRIu64 ") too big.", link->network->can_bitrate);
                         return -ERANGE;
                 }
 
index 67b3789ee6c1e0de88fac93d6d2cbe6521a496be..2a7c223129c07100b904423cef841b48b0c5b4f4 100644 (file)
@@ -245,7 +245,7 @@ IPv6Prefix.ValidLifetimeSec,            config_parse_prefix_lifetime,
 IPv6Prefix.PreferredLifetimeSec,        config_parse_prefix_lifetime,                    0,                             0
 IPv6RoutePrefix.Route,                  config_parse_route_prefix,                       0,                             0
 IPv6RoutePrefix.LifetimeSec,            config_parse_route_prefix_lifetime,              0,                             0
-CAN.BitRate,                            config_parse_si_size,                            0,                             offsetof(Network, can_bitrate)
+CAN.BitRate,                            config_parse_si_uint64,                          0,                             offsetof(Network, can_bitrate)
 CAN.SamplePoint,                        config_parse_permille,                           0,                             offsetof(Network, can_sample_point)
 CAN.RestartSec,                         config_parse_sec,                                0,                             offsetof(Network, can_restart_us)
 CAN.TripleSampling,                     config_parse_tristate,                           0,                             offsetof(Network, can_triple_sampling)
index e1c1c17241df4ad937e5bff8be921af79ef6c0e2..1cfbd0b6b6dfaa2b8872f145149cd95a296f4733 100644 (file)
@@ -194,7 +194,7 @@ struct Network {
         uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
 
         /* CAN support */
-        size_t can_bitrate;
+        uint64_t can_bitrate;
         unsigned can_sample_point;
         usec_t can_restart_us;
         int can_triple_sampling;
index cb20279dda602ad45276dc223fdc1761b0d622c9..463db1cb4da09485b62f3cea570aba7e201630ad 100644 (file)
@@ -555,7 +555,7 @@ int config_parse_iec_size(const char* unit,
         return 0;
 }
 
-int config_parse_si_size(
+int config_parse_si_uint64(
                 const char* unit,
                 const char *filename,
                 unsigned line,
@@ -567,8 +567,7 @@ int config_parse_si_size(
                 void *data,
                 void *userdata) {
 
-        size_t *sz = data;
-        uint64_t v;
+        uint64_t *sz = data;
         int r;
 
         assert(filename);
@@ -576,15 +575,12 @@ int config_parse_si_size(
         assert(rvalue);
         assert(data);
 
-        r = parse_size(rvalue, 1000, &v);
-        if (r >= 0 && (uint64_t) (size_t) v != v)
-                r = -ERANGE;
+        r = parse_size(rvalue, 1000, sz);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue);
                 return 0;
         }
 
-        *sz = (size_t) v;
         return 0;
 }
 
index 287620ad71431a7854e3fa81c5c61f974bb981b6..136ee32426b16a84c68ce2205d023addfa88c6dc 100644 (file)
@@ -118,7 +118,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_uint32);
 CONFIG_PARSER_PROTOTYPE(config_parse_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_double);
 CONFIG_PARSER_PROTOTYPE(config_parse_iec_size);
-CONFIG_PARSER_PROTOTYPE(config_parse_si_size);
+CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_bool);
 CONFIG_PARSER_PROTOTYPE(config_parse_tristate);
index a9059a3ab7a0bd60245f7b06679ed40762defd10..d9c1231fa8f670700424e8f6eeeb0c0fce18c530 100644 (file)
@@ -177,7 +177,7 @@ int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret) {
 }
 
 int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
-                          int *ret_autonegotiation, size_t *ret_speed,
+                          int *ret_autonegotiation, uint64_t *ret_speed,
                           Duplex *ret_duplex, NetDevPort *ret_port) {
         struct ethtool_cmd ecmd = {
                 .cmd = ETHTOOL_GSET,
@@ -734,7 +734,7 @@ int ethtool_set_glinksettings(
                 const char *ifname,
                 int autonegotiation,
                 uint32_t advertise[static N_ADVERTISE],
-                size_t speed,
+                uint64_t speed,
                 Duplex duplex,
                 NetDevPort port) {
         _cleanup_free_ struct ethtool_link_usettings *u = NULL;
index 8468a26bc2601937f3006ba6671408db9b221ff3..8d762876406bb4c6f948eda62fd6966949bc48bd 100644 (file)
@@ -90,7 +90,7 @@ typedef struct netdev_ring_param {
 
 int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
 int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
-                          int *ret_autonegotiation, size_t *ret_speed,
+                          int *ret_autonegotiation, uint64_t *ret_speed,
                           Duplex *ret_duplex, NetDevPort *ret_port);
 int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
 int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex);
@@ -99,7 +99,7 @@ int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, netdev_ring
 int ethtool_set_features(int *ethtool_fd, const char *ifname, int *features);
 int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
                               int autonegotiation, uint32_t advertise[static N_ADVERTISE],
-                              size_t speed, Duplex duplex, NetDevPort port);
+                              uint64_t speed, Duplex duplex, NetDevPort port);
 int ethtool_set_channels(int *ethtool_fd, const char *ifname, netdev_channels *channels);
 
 const char *duplex_to_string(Duplex d) _const_;
index 18b083d87fcb9d0abccd5d8996c580aa304ac122..510b1de72d104aea2e38af2c6d5117b3098f3208 100644 (file)
@@ -38,11 +38,11 @@ static void test_config_parse_iec_size_one(const char *rvalue, size_t expected)
         assert_se(expected == iec_size);
 }
 
-static void test_config_parse_si_size_one(const char *rvalue, size_t expected) {
-        size_t si_size = 0;
+static void test_config_parse_si_uint64_one(const char *rvalue, uint64_t expected) {
+        uint64_t si_uint64 = 0;
 
-        assert_se(config_parse_si_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_size, NULL) >= 0);
-        assert_se(expected == si_size);
+        assert_se(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL) >= 0);
+        assert_se(expected == si_uint64);
 }
 
 static void test_config_parse_int_one(const char *rvalue, int expected) {
@@ -125,17 +125,17 @@ static void test_config_parse_iec_size(void) {
         test_config_parse_iec_size_one("garbage", 0);
 }
 
-static void test_config_parse_si_size(void) {
-        test_config_parse_si_size_one("1024", 1024);
-        test_config_parse_si_size_one("2K", 2000);
-        test_config_parse_si_size_one("10M", 10 * 1000 * 1000);
-        test_config_parse_si_size_one("1G", 1 * 1000 * 1000 * 1000);
-        test_config_parse_si_size_one("0G", 0);
-        test_config_parse_si_size_one("0", 0);
-
-        test_config_parse_si_size_one("-982", 0);
-        test_config_parse_si_size_one("49874444198739873000000G", 0);
-        test_config_parse_si_size_one("garbage", 0);
+static void test_config_parse_si_uint64(void) {
+        test_config_parse_si_uint64_one("1024", 1024);
+        test_config_parse_si_uint64_one("2K", 2000);
+        test_config_parse_si_uint64_one("10M", 10 * 1000 * 1000);
+        test_config_parse_si_uint64_one("1G", 1 * 1000 * 1000 * 1000);
+        test_config_parse_si_uint64_one("0G", 0);
+        test_config_parse_si_uint64_one("0", 0);
+
+        test_config_parse_si_uint64_one("-982", 0);
+        test_config_parse_si_uint64_one("49874444198739873000000G", 0);
+        test_config_parse_si_uint64_one("garbage", 0);
 }
 
 static void test_config_parse_int(void) {
@@ -391,7 +391,7 @@ int main(int argc, char **argv) {
         test_config_parse_log_level();
         test_config_parse_log_facility();
         test_config_parse_iec_size();
-        test_config_parse_si_size();
+        test_config_parse_si_uint64();
         test_config_parse_int();
         test_config_parse_unsigned();
         test_config_parse_strv();
index 686ff1bc5ca9b71e876d8f57868bd5f34c2c9b76..1e794efdcba97a3b33884fd9951943ac106987c1 100644 (file)
@@ -40,7 +40,7 @@ Link.AlternativeName,            config_parse_ifnames,                  1,
 Link.AlternativeNamesPolicy,     config_parse_alternative_names_policy, 0,                             offsetof(link_config, alternative_names_policy)
 Link.Alias,                      config_parse_ifalias,                  0,                             offsetof(link_config, alias)
 Link.MTUBytes,                   config_parse_mtu,                      AF_UNSPEC,                     offsetof(link_config, mtu)
-Link.BitsPerSecond,              config_parse_si_size,                  0,                             offsetof(link_config, speed)
+Link.BitsPerSecond,              config_parse_si_uint64,                0,                             offsetof(link_config, speed)
 Link.Duplex,                     config_parse_duplex,                   0,                             offsetof(link_config, duplex)
 Link.AutoNegotiation,            config_parse_tristate,                 0,                             offsetof(link_config, autonegotiation)
 Link.WakeOnLan,                  config_parse_wol,                      0,                             offsetof(link_config, wol)
index 4a44edfc014dc83bf66e7f9f02f8b419178556fc..e1a25a54a6870f442fc251ecf0b15338b1852380 100644 (file)
@@ -160,9 +160,6 @@ int link_load_one(link_config_ctx *ctx, const char *filename) {
         if (r < 0)
                 return r;
 
-        if (link->speed > UINT_MAX)
-                return -ERANGE;
-
         if (set_isempty(link->match_mac) && set_isempty(link->match_permanent_mac) &&
             strv_isempty(link->match_path) && strv_isempty(link->match_driver) && strv_isempty(link->match_type) &&
             strv_isempty(link->match_name) && strv_isempty(link->match_property) && !link->conditions)
index 496a8bccb78c38a5928cae7e640d60f6f3ee2e57..a85bd4b46b021bca937c713e2e1497fefbd5dbfc 100644 (file)
@@ -53,7 +53,7 @@ struct link_config {
         char **alternative_names;
         char *alias;
         uint32_t mtu;
-        size_t speed;
+        uint64_t speed;
         Duplex duplex;
         int autonegotiation;
         uint32_t advertise[N_ADVERTISE];