int mtu;
struct netdev_stats stats;
enum netdev_flags flags;
+ unsigned int change_seq;
};
struct netdev_dummy {
netdev_dev->hwaddr[5] = n;
netdev_dev->mtu = 1500;
netdev_dev->flags = 0;
+ netdev_dev->change_seq = 1;
n++;
free(notifier);
}
+
+static unsigned int
+netdev_dummy_change_seq(const struct netdev *netdev)
+{
+ return netdev_dev_dummy_cast(netdev_get_dev(netdev))->change_seq;
+}
\f
/* Helper functions. */
{
const char *name = netdev_get_name(netdev);
struct list *list = shash_find_data(&netdev_dummy_notifiers, name);
+ struct netdev_dev_dummy *dev =
+ netdev_dev_dummy_cast(netdev_get_dev(netdev));
if (list) {
struct netdev_dummy_notifier *notifier;
n->cb(n);
}
}
+
+ dev->change_seq++;
+ if (!dev->change_seq) {
+ dev->change_seq++;
+ }
}
static const struct netdev_class dummy_class = {
netdev_dummy_poll_add,
netdev_dummy_poll_remove,
+ netdev_dummy_change_seq
};
void
struct shash_node *shash_node;
unsigned int cache_valid;
+ unsigned int change_seq;
bool miimon; /* Link status of last poll. */
long long int miimon_interval; /* Miimon Poll rate. Disabled if <= 0. */
netdev_linux_miimon_wait();
}
+static void
+netdev_dev_linux_changed(struct netdev_dev_linux *dev)
+{
+ dev->change_seq++;
+ if (!dev->change_seq) {
+ dev->change_seq++;
+ }
+ dev->cache_valid = 0;
+}
+
static void
netdev_linux_cache_cb(const struct rtnetlink_link_change *change,
void *aux OVS_UNUSED)
if (is_netdev_linux_class(netdev_class)) {
dev = netdev_dev_linux_cast(base_dev);
- dev->cache_valid = 0;
+ netdev_dev_linux_changed(dev);
}
}
} else {
netdev_dev_get_devices(&netdev_linux_class, &device_shash);
SHASH_FOR_EACH (node, &device_shash) {
dev = node->data;
- dev->cache_valid = 0;
+ netdev_dev_linux_changed(dev);
}
shash_destroy(&device_shash);
}
cache_notifier_refcount++;
netdev_dev = xzalloc(sizeof *netdev_dev);
+ netdev_dev->change_seq = 1;
netdev_dev_init(&netdev_dev->netdev_dev, name, args, class);
*netdev_devp = &netdev_dev->netdev_dev;
if (list) {
poll_notify(list);
}
+ netdev_dev_linux_changed(dev);
}
timer_set_duration(&dev->miimon_timer, dev->miimon_interval);
}
}
+static unsigned int
+netdev_linux_change_seq(const struct netdev *netdev)
+{
+ return netdev_dev_linux_cast(netdev_get_dev(netdev))->change_seq;
+}
+
#define NETDEV_LINUX_CLASS(NAME, CREATE, ENUMERATE, SET_STATS) \
{ \
NAME, \
netdev_linux_update_flags, \
\
netdev_linux_poll_add, \
- netdev_linux_poll_remove \
+ netdev_linux_poll_remove, \
+ netdev_linux_change_seq \
}
const struct netdev_class netdev_linux_class =
void (*run)(void);
/* Arranges for poll_block() to wake up if the "run" member function needs
- * to be called. May be null if nothing is needed here. */
+ * to be called. Implementations are additionally required to wake
+ * whenever something changes in any of its netdevs which would cause their
+ * ->change_seq() function to change its result. May be null if nothing is
+ * needed here. */
void (*wait)(void);
/* Attempts to create a network device named 'name' with initial 'args' in
/* Cancels poll notification for 'notifier'. */
void (*poll_remove)(struct netdev_notifier *notifier);
+
+ /* Returns a sequence number which indicates changes in one of 'netdev''s
+ * properties. The returned sequence number must be nonzero so that
+ * callers have a value which they may use as a reset when tracking
+ * 'netdev'.
+ *
+ * Minimally, the returned sequence number is required to change whenever
+ * 'netdev''s flags, features, ethernet address, or carrier changes. The
+ * returned sequence number is allowed to change even when 'netdev' doesn't
+ * change, although implementations should try to avoid this. */
+ unsigned int (*change_seq)(const struct netdev *netdev);
};
int netdev_register_provider(const struct netdev_class *);
struct ofpbuf *options;
int dp_ifindex; /* -1 if unknown. */
uint32_t port_no; /* UINT32_MAX if unknown. */
+ unsigned int change_seq;
};
struct netdev_vport {
dev->options = options;
dev->dp_ifindex = dp_ifindex;
dev->port_no = port_no;
+ dev->change_seq = 1;
*netdev_devp = &dev->netdev_dev;
route_table_register();
free(notifier);
}
+static unsigned int
+netdev_vport_change_seq(const struct netdev *netdev)
+{
+ return netdev_dev_vport_cast(netdev_get_dev(netdev))->change_seq;
+}
+
static void
netdev_vport_run(void)
{
char *poll_name = make_poll_name(netdev);
struct list *list = shash_find_data(&netdev_vport_notifiers,
poll_name);
+ struct netdev_dev_vport *ndv;
+
+ ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
if (list) {
struct netdev_vport_notifier *notifier;
}
}
+ ndv->change_seq++;
+ if (!ndv->change_seq) {
+ ndv->change_seq++;
+ }
+
free(poll_name);
}
\f
netdev_vport_update_flags, \
\
netdev_vport_poll_add, \
- netdev_vport_poll_remove,
+ netdev_vport_poll_remove, \
+ netdev_vport_change_seq
void
netdev_vport_register(void)
: EOPNOTSUPP);
}
+/* Returns a sequence number which indicates changes in one of 'netdev''s
+ * properties. The returned sequence will be nonzero so that callers have a
+ * value which they may use as a reset when tracking 'netdev'.
+ *
+ * The returned sequence number will change whenever 'netdev''s flags,
+ * features, ethernet address, or carrier changes. It may change for other
+ * reasons as well, or no reason at all. */
+unsigned int
+netdev_change_seq(const struct netdev *netdev)
+{
+ return netdev_get_dev(netdev)->netdev_class->change_seq(netdev);
+}
+
/* If 'netdev' is a VLAN network device (e.g. one created with vconfig(8)),
* sets '*vlan_vid' to the VLAN VID associated with that device and returns 0.
* Otherwise returns a errno value (specifically ENOENT if 'netdev_name' is the
int netdev_dump_queue_stats(const struct netdev *,
netdev_dump_queue_stats_cb *, void *aux);
+unsigned int netdev_change_seq(const struct netdev *netdev);
+
/* Linux stuff. */
int netdev_get_vlan_vid(const struct netdev *, int *vlan_vid);
* caller must not modify or free.
*
* This is probably not the function that you want. You should probably be
- * using dpif_port_poll() or netdev_monitor_create(), which unlike this
- * function are not Linux-specific.
+ * using dpif_port_poll() or netdev_change_seq(), which unlike this function
+ * are not Linux-specific.
*
* Returns 0 if successful, otherwise a positive errno value. */
int