-/* $OpenBSD: ldpctl.c,v 1.31 2016/05/23 19:06:03 renato Exp $
+/* $OpenBSD: ldpctl.c,v 1.32 2016/07/15 17:09:25 renato Exp $
*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
int show_l2vpn_binding_msg(struct imsg *);
const char *get_media_descr(uint64_t);
void print_baudrate(uint64_t);
-char *print_label(char **, uint32_t);
-const char *print_pw_type(uint16_t);
struct imsgbuf *ibuf;
show_lib_msg(struct imsg *imsg, struct parse_result *res)
{
struct ctl_rt *rt;
- char *dstnet, *local = NULL, *remote = NULL;
+ char *dstnet;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_LIB:
if (strlen(dstnet) > 20)
printf("\n%25s", " ");
printf(" %-15s %-11s %-13s %6s\n", inet_ntoa(rt->nexthop),
- print_label(&local, rt->local_label),
- print_label(&remote, rt->remote_label),
+ log_label(rt->local_label), log_label(rt->remote_label),
rt->in_use ? "yes" : "no");
- free(remote);
- free(local);
free(dstnet);
break;
case IMSG_CTL_END:
{
struct kroute *k;
char *p;
- char *local = NULL, *remote = NULL;
const char *nexthop;
switch (imsg->hdr.type) {
} else if (k->flags & F_CONNECTED)
printf("link#%-13u", k->ifindex);
- printf("%-18s", print_label(&local, k->local_label));
- printf("%s", print_label(&local, k->remote_label));
+ printf("%-18s", log_label(k->local_label));
+ printf("%s", log_label(k->remote_label));
printf("\n");
-
- free(remote);
- free(local);
break;
case IMSG_CTL_END:
printf("\n");
printf("Neighbor: %s - PWID: %u (%s)\n",
inet_ntoa(pw->lsr_id), pw->pwid,
- print_pw_type(pw->type));
+ pw_type_name(pw->type));
printf("%-12s%-15s%-15s%-10s\n", "", "Label", "Group-ID",
"MTU");
if (pw->local_label != NO_LABEL)
else
printf("%llu Bit/s", baudrate);
}
-
-char *
-print_label(char **string, uint32_t label)
-{
- if (label == NO_LABEL) {
- if (asprintf(string, "-") == -1)
- err(1, NULL);
- } else if (label == MPLS_LABEL_IMPLNULL) {
- if (asprintf(string, "imp-null") == -1)
- err(1, NULL);
- } else if (label == MPLS_LABEL_IPV4NULL ||
- label == MPLS_LABEL_IPV6NULL) {
- if (asprintf(string, "exp-null") == -1)
- err(1, NULL);
- } else {
- if (asprintf(string, "%u", label) == -1)
- err(1, NULL);
- }
-
- return (*string);
-}
-
-const char *
-print_pw_type(uint16_t pw_type)
-{
- static char buf[64];
-
- switch (pw_type) {
- case PW_TYPE_ETHERNET_TAGGED:
- return ("Eth Tagged");
- case PW_TYPE_ETHERNET:
- return ("Ethernet");
- default:
- snprintf(buf, sizeof(buf), "[%0x]", pw_type);
- return (buf);
- }
-}
-/* $OpenBSD: labelmapping.c,v 1.56 2016/07/15 17:05:50 renato Exp $ */
+/* $OpenBSD: labelmapping.c,v 1.57 2016/07/15 17:09:25 renato Exp $ */
/*
* Copyright (c) 2014, 2015 Renato Westphal <renato@openbsd.org>
switch (type) {
case MSG_TYPE_LABELMAPPING:
log_debug("label mapping from lsr-id %s, FEC %s, "
- "label %u", inet_ntoa(nbr->id),
- log_map(&me->map), me->map.label);
+ "label %s", inet_ntoa(nbr->id),
+ log_map(&me->map), log_label(me->map.label));
imsg_type = IMSG_LABEL_MAPPING;
break;
case MSG_TYPE_LABELREQUEST:
-/* $OpenBSD: ldp.h,v 1.33 2016/07/01 23:36:38 renato Exp $ */
+/* $OpenBSD: ldp.h,v 1.34 2016/07/15 17:09:25 renato Exp $ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
#define PW_PSN_RX_FAULT (1 << 3)
#define PW_PSN_TX_FAULT (1 << 4)
-#define NO_LABEL UINT_MAX
+#define NO_LABEL UINT32_MAX
#endif /* !_LDP_H_ */
-/* $OpenBSD: log.c,v 1.28 2016/07/01 23:36:38 renato Exp $ */
+/* $OpenBSD: log.c,v 1.29 2016/07/15 17:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+#include <sys/socket.h>
#include <arpa/inet.h>
+#include <netmpls/mpls.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <netdb.h>
+#include <limits.h>
#include "ldpd.h"
#include "ldpe.h"
return ("???");
}
+#define TF_BUFS 4
+#define TF_LEN 32
+
+char *
+log_label(uint32_t label)
+{
+ char *buf;
+ static char tfbuf[TF_BUFS][TF_LEN]; /* ring buffer */
+ static int idx = 0;
+
+ buf = tfbuf[idx++];
+ if (idx == TF_BUFS)
+ idx = 0;
+
+ switch (label) {
+ case NO_LABEL:
+ snprintf(buf, TF_LEN, "-");
+ break;
+ case MPLS_LABEL_IMPLNULL:
+ snprintf(buf, TF_LEN, "imp-null");
+ break;
+ case MPLS_LABEL_IPV4NULL:
+ case MPLS_LABEL_IPV6NULL:
+ snprintf(buf, TF_LEN, "exp-null");
+ break;
+ default:
+ snprintf(buf, TF_LEN, "%u", label);
+ break;
+ }
+
+ return (buf);
+}
+
+char *
+log_hello_src(const struct hello_source *src)
+{
+ static char buf[64];
+
+ switch (src->type) {
+ case HELLO_LINK:
+ snprintf(buf, sizeof(buf), "iface %s",
+ src->link.ia->iface->name);
+ break;
+ case HELLO_TARGETED:
+ snprintf(buf, sizeof(buf), "source %s",
+ log_addr(src->target->af, &src->target->addr));
+ break;
+ }
+
+ return (buf);
+}
+
+const char *
+log_map(const struct map *map)
+{
+ static char buf[64];
+ int af;
+
+ switch (map->type) {
+ case MAP_TYPE_WILDCARD:
+ if (snprintf(buf, sizeof(buf), "wildcard") < 0)
+ return ("???");
+ break;
+ case MAP_TYPE_PREFIX:
+ switch (map->fec.prefix.af) {
+ case AF_IPV4:
+ af = AF_INET;
+ break;
+ case AF_IPV6:
+ af = AF_INET6;
+ break;
+ default:
+ return ("???");
+ }
+
+ if (snprintf(buf, sizeof(buf), "%s/%u",
+ log_addr(af, &map->fec.prefix.prefix),
+ map->fec.prefix.prefixlen) == -1)
+ return ("???");
+ break;
+ case MAP_TYPE_PWID:
+ if (snprintf(buf, sizeof(buf), "pwid %u (%s)",
+ map->fec.pwid.pwid,
+ pw_type_name(map->fec.pwid.type)) == -1)
+ return ("???");
+ break;
+ default:
+ return ("???");
+ }
+
+ return (buf);
+}
+
+const char *
+log_fec(const struct fec *fec)
+{
+ static char buf[64];
+ union ldpd_addr addr;
+
+ switch (fec->type) {
+ case FEC_TYPE_IPV4:
+ addr.v4 = fec->u.ipv4.prefix;
+ if (snprintf(buf, sizeof(buf), "ipv4 %s/%u",
+ log_addr(AF_INET, &addr), fec->u.ipv4.prefixlen) == -1)
+ return ("???");
+ break;
+ case FEC_TYPE_IPV6:
+ addr.v6 = fec->u.ipv6.prefix;
+ if (snprintf(buf, sizeof(buf), "ipv6 %s/%u",
+ log_addr(AF_INET6, &addr), fec->u.ipv6.prefixlen) == -1)
+ return ("???");
+ break;
+ case FEC_TYPE_PWID:
+ if (snprintf(buf, sizeof(buf),
+ "pwid %u (%s) - %s",
+ fec->u.pwid.pwid, pw_type_name(fec->u.pwid.type),
+ inet_ntoa(fec->u.pwid.lsr_id)) == -1)
+ return ("???");
+ break;
+ default:
+ return ("???");
+ }
+
+ return (buf);
+}
+
/* names */
const char *
af_name(int af)
}
}
-char *
-log_hello_src(const struct hello_source *src)
-{
- static char buffer[64];
-
- switch (src->type) {
- case HELLO_LINK:
- snprintf(buffer, sizeof(buffer), "iface %s",
- src->link.ia->iface->name);
- break;
- case HELLO_TARGETED:
- snprintf(buffer, sizeof(buffer), "source %s",
- log_addr(src->target->af, &src->target->addr));
- break;
- }
-
- return (buffer);
-}
-
-const char *
-log_map(const struct map *map)
-{
- static char buf[64];
- int af;
-
- switch (map->type) {
- case MAP_TYPE_WILDCARD:
- if (snprintf(buf, sizeof(buf), "wildcard") < 0)
- return ("???");
- break;
- case MAP_TYPE_PREFIX:
- switch (map->fec.prefix.af) {
- case AF_IPV4:
- af = AF_INET;
- break;
- case AF_IPV6:
- af = AF_INET6;
- break;
- default:
- return ("???");
- }
-
- if (snprintf(buf, sizeof(buf), "%s/%u",
- log_addr(af, &map->fec.prefix.prefix),
- map->fec.prefix.prefixlen) == -1)
- return ("???");
- break;
- case MAP_TYPE_PWID:
- if (snprintf(buf, sizeof(buf), "pwid %u (%s)",
- map->fec.pwid.pwid,
- pw_type_name(map->fec.pwid.type)) == -1)
- return ("???");
- break;
- default:
- return ("???");
- }
-
- return (buf);
-}
-
-const char *
-log_fec(const struct fec *fec)
-{
- static char buf[64];
- union ldpd_addr addr;
-
- switch (fec->type) {
- case FEC_TYPE_IPV4:
- addr.v4 = fec->u.ipv4.prefix;
- if (snprintf(buf, sizeof(buf), "ipv4 %s/%u",
- log_addr(AF_INET, &addr), fec->u.ipv4.prefixlen) == -1)
- return ("???");
- break;
- case FEC_TYPE_IPV6:
- addr.v6 = fec->u.ipv6.prefix;
- if (snprintf(buf, sizeof(buf), "ipv6 %s/%u",
- log_addr(AF_INET6, &addr), fec->u.ipv6.prefixlen) == -1)
- return ("???");
- break;
- case FEC_TYPE_PWID:
- if (snprintf(buf, sizeof(buf),
- "pwid %u (%s) - %s",
- fec->u.pwid.pwid, pw_type_name(fec->u.pwid.type),
- inet_ntoa(fec->u.pwid.lsr_id)) == -1)
- return ("???");
- break;
- default:
- return ("???");
- }
-
- return (buf);
-}
-
static char *msgtypes[] = {
"",
"RTM_ADD: Add Route",
-/* $OpenBSD: log.h,v 1.12 2016/07/01 23:36:38 renato Exp $ */
+/* $OpenBSD: log.h,v 1.13 2016/07/15 17:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
const char *log_in6addr(const struct in6_addr *);
const char *log_in6addr_scope(const struct in6_addr *, unsigned int);
const char *log_addr(int, const union ldpd_addr *);
+char *log_label(uint32_t);
+char *log_hello_src(const struct hello_source *);
+const char *log_map(const struct map *);
+const char *log_fec(const struct fec *);
const char *af_name(int);
const char *socket_name(int);
const char *nbr_state_name(int);
const char *if_type_name(enum iface_type);
const char *status_code_name(uint32_t);
const char *pw_type_name(uint16_t);
-char *log_hello_src(const struct hello_source *);
-const char *log_map(const struct map *);
-const char *log_fec(const struct fec *);
void log_rtmsg(unsigned char);
#endif /* _LOG_H_ */