/*
- * Copyright (c) 2010 Nicira Networks.
+ * Copyright (c) 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
VLOG_DEFINE_THIS_MODULE(netdev_dummy);
-struct netdev_dummy_notifier {
- struct netdev_notifier notifier;
- struct list list_node;
- struct shash_node *shash_node;
-};
-
struct netdev_dev_dummy {
struct netdev_dev netdev_dev;
uint8_t hwaddr[ETH_ADDR_LEN];
int mtu;
struct netdev_stats stats;
enum netdev_flags flags;
+ unsigned int change_seq;
};
struct netdev_dummy {
struct netdev netdev;
};
-static struct shash netdev_dummy_notifiers =
- SHASH_INITIALIZER(&netdev_dummy_notifiers);
-
static int netdev_dummy_create(const struct netdev_class *, const char *,
- const struct shash *, struct netdev_dev **);
+ struct netdev_dev **);
static void netdev_dummy_poll_notify(const struct netdev *);
static bool
static int
netdev_dummy_create(const struct netdev_class *class, const char *name,
- const struct shash *args OVS_UNUSED,
struct netdev_dev **netdev_devp)
{
static unsigned int n = 0xaa550000;
netdev_dev->hwaddr[5] = n;
netdev_dev->mtu = 1500;
netdev_dev->flags = 0;
+ netdev_dev->change_seq = 1;
n++;
}
static int
-netdev_dummy_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
- struct netdev **netdevp)
+netdev_dummy_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
{
struct netdev_dummy *netdev;
free(netdev);
}
+static int
+netdev_dummy_listen(struct netdev *netdev_ OVS_UNUSED)
+{
+ /* It's OK to listen on a dummy device. It just never receives any
+ * packets. */
+ return 0;
+}
+
+static int
+netdev_dummy_recv(struct netdev *netdev_ OVS_UNUSED,
+ void *buffer OVS_UNUSED, size_t size OVS_UNUSED)
+{
+ /* A dummy device never receives any packets. */
+ return -EAGAIN;
+}
+
static int
netdev_dummy_set_etheraddr(struct netdev *netdev,
const uint8_t mac[ETH_ADDR_LEN])
return 0;
}
+static int
+netdev_dummy_set_mtu(const struct netdev *netdev, int mtu)
+{
+ struct netdev_dev_dummy *dev =
+ netdev_dev_dummy_cast(netdev_get_dev(netdev));
+
+ dev->mtu = mtu;
+ return 0;
+}
+
static int
netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
{
return 0;
}
-static int
-netdev_dummy_poll_add(struct netdev *netdev,
- void (*cb)(struct netdev_notifier *), void *aux,
- struct netdev_notifier **notifierp)
+static unsigned int
+netdev_dummy_change_seq(const struct netdev *netdev)
{
- const char *name = netdev_get_name(netdev);
- struct netdev_dummy_notifier *notifier;
- struct list *list;
- struct shash_node *shash_node;
-
- shash_node = shash_find_data(&netdev_dummy_notifiers, name);
- if (!shash_node) {
- list = xmalloc(sizeof *list);
- list_init(list);
- shash_node = shash_add(&netdev_dummy_notifiers, name, list);
- } else {
- list = shash_node->data;
- }
-
- notifier = xmalloc(sizeof *notifier);
- netdev_notifier_init(¬ifier->notifier, netdev, cb, aux);
- list_push_back(list, ¬ifier->list_node);
- notifier->shash_node = shash_node;
-
- *notifierp = ¬ifier->notifier;
-
- return 0;
-}
-
-static void
-netdev_dummy_poll_remove(struct netdev_notifier *notifier_)
-{
- struct netdev_dummy_notifier *notifier =
- CONTAINER_OF(notifier_, struct netdev_dummy_notifier, notifier);
-
- struct list *list;
-
- list = list_remove(¬ifier->list_node);
- if (list_is_empty(list)) {
- shash_delete(&netdev_dummy_notifiers, notifier->shash_node);
- free(list);
- }
-
- free(notifier);
+ return netdev_dev_dummy_cast(netdev_get_dev(netdev))->change_seq;
}
\f
/* Helper functions. */
static void
netdev_dummy_poll_notify(const struct netdev *netdev)
{
- const char *name = netdev_get_name(netdev);
- struct list *list = shash_find_data(&netdev_dummy_notifiers, name);
-
- if (list) {
- struct netdev_dummy_notifier *notifier;
+ struct netdev_dev_dummy *dev =
+ netdev_dev_dummy_cast(netdev_get_dev(netdev));
- LIST_FOR_EACH (notifier, list_node, list) {
- struct netdev_notifier *n = ¬ifier->notifier;
- n->cb(n);
- }
+ dev->change_seq++;
+ if (!dev->change_seq) {
+ dev->change_seq++;
}
}
netdev_dummy_create,
netdev_dummy_destroy,
- NULL,
+ NULL, /* get_config */
+ NULL, /* set_config */
netdev_dummy_open,
netdev_dummy_close,
- NULL, /* enumerate */
-
- NULL, /* recv */
+ netdev_dummy_listen, /* listen */
+ netdev_dummy_recv, /* recv */
NULL, /* recv_wait */
NULL, /* drain */
netdev_dummy_set_etheraddr,
netdev_dummy_get_etheraddr,
netdev_dummy_get_mtu,
+ netdev_dummy_set_mtu,
NULL, /* get_ifindex */
NULL, /* get_carrier */
+ NULL, /* get_carrier_resets */
+ NULL, /* get_miimon */
netdev_dummy_get_stats,
netdev_dummy_set_stats,
NULL, /* get_features */
NULL, /* set_advertisements */
- NULL, /* get_vlan_vid */
NULL, /* set_policing */
NULL, /* get_qos_types */
NULL, /* get_in6 */
NULL, /* add_router */
NULL, /* get_next_hop */
- NULL, /* get_tnl_iface */
+ NULL, /* get_status */
NULL, /* arp_lookup */
netdev_dummy_update_flags,
- netdev_dummy_poll_add,
- netdev_dummy_poll_remove,
+ netdev_dummy_change_seq
};
void