summaryrefslogtreecommitdiff
path: root/sbin/route/show.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2010-03-23 15:01:51 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2010-03-23 15:01:51 +0000
commite06673c1aacda501987dbaa94ca0d3e9cd5defb6 (patch)
tree55bba2dbcea6c7ae74686cd75f0a8340e59cb88b /sbin/route/show.c
parentd272a6541efacb3e00d7f8dd574f1d3e76e313df (diff)
Print MPLS information in route -n get and do some cleanup in the show code.
OK michele@
Diffstat (limited to 'sbin/route/show.c')
-rw-r--r--sbin/route/show.c65
1 files changed, 23 insertions, 42 deletions
diff --git a/sbin/route/show.c b/sbin/route/show.c
index e7852de2e83..0e1b54bb531 100644
--- a/sbin/route/show.c
+++ b/sbin/route/show.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.c,v 1.83 2010/01/13 23:49:06 claudio Exp $ */
+/* $OpenBSD: show.c,v 1.84 2010/03/23 15:01:50 claudio Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
@@ -59,8 +59,7 @@
char *any_ntoa(const struct sockaddr *);
char *link_print(struct sockaddr *);
-char *label_print_op(u_int32_t);
-char *label_print(struct sockaddr *, struct sockaddr *);
+char *label_print(struct sockaddr *);
extern int nflag;
extern int Fflag;
@@ -216,7 +215,7 @@ WID_DST(int af)
if (nflag)
switch (af) {
case AF_MPLS:
- return 34;
+ return 9;
case AF_INET6:
return 34;
default:
@@ -225,7 +224,7 @@ WID_DST(int af)
else
switch (af) {
case AF_MPLS:
- return 34;
+ return 9;
default:
return 18;
}
@@ -244,7 +243,7 @@ pr_rthdr(int af)
"Port", "Proto", "SA(Address/Proto/Type/Direction)");
break;
case PF_MPLS:
- printf("%-16s %-10s %-6s %-18s %-6.6s %5.5s %8.8s %5.5s %4.4s %s\n",
+ printf("%-9s %-9s %-6s %-18s %-6.6s %5.5s %8.8s %5.5s %4.4s %s\n",
"In label", "Out label", "Op", "Gateway",
"Flags", "Refs", "Use", "Mtu", "Prio", "Interface");
break;
@@ -551,15 +550,15 @@ p_sockaddr_mpls(struct sockaddr *in, struct sockaddr *out, int flags, int width)
if (in->sa_family != AF_MPLS)
return;
- if (flags & MPLS_OP_POP || flags == MPLS_OP_LOCAL)
- cp = label_print(in, NULL);
- else
- cp = label_print(in, out);
-
- snprintf(buf, MAXHOSTNAMELEN, "%s %s", cp,
- label_print_op(flags));
+ if (flags & MPLS_OP_POP || flags == MPLS_OP_LOCAL) {
+ printf("%-*s ", width, label_print(in));
+ printf("%-*s ", width, label_print(NULL));
+ } else {
+ printf("%-*s ", width, label_print(in));
+ printf("%-*s ", width, label_print(out));
+ }
- printf("%-*s ", width, buf);
+ printf("%-6s ", mpls_op(flags));
}
void
@@ -625,7 +624,7 @@ routename(struct sockaddr *sa)
case AF_LINK:
return (link_print(sa));
case AF_MPLS:
- return (label_print(sa, NULL));
+ return (label_print(sa));
case AF_UNSPEC:
if (sa->sa_len == sizeof(struct sockaddr_rtlabel)) {
static char name[RTLABEL_LEN];
@@ -833,7 +832,7 @@ netname(struct sockaddr *sa, struct sockaddr *mask)
case AF_LINK:
return (link_print(sa));
case AF_MPLS:
- return (label_print(sa, NULL));
+ return (label_print(sa));
default:
snprintf(line, sizeof(line), "af %d: %s",
sa->sa_family, any_ntoa(sa));
@@ -883,7 +882,7 @@ link_print(struct sockaddr *sa)
}
char *
-label_print_op(u_int32_t type)
+mpls_op(u_int32_t type)
{
switch (type & (MPLS_OP_PUSH | MPLS_OP_POP | MPLS_OP_SWAP)) {
case MPLS_OP_LOCAL:
@@ -900,33 +899,15 @@ label_print_op(u_int32_t type)
}
char *
-label_print(struct sockaddr *in, struct sockaddr *out)
+label_print(struct sockaddr *sa)
{
- struct sockaddr_mpls *insmpls = (struct sockaddr_mpls *)in;
- struct sockaddr_mpls *outsmpls = (struct sockaddr_mpls *)out;
- char ifname_in[IF_NAMESIZE];
- char ifname_out[IF_NAMESIZE];
- char *in_label;
- char *out_label;
-
- if (asprintf(&in_label, "%u",
- ntohl(insmpls->smpls_label) >> MPLS_LABEL_OFFSET) == -1)
- err(1, NULL);
-
- if (outsmpls) {
- if (asprintf(&out_label, "%u",
- ntohl(outsmpls->smpls_label) >> MPLS_LABEL_OFFSET) == -1)
- err(1, NULL);
- } else {
- if (asprintf(&out_label, "-") == -1)
- err(1, NULL);
- }
-
- (void)snprintf(line, sizeof(line), "%-16s %-10s", in_label,
- out_label);
+ struct sockaddr_mpls *smpls = (struct sockaddr_mpls *)sa;
- free(in_label);
- free(out_label);
+ if (smpls)
+ (void)snprintf(line, sizeof(line), "%u",
+ ntohl(smpls->smpls_label) >> MPLS_LABEL_OFFSET);
+ else
+ (void)snprintf(line, sizeof(line), "-");
return (line);
}