X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=vswitchd%2Fbridge.c;h=9868ef5b627e92cfd0f2b786f8eaa0395e37cb88;hb=8628b0b71d1cf5b3bd7425e50f0aa1435aa38804;hp=4b5d0faa9b60bf58d7c3fafa4017e1bde0c278af;hpb=48e1b7fb9b2e0f6c7cf3f54eda9679ec0130e737;p=openvswitch diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 4b5d0faa..9868ef5b 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -533,6 +533,7 @@ port_configure(struct port *port) ofproto_bundle_register(port->bridge->ofproto, port, &s); /* Clean up. */ + free(s.slaves); free(s.trunks); free(s.lacp_slaves); free(s.bond_stable_ids); @@ -1252,30 +1253,25 @@ iface_refresh_lacp_stats(struct iface *iface) static void iface_refresh_stats(struct iface *iface) { - struct iface_stat { - char *name; - int offset; - }; - static const struct iface_stat iface_stats[] = { - { "rx_packets", offsetof(struct netdev_stats, rx_packets) }, - { "tx_packets", offsetof(struct netdev_stats, tx_packets) }, - { "rx_bytes", offsetof(struct netdev_stats, rx_bytes) }, - { "tx_bytes", offsetof(struct netdev_stats, tx_bytes) }, - { "rx_dropped", offsetof(struct netdev_stats, rx_dropped) }, - { "tx_dropped", offsetof(struct netdev_stats, tx_dropped) }, - { "rx_errors", offsetof(struct netdev_stats, rx_errors) }, - { "tx_errors", offsetof(struct netdev_stats, tx_errors) }, - { "rx_frame_err", offsetof(struct netdev_stats, rx_frame_errors) }, - { "rx_over_err", offsetof(struct netdev_stats, rx_over_errors) }, - { "rx_crc_err", offsetof(struct netdev_stats, rx_crc_errors) }, - { "collisions", offsetof(struct netdev_stats, collisions) }, - }; - enum { N_STATS = ARRAY_SIZE(iface_stats) }; - const struct iface_stat *s; - - char *keys[N_STATS]; - int64_t values[N_STATS]; - int n; +#define IFACE_STATS \ + IFACE_STAT(rx_packets, "rx_packets") \ + IFACE_STAT(tx_packets, "tx_packets") \ + IFACE_STAT(rx_bytes, "rx_bytes") \ + IFACE_STAT(tx_bytes, "tx_bytes") \ + IFACE_STAT(rx_dropped, "rx_dropped") \ + IFACE_STAT(tx_dropped, "tx_dropped") \ + IFACE_STAT(rx_errors, "rx_errors") \ + IFACE_STAT(tx_errors, "tx_errors") \ + IFACE_STAT(rx_frame_errors, "rx_frame_err") \ + IFACE_STAT(rx_over_errors, "rx_over_err") \ + IFACE_STAT(rx_crc_errors, "rx_crc_err") \ + IFACE_STAT(collisions, "collisions") + +#define IFACE_STAT(MEMBER, NAME) NAME, + static char *keys[] = { IFACE_STATS }; +#undef IFACE_STAT + int64_t values[ARRAY_SIZE(keys)]; + int i; struct netdev_stats stats; @@ -1287,17 +1283,15 @@ iface_refresh_stats(struct iface *iface) * all-1s, and we will deal with that correctly below. */ netdev_get_stats(iface->netdev, &stats); - n = 0; - for (s = iface_stats; s < &iface_stats[N_STATS]; s++) { - uint64_t value = *(uint64_t *) (((char *) &stats) + s->offset); - if (value != UINT64_MAX) { - keys[n] = s->name; - values[n] = value; - n++; - } - } + /* Copy statistics into values[] array. */ + i = 0; +#define IFACE_STAT(MEMBER, NAME) values[i++] = stats.MEMBER; + IFACE_STATS; +#undef IFACE_STAT + assert(i == ARRAY_SIZE(keys)); - ovsrec_interface_set_statistics(iface->cfg, keys, values, n); + ovsrec_interface_set_statistics(iface->cfg, keys, values, ARRAY_SIZE(keys)); +#undef IFACE_STATS } static void