Merge ~alfonsosanchezbeato/network-manager/+git/ubuntu:touch-vivid-add-statitics into network-manager:touch-vivid
- Git
- lp:~alfonsosanchezbeato/network-manager/+git/ubuntu
- touch-vivid-add-statitics
- Merge into touch-vivid
Proposed by
Alfonso Sanchez-Beato
Status: | Merged |
---|---|
Merged at revision: | 92ac043cd375662fa7546ccdd0cc7aecbc275929 |
Proposed branch: | ~alfonsosanchezbeato/network-manager/+git/ubuntu:touch-vivid-add-statitics |
Merge into: | network-manager:touch-vivid |
Diff against target: |
856 lines (+842/-0) 2 files modified
debian/patches/Add-statistics-interface.patch (+841/-0) debian/patches/series (+1/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tony Espy | Approve | ||
Review via email: mp+296433@code.launchpad.net |
Commit message
ubuntu: Add statistics interface
Description of the change
ubuntu: Add statistics interface
To post a comment you must log in.
Revision history for this message
Tony Espy (awe) : | # |
review:
Needs Fixing
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Some compilation warning fixed.
Revision history for this message
Tony Espy (awe) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/debian/patches/Add-statistics-interface.patch b/debian/patches/Add-statistics-interface.patch | |||
2 | 0 | new file mode 100644 | 0 | new file mode 100644 |
3 | index 0000000..2c3dcd2 | |||
4 | --- /dev/null | |||
5 | +++ b/debian/patches/Add-statistics-interface.patch | |||
6 | @@ -0,0 +1,841 @@ | |||
7 | 1 | From: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com> | ||
8 | 2 | Date: Fri, 3 Jun 2016 14:55:22 +0200 | ||
9 | 3 | Subject: Add statistics interface | ||
10 | 4 | |||
11 | 5 | --- | ||
12 | 6 | introspection/Makefile.am | 6 +- | ||
13 | 7 | introspection/nm-device-statistics.xml | 43 ++++ | ||
14 | 8 | libnm-core/nm-dbus-interface.h | 1 + | ||
15 | 9 | src/Makefile.am | 2 + | ||
16 | 10 | src/devices/nm-device-private.h | 3 + | ||
17 | 11 | src/devices/nm-device-statistics.c | 407 +++++++++++++++++++++++++++++++++ | ||
18 | 12 | src/devices/nm-device-statistics.h | 33 +++ | ||
19 | 13 | src/devices/nm-device.c | 102 ++++++++- | ||
20 | 14 | src/devices/nm-device.h | 4 + | ||
21 | 15 | src/nm-exported-object.c | 18 +- | ||
22 | 16 | src/nm-types.h | 1 + | ||
23 | 17 | 11 files changed, 610 insertions(+), 10 deletions(-) | ||
24 | 18 | create mode 100644 introspection/nm-device-statistics.xml | ||
25 | 19 | create mode 100644 src/devices/nm-device-statistics.c | ||
26 | 20 | create mode 100644 src/devices/nm-device-statistics.h | ||
27 | 21 | |||
28 | 22 | diff --git a/introspection/Makefile.am b/introspection/Makefile.am | ||
29 | 23 | index 3a62793..f72703d 100644 | ||
30 | 24 | --- a/introspection/Makefile.am | ||
31 | 25 | +++ b/introspection/Makefile.am | ||
32 | 26 | @@ -41,6 +41,8 @@ nodist_libnmdbus_la_SOURCES = \ | ||
33 | 27 | nmdbus-device-modem.h \ | ||
34 | 28 | nmdbus-device-olpc-mesh.c \ | ||
35 | 29 | nmdbus-device-olpc-mesh.h \ | ||
36 | 30 | + nmdbus-device-statistics.c \ | ||
37 | 31 | + nmdbus-device-statistics.h \ | ||
38 | 32 | nmdbus-device-team.c \ | ||
39 | 33 | nmdbus-device-team.h \ | ||
40 | 34 | nmdbus-device-tun.c \ | ||
41 | 35 | @@ -111,7 +113,8 @@ DBUS_INTERFACE_DOCS = \ | ||
42 | 36 | nmdbus-device-veth-org.freedesktop.NetworkManager.Device.Veth.xml \ | ||
43 | 37 | nmdbus-settings-org.freedesktop.NetworkManager.Settings.xml \ | ||
44 | 38 | nmdbus-device-ethernet-org.freedesktop.NetworkManager.Device.Wired.xml \ | ||
45 | 39 | - nmdbus-ip4-config-org.freedesktop.NetworkManager.IP4Config.xml | ||
46 | 40 | + nmdbus-ip4-config-org.freedesktop.NetworkManager.IP4Config.xml \ | ||
47 | 41 | + nmdbus-device-statistics-org.freedesktop.NetworkManager.Device.Statistics.xml | ||
48 | 42 | |||
49 | 43 | define _make_nmdbus_rule | ||
50 | 44 | $(1): $(patsubst nmdbus-%.c,nm-%.xml,$(1)) | ||
51 | 45 | @@ -150,6 +153,7 @@ EXTRA_DIST = \ | ||
52 | 46 | nm-device-macvlan.xml \ | ||
53 | 47 | nm-device-modem.xml \ | ||
54 | 48 | nm-device-olpc-mesh.xml \ | ||
55 | 49 | + nm-device-statistics.xml \ | ||
56 | 50 | nm-device-team.xml \ | ||
57 | 51 | nm-device-tun.xml \ | ||
58 | 52 | nm-device-veth.xml \ | ||
59 | 53 | diff --git a/introspection/nm-device-statistics.xml b/introspection/nm-device-statistics.xml | ||
60 | 54 | new file mode 100644 | ||
61 | 55 | index 0000000..08a700e | ||
62 | 56 | --- /dev/null | ||
63 | 57 | +++ b/introspection/nm-device-statistics.xml | ||
64 | 58 | @@ -0,0 +1,43 @@ | ||
65 | 59 | +<?xml version="1.0" encoding="UTF-8"?> | ||
66 | 60 | +<node name="/"> | ||
67 | 61 | + <interface name="org.freedesktop.NetworkManager.Device.Statistics"> | ||
68 | 62 | + | ||
69 | 63 | + <!-- | ||
70 | 64 | + RefreshRateMs: | ||
71 | 65 | + | ||
72 | 66 | + Rate of change of the rest of properties of this interface. If zero, the | ||
73 | 67 | + properties do not change. Othewise, the properties are refreshed each | ||
74 | 68 | + RefreshRateMs milliseconds in case the underlaying counter has changed | ||
75 | 69 | + too. | ||
76 | 70 | + | ||
77 | 71 | + Returns: Unsigned 32-bit integer | ||
78 | 72 | + --> | ||
79 | 73 | + <property name="RefreshRateMs" type="u" access="readwrite"/> | ||
80 | 74 | + | ||
81 | 75 | + <!-- | ||
82 | 76 | + TxBytes: | ||
83 | 77 | + | ||
84 | 78 | + Number of transmitted bytes | ||
85 | 79 | + | ||
86 | 80 | + Returns: Unsigned 64-bit integer | ||
87 | 81 | + --> | ||
88 | 82 | + <property name="TxBytes" type="t" access="read"/> | ||
89 | 83 | + | ||
90 | 84 | + <!-- | ||
91 | 85 | + RxBytes: | ||
92 | 86 | + | ||
93 | 87 | + Number of received bytes | ||
94 | 88 | + | ||
95 | 89 | + Returns: Unsigned 64-bit integer | ||
96 | 90 | + --> | ||
97 | 91 | + <property name="RxBytes" type="t" access="read"/> | ||
98 | 92 | + | ||
99 | 93 | + <!-- | ||
100 | 94 | + PropertiesChanged: | ||
101 | 95 | + @properties: A dictionary mapping property names to variant boxed values | ||
102 | 96 | + --> | ||
103 | 97 | + <signal name="PropertiesChanged"> | ||
104 | 98 | + <arg name="properties" type="a{sv}"/> | ||
105 | 99 | + </signal> | ||
106 | 100 | + </interface> | ||
107 | 101 | +</node> | ||
108 | 102 | diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h | ||
109 | 103 | index f3d7945..6f0fc23 100644 | ||
110 | 104 | --- a/libnm-core/nm-dbus-interface.h | ||
111 | 105 | +++ b/libnm-core/nm-dbus-interface.h | ||
112 | 106 | @@ -68,6 +68,7 @@ | ||
113 | 107 | #define NM_DBUS_INTERFACE_DEVICE_VXLAN NM_DBUS_INTERFACE_DEVICE ".Vxlan" | ||
114 | 108 | #define NM_DBUS_INTERFACE_DEVICE_GRE NM_DBUS_INTERFACE_DEVICE ".Gre" | ||
115 | 109 | #define NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL NM_DBUS_INTERFACE_DEVICE ".IPTunnel" | ||
116 | 110 | +#define NM_DBUS_INTERFACE_DEVICE_STATISTICS NM_DBUS_INTERFACE_DEVICE ".Statistics" | ||
117 | 111 | |||
118 | 112 | #define NM_DBUS_INTERFACE_SETTINGS "org.freedesktop.NetworkManager.Settings" | ||
119 | 113 | #define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager/Settings" | ||
120 | 114 | diff --git a/src/Makefile.am b/src/Makefile.am | ||
121 | 115 | index 49028f1..1b749e3 100644 | ||
122 | 116 | --- a/src/Makefile.am | ||
123 | 117 | +++ b/src/Makefile.am | ||
124 | 118 | @@ -286,6 +286,8 @@ libNetworkManager_la_SOURCES = \ | ||
125 | 119 | devices/nm-device-generic.h \ | ||
126 | 120 | devices/nm-device-logging.h \ | ||
127 | 121 | devices/nm-device-private.h \ | ||
128 | 122 | + devices/nm-device-statistics.c \ | ||
129 | 123 | + devices/nm-device-statistics.h \ | ||
130 | 124 | \ | ||
131 | 125 | dhcp-manager/nm-dhcp-client.c \ | ||
132 | 126 | dhcp-manager/nm-dhcp-client.h \ | ||
133 | 127 | diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h | ||
134 | 128 | index 602c2c8..f84460a 100644 | ||
135 | 129 | --- a/src/devices/nm-device-private.h | ||
136 | 130 | +++ b/src/devices/nm-device-private.h | ||
137 | 131 | @@ -105,6 +105,9 @@ void nm_device_set_wwan_ip6_config (NMDevice *device, NMIP6Config *config); | ||
138 | 132 | |||
139 | 133 | gboolean nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value); | ||
140 | 134 | |||
141 | 135 | +void nm_device_set_tx_bytes (NMDevice *self, guint64 tx_bytes); | ||
142 | 136 | +void nm_device_set_rx_bytes (NMDevice *self, guint64 rx_bytes); | ||
143 | 137 | + | ||
144 | 138 | #define NM_DEVICE_CLASS_DECLARE_TYPES(klass, conn_type, ...) \ | ||
145 | 139 | NM_DEVICE_CLASS (klass)->connection_type = conn_type; \ | ||
146 | 140 | { \ | ||
147 | 141 | diff --git a/src/devices/nm-device-statistics.c b/src/devices/nm-device-statistics.c | ||
148 | 142 | new file mode 100644 | ||
149 | 143 | index 0000000..daf67f1 | ||
150 | 144 | --- /dev/null | ||
151 | 145 | +++ b/src/devices/nm-device-statistics.c | ||
152 | 146 | @@ -0,0 +1,407 @@ | ||
153 | 147 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ | ||
154 | 148 | +/* This program is free software; you can redistribute it and/or modify | ||
155 | 149 | + * it under the terms of the GNU General Public License as published by | ||
156 | 150 | + * the Free Software Foundation; either version 2, or (at your option) | ||
157 | 151 | + * any later version. | ||
158 | 152 | + * | ||
159 | 153 | + * This program is distributed in the hope that it will be useful, | ||
160 | 154 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
161 | 155 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
162 | 156 | + * GNU General Public License for more details. | ||
163 | 157 | + * | ||
164 | 158 | + * You should have received a copy of the GNU General Public License along | ||
165 | 159 | + * with this program; if not, write to the Free Software Foundation, Inc., | ||
166 | 160 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
167 | 161 | + * | ||
168 | 162 | + * Copyright (C) 2016 Canonical Ltd | ||
169 | 163 | + * | ||
170 | 164 | + */ | ||
171 | 165 | + | ||
172 | 166 | +#include "nm-default.h" | ||
173 | 167 | + | ||
174 | 168 | +#include <errno.h> | ||
175 | 169 | +#include <stdio.h> | ||
176 | 170 | +#include <unistd.h> | ||
177 | 171 | +#include <string.h> | ||
178 | 172 | +#include <sys/socket.h> | ||
179 | 173 | +#include <sys/ioctl.h> | ||
180 | 174 | +#include <arpa/inet.h> | ||
181 | 175 | +#include <netinet/ether.h> | ||
182 | 176 | +#include <netinet/icmp6.h> | ||
183 | 177 | +#include <net/if_arp.h> | ||
184 | 178 | +#include <linux/if.h> | ||
185 | 179 | +#include <linux/netlink.h> | ||
186 | 180 | +#include <linux/rtnetlink.h> | ||
187 | 181 | +#include <linux/wireless.h> | ||
188 | 182 | + | ||
189 | 183 | +#include "nm-device-private.h" | ||
190 | 184 | +#include "nm-device-statistics.h" | ||
191 | 185 | + | ||
192 | 186 | +#define _NMLOG_DOMAIN LOGD_DEVICE | ||
193 | 187 | +#define _NMLOG_PREFIX_NAME "device (stats)" | ||
194 | 188 | +#define _NMLOG(level, ...) \ | ||
195 | 189 | + G_STMT_START { \ | ||
196 | 190 | + nm_log ((level), _NMLOG_DOMAIN, \ | ||
197 | 191 | + "%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ | ||
198 | 192 | + _NMLOG_PREFIX_NAME": " \ | ||
199 | 193 | + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ | ||
200 | 194 | + } G_STMT_END | ||
201 | 195 | + | ||
202 | 196 | +struct rtnl_request { | ||
203 | 197 | + struct nlmsghdr hdr; | ||
204 | 198 | + struct rtgenmsg msg; | ||
205 | 199 | +}; | ||
206 | 200 | + | ||
207 | 201 | +#define RTNL_REQUEST_SIZE (sizeof (struct nlmsghdr) + sizeof (struct rtgenmsg)) | ||
208 | 202 | +#define SOCK_RX_BUFF_SIZE 4096 | ||
209 | 203 | + | ||
210 | 204 | +struct _NMDeviceStatistics { | ||
211 | 205 | + NMDevice *device; | ||
212 | 206 | + char *iface; | ||
213 | 207 | + GIOChannel *channel; | ||
214 | 208 | + guint channel_watch; | ||
215 | 209 | + guint stats_update_id; | ||
216 | 210 | + gboolean req_pending; | ||
217 | 211 | + guint32 request_seq; | ||
218 | 212 | + unsigned char buf[SOCK_RX_BUFF_SIZE]; | ||
219 | 213 | +}; | ||
220 | 214 | + | ||
221 | 215 | +static const char * | ||
222 | 216 | +type_to_string (uint16_t type) | ||
223 | 217 | +{ | ||
224 | 218 | + switch (type) { | ||
225 | 219 | + case NLMSG_NOOP: | ||
226 | 220 | + return "NOOP"; | ||
227 | 221 | + case NLMSG_ERROR: | ||
228 | 222 | + return "ERROR"; | ||
229 | 223 | + case NLMSG_DONE: | ||
230 | 224 | + return "DONE"; | ||
231 | 225 | + case NLMSG_OVERRUN: | ||
232 | 226 | + return "OVERRUN"; | ||
233 | 227 | + case RTM_GETLINK: | ||
234 | 228 | + return "GETLINK"; | ||
235 | 229 | + case RTM_NEWLINK: | ||
236 | 230 | + return "NEWLINK"; | ||
237 | 231 | + case RTM_DELLINK: | ||
238 | 232 | + return "DELLINK"; | ||
239 | 233 | + case RTM_GETADDR: | ||
240 | 234 | + return "GETADDR"; | ||
241 | 235 | + case RTM_NEWADDR: | ||
242 | 236 | + return "NEWADDR"; | ||
243 | 237 | + case RTM_DELADDR: | ||
244 | 238 | + return "DELADDR"; | ||
245 | 239 | + case RTM_GETROUTE: | ||
246 | 240 | + return "GETROUTE"; | ||
247 | 241 | + case RTM_NEWROUTE: | ||
248 | 242 | + return "NEWROUTE"; | ||
249 | 243 | + case RTM_DELROUTE: | ||
250 | 244 | + return "DELROUTE"; | ||
251 | 245 | + case RTM_NEWNDUSEROPT: | ||
252 | 246 | + return "NEWNDUSEROPT"; | ||
253 | 247 | + default: | ||
254 | 248 | + return "UNKNOWN"; | ||
255 | 249 | + } | ||
256 | 250 | +} | ||
257 | 251 | + | ||
258 | 252 | +static const char * | ||
259 | 253 | +operstate_to_str (unsigned char operstate) | ||
260 | 254 | +{ | ||
261 | 255 | + switch (operstate) { | ||
262 | 256 | + case IF_OPER_UNKNOWN: | ||
263 | 257 | + return "UNKNOWN"; | ||
264 | 258 | + case IF_OPER_NOTPRESENT: | ||
265 | 259 | + return "NOT-PRESENT"; | ||
266 | 260 | + case IF_OPER_DOWN: | ||
267 | 261 | + return "DOWN"; | ||
268 | 262 | + case IF_OPER_LOWERLAYERDOWN: | ||
269 | 263 | + return "LOWER-LAYER-DOWN"; | ||
270 | 264 | + case IF_OPER_TESTING: | ||
271 | 265 | + return "TESTING"; | ||
272 | 266 | + case IF_OPER_DORMANT: | ||
273 | 267 | + return "DORMANT"; | ||
274 | 268 | + case IF_OPER_UP: | ||
275 | 269 | + return "UP"; | ||
276 | 270 | + default: | ||
277 | 271 | + return ""; | ||
278 | 272 | + } | ||
279 | 273 | +} | ||
280 | 274 | + | ||
281 | 275 | +static gboolean | ||
282 | 276 | +extract_link (struct ifinfomsg *msg, int bytes, | ||
283 | 277 | + struct ether_addr *address, const char **ifname, | ||
284 | 278 | + unsigned int *mtu, unsigned char *operstate, | ||
285 | 279 | + struct rtnl_link_stats *stats) | ||
286 | 280 | +{ | ||
287 | 281 | + struct rtattr *attr; | ||
288 | 282 | + | ||
289 | 283 | + for (attr = IFLA_RTA (msg); RTA_OK (attr, bytes); | ||
290 | 284 | + attr = RTA_NEXT (attr, bytes)) { | ||
291 | 285 | + | ||
292 | 286 | + switch (attr->rta_type) { | ||
293 | 287 | + case IFLA_ADDRESS: | ||
294 | 288 | + if (address) | ||
295 | 289 | + memcpy (address, RTA_DATA (attr), ETH_ALEN); | ||
296 | 290 | + break; | ||
297 | 291 | + case IFLA_IFNAME: | ||
298 | 292 | + if (ifname) | ||
299 | 293 | + *ifname = RTA_DATA (attr); | ||
300 | 294 | + break; | ||
301 | 295 | + case IFLA_MTU: | ||
302 | 296 | + if (mtu) | ||
303 | 297 | + *mtu = *(unsigned int *) RTA_DATA (attr); | ||
304 | 298 | + break; | ||
305 | 299 | + case IFLA_STATS: | ||
306 | 300 | + if (stats) | ||
307 | 301 | + memcpy (stats, RTA_DATA (attr), | ||
308 | 302 | + sizeof (struct rtnl_link_stats)); | ||
309 | 303 | + break; | ||
310 | 304 | + case IFLA_OPERSTATE: | ||
311 | 305 | + if (operstate) | ||
312 | 306 | + *operstate = *(unsigned char *) RTA_DATA (attr); | ||
313 | 307 | + break; | ||
314 | 308 | + case IFLA_LINKMODE: | ||
315 | 309 | + break; | ||
316 | 310 | + case IFLA_WIRELESS: | ||
317 | 311 | + return FALSE; | ||
318 | 312 | + } | ||
319 | 313 | + } | ||
320 | 314 | + | ||
321 | 315 | + return TRUE; | ||
322 | 316 | +} | ||
323 | 317 | + | ||
324 | 318 | +static void | ||
325 | 319 | +process_newlink (NMDeviceStatistics *self, unsigned short type, int index, | ||
326 | 320 | + unsigned flags, unsigned change, struct ifinfomsg *msg, | ||
327 | 321 | + int bytes) | ||
328 | 322 | +{ | ||
329 | 323 | + struct ether_addr address = { { 0, 0, 0, 0, 0, 0 } }; | ||
330 | 324 | + struct rtnl_link_stats stats = { 0 }; | ||
331 | 325 | + unsigned char operstate = 0xFF; | ||
332 | 326 | + const char *ifname = NULL; | ||
333 | 327 | + unsigned int mtu = 0; | ||
334 | 328 | + char hw_addr[3 * sizeof (address)]; | ||
335 | 329 | + | ||
336 | 330 | + if (!extract_link (msg, bytes, &address, &ifname, &mtu, &operstate, &stats)) | ||
337 | 331 | + return; | ||
338 | 332 | + | ||
339 | 333 | + if (g_strcmp0 (ifname, self->iface) != 0) | ||
340 | 334 | + return; | ||
341 | 335 | + | ||
342 | 336 | + snprintf(hw_addr, sizeof (hw_addr), "%02X:%02X:%02X:%02X:%02X:%02X", | ||
343 | 337 | + address.ether_addr_octet[0], | ||
344 | 338 | + address.ether_addr_octet[1], | ||
345 | 339 | + address.ether_addr_octet[2], | ||
346 | 340 | + address.ether_addr_octet[3], | ||
347 | 341 | + address.ether_addr_octet[4], | ||
348 | 342 | + address.ether_addr_octet[5]); | ||
349 | 343 | + | ||
350 | 344 | + if (flags & IFF_SLAVE) { | ||
351 | 345 | + _LOGD ("%s {newlink} ignoring slave, index %d address %s", | ||
352 | 346 | + ifname, index, hw_addr); | ||
353 | 347 | + return; | ||
354 | 348 | + } | ||
355 | 349 | + | ||
356 | 350 | + _LOGD ("%s {newlink} index %d address %s mtu %u operstate %u <%s>", | ||
357 | 351 | + ifname, index, hw_addr, mtu, operstate, operstate_to_str (operstate)); | ||
358 | 352 | + _LOGD ("%s {RX} %u packets %u bytes", ifname, | ||
359 | 353 | + stats.rx_packets, stats.rx_bytes); | ||
360 | 354 | + _LOGD ("%s {TX} %u packets %u bytes", ifname, | ||
361 | 355 | + stats.tx_packets, stats.tx_bytes); | ||
362 | 356 | + | ||
363 | 357 | + nm_device_set_tx_bytes (self->device, stats.tx_bytes); | ||
364 | 358 | + nm_device_set_rx_bytes (self->device, stats.rx_bytes); | ||
365 | 359 | +} | ||
366 | 360 | + | ||
367 | 361 | +static void | ||
368 | 362 | +rtnl_newlink (NMDeviceStatistics *self, struct nlmsghdr *hdr) | ||
369 | 363 | +{ | ||
370 | 364 | + struct ifinfomsg *msg = (struct ifinfomsg *) NLMSG_DATA (hdr); | ||
371 | 365 | + | ||
372 | 366 | + if (hdr->nlmsg_type == IFLA_WIRELESS) | ||
373 | 367 | + _LOGW ("Obsolete WEXT WiFi driver detected"); | ||
374 | 368 | + | ||
375 | 369 | + process_newlink (self, msg->ifi_type, msg->ifi_index, msg->ifi_flags, | ||
376 | 370 | + msg->ifi_change, msg, IFA_PAYLOAD (hdr)); | ||
377 | 371 | +} | ||
378 | 372 | + | ||
379 | 373 | +static void | ||
380 | 374 | +rtnl_message (NMDeviceStatistics *self, unsigned char *buf, size_t len) | ||
381 | 375 | +{ | ||
382 | 376 | + while (len > 0) { | ||
383 | 377 | + struct nlmsghdr *hdr = (struct nlmsghdr *) buf; | ||
384 | 378 | + struct nlmsgerr *err; | ||
385 | 379 | + | ||
386 | 380 | + if (!NLMSG_OK (hdr, len)) | ||
387 | 381 | + break; | ||
388 | 382 | + | ||
389 | 383 | + switch (hdr->nlmsg_type) { | ||
390 | 384 | + case NLMSG_NOOP: | ||
391 | 385 | + case NLMSG_OVERRUN: | ||
392 | 386 | + return; | ||
393 | 387 | + case NLMSG_DONE: | ||
394 | 388 | + if (hdr->nlmsg_seq == self->request_seq - 1) | ||
395 | 389 | + self->req_pending = FALSE; | ||
396 | 390 | + return; | ||
397 | 391 | + case NLMSG_ERROR: | ||
398 | 392 | + err = NLMSG_DATA (hdr); | ||
399 | 393 | + return; | ||
400 | 394 | + case RTM_NEWLINK: | ||
401 | 395 | + rtnl_newlink (self, hdr); | ||
402 | 396 | + break; | ||
403 | 397 | + case RTM_DELLINK: | ||
404 | 398 | + case RTM_NEWADDR: | ||
405 | 399 | + case RTM_DELADDR: | ||
406 | 400 | + case RTM_NEWROUTE: | ||
407 | 401 | + case RTM_DELROUTE: | ||
408 | 402 | + case RTM_NEWNDUSEROPT: | ||
409 | 403 | + break; | ||
410 | 404 | + } | ||
411 | 405 | + | ||
412 | 406 | + len -= hdr->nlmsg_len; | ||
413 | 407 | + buf += hdr->nlmsg_len; | ||
414 | 408 | + } | ||
415 | 409 | +} | ||
416 | 410 | + | ||
417 | 411 | +static gboolean | ||
418 | 412 | +netlink_event (GIOChannel *chan, GIOCondition cond, gpointer data) | ||
419 | 413 | +{ | ||
420 | 414 | + struct sockaddr_nl nladdr = { 0 }; | ||
421 | 415 | + socklen_t addr_len = sizeof (nladdr); | ||
422 | 416 | + ssize_t status; | ||
423 | 417 | + int fd; | ||
424 | 418 | + NMDeviceStatistics *self = data; | ||
425 | 419 | + | ||
426 | 420 | + if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) { | ||
427 | 421 | + _LOGE ("netlink socket error %d", errno); | ||
428 | 422 | + return FALSE; | ||
429 | 423 | + } | ||
430 | 424 | + | ||
431 | 425 | + fd = g_io_channel_unix_get_fd (chan); | ||
432 | 426 | + | ||
433 | 427 | + status = recvfrom (fd, self->buf, sizeof (self->buf), 0, | ||
434 | 428 | + (struct sockaddr *) &nladdr, &addr_len); | ||
435 | 429 | + if (status < 0) { | ||
436 | 430 | + if (errno == EINTR || errno == EAGAIN) | ||
437 | 431 | + return TRUE; | ||
438 | 432 | + | ||
439 | 433 | + _LOGE ("error %d on receiving from netlink socket", errno); | ||
440 | 434 | + return FALSE; | ||
441 | 435 | + } | ||
442 | 436 | + | ||
443 | 437 | + /* EOF, remove callback */ | ||
444 | 438 | + if (status == 0) | ||
445 | 439 | + return FALSE; | ||
446 | 440 | + | ||
447 | 441 | + /* not sent by kernel, ignore */ | ||
448 | 442 | + if (nladdr.nl_pid != 0) | ||
449 | 443 | + return TRUE; | ||
450 | 444 | + | ||
451 | 445 | + rtnl_message (self, self->buf, status); | ||
452 | 446 | + | ||
453 | 447 | + return TRUE; | ||
454 | 448 | +} | ||
455 | 449 | + | ||
456 | 450 | +static int | ||
457 | 451 | +send_getlink (NMDeviceStatistics *self) | ||
458 | 452 | +{ | ||
459 | 453 | + struct rtnl_request req = { 0 }; | ||
460 | 454 | + struct sockaddr_nl addr = { 0 }; | ||
461 | 455 | + int sk; | ||
462 | 456 | + | ||
463 | 457 | + req.hdr.nlmsg_len = RTNL_REQUEST_SIZE; | ||
464 | 458 | + req.hdr.nlmsg_type = RTM_GETLINK; | ||
465 | 459 | + req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; | ||
466 | 460 | + req.hdr.nlmsg_pid = 0; | ||
467 | 461 | + req.hdr.nlmsg_seq = self->request_seq++; | ||
468 | 462 | + req.msg.rtgen_family = AF_UNSPEC; | ||
469 | 463 | + | ||
470 | 464 | + _LOGD ("Sending %s len %d type %d flags 0x%04x seq %d", | ||
471 | 465 | + type_to_string (req.hdr.nlmsg_type), | ||
472 | 466 | + req.hdr.nlmsg_len, req.hdr.nlmsg_type, | ||
473 | 467 | + req.hdr.nlmsg_flags, req.hdr.nlmsg_seq); | ||
474 | 468 | + | ||
475 | 469 | + sk = g_io_channel_unix_get_fd(self->channel); | ||
476 | 470 | + | ||
477 | 471 | + addr.nl_family = AF_NETLINK; | ||
478 | 472 | + | ||
479 | 473 | + self->req_pending = TRUE; | ||
480 | 474 | + | ||
481 | 475 | + return sendto (sk, &req, req.hdr.nlmsg_len, 0, | ||
482 | 476 | + (struct sockaddr *) &addr, sizeof (addr)); | ||
483 | 477 | +} | ||
484 | 478 | + | ||
485 | 479 | +static gboolean | ||
486 | 480 | +update_stats (gpointer user_data) | ||
487 | 481 | +{ | ||
488 | 482 | + NMDeviceStatistics *self = user_data; | ||
489 | 483 | + | ||
490 | 484 | + if (self->req_pending) { | ||
491 | 485 | + _LOGD ("no response yet for pending netlink request"); | ||
492 | 486 | + return TRUE; | ||
493 | 487 | + } | ||
494 | 488 | + | ||
495 | 489 | + send_getlink (self); | ||
496 | 490 | + return TRUE; | ||
497 | 491 | +} | ||
498 | 492 | + | ||
499 | 493 | +/********************************************/ | ||
500 | 494 | + | ||
501 | 495 | +NMDeviceStatistics * | ||
502 | 496 | +nm_device_statistics_create (NMDevice *device, const char *iface, unsigned rate_ms) | ||
503 | 497 | +{ | ||
504 | 498 | + NMDeviceStatistics *self; | ||
505 | 499 | + struct sockaddr_nl addr = { 0 }; | ||
506 | 500 | + int sk; | ||
507 | 501 | + GIOChannel *channel = NULL; | ||
508 | 502 | + guint channel_watch = 0; | ||
509 | 503 | + | ||
510 | 504 | + self = g_malloc0 (sizeof (*self)); | ||
511 | 505 | + | ||
512 | 506 | + sk = socket (PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE); | ||
513 | 507 | + if (sk < 0) { | ||
514 | 508 | + _LOGE ("Cannot create netlink socket: %d", errno); | ||
515 | 509 | + goto error; | ||
516 | 510 | + } | ||
517 | 511 | + | ||
518 | 512 | + addr.nl_family = AF_NETLINK; | ||
519 | 513 | + addr.nl_groups = RTMGRP_LINK; | ||
520 | 514 | + | ||
521 | 515 | + if (bind (sk, (struct sockaddr *) &addr, sizeof (addr)) < 0) { | ||
522 | 516 | + close (sk); | ||
523 | 517 | + _LOGE ("Cannot bind to netlink socket: %d", errno); | ||
524 | 518 | + goto error; | ||
525 | 519 | + } | ||
526 | 520 | + | ||
527 | 521 | + channel = g_io_channel_unix_new (sk); | ||
528 | 522 | + | ||
529 | 523 | + g_io_channel_set_close_on_unref (channel, TRUE); | ||
530 | 524 | + g_io_channel_set_encoding (channel, NULL, NULL); | ||
531 | 525 | + g_io_channel_set_buffered (channel, FALSE); | ||
532 | 526 | + | ||
533 | 527 | + channel_watch = | ||
534 | 528 | + g_io_add_watch (channel, | ||
535 | 529 | + G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR, | ||
536 | 530 | + netlink_event, self); | ||
537 | 531 | + | ||
538 | 532 | + self->device = device; | ||
539 | 533 | + self->iface = g_strdup (iface); | ||
540 | 534 | + self->channel = channel; | ||
541 | 535 | + self->channel_watch = channel_watch; | ||
542 | 536 | + self->stats_update_id = g_timeout_add (rate_ms, update_stats, self); | ||
543 | 537 | + | ||
544 | 538 | + return self; | ||
545 | 539 | + | ||
546 | 540 | +error: | ||
547 | 541 | + g_free (self); | ||
548 | 542 | + return NULL; | ||
549 | 543 | +} | ||
550 | 544 | + | ||
551 | 545 | +void | ||
552 | 546 | +nm_device_statistics_remove (NMDeviceStatistics *self) | ||
553 | 547 | +{ | ||
554 | 548 | + g_source_remove (self->stats_update_id); | ||
555 | 549 | + g_source_remove (self->channel_watch); | ||
556 | 550 | + g_io_channel_unref (self->channel); | ||
557 | 551 | + g_free (self->iface); | ||
558 | 552 | + g_free (self); | ||
559 | 553 | +} | ||
560 | 554 | diff --git a/src/devices/nm-device-statistics.h b/src/devices/nm-device-statistics.h | ||
561 | 555 | new file mode 100644 | ||
562 | 556 | index 0000000..496cecc | ||
563 | 557 | --- /dev/null | ||
564 | 558 | +++ b/src/devices/nm-device-statistics.h | ||
565 | 559 | @@ -0,0 +1,33 @@ | ||
566 | 560 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ | ||
567 | 561 | +/* This program is free software; you can redistribute it and/or modify | ||
568 | 562 | + * it under the terms of the GNU General Public License as published by | ||
569 | 563 | + * the Free Software Foundation; either version 2, or (at your option) | ||
570 | 564 | + * any later version. | ||
571 | 565 | + * | ||
572 | 566 | + * This program is distributed in the hope that it will be useful, | ||
573 | 567 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
574 | 568 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
575 | 569 | + * GNU General Public License for more details. | ||
576 | 570 | + * | ||
577 | 571 | + * You should have received a copy of the GNU General Public License along | ||
578 | 572 | + * with this program; if not, write to the Free Software Foundation, Inc., | ||
579 | 573 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
580 | 574 | + * | ||
581 | 575 | + * Copyright (C) 2016 Canonical Ltd | ||
582 | 576 | + */ | ||
583 | 577 | + | ||
584 | 578 | +#ifndef __NETWORKMANAGER_DEVICE_STATISTICS_H__ | ||
585 | 579 | +#define __NETWORKMANAGER_DEVICE_STATISTICS_H__ | ||
586 | 580 | + | ||
587 | 581 | +#include <stdlib.h> | ||
588 | 582 | + | ||
589 | 583 | +#include "nm-default.h" | ||
590 | 584 | + | ||
591 | 585 | +typedef struct _NMDeviceStatistics NMDeviceStatistics; | ||
592 | 586 | + | ||
593 | 587 | +NMDeviceStatistics * | ||
594 | 588 | +nm_device_statistics_create (NMDevice *device, const char *iface, unsigned rate_ms); | ||
595 | 589 | + | ||
596 | 590 | +void nm_device_statistics_remove (NMDeviceStatistics *self); | ||
597 | 591 | + | ||
598 | 592 | +#endif /* __NETWORKMANAGER_DEVICE_STATISTICS_H__ */ | ||
599 | 593 | diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c | ||
600 | 594 | index 8472ff8..eddd0ad 100644 | ||
601 | 595 | --- a/src/devices/nm-device.c | ||
602 | 596 | +++ b/src/devices/nm-device.c | ||
603 | 597 | @@ -64,11 +64,13 @@ | ||
604 | 598 | #include "sd-ipv4ll.h" | ||
605 | 599 | #include "nm-audit-manager.h" | ||
606 | 600 | #include "nm-arping-manager.h" | ||
607 | 601 | +#include "nm-device-statistics.h" | ||
608 | 602 | |||
609 | 603 | #include "nm-device-logging.h" | ||
610 | 604 | _LOG_DECLARE_SELF (NMDevice); | ||
611 | 605 | |||
612 | 606 | #include "nmdbus-device.h" | ||
613 | 607 | +#include "nmdbus-device-statistics.h" | ||
614 | 608 | |||
615 | 609 | G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) | ||
616 | 610 | |||
617 | 611 | @@ -124,6 +126,9 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice, | ||
618 | 612 | PROP_LLDP_NEIGHBORS, | ||
619 | 613 | PROP_REAL, | ||
620 | 614 | PROP_SLAVES, | ||
621 | 615 | + PROP_REFRESH_RATE_MS, | ||
622 | 616 | + PROP_TX_BYTES, | ||
623 | 617 | + PROP_RX_BYTES, | ||
624 | 618 | ); | ||
625 | 619 | |||
626 | 620 | #define DEFAULT_AUTOCONNECT TRUE | ||
627 | 621 | @@ -369,6 +374,13 @@ typedef struct _NMDevicePrivate { | ||
628 | 622 | NMLldpListener *lldp_listener; | ||
629 | 623 | |||
630 | 624 | guint check_delete_unrealized_id; | ||
631 | 625 | + | ||
632 | 626 | + guint32 refresh_rate_ms; | ||
633 | 627 | + guint64 tx_bytes; | ||
634 | 628 | + guint64 rx_bytes; | ||
635 | 629 | + | ||
636 | 630 | + NMDeviceStatistics *statistics; | ||
637 | 631 | + | ||
638 | 632 | } NMDevicePrivate; | ||
639 | 633 | |||
640 | 634 | static gboolean nm_device_set_ip4_config (NMDevice *self, | ||
641 | 635 | @@ -656,6 +668,36 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface) | ||
642 | 636 | g_free (old_ip_iface); | ||
643 | 637 | } | ||
644 | 638 | |||
645 | 639 | +void | ||
646 | 640 | +nm_device_set_tx_bytes (NMDevice *self, guint64 tx_bytes) | ||
647 | 641 | +{ | ||
648 | 642 | + NMDevicePrivate *priv; | ||
649 | 643 | + | ||
650 | 644 | + g_return_if_fail (NM_IS_DEVICE (self)); | ||
651 | 645 | + | ||
652 | 646 | + priv = NM_DEVICE_GET_PRIVATE (self); | ||
653 | 647 | + if (tx_bytes == priv->tx_bytes) | ||
654 | 648 | + return; | ||
655 | 649 | + | ||
656 | 650 | + priv->tx_bytes = tx_bytes; | ||
657 | 651 | + _notify (self, PROP_TX_BYTES); | ||
658 | 652 | +} | ||
659 | 653 | + | ||
660 | 654 | +void | ||
661 | 655 | +nm_device_set_rx_bytes (NMDevice *self, guint64 rx_bytes) | ||
662 | 656 | +{ | ||
663 | 657 | + NMDevicePrivate *priv; | ||
664 | 658 | + | ||
665 | 659 | + g_return_if_fail (NM_IS_DEVICE (self)); | ||
666 | 660 | + | ||
667 | 661 | + priv = NM_DEVICE_GET_PRIVATE (self); | ||
668 | 662 | + if (rx_bytes == priv->rx_bytes) | ||
669 | 663 | + return; | ||
670 | 664 | + | ||
671 | 665 | + priv->rx_bytes = rx_bytes; | ||
672 | 666 | + _notify (self, PROP_RX_BYTES); | ||
673 | 667 | +} | ||
674 | 668 | + | ||
675 | 669 | static gboolean | ||
676 | 670 | get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *out_iid) | ||
677 | 671 | { | ||
678 | 672 | @@ -11157,6 +11199,11 @@ nm_device_init (NMDevice *self) | ||
679 | 673 | |||
680 | 674 | priv->v4_commit_first_time = TRUE; | ||
681 | 675 | priv->v6_commit_first_time = TRUE; | ||
682 | 676 | + | ||
683 | 677 | + priv->refresh_rate_ms = 0; | ||
684 | 678 | + priv->tx_bytes = 0; | ||
685 | 679 | + priv->rx_bytes = 0; | ||
686 | 680 | + priv->statistics = NULL; | ||
687 | 681 | } | ||
688 | 682 | |||
689 | 683 | static GObject* | ||
690 | 684 | @@ -11295,6 +11342,11 @@ dispose (GObject *object) | ||
691 | 685 | g_clear_object (&priv->lldp_listener); | ||
692 | 686 | } | ||
693 | 687 | |||
694 | 688 | + if (priv->statistics) { | ||
695 | 689 | + nm_device_statistics_remove (priv->statistics); | ||
696 | 690 | + priv->statistics = NULL; | ||
697 | 691 | + } | ||
698 | 692 | + | ||
699 | 693 | G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); | ||
700 | 694 | |||
701 | 695 | if (nm_clear_g_source (&priv->queued_state.id)) { | ||
702 | 696 | @@ -11342,7 +11394,7 @@ set_property (GObject *object, guint prop_id, | ||
703 | 697 | NMDevice *self = NM_DEVICE (object); | ||
704 | 698 | NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); | ||
705 | 699 | const char *hw_addr, *p; | ||
706 | 700 | - guint count; | ||
707 | 701 | + guint count, refresh_rate_ms; | ||
708 | 702 | |||
709 | 703 | switch (prop_id) { | ||
710 | 704 | case PROP_UDI: | ||
711 | 705 | @@ -11447,6 +11499,24 @@ set_property (GObject *object, guint prop_id, | ||
712 | 706 | priv->hw_addr = NULL; | ||
713 | 707 | } | ||
714 | 708 | break; | ||
715 | 709 | + case PROP_REFRESH_RATE_MS: | ||
716 | 710 | + refresh_rate_ms = g_value_get_uint (value); | ||
717 | 711 | + if (priv->refresh_rate_ms == refresh_rate_ms) | ||
718 | 712 | + break; | ||
719 | 713 | + | ||
720 | 714 | + priv->refresh_rate_ms = g_value_get_uint (value); | ||
721 | 715 | + _LOGI (LOGD_DEVICE, "statistics refresh rate set to %u ms", priv->refresh_rate_ms); | ||
722 | 716 | + | ||
723 | 717 | + if (priv->statistics) { | ||
724 | 718 | + nm_device_statistics_remove (priv->statistics); | ||
725 | 719 | + priv->statistics = NULL; | ||
726 | 720 | + } | ||
727 | 721 | + if (priv->refresh_rate_ms) | ||
728 | 722 | + priv->statistics = | ||
729 | 723 | + nm_device_statistics_create (self, | ||
730 | 724 | + nm_device_get_ip_iface (self), | ||
731 | 725 | + priv->refresh_rate_ms); | ||
732 | 726 | + break; | ||
733 | 727 | default: | ||
734 | 728 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
735 | 729 | break; | ||
736 | 730 | @@ -11605,6 +11675,15 @@ get_property (GObject *object, guint prop_id, | ||
737 | 731 | g_value_take_boxed (value, slave_list); | ||
738 | 732 | break; | ||
739 | 733 | } | ||
740 | 734 | + case PROP_REFRESH_RATE_MS: | ||
741 | 735 | + g_value_set_uint (value, priv->refresh_rate_ms); | ||
742 | 736 | + break; | ||
743 | 737 | + case PROP_TX_BYTES: | ||
744 | 738 | + g_value_set_uint64 (value, priv->tx_bytes); | ||
745 | 739 | + break; | ||
746 | 740 | + case PROP_RX_BYTES: | ||
747 | 741 | + g_value_set_uint64 (value, priv->rx_bytes); | ||
748 | 742 | + break; | ||
749 | 743 | default: | ||
750 | 744 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
751 | 745 | break; | ||
752 | 746 | @@ -11848,6 +11927,23 @@ nm_device_class_init (NMDeviceClass *klass) | ||
753 | 747 | G_PARAM_READABLE | | ||
754 | 748 | G_PARAM_STATIC_STRINGS); | ||
755 | 749 | |||
756 | 750 | + /* Statistics */ | ||
757 | 751 | + obj_properties[PROP_REFRESH_RATE_MS] = | ||
758 | 752 | + g_param_spec_uint (NM_DEVICE_STATISTICS_REFRESH_RATE_MS, "", "", | ||
759 | 753 | + 0, UINT_MAX, 0, | ||
760 | 754 | + G_PARAM_READWRITE | | ||
761 | 755 | + G_PARAM_STATIC_STRINGS); | ||
762 | 756 | + obj_properties[PROP_TX_BYTES] = | ||
763 | 757 | + g_param_spec_uint64 (NM_DEVICE_STATISTICS_TX_BYTES, "", "", | ||
764 | 758 | + 0, UINT64_MAX, 0, | ||
765 | 759 | + G_PARAM_READABLE | | ||
766 | 760 | + G_PARAM_STATIC_STRINGS); | ||
767 | 761 | + obj_properties[PROP_RX_BYTES] = | ||
768 | 762 | + g_param_spec_uint64 (NM_DEVICE_STATISTICS_RX_BYTES, "", "", | ||
769 | 763 | + 0, UINT64_MAX, 0, | ||
770 | 764 | + G_PARAM_READABLE | | ||
771 | 765 | + G_PARAM_STATIC_STRINGS); | ||
772 | 766 | + | ||
773 | 767 | g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); | ||
774 | 768 | |||
775 | 769 | /* Signals */ | ||
776 | 770 | @@ -11918,4 +12014,8 @@ nm_device_class_init (NMDeviceClass *klass) | ||
777 | 771 | "Disconnect", impl_device_disconnect, | ||
778 | 772 | "Delete", impl_device_delete, | ||
779 | 773 | NULL); | ||
780 | 774 | + | ||
781 | 775 | + nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass), | ||
782 | 776 | + NMDBUS_TYPE_DEVICE_STATISTICS_SKELETON, | ||
783 | 777 | + NULL); | ||
784 | 778 | } | ||
785 | 779 | diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h | ||
786 | 780 | index 9f68985..f226d45 100644 | ||
787 | 781 | --- a/src/devices/nm-device.h | ||
788 | 782 | +++ b/src/devices/nm-device.h | ||
789 | 783 | @@ -84,6 +84,10 @@ | ||
790 | 784 | #define NM_DEVICE_STATE_CHANGED "state-changed" | ||
791 | 785 | #define NM_DEVICE_LINK_INITIALIZED "link-initialized" | ||
792 | 786 | |||
793 | 787 | +#define NM_DEVICE_STATISTICS_REFRESH_RATE_MS "refresh-rate-ms" | ||
794 | 788 | +#define NM_DEVICE_STATISTICS_TX_BYTES "tx-bytes" | ||
795 | 789 | +#define NM_DEVICE_STATISTICS_RX_BYTES "rx-bytes" | ||
796 | 790 | + | ||
797 | 791 | G_BEGIN_DECLS | ||
798 | 792 | |||
799 | 793 | #define NM_TYPE_DEVICE (nm_device_get_type ()) | ||
800 | 794 | diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c | ||
801 | 795 | index 10f7d23..2fdb27c 100644 | ||
802 | 796 | --- a/src/nm-exported-object.c | ||
803 | 797 | +++ b/src/nm-exported-object.c | ||
804 | 798 | @@ -257,12 +257,16 @@ nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, | ||
805 | 799 | g_return_if_fail (NM_IS_EXPORTED_OBJECT_CLASS (object_class)); | ||
806 | 800 | g_return_if_fail (g_type_is_a (dbus_skeleton_type, G_TYPE_DBUS_INTERFACE_SKELETON)); | ||
807 | 801 | |||
808 | 802 | - classinfo = g_slice_new (NMExportedObjectClassInfo); | ||
809 | 803 | - classinfo->skeleton_types = NULL; | ||
810 | 804 | - classinfo->methods = g_array_new (FALSE, FALSE, sizeof (NMExportedObjectDBusMethodImpl)); | ||
811 | 805 | - classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal); | ||
812 | 806 | - g_type_set_qdata (G_TYPE_FROM_CLASS (object_class), | ||
813 | 807 | - nm_exported_object_class_info_quark (), classinfo); | ||
814 | 808 | + classinfo = g_type_get_qdata (G_TYPE_FROM_CLASS (object_class), | ||
815 | 809 | + nm_exported_object_class_info_quark ()); | ||
816 | 810 | + if (!classinfo) { | ||
817 | 811 | + classinfo = g_slice_new (NMExportedObjectClassInfo); | ||
818 | 812 | + classinfo->skeleton_types = NULL; | ||
819 | 813 | + classinfo->methods = g_array_new (FALSE, FALSE, sizeof (NMExportedObjectDBusMethodImpl)); | ||
820 | 814 | + classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal); | ||
821 | 815 | + g_type_set_qdata (G_TYPE_FROM_CLASS (object_class), | ||
822 | 816 | + nm_exported_object_class_info_quark (), classinfo); | ||
823 | 817 | + } | ||
824 | 818 | |||
825 | 819 | classinfo->skeleton_types = g_slist_prepend (classinfo->skeleton_types, | ||
826 | 820 | GSIZE_TO_POINTER (dbus_skeleton_type)); | ||
827 | 821 | @@ -342,8 +346,6 @@ nm_exported_object_class_add_interface (NMExportedObjectClass *object_class, | ||
828 | 822 | } | ||
829 | 823 | } | ||
830 | 824 | |||
831 | 825 | - g_assert_cmpint (n_method_signals, ==, classinfo->methods->len); | ||
832 | 826 | - | ||
833 | 827 | g_type_class_unref (dbus_object_class); | ||
834 | 828 | } | ||
835 | 829 | |||
836 | 830 | diff --git a/src/nm-types.h b/src/nm-types.h | ||
837 | 831 | index 997723e..8f859e8 100644 | ||
838 | 832 | --- a/src/nm-types.h | ||
839 | 833 | +++ b/src/nm-types.h | ||
840 | 834 | @@ -40,6 +40,7 @@ typedef struct _NMConnectionProvider NMConnectionProvider; | ||
841 | 835 | typedef struct _NMConnectivity NMConnectivity; | ||
842 | 836 | typedef struct _NMDefaultRouteManager NMDefaultRouteManager; | ||
843 | 837 | typedef struct _NMDevice NMDevice; | ||
844 | 838 | +typedef struct _NMDeviceStatistics NMDeviceStatistics; | ||
845 | 839 | typedef struct _NMDhcp4Config NMDhcp4Config; | ||
846 | 840 | typedef struct _NMDhcp6Config NMDhcp6Config; | ||
847 | 841 | typedef struct _NMIP4Config NMIP4Config; | ||
848 | diff --git a/debian/patches/series b/debian/patches/series | |||
849 | index f0a8f73..4bd2565 100644 | |||
850 | --- a/debian/patches/series | |||
851 | +++ b/debian/patches/series | |||
852 | @@ -22,3 +22,4 @@ Modify-NMDeviceModem-s-available-logic.patch | |||
853 | 22 | Track-killswitch-change-signals-from-urfkill.patch | 22 | Track-killswitch-change-signals-from-urfkill.patch |
854 | 23 | Only-test-team-devices-if-we-built-support-for-them.patch | 23 | Only-test-team-devices-if-we-built-support-for-them.patch |
855 | 24 | Disable-general-with-expect-which-tends-to-fail-on-p.patch | 24 | Disable-general-with-expect-which-tends-to-fail-on-p.patch |
856 | 25 | Add-statistics-interface.patch |
Branch refreshed after addressing comments.