ospfd: more explicit error message

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ospfd: more explicit error message

Denis Fondras
Currently ospfd logs routing message type code instead of name.
Make it more explicit.

remi@ is OK but wonders if rtm_type_name() will be updated as needed (that's why
I also log the typecode)
What do you think ?

Denis


Index: kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/kroute.c,v
retrieving revision 1.112
diff -u -p -r1.112 kroute.c
--- kroute.c 28 Dec 2018 19:25:10 -0000 1.112
+++ kroute.c 1 Nov 2019 18:00:31 -0000
@@ -1269,7 +1269,8 @@ retry:
  return (0);
  }
  }
- log_warn("send_rtmsg: action %u, prefix %s/%u", hdr.rtm_type,
+ log_warn("send_rtmsg: action %s(%d), prefix %s/%u",
+    rtm_type_name(hdr.rtm_type), hdr.rtm_type,
     inet_ntoa(kroute->prefix), kroute->prefixlen);
  return (0);
  }
Index: logmsg.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/logmsg.c,v
retrieving revision 1.1
diff -u -p -r1.1 logmsg.c
--- logmsg.c 2 Sep 2016 14:04:25 -0000 1.1
+++ logmsg.c 1 Nov 2019 18:00:31 -0000
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <sys/socket.h>
+#include <net/route.h>
 
 #include "ospfd.h"
 #include "log.h"
@@ -137,6 +139,35 @@ path_type_name(enum path_type type)
  return ("Type 1 ext");
  case PT_TYPE2_EXT:
  return ("Type 2 ext");
+ }
+ /* NOTREACHED */
+ return ("unknown");
+}
+
+const char *
+rtm_type_name(int type)
+{
+ switch(type) {
+ case RTM_ADD:
+ return("RTM_ADD");
+ case RTM_GET:
+ return("RTM_GET");
+ case RTM_CHANGE:
+ return("RTM_CHANGE");
+ case RTM_DELETE:
+ return("RTM_DELETE");
+ case RTM_IFINFO:
+ return("RTM_IFINFO");
+ case RTM_NEWADDR:
+ return("RTM_NEWADDR");
+ case RTM_DELADDR:
+ return("RTM_DELADDR");
+ case RTM_IFANNOUNCE:
+ return("RTM_IFANNOUNCE");
+ case RTM_DESYNC:
+ return("RTM_DESYNC");
+ case RTM_BFD:
+ return("RTM_BFD");
  }
  /* NOTREACHED */
  return ("unknown");
Index: ospfd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/ospfd.h,v
retrieving revision 1.104
diff -u -p -r1.104 ospfd.h
--- ospfd.h 16 May 2019 05:49:22 -0000 1.104
+++ ospfd.h 1 Nov 2019 18:00:31 -0000
@@ -598,6 +598,7 @@ const char *if_type_name(enum iface_type
 const char *if_auth_name(enum auth_type);
 const char *dst_type_name(enum dst_type);
 const char *path_type_name(enum path_type);
+const char *rtm_type_name(int);
 
 /* name2id.c */
 u_int16_t rtlabel_name2id(const char *);