self-contained tap creation in the switchd
[sliver-openvswitch.git] / lib / netdev-linux.c
index 08937de..412a92d 100644 (file)
@@ -69,7 +69,6 @@
 #include "sset.h"
 #include "timer.h"
 #include "vlog.h"
-#include "tunalloc.h"
 
 VLOG_DEFINE_THIS_MODULE(netdev_linux);
 
@@ -733,7 +732,7 @@ netdev_linux_destroy(struct netdev_dev *netdev_dev_)
         netdev_dev->tc->ops->tc_destroy(netdev_dev->tc);
     }
 
-    if (class == &netdev_tap_class || class == &netdev_tap_pl_class) {
+    if (class == &netdev_tap_class) {
         destroy_tap(netdev_dev);
     }
     free(netdev_dev);
@@ -769,7 +768,7 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
         }
     }
 
-    if (!strncmp(netdev_dev_get_type(netdev_dev_), "tap", 3) &&
+    if (!strcmp(netdev_dev_get_type(netdev_dev_), "tap") &&
         !netdev_dev->state.tap.opened) {
 
         /* We assume that the first user of the tap device is the primary user
@@ -794,7 +793,7 @@ netdev_linux_close(struct netdev *netdev_)
 {
     struct netdev_linux *netdev = netdev_linux_cast(netdev_);
 
-    if (netdev->fd > 0 && strncmp(netdev_get_type(netdev_), "tap", 3)) {
+    if (netdev->fd > 0 && strcmp(netdev_get_type(netdev_), "tap")) {
         close(netdev->fd);
     }
     free(netdev);
@@ -868,8 +867,7 @@ netdev_linux_recv(struct netdev *netdev_, void *data, size_t size)
     for (;;) {
         ssize_t retval;
 
-        retval = ((netdev_->netdev_dev->netdev_class == &netdev_tap_class ||
-                   netdev_->netdev_dev->netdev_class == &netdev_tap_pl_class)
+        retval = (netdev_->netdev_dev->netdev_class == &netdev_tap_class
                   ? read(netdev->fd, data, size)
                   : recv(netdev->fd, data, size, MSG_TRUNC));
         if (retval >= 0) {
@@ -902,7 +900,7 @@ netdev_linux_drain(struct netdev *netdev_)
     struct netdev_linux *netdev = netdev_linux_cast(netdev_);
     if (netdev->fd < 0) {
         return 0;
-    } else if (!strncmp(netdev_get_type(netdev_), "tap", 3)) {
+    } else if (!strcmp(netdev_get_type(netdev_), "tap")) {
         struct ifreq ifr;
         int error = netdev_linux_do_ioctl(netdev_get_name(netdev_), &ifr,
                                           SIOCGIFTXQLEN, "SIOCGIFTXQLEN");
@@ -1013,7 +1011,7 @@ netdev_linux_send_wait(struct netdev *netdev_)
     struct netdev_linux *netdev = netdev_linux_cast(netdev_);
     if (netdev->fd < 0) {
         /* Nothing to do. */
-    } else if (strncmp(netdev_get_type(netdev_), "tap", 3)) {
+    } else if (strcmp(netdev_get_type(netdev_), "tap")) {
         poll_fd_wait(netdev->fd, POLLOUT);
     } else {
         /* TAP device always accepts packets.*/
@@ -1788,51 +1786,6 @@ netdev_linux_get_qos_types(const struct netdev *netdev OVS_UNUSED,
     return 0;
 }
 
-static int
-netdev_linux_create_tap_pl(const struct netdev_class *class OVS_UNUSED,
-                        const char *name, struct netdev_dev **netdev_devp)
-{
-    struct netdev_dev_linux *netdev_dev;
-    struct tap_state *state;
-    char real_name[IFNAMSIZ];
-    int error;
-
-    netdev_dev = xzalloc(sizeof *netdev_dev);
-    state = &netdev_dev->state.tap;
-
-    error = cache_notifier_ref();
-    if (error) {
-        goto error;
-    }
-
-    /* Open tap device. */
-    state->fd = tun_alloc(IFF_TAP, real_name);
-    if (state->fd < 0) {
-        error = errno;
-        VLOG_WARN("tun_alloc(IFF_TAP, %s) failed: %s", name, strerror(error));
-        goto error_unref_notifier;
-    }
-    if (strcmp(name, real_name)) {
-        VLOG_WARN("tap_pl: requested %s, created %s", name, real_name);
-    }
-
-    /* Make non-blocking. */
-    error = set_nonblocking(state->fd);
-    if (error) {
-        goto error_unref_notifier;
-    }
-
-    netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_tap_pl_class);
-    *netdev_devp = &netdev_dev->netdev_dev;
-    return 0;
-
-error_unref_notifier:
-    cache_notifier_unref();
-error:
-    free(netdev_dev);
-    return error;
-}
-
 static const struct tc_ops *
 tc_lookup_ovs_name(const char *name)
 {
@@ -2424,13 +2377,6 @@ netdev_linux_update_flags(struct netdev *netdev, enum netdev_flags off,
     return error;
 }
 
-static int
-netdev_tap_pl_update_flags(struct netdev *netdev OVS_UNUSED, enum netdev_flags off OVS_UNUSED,
-                          enum netdev_flags on OVS_UNUSED, enum netdev_flags *old_flagsp OVS_UNUSED)
-{
-    return 0;
-}
-
 static unsigned int
 netdev_linux_change_seq(const struct netdev *netdev)
 {
@@ -2438,8 +2384,7 @@ netdev_linux_change_seq(const struct netdev *netdev)
 }
 
 #define NETDEV_LINUX_CLASS(NAME, CREATE, GET_STATS, SET_STATS,  \
-                           GET_FEATURES, GET_STATUS,            \
-                           UPDATE_FLAGS)                        \
+                           GET_FEATURES, GET_STATUS)            \
 {                                                               \
     NAME,                                                       \
                                                                 \
@@ -2497,7 +2442,7 @@ netdev_linux_change_seq(const struct netdev *netdev)
     GET_STATUS,                                                 \
     netdev_linux_arp_lookup,                                    \
                                                                 \
-    UPDATE_FLAGS,                                               \
+    netdev_linux_update_flags,                                  \
                                                                 \
     netdev_linux_change_seq                                     \
 }
