]> git.proxmox.com Git - mirror_frr.git/blobdiff - isisd/isis_misc.c
Merge pull request #6407 from donaldsharp/revert_ospfv3_fix
[mirror_frr.git] / isisd / isis_misc.c
index d4c38efaf3016ed1c8f0a36758ba79262b0d5be9..27d06e8da7344149fb770b5f986ac8fb3c32f5ad 100644 (file)
@@ -29,6 +29,7 @@
 #include "hash.h"
 #include "if.h"
 #include "command.h"
+#include "network.h"
 
 #include "isisd/isis_constants.h"
 #include "isisd/isis_common.h"
@@ -117,7 +118,8 @@ int dotformat2buff(uint8_t *buff, const char *dotted)
                        break;
                }
 
-               if ((isxdigit((int)*pos)) && (isxdigit((int)*(pos + 1)))) {
+               if ((isxdigit((unsigned char)*pos)) &&
+                   (isxdigit((unsigned char)*(pos + 1)))) {
                        memcpy(number, pos, 2);
                        pos += 2;
                } else {
@@ -157,7 +159,8 @@ int sysid2buff(uint8_t *buff, const char *dotted)
                        pos++;
                        continue;
                }
-               if ((isxdigit((int)*pos)) && (isxdigit((int)*(pos + 1)))) {
+               if ((isxdigit((unsigned char)*pos)) &&
+                   (isxdigit((unsigned char)*(pos + 1)))) {
                        memcpy(number, pos, 2);
                        pos += 2;
                } else {
@@ -411,7 +414,7 @@ unsigned long isis_jitter(unsigned long timer, unsigned long jitter)
         * most IS-IS timers are no longer than 16 bit
         */
 
-       j = 1 + (int)((RANDOM_SPREAD * random()) / (RAND_MAX + 1.0));
+       j = 1 + (int)((RANDOM_SPREAD * frr_weak_random()) / (RAND_MAX + 1.0));
 
        k = timer - (timer * (100 - jitter)) / 100;
 
@@ -519,7 +522,7 @@ void log_multiline(int priority, const char *prefix, const char *format, ...)
        char *p;
 
        va_start(ap, format);
-       p = asnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
+       p = vasnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
        va_end(ap);
 
        if (!p)
@@ -535,6 +538,26 @@ void log_multiline(int priority, const char *prefix, const char *format, ...)
                XFREE(MTYPE_TMP, p);
 }
 
+char *log_uptime(time_t uptime, char *buf, size_t nbuf)
+{
+       struct tm *tm;
+       time_t difftime = time(NULL);
+       difftime -= uptime;
+       tm = gmtime(&difftime);
+
+       if (difftime < ONE_DAY_SECOND)
+               snprintf(buf, nbuf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
+                        tm->tm_sec);
+       else if (difftime < ONE_WEEK_SECOND)
+               snprintf(buf, nbuf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
+                        tm->tm_min);
+       else
+               snprintf(buf, nbuf, "%02dw%dd%02dh", tm->tm_yday / 7,
+                        tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
+
+       return buf;
+}
+
 void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
 {
        char shortbuf[256];
@@ -542,7 +565,7 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
        char *p;
 
        va_start(ap, format);
-       p = asnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
+       p = vasnprintfrr(MTYPE_TMP, shortbuf, sizeof(shortbuf), format, ap);
        va_end(ap);
 
        if (!p)
@@ -560,19 +583,12 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
 
 void vty_out_timestr(struct vty *vty, time_t uptime)
 {
-       struct tm *tm;
        time_t difftime = time(NULL);
+       char buf[MONOTIME_STRLEN];
+
        difftime -= uptime;
-       tm = gmtime(&difftime);
 
-       if (difftime < ONE_DAY_SECOND)
-               vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
-                       tm->tm_sec);
-       else if (difftime < ONE_WEEK_SECOND)
-               vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
-                       tm->tm_min);
-       else
-               vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
-                       tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour);
-       vty_out(vty, " ago");
+       frrtime_to_interval(difftime, buf, sizeof(buf));
+
+       vty_out(vty, "%s ago", buf);
 }