317 lines
15 KiB
Diff
317 lines
15 KiB
Diff
From 502991215726347b2b3b0dfcee29c66e4038c888 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 21 Jan 2020 20:06:40 +0900
|
|
Subject: [PATCH 1413/1760] network,udev: use uint64_t for bit rate
|
|
|
|
Fixes #14620.
|
|
|
|
This patch has been modified to fit current code. The related files of
|
|
this modification, reasons, and urls.
|
|
src/network/networkctl.c
|
|
systemd use table_set_width(table, 0) if --full is specified. systemd defined table_log_add_error().
|
|
https://github.com/systemd/systemd/pull/14538/commits/bd17fa8cd870bc403e698fafa5ac0bd6dc4af901
|
|
src/shared/ethtool-util.c
|
|
Rename *fd to *ethtool_fd when refactoring.
|
|
https://github.com/systemd/systemd/pull/14523/commits/64be35ab02c6f9c70355bd1ace9ffbc4c3fa901f
|
|
src/shared/ethtool-util.h
|
|
Rename *fd to *ethtool_fd when refactoring.
|
|
https://github.com/systemd/systemd/pull/14523/commits/64be35ab02c6f9c70355bd1ace9ffbc4c3fa901f
|
|
src/udev/net/link-config-gperf.gperf
|
|
udev introduce AlternativeNamesPolicy= setting. the table's width is was changed.
|
|
https://github.com/systemd/systemd/pull/14360/commits/ef1d2c07f9567dfea8a4e012d8779a4ded2d9ae6
|
|
src/udev/net/link-config.c
|
|
network, udev: support permanent mac address.
|
|
https://github.com/systemd/systemd/pull/14448/commits/4bb7cc828706348de3efce7368c14fc994cebb20
|
|
src/udev/net/link-config.h
|
|
network, udev: add altname support.
|
|
https://github.com/systemd/systemd/pull/14350/commits/a5053a158b43c5ddee90f4915b9fc603e0191d6d
|
|
Reference: https://github.com/systemd/systemd/commit/502991215726347b2b3b0dfcee29c66e4038c888
|
|
Conflict: NA
|
|
---
|
|
src/core/load-fragment.c | 2 +-
|
|
src/network/networkctl.c | 4 +--
|
|
src/network/networkd-can.c | 2 +-
|
|
src/network/networkd-network-gperf.gperf | 2 +-
|
|
src/network/networkd-network.h | 2 +-
|
|
src/shared/conf-parser.c | 10 +++-----
|
|
src/shared/conf-parser.h | 2 +-
|
|
src/shared/ethtool-util.c | 4 +--
|
|
src/shared/ethtool-util.h | 4 +--
|
|
src/test/test-conf-parser.c | 32 ++++++++++++------------
|
|
src/udev/net/link-config-gperf.gperf | 2 +-
|
|
src/udev/net/link-config.c | 3 ---
|
|
src/udev/net/link-config.h | 2 +-
|
|
13 files changed, 32 insertions(+), 39 deletions(-)
|
|
|
|
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
|
index 6c24ed3..617613b 100644
|
|
--- a/src/core/load-fragment.c
|
|
+++ b/src/core/load-fragment.c
|
|
@@ -4895,7 +4895,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 3100a2e..93227b4 100644
|
|
--- a/src/network/networkctl.c
|
|
+++ b/src/network/networkctl.c
|
|
@@ -155,7 +155,7 @@ typedef struct LinkInfo {
|
|
|
|
/* ethtool info */
|
|
int autonegotiation;
|
|
- size_t speed;
|
|
+ uint64_t speed;
|
|
Duplex duplex;
|
|
NetDevPort port;
|
|
|
|
@@ -1275,7 +1275,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 r;
|
|
}
|
|
diff --git a/src/network/networkd-can.c b/src/network/networkd-can.c
|
|
index 5755df5..c3ad430 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 43163a3..e54c9b8 100644
|
|
--- a/src/network/networkd-network-gperf.gperf
|
|
+++ b/src/network/networkd-network-gperf.gperf
|
|
@@ -225,7 +225,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 486b8c3..84f691e 100644
|
|
--- a/src/network/networkd-network.h
|
|
+++ b/src/network/networkd-network.h
|
|
@@ -166,7 +166,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 4079208..7b8a286 100644
|
|
--- a/src/shared/conf-parser.c
|
|
+++ b/src/shared/conf-parser.c
|
|
@@ -545,7 +545,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,
|
|
@@ -557,8 +557,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);
|
|
@@ -566,15 +565,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 04c68b1..1a83e22 100644
|
|
--- a/src/shared/conf-parser.h
|
|
+++ b/src/shared/conf-parser.h
|
|
@@ -119,7 +119,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 b0961df..38d68b0 100644
|
|
--- a/src/shared/ethtool-util.c
|
|
+++ b/src/shared/ethtool-util.c
|
|
@@ -176,7 +176,7 @@ int ethtool_get_driver(int *fd, const char *ifname, char **ret) {
|
|
}
|
|
|
|
int ethtool_get_link_info(int *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,
|
|
@@ -645,7 +645,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 8b32b24..4ea08d1 100644
|
|
--- a/src/shared/ethtool-util.h
|
|
+++ b/src/shared/ethtool-util.h
|
|
@@ -81,14 +81,14 @@ typedef struct netdev_channels {
|
|
|
|
int ethtool_get_driver(int *fd, const char *ifname, char **ret);
|
|
int ethtool_get_link_info(int *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_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex);
|
|
int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
|
|
int ethtool_set_features(int *fd, const char *ifname, int *features);
|
|
int ethtool_set_glinksettings(int *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 *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 597265e..ecb4ef2 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);
|
|
-
|
|
- 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) {
|
|
@@ -379,7 +379,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 a3d7dec..eb2d565 100644
|
|
--- a/src/udev/net/link-config-gperf.gperf
|
|
+++ b/src/udev/net/link-config-gperf.gperf
|
|
@@ -37,7 +37,7 @@ Link.NamePolicy, config_parse_name_policy, 0,
|
|
Link.Name, config_parse_ifname, 0, offsetof(link_config, name)
|
|
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 d44af64..6a414db 100644
|
|
--- a/src/udev/net/link-config.c
|
|
+++ b/src/udev/net/link-config.c
|
|
@@ -157,9 +157,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) && 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 cd99cd5..26666ad 100644
|
|
--- a/src/udev/net/link-config.h
|
|
+++ b/src/udev/net/link-config.h
|
|
@@ -50,7 +50,7 @@ struct link_config {
|
|
char *name;
|
|
char *alias;
|
|
uint32_t mtu;
|
|
- size_t speed;
|
|
+ uint64_t speed;
|
|
Duplex duplex;
|
|
int autonegotiation;
|
|
uint32_t advertise[N_ADVERTISE];
|
|
--
|
|
2.23.0
|
|
|