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 struct timestamp_control tsctl
;
183 tsctl
.already_rendered
= 0;
185 /* If zlog is not specified, use default one. */
189 /* When zlog_default is also NULL, use stderr for logging. */
193 time_print(stderr
, &tsctl
);
194 fprintf (stderr
, "%s: ", "unknown");
195 vfprintf (stderr
, format
, args
);
196 fprintf (stderr
, "\n");
199 /* In this case we return at here. */
202 tsctl
.precision
= zl
->timestamp_precision
;
205 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
209 vsyslog (priority
|zlog_default
->facility
, format
, ac
);
214 sprintf (proto_str
, "%s[%d]: ", zlog_proto_names
[zl
->protocol
], zl
->instance
);
216 sprintf (proto_str
, "%s: ", zlog_proto_names
[zl
->protocol
]);
219 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
222 time_print (zl
->fp
, &tsctl
);
223 if (zl
->record_priority
)
224 fprintf (zl
->fp
, "%s: ", zlog_priority
[priority
]);
225 fprintf (zl
->fp
, "%s", proto_str
);
227 vfprintf (zl
->fp
, format
, ac
);
229 fprintf (zl
->fp
, "\n");
234 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
237 time_print (stdout
, &tsctl
);
238 if (zl
->record_priority
)
239 fprintf (stdout
, "%s: ", zlog_priority
[priority
]);
240 fprintf (stdout
, "%s", proto_str
);
242 vfprintf (stdout
, format
, ac
);
244 fprintf (stdout
, "\n");
248 /* Terminal monitor. */
249 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
250 vty_log ((zl
->record_priority
? zlog_priority
[priority
] : NULL
),
251 proto_str
, format
, &tsctl
, args
);
255 str_append(char *dst
, int len
, const char *src
)
257 while ((len
-- > 0) && *src
)
263 num_append(char *s
, int len
, u_long x
)
269 return str_append(s
,len
,"0");
270 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
271 while (x
&& (t
> buf
))
276 return str_append(s
,len
,t
);
279 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
281 hex_append(char *s
, int len
, u_long x
)
287 return str_append(s
,len
,"0");
288 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
289 while (x
&& (t
> buf
))
292 *--t
= ((cc
< 10) ? ('0'+cc
) : ('a'+cc
-10));
295 return str_append(s
,len
,t
);
299 /* Needs to be enhanced to support Solaris. */
308 struct sockaddr_un addr
;
310 if ((fd
= socket(AF_UNIX
,SOCK_DGRAM
,0)) < 0)
312 addr
.sun_family
= AF_UNIX
;
314 #define SYSLOG_SOCKET_PATH _PATH_LOG
316 #define SYSLOG_SOCKET_PATH "/dev/log"
318 s
= str_append(addr
.sun_path
,sizeof(addr
.sun_path
),SYSLOG_SOCKET_PATH
);
319 #undef SYSLOG_SOCKET_PATH
321 if (connect(fd
,(struct sockaddr
*)&addr
,sizeof(addr
)) < 0)
331 syslog_sigsafe(int priority
, const char *msg
, size_t msglen
)
333 static int syslog_fd
= -1;
334 char buf
[sizeof("<1234567890>ripngd[1234567890]: ")+msglen
+50];
337 if ((syslog_fd
< 0) && ((syslog_fd
= syslog_connect()) < 0))
340 #define LOC s,buf+sizeof(buf)-s
342 s
= str_append(LOC
,"<");
343 s
= num_append(LOC
,priority
);
344 s
= str_append(LOC
,">");
345 /* forget about the timestamp, too difficult in a signal handler */
346 s
= str_append(LOC
,zlog_default
->ident
);
347 if (zlog_default
->syslog_options
& LOG_PID
)
349 s
= str_append(LOC
,"[");
350 s
= num_append(LOC
,getpid());
351 s
= str_append(LOC
,"]");
353 s
= str_append(LOC
,": ");
354 s
= str_append(LOC
,msg
);
355 write_wrapper (syslog_fd
,buf
,s
-buf
);
362 #define CRASHLOG_PREFIX "/var/tmp/quagga."
363 #define CRASHLOG_SUFFIX "crashlog"
364 if (zlog_default
&& zlog_default
->ident
)
366 /* Avoid strlen since it is not async-signal-safe. */
370 for (p
= zlog_default
->ident
, ilen
= 0; *p
; p
++)
373 char buf
[sizeof(CRASHLOG_PREFIX
)+ilen
+sizeof(CRASHLOG_SUFFIX
)+3];
375 #define LOC s,buf+sizeof(buf)-s
376 s
= str_append(LOC
, CRASHLOG_PREFIX
);
377 s
= str_append(LOC
, zlog_default
->ident
);
378 s
= str_append(LOC
, ".");
379 s
= str_append(LOC
, CRASHLOG_SUFFIX
);
382 return open(buf
, O_WRONLY
|O_CREAT
|O_EXCL
, LOGFILE_MASK
);
385 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX
, O_WRONLY
|O_CREAT
|O_EXCL
,
387 #undef CRASHLOG_SUFFIX
388 #undef CRASHLOG_PREFIX
391 /* Note: the goal here is to use only async-signal-safe functions. */
393 zlog_signal(int signo
, const char *action
395 , siginfo_t
*siginfo
, void *program_counter
400 char buf
[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
402 char *msgstart
= buf
;
403 #define LOC s,buf+sizeof(buf)-s
408 s
= str_append(LOC
,zlog_proto_names
[zlog_default
->protocol
]);
413 s
= str_append(LOC
,"Received signal ");
414 s
= num_append(LOC
,signo
);
415 s
= str_append(LOC
," at ");
416 s
= num_append(LOC
,now
);
418 s
= str_append(LOC
," (si_addr 0x");
419 s
= hex_append(LOC
,(u_long
)(siginfo
->si_addr
));
422 s
= str_append(LOC
,", PC 0x");
423 s
= hex_append(LOC
,(u_long
)program_counter
);
425 s
= str_append(LOC
,"); ");
426 #else /* SA_SIGINFO */
427 s
= str_append(LOC
,"; ");
428 #endif /* SA_SIGINFO */
429 s
= str_append(LOC
,action
);
430 if (s
< buf
+sizeof(buf
))
433 /* N.B. implicit priority is most severe */
436 #define DUMP(FD) write_wrapper(FD, buf, s-buf);
437 /* If no file logging configured, try to write to fallback log file. */
438 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
444 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
446 /* Remove trailing '\n' for monitor and syslog */
448 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
449 vty_log_fixed(buf
,s
-buf
);
450 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
451 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
455 zlog_backtrace_sigsafe(PRI
,
466 /* Log a backtrace using only async-signal-safe functions.
467 Needs to be enhanced to support syslog logging. */
469 zlog_backtrace_sigsafe(int priority
, void *program_counter
)
471 #ifdef HAVE_STACK_TRACE
472 static const char pclabel
[] = "Program counter: ";
476 char *s
, **bt
= NULL
;
477 #define LOC s,buf+sizeof(buf)-s
479 #ifdef HAVE_GLIBC_BACKTRACE
480 size
= backtrace(array
, array_size(array
));
481 if (size
<= 0 || (size_t)size
> array_size(array
))
485 if (program_counter) \
487 write_wrapper(FD, pclabel, sizeof(pclabel)-1); \
488 backtrace_symbols_fd(&program_counter, 1, FD); \
490 write_wrapper(FD, buf, s-buf); \
491 backtrace_symbols_fd(array, size, FD); \
493 #elif defined(HAVE_PRINTSTACK)
495 if (program_counter) \
496 write_wrapper((FD), pclabel, sizeof(pclabel)-1); \
497 write_wrapper((FD), buf, s-buf); \
500 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
503 s
= str_append(LOC
,"Backtrace for ");
504 s
= num_append(LOC
,size
);
505 s
= str_append(LOC
," stack frames:\n");
507 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
513 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
515 /* Remove trailing '\n' for monitor and syslog */
517 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
518 vty_log_fixed(buf
,s
-buf
);
519 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
520 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
523 #ifdef HAVE_GLIBC_BACKTRACE
524 bt
= backtrace_symbols(array
, size
);
526 /* Just print the function addresses. */
527 for (i
= 0; i
< size
; i
++)
531 s
= str_append(LOC
, bt
[i
]);
533 s
= str_append(LOC
,"[bt ");
534 s
= num_append(LOC
,i
);
535 s
= str_append(LOC
,"] 0x");
536 s
= hex_append(LOC
,(u_long
)(array
[i
]));
539 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
540 vty_log_fixed(buf
,s
-buf
);
541 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
542 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
550 #endif /* HAVE_STRACK_TRACE */
554 zlog_backtrace(int priority
)
556 #ifndef HAVE_GLIBC_BACKTRACE
557 zlog(NULL
, priority
, "No backtrace available on this platform.");
563 size
= backtrace(array
, array_size(array
));
564 if (size
<= 0 || (size_t)size
> array_size(array
))
566 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
567 "(valid range is between 1 and %lu)",
568 size
, (unsigned long)(array_size(array
)));
571 zlog(NULL
, priority
, "Backtrace for %d stack frames:", size
);
572 if (!(strings
= backtrace_symbols(array
, size
)))
574 zlog_err("Cannot get backtrace symbols (out of memory?)");
575 for (i
= 0; i
< size
; i
++)
576 zlog(NULL
, priority
, "[bt %d] %p",i
,array
[i
]);
580 for (i
= 0; i
< size
; i
++)
581 zlog(NULL
, priority
, "[bt %d] %s",i
,strings
[i
]);
584 #endif /* HAVE_GLIBC_BACKTRACE */
588 zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
592 va_start(args
, format
);
593 vzlog (zl
, priority
, format
, args
);
597 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
599 FUNCNAME(const char *format, ...) \
602 va_start(args, format); \
603 vzlog (NULL, PRIORITY, format, args); \
607 ZLOG_FUNC(zlog_err
, LOG_ERR
)
609 ZLOG_FUNC(zlog_warn
, LOG_WARNING
)
611 ZLOG_FUNC(zlog_info
, LOG_INFO
)
613 ZLOG_FUNC(zlog_notice
, LOG_NOTICE
)
615 ZLOG_FUNC(zlog_debug
, LOG_DEBUG
)
620 _zlog_assert_failed (const char *assertion
, const char *file
,
621 unsigned int line
, const char *function
)
623 /* Force fallback file logging? */
624 if (zlog_default
&& !zlog_default
->fp
&&
625 ((logfile_fd
= open_crashlog()) >= 0) &&
626 ((zlog_default
->fp
= fdopen(logfile_fd
, "w")) != NULL
))
627 zlog_default
->maxlvl
[ZLOG_DEST_FILE
] = LOG_ERR
;
628 zlog(NULL
, LOG_CRIT
, "Assertion `%s' failed in file %s, line %u, function %s",
629 assertion
,file
,line
,(function
? function
: "?"));
630 zlog_backtrace(LOG_CRIT
);
635 /* Open log stream */
637 openzlog (const char *progname
, zlog_proto_t protocol
, u_short instance
,
638 int syslog_flags
, int syslog_facility
)
643 zl
= XCALLOC(MTYPE_ZLOG
, sizeof (struct zlog
));
645 zl
->ident
= progname
;
646 zl
->protocol
= protocol
;
647 zl
->instance
= instance
;
648 zl
->facility
= syslog_facility
;
649 zl
->syslog_options
= syslog_flags
;
651 /* Set default logging levels. */
652 for (i
= 0; i
< array_size(zl
->maxlvl
); i
++)
653 zl
->maxlvl
[i
] = ZLOG_DISABLED
;
654 zl
->maxlvl
[ZLOG_DEST_MONITOR
] = LOG_DEBUG
;
655 zl
->default_lvl
= LOG_DEBUG
;
657 openlog (progname
, syslog_flags
, zl
->facility
);
663 closezlog (struct zlog
*zl
)
670 if (zl
->filename
!= NULL
)
671 XFREE(MTYPE_ZLOG
, zl
->filename
);
673 XFREE (MTYPE_ZLOG
, zl
);
676 /* Called from command.c. */
678 zlog_set_level (struct zlog
*zl
, zlog_dest_t dest
, int log_level
)
683 zl
->maxlvl
[dest
] = log_level
;
687 zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
)
692 /* There is opend file. */
693 zlog_reset_file (zl
);
695 /* Set default zl. */
700 oldumask
= umask (0777 & ~LOGFILE_MASK
);
701 fp
= fopen (filename
, "a");
707 zl
->filename
= XSTRDUP(MTYPE_ZLOG
, filename
);
708 zl
->maxlvl
[ZLOG_DEST_FILE
] = log_level
;
710 logfile_fd
= fileno(fp
);
715 /* Reset opend file. */
717 zlog_reset_file (struct zlog
*zl
)
726 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
729 XFREE(MTYPE_ZLOG
, zl
->filename
);
735 /* Reopen log file. */
737 zlog_rotate (struct zlog
*zl
)
748 level
= zl
->maxlvl
[ZLOG_DEST_FILE
];
749 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
756 oldumask
= umask (0777 & ~LOGFILE_MASK
);
757 zl
->fp
= fopen (zl
->filename
, "a");
762 zlog_err("Log rotate failed: cannot open file %s for append: %s",
763 zl
->filename
, safe_strerror(save_errno
));
766 logfile_fd
= fileno(zl
->fp
);
767 zl
->maxlvl
[ZLOG_DEST_FILE
] = level
;
773 /* Message lookup function. */
775 lookup (const struct message
*mes
, int key
)
777 const struct message
*pnt
;
779 for (pnt
= mes
; pnt
->key
!= 0; pnt
++)
786 /* Older/faster version of message lookup function, but requires caller to pass
787 * in the array size (instead of relying on a 0 key to terminate the search).
789 * The return value is the message string if found, or the 'none' pointer
790 * provided otherwise.
793 mes_lookup (const struct message
*meslist
, int max
, int index
,
794 const char *none
, const char *mesname
)
796 int pos
= index
- meslist
[0].key
;
798 /* first check for best case: index is in range and matches the key
799 * value in that slot.
800 * NB: key numbering might be offset from 0. E.g. protocol constants
803 if ((pos
>= 0) && (pos
< max
)
804 && (meslist
[pos
].key
== index
))
805 return meslist
[pos
].str
;
807 /* fall back to linear search */
811 for (i
= 0; i
< max
; i
++, meslist
++)
813 if (meslist
->key
== index
)
815 const char *str
= (meslist
->str
? meslist
->str
: none
);
817 zlog_debug ("message index %d [%s] found in %s at position %d (max is %d)",
818 index
, str
, mesname
, i
, max
);
823 zlog_err("message index %d not found in %s (max is %d)", index
, mesname
, max
);
828 /* Wrapper around strerror to handle case where it returns NULL. */
830 safe_strerror(int errnum
)
832 const char *s
= strerror(errnum
);
833 return (s
!= NULL
) ? s
: "Unknown error";
836 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
837 static const struct zebra_desc_table command_types
[] = {
838 DESC_ENTRY (ZEBRA_INTERFACE_ADD
),
839 DESC_ENTRY (ZEBRA_INTERFACE_DELETE
),
840 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD
),
841 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE
),
842 DESC_ENTRY (ZEBRA_INTERFACE_UP
),
843 DESC_ENTRY (ZEBRA_INTERFACE_DOWN
),
844 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD
),
845 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE
),
846 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD
),
847 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE
),
848 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD
),
849 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE
),
850 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD
),
851 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
),
852 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP
),
853 DESC_ENTRY (ZEBRA_IPV6_NEXTHOP_LOOKUP
),
854 DESC_ENTRY (ZEBRA_IPV4_IMPORT_LOOKUP
),
855 DESC_ENTRY (ZEBRA_IPV6_IMPORT_LOOKUP
),
856 DESC_ENTRY (ZEBRA_INTERFACE_RENAME
),
857 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD
),
858 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE
),
859 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE
),
860 DESC_ENTRY (ZEBRA_HELLO
),
861 DESC_ENTRY (ZEBRA_NEXTHOP_REGISTER
),
862 DESC_ENTRY (ZEBRA_NEXTHOP_UNREGISTER
),
863 DESC_ENTRY (ZEBRA_NEXTHOP_UPDATE
),
864 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
),
865 DESC_ENTRY (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
),
866 DESC_ENTRY (ZEBRA_INTERFACE_BFD_DEST_UPDATE
),
867 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_REGISTER
),
868 DESC_ENTRY (ZEBRA_IMPORT_ROUTE_UNREGISTER
),
869 DESC_ENTRY (ZEBRA_IMPORT_CHECK_UPDATE
),
870 DESC_ENTRY (ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
),
871 DESC_ENTRY (ZEBRA_BFD_DEST_REGISTER
),
872 DESC_ENTRY (ZEBRA_BFD_DEST_DEREGISTER
),
873 DESC_ENTRY (ZEBRA_BFD_DEST_UPDATE
),
874 DESC_ENTRY (ZEBRA_BFD_DEST_REPLAY
),
875 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_ADD
),
876 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV4_DEL
),
877 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_ADD
),
878 DESC_ENTRY (ZEBRA_REDISTRIBUTE_IPV6_DEL
),
879 DESC_ENTRY (ZEBRA_VRF_UNREGISTER
),
880 DESC_ENTRY (ZEBRA_VRF_ADD
),
881 DESC_ENTRY (ZEBRA_VRF_DELETE
),
882 DESC_ENTRY (ZEBRA_INTERFACE_VRF_UPDATE
),
883 DESC_ENTRY (ZEBRA_BFD_CLIENT_REGISTER
),
884 DESC_ENTRY (ZEBRA_INTERFACE_ENABLE_RADV
),
885 DESC_ENTRY (ZEBRA_INTERFACE_DISABLE_RADV
),
886 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB
),
890 static const struct zebra_desc_table unknown
= { 0, "unknown", '?' };
892 static const struct zebra_desc_table
*
893 zroute_lookup(u_int zroute
)
897 if (zroute
>= array_size(route_types
))
899 zlog_err("unknown zebra route type: %u", zroute
);
902 if (zroute
== route_types
[zroute
].type
)
903 return &route_types
[zroute
];
904 for (i
= 0; i
< array_size(route_types
); i
++)
906 if (zroute
== route_types
[i
].type
)
908 zlog_warn("internal error: route type table out of order "
909 "while searching for %u, please notify developers", zroute
);
910 return &route_types
[i
];
913 zlog_err("internal error: cannot find route type %u in table!", zroute
);
918 zebra_route_string(u_int zroute
)
920 return zroute_lookup(zroute
)->string
;
924 zebra_route_char(u_int zroute
)
926 return zroute_lookup(zroute
)->chr
;
930 zserv_command_string (unsigned int command
)
932 if (command
>= array_size(command_types
))
934 zlog_err ("unknown zserv command type: %u", command
);
935 return unknown
.string
;
937 return command_types
[command
].string
;
941 proto_name2num(const char *s
)
945 for (i
=0; i
<array_size(route_types
); ++i
)
946 if (strcasecmp(s
, route_types
[i
].string
) == 0)
947 return route_types
[i
].type
;
952 proto_redistnum(int afi
, const char *s
)
959 if (strncmp (s
, "k", 1) == 0)
960 return ZEBRA_ROUTE_KERNEL
;
961 else if (strncmp (s
, "c", 1) == 0)
962 return ZEBRA_ROUTE_CONNECT
;
963 else if (strncmp (s
, "s", 1) == 0)
964 return ZEBRA_ROUTE_STATIC
;
965 else if (strncmp (s
, "r", 1) == 0)
966 return ZEBRA_ROUTE_RIP
;
967 else if (strncmp (s
, "o", 1) == 0)
968 return ZEBRA_ROUTE_OSPF
;
969 else if (strncmp (s
, "i", 1) == 0)
970 return ZEBRA_ROUTE_ISIS
;
971 else if (strncmp (s
, "bg", 2) == 0)
972 return ZEBRA_ROUTE_BGP
;
973 else if (strncmp (s
, "ta", 2) == 0)
974 return ZEBRA_ROUTE_TABLE
;
978 if (strncmp (s
, "k", 1) == 0)
979 return ZEBRA_ROUTE_KERNEL
;
980 else if (strncmp (s
, "c", 1) == 0)
981 return ZEBRA_ROUTE_CONNECT
;
982 else if (strncmp (s
, "s", 1) == 0)
983 return ZEBRA_ROUTE_STATIC
;
984 else if (strncmp (s
, "r", 1) == 0)
985 return ZEBRA_ROUTE_RIPNG
;
986 else if (strncmp (s
, "o", 1) == 0)
987 return ZEBRA_ROUTE_OSPF6
;
988 else if (strncmp (s
, "i", 1) == 0)
989 return ZEBRA_ROUTE_ISIS
;
990 else if (strncmp (s
, "bg", 2) == 0)
991 return ZEBRA_ROUTE_BGP
;
992 else if (strncmp (s
, "ta", 2) == 0)
993 return ZEBRA_ROUTE_TABLE
;
999 zlog_hexdump (const void *mem
, unsigned int len
) {
1000 unsigned long i
= 0;
1002 unsigned int columns
= 8;
1003 char buf
[(len
* 4) + ((len
/4) * 20) + 30];
1006 for (i
= 0; i
< len
+ ((len
% columns
) ? (columns
- len
% columns
) : 0); i
++)
1009 if (i
% columns
== 0)
1010 s
+= sprintf(s
, "0x%016lx: ", (unsigned long)mem
+ i
);
1012 /* print hex data */
1014 s
+= sprintf(s
, "%02x ", 0xFF & ((const char*)mem
)[i
]);
1016 /* end of block, just aligning for ASCII dump */
1018 s
+= sprintf(s
, " ");
1020 /* print ASCII dump */
1021 if (i
% columns
== (columns
- 1))
1023 for (j
= i
- (columns
- 1); j
<= i
; j
++)
1025 if (j
>= len
) /* end of block, not really printing */
1026 s
+= sprintf(s
, " ");
1028 else if(isprint((int)((const char *)mem
)[j
])) /* printable char */
1029 s
+= sprintf(s
, "%c", 0xFF & ((const char *)mem
)[j
]);
1031 else /* other char */
1032 s
+= sprintf(s
, ".");
1034 s
+= sprintf(s
, "\n");
1037 zlog_debug("\n%s", buf
);