summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2009-09-14 11:49:26 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2009-09-14 11:49:26 +0000
commit15a3e8853859cbe52bda8c7a38613274f7e374df (patch)
tree024009d39085a463f5745768912a2aa25f6d8312 /usr.sbin
parent59b6c9cab8ebff096556ff3792cd31dae17bd54d (diff)
Switch the various link state printing codes to use the new if_media
independent LINK_STATE_DESCRIPTIONS. Code is now more or less a one to one copy of get_linkstate() in route/route.c. OK henning, michele, sthen, deraadt
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpctl/bgpctl.c64
-rw-r--r--usr.sbin/dvmrpctl/dvmrpctl.c40
-rw-r--r--usr.sbin/ldpctl/ldpctl.c60
-rw-r--r--usr.sbin/ospf6ctl/ospf6ctl.c38
-rw-r--r--usr.sbin/ospfctl/ospfctl.c63
-rw-r--r--usr.sbin/ripctl/ripctl.c60
6 files changed, 102 insertions, 223 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index 1e0bb751a36..7fbf1598e70 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.145 2009/07/23 14:55:25 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.146 2009/09/14 11:49:25 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -860,7 +860,6 @@ show_nexthop_msg(struct imsg *imsg)
struct kroute *k;
struct kroute6 *k6;
char *s;
- int ifms_type;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NEXTHOP:
@@ -899,19 +898,13 @@ show_nexthop_msg(struct imsg *imsg)
}
if (p->kif.ifname[0]) {
char *s1;
- ifms_type = ift2ifm(p->kif.media_type);
- if (LINK_STATE_IS_UP(p->kif.link_state)) {
- if (p->kif.baudrate) {
- if (asprintf(&s1, ", %s",
- get_baudrate(p->kif.baudrate,
- "bps")) == -1)
- err(1, NULL);
- } else if (asprintf(&s1, ", %s", get_linkstate(
- ifms_type, p->kif.link_state)) == -1)
- err(1, NULL);
- } else if (ifms_type)
- if (asprintf(&s1, ", %s", get_linkstate(
- ifms_type, p->kif.link_state)) == -1)
+ if (p->kif.baudrate) {
+ if (asprintf(&s1, ", %s",
+ get_baudrate(p->kif.baudrate,
+ "bps")) == -1)
+ err(1, NULL);
+ } else if (asprintf(&s1, ", %s", get_linkstate(
+ p->kif.media_type, p->kif.link_state)) == -1)
err(1, NULL);
if (asprintf(&s, "%s (%s%s)", p->kif.ifname,
p->kif.flags & IFF_UP ? "UP" : "DOWN", s1) == -1)
@@ -940,9 +933,8 @@ show_interface_head(void)
"Link state");
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -978,23 +970,15 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown link state");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
const char *
@@ -1032,16 +1016,12 @@ show_interface_msg(struct imsg *imsg)
printf("%-15s", k->flags & IFF_UP ? "UP" : "");
if ((ifms_type = ift2ifm(k->media_type)) != 0)
- printf("%s, %s", get_media_descr(ifms_type),
- get_linkstate(ifms_type, k->link_state));
- else if (k->link_state == LINK_STATE_UNKNOWN)
- printf("unknown");
- else
- printf("link state %u", k->link_state);
+ printf("%s, ", get_media_descr(ifms_type));
- if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) {
+ printf("%s", get_linkstate(k->media_type, k->link_state));
+
+ if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0)
printf(", %s", get_baudrate(k->baudrate, "Bit/s"));
- }
printf("\n");
break;
case IMSG_CTL_END:
diff --git a/usr.sbin/dvmrpctl/dvmrpctl.c b/usr.sbin/dvmrpctl/dvmrpctl.c
index 6cac076e5a3..5671258d51e 100644
--- a/usr.sbin/dvmrpctl/dvmrpctl.c
+++ b/usr.sbin/dvmrpctl/dvmrpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dvmrpctl.c,v 1.7 2009/06/06 07:52:04 pyr Exp $ */
+/* $OpenBSD: dvmrpctl.c,v 1.8 2009/09/14 11:49:25 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -279,8 +279,8 @@ show_interface_msg(struct imsg *imsg)
iface->name, netid, if_state_name(iface->state),
iface->probe_timer == 0 ? "00:00:00" :
fmt_timeframe_core(iface->probe_timer),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate), iface->uptime == 0 ? "00:00:00" :
+ get_linkstate(iface->mediatype, iface->linkstate),
+ iface->uptime == 0 ? "00:00:00" :
fmt_timeframe_core(iface->uptime), iface->group_cnt);
free(netid);
break;
@@ -310,8 +310,7 @@ show_interface_detail_msg(struct imsg *imsg)
inet_ntoa(iface->addr),
mask2prefixlen(iface->mask.s_addr));
printf(" Linkstate %s\n",
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate));
+ get_linkstate(iface->mediatype, iface->linkstate));
printf(" Network type %s, cost: %d\n",
if_type_name(iface->type), iface->metric);
printf(" State %s, querier ", if_state_name(iface->state));
@@ -652,30 +651,19 @@ show_mfc_detail_msg(struct imsg *imsg)
return (0);
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
-const struct ifmedia_description
- ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown link state");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
diff --git a/usr.sbin/ldpctl/ldpctl.c b/usr.sbin/ldpctl/ldpctl.c
index 205da0ac94b..05a0e6e91af 100644
--- a/usr.sbin/ldpctl/ldpctl.c
+++ b/usr.sbin/ldpctl/ldpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpctl.c,v 1.4 2009/08/02 16:19:17 michele Exp $
+/* $OpenBSD: ldpctl.c,v 1.5 2009/09/14 11:49:25 claudio Exp $
*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -289,8 +289,8 @@ show_interface_msg(struct imsg *imsg)
err(1, NULL);
printf("%-11s %-18s %-10s %-10s %-8s\n",
iface->name, netid, if_state_name(iface->state),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate), iface->uptime == 0 ? "00:00:00" :
+ get_linkstate(iface->mediatype, iface->linkstate),
+ iface->uptime == 0 ? "00:00:00" :
fmt_timeframe_core(iface->uptime));
free(netid);
break;
@@ -461,28 +461,11 @@ show_lfib_interface_msg(struct imsg *imsg)
k = imsg->data;
printf("%-15s", k->ifname);
printf("%-15s", k->flags & IFF_UP ? "UP" : "");
- switch (k->media_type) {
- case IFT_ETHER:
- ifms_type = IFM_ETHER;
- break;
- case IFT_FDDI:
- ifms_type = IFM_FDDI;
- break;
- case IFT_CARP:
- ifms_type = IFM_CARP;
- break;
- default:
- ifms_type = 0;
- break;
- }
-
+ ifms_type = get_ifms_type(k->media_type);
if (ifms_type)
- printf("%s, %s", get_media_descr(ifms_type),
- get_linkstate(ifms_type, k->link_state));
- else if (k->link_state == LINK_STATE_UNKNOWN)
- printf("unknown");
- else
- printf("link state %u", k->link_state);
+ printf("%s, ", get_media_descr(ifms_type));
+
+ printf("%s", get_linkstate(k->media_type, k->link_state));
if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) {
printf(", ");
@@ -500,9 +483,8 @@ show_lfib_interface_msg(struct imsg *imsg)
return (0);
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -521,23 +503,15 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown link state");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
void
diff --git a/usr.sbin/ospf6ctl/ospf6ctl.c b/usr.sbin/ospf6ctl/ospf6ctl.c
index 9d8f436797e..952bf332290 100644
--- a/usr.sbin/ospf6ctl/ospf6ctl.c
+++ b/usr.sbin/ospf6ctl/ospf6ctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6ctl.c,v 1.28 2009/07/28 19:05:22 claudio Exp $ */
+/* $OpenBSD: ospf6ctl.c,v 1.29 2009/09/14 11:49:25 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -348,8 +348,8 @@ show_interface_msg(struct imsg *imsg)
printf("%-11s %-29s %-6s %-10s %-10s %s\n",
iface->name, netid, if_state_name(iface->state),
fmt_timeframe_core(iface->hello_timer),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate), fmt_timeframe_core(iface->uptime));
+ get_linkstate(iface->mediatype, iface->linkstate),
+ fmt_timeframe_core(iface->uptime));
free(netid);
break;
case IMSG_CTL_END:
@@ -377,8 +377,7 @@ show_interface_detail_msg(struct imsg *imsg)
log_in6addr(&iface->addr), inet_ntoa(iface->area));
printf(" Link type %s, state %s",
get_media_descr(get_ifms_type(iface->mediatype)),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate));
+ get_linkstate(iface->mediatype, iface->linkstate));
if (iface->linkstate != LINK_STATE_DOWN &&
iface->baudrate > 0) {
printf(", ");
@@ -1231,9 +1230,8 @@ show_fib_msg(struct imsg *imsg)
return (0);
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -1252,23 +1250,15 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
void
diff --git a/usr.sbin/ospfctl/ospfctl.c b/usr.sbin/ospfctl/ospfctl.c
index 99a4ad8fc89..d770e5dbd92 100644
--- a/usr.sbin/ospfctl/ospfctl.c
+++ b/usr.sbin/ospfctl/ospfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfctl.c,v 1.48 2009/06/06 07:31:26 eric Exp $ */
+/* $OpenBSD: ospfctl.c,v 1.49 2009/09/14 11:49:25 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -377,8 +377,8 @@ show_interface_msg(struct imsg *imsg)
iface->name, netid, if_state_name(iface->state),
iface->hello_timer < 0 ? "-" :
fmt_timeframe_core(iface->hello_timer),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate), fmt_timeframe_core(iface->uptime),
+ get_linkstate(iface->mediatype, iface->linkstate),
+ fmt_timeframe_core(iface->uptime),
iface->nbr_cnt, iface->adj_cnt);
free(netid);
break;
@@ -408,8 +408,7 @@ show_interface_detail_msg(struct imsg *imsg)
mask2prefixlen(iface->mask.s_addr));
printf("Area %s\n", inet_ntoa(iface->area));
printf(" Linkstate %s\n",
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate));
+ get_linkstate(iface->mediatype, iface->linkstate));
printf(" Router ID %s, network type %s, cost: %d\n",
inet_ntoa(iface->rtr_id),
if_type_name(iface->type), iface->metric);
@@ -1177,9 +1176,8 @@ show_interface_head(void)
"Link state");
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -1198,23 +1196,15 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
void
@@ -1241,28 +1231,11 @@ show_fib_interface_msg(struct imsg *imsg)
k = imsg->data;
printf("%-15s", k->ifname);
printf("%-15s", k->flags & IFF_UP ? "UP" : "");
- switch (k->media_type) {
- case IFT_ETHER:
- ifms_type = IFM_ETHER;
- break;
- case IFT_FDDI:
- ifms_type = IFM_FDDI;
- break;
- case IFT_CARP:
- ifms_type = IFM_CARP;
- break;
- default:
- ifms_type = 0;
- break;
- }
-
+ ifms_type = get_ifms_type(k->media_type);
if (ifms_type)
- printf("%s, %s", get_media_descr(ifms_type),
- get_linkstate(ifms_type, k->link_state));
- else if (k->link_state == LINK_STATE_UNKNOWN)
- printf("unknown");
- else
- printf("link state %u", k->link_state);
+ printf("%s, ", get_media_descr(ifms_type));
+
+ printf("%s", get_linkstate(k->media_type, k->link_state));
if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) {
printf(", ");
diff --git a/usr.sbin/ripctl/ripctl.c b/usr.sbin/ripctl/ripctl.c
index 4578351568f..dc463d2b602 100644
--- a/usr.sbin/ripctl/ripctl.c
+++ b/usr.sbin/ripctl/ripctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripctl.c,v 1.8 2009/07/17 09:14:26 michele Exp $
+/* $OpenBSD: ripctl.c,v 1.9 2009/09/14 11:49:25 claudio Exp $
*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -288,8 +288,8 @@ show_interface_msg(struct imsg *imsg)
err(1, NULL);
printf("%-11s %-18s %-10s %-10s %-8s\n",
iface->name, netid, if_state_name(iface->state),
- get_linkstate(get_ifms_type(iface->mediatype),
- iface->linkstate), iface->uptime == 0 ? "00:00:00" :
+ get_linkstate(iface->mediatype, iface->linkstate),
+ iface->uptime == 0 ? "00:00:00" :
fmt_timeframe_core(iface->uptime));
free(netid);
break;
@@ -436,28 +436,11 @@ show_fib_interface_msg(struct imsg *imsg)
k = imsg->data;
printf("%-15s", k->ifname);
printf("%-15s", k->flags & IFF_UP ? "UP" : "");
- switch (k->media_type) {
- case IFT_ETHER:
- ifms_type = IFM_ETHER;
- break;
- case IFT_FDDI:
- ifms_type = IFM_FDDI;
- break;
- case IFT_CARP:
- ifms_type = IFM_CARP;
- break;
- default:
- ifms_type = 0;
- break;
- }
-
+ ifms_type = get_ifms_type(k->media_type);
if (ifms_type)
- printf("%s, %s", get_media_descr(ifms_type),
- get_linkstate(ifms_type, k->link_state));
- else if (k->link_state == LINK_STATE_UNKNOWN)
- printf("unknown");
- else
- printf("link state %u", k->link_state);
+ printf("%s, ", get_media_descr(ifms_type));
+
+ printf("%s", get_linkstate(k->media_type, k->link_state));
if (k->link_state != LINK_STATE_DOWN && k->baudrate > 0) {
printf(", ");
@@ -475,9 +458,8 @@ show_fib_interface_msg(struct imsg *imsg)
return (0);
}
-const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
-const struct ifmedia_status_description
- ifm_status_descriptions[] = IFM_STATUS_DESCRIPTIONS;
+const struct if_status_description
+ if_status_descriptions[] = LINK_STATE_DESCRIPTIONS;
const struct ifmedia_description
ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS;
@@ -496,23 +478,15 @@ get_media_descr(int media_type)
const char *
get_linkstate(int media_type, int link_state)
{
- const struct ifmedia_status_description *p;
- int i;
-
- if (link_state == LINK_STATE_UNKNOWN)
- return ("unknown");
-
- for (i = 0; ifm_status_valid_list[i] != 0; i++)
- for (p = ifm_status_descriptions; p->ifms_valid != 0; p++) {
- if (p->ifms_type != media_type ||
- p->ifms_valid != ifm_status_valid_list[i])
- continue;
- if (LINK_STATE_IS_UP(link_state))
- return (p->ifms_string[1]);
- return (p->ifms_string[0]);
- }
+ const struct if_status_description *p;
+ static char buf[8];
- return ("unknown link state");
+ for (p = if_status_descriptions; p->ifs_string != NULL; p++) {
+ if (LINK_STATE_DESC_MATCH(p, media_type, link_state))
+ return (p->ifs_string);
+ }
+ snprintf(buf, sizeof(buf), "[#%d]", link_state);
+ return (buf);
}
void