Newer version after a comment by claudio@.

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.
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 22:12:18 -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, prefix %s/%u",
+                   rtm_type_name(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 22:12:18 -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"
@@ -140,4 +142,36 @@ path_type_name(enum path_type type)
        }
        /* NOTREACHED */
        return ("unknown");
+}
+
+const char *
+rtm_type_name(int type)
+{
+       static char buf[13];
+       
+       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");
+       default:
+               snprintf(buf, sizeof(buf), "#%d", type);
+               return(buf);
+       }
 }
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 22:12:18 -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 *);

Reply via email to