summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsben Norby <norby@cvs.openbsd.org>2006-03-23 18:37:35 +0000
committerEsben Norby <norby@cvs.openbsd.org>2006-03-23 18:37:35 +0000
commit26b512eab382feda7dce937ab290183de33fd254 (patch)
tree51d3fd2958c3df0a32caa8b9d4f1adafbfabef11
parentc83cee38b062d0789008997b2afacb27f9291186 (diff)
List interfaces they way we list neighbors etc.
This makes it much easier to grep in the output. The original format of "show interface" can be seen with "show interface detail". help and ok claudio@
-rw-r--r--usr.sbin/ospfctl/ospfctl.c62
-rw-r--r--usr.sbin/ospfctl/parser.c11
-rw-r--r--usr.sbin/ospfctl/parser.h3
-rw-r--r--usr.sbin/ospfd/interface.c3
-rw-r--r--usr.sbin/ospfd/ospfd.h3
5 files changed, 74 insertions, 8 deletions
diff --git a/usr.sbin/ospfctl/ospfctl.c b/usr.sbin/ospfctl/ospfctl.c
index 339ab1be378..807c286f517 100644
--- a/usr.sbin/ospfctl/ospfctl.c
+++ b/usr.sbin/ospfctl/ospfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfctl.c,v 1.29 2006/03/22 15:37:44 claudio Exp $ */
+/* $OpenBSD: ospfctl.c,v 1.30 2006/03/23 18:37:34 norby Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -40,6 +40,7 @@
__dead void usage(void);
int show_summary_msg(struct imsg *);
int show_interface_msg(struct imsg *);
+int show_interface_detail_msg(struct imsg *);
const char *print_link(int);
const char *fmt_timeframe(time_t t);
const char *fmt_timeframe_core(time_t t);
@@ -123,6 +124,10 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, NULL, 0);
break;
case SHOW_IFACE:
+ printf("%-11s %-18s %-6s %-10s %-10s %-8s %3s %3s\n",
+ "Interface", "Address", "State", "HelloTimer", "Linkstate",
+ "Uptime", "nc", "ac");
+ case SHOW_IFACE_DTAIL:
if (*res->ifname) {
ifidx = if_nametoindex(res->ifname);
if (ifidx == 0)
@@ -228,6 +233,9 @@ main(int argc, char *argv[])
case SHOW_IFACE:
done = show_interface_msg(&imsg);
break;
+ case SHOW_IFACE_DTAIL:
+ done = show_interface_detail_msg(&imsg);
+ break;
case SHOW_NBR:
done = show_nbr_msg(&imsg);
break;
@@ -321,6 +329,58 @@ int
show_interface_msg(struct imsg *imsg)
{
struct ctl_iface *iface;
+ char *netid;
+ int ifms_type;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_INTERFACE:
+ iface = imsg->data;
+
+ switch (iface->mediatype) {
+ case IFT_ETHER:
+ ifms_type = IFM_ETHER;
+ break;
+ case IFT_FDDI:
+ ifms_type = IFM_FDDI;
+ break;
+ case IFT_ISO88025:
+ ifms_type = IFM_TOKEN;
+ break;
+ case IFT_CARP:
+ ifms_type = IFM_CARP;
+ break;
+ default:
+ ifms_type = 0;
+ break;
+ }
+
+ if (asprintf(&netid, "%s/%d", inet_ntoa(iface->addr),
+ mask2prefixlen(iface->mask.s_addr)) == -1)
+ err(1, NULL);
+ printf("%-11s %-18s %-6s %-10s %-10s %s %3d %3d\n",
+ iface->name, netid, if_state_name(iface->state),
+ iface->hello_timer < 0 ? "stopped" :
+ fmt_timeframe_core(iface->hello_timer),
+ get_linkstate(ifms_type, iface->linkstate),
+ iface->uptime == 0 ? "00:00:00" :
+ fmt_timeframe_core(iface->uptime), iface->nbr_cnt,
+ iface->adj_cnt);
+ free(netid);
+ break;
+ case IMSG_CTL_END:
+ printf("\n");
+ return (1);
+ default:
+ break;
+ }
+
+ return (0);
+}
+
+int
+show_interface_detail_msg(struct imsg *imsg)
+{
+ struct ctl_iface *iface;
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_INTERFACE:
diff --git a/usr.sbin/ospfctl/parser.c b/usr.sbin/ospfctl/parser.c
index 72ce75bc635..11babc4a357 100644
--- a/usr.sbin/ospfctl/parser.c
+++ b/usr.sbin/ospfctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.10 2006/03/22 15:37:44 claudio Exp $ */
+/* $OpenBSD: parser.c,v 1.11 2006/03/23 18:37:34 norby Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -84,9 +84,10 @@ static const struct token t_show[] = {
};
static const struct token t_show_iface[] = {
- {NOTOKEN, "", NONE, NULL},
- {IFNAME, "", NONE, NULL},
- {ENDTOKEN, "", NONE, NULL}
+ {NOTOKEN, "", NONE, NULL},
+ {KEYWORD, "detail", SHOW_IFACE_DTAIL, NULL},
+ {IFNAME, "", SHOW_IFACE_DTAIL, NULL},
+ {ENDTOKEN, "", NONE, NULL}
};
static const struct token t_show_db[] = {
@@ -219,6 +220,8 @@ match_token(const char *word, const struct token table[])
err(1, "interface name too long");
match++;
t = &table[i];
+ if (t->value)
+ res.action = t->value;
}
break;
diff --git a/usr.sbin/ospfctl/parser.h b/usr.sbin/ospfctl/parser.h
index ac7dea40f42..3386d9883eb 100644
--- a/usr.sbin/ospfctl/parser.h
+++ b/usr.sbin/ospfctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.7 2006/03/22 15:37:44 claudio Exp $ */
+/* $OpenBSD: parser.h,v 1.8 2006/03/23 18:37:34 norby Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -32,6 +32,7 @@ enum actions {
SHOW,
SHOW_SUM,
SHOW_IFACE,
+ SHOW_IFACE_DTAIL,
SHOW_NBR,
SHOW_NBR_DTAIL,
SHOW_DB,
diff --git a/usr.sbin/ospfd/interface.c b/usr.sbin/ospfd/interface.c
index 28e9a92d002..32d0d60b6d6 100644
--- a/usr.sbin/ospfd/interface.c
+++ b/usr.sbin/ospfd/interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.c,v 1.48 2006/03/15 13:25:33 claudio Exp $ */
+/* $OpenBSD: interface.c,v 1.49 2006/03/23 18:37:34 norby Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -635,6 +635,7 @@ if_to_ctl(struct iface *iface)
ictl.rxmt_interval = iface->rxmt_interval;
ictl.type = iface->type;
ictl.linkstate = iface->linkstate;
+ ictl.mediatype = iface->media_type;
ictl.priority = iface->priority;
ictl.passive = iface->passive;
ictl.auth_type = iface->auth_type;
diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h
index bd0bd373286..e65019e5b04 100644
--- a/usr.sbin/ospfd/ospfd.h
+++ b/usr.sbin/ospfd/ospfd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.h,v 1.53 2006/03/22 16:01:20 claudio Exp $ */
+/* $OpenBSD: ospfd.h,v 1.54 2006/03/23 18:37:34 norby Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -435,6 +435,7 @@ struct ctl_iface {
u_int16_t rxmt_interval;
enum iface_type type;
u_int8_t linkstate;
+ u_int8_t mediatype;
u_int8_t priority;
u_int8_t passive;
enum auth_type auth_type;