5 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
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
[] =
57 const char *zlog_priority
[] =
72 /* For time string format. */
75 quagga_timestamp(int timestamp_precision
, char *buf
, size_t buflen
)
84 /* would it be sufficient to use global 'recent_time' here? I fear not... */
85 gettimeofday(&clock
, NULL
);
87 /* first, we update the cache if the time has changed */
88 if (cache
.last
!= clock
.tv_sec
)
91 cache
.last
= clock
.tv_sec
;
92 tm
= localtime(&cache
.last
);
93 cache
.len
= strftime(cache
.buf
, sizeof(cache
.buf
),
94 "%Y/%m/%d %H:%M:%S", tm
);
96 /* note: it's not worth caching the subsecond part, because
97 chances are that back-to-back calls are not sufficiently close together
98 for the clock not to have ticked forward */
100 if (buflen
> cache
.len
)
102 memcpy(buf
, cache
.buf
, cache
.len
);
103 if ((timestamp_precision
> 0) &&
104 (buflen
> cache
.len
+1+timestamp_precision
))
106 /* should we worry about locale issues? */
107 static const int divisor
[] = {0, 100000, 10000, 1000, 100, 10, 1};
109 char *p
= buf
+cache
.len
+1+(prec
= timestamp_precision
);
112 /* this is unlikely to happen, but protect anyway */
117 clock
.tv_usec
/= divisor
[prec
];
120 *p
-- = '0'+(clock
.tv_usec
% 10);
125 return cache
.len
+1+timestamp_precision
;
127 buf
[cache
.len
] = '\0';
135 /* Utility routine for current time printing. */
137 time_print(FILE *fp
, struct timestamp_control
*ctl
)
139 if (!ctl
->already_rendered
)
141 ctl
->len
= quagga_timestamp(ctl
->precision
, ctl
->buf
, sizeof(ctl
->buf
));
142 ctl
->already_rendered
= 1;
144 fprintf(fp
, "%s ", ctl
->buf
);
148 /* va_list version of zlog. */
150 vzlog (struct zlog
*zl
, int priority
, const char *format
, va_list args
)
152 struct timestamp_control tsctl
;
153 tsctl
.already_rendered
= 0;
155 /* If zlog is not specified, use default one. */
159 /* When zlog_default is also NULL, use stderr for logging. */
163 time_print(stderr
, &tsctl
);
164 fprintf (stderr
, "%s: ", "unknown");
165 vfprintf (stderr
, format
, args
);
166 fprintf (stderr
, "\n");
169 /* In this case we return at here. */
172 tsctl
.precision
= zl
->timestamp_precision
;
175 if (priority
<= zl
->maxlvl
[ZLOG_DEST_SYSLOG
])
179 vsyslog (priority
|zlog_default
->facility
, format
, ac
);
184 if ((priority
<= zl
->maxlvl
[ZLOG_DEST_FILE
]) && zl
->fp
)
187 time_print (zl
->fp
, &tsctl
);
188 if (zl
->record_priority
)
189 fprintf (zl
->fp
, "%s: ", zlog_priority
[priority
]);
190 fprintf (zl
->fp
, "%s: ", zlog_proto_names
[zl
->protocol
]);
192 vfprintf (zl
->fp
, format
, ac
);
194 fprintf (zl
->fp
, "\n");
199 if (priority
<= zl
->maxlvl
[ZLOG_DEST_STDOUT
])
202 time_print (stdout
, &tsctl
);
203 if (zl
->record_priority
)
204 fprintf (stdout
, "%s: ", zlog_priority
[priority
]);
205 fprintf (stdout
, "%s: ", zlog_proto_names
[zl
->protocol
]);
207 vfprintf (stdout
, format
, ac
);
209 fprintf (stdout
, "\n");
213 /* Terminal monitor. */
214 if (priority
<= zl
->maxlvl
[ZLOG_DEST_MONITOR
])
215 vty_log ((zl
->record_priority
? zlog_priority
[priority
] : NULL
),
216 zlog_proto_names
[zl
->protocol
], format
, &tsctl
, args
);
220 str_append(char *dst
, int len
, const char *src
)
222 while ((len
-- > 0) && *src
)
228 num_append(char *s
, int len
, u_long x
)
234 return str_append(s
,len
,"0");
235 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
236 while (x
&& (t
> buf
))
241 return str_append(s
,len
,t
);
244 #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
246 hex_append(char *s
, int len
, u_long x
)
252 return str_append(s
,len
,"0");
253 *(t
= &buf
[sizeof(buf
)-1]) = '\0';
254 while (x
&& (t
> buf
))
257 *--t
= ((cc
< 10) ? ('0'+cc
) : ('a'+cc
-10));
260 return str_append(s
,len
,t
);
264 /* Needs to be enhanced to support Solaris. */
273 struct sockaddr_un addr
;
275 if ((fd
= socket(AF_UNIX
,SOCK_DGRAM
,0)) < 0)
277 addr
.sun_family
= AF_UNIX
;
279 #define SYSLOG_SOCKET_PATH _PATH_LOG
281 #define SYSLOG_SOCKET_PATH "/dev/log"
283 s
= str_append(addr
.sun_path
,sizeof(addr
.sun_path
),SYSLOG_SOCKET_PATH
);
284 #undef SYSLOG_SOCKET_PATH
286 if (connect(fd
,(struct sockaddr
*)&addr
,sizeof(addr
)) < 0)
296 syslog_sigsafe(int priority
, const char *msg
, size_t msglen
)
298 static int syslog_fd
= -1;
299 char buf
[sizeof("<1234567890>ripngd[1234567890]: ")+msglen
+50];
302 if ((syslog_fd
< 0) && ((syslog_fd
= syslog_connect()) < 0))
305 #define LOC s,buf+sizeof(buf)-s
307 s
= str_append(LOC
,"<");
308 s
= num_append(LOC
,priority
);
309 s
= str_append(LOC
,">");
310 /* forget about the timestamp, too difficult in a signal handler */
311 s
= str_append(LOC
,zlog_default
->ident
);
312 if (zlog_default
->syslog_options
& LOG_PID
)
314 s
= str_append(LOC
,"[");
315 s
= num_append(LOC
,getpid());
316 s
= str_append(LOC
,"]");
318 s
= str_append(LOC
,": ");
319 s
= str_append(LOC
,msg
);
320 write(syslog_fd
,buf
,s
-buf
);
327 #define CRASHLOG_PREFIX "/var/tmp/quagga."
328 #define CRASHLOG_SUFFIX "crashlog"
329 if (zlog_default
&& zlog_default
->ident
)
331 /* Avoid strlen since it is not async-signal-safe. */
335 for (p
= zlog_default
->ident
, ilen
= 0; *p
; p
++)
338 char buf
[sizeof(CRASHLOG_PREFIX
)+ilen
+sizeof(CRASHLOG_SUFFIX
)+3];
340 #define LOC s,buf+sizeof(buf)-s
341 s
= str_append(LOC
, CRASHLOG_PREFIX
);
342 s
= str_append(LOC
, zlog_default
->ident
);
343 s
= str_append(LOC
, ".");
344 s
= str_append(LOC
, CRASHLOG_SUFFIX
);
347 return open(buf
, O_WRONLY
|O_CREAT
|O_EXCL
, LOGFILE_MASK
);
350 return open(CRASHLOG_PREFIX CRASHLOG_SUFFIX
, O_WRONLY
|O_CREAT
|O_EXCL
,
352 #undef CRASHLOG_SUFFIX
353 #undef CRASHLOG_PREFIX
356 /* Note: the goal here is to use only async-signal-safe functions. */
358 zlog_signal(int signo
, const char *action
360 , siginfo_t
*siginfo
, void *program_counter
365 char buf
[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")+100];
367 char *msgstart
= buf
;
368 #define LOC s,buf+sizeof(buf)-s
373 s
= str_append(LOC
,zlog_proto_names
[zlog_default
->protocol
]);
378 s
= str_append(LOC
,"Received signal ");
379 s
= num_append(LOC
,signo
);
380 s
= str_append(LOC
," at ");
381 s
= num_append(LOC
,now
);
383 s
= str_append(LOC
," (si_addr 0x");
384 s
= hex_append(LOC
,(u_long
)(siginfo
->si_addr
));
387 s
= str_append(LOC
,", PC 0x");
388 s
= hex_append(LOC
,(u_long
)program_counter
);
390 s
= str_append(LOC
,"); ");
391 #else /* SA_SIGINFO */
392 s
= str_append(LOC
,"; ");
393 #endif /* SA_SIGINFO */
394 s
= str_append(LOC
,action
);
395 if (s
< buf
+sizeof(buf
))
398 /* N.B. implicit priority is most severe */
401 #define DUMP(FD) write(FD, buf, s-buf);
402 /* If no file logging configured, try to write to fallback log file. */
403 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
409 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
411 /* Remove trailing '\n' for monitor and syslog */
413 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
414 vty_log_fixed(buf
,s
-buf
);
415 if (PRI
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
416 syslog_sigsafe(PRI
|zlog_default
->facility
,msgstart
,s
-msgstart
);
420 zlog_backtrace_sigsafe(PRI
,
431 /* Log a backtrace using only async-signal-safe functions.
432 Needs to be enhanced to support syslog logging. */
434 zlog_backtrace_sigsafe(int priority
, void *program_counter
)
436 #ifdef HAVE_STACK_TRACE
437 static const char pclabel
[] = "Program counter: ";
441 char *s
, **bt
= NULL
;
442 #define LOC s,buf+sizeof(buf)-s
444 #ifdef HAVE_GLIBC_BACKTRACE
445 if (((size
= backtrace(array
,sizeof(array
)/sizeof(array
[0]))) <= 0) ||
446 ((size_t)size
> sizeof(array
)/sizeof(array
[0])))
450 if (program_counter) \
452 write(FD, pclabel, sizeof(pclabel)-1); \
453 backtrace_symbols_fd(&program_counter, 1, FD); \
455 write(FD, buf, s-buf); \
456 backtrace_symbols_fd(array, size, FD); \
458 #elif defined(HAVE_PRINTSTACK)
460 if (program_counter) \
461 write((FD), pclabel, sizeof(pclabel)-1); \
462 write((FD), buf, s-buf); \
465 #endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
468 s
= str_append(LOC
,"Backtrace for ");
469 s
= num_append(LOC
,size
);
470 s
= str_append(LOC
," stack frames:\n");
472 if ((logfile_fd
>= 0) || ((logfile_fd
= open_crashlog()) >= 0))
478 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_STDOUT
])
480 /* Remove trailing '\n' for monitor and syslog */
482 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
483 vty_log_fixed(buf
,s
-buf
);
484 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
485 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
488 #ifdef HAVE_GLIBC_BACKTRACE
489 bt
= backtrace_symbols(array
, size
);
491 /* Just print the function addresses. */
492 for (i
= 0; i
< size
; i
++)
496 s
= str_append(LOC
, bt
[i
]);
498 s
= str_append(LOC
,"[bt ");
499 s
= num_append(LOC
,i
);
500 s
= str_append(LOC
,"] 0x");
501 s
= hex_append(LOC
,(u_long
)(array
[i
]));
504 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_MONITOR
])
505 vty_log_fixed(buf
,s
-buf
);
506 if (priority
<= zlog_default
->maxlvl
[ZLOG_DEST_SYSLOG
])
507 syslog_sigsafe(priority
|zlog_default
->facility
,buf
,s
-buf
);
515 #endif /* HAVE_STRACK_TRACE */
519 zlog_backtrace(int priority
)
521 #ifndef HAVE_GLIBC_BACKTRACE
522 zlog(NULL
, priority
, "No backtrace available on this platform.");
528 if (((size
= backtrace(array
,sizeof(array
)/sizeof(array
[0]))) <= 0) ||
529 ((size_t)size
> sizeof(array
)/sizeof(array
[0])))
531 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
532 "(valid range is between 1 and %lu)",
533 size
, (unsigned long)(sizeof(array
)/sizeof(array
[0])));
536 zlog(NULL
, priority
, "Backtrace for %d stack frames:", size
);
537 if (!(strings
= backtrace_symbols(array
, size
)))
539 zlog_err("Cannot get backtrace symbols (out of memory?)");
540 for (i
= 0; i
< size
; i
++)
541 zlog(NULL
, priority
, "[bt %d] %p",i
,array
[i
]);
545 for (i
= 0; i
< size
; i
++)
546 zlog(NULL
, priority
, "[bt %d] %s",i
,strings
[i
]);
549 #endif /* HAVE_GLIBC_BACKTRACE */
553 zlog (struct zlog
*zl
, int priority
, const char *format
, ...)
557 va_start(args
, format
);
558 vzlog (zl
, priority
, format
, args
);
562 #define ZLOG_FUNC(FUNCNAME,PRIORITY) \
564 FUNCNAME(const char *format, ...) \
567 va_start(args, format); \
568 vzlog (NULL, PRIORITY, format, args); \
572 ZLOG_FUNC(zlog_err
, LOG_ERR
)
574 ZLOG_FUNC(zlog_warn
, LOG_WARNING
)
576 ZLOG_FUNC(zlog_info
, LOG_INFO
)
578 ZLOG_FUNC(zlog_notice
, LOG_NOTICE
)
580 ZLOG_FUNC(zlog_debug
, LOG_DEBUG
)
584 #define PLOG_FUNC(FUNCNAME,PRIORITY) \
586 FUNCNAME(struct zlog *zl, const char *format, ...) \
589 va_start(args, format); \
590 vzlog (zl, PRIORITY, format, args); \
594 PLOG_FUNC(plog_err
, LOG_ERR
)
596 PLOG_FUNC(plog_warn
, LOG_WARNING
)
598 PLOG_FUNC(plog_info
, LOG_INFO
)
600 PLOG_FUNC(plog_notice
, LOG_NOTICE
)
602 PLOG_FUNC(plog_debug
, LOG_DEBUG
)
607 _zlog_assert_failed (const char *assertion
, const char *file
,
608 unsigned int line
, const char *function
)
610 /* Force fallback file logging? */
611 if (zlog_default
&& !zlog_default
->fp
&&
612 ((logfile_fd
= open_crashlog()) >= 0) &&
613 ((zlog_default
->fp
= fdopen(logfile_fd
, "w")) != NULL
))
614 zlog_default
->maxlvl
[ZLOG_DEST_FILE
] = LOG_ERR
;
615 zlog(NULL
, LOG_CRIT
, "Assertion `%s' failed in file %s, line %u, function %s",
616 assertion
,file
,line
,(function
? function
: "?"));
617 zlog_backtrace(LOG_CRIT
);
622 /* Open log stream */
624 openzlog (const char *progname
, zlog_proto_t protocol
,
625 int syslog_flags
, int syslog_facility
)
630 zl
= XCALLOC(MTYPE_ZLOG
, sizeof (struct zlog
));
632 zl
->ident
= progname
;
633 zl
->protocol
= protocol
;
634 zl
->facility
= syslog_facility
;
635 zl
->syslog_options
= syslog_flags
;
637 /* Set default logging levels. */
638 for (i
= 0; i
< sizeof(zl
->maxlvl
)/sizeof(zl
->maxlvl
[0]); i
++)
639 zl
->maxlvl
[i
] = ZLOG_DISABLED
;
640 zl
->maxlvl
[ZLOG_DEST_MONITOR
] = LOG_DEBUG
;
641 zl
->default_lvl
= LOG_DEBUG
;
643 openlog (progname
, syslog_flags
, zl
->facility
);
649 closezlog (struct zlog
*zl
)
656 if (zl
->filename
!= NULL
)
659 XFREE (MTYPE_ZLOG
, zl
);
662 /* Called from command.c. */
664 zlog_set_level (struct zlog
*zl
, zlog_dest_t dest
, int log_level
)
669 zl
->maxlvl
[dest
] = log_level
;
673 zlog_set_file (struct zlog
*zl
, const char *filename
, int log_level
)
678 /* There is opend file. */
679 zlog_reset_file (zl
);
681 /* Set default zl. */
686 oldumask
= umask (0777 & ~LOGFILE_MASK
);
687 fp
= fopen (filename
, "a");
693 zl
->filename
= strdup (filename
);
694 zl
->maxlvl
[ZLOG_DEST_FILE
] = log_level
;
696 logfile_fd
= fileno(fp
);
701 /* Reset opend file. */
703 zlog_reset_file (struct zlog
*zl
)
712 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
721 /* Reopen log file. */
723 zlog_rotate (struct zlog
*zl
)
734 level
= zl
->maxlvl
[ZLOG_DEST_FILE
];
735 zl
->maxlvl
[ZLOG_DEST_FILE
] = ZLOG_DISABLED
;
742 oldumask
= umask (0777 & ~LOGFILE_MASK
);
743 zl
->fp
= fopen (zl
->filename
, "a");
748 zlog_err("Log rotate failed: cannot open file %s for append: %s",
749 zl
->filename
, safe_strerror(save_errno
));
752 logfile_fd
= fileno(zl
->fp
);
753 zl
->maxlvl
[ZLOG_DEST_FILE
] = level
;
759 /* Message lookup function. */
761 lookup (const struct message
*mes
, int key
)
763 const struct message
*pnt
;
765 for (pnt
= mes
; pnt
->key
!= 0; pnt
++)
772 /* Older/faster version of message lookup function, but requires caller to pass
773 * in the array size (instead of relying on a 0 key to terminate the search).
775 * The return value is the message string if found, or the 'none' pointer
776 * provided otherwise.
779 mes_lookup (const struct message
*meslist
, int max
, int index
, const char *none
)
781 int pos
= index
- meslist
[0].key
;
783 /* first check for best case: index is in range and matches the key
784 * value in that slot.
785 * NB: key numbering might be offset from 0. E.g. protocol constants
788 if ((pos
>= 0) && (pos
< max
)
789 && (meslist
[pos
].key
== index
))
790 return meslist
[pos
].str
;
792 /* fall back to linear search */
796 for (i
= 0; i
< max
; i
++, meslist
++)
798 if (meslist
->key
== index
)
800 const char *str
= (meslist
->str
? meslist
->str
: none
);
802 zlog_debug ("message index %d [%s] found in position %d (max is %d)",
808 zlog_err("message index %d not found (max is %d)", index
, max
);
813 /* Wrapper around strerror to handle case where it returns NULL. */
815 safe_strerror(int errnum
)
817 const char *s
= strerror(errnum
);
818 return (s
!= NULL
) ? s
: "Unknown error";
821 struct zebra_desc_table
828 #define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
829 static const struct zebra_desc_table route_types
[] = {
830 DESC_ENTRY (ZEBRA_ROUTE_SYSTEM
, "system", 'X' ),
831 DESC_ENTRY (ZEBRA_ROUTE_KERNEL
, "kernel", 'K' ),
832 DESC_ENTRY (ZEBRA_ROUTE_CONNECT
, "connected", 'C' ),
833 DESC_ENTRY (ZEBRA_ROUTE_STATIC
, "static", 'S' ),
834 DESC_ENTRY (ZEBRA_ROUTE_RIP
, "rip", 'R' ),
835 DESC_ENTRY (ZEBRA_ROUTE_RIPNG
, "ripng", 'R' ),
836 DESC_ENTRY (ZEBRA_ROUTE_OSPF
, "ospf", 'O' ),
837 DESC_ENTRY (ZEBRA_ROUTE_OSPF6
, "ospf6", 'O' ),
838 DESC_ENTRY (ZEBRA_ROUTE_ISIS
, "isis", 'I' ),
839 DESC_ENTRY (ZEBRA_ROUTE_BGP
, "bgp", 'B' ),
840 DESC_ENTRY (ZEBRA_ROUTE_HSLS
, "hsls", 'H' ),
844 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
845 static const struct zebra_desc_table command_types
[] = {
846 DESC_ENTRY (ZEBRA_INTERFACE_ADD
),
847 DESC_ENTRY (ZEBRA_INTERFACE_DELETE
),
848 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_ADD
),
849 DESC_ENTRY (ZEBRA_INTERFACE_ADDRESS_DELETE
),
850 DESC_ENTRY (ZEBRA_INTERFACE_UP
),
851 DESC_ENTRY (ZEBRA_INTERFACE_DOWN
),
852 DESC_ENTRY (ZEBRA_IPV4_ROUTE_ADD
),
853 DESC_ENTRY (ZEBRA_IPV4_ROUTE_DELETE
),
854 DESC_ENTRY (ZEBRA_IPV6_ROUTE_ADD
),
855 DESC_ENTRY (ZEBRA_IPV6_ROUTE_DELETE
),
856 DESC_ENTRY (ZEBRA_REDISTRIBUTE_ADD
),
857 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DELETE
),
858 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_ADD
),
859 DESC_ENTRY (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
),
860 DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP
),
861 DESC_ENTRY (ZEBRA_IPV6_NEXTHOP_LOOKUP
),
862 DESC_ENTRY (ZEBRA_IPV4_IMPORT_LOOKUP
),
863 DESC_ENTRY (ZEBRA_IPV6_IMPORT_LOOKUP
),
864 DESC_ENTRY (ZEBRA_INTERFACE_RENAME
),
865 DESC_ENTRY (ZEBRA_ROUTER_ID_ADD
),
866 DESC_ENTRY (ZEBRA_ROUTER_ID_DELETE
),
867 DESC_ENTRY (ZEBRA_ROUTER_ID_UPDATE
),
871 static const struct zebra_desc_table unknown
= { 0, "unknown", '?' };
873 static const struct zebra_desc_table
*
874 zroute_lookup(u_int zroute
)
878 if (zroute
>= sizeof(route_types
)/sizeof(route_types
[0]))
880 zlog_err("unknown zebra route type: %u", zroute
);
883 if (zroute
== route_types
[zroute
].type
)
884 return &route_types
[zroute
];
885 for (i
= 0; i
< sizeof(route_types
)/sizeof(route_types
[0]); i
++)
887 if (zroute
== route_types
[i
].type
)
889 zlog_warn("internal error: route type table out of order "
890 "while searching for %u, please notify developers", zroute
);
891 return &route_types
[i
];
894 zlog_err("internal error: cannot find route type %u in table!", zroute
);
899 zebra_route_string(u_int zroute
)
901 return zroute_lookup(zroute
)->string
;
905 zebra_route_char(u_int zroute
)
907 return zroute_lookup(zroute
)->chr
;
911 zserv_command_string (unsigned int command
)
913 if (command
>= sizeof(command_types
)/sizeof(command_types
[0]))
915 zlog_err ("unknown zserv command type: %u", command
);
916 return unknown
.string
;
918 return command_types
[command
].string
;
921 #define RTSIZE (sizeof(route_types)/sizeof(route_types[0]))
924 proto_name2num(const char *s
)
928 for (i
=0; i
<RTSIZE
; ++i
)
929 if (strcasecmp(s
, route_types
[i
].string
) == 0)
930 return route_types
[i
].type
;