ifconfig: Displaying of interface metric.

This commit is contained in:
Mats Erik Andersson
2012-12-03 23:20:27 +01:00
parent 065f43884c
commit 0d19e38f4f
6 changed files with 66 additions and 22 deletions

View File

@@ -1,3 +1,26 @@
2012-12-03 Mats Erik Andersson <gnu@gisladisker.se>
ifconfig: Audit displaying of metrics.
The portable display is to supress metric naught.
* ifconfig/printif.c (fh_metric_query) [SIOCGIFMETRIC]:
Add the further condition `form->ifr->ifr_metric > 0'
(fh_metric) [SIOCGIFMETRIC]: Do not report value 0 of
`form->ifr->ifr_metric' as 1.
* ifconfig/system/bsd.c (system_fh_metric): Remove.
* ifconfig/system/bsd.h (SYSTEM_FORMAT_HANDLER):
Delete key "metric".
(system_fh_metric): Remove prototype.
Implement exceptional handler for GNU/Linux.
* ifconfig/system/linux.c (system_fh_metric_query)
(system_fh_metric): New functions.
* ifconfig/system/linux.h (SYSTEM_FORMAT_HANDLER):
Add new keys "metric?" and "metric".
(system_fh_metric_query, system_fh_metric):
New prototypes.
2012-12-03 Mats Erik Andersson <gnu@gisladisker.se>
ifconfig.sh: Avoid substring matches.

View File

@@ -788,11 +788,15 @@ fh_mtu (format_data_t form, int argc, char *argv[])
#endif
}
/* The portable behaviour is to display strictly positive
* metrics, but to supress the default value naught.
*/
void
fh_metric_query (format_data_t form, int argc, char *argv[])
{
#ifdef SIOCGIFMETRIC
if (ioctl (form->sfd, SIOCGIFMETRIC, form->ifr) >= 0)
if (ioctl (form->sfd, SIOCGIFMETRIC, form->ifr) >= 0
&& form->ifr->ifr_metric > 0)
select_arg (form, argc, argv, 0);
else
#endif
@@ -808,8 +812,7 @@ fh_metric (format_data_t form, int argc, char *argv[])
"SIOCGIFMETRIC failed for interface `%s'",
form->ifr->ifr_name);
else
put_int (form, argc, argv,
form->ifr->ifr_metric ? form->ifr->ifr_metric : 1);
put_int (form, argc, argv, form->ifr->ifr_metric);
#else
*column += printf ("(not available)");
had_output = 1;

View File

@@ -169,19 +169,3 @@ system_fh_hwtype (format_data_t form, int argc, char *argv[])
put_string (form, "(unknown hwtype)");
}
}
void
system_fh_metric (format_data_t form, int argc, char *argv[])
{
#ifdef SIOCGIFMETRIC
if (ioctl (form->sfd, SIOCGIFMETRIC, form->ifr) < 0)
error (EXIT_FAILURE, errno,
"SIOCGIFMETRIC failed for interface `%s'",
form->ifr->ifr_name);
else
put_int (form, argc, argv, form->ifr->ifr_metric);
#else
*column += printf ("(not available)");
had_output = 1;
#endif
}

View File

@@ -61,13 +61,11 @@ struct system_ifconfig
{"hwaddr?", system_fh_hwaddr_query}, \
{"hwaddr", system_fh_hwaddr}, \
{"hwtype?", system_fh_hwtype_query}, \
{"hwtype", system_fh_hwtype}, \
{"metric", system_fh_metric},
{"hwtype", system_fh_hwtype},
void system_fh_hwaddr_query (format_data_t form, int argc, char *argv[]);
void system_fh_hwaddr (format_data_t form, int argc, char *argv[]);
void system_fh_hwtype_query (format_data_t form, int argc, char *argv[]);
void system_fh_hwtype (format_data_t form, int argc, char *argv[]);
void system_fh_metric (format_data_t form, int argc, char *argv[]);
#endif /* IFCONFIG_SYSTEM_BSD_H */

View File

@@ -594,6 +594,38 @@ system_fh_hwtype (format_data_t form, int argc, char *argv[])
#endif
}
/* Accept every value of metric as printable. The net-tools'
* implementation of ifconfig displays metric 0 as `1', so we
* aim at the same thing, even though all other unices disagree.
*/
void
system_fh_metric_query (format_data_t form, int argc, char *argv[])
{
#ifdef SIOCGIFMETRIC
if (ioctl (form->sfd, SIOCGIFMETRIC, form->ifr) >= 0)
select_arg (form, argc, argv, 0);
else
#endif
select_arg (form, argc, argv, 1);
}
void
system_fh_metric (format_data_t form, int argc, char *argv[])
{
#ifdef SIOCGIFMETRIC
if (ioctl (form->sfd, SIOCGIFMETRIC, form->ifr) < 0)
error (EXIT_FAILURE, errno,
"SIOCGIFMETRIC failed for interface `%s'",
form->ifr->ifr_name);
else
put_int (form, argc, argv,
form->ifr->ifr_metric ? form->ifr->ifr_metric : 1);
#else
*column += printf ("(not available)");
had_output = 1;
#endif
}
void
system_fh_txqlen_query (format_data_t form, int argc, char *argv[])
{

View File

@@ -51,6 +51,8 @@ struct system_ifconfig
{"hwaddr", system_fh_hwaddr}, \
{"hwtype?", system_fh_hwtype_query}, \
{"hwtype", system_fh_hwtype}, \
{"metric?", system_fh_metric_query}, \
{"metric", system_fh_metric}, \
{"txqlen?", system_fh_txqlen_query}, \
{"txqlen", system_fh_txqlen}, \
{"ifstat?", system_fh_ifstat_query}, \
@@ -82,6 +84,8 @@ void system_fh_hwaddr_query (format_data_t form, int argc, char *argv[]);
void system_fh_hwaddr (format_data_t form, int argc, char *argv[]);
void system_fh_hwtype_query (format_data_t form, int argc, char *argv[]);
void system_fh_hwtype (format_data_t form, int argc, char *argv[]);
void system_fh_metric_query (format_data_t form, int argc, char *argv[]);
void system_fh_metric (format_data_t form, int argc, char *argv[]);
void system_fh_txqlen_query (format_data_t form, int argc, char *argv[]);
void system_fh_txqlen (format_data_t form, int argc, char *argv[]);