summaryrefslogtreecommitdiff
path: root/sbin/route
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
parentd272a6541efacb3e00d7f8dd574f1d3e76e313df (diff)
Print MPLS information in route -n get and do some cleanup in the show code.
OK michele@
Diffstat (limited to 'sbin/route')
-rw-r--r--sbin/route/route.c12
-rw-r--r--sbin/route/show.c65
-rw-r--r--sbin/route/show.h3
3 files changed, 35 insertions, 45 deletions
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 58b78246346..4978eebf236 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.141 2009/12/01 16:21:46 reyk Exp $ */
+/* $OpenBSD: route.c,v 1.142 2010/03/23 15:01:50 claudio Exp $ */
/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */
/*
@@ -1206,7 +1206,7 @@ char ifnetflags[] =
"\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6NOTRAILERS\7RUNNING\010NOARP\011PPROMISC"
"\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1\017LINK2\020MULTICAST";
char addrnames[] =
-"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD\013LABEL";
+"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD\011SRC\12SRCMASK\013LABEL";
const char *
get_linkstate(int mt, int link_state)
@@ -1325,6 +1325,7 @@ print_getmsg(struct rt_msghdr *rtm, int msglen)
struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
struct sockaddr_dl *ifp = NULL;
struct sockaddr_rtlabel *sa_rl = NULL;
+ struct sockaddr *mpls = NULL;
struct sockaddr *sa;
char *cp;
int i;
@@ -1366,6 +1367,9 @@ print_getmsg(struct rt_msghdr *rtm, int msglen)
((struct sockaddr_dl *)sa)->sdl_nlen)
ifp = (struct sockaddr_dl *)sa;
break;
+ case RTA_SRC:
+ mpls = sa;
+ break;
case RTA_LABEL:
sa_rl = (struct sockaddr_rtlabel *)sa;
break;
@@ -1390,6 +1394,10 @@ print_getmsg(struct rt_msghdr *rtm, int msglen)
ifp->sdl_nlen, ifp->sdl_data);
if (ifa)
printf(" if address: %s\n", routename(ifa));
+ if (mpls) {
+ printf(" mpls label: %s %s\n", mpls_op(rtm->rtm_mpls),
+ routename(mpls));
+ }
printf(" priority: %u (%s)\n", rtm->rtm_priority,
priorityname(rtm->rtm_priority));
printf(" flags: ");
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);
}
diff --git a/sbin/route/show.h b/sbin/route/show.h
index 54e24c2f13f..a5a5c139a4d 100644
--- a/sbin/route/show.h
+++ b/sbin/route/show.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.h,v 1.6 2006/06/16 17:46:43 henning Exp $ */
+/* $OpenBSD: show.h,v 1.7 2010/03/23 15:01:50 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -22,5 +22,6 @@
void p_rttables(int, u_int);
char *routename(struct sockaddr *);
char *netname(struct sockaddr *, struct sockaddr *);
+char *mpls_op(u_int32_t);
#endif /* __SHOW_H__ */