3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #define QUAGGA_DEFINE_DESC_TABLE
33 /* for printstack on solaris */
34 #ifdef HAVE_UCONTEXT_H
38 static int logfile_fd = -1; /* Used in signal handler. */
40 struct zlog *zlog_default = NULL;
42 const char *zlog_proto_names[] =
60 const char *zlog_priority[] =
75 /* For time string format. */
78 quagga_timestamp(int timestamp_precision, char *buf, size_t buflen)
87 /* would it be sufficient to use global 'recent_time' here? I fear not... */
88 gettimeofday(&clock, NULL);
90 /* first, we update the cache if the time has changed */
91 if (cache.last != clock.tv_sec)
94 cache.last = clock.tv_sec;
95 tm = localtime(&cache.last);
96 cache.len = strftime(cache.buf, sizeof(cache.buf),
97 "%Y/%m/%d %H:%M:%S", tm);
99 /* note: it's not worth caching the subsecond part, because
100 chances are that back-to-back calls are not sufficiently close together
101 for the clock not to have ticked forward */
103 if (buflen > cache.len)
105 memcpy(buf, cache.buf, cache.len);
106 if ((timestamp_precision > 0) &&
107 (buflen > cache.len+1+timestamp_precision))
109 /* should we worry about locale issues? */
110 static const int divisor[] = {0, 100000, 10000, 1000, 100, 10, 1};
112 char *p = buf+cache.len+1+(prec = timestamp_precision);
115 /* this is unlikely to happen, but protect anyway */
120 clock.tv_usec /= divisor[prec];
123 *p-- = '0'+(clock.tv_usec % 10);
128 return cache.len+1+timestamp_precision;
130 buf[cache.len] = '\0';
138 /* Utility routine for current time printing. */
140 time_print(FILE *fp, struct timestamp_control *ctl)
142 if (!ctl->already_rendered)
144 ctl->len = quagga_timestamp(ctl->precision, ctl->buf, sizeof(ctl->buf));
145 ctl->already_rendered = 1;
147 fprintf(fp, "%s ", ctl->buf);
151 /* va_list version of zlog. */
153 vzlog (struct zlog *zl, int priority, const char *format, va_list args)
155 int original_errno = errno;
156 struct timestamp_control tsctl;
157 tsctl.already_rendered = 0;
159 /* If zlog is not specified, use default one. */
163 /* When zlog_default is also NULL, use stderr for logging. */
167 time_print(stderr, &tsctl);
168 fprintf (stderr, "%s: ", "unknown");
169 vfprintf (stderr, format, args);
170 fprintf (stderr, "\n");
173 /* In this case we return at here. */
174 errno = original_errno;
177 tsctl.precision = zl->timestamp_precision;
180 if (priority <= zl->maxlvl[ZLOG_DEST_SYSLOG])
184 vsyslog (priority|zlog_default->facility, format, ac);
189 if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp)
192 time_print (zl->fp, &tsctl);
193 if (zl->record_priority)
194 fprintf (zl->fp, "%s: ", zlog_priority[priority]);
195 fprintf (zl->fp, "%s: ", zlog_proto_names[zl->protocol]);
197 vfprintf (zl->fp, format, ac);
199 fprintf (zl->fp, "\n");
204 if (priority <= zl->maxlvl[ZLOG_DEST_STDOUT])
207 time_print (stdout, &tsctl);
208 if (zl->record_priority)
209 fprintf (stdout, "%s: ", zlog_priority[priority]);
210 fprintf (stdout, "%s: ", zlog_proto_names[zl->protocol]);
212 vfprintf (stdout, format, ac);
214 fprintf (stdout, "\n");
218 /* Terminal monitor. */
219 if (priority <= zl->maxlvl[ZLOG_DEST_MONITOR])
220 vty_log ((zl->record_priority ? zlog_priority[priority] : NULL),
221 zlog_proto_names[zl->protocol], format, &tsctl, args);
223 errno = original_errno;
227 str_append(char *dst, int len, const char *src)
229 while ((len-- > 0) && *src)
235 num_append(char *s, int len, u_long x)
241 return str_append(s,len,"0");
242 *(t = &buf[sizeof(buf)-1]) = '\0';
243 while (x && (t > buf))
248 return str_append(s,len,t);
251 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
253 hex_append(char *s, int len, u_long x)
259 return str_append(s,len,"0");
260 *(t = &buf[sizeof(buf)-1]) = '\0';
261 while (x && (t > buf))
264 *--t = ((cc < 10) ? ('0'+cc) : ('a'+cc-10));
267 return str_append(s,len,t);
271 /* Needs to be enhanced to support Solaris. */
280 struct sockaddr_un addr;
282 if ((fd = socket(AF_UNIX,SOCK_DGRAM,0)) < 0)
284 addr.sun_family = AF_UNIX;
286 #define SYSLOG_SOCKET_PATH _PATH_LOG
288 #define SYSLOG_SOCKET_PATH "/dev/log"
290 s = str_append(addr.sun_path,sizeof(addr.sun_path),SYSLOG_SOCKET_PATH);
291 #undef SYSLOG_SOCKET_PATH
293 if (connect(fd,(struct sockaddr *)&addr,sizeof(addr)) < 0)
303 syslog_sigsafe(int priority, const char *msg, size_t msglen)
305 static int syslog_fd = -1;
306 char buf[sizeof("<1234567890>ripngd[1234567890]: ")+msglen+50];
309 if ((syslog_fd < 0) && ((syslog_fd = syslog_connect()) < 0))
312 #define LOC s,buf+sizeof(buf)-s
314 s = str_append(LOC,"<");
315 s = num_append(LOC,priority);
316 s = str_append(LOC,">");
317 /* forget about the timestamp, too difficult in a signal handler */
318 s = str_append(LOC,zlog_default->ident);
319 if (zlog_default->syslog_options & LOG_PID)
321 s = str_append(LOC,"[");
322 s = num_append(LOC,getpid());
323 s = str_append(LOC,"]");
325 s = str_append(LOC,": ");
326 s = str_append(LOC,msg);
327 write(syslog_fd,buf,s-buf);
334 #define CRASHLOG_PREFIX "/var/tmp/quagga."
335 #define CRASHLOG_SUFFIX "crashlog"
336 if (zlog_default && zlog_default->ident)
338 /* Avoid strlen since it is not async-signal-safe. */
342 for (p = zlog_default->ident, ilen = 0; *p; p++)
345 char buf[sizeof(CRASHLOG_PREFIX)+ilen+sizeof(CRASHLOG_SUFFIX)+3];
347 #define LOC s,buf+sizeof(buf)-s
348 s = str_append(LOC, CRASHLOG_PREFIX);
349 s = str_append(LOC, zlog_default->ident);
350 s = str_append(LOC, ".");
351 s = str_append(LOC, CRASHLOG_SUFFIX);
354 return open(buf, O_WRONLY|O_CREAT|O_EXCL, LOGFILE_MASK);
357 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX, O_WRONLY|O_CREAT|O_EXCL,
359 #undef CRASHLOG_SUFFIX
360 #undef CRASHLOG_PREFIX
363 /* Note: the goal here is to use only async-signal-safe functions. */
365 zlog_signal(int signo, const char *action
367 , siginfo_t *siginfo, void *program_counter
372 char buf[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
374 char *msgstart = buf;
375 #define LOC s,buf+sizeof(buf)-s
380 s = str_append(LOC,zlog_proto_names[zlog_default->protocol]);
385 s = str_append(LOC,"Received signal ");
386 s = num_append(LOC,signo);
387 s = str_append(LOC," at ");
388 s = num_append(LOC,now);
390 s = str_append(LOC," (si_addr 0x");
391 s = hex_append(LOC,(u_long)(siginfo->si_addr));
394 s = str_append(LOC,", PC 0x");
395 s = hex_append(LOC,(u_long)program_counter);
397 s = str_append(LOC,"); ");
398 #else /* SA_SIGINFO */
399 s = str_append(LOC,"; ");
400 #endif /* SA_SIGINFO */
401 s = str_append(LOC,action);
402 if (s < buf+sizeof(buf))
405 /* N.B. implicit priority is most severe */
408 #define DUMP(FD) write(FD, buf, s-buf);
409 /* If no file logging configured, try to write to fallback log file. */
410 if ((logfile_fd >= 0) || ((logfile_fd = open_crashlog()) >= 0))
416 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_STDOUT])
418 /* Remove trailing '\n' for monitor and syslog */
420 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_MONITOR])
421 vty_log_fixed(buf,s-buf);
422 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG])
423 syslog_sigsafe(PRI|zlog_default->facility,msgstart,s-msgstart);
427 zlog_backtrace_sigsafe(PRI,
437 s = str_append (LOC, "no thread information available\n");
440 s = str_append (LOC, "in thread ");
441 s = str_append (LOC, thread_current->funcname);
442 s = str_append (LOC, " scheduled from ");
443 s = str_append (LOC, thread_current->schedfrom);
444 s = str_append (LOC, ":");
445 s = num_append (LOC, thread_current->schedfrom_line);
446 s = str_append (LOC, "\n");
449 #define DUMP(FD) write(FD, buf, s-buf);
450 /* If no file logging configured, try to write to fallback log file. */
457 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_STDOUT])
459 /* Remove trailing '\n' for monitor and syslog */
461 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_MONITOR])
462 vty_log_fixed(buf,s-buf);
463 if (PRI <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG])
464 syslog_sigsafe(PRI|zlog_default->facility,msgstart,s-msgstart);
472 /* Log a backtrace using only async-signal-safe functions.
473 Needs to be enhanced to support syslog logging. */
475 zlog_backtrace_sigsafe(int priority, void *program_counter)
477 #ifdef HAVE_STACK_TRACE
478 static const char pclabel[] = "Program counter: ";
482 char *s, **bt = NULL;
483 #define LOC s,buf+sizeof(buf)-s
485 #ifdef HAVE_GLIBC_BACKTRACE
486 size = backtrace(array, array_size(array));
487 if (size <= 0 || (size_t)size > array_size(array))
491 if (program_counter) \
493 write(FD, pclabel, sizeof(pclabel)-1); \
494 backtrace_symbols_fd(&program_counter, 1, FD); \
496 write(FD, buf, s-buf); \
497 backtrace_symbols_fd(array, size, FD); \
499 #elif defined(HAVE_PRINTSTACK)
501 if (program_counter) \
502 write((FD), pclabel, sizeof(pclabel)-1); \
503 write((FD), buf, s-buf); \
506 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
509 s = str_append(LOC,"Backtrace for ");
510 s = num_append(LOC,size);
511 s = str_append(LOC," stack frames:\n");
513 if ((logfile_fd >= 0) || ((logfile_fd = open_crashlog()) >= 0))
519 if (priority <= zlog_default->maxlvl[ZLOG_DEST_STDOUT])
521 /* Remove trailing '\n' for monitor and syslog */
523 if (priority <= zlog_default->maxlvl[ZLOG_DEST_MONITOR])
524 vty_log_fixed(buf,s-buf);
525 if (priority <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG])
526 syslog_sigsafe(priority|zlog_default->facility,buf,s-buf);
529 #ifdef HAVE_GLIBC_BACKTRACE
530 bt = backtrace_symbols(array, size);
532 /* Just print the function addresses. */
533 for (i = 0; i < size; i++)
537 s = str_append(LOC, bt[i]);
539 s = str_append(LOC,"[bt ");
540 s = num_append(LOC,i);
541 s = str_append(LOC,"] 0x");
542 s = hex_append(LOC,(u_long)(array[i]));
545 if (priority <= zlog_default->maxlvl[ZLOG_DEST_MONITOR])
546 vty_log_fixed(buf,s-buf);
547 if (priority <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG])
548 syslog_sigsafe(priority|zlog_default->facility,buf,s-buf);
556 #endif /* HAVE_STRACK_TRACE */
560 zlog_backtrace(int priority)
562 #ifndef HAVE_GLIBC_BACKTRACE
563 zlog(NULL, priority, "No backtrace available on this platform.");
569 size = backtrace(array, array_size(array));
570 if (size <= 0 || (size_t)size > array_size(array))
572 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
573 "(valid range is between 1 and %lu)",
574 size, (unsigned long)(array_size(array)));
577 zlog(NULL, priority, "Backtrace for %d stack frames:", size);
578 if (!(strings = backtrace_symbols(array, size)))
580 zlog_err("Cannot get backtrace symbols (out of memory?)");
581 for (i = 0; i < size; i++)
582 zlog(NULL, priority, "[bt %d] %p",i,array[i]);
586 for (i = 0; i < size; i++)
587 zlog(NULL, priority, "[bt %d] %s",i,strings[i]);
590 #endif /* HAVE_GLIBC_BACKTRACE */
594 zlog (struct zlog *zl, int priority, const char *format, ...)
598 va_start(args, format);
599 vzlog (zl, priority, format, args);
603 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
605 FUNCNAME(const char *format, ...) \
608 va_start(args, format); \
609 vzlog (NULL, PRIORITY, format, args); \
613 ZLOG_FUNC(zlog_err, LOG_ERR)
615 ZLOG_FUNC(zlog_warn, LOG_WARNING)
617 ZLOG_FUNC(zlog_info, LOG_INFO)
619 ZLOG_FUNC(zlog_notice, LOG_NOTICE)
621 ZLOG_FUNC(zlog_debug, LOG_DEBUG)
625 #define PLOG_FUNC(FUNCNAME,PRIORITY) \
627 FUNCNAME(struct zlog *zl, const char *format, ...) \
630 va_start(args, format); \
631 vzlog (zl, PRIORITY, format, args); \
635 PLOG_FUNC(plog_err, LOG_ERR)
637 PLOG_FUNC(plog_warn, LOG_WARNING)
639 PLOG_FUNC(plog_info, LOG_INFO)
641 PLOG_FUNC(plog_notice, LOG_NOTICE)
643 PLOG_FUNC(plog_debug, LOG_DEBUG)
647 void zlog_thread_info (int log_level)
650 zlog(NULL, log_level, "Current thread function %s, scheduled from "
651 "file %s, line %u", thread_current->funcname,
652 thread_current->schedfrom, thread_current->schedfrom_line);
654 zlog(NULL, log_level, "Current thread not known/applicable");
658 _zlog_assert_failed (const char *assertion, const char *file,
659 unsigned int line, const char *function)
661 /* Force fallback file logging? */
662 if (zlog_default && !zlog_default->fp &&
663 ((logfile_fd = open_crashlog()) >= 0) &&
664 ((zlog_default->fp = fdopen(logfile_fd, "w")) != NULL))
665 zlog_default->maxlvl[ZLOG_DEST_FILE] = LOG_ERR;
666 zlog(NULL, LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s",
667 assertion,file,line,(function ? function : "?"));
668 zlog_backtrace(LOG_CRIT);
669 zlog_thread_info(LOG_CRIT);
674 /* Open log stream */
676 openzlog (const char *progname, zlog_proto_t protocol,
677 int syslog_flags, int syslog_facility)
682 zl = XCALLOC(MTYPE_ZLOG, sizeof (struct zlog));
684 zl->ident = progname;
685 zl->protocol = protocol;
686 zl->facility = syslog_facility;
687 zl->syslog_options = syslog_flags;
689 /* Set default logging levels. */
690 for (i = 0; i < array_size(zl->maxlvl); i++)
691 zl->maxlvl[i] = ZLOG_DISABLED;
692 zl->maxlvl[ZLOG_DEST_MONITOR] = LOG_DEBUG;
693 zl->default_lvl = LOG_DEBUG;
695 openlog (progname, syslog_flags, zl->facility);
701 closezlog (struct zlog *zl)
708 if (zl->filename != NULL)
711 XFREE (MTYPE_ZLOG, zl);
714 /* Called from command.c. */
716 zlog_set_level (struct zlog *zl, zlog_dest_t dest, int log_level)
721 zl->maxlvl[dest] = log_level;
725 zlog_set_file (struct zlog *zl, const char *filename, int log_level)
730 /* There is opend file. */
731 zlog_reset_file (zl);
733 /* Set default zl. */
738 oldumask = umask (0777 & ~LOGFILE_MASK);
739 fp = fopen (filename, "a");
745 zl->filename = strdup (filename);
746 zl->maxlvl[ZLOG_DEST_FILE] = log_level;
748 logfile_fd = fileno(fp);
753 /* Reset opend file. */
755 zlog_reset_file (struct zlog *zl)
764 zl->maxlvl[ZLOG_DEST_FILE] = ZLOG_DISABLED;
773 /* Reopen log file. */
775 zlog_rotate (struct zlog *zl)
786 level = zl->maxlvl[ZLOG_DEST_FILE];
787 zl->maxlvl[ZLOG_DEST_FILE] = ZLOG_DISABLED;
794 oldumask = umask (0777 & ~LOGFILE_MASK);
795 zl->fp = fopen (zl->filename, "a");
800 zlog_err("Log rotate failed: cannot open file %s for append: %s",
801 zl->filename, safe_strerror(save_errno));
804 logfile_fd = fileno(zl->fp);
805 zl->maxlvl[ZLOG_DEST_FILE] = level;
811 /* Message lookup function. */
813 lookup (const struct message *mes, int key)
815 const struct message *pnt;
817 for (pnt = mes; pnt->key != 0; pnt++)
824 /* Older/faster version of message lookup function, but requires caller to pass
825 * in the array size (instead of relying on a 0 key to terminate the search).
827 * The return value is the message string if found, or the 'none' pointer
828 * provided otherwise.
831 mes_lookup (const struct message *meslist, int max, int index,
832 const char *none, const char *mesname)
834 int pos = index - meslist[0].key;
836 /* first check for best case: index is in range and matches the key
837 * value in that slot.
838 * NB: key numbering might be offset from 0. E.g. protocol constants
841 if ((pos >= 0) && (pos < max)
842 && (meslist[pos].key == index))
843 return meslist[pos].str;
845 /* fall back to linear search */
849 for (i = 0; i < max; i++, meslist++)
851 if (meslist->key == index)
853 const char *str = (meslist->str ? meslist->str : none);
855 zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
856 index, str, mesname, i, max);
861 zlog_err("message index %d not found in %s (max is %d)", index, mesname, max);
866 /* Wrapper around strerror to handle case where it returns NULL. */
868 safe_strerror(int errnum)
870 const char *s = strerror(errnum);
871 return (s != NULL) ? s : "Unknown error";
874 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
875 static const struct zebra_desc_table command_types[] = {
876 DESC_ENTRY (ZEBRA_INTERFACE_ADD),
877 DESC_ENTRY (ZEBRA_INTERFACE_DELETE),
878 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD),
879 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE),
880 DESC_ENTRY (ZEBRA_INTERFACE_UP),
881 DESC_ENTRY (ZEBRA_INTERFACE_DOWN),
882 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD),
883 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE),
884 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD),
885 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE),
886 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD),
887 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE),
888 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD),
889 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE),
890 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP),
891 DESC_ENTRY (ZEBRA_IPV6_NEXTHOP_LOOKUP),
892 DESC_ENTRY (ZEBRA_IPV4_IMPORT_LOOKUP),
893 DESC_ENTRY (ZEBRA_IPV6_IMPORT_LOOKUP),
894 DESC_ENTRY (ZEBRA_INTERFACE_RENAME),
895 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD),
896 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE),
897 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE),
898 DESC_ENTRY (ZEBRA_HELLO),
899 DESC_ENTRY (ZEBRA_NEXTHOP_REGISTER),
900 DESC_ENTRY (ZEBRA_NEXTHOP_UNREGISTER),
901 DESC_ENTRY (ZEBRA_NEXTHOP_UPDATE),
905 static const struct zebra_desc_table unknown = { 0, "unknown", '?' };
907 static const struct zebra_desc_table *
908 zroute_lookup(u_int zroute)
912 if (zroute >= array_size(route_types))
914 zlog_err("unknown zebra route type: %u", zroute);
917 if (zroute == route_types[zroute].type)
918 return &route_types[zroute];
919 for (i = 0; i < array_size(route_types); i++)
921 if (zroute == route_types[i].type)
923 zlog_warn("internal error: route type table out of order "
924 "while searching for %u, please notify developers", zroute);
925 return &route_types[i];
928 zlog_err("internal error: cannot find route type %u in table!", zroute);
933 zebra_route_string(u_int zroute)
935 return zroute_lookup(zroute)->string;
939 zebra_route_char(u_int zroute)
941 return zroute_lookup(zroute)->chr;
945 zserv_command_string (unsigned int command)
947 if (command >= array_size(command_types))
949 zlog_err ("unknown zserv command type: %u", command);
950 return unknown.string;
952 return command_types[command].string;
956 proto_name2num(const char *s)
960 for (i=0; i<array_size(route_types); ++i)
961 if (strcasecmp(s, route_types[i].string) == 0)
962 return route_types[i].type;
967 proto_redistnum(int afi, const char *s)
974 if (strncmp (s, "k", 1) == 0)
975 return ZEBRA_ROUTE_KERNEL;
976 else if (strncmp (s, "c", 1) == 0)
977 return ZEBRA_ROUTE_CONNECT;
978 else if (strncmp (s, "s", 1) == 0)
979 return ZEBRA_ROUTE_STATIC;
980 else if (strncmp (s, "r", 1) == 0)
981 return ZEBRA_ROUTE_RIP;
982 else if (strncmp (s, "o", 1) == 0)
983 return ZEBRA_ROUTE_OSPF;
984 else if (strncmp (s, "i", 1) == 0)
985 return ZEBRA_ROUTE_ISIS;
986 else if (strncmp (s, "bg", 2) == 0)
987 return ZEBRA_ROUTE_BGP;
988 else if (strncmp (s, "ba", 2) == 0)
989 return ZEBRA_ROUTE_BABEL;
990 else if (strncmp (s, "n", 1) == 0)
991 return ZEBRA_ROUTE_NHRP;
995 if (strncmp (s, "k", 1) == 0)
996 return ZEBRA_ROUTE_KERNEL;
997 else if (strncmp (s, "c", 1) == 0)
998 return ZEBRA_ROUTE_CONNECT;
999 else if (strncmp (s, "s", 1) == 0)
1000 return ZEBRA_ROUTE_STATIC;
1001 else if (strncmp (s, "r", 1) == 0)
1002 return ZEBRA_ROUTE_RIPNG;
1003 else if (strncmp (s, "o", 1) == 0)
1004 return ZEBRA_ROUTE_OSPF6;
1005 else if (strncmp (s, "i", 1) == 0)
1006 return ZEBRA_ROUTE_ISIS;
1007 else if (strncmp (s, "bg", 2) == 0)
1008 return ZEBRA_ROUTE_BGP;
1009 else if (strncmp (s, "ba", 2) == 0)
1010 return ZEBRA_ROUTE_BABEL;
1011 else if (strncmp (s, "n", 1) == 0)
1012 return ZEBRA_ROUTE_NHRP;
1018 zlog_hexdump (void *mem, unsigned int len) {
1019 unsigned long i = 0;
1021 unsigned int columns = 8;
1022 char buf[(len * 4) + ((len/4) * 20) + 30];
1025 for (i = 0; i < len + ((len % columns) ? (columns - len % columns) : 0); i++)
1028 if (i % columns == 0)
1029 s += sprintf(s, "0x%016lx: ", (unsigned long)mem + i);
1031 /* print hex data */
1033 s += sprintf(s, "%02x ", 0xFF & ((char*)mem)[i]);
1035 /* end of block, just aligning for ASCII dump */
1037 s += sprintf(s, " ");
1039 /* print ASCII dump */
1040 if (i % columns == (columns - 1))
1042 for (j = i - (columns - 1); j <= i; j++)
1044 if (j >= len) /* end of block, not really printing */
1045 s += sprintf(s, " ");
1047 else if(isprint((int)((char*)mem)[j])) /* printable char */
1048 s += sprintf(s, "%c", 0xFF & ((char*)mem)[j]);
1050 else /* other char */
1051 s += sprintf(s, ".");
1053 s += sprintf(s, "\n");
1056 zlog_debug("\n%s", buf);