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 DEFINE_MTYPE_STATIC(LIB
, ZLOG
, "Logging")
40 static int logfile_fd
= -1; /* Used in signal handler. */
42 struct zlog
*zlog_default
= NULL
;
44 const char *zlog_proto_names
[] =
60 const char *zlog_priority
[] =
76 * glibc has declared that the return value from write *must* not be
78 * gcc see's this problem and issues a warning for the line.
80 * Why is this a big deal you say? Because both of them are right
81 * and if you have -Werror enabled then all calls to write
82 * generate a build error and the build stops.
84 * clang has helpfully allowed this construct:
86 * to tell the compiler yeah I know it has a return value
87 * I don't care about it at this time.
88 * gcc doesn't have this ability.
90 * This code was written such that it didn't care about the
91 * return value from write. At this time do I want
92 * to go through and fix and test this code for correctness.
93 * So just wrapper the bad behavior and move on.
95 static void write_wrapper (int fd
, const void *buf
, size_t count
)
97 if (write (fd
, buf
, count
) <= 0)
103 /* For time string format. */
106 quagga_timestamp(int timestamp_precision
, char *buf
, size_t buflen
)
113 struct timeval clock
;
115 /* would it be sufficient to use global 'recent_time' here? I fear not... */
116 gettimeofday(&clock
, NULL
);
118 /* first, we update the cache if the time has changed */
119 if (cache
.last
!= clock
.tv_sec
)
122 cache
.last
= clock
.tv_sec
;
123 tm
= localtime(&cache
.last
);
124 cache
.len
= strftime(cache
.buf
, sizeof(cache
.buf
),
125 "%Y/%m/%d %H:%M:%S", tm
);
127 /* note: it's not worth caching the subsecond part, because
128 chances are that back-to-back calls are not sufficiently close together
129 for the clock not to have ticked forward */
131 if (buflen
> cache
.len
)
133 memcpy(buf
, cache
.buf
, cache
.len
);
134 if ((timestamp_precision
> 0) &&
135 (buflen
> cache
.len
+1+timestamp_precision
))
137 /* should we worry about locale issues? */
138 static const int divisor
[] = {0, 100000, 10000, 1000, 100, 10, 1};
140 char *p
= buf
+cache
.len
+1+(prec
= timestamp_precision
);
143 /* this is unlikely to happen, but protect anyway */
148 clock
.tv_usec
/= divisor
[prec
];
151 *p
-- = '0'+(clock
.tv_usec
% 10);
156 return cache
.len
+1+timestamp_precision
;
158 buf
[cache
.len
] = '\0';
166 /* Utility routine for current time printing. */
168 time_print(FILE *fp
, struct timestamp_control
*ctl
)
170 if (!ctl
->already_rendered
)
172 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
173 ctl
->already_rendered
= 1;
175 fprintf(fp
, "%s ", ctl
->buf
);
179 /* va_list version of zlog. */
181 vzlog (struct zlog
*zl
, int priority
, const char *format
, va_list args
)
184 int original_errno
= errno
;
185 struct timestamp_control tsctl
;
186 tsctl
.already_rendered
= 0;
188 /* If zlog is not specified, use default one. */
192 /* When zlog_default is also NULL, use stderr for logging. */
196 time_print(stderr
, &tsctl
);
197 fprintf (stderr
, "%s: ", "unknown");
198 vfprintf (stderr
, format
, args
);
199 fprintf (stderr
, "\n");
202 /* In this case we return at here. */
203 errno
= original_errno
;
206 tsctl
.precision
= zl
->timestamp_precision
;
209 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
213 vsyslog (priority
|zlog_default
->facility
, format
, ac
);
218 sprintf (proto_str
, "%s[%d]: ", zlog_proto_names
[zl
->protocol
], zl
->instance
);
220 sprintf (proto_str
, "%s: ", zlog_proto_names
[zl
->protocol
]);
223 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
226 time_print (zl
->fp
, &tsctl
);
227 if (zl
->record_priority
)
228 fprintf (zl
->fp
, "%s: ", zlog_priority
[priority
]);
229 fprintf (zl
->fp
, "%s", proto_str
);
231 vfprintf (zl
->fp
, format
, ac
);
233 fprintf (zl
->fp
, "\n");
238 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
241 time_print (stdout
, &tsctl
);
242 if (zl
->record_priority
)
243 fprintf (stdout
, "%s: ", zlog_priority
[priority
]);
244 fprintf (stdout
, "%s", proto_str
);
246 vfprintf (stdout
, format
, ac
);
248 fprintf (stdout
, "\n");
252 /* Terminal monitor. */
253 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
254 vty_log ((zl
->record_priority
? zlog_priority
[priority
] : NULL
),
255 proto_str
, format
, &tsctl
, args
);
257 errno
= original_errno
;
261 str_append(char *dst
, int len
, const char *src
)
263 while ((len
-- > 0) && *src
)
269 num_append(char *s
, int len
, u_long x
)
275 return str_append(s
,len
,"0");
276 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
277 while (x
&& (t
> buf
))
282 return str_append(s
,len
,t
);
285 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
287 hex_append(char *s
, int len
, u_long x
)
293 return str_append(s
,len
,"0");
294 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
295 while (x
&& (t
> buf
))
298 *--t
= ((cc
< 10) ? ('0'+cc
) : ('a'+cc
-10));
301 return str_append(s
,len
,t
);
305 /* Needs to be enhanced to support Solaris. */
314 struct sockaddr_un addr
;
316 if ((fd
= socket(AF_UNIX
,SOCK_DGRAM
,0)) < 0)
318 addr
.sun_family
= AF_UNIX
;
320 #define SYSLOG_SOCKET_PATH _PATH_LOG
322 #define SYSLOG_SOCKET_PATH "/dev/log"
324 s
= str_append(addr
.sun_path
,sizeof(addr
.sun_path
),SYSLOG_SOCKET_PATH
);
325 #undef SYSLOG_SOCKET_PATH
327 if (connect(fd
,(struct sockaddr
*)&addr
,sizeof(addr
)) < 0)
337 syslog_sigsafe(int priority
, const char *msg
, size_t msglen
)
339 static int syslog_fd
= -1;
340 char buf
[sizeof("<1234567890>ripngd[1234567890]: ")+msglen
+50];
343 if ((syslog_fd
< 0) && ((syslog_fd
= syslog_connect()) < 0))
346 #define LOC s,buf+sizeof(buf)-s
348 s
= str_append(LOC
,"<");
349 s
= num_append(LOC
,priority
);
350 s
= str_append(LOC
,">");
351 /* forget about the timestamp, too difficult in a signal handler */
352 s
= str_append(LOC
,zlog_default
->ident
);
353 if (zlog_default
->syslog_options
& LOG_PID
)
355 s
= str_append(LOC
,"[");
356 s
= num_append(LOC
,getpid());
357 s
= str_append(LOC
,"]");
359 s
= str_append(LOC
,": ");
360 s
= str_append(LOC
,msg
);
361 write_wrapper (syslog_fd
,buf
,s
-buf
);
368 #define CRASHLOG_PREFIX "/var/tmp/quagga."
369 #define CRASHLOG_SUFFIX "crashlog"
370 if (zlog_default
&& zlog_default
->ident
)
372 /* Avoid strlen since it is not async-signal-safe. */
376 for (p
= zlog_default
->ident
, ilen
= 0; *p
; p
++)
379 char buf
[sizeof(CRASHLOG_PREFIX
)+ilen
+sizeof(CRASHLOG_SUFFIX
)+3];
381 #define LOC s,buf+sizeof(buf)-s
382 s
= str_append(LOC
, CRASHLOG_PREFIX
);
383 s
= str_append(LOC
, zlog_default
->ident
);
384 s
= str_append(LOC
, ".");
385 s
= str_append(LOC
, CRASHLOG_SUFFIX
);
388 return open(buf
, O_WRONLY
|O_CREAT
|O_EXCL
, LOGFILE_MASK
);
391 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX
, O_WRONLY
|O_CREAT
|O_EXCL
,
393 #undef CRASHLOG_SUFFIX
394 #undef CRASHLOG_PREFIX
397 /* Note: the goal here is to use only async-signal-safe functions. */
399 zlog_signal(int signo
, const char *action
401 , siginfo_t
*siginfo
, void *program_counter
406 char buf
[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
408 char *msgstart
= buf
;
409 #define LOC s,buf+sizeof(buf)-s
414 s
= str_append(LOC
,zlog_proto_names
[zlog_default
->protocol
]);
419 s
= str_append(LOC
,"Received signal ");
420 s
= num_append(LOC
,signo
);
421 s
= str_append(LOC
," at ");
422 s
= num_append(LOC
,now
);
424 s
= str_append(LOC
," (si_addr 0x");
425 s
= hex_append(LOC
,(u_long
)(siginfo
->si_addr
));
428 s
= str_append(LOC
,", PC 0x");
429 s
= hex_append(LOC
,(u_long
)program_counter
);
431 s
= str_append(LOC
,"); ");
432 #else /* SA_SIGINFO */
433 s
= str_append(LOC
,"; ");
434 #endif /* SA_SIGINFO */
435 s
= str_append(LOC
,action
);
436 if (s
< buf
+sizeof(buf
))
439 /* N.B. implicit priority is most severe */
442 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
443 /* If no file logging configured, try to write to fallback log file. */
444 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
450 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
452 /* Remove trailing '\n' for monitor and syslog */
454 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
455 vty_log_fixed(buf
,s
-buf
);
456 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
457 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
461 zlog_backtrace_sigsafe(PRI
,
471 s
= str_append (LOC
, "no thread information available\n");
474 s
= str_append (LOC
, "in thread ");
475 s
= str_append (LOC
, thread_current
->funcname
);
476 s
= str_append (LOC
, " scheduled from ");
477 s
= str_append (LOC
, thread_current
->schedfrom
);
478 s
= str_append (LOC
, ":");
479 s
= num_append (LOC
, thread_current
->schedfrom_line
);
480 s
= str_append (LOC
, "\n");
483 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
484 /* If no file logging configured, try to write to fallback log file. */
491 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
493 /* Remove trailing '\n' for monitor and syslog */
495 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
496 vty_log_fixed(buf
,s
-buf
);
497 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
498 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
506 /* Log a backtrace using only async-signal-safe functions.
507 Needs to be enhanced to support syslog logging. */
509 zlog_backtrace_sigsafe(int priority
, void *program_counter
)
511 #ifdef HAVE_STACK_TRACE
512 static const char pclabel
[] = "Program counter: ";
516 char *s
, **bt
= NULL
;
517 #define LOC s,buf+sizeof(buf)-s
519 #ifdef HAVE_GLIBC_BACKTRACE
520 size
= backtrace(array
, array_size(array
));
521 if (size
<= 0 || (size_t)size
> array_size(array
))
525 if (program_counter) \
527 write_wrapper(FD, pclabel, sizeof(pclabel)-1); \
528 backtrace_symbols_fd(&program_counter, 1, FD); \
530 write_wrapper(FD, buf, s-buf); \
531 backtrace_symbols_fd(array, size, FD); \
533 #elif defined(HAVE_PRINTSTACK)
535 if (program_counter) \
536 write_wrapper((FD), pclabel, sizeof(pclabel)-1); \
537 write_wrapper((FD), buf, s-buf); \
540 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
543 s
= str_append(LOC
,"Backtrace for ");
544 s
= num_append(LOC
,size
);
545 s
= str_append(LOC
," stack frames:\n");
547 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
553 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
555 /* Remove trailing '\n' for monitor and syslog */
557 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
558 vty_log_fixed(buf
,s
-buf
);
559 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
560 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
563 #ifdef HAVE_GLIBC_BACKTRACE
564 bt
= backtrace_symbols(array
, size
);
566 /* Just print the function addresses. */
567 for (i
= 0; i
< size
; i
++)
571 s
= str_append(LOC
, bt
[i
]);
573 s
= str_append(LOC
,"[bt ");
574 s
= num_append(LOC
,i
);
575 s
= str_append(LOC
,"] 0x");
576 s
= hex_append(LOC
,(u_long
)(array
[i
]));
579 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
580 vty_log_fixed(buf
,s
-buf
);
581 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
582 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
590 #endif /* HAVE_STRACK_TRACE */
594 zlog_backtrace(int priority
)
596 #ifndef HAVE_GLIBC_BACKTRACE
597 zlog(NULL
, priority
, "No backtrace available on this platform.");
603 size
= backtrace(array
, array_size(array
));
604 if (size
<= 0 || (size_t)size
> array_size(array
))
606 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
607 "(valid range is between 1 and %lu)",
608 size
, (unsigned long)(array_size(array
)));
611 zlog(NULL
, priority
, "Backtrace for %d stack frames:", size
);
612 if (!(strings
= backtrace_symbols(array
, size
)))
614 zlog_err("Cannot get backtrace symbols (out of memory?)");
615 for (i
= 0; i
< size
; i
++)
616 zlog(NULL
, priority
, "[bt %d] %p",i
,array
[i
]);
620 for (i
= 0; i
< size
; i
++)
621 zlog(NULL
, priority
, "[bt %d] %s",i
,strings
[i
]);
624 #endif /* HAVE_GLIBC_BACKTRACE */
628 zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
632 va_start(args
, format
);
633 vzlog (zl
, priority
, format
, args
);
637 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
639 FUNCNAME(const char *format, ...) \
642 va_start(args, format); \
643 vzlog (NULL, PRIORITY, format, args); \
647 ZLOG_FUNC(zlog_err
, LOG_ERR
)
649 ZLOG_FUNC(zlog_warn
, LOG_WARNING
)
651 ZLOG_FUNC(zlog_info
, LOG_INFO
)
653 ZLOG_FUNC(zlog_notice
, LOG_NOTICE
)
655 ZLOG_FUNC(zlog_debug
, LOG_DEBUG
)
659 void zlog_thread_info (int log_level
)
662 zlog(NULL
, log_level
, "Current thread function %s, scheduled from "
663 "file %s, line %u", thread_current
->funcname
,
664 thread_current
->schedfrom
, thread_current
->schedfrom_line
);
666 zlog(NULL
, log_level
, "Current thread not known/applicable");
670 _zlog_assert_failed (const char *assertion
, const char *file
,
671 unsigned int line
, const char *function
)
673 /* Force fallback file logging? */
674 if (zlog_default
&& !zlog_default
->fp
&&
675 ((logfile_fd
= open_crashlog()) >= 0) &&
676 ((zlog_default
->fp
= fdopen(logfile_fd
, "w")) != NULL
))
677 zlog_default
->maxlvl
[ZLOG_DEST_FILE
] = LOG_ERR
;
678 zlog(NULL
, LOG_CRIT
, "Assertion `%s' failed in file %s, line %u, function %s",
679 assertion
,file
,line
,(function
? function
: "?"));
680 zlog_backtrace(LOG_CRIT
);
681 zlog_thread_info(LOG_CRIT
);
686 memory_oom (size_t size
, const char *name
)
688 zlog_err("out of memory: failed to allocate %zu bytes for %s"
689 "object", size
, name
);
690 zlog_backtrace(LOG_ERR
);
694 /* Open log stream */
696 openzlog (const char *progname
, zlog_proto_t protocol
, u_short instance
,
697 int syslog_flags
, int syslog_facility
)
702 zl
= XCALLOC(MTYPE_ZLOG
, sizeof (struct zlog
));
704 zl
->ident
= progname
;
705 zl
->protocol
= protocol
;
706 zl
->instance
= instance
;
707 zl
->facility
= syslog_facility
;
708 zl
->syslog_options
= syslog_flags
;
710 /* Set default logging levels. */
711 for (i
= 0; i
< array_size(zl
->maxlvl
); i
++)
712 zl
->maxlvl
[i
] = ZLOG_DISABLED
;
713 zl
->maxlvl
[ZLOG_DEST_MONITOR
] = LOG_DEBUG
;
714 zl
->default_lvl
= LOG_DEBUG
;
716 openlog (progname
, syslog_flags
, zl
->facility
);
722 closezlog (struct zlog
*zl
)
729 if (zl
->filename
!= NULL
)
730 XFREE(MTYPE_ZLOG
, zl
->filename
);
732 XFREE (MTYPE_ZLOG
, zl
);
735 /* Called from command.c. */
737 zlog_set_level (struct zlog
*zl
, zlog_dest_t dest
, int log_level
)
742 zl
->maxlvl
[dest
] = log_level
;
746 zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
)
751 /* There is opend file. */
752 zlog_reset_file (zl
);
754 /* Set default zl. */
759 oldumask
= umask (0777 & ~LOGFILE_MASK
);
760 fp
= fopen (filename
, "a");
766 zl
->filename
= XSTRDUP(MTYPE_ZLOG
, filename
);
767 zl
->maxlvl
[ZLOG_DEST_FILE
] = log_level
;
769 logfile_fd
= fileno(fp
);
774 /* Reset opend file. */
776 zlog_reset_file (struct zlog
*zl
)
785 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
788 XFREE(MTYPE_ZLOG
, zl
->filename
);
794 /* Reopen log file. */
796 zlog_rotate (struct zlog
*zl
)
807 level
= zl
->maxlvl
[ZLOG_DEST_FILE
];
808 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
815 oldumask
= umask (0777 & ~LOGFILE_MASK
);
816 zl
->fp
= fopen (zl
->filename
, "a");
821 zlog_err("Log rotate failed: cannot open file %s for append: %s",
822 zl
->filename
, safe_strerror(save_errno
));
825 logfile_fd
= fileno(zl
->fp
);
826 zl
->maxlvl
[ZLOG_DEST_FILE
] = level
;
832 /* Message lookup function. */
834 lookup (const struct message
*mes
, int key
)
836 const struct message
*pnt
;
838 for (pnt
= mes
; pnt
->key
!= 0; pnt
++)
845 /* Older/faster version of message lookup function, but requires caller to pass
846 * in the array size (instead of relying on a 0 key to terminate the search).
848 * The return value is the message string if found, or the 'none' pointer
849 * provided otherwise.
852 mes_lookup (const struct message
*meslist
, int max
, int index
,
853 const char *none
, const char *mesname
)
855 int pos
= index
- meslist
[0].key
;
857 /* first check for best case: index is in range and matches the key
858 * value in that slot.
859 * NB: key numbering might be offset from 0. E.g. protocol constants
862 if ((pos
>= 0) && (pos
< max
)
863 && (meslist
[pos
].key
== index
))
864 return meslist
[pos
].str
;
866 /* fall back to linear search */
870 for (i
= 0; i
< max
; i
++, meslist
++)
872 if (meslist
->key
== index
)
874 const char *str
= (meslist
->str
? meslist
->str
: none
);
876 zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
877 index
, str
, mesname
, i
, max
);
882 zlog_err("message index %d not found in %s (max is %d)", index
, mesname
, max
);
887 /* Wrapper around strerror to handle case where it returns NULL. */
889 safe_strerror(int errnum
)
891 const char *s
= strerror(errnum
);
892 return (s
!= NULL
) ? s
: "Unknown error";
895 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
896 static const struct zebra_desc_table command_types
[] = {
897 DESC_ENTRY (ZEBRA_INTERFACE_ADD
),
898 DESC_ENTRY (ZEBRA_INTERFACE_DELETE
),
899 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD
),
900 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE
),
901 DESC_ENTRY (ZEBRA_INTERFACE_UP
),
902 DESC_ENTRY (ZEBRA_INTERFACE_DOWN
),
903 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD
),
904 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE
),
905 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD
),
906 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE
),
907 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD
),
908 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE
),
909 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD
),
910 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
),
911 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD
),
912 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE
),
913 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE
),
914 DESC_ENTRY (ZEBRA_HELLO
),
915 DESC_ENTRY (ZEBRA_NEXTHOP_REGISTER
),
916 DESC_ENTRY (ZEBRA_NEXTHOP_UNREGISTER
),
917 DESC_ENTRY (ZEBRA_NEXTHOP_UPDATE
),
918 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
),
919 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
),
920 DESC_ENTRY (ZEBRA_INTERFACE_BFD_DEST_UPDATE
),
921 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_REGISTER
),
922 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_UNREGISTER
),
923 DESC_ENTRY (ZEBRA_IMPORT_CHECK_UPDATE
),
924 DESC_ENTRY (ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
),
925 DESC_ENTRY (ZEBRA_BFD_DEST_REGISTER
),
926 DESC_ENTRY (ZEBRA_BFD_DEST_DEREGISTER
),
927 DESC_ENTRY (ZEBRA_BFD_DEST_UPDATE
),
928 DESC_ENTRY (ZEBRA_BFD_DEST_REPLAY
),
929 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_ADD
),
930 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_DEL
),
931 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_ADD
),
932 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_DEL
),
933 DESC_ENTRY (ZEBRA_VRF_UNREGISTER
),
934 DESC_ENTRY (ZEBRA_VRF_ADD
),
935 DESC_ENTRY (ZEBRA_VRF_DELETE
),
936 DESC_ENTRY (ZEBRA_INTERFACE_VRF_UPDATE
),
937 DESC_ENTRY (ZEBRA_BFD_CLIENT_REGISTER
),
938 DESC_ENTRY (ZEBRA_INTERFACE_ENABLE_RADV
),
939 DESC_ENTRY (ZEBRA_INTERFACE_DISABLE_RADV
),
940 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB
),
944 static const struct zebra_desc_table unknown
= { 0, "unknown", '?' };
946 static const struct zebra_desc_table
*
947 zroute_lookup(u_int zroute
)
951 if (zroute
>= array_size(route_types
))
953 zlog_err("unknown zebra route type: %u", zroute
);
956 if (zroute
== route_types
[zroute
].type
)
957 return &route_types
[zroute
];
958 for (i
= 0; i
< array_size(route_types
); i
++)
960 if (zroute
== route_types
[i
].type
)
962 zlog_warn("internal error: route type table out of order "
963 "while searching for %u, please notify developers", zroute
);
964 return &route_types
[i
];
967 zlog_err("internal error: cannot find route type %u in table!", zroute
);
972 zebra_route_string(u_int zroute
)
974 return zroute_lookup(zroute
)->string
;
978 zebra_route_char(u_int zroute
)
980 return zroute_lookup(zroute
)->chr
;
984 zserv_command_string (unsigned int command
)
986 if (command
>= array_size(command_types
))
988 zlog_err ("unknown zserv command type: %u", command
);
989 return unknown
.string
;
991 return command_types
[command
].string
;
995 proto_name2num(const char *s
)
999 for (i
=0; i
<array_size(route_types
); ++i
)
1000 if (strcasecmp(s
, route_types
[i
].string
) == 0)
1001 return route_types
[i
].type
;
1006 proto_redistnum(int afi
, const char *s
)
1013 if (strncmp (s
, "k", 1) == 0)
1014 return ZEBRA_ROUTE_KERNEL
;
1015 else if (strncmp (s
, "c", 1) == 0)
1016 return ZEBRA_ROUTE_CONNECT
;
1017 else if (strncmp (s
, "s", 1) == 0)
1018 return ZEBRA_ROUTE_STATIC
;
1019 else if (strncmp (s
, "r", 1) == 0)
1020 return ZEBRA_ROUTE_RIP
;
1021 else if (strncmp (s
, "o", 1) == 0)
1022 return ZEBRA_ROUTE_OSPF
;
1023 else if (strncmp (s
, "i", 1) == 0)
1024 return ZEBRA_ROUTE_ISIS
;
1025 else if (strncmp (s
, "bg", 2) == 0)
1026 return ZEBRA_ROUTE_BGP
;
1027 else if (strncmp (s
, "ta", 2) == 0)
1028 return ZEBRA_ROUTE_TABLE
;
1032 if (strncmp (s
, "k", 1) == 0)
1033 return ZEBRA_ROUTE_KERNEL
;
1034 else if (strncmp (s
, "c", 1) == 0)
1035 return ZEBRA_ROUTE_CONNECT
;
1036 else if (strncmp (s
, "s", 1) == 0)
1037 return ZEBRA_ROUTE_STATIC
;
1038 else if (strncmp (s
, "r", 1) == 0)
1039 return ZEBRA_ROUTE_RIPNG
;
1040 else if (strncmp (s
, "o", 1) == 0)
1041 return ZEBRA_ROUTE_OSPF6
;
1042 else if (strncmp (s
, "i", 1) == 0)
1043 return ZEBRA_ROUTE_ISIS
;
1044 else if (strncmp (s
, "bg", 2) == 0)
1045 return ZEBRA_ROUTE_BGP
;
1046 else if (strncmp (s
, "ta", 2) == 0)
1047 return ZEBRA_ROUTE_TABLE
;
1053 zlog_hexdump (const void *mem
, unsigned int len
) {
1054 unsigned long i
= 0;
1056 unsigned int columns
= 8;
1057 char buf
[(len
* 4) + ((len
/4) * 20) + 30];
1060 for (i
= 0; i
< len
+ ((len
% columns
) ? (columns
- len
% columns
) : 0); i
++)
1063 if (i
% columns
== 0)
1064 s
+= sprintf(s
, "0x%016lx: ", (unsigned long)mem
+ i
);
1066 /* print hex data */
1068 s
+= sprintf(s
, "%02x ", 0xFF & ((const char*)mem
)[i
]);
1070 /* end of block, just aligning for ASCII dump */
1072 s
+= sprintf(s
, " ");
1074 /* print ASCII dump */
1075 if (i
% columns
== (columns
- 1))
1077 for (j
= i
- (columns
- 1); j
<= i
; j
++)
1079 if (j
>= len
) /* end of block, not really printing */
1080 s
+= sprintf(s
, " ");
1082 else if(isprint((int)((const char *)mem
)[j
])) /* printable char */
1083 s
+= sprintf(s
, "%c", 0xFF & ((const char *)mem
)[j
]);
1085 else /* other char */
1086 s
+= sprintf(s
, ".");
1088 s
+= sprintf(s
, "\n");
1091 zlog_debug("\n%s", buf
);