mirror of
https://git.savannah.gnu.org/git/inetutils.git
synced 2026-01-12 00:19:39 +08:00
ifconfig: Displaying of interface metric.
This commit is contained in:
23
ChangeLog
23
ChangeLog
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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[])
|
||||
{
|
||||
|
||||
@@ -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[]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user