1 From 5b4e80afa7d9d15ba5e7d8e357a261c18fad02a6 Mon Sep 17 00:00:00 2001
2 From: Mats Erik Andersson <gnu@gisladisker.se>
3 Date: Fri, 7 Aug 2015 22:51:43 +0200
4 Subject: [PATCH 10/60] ifconfig: Statistics for BSD systems.
7 ChangeLog | 24 +++++++++++++
8 ifconfig/system/bsd.c | 82 +++++++++++++++++++++++++++++++++++++++++++
9 ifconfig/system/bsd.h | 35 +++++++++++++++++-
10 3 files changed, 140 insertions(+), 1 deletion(-)
12 diff --git a/ChangeLog b/ChangeLog
13 index 6c592b72..73b281b9 100644
17 +2015-08-07 Mats Erik Andersson <gnu@gisladisker.se>
19 + ifconfig: Statistics for BSD systems.
21 + * ifconfig/system/bsd.c (system_fh_ifstat_query)
22 + (get_if_data_by_name, system_fh_missing_stat): New functions.
23 + (_IU_DECLARE2): New macro.
24 + (system_fh_rx_bytes, system_fh_rx_dropped, system_fh_rx_errors)
25 + (system_fh_rx_packets, system_fh_tx_bytes, system_fh_tx_errors)
26 + (system_fh_tx_packets, system_fh_collisions): New functions
27 + defined using _IU_DECLARE2.
28 + (system_fh_tx_dropped): New function.
29 + * ifconfig/system/bsd.h (_IU_CAT2, _IU_DCL, _IU_EXTRN): New
30 + macros identical to those in `ifconfig/system/linux.h'.
31 + (SYSTEM_FORMAT_HANDLER) <ifstat?, collisions, rxbytes>
32 + <rxdropped, rxerrors, rxfifoerr, rxframeerr, rxpackets>
33 + <txbytes, txcarrier, txdropped, txerrors, txfifoerr, txpackets>:
35 + (system_fh_ifstat_query, system_fh_missing_stat): New prototypes.
36 + (system_fh_rx_bytes, system_fh_tx_bytes, system_fh_rx_dropped)
37 + (system_fh_tx_dropped, system_fh_rx_errors, system_fh_tx_errors)
38 + (system_fh_rx_packets, system_fh_tx_packets, system_fh_collisions):
39 + New prototypes generated by _IU_EXTERN.
41 2015-08-02 Mats Erik Andersson <gnu@gisladisker.se>
43 ifconfig: Verbose report on changed flags.
44 diff --git a/ifconfig/system/bsd.c b/ifconfig/system/bsd.c
45 index 1db525ba..ec47ce62 100644
46 --- a/ifconfig/system/bsd.c
47 +++ b/ifconfig/system/bsd.c
48 @@ -198,6 +198,19 @@ struct ifmediareq ifm;
53 +system_fh_ifstat_query (format_data_t form, int argc, char *argv[])
55 + /* Flush an existing interface list, thus renewing statistics. */
62 + select_arg (form, argc, argv, getifaddrs (&ifp) ? 1 : 0);
65 struct if_nameindex* (*system_if_nameindex) (void) = if_nameindex;
68 @@ -728,3 +741,72 @@ system_fh_tunsrc (format_data_t form, int argc, char *argv[])
69 put_string (form, "(no physrc)");
70 #endif /* SIOCGIFPSRCADDR */
73 +static struct if_data *
74 +get_if_data_by_name (format_data_t form)
77 + struct if_data *data = NULL;
83 + for (fp = ifp; fp; fp = fp->ifa_next)
85 + /* The choice of AF_LINK is the only portable alternative.
86 + * Then IP, ARP etcera are included in all counters.
88 + if (fp->ifa_addr->sa_family != AF_LINK ||
89 + strcmp (fp->ifa_name, form->ifr->ifr_name))
92 + data = (struct if_data *) fp->ifa_data;
100 +system_fh_missing_stat (format_data_t form, int argc, char *argv[])
102 + /* FIXME: Would a dash be a better answer? */
103 + put_ulong (form, argc, argv, 0);
106 +#define _IU_DECLARE2(fld, udata) \
108 +_IU_CAT2 (system_fh_, fld) (format_data_t form, int argc, char *argv[]) \
110 + struct if_data *data = get_if_data_by_name (form); \
112 + put_ulong (form, argc, argv, data->_IU_CAT2(ifi_, udata)); \
114 + put_string (form, "(" #fld " unknown)"); \
117 +_IU_DECLARE2 (rx_bytes, ibytes)
118 +_IU_DECLARE2 (rx_dropped, iqdrops)
119 +_IU_DECLARE2 (rx_errors, ierrors)
120 +_IU_DECLARE2 (rx_packets, ipackets)
121 +_IU_DECLARE2 (tx_bytes, obytes)
122 +_IU_DECLARE2 (tx_errors, oerrors)
123 +_IU_DECLARE2 (tx_packets, opackets)
124 +_IU_DECLARE2 (collisions, collisions)
127 +system_fh_tx_dropped (format_data_t form, int argc, char *argv[])
130 + struct if_data *data = get_if_data_by_name (form);
133 + put_ulong (form, argc, argv, data->ifi_oqdrops);
135 + put_string (form, "(txerrors unknown)");
136 +#else /* !_IFI_OQDROPS */
137 + /* FIXME: Would a dash be a better answer? */
138 + put_ulong (form, argc, argv, 0);
141 diff --git a/ifconfig/system/bsd.h b/ifconfig/system/bsd.h
142 index 918c1f2c..3398df65 100644
143 --- a/ifconfig/system/bsd.h
144 +++ b/ifconfig/system/bsd.h
145 @@ -57,6 +57,12 @@ struct system_ifconfig
147 /* Output format support. */
149 +# define _IU_CAT2(a, b) a ## b
150 +# define _IU_DCL(name, fld) \
151 + {#name, _IU_CAT2(system_fh_, fld) }
152 +# define _IU_EXTRN(fld) \
153 + extern void _IU_CAT2(system_fh_, fld) (format_data_t, int, char *[]); \
155 # define SYSTEM_FORMAT_HANDLER \
156 {"bsd", fh_nothing}, \
157 {IU_BSD_TYPE, fh_nothing}, \
158 @@ -74,7 +80,21 @@ struct system_ifconfig
159 {"status", system_fh_status}, \
160 {"tunnel?", system_fh_tunnel_query}, \
161 {"tundst", system_fh_tundst}, \
162 - {"tunsrc", system_fh_tunsrc},
163 + {"tunsrc", system_fh_tunsrc}, \
164 + {"ifstat?", system_fh_ifstat_query}, \
165 + _IU_DCL (collisions, collisions), \
166 + _IU_DCL (rxbytes, rx_bytes), \
167 + _IU_DCL (rxdropped, rx_dropped), \
168 + _IU_DCL (rxerrors, rx_errors), \
169 + {"rxfifoerr", system_fh_missing_stat}, \
170 + {"rxframeerr", system_fh_missing_stat}, \
171 + _IU_DCL (rxpackets, rx_packets), \
172 + _IU_DCL (txbytes, tx_bytes), \
173 + {"txcarrier", system_fh_missing_stat}, \
174 + _IU_DCL (txdropped, tx_dropped), \
175 + _IU_DCL (txerrors, tx_errors), \
176 + {"txfifoerr", system_fh_missing_stat}, \
177 + _IU_DCL (txpackets, tx_packets),
179 void system_fh_brdaddr_query (format_data_t form, int argc, char *argv[]);
180 void system_fh_brdaddr (format_data_t form, int argc, char *argv[]);
181 @@ -92,4 +112,17 @@ void system_fh_tunnel_query (format_data_t form, int argc, char *argv[]);
182 void system_fh_tundst (format_data_t form, int argc, char *argv[]);
183 void system_fh_tunsrc (format_data_t form, int argc, char *argv[]);
185 +void system_fh_ifstat_query (format_data_t form, int argc, char *argv[]);
186 +void system_fh_missing_stat (format_data_t form, int argc, char *argv[]);
188 +_IU_EXTRN (rx_bytes)
189 +_IU_EXTRN (tx_bytes)
190 +_IU_EXTRN (rx_dropped)
191 +_IU_EXTRN (tx_dropped)
192 +_IU_EXTRN (rx_errors)
193 +_IU_EXTRN (tx_errors)
194 +_IU_EXTRN (rx_packets)
195 +_IU_EXTRN (tx_packets)
196 +_IU_EXTRN (collisions)
198 #endif /* IFCONFIG_SYSTEM_BSD_H */
200 2.26.0.292.g33ef6b2f38