diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-09-14 11:49:26 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2009-09-14 11:49:26 +0000 |
commit | 15a3e8853859cbe52bda8c7a38613274f7e374df (patch) | |
tree | 024009d39085a463f5745768912a2aa25f6d8312 /usr.sbin/ripctl | |
parent | 59b6c9cab8ebff096556ff3792cd31dae17bd54d (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/ripctl')
-rw-r--r-- | usr.sbin/ripctl/ripctl.c | 60 |
1 files changed, 17 insertions, 43 deletions
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 |