summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2019-04-11 11:32:24 +0000
committersthen <sthen@openbsd.org>2019-04-11 11:32:24 +0000
commit3561a859673728e2c02252cce67adc25cc2a1eaf (patch)
tree23802ed1c23235d17fa0576c611c0bd302b54aa1
parentKNF per naddy@ (diff)
downloadwireguard-openbsd-3561a859673728e2c02252cce67adc25cc2a1eaf.tar.xz
wireguard-openbsd-3561a859673728e2c02252cce67adc25cc2a1eaf.zip
print transceiver information inline with standard interface details
(like media/joinlist do) rather than totally separate; this also allows "ifconfig -a sff" or "ifconfig ix sff". tweak display format to make it look closer to the standard lines. ok deraadt
-rw-r--r--sbin/ifconfig/ifconfig.c19
-rw-r--r--sbin/ifconfig/sff.c37
2 files changed, 30 insertions, 26 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 505b26f34b0..464e907d47b 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.398 2019/04/10 10:14:37 dlg Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.399 2019/04/11 11:32:24 sthen Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -172,6 +172,7 @@ int showcapsflag;
int shownet80211chans;
int shownet80211nodes;
int showclasses;
+int showtransceiver;
struct ifencap;
@@ -342,6 +343,7 @@ void utf16_to_char(uint16_t *, int, char *, size_t);
int char_to_utf16(const char *, uint16_t *, size_t);
void transceiver(const char *, int);
void transceiverdump(const char *, int);
+int if_sff_info(int, const char *, int);
#else
void setignore(const char *, int);
#endif
@@ -591,8 +593,8 @@ const struct cmd {
{ "datapath", NEXTARG, 0, switch_datapathid },
{ "portno", NEXTARG2, 0, NULL, switch_portno },
{ "addlocal", NEXTARG, 0, addlocal },
- { "transceiver", 0, 0, transceiver },
- { "sff", 0, 0, transceiver },
+ { "transceiver", NEXTARG0, 0, transceiver },
+ { "sff", NEXTARG0, 0, transceiver },
{ "sffdump", 0, 0, transceiverdump },
#else /* SMALL */
{ "powersave", NEXTARG0, 0, setignore },
@@ -3371,6 +3373,12 @@ status(int link, struct sockaddr_dl *sdl, int ls)
printf("unknown");
putchar('\n');
}
+
+ if (showtransceiver) {
+ if (if_sff_info(s, name, 0) == -1)
+ if (!aflag && errno != EPERM && errno != ENOTTY)
+ warn("%s transceiver", name);
+ }
#endif
ieee80211_status();
@@ -4040,13 +4048,10 @@ unsetpwe3neighbor(const char *val, int d)
warn("-pweneighbor");
}
-int if_sff_info(int, const char *, int);
-
void
transceiver(const char *value, int d)
{
- if (if_sff_info(s, name, 0) == -1)
- err(1, "%s %s", name, __func__);
+ showtransceiver = 1;
}
void
diff --git a/sbin/ifconfig/sff.c b/sbin/ifconfig/sff.c
index 3f274c3481e..8a04501555b 100644
--- a/sbin/ifconfig/sff.c
+++ b/sbin/ifconfig/sff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sff.c,v 1.5 2019/04/10 18:02:50 deraadt Exp $ */
+/* $OpenBSD: sff.c,v 1.6 2019/04/11 11:32:24 sthen Exp $ */
/*
* Copyright (c) 2019 David Gwynne <dlg@openbsd.org>
@@ -295,7 +295,7 @@ if_sff_info(int s, const char *ifname, int dump)
id = pg0.sff_data[0]; /* SFF8472_ID */
- printf("%s: %s ", ifname, sff_id_name(id));
+ printf("\ttransceiver: %s ", sff_id_name(id));
switch (id) {
case SFF8024_ID_SFP:
ext_id = pg0.sff_data[SFF8472_EXT_ID];
@@ -400,7 +400,7 @@ if_sff_printalarm(const char *unit, int range, float actual,
{
printf("%.02f%s", actual, unit);
if (range == 1)
- printf(" (low %.02f%s high %.02f%s)", alrm_low,
+ printf(" (low %.02f%s, high %.02f%s)", alrm_low,
unit, alrm_high, unit);
if(actual > alrm_high || actual < alrm_low)
@@ -417,14 +417,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
uint16_t wavelength;
con = pg0->sff_data[SFF8472_CON];
- printf("%s (", sff_con_name(con));
-
- if_sff_ascii_print(pg0, "",
- SFF8472_VENDOR_START, SFF8472_VENDOR_END, " ");
- if_sff_ascii_print(pg0, "",
- SFF8472_PRODUCT_START, SFF8472_PRODUCT_END, "");
- if_sff_ascii_print(pg0, " rev ",
- SFF8472_REVISION_START, SFF8472_REVISION_END, "");
+ printf("%s", sff_con_name(con));
wavelength = if_sff_int(pg0, SFF8472_WAVELENGTH);
switch (wavelength) {
@@ -437,11 +430,17 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
printf(", %.02u nm", wavelength);
}
- printf(")\n\t");
+ printf("\n\tmodel: ");
+ if_sff_ascii_print(pg0, "",
+ SFF8472_VENDOR_START, SFF8472_VENDOR_END, " ");
+ if_sff_ascii_print(pg0, "",
+ SFF8472_PRODUCT_START, SFF8472_PRODUCT_END, "");
+ if_sff_ascii_print(pg0, " rev ",
+ SFF8472_REVISION_START, SFF8472_REVISION_END, "");
- if_sff_ascii_print(pg0, "serial ",
+ if_sff_ascii_print(pg0, "\n\tserial: ",
SFF8472_SERIAL_START, SFF8472_SERIAL_END, ", ");
- if_sff_date_print(pg0, "date ", SFF8472_DATECODE, "\n");
+ if_sff_date_print(pg0, "date: ", SFF8472_DATECODE, "\n");
ddm_types = pg0->sff_data[SFF8472_DDM_TYPE];
if (pg0->sff_data[SFF8472_COMPLIANCE] == SFF8472_COMPLIANCE_NONE ||
@@ -460,7 +459,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
"(WARNING: needs more code)\n");
}
- printf("\tvoltage ");
+ printf("\tvoltage: ");
if_sff_printalarm(" V", 0,
if_sff_uint(&ddm, SFF8472_DDM_VCC) / SFF_VCC_FACTOR,
if_sff_uint(&ddm, SFF8472_AW_VCC + ALRM_HIGH) / SFF_VCC_FACTOR,
@@ -468,7 +467,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
if_sff_uint(&ddm, SFF8472_AW_VCC + WARN_HIGH) / SFF_VCC_FACTOR,
if_sff_uint(&ddm, SFF8472_AW_VCC + WARN_LOW) / SFF_VCC_FACTOR);
- printf(", bias current ");
+ printf(", bias current: ");
if_sff_printalarm(" mA", 0,
if_sff_uint(&ddm, SFF8472_DDM_TX_BIAS) / SFF_BIAS_FACTOR,
if_sff_uint(&ddm, SFF8472_AW_TX_BIAS + ALRM_HIGH) / SFF_BIAS_FACTOR,
@@ -476,7 +475,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
if_sff_uint(&ddm, SFF8472_AW_TX_BIAS + WARN_HIGH) / SFF_BIAS_FACTOR,
if_sff_uint(&ddm, SFF8472_AW_TX_BIAS + WARN_LOW) / SFF_BIAS_FACTOR);
- printf("\n\ttemp ");
+ printf("\n\ttemp: ");
if_sff_printalarm(" C", 1,
if_sff_int(&ddm, SFF8472_DDM_TEMP) / SFF_TEMP_FACTOR,
if_sff_int(&ddm, SFF8472_AW_TEMP + ALRM_HIGH) / SFF_TEMP_FACTOR,
@@ -484,7 +483,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
if_sff_int(&ddm, SFF8472_AW_TEMP + WARN_HIGH) / SFF_TEMP_FACTOR,
if_sff_int(&ddm, SFF8472_AW_TEMP + WARN_LOW) / SFF_TEMP_FACTOR);
- printf("\n\ttx ");
+ printf("\n\ttx: ");
if_sff_printalarm(" dBm", 1,
if_sff_power2dbm(&ddm, SFF8472_DDM_TX_POWER),
if_sff_power2dbm(&ddm, SFF8472_AW_TX_POWER + ALRM_HIGH),
@@ -492,7 +491,7 @@ if_sff8472(int s, const char *ifname, int dump, const struct if_sffpage *pg0)
if_sff_power2dbm(&ddm, SFF8472_AW_TX_POWER + WARN_HIGH),
if_sff_power2dbm(&ddm, SFF8472_AW_TX_POWER + WARN_LOW));
- printf("\n\trx ");
+ printf("\n\trx: ");
if_sff_printalarm(" dBm", 1,
if_sff_power2dbm(&ddm, SFF8472_DDM_RX_POWER),
if_sff_power2dbm(&ddm, SFF8472_AW_RX_POWER + ALRM_HIGH),