summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog7
-rw-r--r--lib/log.c59
-rw-r--r--lib/zebra.h8
3 files changed, 73 insertions, 1 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index fd3feffa..956b10eb 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+ * zebra.h: Declare new functions zebra_route_string() and
+ zebra_route_char().
+ * log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
+ functions to map zebra route numbers to strings.
+
2005-09-29 Alain Ritoux <alain.ritoux@6wind.com>
* smux.[ch]: allow to retreive global OID (identified by <0
diff --git a/lib/log.c b/lib/log.c
index 2c4b399a..6748dbc0 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1,5 +1,5 @@
/*
- * $Id: log.c,v 1.25 2005/02/03 19:22:05 ajs Exp $
+ * $Id: log.c,v 1.26 2005/10/01 17:38:07 ajs Exp $
*
* Logging of zebra
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
@@ -703,3 +703,60 @@ safe_strerror(int errnum)
const char *s = strerror(errnum);
return (s != NULL) ? s : "Unknown error";
}
+
+/* Note: this table must match the ordering in lib/zebra.h */
+static const struct zebra_route_desc {
+ u_int zroute;
+ const char *string;
+ char chr;
+} route_types[] = {
+ { ZEBRA_ROUTE_SYSTEM, "system", 'X' },
+ { ZEBRA_ROUTE_KERNEL, "kernel", 'K' },
+ { ZEBRA_ROUTE_CONNECT, "connected", 'C' },
+ { ZEBRA_ROUTE_STATIC, "static", 'S' },
+ { ZEBRA_ROUTE_RIP, "rip", 'R' },
+ { ZEBRA_ROUTE_RIPNG, "ripng", 'R' },
+ { ZEBRA_ROUTE_OSPF, "ospf", 'O' },
+ { ZEBRA_ROUTE_OSPF6, "ospf6", 'O' },
+ { ZEBRA_ROUTE_ISIS, "isis", 'I' },
+ { ZEBRA_ROUTE_BGP, "bgp", 'B' },
+ { ZEBRA_ROUTE_HSLS, "hsls", 'H' },
+};
+
+static const struct zebra_route_desc *
+zroute_lookup(u_int zroute)
+{
+ static const struct zebra_route_desc unknown = { 0, "unknown", '?' };
+ u_int i;
+
+ if (zroute >= sizeof(route_types)/sizeof(route_types[0]))
+ {
+ zlog_err("unknown zebra route type: %u", zroute);
+ return &unknown;
+ }
+ if (zroute == route_types[zroute].zroute)
+ return &route_types[zroute];
+ for (i = 0; i < sizeof(route_types)/sizeof(route_types[0]); i++)
+ {
+ if (zroute == route_types[i].zroute)
+ {
+ zlog_warn("internal error: route type table out of order "
+ "while searching for %u, please notify developers", zroute);
+ return &route_types[i];
+ }
+ }
+ zlog_err("internal error: cannot find route type %u in table!", zroute);
+ return &unknown;
+}
+
+const char *
+zebra_route_string(u_int zroute)
+{
+ return zroute_lookup(zroute)->string;
+}
+
+char
+zebra_route_char(u_int zroute)
+{
+ return zroute_lookup(zroute)->chr;
+}
diff --git a/lib/zebra.h b/lib/zebra.h
index 03af70d3..88f16252 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -391,6 +391,14 @@ struct in_pktinfo
#define ZEBRA_ROUTE_HSLS 10
#define ZEBRA_ROUTE_MAX 11
+/* Note: whenever a new route type is added (or the numbering is changed),
+ the route_types[] table in lib/log.c must be updated! */
+
+/* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
+extern const char *zebra_route_string(u_int route_type);
+/* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
+extern char zebra_route_char(u_int route_type);
+
/* Zebra's family types. */
#define ZEBRA_FAMILY_IPV4 1
#define ZEBRA_FAMILY_IPV6 2