diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 0de9adb6e56..379be9c96b6 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -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" }, diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 629bce29b9c..a470488664b 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -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); } diff --git a/src/network/networkd-can.c b/src/network/networkd-can.c index bdd88659c54..5087dbbc2ea 100644 --- a/src/network/networkd-can.c +++ b/src/network/networkd-can.c @@ -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; } diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 67b3789ee6c..2a7c223129c 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -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) diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index e1c1c17241d..1cfbd0b6b6d 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -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; diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index cb20279dda6..463db1cb4da 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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; } diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 287620ad714..136ee32426b 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -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); diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index a9059a3ab7a..d9c1231fa8f 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -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; diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h index 8468a26bc26..8d762876406 100644 --- a/src/shared/ethtool-util.h +++ b/src/shared/ethtool-util.h @@ -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_; diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index 18b083d87fc..510b1de72d1 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -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); +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_size_one("-982", 0); - test_config_parse_si_size_one("49874444198739873000000G", 0); - test_config_parse_si_size_one("garbage", 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(); diff --git a/src/udev/net/link-config-gperf.gperf b/src/udev/net/link-config-gperf.gperf index 686ff1bc5ca..1e794efdcba 100644 --- a/src/udev/net/link-config-gperf.gperf +++ b/src/udev/net/link-config-gperf.gperf @@ -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) diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 4a44edfc014..e1a25a54a68 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -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) diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h index 496a8bccb78..a85bd4b46b0 100644 --- a/src/udev/net/link-config.h +++ b/src/udev/net/link-config.h @@ -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];