VLOG_DEFINE_THIS_MODULE(netdev_pltap);
-struct netdev_dev_pltap {
- struct netdev_dev up;
+struct netdev_pltap {
+ struct netdev up;
char *real_name;
struct netdev_stats stats;
enum netdev_flags new_flags;
static struct list sync_list;
-struct netdev_pltap {
- struct netdev up;
-};
-
struct netdev_rx_pltap {
struct netdev_rx up;
int fd;
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
-static struct shash pltap_netdev_devs = SHASH_INITIALIZER(&pltap_netdev_devs);
+static struct shash pltap_netdevs = SHASH_INITIALIZER(&pltap_netdevs);
static int netdev_pltap_create(const struct netdev_class *, const char *,
- struct netdev_dev **);
+ struct netdev **);
-static void netdev_pltap_update_seq(struct netdev_dev_pltap *);
-static int get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags);
+static void netdev_pltap_update_seq(struct netdev_pltap *);
+static int get_flags(struct netdev_pltap *dev, enum netdev_flags *flags);
static bool
-netdev_pltap_finalized(struct netdev_dev_pltap *dev)
+netdev_pltap_finalized(struct netdev_pltap *dev)
{
return dev->valid_local_ip && dev->valid_local_netmask;
}
return class->create == netdev_pltap_create;
}
-static struct netdev_dev_pltap *
-netdev_dev_pltap_cast(const struct netdev_dev *netdev_dev)
-{
- ovs_assert(is_netdev_pltap_class(netdev_dev_get_class(netdev_dev)));
- return CONTAINER_OF(netdev_dev, struct netdev_dev_pltap, up);
-}
-
static struct netdev_pltap *
netdev_pltap_cast(const struct netdev *netdev)
{
- struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
- ovs_assert(is_netdev_pltap_class(netdev_dev_get_class(netdev_dev)));
+ ovs_assert(is_netdev_pltap_class(netdev_get_class(netdev)));
return CONTAINER_OF(netdev, struct netdev_pltap, up);
}
return CONTAINER_OF(rx, struct netdev_rx_pltap, up);
}
-static void sync_needed(struct netdev_dev_pltap *dev)
+static void sync_needed(struct netdev_pltap *dev)
{
if (dev->sync_flags_needed)
return;
}
-static void sync_done(struct netdev_dev_pltap *dev)
+static void sync_done(struct netdev_pltap *dev)
{
if (!dev->sync_flags_needed)
return;
static int
netdev_pltap_create(const struct netdev_class *class OVS_UNUSED, const char *name,
- struct netdev_dev **netdev_devp)
+ struct netdev **netdevp)
{
- struct netdev_dev_pltap *netdev_dev;
+ struct netdev_pltap *netdev;
int error;
- netdev_dev = xzalloc(sizeof *netdev_dev);
+ netdev = xzalloc(sizeof *netdev);
- netdev_dev->real_name = xzalloc(IFNAMSIZ + 1);
- memset(&netdev_dev->local_addr, 0, sizeof(netdev_dev->local_addr));
- netdev_dev->valid_local_ip = false;
- netdev_dev->valid_local_netmask = false;
- netdev_dev->flags = 0;
- netdev_dev->sync_flags_needed = false;
- list_init(&netdev_dev->sync_list);
+ netdev->real_name = xzalloc(IFNAMSIZ + 1);
+ memset(&netdev->local_addr, 0, sizeof(netdev->local_addr));
+ netdev->valid_local_ip = false;
+ netdev->valid_local_netmask = false;
+ netdev->flags = 0;
+ netdev->sync_flags_needed = false;
+ list_init(&netdev->sync_list);
/* Open tap device. */
- netdev_dev->fd = tun_alloc(IFF_TAP, netdev_dev->real_name);
- if (netdev_dev->fd < 0) {
+ netdev->fd = tun_alloc(IFF_TAP, netdev->real_name);
+ if (netdev->fd < 0) {
error = errno;
- VLOG_WARN("tun_alloc(IFF_TAP, %s) failed: %s", name, strerror(error));
+ VLOG_WARN("tun_alloc(IFF_TAP, %s) failed: %s", name, ovs_strerror(error));
goto cleanup;
}
- VLOG_DBG("real_name = %s", netdev_dev->real_name);
+ VLOG_DBG("real_name = %s", netdev->real_name);
/* Make non-blocking. */
- error = set_nonblocking(netdev_dev->fd);
+ error = set_nonblocking(netdev->fd);
if (error) {
goto cleanup;
}
- netdev_dev_init(&netdev_dev->up, name, &netdev_pltap_class);
- shash_add(&pltap_netdev_devs, name, netdev_dev);
- *netdev_devp = &netdev_dev->up;
+ netdev_init(&netdev->up, name, &netdev_pltap_class);
+ shash_add(&pltap_netdevs, name, netdev);
+ *netdevp = &netdev->up;
return 0;
cleanup:
- free(netdev_dev);
+ free(netdev);
return error;
}
static void
-netdev_pltap_destroy(struct netdev_dev *netdev_dev_)
+netdev_pltap_destroy(struct netdev *netdev_)
{
- struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(netdev_dev_);
-
- if (netdev_dev->fd != -1)
- close(netdev_dev->fd);
-
- sync_done(netdev_dev);
-
- shash_find_and_delete(&pltap_netdev_devs,
- netdev_dev_get_name(netdev_dev_));
- free(netdev_dev);
-}
-
-static int
-netdev_pltap_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
-{
- struct netdev_pltap *netdev;
+ struct netdev_pltap *netdev = netdev_pltap_cast(netdev_);
- netdev = xmalloc(sizeof *netdev);
- netdev_init(&netdev->up, netdev_dev_);
+ if (netdev->fd != -1)
+ close(netdev->fd);
- *netdevp = &netdev->up;
- return 0;
-}
+ sync_done(netdev);
-static void
-netdev_pltap_close(struct netdev *netdev_)
-{
- struct netdev_pltap *netdev = netdev_pltap_cast(netdev_);
+ shash_find_and_delete(&pltap_netdevs,
+ netdev_get_name(netdev_));
free(netdev);
}
-
-static int netdev_pltap_up(struct netdev_dev_pltap *dev);
+static int netdev_pltap_up(struct netdev_pltap *dev);
static int
netdev_pltap_rx_open(struct netdev *netdev_, struct netdev_rx **rxp)
{
- struct netdev_dev_pltap *netdev_dev =
- netdev_dev_pltap_cast(netdev_get_dev(netdev_));
+ struct netdev_pltap *netdev =
+ netdev_pltap_cast(netdev_);
struct netdev_rx_pltap *rx;
int err;
rx = xmalloc(sizeof *rx);
- netdev_rx_init(&rx->up, netdev_get_dev(netdev_), &netdev_rx_pltap_class);
- rx->fd = netdev_dev->fd;
+ netdev_rx_init(&rx->up, netdev_, &netdev_rx_pltap_class);
+ rx->fd = netdev->fd;
*rxp = &rx->up;
- if (!netdev_pltap_finalized(netdev_dev))
+ if (!netdev_pltap_finalized(netdev))
return 0;
- err = netdev_pltap_up(netdev_dev);
+ err = netdev_pltap_up(netdev);
if (err) {
free(rx);
*rxp = NULL;
ofd = open(ofname, O_RDONLY | O_NONBLOCK);
if (ofd < 0) {
- VLOG_ERR("Cannot open %s: %s", ofname, strerror(errno));
+ VLOG_ERR("Cannot open %s: %s", ofname, ovs_strerror(errno));
error = errno;
goto cleanup;
}
ifd = open(ifname, O_WRONLY | O_NONBLOCK);
if (ifd < 0) {
- VLOG_ERR("Cannot open %s: %s", ifname, strerror(errno));
+ VLOG_ERR("Cannot open %s: %s", ifname, ovs_strerror(errno));
error = errno;
goto cleanup;
}
if (select(maxfd + 1, &readset, &writeset, &errorset, NULL) < 0) {
if (errno == EINTR)
continue;
- VLOG_ERR("selec error: %s", strerror(errno));
+ VLOG_ERR("selec error: %s", ovs_strerror(errno));
error = errno;
goto cleanup;
}
ssize_t n = write(ifd, msg + bytes_written, bytes_to_write);
if (n < 0) {
if (errno != EAGAIN && errno != EINTR) {
- VLOG_ERR("write on %s: %s", ifname, strerror(errno));
+ VLOG_ERR("write on %s: %s", ifname, ovs_strerror(errno));
error = errno;
goto cleanup;
}
ssize_t n = read(ofd, reply + bytes_read, bytes_to_read);
if (n < 0) {
if (errno != EAGAIN && errno != EINTR) {
- VLOG_ERR("read on %s: %s", ofname, strerror(errno));
+ VLOG_ERR("read on %s: %s", ofname, ovs_strerror(errno));
error = errno;
goto cleanup;
}
}
static int
-netdev_pltap_up(struct netdev_dev_pltap *dev)
+netdev_pltap_up(struct netdev_pltap *dev)
{
if (!netdev_pltap_finalized(dev)) {
return 0;
}
static int
-netdev_pltap_down(struct netdev_dev_pltap *dev)
+netdev_pltap_down(struct netdev_pltap *dev)
{
if (!netdev_pltap_finalized(dev)) {
return 0;
}
static int
-netdev_pltap_promisc(struct netdev_dev_pltap *dev, bool promisc)
+netdev_pltap_promisc(struct netdev_pltap *dev, bool promisc)
{
if (!netdev_pltap_finalized(dev)) {
return 0;
}
static void
-netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
+netdev_pltap_sync_flags(struct netdev_pltap *dev)
{
if (dev->fd < 0 || !netdev_pltap_finalized(dev)) {
static int
-netdev_pltap_get_config(struct netdev_dev *dev_, struct smap *args)
+netdev_pltap_get_config(const struct netdev *dev_, struct smap *args)
{
- struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
+ struct netdev_pltap *netdev = netdev_pltap_cast(dev_);
- if (netdev_dev->valid_local_ip)
+ if (netdev->valid_local_ip)
smap_add_format(args, "local_ip", IP_FMT,
- IP_ARGS(netdev_dev->local_addr.sin_addr.s_addr));
- if (netdev_dev->valid_local_netmask)
+ IP_ARGS(netdev->local_addr.sin_addr.s_addr));
+ if (netdev->valid_local_netmask)
smap_add_format(args, "local_netmask", "%"PRIu32,
- ntohs(netdev_dev->local_netmask));
+ ntohs(netdev->local_netmask));
return 0;
}
static int
-netdev_pltap_set_config(struct netdev_dev *dev_, const struct smap *args)
+netdev_pltap_set_config(struct netdev *dev_, const struct smap *args)
{
- struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
+ struct netdev_pltap *netdev = netdev_pltap_cast(dev_);
struct shash_node *node;
- VLOG_DBG("pltap_set_config(%s)", netdev_dev_get_name(dev_));
+ VLOG_DBG("pltap_set_config(%s)", netdev_get_name(dev_));
SMAP_FOR_EACH(node, args) {
VLOG_DBG("arg: %s->%s", node->name, (char*)node->data);
if (!strcmp(node->name, "local_ip")) {
if (lookup_ip(node->data, &addr)) {
VLOG_WARN("%s: bad 'local_ip'", node->name);
} else {
- netdev_dev->local_addr.sin_addr = addr;
- netdev_dev->valid_local_ip = true;
+ netdev->local_addr.sin_addr = addr;
+ netdev->valid_local_ip = true;
}
} else if (!strcmp(node->name, "local_netmask")) {
- netdev_dev->local_netmask = atoi(node->data);
+ netdev->local_netmask = atoi(node->data);
// XXX check valididy
- netdev_dev->valid_local_netmask = true;
+ netdev->valid_local_netmask = true;
} else {
VLOG_WARN("%s: unknown argument '%s'",
- netdev_dev_get_name(dev_), node->name);
+ netdev_get_name(dev_), node->name);
}
}
- if (netdev_pltap_finalized(netdev_dev)) {
- netdev_dev->new_flags |= NETDEV_UP;
- sync_needed(netdev_dev);
+ if (netdev_pltap_finalized(netdev)) {
+ netdev->new_flags |= NETDEV_UP;
+ sync_needed(netdev);
}
return 0;
}
netdev_rx_pltap_recv(struct netdev_rx *rx_, void *buffer, size_t size)
{
struct netdev_rx_pltap *rx = netdev_rx_pltap_cast(rx_);
- char prefix[4];
+ struct tun_pi pi;
struct iovec iov[2] = {
- { .iov_base = prefix, .iov_len = 4 },
+ { .iov_base = &pi, .iov_len = sizeof(pi) },
{ .iov_base = buffer, .iov_len = size }
};
for (;;) {
} else if (errno != EINTR) {
if (errno != EAGAIN) {
VLOG_WARN_RL(&rl, "error receiveing Ethernet packet on %s: %s",
- netdev_rx_get_name(rx_), strerror(errno));
+ netdev_rx_get_name(rx_), ovs_strerror(errno));
}
return -errno;
}
netdev_rx_pltap_wait(struct netdev_rx *rx_)
{
struct netdev_rx_pltap *rx = netdev_rx_pltap_cast(rx_);
- struct netdev_dev_pltap *netdev_dev =
- netdev_dev_pltap_cast(rx->up.netdev_dev);
- if (rx->fd >= 0 && netdev_pltap_finalized(netdev_dev)) {
+ struct netdev_pltap *netdev =
+ netdev_pltap_cast(rx->up.netdev);
+ if (rx->fd >= 0 && netdev_pltap_finalized(netdev)) {
poll_fd_wait(rx->fd, POLLIN);
}
}
static int
netdev_pltap_send(struct netdev *netdev_, const void *buffer, size_t size)
{
- struct netdev_dev_pltap *dev =
- netdev_dev_pltap_cast(netdev_get_dev(netdev_));
- char prefix[4] = { 0, 0, 8, 6 };
+ struct netdev_pltap *dev =
+ netdev_pltap_cast(netdev_);
+ struct tun_pi pi = { 0, 0x86 };
struct iovec iov[2] = {
- { .iov_base = prefix, .iov_len = 4 },
+ { .iov_base = &pi, .iov_len = sizeof(pi) },
{ .iov_base = (char*) buffer, .iov_len = size }
};
if (dev->fd < 0)
} else if (errno != EINTR) {
if (errno != EAGAIN) {
VLOG_WARN_RL(&rl, "error sending Ethernet packet on %s: %s",
- netdev_get_name(netdev_), strerror(errno));
+ netdev_get_name(netdev_), ovs_strerror(errno));
}
return errno;
}
static void
netdev_pltap_send_wait(struct netdev *netdev_)
{
- struct netdev_dev_pltap *dev =
- netdev_dev_pltap_cast(netdev_get_dev(netdev_));
+ struct netdev_pltap *dev =
+ netdev_pltap_cast(netdev_);
if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
poll_fd_wait(dev->fd, POLLOUT);
}
// XXX from netdev-linux.c
static int
-get_etheraddr(struct netdev_dev_pltap *dev, uint8_t ea[ETH_ADDR_LEN])
+get_etheraddr(struct netdev_pltap *dev, uint8_t ea[ETH_ADDR_LEN])
{
struct ifreq ifr;
int hwaddr_family;
* to INFO for that case. */
VLOG(errno == ENODEV ? VLL_INFO : VLL_ERR,
"ioctl(SIOCGIFHWADDR) on %s device failed: %s",
- dev->real_name, strerror(errno));
+ dev->real_name, ovs_strerror(errno));
return errno;
}
hwaddr_family = ifr.ifr_hwaddr.sa_family;
}
static int
-get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags)
+get_flags(struct netdev_pltap *dev, enum netdev_flags *flags)
{
struct ifreq ifr;
netdev_pltap_get_etheraddr(const struct netdev *netdev,
uint8_t mac[ETH_ADDR_LEN])
{
- struct netdev_dev_pltap *dev =
- netdev_dev_pltap_cast(netdev_get_dev(netdev));
+ struct netdev_pltap *dev =
+ netdev_pltap_cast(netdev);
if (dev->fd < 0)
return EAGAIN;
return get_etheraddr(dev, mac);
static int
-netdev_pltap_update_flags(struct netdev_dev *dev_,
+netdev_pltap_update_flags(struct netdev *dev_,
enum netdev_flags off, enum netdev_flags on,
enum netdev_flags *old_flagsp)
{
- struct netdev_dev_pltap *netdev_dev =
- netdev_dev_pltap_cast(dev_);
+ struct netdev_pltap *netdev =
+ netdev_pltap_cast(dev_);
int error = 0;
if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
return EINVAL;
}
- if (netdev_pltap_finalized(netdev_dev)) {
- error = get_flags(netdev_dev, &netdev_dev->flags);
+ if (netdev_pltap_finalized(netdev)) {
+ error = get_flags(netdev, &netdev->flags);
}
- *old_flagsp = netdev_dev->flags;
- netdev_dev->new_flags |= on;
- netdev_dev->new_flags &= ~off;
- if (netdev_dev->flags != netdev_dev->new_flags) {
+ *old_flagsp = netdev->flags;
+ netdev->new_flags |= on;
+ netdev->new_flags &= ~off;
+ if (netdev->flags != netdev->new_flags) {
/* we cannot sync here, since we may be in a signal handler */
- sync_needed(netdev_dev);
+ sync_needed(netdev);
}
return error;
static unsigned int
netdev_pltap_change_seq(const struct netdev *netdev)
{
- return netdev_dev_pltap_cast(netdev_get_dev(netdev))->change_seq;
+ return netdev_pltap_cast(netdev)->change_seq;
}
\f
/* Helper functions. */
static void
-netdev_pltap_update_seq(struct netdev_dev_pltap *dev)
+netdev_pltap_update_seq(struct netdev_pltap *dev)
{
dev->change_seq++;
if (!dev->change_seq) {
netdev_pltap_get_real_name(struct unixctl_conn *conn,
int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
{
- struct netdev_dev_pltap *pltap_dev;
+ struct netdev_pltap *pltap_dev;
- pltap_dev = shash_find_data(&pltap_netdev_devs, argv[1]);
+ pltap_dev = shash_find_data(&pltap_netdevs, argv[1]);
if (!pltap_dev) {
unixctl_command_reply_error(conn, "no such pltap netdev");
return;
list_init(&sync_list);
af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (af_inet_sock < 0) {
- VLOG_ERR("failed to create inet socket: %s", strerror(errno));
+ VLOG_ERR("failed to create inet socket: %s", ovs_strerror(errno));
}
unixctl_command_register("netdev-pltap/get-tapname", "port",
1, 1, netdev_pltap_get_real_name, NULL);
static void
netdev_pltap_run(void)
{
- struct netdev_dev_pltap *iter, *next;
+ struct netdev_pltap *iter, *next;
LIST_FOR_EACH_SAFE(iter, next, sync_list, &sync_list) {
netdev_pltap_sync_flags(iter);
}
netdev_pltap_set_config,
NULL, /* get_tunnel_config */
- netdev_pltap_open,
- netdev_pltap_close,
-
netdev_pltap_rx_open,
netdev_pltap_send,