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
[] =
58 const char *zlog_priority
[] =
74 * glibc has declared that the return value from write *must* not be
76 * gcc see's this problem and issues a warning for the line.
78 * Why is this a big deal you say? Because both of them are right
79 * and if you have -Werror enabled then all calls to write
80 * generate a build error and the build stops.
82 * clang has helpfully allowed this construct:
84 * to tell the compiler yeah I know it has a return value
85 * I don't care about it at this time.
86 * gcc doesn't have this ability.
88 * This code was written such that it didn't care about the
89 * return value from write. At this time do I want
90 * to go through and fix and test this code for correctness.
91 * So just wrapper the bad behavior and move on.
93 static void write_wrapper (int fd
, const void *buf
, size_t count
)
95 if (write (fd
, buf
, count
) <= 0)
101 /* For time string format. */
104 quagga_timestamp(int timestamp_precision
, char *buf
, size_t buflen
)
111 struct timeval clock
;
113 /* would it be sufficient to use global 'recent_time' here? I fear not... */
114 gettimeofday(&clock
, NULL
);
116 /* first, we update the cache if the time has changed */
117 if (cache
.last
!= clock
.tv_sec
)
120 cache
.last
= clock
.tv_sec
;
121 tm
= localtime(&cache
.last
);
122 cache
.len
= strftime(cache
.buf
, sizeof(cache
.buf
),
123 "%Y/%m/%d %H:%M:%S", tm
);
125 /* note: it's not worth caching the subsecond part, because
126 chances are that back-to-back calls are not sufficiently close together
127 for the clock not to have ticked forward */
129 if (buflen
> cache
.len
)
131 memcpy(buf
, cache
.buf
, cache
.len
);
132 if ((timestamp_precision
> 0) &&
133 (buflen
> cache
.len
+1+timestamp_precision
))
135 /* should we worry about locale issues? */
136 static const int divisor
[] = {0, 100000, 10000, 1000, 100, 10, 1};
138 char *p
= buf
+cache
.len
+1+(prec
= timestamp_precision
);
141 /* this is unlikely to happen, but protect anyway */
146 clock
.tv_usec
/= divisor
[prec
];
149 *p
-- = '0'+(clock
.tv_usec
% 10);
154 return cache
.len
+1+timestamp_precision
;
156 buf
[cache
.len
] = '\0';
164 /* Utility routine for current time printing. */
166 time_print(FILE *fp
, struct timestamp_control
*ctl
)
168 if (!ctl
->already_rendered
)
170 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
171 ctl
->already_rendered
= 1;
173 fprintf(fp
, "%s ", ctl
->buf
);
177 /* va_list version of zlog. */
179 vzlog (struct zlog
*zl
, int priority
, const char *format
, va_list args
)
182 int original_errno
= errno
;
183 struct timestamp_control tsctl
;
184 tsctl
.already_rendered
= 0;
186 /* If zlog is not specified, use default one. */
190 /* When zlog_default is also NULL, use stderr for logging. */
194 time_print(stderr
, &tsctl
);
195 fprintf (stderr
, "%s: ", "unknown");
196 vfprintf (stderr
, format
, args
);
197 fprintf (stderr
, "\n");
200 /* In this case we return at here. */
201 errno
= original_errno
;
204 tsctl
.precision
= zl
->timestamp_precision
;
207 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
211 vsyslog (priority
|zlog_default
->facility
, format
, ac
);
216 sprintf (proto_str
, "%s[%d]: ", zlog_proto_names
[zl
->protocol
], zl
->instance
);
218 sprintf (proto_str
, "%s: ", zlog_proto_names
[zl
->protocol
]);
221 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
224 time_print (zl
->fp
, &tsctl
);
225 if (zl
->record_priority
)
226 fprintf (zl
->fp
, "%s: ", zlog_priority
[priority
]);
227 fprintf (zl
->fp
, "%s", proto_str
);
229 vfprintf (zl
->fp
, format
, ac
);
231 fprintf (zl
->fp
, "\n");
236 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
239 time_print (stdout
, &tsctl
);
240 if (zl
->record_priority
)
241 fprintf (stdout
, "%s: ", zlog_priority
[priority
]);
242 fprintf (stdout
, "%s", proto_str
);
244 vfprintf (stdout
, format
, ac
);
246 fprintf (stdout
, "\n");
250 /* Terminal monitor. */
251 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
252 vty_log ((zl
->record_priority
? zlog_priority
[priority
] : NULL
),
253 proto_str
, format
, &tsctl
, args
);
255 errno
= original_errno
;
259 str_append(char *dst
, int len
, const char *src
)
261 while ((len
-- > 0) && *src
)
267 num_append(char *s
, int len
, u_long x
)
273 return str_append(s
,len
,"0");
274 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
275 while (x
&& (t
> buf
))
280 return str_append(s
,len
,t
);
283 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
285 hex_append(char *s
, int len
, u_long x
)
291 return str_append(s
,len
,"0");
292 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
293 while (x
&& (t
> buf
))
296 *--t
= ((cc
< 10) ? ('0'+cc
) : ('a'+cc
-10));
299 return str_append(s
,len
,t
);
303 /* Needs to be enhanced to support Solaris. */
312 struct sockaddr_un addr
;
314 if ((fd
= socket(AF_UNIX
,SOCK_DGRAM
,0)) < 0)
316 addr
.sun_family
= AF_UNIX
;
318 #define SYSLOG_SOCKET_PATH _PATH_LOG
320 #define SYSLOG_SOCKET_PATH "/dev/log"
322 s
= str_append(addr
.sun_path
,sizeof(addr
.sun_path
),SYSLOG_SOCKET_PATH
);
323 #undef SYSLOG_SOCKET_PATH
325 if (connect(fd
,(struct sockaddr
*)&addr
,sizeof(addr
)) < 0)
335 syslog_sigsafe(int priority
, const char *msg
, size_t msglen
)
337 static int syslog_fd
= -1;
338 char buf
[sizeof("<1234567890>ripngd[1234567890]: ")+msglen
+50];
341 if ((syslog_fd
< 0) && ((syslog_fd
= syslog_connect()) < 0))
344 #define LOC s,buf+sizeof(buf)-s
346 s
= str_append(LOC
,"<");
347 s
= num_append(LOC
,priority
);
348 s
= str_append(LOC
,">");
349 /* forget about the timestamp, too difficult in a signal handler */
350 s
= str_append(LOC
,zlog_default
->ident
);
351 if (zlog_default
->syslog_options
& LOG_PID
)
353 s
= str_append(LOC
,"[");
354 s
= num_append(LOC
,getpid());
355 s
= str_append(LOC
,"]");
357 s
= str_append(LOC
,": ");
358 s
= str_append(LOC
,msg
);
359 write_wrapper (syslog_fd
,buf
,s
-buf
);
366 #define CRASHLOG_PREFIX "/var/tmp/quagga."
367 #define CRASHLOG_SUFFIX "crashlog"
368 if (zlog_default
&& zlog_default
->ident
)
370 /* Avoid strlen since it is not async-signal-safe. */
374 for (p
= zlog_default
->ident
, ilen
= 0; *p
; p
++)
377 char buf
[sizeof(CRASHLOG_PREFIX
)+ilen
+sizeof(CRASHLOG_SUFFIX
)+3];
379 #define LOC s,buf+sizeof(buf)-s
380 s
= str_append(LOC
, CRASHLOG_PREFIX
);
381 s
= str_append(LOC
, zlog_default
->ident
);
382 s
= str_append(LOC
, ".");
383 s
= str_append(LOC
, CRASHLOG_SUFFIX
);
386 return open(buf
, O_WRONLY
|O_CREAT
|O_EXCL
, LOGFILE_MASK
);
389 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX
, O_WRONLY
|O_CREAT
|O_EXCL
,
391 #undef CRASHLOG_SUFFIX
392 #undef CRASHLOG_PREFIX
395 /* Note: the goal here is to use only async-signal-safe functions. */
397 zlog_signal(int signo
, const char *action
399 , siginfo_t
*siginfo
, void *program_counter
404 char buf
[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
406 char *msgstart
= buf
;
407 #define LOC s,buf+sizeof(buf)-s
412 s
= str_append(LOC
,zlog_proto_names
[zlog_default
->protocol
]);
417 s
= str_append(LOC
,"Received signal ");
418 s
= num_append(LOC
,signo
);
419 s
= str_append(LOC
," at ");
420 s
= num_append(LOC
,now
);
422 s
= str_append(LOC
," (si_addr 0x");
423 s
= hex_append(LOC
,(u_long
)(siginfo
->si_addr
));
426 s
= str_append(LOC
,", PC 0x");
427 s
= hex_append(LOC
,(u_long
)program_counter
);
429 s
= str_append(LOC
,"); ");
430 #else /* SA_SIGINFO */
431 s
= str_append(LOC
,"; ");
432 #endif /* SA_SIGINFO */
433 s
= str_append(LOC
,action
);
434 if (s
< buf
+sizeof(buf
))
437 /* N.B. implicit priority is most severe */
440 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
441 /* If no file logging configured, try to write to fallback log file. */
442 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
448 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
450 /* Remove trailing '\n' for monitor and syslog */
452 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
453 vty_log_fixed(buf
,s
-buf
);
454 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
455 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
459 zlog_backtrace_sigsafe(PRI
,
469 s
= str_append (LOC
, "no thread information available\n");
472 s
= str_append (LOC
, "in thread ");
473 s
= str_append (LOC
, thread_current
->funcname
);
474 s
= str_append (LOC
, " scheduled from ");
475 s
= str_append (LOC
, thread_current
->schedfrom
);
476 s
= str_append (LOC
, ":");
477 s
= num_append (LOC
, thread_current
->schedfrom_line
);
478 s
= str_append (LOC
, "\n");
481 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
482 /* If no file logging configured, try to write to fallback log file. */
489 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
491 /* Remove trailing '\n' for monitor and syslog */
493 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
494 vty_log_fixed(buf
,s
-buf
);
495 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
496 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
504 /* Log a backtrace using only async-signal-safe functions.
505 Needs to be enhanced to support syslog logging. */
507 zlog_backtrace_sigsafe(int priority
, void *program_counter
)
509 #ifdef HAVE_STACK_TRACE
510 static const char pclabel
[] = "Program counter: ";
514 char *s
, **bt
= NULL
;
515 #define LOC s,buf+sizeof(buf)-s
517 #ifdef HAVE_GLIBC_BACKTRACE
518 size
= backtrace(array
, array_size(array
));
519 if (size
<= 0 || (size_t)size
> array_size(array
))
523 if (program_counter) \
525 write_wrapper(FD, pclabel, sizeof(pclabel)-1); \
526 backtrace_symbols_fd(&program_counter, 1, FD); \
528 write_wrapper(FD, buf, s-buf); \
529 backtrace_symbols_fd(array, size, FD); \
531 #elif defined(HAVE_PRINTSTACK)
533 if (program_counter) \
534 write_wrapper((FD), pclabel, sizeof(pclabel)-1); \
535 write_wrapper((FD), buf, s-buf); \
538 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
541 s
= str_append(LOC
,"Backtrace for ");
542 s
= num_append(LOC
,size
);
543 s
= str_append(LOC
," stack frames:\n");
545 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
551 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
553 /* Remove trailing '\n' for monitor and syslog */
555 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
556 vty_log_fixed(buf
,s
-buf
);
557 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
558 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
561 #ifdef HAVE_GLIBC_BACKTRACE
562 bt
= backtrace_symbols(array
, size
);
564 /* Just print the function addresses. */
565 for (i
= 0; i
< size
; i
++)
569 s
= str_append(LOC
, bt
[i
]);
571 s
= str_append(LOC
,"[bt ");
572 s
= num_append(LOC
,i
);
573 s
= str_append(LOC
,"] 0x");
574 s
= hex_append(LOC
,(u_long
)(array
[i
]));
577 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
578 vty_log_fixed(buf
,s
-buf
);
579 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
580 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
588 #endif /* HAVE_STRACK_TRACE */
592 zlog_backtrace(int priority
)
594 #ifndef HAVE_GLIBC_BACKTRACE
595 zlog(NULL
, priority
, "No backtrace available on this platform.");
601 size
= backtrace(array
, array_size(array
));
602 if (size
<= 0 || (size_t)size
> array_size(array
))
604 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
605 "(valid range is between 1 and %lu)",
606 size
, (unsigned long)(array_size(array
)));
609 zlog(NULL
, priority
, "Backtrace for %d stack frames:", size
);
610 if (!(strings
= backtrace_symbols(array
, size
)))
612 zlog_err("Cannot get backtrace symbols (out of memory?)");
613 for (i
= 0; i
< size
; i
++)
614 zlog(NULL
, priority
, "[bt %d] %p",i
,array
[i
]);
618 for (i
= 0; i
< size
; i
++)
619 zlog(NULL
, priority
, "[bt %d] %s",i
,strings
[i
]);
622 #endif /* HAVE_GLIBC_BACKTRACE */
626 zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
630 va_start(args
, format
);
631 vzlog (zl
, priority
, format
, args
);
635 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
637 FUNCNAME(const char *format, ...) \
640 va_start(args, format); \
641 vzlog (NULL, PRIORITY, format, args); \
645 ZLOG_FUNC(zlog_err
, LOG_ERR
)
647 ZLOG_FUNC(zlog_warn
, LOG_WARNING
)
649 ZLOG_FUNC(zlog_info
, LOG_INFO
)
651 ZLOG_FUNC(zlog_notice
, LOG_NOTICE
)
653 ZLOG_FUNC(zlog_debug
, LOG_DEBUG
)
657 void zlog_thread_info (int log_level
)
660 zlog(NULL
, log_level
, "Current thread function %s, scheduled from "
661 "file %s, line %u", thread_current
->funcname
,
662 thread_current
->schedfrom
, thread_current
->schedfrom_line
);
664 zlog(NULL
, log_level
, "Current thread not known/applicable");
668 _zlog_assert_failed (const char *assertion
, const char *file
,
669 unsigned int line
, const char *function
)
671 /* Force fallback file logging? */
672 if (zlog_default
&& !zlog_default
->fp
&&
673 ((logfile_fd
= open_crashlog()) >= 0) &&
674 ((zlog_default
->fp
= fdopen(logfile_fd
, "w")) != NULL
))
675 zlog_default
->maxlvl
[ZLOG_DEST_FILE
] = LOG_ERR
;
676 zlog(NULL
, LOG_CRIT
, "Assertion `%s' failed in file %s, line %u, function %s",
677 assertion
,file
,line
,(function
? function
: "?"));
678 zlog_backtrace(LOG_CRIT
);
679 zlog_thread_info(LOG_CRIT
);
684 /* Open log stream */
686 openzlog (const char *progname
, zlog_proto_t protocol
, u_short instance
,
687 int syslog_flags
, int syslog_facility
)
692 zl
= XCALLOC(MTYPE_ZLOG
, sizeof (struct zlog
));
694 zl
->ident
= progname
;
695 zl
->protocol
= protocol
;
696 zl
->instance
= instance
;
697 zl
->facility
= syslog_facility
;
698 zl
->syslog_options
= syslog_flags
;
700 /* Set default logging levels. */
701 for (i
= 0; i
< array_size(zl
->maxlvl
); i
++)
702 zl
->maxlvl
[i
] = ZLOG_DISABLED
;
703 zl
->maxlvl
[ZLOG_DEST_MONITOR
] = LOG_DEBUG
;
704 zl
->default_lvl
= LOG_DEBUG
;
706 openlog (progname
, syslog_flags
, zl
->facility
);
712 closezlog (struct zlog
*zl
)
719 if (zl
->filename
!= NULL
)
720 XFREE(MTYPE_ZLOG
, zl
->filename
);
722 XFREE (MTYPE_ZLOG
, zl
);
725 /* Called from command.c. */
727 zlog_set_level (struct zlog
*zl
, zlog_dest_t dest
, int log_level
)
732 zl
->maxlvl
[dest
] = log_level
;
736 zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
)
741 /* There is opend file. */
742 zlog_reset_file (zl
);
744 /* Set default zl. */
749 oldumask
= umask (0777 & ~LOGFILE_MASK
);
750 fp
= fopen (filename
, "a");
756 zl
->filename
= XSTRDUP(MTYPE_ZLOG
, filename
);
757 zl
->maxlvl
[ZLOG_DEST_FILE
] = log_level
;
759 logfile_fd
= fileno(fp
);
764 /* Reset opend file. */
766 zlog_reset_file (struct zlog
*zl
)
775 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
778 XFREE(MTYPE_ZLOG
, zl
->filename
);
784 /* Reopen log file. */
786 zlog_rotate (struct zlog
*zl
)
797 level
= zl
->maxlvl
[ZLOG_DEST_FILE
];
798 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
805 oldumask
= umask (0777 & ~LOGFILE_MASK
);
806 zl
->fp
= fopen (zl
->filename
, "a");
811 zlog_err("Log rotate failed: cannot open file %s for append: %s",
812 zl
->filename
, safe_strerror(save_errno
));
815 logfile_fd
= fileno(zl
->fp
);
816 zl
->maxlvl
[ZLOG_DEST_FILE
] = level
;
822 /* Message lookup function. */
824 lookup (const struct message
*mes
, int key
)
826 const struct message
*pnt
;
828 for (pnt
= mes
; pnt
->key
!= 0; pnt
++)
835 /* Older/faster version of message lookup function, but requires caller to pass
836 * in the array size (instead of relying on a 0 key to terminate the search).
838 * The return value is the message string if found, or the 'none' pointer
839 * provided otherwise.
842 mes_lookup (const struct message
*meslist
, int max
, int index
,
843 const char *none
, const char *mesname
)
845 int pos
= index
- meslist
[0].key
;
847 /* first check for best case: index is in range and matches the key
848 * value in that slot.
849 * NB: key numbering might be offset from 0. E.g. protocol constants
852 if ((pos
>= 0) && (pos
< max
)
853 && (meslist
[pos
].key
== index
))
854 return meslist
[pos
].str
;
856 /* fall back to linear search */
860 for (i
= 0; i
< max
; i
++, meslist
++)
862 if (meslist
->key
== index
)
864 const char *str
= (meslist
->str
? meslist
->str
: none
);
866 zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
867 index
, str
, mesname
, i
, max
);
872 zlog_err("message index %d not found in %s (max is %d)", index
, mesname
, max
);
877 /* Wrapper around strerror to handle case where it returns NULL. */
879 safe_strerror(int errnum
)
881 const char *s
= strerror(errnum
);
882 return (s
!= NULL
) ? s
: "Unknown error";
885 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
886 static const struct zebra_desc_table command_types
[] = {
887 DESC_ENTRY (ZEBRA_INTERFACE_ADD
),
888 DESC_ENTRY (ZEBRA_INTERFACE_DELETE
),
889 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD
),
890 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE
),
891 DESC_ENTRY (ZEBRA_INTERFACE_UP
),
892 DESC_ENTRY (ZEBRA_INTERFACE_DOWN
),
893 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD
),
894 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE
),
895 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD
),
896 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE
),
897 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD
),
898 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE
),
899 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD
),
900 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
),
901 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD
),
902 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE
),
903 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE
),
904 DESC_ENTRY (ZEBRA_HELLO
),
905 DESC_ENTRY (ZEBRA_NEXTHOP_REGISTER
),
906 DESC_ENTRY (ZEBRA_NEXTHOP_UNREGISTER
),
907 DESC_ENTRY (ZEBRA_NEXTHOP_UPDATE
),
908 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
),
909 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
),
910 DESC_ENTRY (ZEBRA_INTERFACE_BFD_DEST_UPDATE
),
911 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_REGISTER
),
912 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_UNREGISTER
),
913 DESC_ENTRY (ZEBRA_IMPORT_CHECK_UPDATE
),
914 DESC_ENTRY (ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
),
915 DESC_ENTRY (ZEBRA_BFD_DEST_REGISTER
),
916 DESC_ENTRY (ZEBRA_BFD_DEST_DEREGISTER
),
917 DESC_ENTRY (ZEBRA_BFD_DEST_UPDATE
),
918 DESC_ENTRY (ZEBRA_BFD_DEST_REPLAY
),
919 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_ADD
),
920 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_DEL
),
921 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_ADD
),
922 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_DEL
),
923 DESC_ENTRY (ZEBRA_VRF_UNREGISTER
),
924 DESC_ENTRY (ZEBRA_VRF_ADD
),
925 DESC_ENTRY (ZEBRA_VRF_DELETE
),
926 DESC_ENTRY (ZEBRA_INTERFACE_VRF_UPDATE
),
927 DESC_ENTRY (ZEBRA_BFD_CLIENT_REGISTER
),
928 DESC_ENTRY (ZEBRA_INTERFACE_ENABLE_RADV
),
929 DESC_ENTRY (ZEBRA_INTERFACE_DISABLE_RADV
),
930 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB
),
934 static const struct zebra_desc_table unknown
= { 0, "unknown", '?' };
936 static const struct zebra_desc_table
*
937 zroute_lookup(u_int zroute
)
941 if (zroute
>= array_size(route_types
))
943 zlog_err("unknown zebra route type: %u", zroute
);
946 if (zroute
== route_types
[zroute
].type
)
947 return &route_types
[zroute
];
948 for (i
= 0; i
< array_size(route_types
); i
++)
950 if (zroute
== route_types
[i
].type
)
952 zlog_warn("internal error: route type table out of order "
953 "while searching for %u, please notify developers", zroute
);
954 return &route_types
[i
];
957 zlog_err("internal error: cannot find route type %u in table!", zroute
);
962 zebra_route_string(u_int zroute
)
964 return zroute_lookup(zroute
)->string
;
968 zebra_route_char(u_int zroute
)
970 return zroute_lookup(zroute
)->chr
;
974 zserv_command_string (unsigned int command
)
976 if (command
>= array_size(command_types
))
978 zlog_err ("unknown zserv command type: %u", command
);
979 return unknown
.string
;
981 return command_types
[command
].string
;
985 proto_name2num(const char *s
)
989 for (i
=0; i
<array_size(route_types
); ++i
)
990 if (strcasecmp(s
, route_types
[i
].string
) == 0)
991 return route_types
[i
].type
;
996 proto_redistnum(int afi
, const char *s
)
1003 if (strncmp (s
, "k", 1) == 0)
1004 return ZEBRA_ROUTE_KERNEL
;
1005 else if (strncmp (s
, "c", 1) == 0)
1006 return ZEBRA_ROUTE_CONNECT
;
1007 else if (strncmp (s
, "s", 1) == 0)
1008 return ZEBRA_ROUTE_STATIC
;
1009 else if (strncmp (s
, "r", 1) == 0)
1010 return ZEBRA_ROUTE_RIP
;
1011 else if (strncmp (s
, "o", 1) == 0)
1012 return ZEBRA_ROUTE_OSPF
;
1013 else if (strncmp (s
, "i", 1) == 0)
1014 return ZEBRA_ROUTE_ISIS
;
1015 else if (strncmp (s
, "bg", 2) == 0)
1016 return ZEBRA_ROUTE_BGP
;
1017 else if (strncmp (s
, "ta", 2) == 0)
1018 return ZEBRA_ROUTE_TABLE
;
1022 if (strncmp (s
, "k", 1) == 0)
1023 return ZEBRA_ROUTE_KERNEL
;
1024 else if (strncmp (s
, "c", 1) == 0)
1025 return ZEBRA_ROUTE_CONNECT
;
1026 else if (strncmp (s
, "s", 1) == 0)
1027 return ZEBRA_ROUTE_STATIC
;
1028 else if (strncmp (s
, "r", 1) == 0)
1029 return ZEBRA_ROUTE_RIPNG
;
1030 else if (strncmp (s
, "o", 1) == 0)
1031 return ZEBRA_ROUTE_OSPF6
;
1032 else if (strncmp (s
, "i", 1) == 0)
1033 return ZEBRA_ROUTE_ISIS
;
1034 else if (strncmp (s
, "bg", 2) == 0)
1035 return ZEBRA_ROUTE_BGP
;
1036 else if (strncmp (s
, "ta", 2) == 0)
1037 return ZEBRA_ROUTE_TABLE
;
1043 zlog_hexdump (const void *mem
, unsigned int len
) {
1044 unsigned long i
= 0;
1046 unsigned int columns
= 8;
1047 char buf
[(len
* 4) + ((len
/4) * 20) + 30];
1050 for (i
= 0; i
< len
+ ((len
% columns
) ? (columns
- len
% columns
) : 0); i
++)
1053 if (i
% columns
== 0)
1054 s
+= sprintf(s
, "0x%016lx: ", (unsigned long)mem
+ i
);
1056 /* print hex data */
1058 s
+= sprintf(s
, "%02x ", 0xFF & ((const char*)mem
)[i
]);
1060 /* end of block, just aligning for ASCII dump */
1062 s
+= sprintf(s
, " ");
1064 /* print ASCII dump */
1065 if (i
% columns
== (columns
- 1))
1067 for (j
= i
- (columns
- 1); j
<= i
; j
++)
1069 if (j
>= len
) /* end of block, not really printing */
1070 s
+= sprintf(s
, " ");
1072 else if(isprint((int)((const char *)mem
)[j
])) /* printable char */
1073 s
+= sprintf(s
, "%c", 0xFF & ((const char *)mem
)[j
]);
1075 else /* other char */
1076 s
+= sprintf(s
, ".");
1078 s
+= sprintf(s
, "\n");
1081 zlog_debug("\n%s", buf
);