1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-08 20:58:20 +03:00

network: introduce log_nexthop_debug()

This commit is contained in:
Yu Watanabe 2021-02-05 09:44:49 +09:00
parent 6283e71ba8
commit 56223d926d

View File

@ -217,6 +217,21 @@ static int nexthop_add(Link *link, NextHop *in, NextHop **ret) {
return is_new;
}
static void log_nexthop_debug(const NextHop *nexthop, const char *str, const Link *link) {
assert(nexthop);
assert(str);
assert(link);
if (DEBUG_LOGGING) {
_cleanup_free_ char *gw = NULL;
(void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw);
log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s",
str, nexthop->id, strna(gw));
}
}
static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
@ -254,14 +269,7 @@ static int nexthop_configure(NextHop *nexthop, Link *link) {
assert(link->ifindex > 0);
assert(IN_SET(nexthop->family, AF_INET, AF_INET6));
if (DEBUG_LOGGING) {
_cleanup_free_ char *gw = NULL;
if (!in_addr_is_null(nexthop->family, &nexthop->gw))
(void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw);
log_link_debug(link, "Configuring nexthop: gw: %s", strna(gw));
}
log_nexthop_debug(nexthop, "Configuring", link);
r = sd_rtnl_message_new_nexthop(link->manager->rtnl, &req,
RTM_NEWNEXTHOP, nexthop->family,
@ -343,7 +351,6 @@ int link_set_nexthop(Link *link) {
int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
_cleanup_(nexthop_freep) NextHop *tmp = NULL;
_cleanup_free_ char *gateway = NULL;
NextHop *nexthop = NULL;
uint32_t ifindex;
uint16_t type;
@ -415,15 +422,12 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
(void) nexthop_get(link, tmp, &nexthop);
if (DEBUG_LOGGING)
(void) in_addr_to_string(tmp->family, &tmp->gw, &gateway);
switch (type) {
case RTM_NEWNEXTHOP:
if (nexthop)
log_link_debug(link, "Received remembered nexthop: %s, id: %d", strna(gateway), tmp->id);
log_nexthop_debug(tmp, "Received remembered", link);
else {
log_link_debug(link, "Remembering foreign nexthop: %s, id: %d", strna(gateway), tmp->id);
log_nexthop_debug(tmp, "Remembering foreign", link);
r = nexthop_add_foreign(link, tmp, &nexthop);
if (r < 0) {
log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m");
@ -432,12 +436,8 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
}
break;
case RTM_DELNEXTHOP:
if (nexthop) {
log_link_debug(link, "Forgetting nexthop: %s, id: %d", strna(gateway), tmp->id);
nexthop_free(nexthop);
} else
log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, id: %d, ignoring.",
strna(gateway), tmp->id);
log_nexthop_debug(tmp, nexthop ? "Forgetting" : "Kernel removed unknown", link);
nexthop_free(nexthop);
break;
default: