From: Giuseppe Lettieri Date: Thu, 20 Dec 2012 15:00:03 +0000 (+0100) Subject: move promisc to its own function X-Git-Tag: sliver-openvswitch-1.9.90-2~3 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=8e833b5a5322bf4daf7d9dd7fc0fc32ee8bf69e2 move promisc to its own function --- diff --git a/lib/netdev-pltap.c b/lib/netdev-pltap.c index 915897740..42b38a2cf 100644 --- a/lib/netdev-pltap.c +++ b/lib/netdev-pltap.c @@ -369,13 +369,42 @@ cleanup: return error; } -static void -netdev_pltap_sync_flags(struct netdev_dev_pltap *dev) +static int +netdev_pltap_promisc(struct netdev_dev_pltap *dev, bool promisc) { int error = 0; char *msg = NULL, *reply = NULL; const size_t reply_size = 1024; + if (!netdev_pltap_finalized(dev)) { + return 0; + } + + msg = xasprintf("%s\n%s", + dev->real_name, + (promisc ? "" : "-\n")); + reply = (char*)xmalloc(reply_size); + if (!msg || !reply) { + VLOG_ERR("Out of memory\n"); + goto cleanup; + } + error = vsys_transaction("promisc", msg, reply, reply_size); + if (error) { + goto cleanup; + } + netdev_pltap_update_seq(dev); + +cleanup: + free(msg); + free(reply); + + return error; +} + +static void +netdev_pltap_sync_flags(struct netdev_dev_pltap *dev) +{ + if (dev->fd < 0 || !netdev_pltap_finalized(dev)) return; @@ -393,28 +422,10 @@ netdev_pltap_sync_flags(struct netdev_dev_pltap *dev) } if ((dev->new_flags & NETDEV_PROMISC) ^ (dev->flags & NETDEV_PROMISC)) { - msg = xasprintf("%s\n%s", - dev->real_name, - (dev->new_flags & NETDEV_PROMISC ? "" : "-\n")); - reply = (char*)xmalloc(reply_size); - if (!msg || !reply) { - VLOG_ERR("Out of memory\n"); - goto cleanup; - } - error = vsys_transaction("promisc", msg, reply, reply_size); - if (error) { - goto cleanup; - } - netdev_pltap_update_seq(dev); + (void) netdev_pltap_promisc(dev, dev->new_flags & NETDEV_PROMISC); } -cleanup: - sync_done(dev); - free(msg); - free(reply); - - return error; }