@@ -2509,8 +2454,7 @@ const struct netdev_class netdev_linux_class =
         netdev_linux_get_stats,
         NULL,                    /* set_stats */
         netdev_linux_get_features,
-        netdev_linux_get_drv_info,
-        netdev_linux_update_flags);
+        netdev_linux_get_drv_info);
 
 const struct netdev_class netdev_tap_class =
     NETDEV_LINUX_CLASS(
@@ -2519,8 +2463,7 @@ const struct netdev_class netdev_tap_class =
         netdev_tap_get_stats,
         NULL,                   /* set_stats */
         netdev_linux_get_features,
-        netdev_linux_get_drv_info,
-        netdev_linux_update_flags);
+        netdev_linux_get_drv_info);
 
 const struct netdev_class netdev_internal_class =
     NETDEV_LINUX_CLASS(
@@ -2529,18 +2472,7 @@ const struct netdev_class netdev_internal_class =
         netdev_internal_get_stats,
         netdev_vport_set_stats,
         NULL,                  /* get_features */
-        netdev_internal_get_drv_info,
-        netdev_linux_update_flags);
-
-const struct netdev_class netdev_tap_pl_class =
-    NETDEV_LINUX_CLASS(
-        "tap_pl",
-        netdev_linux_create_tap_pl,
-        netdev_tap_get_stats,
-        NULL,                   /* set_stats */
-        netdev_linux_get_features,
-        netdev_linux_get_drv_info,
-       netdev_tap_pl_update_flags);    
+        netdev_internal_get_drv_info);
 \f
 /* HTB traffic control class. */