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 FRR_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
;
45 * This must be kept in the same order as the
48 const char *zlog_proto_names
[] =
66 const char *zlog_priority
[] =
82 * glibc has declared that the return value from write *must* not be
84 * gcc see's this problem and issues a warning for the line.
86 * Why is this a big deal you say? Because both of them are right
87 * and if you have -Werror enabled then all calls to write
88 * generate a build error and the build stops.
90 * clang has helpfully allowed this construct:
92 * to tell the compiler yeah I know it has a return value
93 * I don't care about it at this time.
94 * gcc doesn't have this ability.
96 * This code was written such that it didn't care about the
97 * return value from write. At this time do I want
98 * to go through and fix and test this code for correctness.
99 * So just wrapper the bad behavior and move on.
101 static void write_wrapper (int fd
, const void *buf
, size_t count
)
103 if (write (fd
, buf
, count
) <= 0)
109 /* For time string format. */
112 quagga_timestamp(int timestamp_precision
, char *buf
, size_t buflen
)
119 struct timeval clock
;
121 gettimeofday(&clock
, NULL
);
123 /* first, we update the cache if the time has changed */
124 if (cache
.last
!= clock
.tv_sec
)
127 cache
.last
= clock
.tv_sec
;
128 tm
= localtime(&cache
.last
);
129 cache
.len
= strftime(cache
.buf
, sizeof(cache
.buf
),
130 "%Y/%m/%d %H:%M:%S", tm
);
132 /* note: it's not worth caching the subsecond part, because
133 chances are that back-to-back calls are not sufficiently close together
134 for the clock not to have ticked forward */
136 if (buflen
> cache
.len
)
138 memcpy(buf
, cache
.buf
, cache
.len
);
139 if ((timestamp_precision
> 0) &&
140 (buflen
> cache
.len
+1+timestamp_precision
))
142 /* should we worry about locale issues? */
143 static const int divisor
[] = {0, 100000, 10000, 1000, 100, 10, 1};
145 char *p
= buf
+cache
.len
+1+(prec
= timestamp_precision
);
148 /* this is unlikely to happen, but protect anyway */
153 clock
.tv_usec
/= divisor
[prec
];
156 *p
-- = '0'+(clock
.tv_usec
% 10);
161 return cache
.len
+1+timestamp_precision
;
163 buf
[cache
.len
] = '\0';
171 /* Utility routine for current time printing. */
173 time_print(FILE *fp
, struct timestamp_control
*ctl
)
175 if (!ctl
->already_rendered
)
177 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
178 ctl
->already_rendered
= 1;
180 fprintf(fp
, "%s ", ctl
->buf
);
184 /* va_list version of zlog. */
186 vzlog (struct zlog
*zl
, int priority
, const char *format
, va_list args
)
189 int original_errno
= errno
;
190 struct timestamp_control tsctl
;
191 tsctl
.already_rendered
= 0;
193 /* If zlog is not specified, use default one. */
197 /* When zlog_default is also NULL, use stderr for logging. */
201 time_print(stderr
, &tsctl
);
202 fprintf (stderr
, "%s: ", "unknown");
203 vfprintf (stderr
, format
, args
);
204 fprintf (stderr
, "\n");
207 /* In this case we return at here. */
208 errno
= original_errno
;
211 tsctl
.precision
= zl
->timestamp_precision
;
214 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
218 vsyslog (priority
|zlog_default
->facility
, format
, ac
);
223 sprintf (proto_str
, "%s[%d]: ", zlog_proto_names
[zl
->protocol
], zl
->instance
);
225 sprintf (proto_str
, "%s: ", zlog_proto_names
[zl
->protocol
]);
228 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
231 time_print (zl
->fp
, &tsctl
);
232 if (zl
->record_priority
)
233 fprintf (zl
->fp
, "%s: ", zlog_priority
[priority
]);
234 fprintf (zl
->fp
, "%s", proto_str
);
236 vfprintf (zl
->fp
, format
, ac
);
238 fprintf (zl
->fp
, "\n");
243 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
246 time_print (stdout
, &tsctl
);
247 if (zl
->record_priority
)
248 fprintf (stdout
, "%s: ", zlog_priority
[priority
]);
249 fprintf (stdout
, "%s", proto_str
);
251 vfprintf (stdout
, format
, ac
);
253 fprintf (stdout
, "\n");
257 /* Terminal monitor. */
258 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
259 vty_log ((zl
->record_priority
? zlog_priority
[priority
] : NULL
),
260 proto_str
, format
, &tsctl
, args
);
262 errno
= original_errno
;
266 vzlog_test (struct zlog
*zl
, int priority
)
268 /* If zlog is not specified, use default one. */
272 /* When zlog_default is also NULL, use stderr for logging. */
279 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
285 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
291 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
296 /* Terminal monitor. */
297 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
304 str_append(char *dst
, int len
, const char *src
)
306 while ((len
-- > 0) && *src
)
312 num_append(char *s
, int len
, u_long x
)
318 return str_append(s
,len
,"0");
319 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
320 while (x
&& (t
> buf
))
325 return str_append(s
,len
,t
);
328 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
330 hex_append(char *s
, int len
, u_long x
)
336 return str_append(s
,len
,"0");
337 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
338 while (x
&& (t
> buf
))
341 *--t
= ((cc
< 10) ? ('0'+cc
) : ('a'+cc
-10));
344 return str_append(s
,len
,t
);
348 /* Needs to be enhanced to support Solaris. */
357 struct sockaddr_un addr
;
359 if ((fd
= socket(AF_UNIX
,SOCK_DGRAM
,0)) < 0)
361 addr
.sun_family
= AF_UNIX
;
363 #define SYSLOG_SOCKET_PATH _PATH_LOG
365 #define SYSLOG_SOCKET_PATH "/dev/log"
367 s
= str_append(addr
.sun_path
,sizeof(addr
.sun_path
),SYSLOG_SOCKET_PATH
);
368 #undef SYSLOG_SOCKET_PATH
370 if (connect(fd
,(struct sockaddr
*)&addr
,sizeof(addr
)) < 0)
380 syslog_sigsafe(int priority
, const char *msg
, size_t msglen
)
382 static int syslog_fd
= -1;
383 char buf
[sizeof("<1234567890>ripngd[1234567890]: ")+msglen
+50];
386 if ((syslog_fd
< 0) && ((syslog_fd
= syslog_connect()) < 0))
389 #define LOC s,buf+sizeof(buf)-s
391 s
= str_append(LOC
,"<");
392 s
= num_append(LOC
,priority
);
393 s
= str_append(LOC
,">");
394 /* forget about the timestamp, too difficult in a signal handler */
395 s
= str_append(LOC
,zlog_default
->ident
);
396 if (zlog_default
->syslog_options
& LOG_PID
)
398 s
= str_append(LOC
,"[");
399 s
= num_append(LOC
,getpid());
400 s
= str_append(LOC
,"]");
402 s
= str_append(LOC
,": ");
403 s
= str_append(LOC
,msg
);
404 write_wrapper (syslog_fd
,buf
,s
-buf
);
411 #define CRASHLOG_PREFIX "/var/tmp/quagga."
412 #define CRASHLOG_SUFFIX "crashlog"
413 if (zlog_default
&& zlog_default
->ident
)
415 /* Avoid strlen since it is not async-signal-safe. */
419 for (p
= zlog_default
->ident
, ilen
= 0; *p
; p
++)
422 char buf
[sizeof(CRASHLOG_PREFIX
)+ilen
+sizeof(CRASHLOG_SUFFIX
)+3];
424 #define LOC s,buf+sizeof(buf)-s
425 s
= str_append(LOC
, CRASHLOG_PREFIX
);
426 s
= str_append(LOC
, zlog_default
->ident
);
427 s
= str_append(LOC
, ".");
428 s
= str_append(LOC
, CRASHLOG_SUFFIX
);
431 return open(buf
, O_WRONLY
|O_CREAT
|O_EXCL
, LOGFILE_MASK
);
434 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX
, O_WRONLY
|O_CREAT
|O_EXCL
,
436 #undef CRASHLOG_SUFFIX
437 #undef CRASHLOG_PREFIX
440 /* Note: the goal here is to use only async-signal-safe functions. */
442 zlog_signal(int signo
, const char *action
444 , siginfo_t
*siginfo
, void *program_counter
449 char buf
[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
451 char *msgstart
= buf
;
452 #define LOC s,buf+sizeof(buf)-s
457 s
= str_append(LOC
,zlog_proto_names
[zlog_default
->protocol
]);
462 s
= str_append(LOC
,"Received signal ");
463 s
= num_append(LOC
,signo
);
464 s
= str_append(LOC
," at ");
465 s
= num_append(LOC
,now
);
467 s
= str_append(LOC
," (si_addr 0x");
468 s
= hex_append(LOC
,(u_long
)(siginfo
->si_addr
));
471 s
= str_append(LOC
,", PC 0x");
472 s
= hex_append(LOC
,(u_long
)program_counter
);
474 s
= str_append(LOC
,"); ");
475 #else /* SA_SIGINFO */
476 s
= str_append(LOC
,"; ");
477 #endif /* SA_SIGINFO */
478 s
= str_append(LOC
,action
);
479 if (s
< buf
+sizeof(buf
))
482 /* N.B. implicit priority is most severe */
485 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
486 /* If no file logging configured, try to write to fallback log file. */
487 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
493 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
495 /* Remove trailing '\n' for monitor and syslog */
497 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
498 vty_log_fixed(buf
,s
-buf
);
499 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
500 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
504 zlog_backtrace_sigsafe(PRI
,
514 s
= str_append (LOC
, "no thread information available\n");
517 s
= str_append (LOC
, "in thread ");
518 s
= str_append (LOC
, thread_current
->funcname
);
519 s
= str_append (LOC
, " scheduled from ");
520 s
= str_append (LOC
, thread_current
->schedfrom
);
521 s
= str_append (LOC
, ":");
522 s
= num_append (LOC
, thread_current
->schedfrom_line
);
523 s
= str_append (LOC
, "\n");
526 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
527 /* If no file logging configured, try to write to fallback log file. */
534 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
536 /* Remove trailing '\n' for monitor and syslog */
538 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
539 vty_log_fixed(buf
,s
-buf
);
540 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
541 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
549 /* Log a backtrace using only async-signal-safe functions.
550 Needs to be enhanced to support syslog logging. */
552 zlog_backtrace_sigsafe(int priority
, void *program_counter
)
554 #ifdef HAVE_STACK_TRACE
555 static const char pclabel
[] = "Program counter: ";
559 char *s
, **bt
= NULL
;
560 #define LOC s,buf+sizeof(buf)-s
562 #ifdef HAVE_GLIBC_BACKTRACE
563 size
= backtrace(array
, array_size(array
));
564 if (size
<= 0 || (size_t)size
> array_size(array
))
568 if (program_counter) \
570 write_wrapper(FD, pclabel, sizeof(pclabel)-1); \
571 backtrace_symbols_fd(&program_counter, 1, FD); \
573 write_wrapper(FD, buf, s-buf); \
574 backtrace_symbols_fd(array, size, FD); \
576 #elif defined(HAVE_PRINTSTACK)
578 if (program_counter) \
579 write_wrapper((FD), pclabel, sizeof(pclabel)-1); \
580 write_wrapper((FD), buf, s-buf); \
583 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
586 s
= str_append(LOC
,"Backtrace for ");
587 s
= num_append(LOC
,size
);
588 s
= str_append(LOC
," stack frames:\n");
590 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
596 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
598 /* Remove trailing '\n' for monitor and syslog */
600 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
601 vty_log_fixed(buf
,s
-buf
);
602 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
603 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
606 #ifdef HAVE_GLIBC_BACKTRACE
607 bt
= backtrace_symbols(array
, size
);
609 /* Just print the function addresses. */
610 for (i
= 0; i
< size
; i
++)
614 s
= str_append(LOC
, bt
[i
]);
616 s
= str_append(LOC
,"[bt ");
617 s
= num_append(LOC
,i
);
618 s
= str_append(LOC
,"] 0x");
619 s
= hex_append(LOC
,(u_long
)(array
[i
]));
622 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
623 vty_log_fixed(buf
,s
-buf
);
624 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
625 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
633 #endif /* HAVE_STRACK_TRACE */
637 zlog_backtrace(int priority
)
639 #ifndef HAVE_GLIBC_BACKTRACE
640 zlog(NULL
, priority
, "No backtrace available on this platform.");
646 size
= backtrace(array
, array_size(array
));
647 if (size
<= 0 || (size_t)size
> array_size(array
))
649 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
650 "(valid range is between 1 and %lu)",
651 size
, (unsigned long)(array_size(array
)));
654 zlog(NULL
, priority
, "Backtrace for %d stack frames:", size
);
655 if (!(strings
= backtrace_symbols(array
, size
)))
657 zlog_err("Cannot get backtrace symbols (out of memory?)");
658 for (i
= 0; i
< size
; i
++)
659 zlog(NULL
, priority
, "[bt %d] %p",i
,array
[i
]);
663 for (i
= 0; i
< size
; i
++)
664 zlog(NULL
, priority
, "[bt %d] %s",i
,strings
[i
]);
667 #endif /* HAVE_GLIBC_BACKTRACE */
671 zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
675 va_start(args
, format
);
676 vzlog (zl
, priority
, format
, args
);
680 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
682 FUNCNAME(const char *format, ...) \
685 va_start(args, format); \
686 vzlog (NULL, PRIORITY, format, args); \
690 ZLOG_FUNC(zlog_err
, LOG_ERR
)
692 ZLOG_FUNC(zlog_warn
, LOG_WARNING
)
694 ZLOG_FUNC(zlog_info
, LOG_INFO
)
696 ZLOG_FUNC(zlog_notice
, LOG_NOTICE
)
698 ZLOG_FUNC(zlog_debug
, LOG_DEBUG
)
702 void zlog_thread_info (int log_level
)
705 zlog(NULL
, log_level
, "Current thread function %s, scheduled from "
706 "file %s, line %u", thread_current
->funcname
,
707 thread_current
->schedfrom
, thread_current
->schedfrom_line
);
709 zlog(NULL
, log_level
, "Current thread not known/applicable");
713 _zlog_assert_failed (const char *assertion
, const char *file
,
714 unsigned int line
, const char *function
)
716 /* Force fallback file logging? */
717 if (zlog_default
&& !zlog_default
->fp
&&
718 ((logfile_fd
= open_crashlog()) >= 0) &&
719 ((zlog_default
->fp
= fdopen(logfile_fd
, "w")) != NULL
))
720 zlog_default
->maxlvl
[ZLOG_DEST_FILE
] = LOG_ERR
;
721 zlog(NULL
, LOG_CRIT
, "Assertion `%s' failed in file %s, line %u, function %s",
722 assertion
,file
,line
,(function
? function
: "?"));
723 zlog_backtrace(LOG_CRIT
);
724 zlog_thread_info(LOG_CRIT
);
725 log_memstats_stderr ("log");
730 memory_oom (size_t size
, const char *name
)
732 zlog_err("out of memory: failed to allocate %zu bytes for %s"
733 "object", size
, name
);
734 zlog_backtrace(LOG_ERR
);
738 /* Open log stream */
740 openzlog (const char *progname
, zlog_proto_t protocol
, u_short instance
,
741 int syslog_flags
, int syslog_facility
)
746 zl
= XCALLOC(MTYPE_ZLOG
, sizeof (struct zlog
));
748 zl
->ident
= progname
;
749 zl
->protocol
= protocol
;
750 zl
->instance
= instance
;
751 zl
->facility
= syslog_facility
;
752 zl
->syslog_options
= syslog_flags
;
754 /* Set default logging levels. */
755 for (i
= 0; i
< array_size(zl
->maxlvl
); i
++)
756 zl
->maxlvl
[i
] = ZLOG_DISABLED
;
757 zl
->maxlvl
[ZLOG_DEST_MONITOR
] = LOG_DEBUG
;
758 zl
->default_lvl
= LOG_DEBUG
;
760 openlog (progname
, syslog_flags
, zl
->facility
);
766 closezlog (struct zlog
*zl
)
773 if (zl
->filename
!= NULL
)
774 XFREE(MTYPE_ZLOG
, zl
->filename
);
776 XFREE (MTYPE_ZLOG
, zl
);
779 /* Called from command.c. */
781 zlog_set_level (struct zlog
*zl
, zlog_dest_t dest
, int log_level
)
786 zl
->maxlvl
[dest
] = log_level
;
790 zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
)
795 /* There is opend file. */
796 zlog_reset_file (zl
);
798 /* Set default zl. */
803 oldumask
= umask (0777 & ~LOGFILE_MASK
);
804 fp
= fopen (filename
, "a");
810 zl
->filename
= XSTRDUP(MTYPE_ZLOG
, filename
);
811 zl
->maxlvl
[ZLOG_DEST_FILE
] = log_level
;
813 logfile_fd
= fileno(fp
);
818 /* Reset opend file. */
820 zlog_reset_file (struct zlog
*zl
)
829 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
832 XFREE(MTYPE_ZLOG
, zl
->filename
);
838 /* Reopen log file. */
840 zlog_rotate (struct zlog
*zl
)
851 level
= zl
->maxlvl
[ZLOG_DEST_FILE
];
852 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
859 oldumask
= umask (0777 & ~LOGFILE_MASK
);
860 zl
->fp
= fopen (zl
->filename
, "a");
865 zlog_err("Log rotate failed: cannot open file %s for append: %s",
866 zl
->filename
, safe_strerror(save_errno
));
869 logfile_fd
= fileno(zl
->fp
);
870 zl
->maxlvl
[ZLOG_DEST_FILE
] = level
;
876 /* Message lookup function. */
878 lookup (const struct message
*mes
, int key
)
880 const struct message
*pnt
;
882 for (pnt
= mes
; pnt
->key
!= 0; pnt
++)
889 /* Older/faster version of message lookup function, but requires caller to pass
890 * in the array size (instead of relying on a 0 key to terminate the search).
892 * The return value is the message string if found, or the 'none' pointer
893 * provided otherwise.
896 mes_lookup (const struct message
*meslist
, int max
, int index
,
897 const char *none
, const char *mesname
)
899 int pos
= index
- meslist
[0].key
;
901 /* first check for best case: index is in range and matches the key
902 * value in that slot.
903 * NB: key numbering might be offset from 0. E.g. protocol constants
906 if ((pos
>= 0) && (pos
< max
)
907 && (meslist
[pos
].key
== index
))
908 return meslist
[pos
].str
;
910 /* fall back to linear search */
914 for (i
= 0; i
< max
; i
++, meslist
++)
916 if (meslist
->key
== index
)
918 const char *str
= (meslist
->str
? meslist
->str
: none
);
920 zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
921 index
, str
, mesname
, i
, max
);
926 zlog_err("message index %d not found in %s (max is %d)", index
, mesname
, max
);
931 /* Wrapper around strerror to handle case where it returns NULL. */
933 safe_strerror(int errnum
)
935 const char *s
= strerror(errnum
);
936 return (s
!= NULL
) ? s
: "Unknown error";
939 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
940 static const struct zebra_desc_table command_types
[] = {
941 DESC_ENTRY (ZEBRA_INTERFACE_ADD
),
942 DESC_ENTRY (ZEBRA_INTERFACE_DELETE
),
943 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD
),
944 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE
),
945 DESC_ENTRY (ZEBRA_INTERFACE_UP
),
946 DESC_ENTRY (ZEBRA_INTERFACE_DOWN
),
947 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD
),
948 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE
),
949 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD
),
950 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE
),
951 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD
),
952 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE
),
953 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD
),
954 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
),
955 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD
),
956 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE
),
957 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE
),
958 DESC_ENTRY (ZEBRA_HELLO
),
959 DESC_ENTRY (ZEBRA_NEXTHOP_REGISTER
),
960 DESC_ENTRY (ZEBRA_NEXTHOP_UNREGISTER
),
961 DESC_ENTRY (ZEBRA_NEXTHOP_UPDATE
),
962 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
),
963 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
),
964 DESC_ENTRY (ZEBRA_INTERFACE_BFD_DEST_UPDATE
),
965 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_REGISTER
),
966 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_UNREGISTER
),
967 DESC_ENTRY (ZEBRA_IMPORT_CHECK_UPDATE
),
968 DESC_ENTRY (ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
),
969 DESC_ENTRY (ZEBRA_BFD_DEST_REGISTER
),
970 DESC_ENTRY (ZEBRA_BFD_DEST_DEREGISTER
),
971 DESC_ENTRY (ZEBRA_BFD_DEST_UPDATE
),
972 DESC_ENTRY (ZEBRA_BFD_DEST_REPLAY
),
973 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_ADD
),
974 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_DEL
),
975 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_ADD
),
976 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_DEL
),
977 DESC_ENTRY (ZEBRA_VRF_UNREGISTER
),
978 DESC_ENTRY (ZEBRA_VRF_ADD
),
979 DESC_ENTRY (ZEBRA_VRF_DELETE
),
980 DESC_ENTRY (ZEBRA_INTERFACE_VRF_UPDATE
),
981 DESC_ENTRY (ZEBRA_BFD_CLIENT_REGISTER
),
982 DESC_ENTRY (ZEBRA_INTERFACE_ENABLE_RADV
),
983 DESC_ENTRY (ZEBRA_INTERFACE_DISABLE_RADV
),
984 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB
),
985 DESC_ENTRY (ZEBRA_MPLS_LABELS_ADD
),
986 DESC_ENTRY (ZEBRA_MPLS_LABELS_DELETE
),
987 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_ADD
),
988 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_DELETE
),
989 DESC_ENTRY (ZEBRA_IPV6_NEXTHOP_ADD
),
990 DESC_ENTRY (ZEBRA_IPV6_NEXTHOP_DELETE
),
991 DESC_ENTRY (ZEBRA_IPMR_ROUTE_STATS
),
995 static const struct zebra_desc_table unknown
= { 0, "unknown", '?' };
997 static const struct zebra_desc_table
*
998 zroute_lookup(u_int zroute
)
1002 if (zroute
>= array_size(route_types
))
1004 zlog_err("unknown zebra route type: %u", zroute
);
1007 if (zroute
== route_types
[zroute
].type
)
1008 return &route_types
[zroute
];
1009 for (i
= 0; i
< array_size(route_types
); i
++)
1011 if (zroute
== route_types
[i
].type
)
1013 zlog_warn("internal error: route type table out of order "
1014 "while searching for %u, please notify developers", zroute
);
1015 return &route_types
[i
];
1018 zlog_err("internal error: cannot find route type %u in table!", zroute
);
1023 zebra_route_string(u_int zroute
)
1025 return zroute_lookup(zroute
)->string
;
1029 zebra_route_char(u_int zroute
)
1031 return zroute_lookup(zroute
)->chr
;
1035 zserv_command_string (unsigned int command
)
1037 if (command
>= array_size(command_types
))
1039 zlog_err ("unknown zserv command type: %u", command
);
1040 return unknown
.string
;
1042 return command_types
[command
].string
;
1046 proto_name2num(const char *s
)
1050 for (i
=0; i
<array_size(route_types
); ++i
)
1051 if (strcasecmp(s
, route_types
[i
].string
) == 0)
1052 return route_types
[i
].type
;
1057 proto_redistnum(int afi
, const char *s
)
1064 if (strmatch (s
, "kernel"))
1065 return ZEBRA_ROUTE_KERNEL
;
1066 else if (strmatch (s
, "connected"))
1067 return ZEBRA_ROUTE_CONNECT
;
1068 else if (strmatch (s
, "static"))
1069 return ZEBRA_ROUTE_STATIC
;
1070 else if (strmatch (s
, "rip"))
1071 return ZEBRA_ROUTE_RIP
;
1072 else if (strmatch (s
, "ospf"))
1073 return ZEBRA_ROUTE_OSPF
;
1074 else if (strmatch (s
, "isis"))
1075 return ZEBRA_ROUTE_ISIS
;
1076 else if (strmatch (s
, "bgp"))
1077 return ZEBRA_ROUTE_BGP
;
1078 else if (strmatch (s
, "table"))
1079 return ZEBRA_ROUTE_TABLE
;
1080 else if (strmatch (s
, "vnc"))
1081 return ZEBRA_ROUTE_VNC
;
1082 else if (strmatch (s
, "vnc-direct"))
1083 return ZEBRA_ROUTE_VNC_DIRECT
;
1087 if (strmatch (s
, "kernel"))
1088 return ZEBRA_ROUTE_KERNEL
;
1089 else if (strmatch (s
, "connected"))
1090 return ZEBRA_ROUTE_CONNECT
;
1091 else if (strmatch (s
, "static"))
1092 return ZEBRA_ROUTE_STATIC
;
1093 else if (strmatch (s
, "ripng"))
1094 return ZEBRA_ROUTE_RIPNG
;
1095 else if (strmatch (s
, "ospf6"))
1096 return ZEBRA_ROUTE_OSPF6
;
1097 else if (strmatch (s
, "isis"))
1098 return ZEBRA_ROUTE_ISIS
;
1099 else if (strmatch (s
, "bgp"))
1100 return ZEBRA_ROUTE_BGP
;
1101 else if (strmatch (s
, "table"))
1102 return ZEBRA_ROUTE_TABLE
;
1103 else if (strmatch (s
, "vnc"))
1104 return ZEBRA_ROUTE_VNC
;
1105 else if (strmatch (s
, "vnc-direct"))
1106 return ZEBRA_ROUTE_VNC_DIRECT
;
1112 zlog_hexdump (const void *mem
, unsigned int len
) {
1113 unsigned long i
= 0;
1115 unsigned int columns
= 8;
1116 char buf
[(len
* 4) + ((len
/4) * 20) + 30];
1119 for (i
= 0; i
< len
+ ((len
% columns
) ? (columns
- len
% columns
) : 0); i
++)
1122 if (i
% columns
== 0)
1123 s
+= sprintf(s
, "0x%016lx: ", (unsigned long)mem
+ i
);
1125 /* print hex data */
1127 s
+= sprintf(s
, "%02x ", 0xFF & ((const char*)mem
)[i
]);
1129 /* end of block, just aligning for ASCII dump */
1131 s
+= sprintf(s
, " ");
1133 /* print ASCII dump */
1134 if (i
% columns
== (columns
- 1))
1136 for (j
= i
- (columns
- 1); j
<= i
; j
++)
1138 if (j
>= len
) /* end of block, not really printing */
1139 s
+= sprintf(s
, " ");
1141 else if(isprint((int)((const char *)mem
)[j
])) /* printable char */
1142 s
+= sprintf(s
, "%c", 0xFF & ((const char *)mem
)[j
]);
1144 else /* other char */
1145 s
+= sprintf(s
, ".");
1147 s
+= sprintf(s
, "\n");
1150 zlog_debug("\n%s", buf
);