From 152e64e3013d67125accb15cf37f723b886e367b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 22 Nov 2019 08:03:25 -0500 Subject: [PATCH 1/2] eigrpd: Cleanup eigrp_if_name_string This function was excessively complicated. Simplify and make everyone use the same access macro. Signed-off-by: Donald Sharp --- eigrpd/eigrp_dump.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/eigrpd/eigrp_dump.c b/eigrpd/eigrp_dump.c index 583db6622d..15c7a20639 100644 --- a/eigrpd/eigrp_dump.c +++ b/eigrpd/eigrp_dump.c @@ -144,13 +144,10 @@ void eigrp_header_dump(struct eigrp_header *eigrph) const char *eigrp_if_name_string(struct eigrp_interface *ei) { - static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - if (!ei) return "inactive"; - snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%s", ei->ifp->name); - return buf; + return ei->ifp->name; } const char *eigrp_topology_ip_string(struct eigrp_prefix_entry *tn) @@ -209,7 +206,7 @@ void show_ip_eigrp_interface_header(struct vty *vty, struct eigrp *eigrp) void show_ip_eigrp_interface_sub(struct vty *vty, struct eigrp *eigrp, struct eigrp_interface *ei) { - vty_out(vty, "%-11s ", eigrp_if_name_string(ei)); + vty_out(vty, "%-11s ", IF_NAME(ei)); vty_out(vty, "%-11u", ei->params.bandwidth); vty_out(vty, "%-11u", ei->params.delay); vty_out(vty, "%-7u", ei->nbrs->count); @@ -250,7 +247,7 @@ void show_ip_eigrp_neighbor_sub(struct vty *vty, struct eigrp_neighbor *nbr, { vty_out(vty, "%-3u %-17s %-21s", 0, eigrp_neigh_ip_string(nbr), - eigrp_if_name_string(nbr->ei)); + IF_NAME(nbr->ei)); if (nbr->t_holddown) vty_out(vty, "%-7lu", thread_timer_remain_second(nbr->t_holddown)); @@ -313,11 +310,11 @@ void show_ip_eigrp_nexthop_entry(struct vty *vty, struct eigrp *eigrp, if (te->adv_router == eigrp->neighbor_self) vty_out(vty, "%-7s%s, %s\n", " ", "via Connected", - eigrp_if_name_string(te->ei)); + IF_NAME(te->ei)); else { vty_out(vty, "%-7s%s%s (%u/%u), %s\n", " ", "via ", inet_ntoa(te->adv_router->src), te->distance, - te->reported_distance, eigrp_if_name_string(te->ei)); + te->reported_distance, IF_NAME(te->ei)); } } From d2d3d394150f04a512d4ad4a3de0d84b0c1a31d5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 22 Nov 2019 08:17:27 -0500 Subject: [PATCH 2/2] eigrpd: Cleanup address dump functions to be a bit smarter The address dump functionality needed to be written a bit better. Signed-off-by: Donald Sharp --- eigrpd/eigrp_dump.c | 42 ------------------------------------------ eigrpd/eigrp_dump.h | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/eigrpd/eigrp_dump.c b/eigrpd/eigrp_dump.c index 15c7a20639..7278b002d8 100644 --- a/eigrpd/eigrp_dump.c +++ b/eigrpd/eigrp_dump.c @@ -150,48 +150,6 @@ const char *eigrp_if_name_string(struct eigrp_interface *ei) return ei->ifp->name; } -const char *eigrp_topology_ip_string(struct eigrp_prefix_entry *tn) -{ - static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - uint32_t ifaddr; - - ifaddr = ntohl(tn->destination->u.prefix4.s_addr); - snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%u.%u.%u.%u", - (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff, - (ifaddr >> 8) & 0xff, ifaddr & 0xff); - return buf; -} - - -const char *eigrp_if_ip_string(struct eigrp_interface *ei) -{ - static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - uint32_t ifaddr; - - if (!ei) - return "inactive"; - - ifaddr = ntohl(ei->address.u.prefix4.s_addr); - snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%u.%u.%u.%u", - (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff, - (ifaddr >> 8) & 0xff, ifaddr & 0xff); - - return buf; -} - -const char *eigrp_neigh_ip_string(struct eigrp_neighbor *nbr) -{ - static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - uint32_t ifaddr; - - ifaddr = ntohl(nbr->src.s_addr); - snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%u.%u.%u.%u", - (ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff, - (ifaddr >> 8) & 0xff, ifaddr & 0xff); - - return buf; -} - void show_ip_eigrp_interface_header(struct vty *vty, struct eigrp *eigrp) { diff --git a/eigrpd/eigrp_dump.h b/eigrpd/eigrp_dump.h index 34b55ab419..f141f3cbc6 100644 --- a/eigrpd/eigrp_dump.h +++ b/eigrpd/eigrp_dump.h @@ -138,9 +138,21 @@ extern unsigned long term_debug_eigrp_zebra; /* Prototypes. */ extern const char *eigrp_if_name_string(struct eigrp_interface *); -extern const char *eigrp_if_ip_string(struct eigrp_interface *); -extern const char *eigrp_neigh_ip_string(struct eigrp_neighbor *); -extern const char *eigrp_topology_ip_string(struct eigrp_prefix_entry *); +static inline const char +*eigrp_topology_ip_string(struct eigrp_prefix_entry *tn) +{ + return inet_ntoa(tn->destination->u.prefix4); +} + +static inline const char *eigrp_if_ip_string(struct eigrp_interface *ei) +{ + return ei ? inet_ntoa(ei->address.u.prefix4) : "inactive"; +} + +static inline const char *eigrp_neigh_ip_string(struct eigrp_neighbor *nbr) +{ + return inet_ntoa(nbr->src); +} extern void eigrp_ip_header_dump(struct ip *); extern void eigrp_header_dump(struct eigrp_header *);