]>
git.proxmox.com Git - mirror_frr.git/blob - ldpd/log.c
4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 static const char * const procnames
[] = {
35 void vlog(int, const char *, va_list);
38 logit(int pri
, const char *fmt
, ...)
48 vlog(int pri
, const char *fmt
, va_list ap
)
52 switch (ldpd_process
) {
54 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
55 lde_imsg_compose_parent(IMSG_LOG
, pri
, buf
, strlen(buf
) + 1);
58 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
59 ldpe_imsg_compose_parent(IMSG_LOG
, pri
, buf
, strlen(buf
) + 1);
62 vzlog(NULL
, pri
, fmt
, ap
);
68 log_warn(const char *emsg
, ...)
73 /* best effort to even work in out of memory situations */
75 logit(LOG_CRIT
, "%s", strerror(errno
));
79 if (asprintf(&nfmt
, "%s: %s", emsg
, strerror(errno
)) == -1) {
81 vlog(LOG_CRIT
, emsg
, ap
);
82 logit(LOG_CRIT
, "%s", strerror(errno
));
84 vlog(LOG_CRIT
, nfmt
, ap
);
92 log_warnx(const char *emsg
, ...)
97 vlog(LOG_CRIT
, emsg
, ap
);
102 log_info(const char *emsg
, ...)
107 vlog(LOG_INFO
, emsg
, ap
);
112 log_notice(const char *emsg
, ...)
117 vlog(LOG_NOTICE
, emsg
, ap
);
122 log_debug(const char *emsg
, ...)
127 vlog(LOG_DEBUG
, emsg
, ap
);
132 fatal(const char *emsg
)
135 logit(LOG_CRIT
, "fatal in %s: %s", procnames
[ldpd_process
],
139 logit(LOG_CRIT
, "fatal in %s: %s: %s",
140 procnames
[ldpd_process
], emsg
, strerror(errno
));
142 logit(LOG_CRIT
, "fatal in %s: %s",
143 procnames
[ldpd_process
], emsg
);
149 fatalx(const char *emsg
)
157 log_sockaddr(void *vp
)
159 static char buf
[NUM_LOGS
][NI_MAXHOST
];
160 static int round
= 0;
161 struct sockaddr
*sa
= vp
;
163 round
= (round
+ 1) % NUM_LOGS
;
165 if (getnameinfo(sa
, sockaddr_len(sa
), buf
[round
], NI_MAXHOST
, NULL
, 0,
167 return ("(unknown)");
173 log_in6addr(const struct in6_addr
*addr
)
175 struct sockaddr_in6 sa_in6
;
177 memset(&sa_in6
, 0, sizeof(sa_in6
));
178 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
179 sa_in6
.sin6_len
= sizeof(sa_in6
);
181 sa_in6
.sin6_family
= AF_INET6
;
182 sa_in6
.sin6_addr
= *addr
;
184 recoverscope(&sa_in6
);
186 return (log_sockaddr(&sa_in6
));
190 log_in6addr_scope(const struct in6_addr
*addr
, unsigned int ifindex
)
192 struct sockaddr_in6 sa_in6
;
194 memset(&sa_in6
, 0, sizeof(sa_in6
));
195 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
196 sa_in6
.sin6_len
= sizeof(sa_in6
);
198 sa_in6
.sin6_family
= AF_INET6
;
199 sa_in6
.sin6_addr
= *addr
;
201 addscope(&sa_in6
, ifindex
);
203 return (log_sockaddr(&sa_in6
));
207 log_addr(int af
, const union ldpd_addr
*addr
)
209 static char buf
[NUM_LOGS
][INET6_ADDRSTRLEN
];
210 static int round
= 0;
214 round
= (round
+ 1) % NUM_LOGS
;
215 if (inet_ntop(AF_INET
, &addr
->v4
, buf
[round
],
216 sizeof(buf
[round
])) == NULL
)
220 return (log_in6addr(&addr
->v6
));
232 log_label(uint32_t label
)
235 static char tfbuf
[TF_BUFS
][TF_LEN
]; /* ring buffer */
244 snprintf(buf
, TF_LEN
, "-");
246 case MPLS_LABEL_IMPLNULL
:
247 snprintf(buf
, TF_LEN
, "imp-null");
249 case MPLS_LABEL_IPV4NULL
:
250 case MPLS_LABEL_IPV6NULL
:
251 snprintf(buf
, TF_LEN
, "exp-null");
254 snprintf(buf
, TF_LEN
, "%u", label
);
265 static char tfbuf
[TF_BUFS
][TF_LEN
]; /* ring buffer */
267 unsigned int sec
, min
, hrs
, day
, week
;
285 snprintf(buf
, TF_LEN
, "%02uw%01ud%02uh", week
, day
, hrs
);
287 snprintf(buf
, TF_LEN
, "%01ud%02uh%02um", day
, hrs
, min
);
289 snprintf(buf
, TF_LEN
, "%02u:%02u:%02u", hrs
, min
, sec
);
295 log_hello_src(const struct hello_source
*src
)
301 snprintf(buf
, sizeof(buf
), "iface %s",
302 src
->link
.ia
->iface
->name
);
305 snprintf(buf
, sizeof(buf
), "source %s",
306 log_addr(src
->target
->af
, &src
->target
->addr
));
314 log_map(const struct map
*map
)
316 static char buf
[128];
319 case MAP_TYPE_WILDCARD
:
320 if (snprintf(buf
, sizeof(buf
), "wildcard") < 0)
323 case MAP_TYPE_PREFIX
:
324 if (snprintf(buf
, sizeof(buf
), "%s/%u",
325 log_addr(map
->fec
.prefix
.af
, &map
->fec
.prefix
.prefix
),
326 map
->fec
.prefix
.prefixlen
) == -1)
330 if (snprintf(buf
, sizeof(buf
), "pw-id %u group-id %u (%s)",
331 map
->fec
.pwid
.pwid
, map
->fec
.pwid
.group_id
,
332 pw_type_name(map
->fec
.pwid
.type
)) == -1)
343 log_fec(const struct fec
*fec
)
346 union ldpd_addr addr
;
350 addr
.v4
= fec
->u
.ipv4
.prefix
;
351 if (snprintf(buf
, sizeof(buf
), "ipv4 %s/%u",
352 log_addr(AF_INET
, &addr
), fec
->u
.ipv4
.prefixlen
) == -1)
356 addr
.v6
= fec
->u
.ipv6
.prefix
;
357 if (snprintf(buf
, sizeof(buf
), "ipv6 %s/%u",
358 log_addr(AF_INET6
, &addr
), fec
->u
.ipv6
.prefixlen
) == -1)
362 if (snprintf(buf
, sizeof(buf
),
364 fec
->u
.pwid
.pwid
, pw_type_name(fec
->u
.pwid
.type
),
365 inet_ntoa(fec
->u
.pwid
.lsr_id
)) == -1)
394 socket_name(int type
)
397 case LDP_SOCKET_DISC
:
398 return ("discovery");
399 case LDP_SOCKET_EDISC
:
400 return ("extended discovery");
401 case LDP_SOCKET_SESSION
:
409 nbr_state_name(int state
)
412 case NBR_STA_PRESENT
:
414 case NBR_STA_INITIAL
:
415 return ("INITIALIZED");
416 case NBR_STA_OPENREC
:
418 case NBR_STA_OPENSENT
:
421 return ("OPERATIONAL");
428 if_state_name(int state
)
441 if_type_name(enum iface_type type
)
444 case IF_TYPE_POINTOPOINT
:
445 return ("POINTOPOINT");
446 case IF_TYPE_BROADCAST
:
447 return ("BROADCAST");
454 msg_name(uint16_t msg
)
459 case MSG_TYPE_NOTIFICATION
:
460 return ("notification");
464 return ("initialization");
465 case MSG_TYPE_KEEPALIVE
:
466 return ("keepalive");
467 case MSG_TYPE_CAPABILITY
:
468 return ("capability");
471 case MSG_TYPE_ADDRWITHDRAW
:
472 return ("address withdraw");
473 case MSG_TYPE_LABELMAPPING
:
474 return ("label mapping");
475 case MSG_TYPE_LABELREQUEST
:
476 return ("label request");
477 case MSG_TYPE_LABELWITHDRAW
:
478 return ("label withdraw");
479 case MSG_TYPE_LABELRELEASE
:
480 return ("label release");
481 case MSG_TYPE_LABELABORTREQ
:
483 snprintf(buf
, sizeof(buf
), "[%08x]", msg
);
489 status_code_name(uint32_t status
)
497 return ("Bad LDP Identifier");
498 case S_BAD_PROTO_VER
:
499 return ("Bad Protocol Version");
501 return ("Bad PDU Length");
503 return ("Unknown Message Type");
505 return ("Bad Message Length");
507 return ("Unknown TLV");
509 return ("Bad TLV Length");
511 return ("Malformed TLV Value");
513 return ("Hold Timer Expired");
516 case S_LOOP_DETECTED
:
517 return ("Loop Detected");
519 return ("Unknown FEC");
523 return ("No Label Resources");
525 return ("Label Resources Available");
527 return ("Session Rejected, No Hello");
528 case S_PARM_ADV_MODE
:
529 return ("Rejected Advertisement Mode Parameter");
531 return ("Rejected Max PDU Length Parameter");
533 return ("Rejected Label Range Parameter");
534 case S_KEEPALIVE_TMR
:
535 return ("KeepAlive Timer Expired");
537 return ("Label Request Aborted");
539 return ("Missing Message Parameters");
541 return ("Unsupported Address Family");
542 case S_KEEPALIVE_BAD
:
543 return ("Bad KeepAlive Time");
545 return ("Internal Error");
547 return ("Illegal C-Bit");
549 return ("Wrong C-Bit");
550 case S_INCPT_BITRATE
:
551 return ("Incompatible bit-rate");
553 return ("CEP-TDM mis-configuration");
555 return ("PW Status");
557 return ("Unassigned/Unrecognized TAI");
559 return ("Generic Misconfiguration Error");
560 case S_WITHDRAW_MTHD
:
561 return ("Label Withdraw PW Status Method");
562 case S_UNSSUPORTDCAP
:
563 return ("Unsupported Capability");
564 case S_TRANS_MISMTCH
:
565 return ("Transport Connection Mismatch");
566 case S_DS_NONCMPLNCE
:
567 return ("Dual-Stack Noncompliance");
569 snprintf(buf
, sizeof(buf
), "[%08x]", status
);
575 pw_type_name(uint16_t pw_type
)
580 case PW_TYPE_ETHERNET_TAGGED
:
581 return ("Eth Tagged");
582 case PW_TYPE_ETHERNET
:
585 snprintf(buf
, sizeof(buf
), "[%0x]", pw_type
);