summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2016-09-08 19:37:42 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-09-08 19:37:42 -0400
commitdfee47aa92d9cda6c2fe4f9873bfe1ae808bae57 (patch)
tree73cfb27167349081bf270020e8c270c926c331d7 /lib
parentb5826a12a2a4c4a9e4ccd267f47e2711683355f7 (diff)
parentdcaf0c593f8967cc2d9b3960abc525632d217c6c (diff)
Merge remote-tracking branch 'origin/cmaster' into cmaster-next
Diffstat (limited to 'lib')
-rw-r--r--lib/nexthop.c33
-rw-r--r--lib/nexthop.h4
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index 5853884218..14486ea157 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -153,3 +153,36 @@ nexthops_free (struct nexthop *nexthop)
nexthop_free (nh);
}
}
+
+const char *
+nexthop2str (struct nexthop *nexthop, char *str, int size)
+{
+ switch (nexthop->type)
+ {
+ case NEXTHOP_TYPE_IFINDEX:
+ snprintf (str, size, "if %u", nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_IPV4:
+ snprintf (str, size, "%s", inet_ntoa (nexthop->gate.ipv4));
+ break;
+ case NEXTHOP_TYPE_IPV4_IFINDEX:
+ snprintf (str, size, "%s if %u",
+ inet_ntoa (nexthop->gate.ipv4), nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_IPV6:
+ snprintf (str, size, "%s", inet6_ntoa (nexthop->gate.ipv6));
+ break;
+ case NEXTHOP_TYPE_IPV6_IFINDEX:
+ snprintf (str, size, "%s if %u",
+ inet6_ntoa (nexthop->gate.ipv6), nexthop->ifindex);
+ break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ snprintf (str, size, "blackhole");
+ break;
+ default:
+ snprintf (str, size, "unknown");
+ break;
+ }
+
+ return str;
+}
diff --git a/lib/nexthop.h b/lib/nexthop.h
index 4445c4ad27..39e8b5425f 100644
--- a/lib/nexthop.h
+++ b/lib/nexthop.h
@@ -26,6 +26,9 @@
#include "prefix.h"
+/* Maximum next hop string length - gateway + ifindex */
+#define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30)
+
union g_addr {
struct in_addr ipv4;
struct in6_addr ipv6;
@@ -97,4 +100,5 @@ void nexthops_free (struct nexthop *nexthop);
extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
extern int nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2);
+extern const char * nexthop2str (struct nexthop *nexthop, char *str, int size);
#endif /*_LIB_NEXTHOP_H */