diff options
| author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-01-17 13:15:20 -0200 |
|---|---|---|
| committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-01-21 07:32:52 -0200 |
| commit | 981dc13f4635625d3f964ae5bd74c502d033a61e (patch) | |
| tree | aba8bab6f4203f6f981c9e0e5fff3435f8a0f671 /zebra/rt_socket.c | |
| parent | 31be7dbbc5dae175a35a66a7da4b516ec9124bb8 (diff) | |
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 <rzalamena@opensourcerouting.org>
Diffstat (limited to 'zebra/rt_socket.c')
| -rw-r--r-- | zebra/rt_socket.c | 33 |
1 files changed, 25 insertions, 8 deletions
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 |
