mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
network: do not append table number in TableString field in json output
The json output already contains table number, hence, it is not necessary to include number in the string.
This commit is contained in:
@@ -274,7 +274,7 @@ static int route_build_json(Route *route, JsonVariant **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = manager_get_route_table_to_string(manager, route->table, &table);
|
||||
r = manager_get_route_table_to_string(manager, route->table, /* append_num = */ false, &table);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -357,7 +357,7 @@ static int routing_policy_rule_build_json(RoutingPolicyRule *rule, JsonVariant *
|
||||
assert(rule->manager);
|
||||
assert(ret);
|
||||
|
||||
r = manager_get_route_table_to_string(rule->manager, rule->table, &table);
|
||||
r = manager_get_route_table_to_string(rule->manager, rule->table, /* append_num = */ false, &table);
|
||||
if (r < 0 && r != -EINVAL)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -411,10 +411,9 @@ int manager_get_route_table_from_string(const Manager *m, const char *s, uint32_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **ret) {
|
||||
int manager_get_route_table_to_string(const Manager *m, uint32_t table, bool append_num, char **ret) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(ret);
|
||||
@@ -426,13 +425,16 @@ int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **r
|
||||
if (!s)
|
||||
s = hashmap_get(m->route_table_names_by_number, UINT32_TO_PTR(table));
|
||||
|
||||
if (s)
|
||||
/* Currently, this is only used in debugging logs. To not confuse any bug
|
||||
* reports, let's include the table number. */
|
||||
r = asprintf(&str, "%s(%" PRIu32 ")", s, table);
|
||||
else
|
||||
r = asprintf(&str, "%" PRIu32, table);
|
||||
if (r < 0)
|
||||
if (s && !append_num) {
|
||||
str = strdup(s);
|
||||
if (!str)
|
||||
return -ENOMEM;
|
||||
|
||||
} else if (asprintf(&str, "%s%s%" PRIu32 "%s",
|
||||
strempty(s),
|
||||
s ? "(" : "",
|
||||
table,
|
||||
s ? ")" : "") < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(str);
|
||||
|
||||
@@ -44,6 +44,6 @@ int route_protocol_full_to_string_alloc(int t, char **ret);
|
||||
int route_flags_to_string_alloc(uint32_t flags, char **ret);
|
||||
|
||||
int manager_get_route_table_from_string(const Manager *m, const char *table, uint32_t *ret);
|
||||
int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **ret);
|
||||
int manager_get_route_table_to_string(const Manager *m, uint32_t table, bool append_num, char **ret);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_table_names);
|
||||
|
||||
@@ -597,7 +597,7 @@ static void log_route_debug(const Route *route, const char *str, const Link *lin
|
||||
if (in_addr_is_set(route->family, &route->prefsrc))
|
||||
(void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc);
|
||||
(void) route_scope_to_string_alloc(route->scope, &scope);
|
||||
(void) manager_get_route_table_to_string(manager, route->table, &table);
|
||||
(void) manager_get_route_table_to_string(manager, route->table, /* append_num = */ true, &table);
|
||||
(void) route_protocol_full_to_string_alloc(route->protocol, &proto);
|
||||
(void) route_flags_to_string_alloc(route->flags, &flags);
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, const c
|
||||
return;
|
||||
|
||||
(void) network_config_state_to_string_alloc(rule->state, &state);
|
||||
(void) manager_get_route_table_to_string(m, rule->table, &table);
|
||||
(void) manager_get_route_table_to_string(m, rule->table, /* append_num = */ true, &table);
|
||||
|
||||
log_link_debug(link,
|
||||
"%s %s routing policy rule (%s): priority: %"PRIu32", %s -> %s, iif: %s, oif: %s, table: %s",
|
||||
|
||||
@@ -114,9 +114,14 @@ static void test_route_tables_one(Manager *manager, const char *name, uint32_t n
|
||||
}
|
||||
|
||||
assert_se(asprintf(&expected, "%s(%" PRIu32 ")", name, number) >= 0);
|
||||
assert_se(manager_get_route_table_to_string(manager, number, &str) >= 0);
|
||||
assert_se(manager_get_route_table_to_string(manager, number, /* append_num = */ true, &str) >= 0);
|
||||
assert_se(streq(str, expected));
|
||||
|
||||
str = mfree(str);
|
||||
|
||||
assert_se(manager_get_route_table_to_string(manager, number, /* append_num = */ false, &str) >= 0);
|
||||
assert_se(streq(str, name));
|
||||
|
||||
assert_se(manager_get_route_table_from_string(manager, name, &t) >= 0);
|
||||
assert_se(t == number);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user