From 31be7dbbc5dae175a35a66a7da4b516ec9124bb8 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 17 Jan 2019 13:12:13 -0200 Subject: zebra: fix debug messages with prefixes Debug messages should use `prefix_buf` and `prefix2str` should only be called once in `kernel_rtm`. Signed-off-by: Rafael Zalamena --- zebra/rt_socket.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'zebra/rt_socket.c') diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 29e9bf82f0..08f9a2c719 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -131,7 +131,7 @@ static int kernel_rtm(int cmd, const struct prefix *p, char prefix_buf[PREFIX_STRLEN]; enum blackhole_type bh_type = BLACKHOLE_UNSPEC; - if (IS_ZEBRA_DEBUG_RIB) + if (IS_ZEBRA_DEBUG_RIB || IS_ZEBRA_DEBUG_KERNEL) prefix2str(p, prefix_buf, sizeof(prefix_buf)); /* @@ -301,12 +301,11 @@ static int kernel_rtm(int cmd, const struct prefix *p, /* Note any unexpected status returns */ default: - flog_err(EC_LIB_SYSTEM_CALL, - "%s: %s: rtm_write() unexpectedly returned %d for command %s", - __func__, - prefix2str(p, prefix_buf, - sizeof(prefix_buf)), - error, lookup_msg(rtm_type_str, cmd, NULL)); + flog_err( + EC_LIB_SYSTEM_CALL, + "%s: %s: rtm_write() unexpectedly returned %d for command %s", + __func__, prefix_buf, error, + lookup_msg(rtm_type_str, cmd, NULL)); break; } } /* for (ALL_NEXTHOPS(...))*/ @@ -314,9 +313,9 @@ static int kernel_rtm(int cmd, const struct prefix *p, /* If there was no useful nexthop, then complain. */ if (nexthop_num == 0) { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: No useful nexthops were found in RIB prefix %s", - __func__, prefix2str(p, prefix_buf, - sizeof(prefix_buf))); + zlog_debug( + "%s: No useful nexthops were found in RIB prefix %s", + __func__, prefix_buf); return 1; } -- cgit v1.2.3 From 981dc13f4635625d3f964ae5bd74c502d033a61e Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 17 Jan 2019 13:15:20 -0200 Subject: zebra: fix debug prefix string size `gate_buf` should be big enough to hold IPv6 addresses and `inet_ntop` should be run in the correct `sockaddr` struct member. Signed-off-by: Rafael Zalamena --- zebra/rt_socket.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'zebra/rt_socket.c') diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 08f9a2c719..8012498e80 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -128,6 +128,7 @@ static int kernel_rtm(int cmd, const struct prefix *p, ifindex_t ifindex = 0; bool gate = false; int error; + char gate_buf[INET6_BUFSIZ]; char prefix_buf[PREFIX_STRLEN]; enum blackhole_type bh_type = BLACKHOLE_UNSPEC; @@ -185,7 +186,7 @@ static int kernel_rtm(int cmd, const struct prefix *p, smplsp = NULL; gate = false; - char gate_buf[INET_ADDRSTRLEN] = "NULL"; + snprintf(gate_buf, sizeof(gate_buf), "NULL"); switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: @@ -266,13 +267,29 @@ static int kernel_rtm(int cmd, const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (!gate) { - zlog_debug("%s: %s: attention! gate not found for re", - __func__, prefix_buf); - } else - inet_ntop(p->family == AFI_IP ? AF_INET - : AF_INET6, - &sin_gate.sin.sin_addr, - gate_buf, INET_ADDRSTRLEN); + zlog_debug( + "%s: %s: attention! gate not found for re", + __func__, prefix_buf); + } else { + switch (p->family) { + case AFI_IP: + inet_ntop(AF_INET, + &sin_gate.sin.sin_addr, + gate_buf, sizeof(gate_buf)); + break; + + case AFI_IP6: + inet_ntop(AF_INET6, + &sin_gate.sin6.sin6_addr, + gate_buf, sizeof(gate_buf)); + break; + + default: + snprintf(gate_buf, sizeof(gate_buf), + "(invalid-af)"); + break; + } + } } switch (error) { /* We only flag nexthops as being in FIB if -- cgit v1.2.3