int fd;
};
-static int af_inet_sock = -1;
-
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
static struct shash pltap_netdevs = SHASH_INITIALIZER(&pltap_netdevs);
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->real_name);
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;
}
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;
}
{
struct netdev_pltap *dev =
netdev_pltap_cast(netdev_);
- char prefix[4] = { 0, 0, 8, 6 };
+ 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;
}
{
struct ifreq ifr;
int hwaddr_family;
+ int error;
memset(&ifr, 0, sizeof ifr);
ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
- if (ioctl(af_inet_sock, SIOCGIFHWADDR, &ifr) < 0) {
- /* ENODEV probably means that a vif disappeared asynchronously and
- * hasn't been removed from the database yet, so reduce the log level
- * to INFO for that case. */
- VLOG(errno == ENODEV ? VLL_INFO : VLL_ERR,
- "ioctl(SIOCGIFHWADDR) on %s device failed: %s",
- dev->real_name, strerror(errno));
+ error = af_inet_ifreq_ioctl(dev->real_name, &ifr,
+ SIOCGIFHWADDR, "SIOCGIFHWADDR");
+ if (error) {
return errno;
}
hwaddr_family = ifr.ifr_hwaddr.sa_family;
get_flags(struct netdev_pltap *dev, enum netdev_flags *flags)
{
struct ifreq ifr;
+ int error;
- memset(&ifr, 0, sizeof ifr);
- ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
- if (ioctl(af_inet_sock, SIOCGIFFLAGS, &ifr) < 0)
- return errno;
+ error = af_inet_ifreq_ioctl(dev->real_name, &ifr,
+ SIOCGIFFLAGS, "SIOCGIFFLAGS");
+ if (error) {
+ return error;
+ }
*flags = 0;
if (ifr.ifr_flags & IFF_UP)
*flags |= NETDEV_UP;
netdev_pltap_init(void)
{
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));
- }
unixctl_command_register("netdev-pltap/get-tapname", "port",
1, 1, netdev_pltap_get_real_name, NULL);
return 0;