X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetdev-dummy.c;h=9cd06f194b357be4008b49321def99e2d1a0e71c;hb=e317253b1391c7b0a84c8dd51eaf1f3cc16eff56;hp=218a022883eceb2ec4f3774e6e7677a9cb487648;hpb=ea83a2fcd0d31246ece7bdea4c54e162f432e81c;p=sliver-openvswitch.git diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index 218a02288..9cd06f194 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -28,27 +28,19 @@ 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 **); static void netdev_dummy_poll_notify(const struct netdev *); @@ -76,14 +68,14 @@ netdev_dummy_cast(const struct netdev *netdev) static int netdev_dummy_create(const struct netdev_class *class, const char *name, - const struct shash *args OVS_UNUSED, + const struct shash *args, struct netdev_dev **netdev_devp) { static unsigned int n = 0xaa550000; struct netdev_dev_dummy *netdev_dev; netdev_dev = xzalloc(sizeof *netdev_dev); - netdev_dev_init(&netdev_dev->netdev_dev, name, class); + netdev_dev_init(&netdev_dev->netdev_dev, name, args, class); netdev_dev->hwaddr[0] = 0xaa; netdev_dev->hwaddr[1] = 0x55; netdev_dev->hwaddr[2] = n >> 24; @@ -92,6 +84,7 @@ netdev_dummy_create(const struct netdev_class *class, const char *name, netdev_dev->hwaddr[5] = n; netdev_dev->mtu = 1500; netdev_dev->flags = 0; + netdev_dev->change_seq = 1; n++; @@ -205,50 +198,10 @@ netdev_dummy_update_flags(struct netdev *netdev, return 0; } -static int -netdev_dummy_poll_add(struct netdev *netdev, - void (*cb)(struct netdev_notifier *), void *aux, - struct netdev_notifier **notifierp) -{ - 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_) +static unsigned int +netdev_dummy_change_seq(const struct netdev *netdev) { - 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; } /* Helper functions. */ @@ -256,16 +209,12 @@ netdev_dummy_poll_remove(struct netdev_notifier *notifier_) 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++; } } @@ -277,7 +226,8 @@ static const struct netdev_class dummy_class = { netdev_dummy_create, netdev_dummy_destroy, - NULL, + NULL, /* set_config */ + NULL, /* config_equal */ netdev_dummy_open, netdev_dummy_close, @@ -296,6 +246,7 @@ static const struct netdev_class dummy_class = { netdev_dummy_get_mtu, NULL, /* get_ifindex */ NULL, /* get_carrier */ + NULL, /* get_miimon */ netdev_dummy_get_stats, netdev_dummy_set_stats, @@ -320,13 +271,12 @@ static const struct netdev_class dummy_class = { 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