netdev-linux: Return correct error codes on receive.
[sliver-openvswitch.git] / lib / netdev-linux.c
index 7fde7e0..c71bdd4 100644 (file)
@@ -239,9 +239,11 @@ netdev_linux_open(const char *name, char *suffix, int ethertype,
 
         /* Create tap device. */
         ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-        error = netdev_linux_do_ioctl(&netdev->netdev, &ifr,
-                                      TUNSETIFF, "TUNSETIFF");
-        if (error) {
+        strncpy(ifr.ifr_name, suffix, sizeof ifr.ifr_name);
+        if (ioctl(netdev->tap_fd, TUNSETIFF, &ifr) == -1) {
+            VLOG_WARN("%s: creating tap device failed: %s", suffix,
+                      strerror(errno));
+            error = errno;
             goto error;
         }
 
@@ -368,7 +370,7 @@ netdev_linux_recv(struct netdev *netdev_, void *data, size_t size)
 
     if (netdev->tap_fd < 0) {
         /* Device was opened with NETDEV_ETH_TYPE_NONE. */
-        return EAGAIN;
+        return -EAGAIN;
     }
 
     for (;;) {
@@ -380,7 +382,7 @@ netdev_linux_recv(struct netdev *netdev_, void *data, size_t size)
                 VLOG_WARN_RL(&rl, "error receiving Ethernet packet on %s: %s",
                              strerror(errno), netdev_get_name(netdev_));
             }
-            return errno;
+            return -errno;
         }
     }
 }
@@ -654,6 +656,8 @@ netdev_linux_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
                                                      "openvswitch");
             }
         }
+
+        netdev->cache->valid |= VALID_IS_INTERNAL;
     }
 
     if (netdev->cache->is_internal) {
@@ -1494,6 +1498,7 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats)
 
     if (!attrs[IFLA_STATS]) {
         VLOG_WARN_RL(&rl, "RTM_GETLINK reply lacks stats");
+        ofpbuf_delete(reply);
         return EPROTO;
     }
 
@@ -1520,6 +1525,8 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats)
     stats->tx_heartbeat_errors = rtnl_stats->tx_heartbeat_errors;
     stats->tx_window_errors = rtnl_stats->tx_window_errors;
 
+    ofpbuf_delete(reply);
+
     return 0;
 }