static struct netdev_dev_pltap *
netdev_dev_pltap_cast(const struct netdev_dev *netdev_dev)
{
- assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
+ ovs_assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
return CONTAINER_OF(netdev_dev, struct netdev_dev_pltap, netdev_dev);
}
netdev_pltap_cast(const struct netdev *netdev)
{
struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
- assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
+ ovs_assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
return CONTAINER_OF(netdev, struct netdev_pltap, netdev);
}
}
static int vsys_transaction(const char *script,
- const char *msg, char *reply, size_t reply_size)
+ const char **preply, char *format, ...)
{
+ char *msg = NULL, *reply = NULL;
+ const size_t reply_size = 1024;
int ifd = -1, ofd = -1, maxfd;
size_t bytes_to_write, bytes_to_read,
bytes_written = 0, bytes_read = 0;
int error = 0;
char *ofname = NULL, *ifname = NULL;
+ va_list args;
+
+ va_start(args, format);
+ msg = xvasprintf(format, args);
+ va_end(args);
+ reply = (char*)xmalloc(reply_size);
+ if (!msg || !reply) {
+ VLOG_ERR("Out of memory");
+ error = ENOMEM;
+ goto cleanup;
+ }
ofname = xasprintf("/vsys/%s.out", script);
ifname = xasprintf("/vsys/%s.in", script);
}
if (bytes_read) {
reply[bytes_read] = '\0';
- VLOG_ERR("%s returned: %s", script, reply);
+ if (preply) {
+ *preply = reply;
+ reply = NULL; /* prevent freeing the reply msg */
+ } else {
+ VLOG_ERR("%s returned: %s", script, reply);
+ }
error = EAGAIN;
goto cleanup;
}
cleanup:
+ free(msg);
+ free(reply);
free(ofname);
free(ifname);
close(ifd);
static int
netdev_pltap_up(struct netdev_dev_pltap *dev)
{
- int error;
- char *msg = NULL, *reply = NULL;
- const size_t reply_size = 1024;
-
if (!netdev_pltap_finalized(dev)) {
return 0;
}
- msg = xasprintf("%s\n"IP_FMT"\n%d\n",
- dev->real_name,
- IP_ARGS(&dev->local_addr.sin_addr),
- dev->local_netmask);
- reply = (char*)xmalloc(reply_size);
- if (!msg || !reply) {
- VLOG_ERR("Out of memory\n");
- error = ENOMEM;
- goto cleanup;
- }
- error = vsys_transaction("vif_up", msg, reply, reply_size);
- if (error) {
- goto cleanup;
- }
- netdev_pltap_update_seq(dev);
-
-cleanup:
- free(msg);
- free(reply);
-
- return error;
+ return vsys_transaction("vif_up", NULL, "%s\n"IP_FMT"\n%d\n",
+ dev->real_name,
+ IP_ARGS(dev->local_addr.sin_addr.s_addr),
+ dev->local_netmask);
}
static int
netdev_pltap_down(struct netdev_dev_pltap *dev)
{
- int error;
- char *msg = NULL, *reply = NULL;
- const size_t reply_size = 1024;
-
if (!netdev_pltap_finalized(dev)) {
return 0;
}
- msg = xasprintf("%s\n", dev->real_name);
- reply = (char*)xmalloc(reply_size);
- if (!msg || !reply) {
- VLOG_ERR("Out of memory\n");
- error = ENOMEM;
- goto cleanup;
- }
- error = vsys_transaction("vif_down", msg, reply, reply_size);
- if (error) {
- goto cleanup;
- }
- netdev_pltap_update_seq(dev);
+ return vsys_transaction("vif_down", NULL, "%s\n", dev->real_name);
+}
-cleanup:
- free(msg);
- free(reply);
+static int
+netdev_pltap_promisc(struct netdev_dev_pltap *dev, bool promisc)
+{
+ if (!netdev_pltap_finalized(dev)) {
+ return 0;
+ }
- return error;
+ return vsys_transaction("promisc", NULL, "%s\n%s",
+ dev->real_name,
+ (promisc ? "" : "-\n"));
}
static void
netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
{
- int error = 0;
- char *msg = NULL, *reply = NULL;
- const size_t reply_size = 1024;
- if (dev->fd < 0 || !netdev_pltap_finalized(dev))
+ if (dev->fd < 0 || !netdev_pltap_finalized(dev)) {
+ sync_done(dev);
return;
+ }
VLOG_DBG("sync_flags(%s): current: %s %s target: %s %s",
dev->real_name,
}
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:
-
+ netdev_pltap_update_seq(dev);
sync_done(dev);
- free(msg);
- free(reply);
-
- return error;
}
if (netdev_dev->valid_local_ip)
smap_add_format(args, "local_ip", IP_FMT,
- IP_ARGS(&netdev_dev->local_addr.sin_addr));
+ IP_ARGS(netdev_dev->local_addr.sin_addr.s_addr));
if (netdev_dev->valid_local_netmask)
smap_add_format(args, "local_netmask", "%"PRIu32,
ntohs(netdev_dev->local_netmask));
return EINVAL;
}
- error = get_flags(dev, &dev->flags);
+ if (netdev_pltap_finalized(dev)) {
+ error = get_flags(dev, &dev->flags);
+ }
*old_flagsp = dev->flags;
dev->new_flags |= on;
dev->new_flags &= ~off;
netdev_pltap_destroy,
netdev_pltap_get_config,
netdev_pltap_set_config,
+ NULL, /* get_tunnel_config */
netdev_pltap_open,
netdev_pltap_close,