datapath-windows: Make VPORT ovs number values smaller than MAXUINT16
[cascardo/ovs.git] / lib / netdev-vport.c
index c214bf7..83f1296 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
 
 VLOG_DEFINE_THIS_MODULE(netdev_vport);
 
+#define GENEVE_DST_PORT 6081
 #define VXLAN_DST_PORT 4789
 #define LISP_DST_PORT 4341
 
@@ -133,7 +134,8 @@ netdev_vport_needs_dst_port(const struct netdev *dev)
     const char *type = netdev_get_type(dev);
 
     return (class->get_config == get_tunnel_config &&
-            (!strcmp("vxlan", type) || !strcmp("lisp", type)));
+            (!strcmp("geneve", type) || !strcmp("vxlan", type) ||
+             !strcmp("lisp", type)));
 }
 
 const char *
@@ -146,25 +148,28 @@ const char *
 netdev_vport_get_dpif_port(const struct netdev *netdev,
                            char namebuf[], size_t bufsize)
 {
+    const struct netdev_class *class = netdev_get_class(netdev);
+    const char *dpif_port = netdev_vport_class_get_dpif_port(class);
+
+    if (!dpif_port) {
+        return netdev_get_name(netdev);
+    }
+
     if (netdev_vport_needs_dst_port(netdev)) {
         const struct netdev_vport *vport = netdev_vport_cast(netdev);
-        const char *type = netdev_get_type(netdev);
 
         /*
-         * Note: IFNAMSIZ is 16 bytes long. The maximum length of a VXLAN
-         * or LISP port name below is 15 or 14 bytes respectively. Still,
-         * assert here on the size of strlen(type) in case that changes
-         * in the future.
+         * Note: IFNAMSIZ is 16 bytes long. Implementations should choose
+         * a dpif port name that is short enough to fit including any
+         * port numbers but assert just in case.
          */
         BUILD_ASSERT(NETDEV_VPORT_NAME_BUFSIZE >= IFNAMSIZ);
-        ovs_assert(strlen(type) + 10 < IFNAMSIZ);
-        snprintf(namebuf, bufsize, "%s_sys_%d", type,
+        ovs_assert(strlen(dpif_port) + 6 < IFNAMSIZ);
+        snprintf(namebuf, bufsize, "%s_%d", dpif_port,
                  ntohs(vport->tnl_cfg.dst_port));
         return namebuf;
     } else {
-        const struct netdev_class *class = netdev_get_class(netdev);
-        const char *dpif_port = netdev_vport_class_get_dpif_port(class);
-        return dpif_port ? dpif_port : netdev_get_name(netdev);
+        return dpif_port;
     }
 }
 
@@ -198,8 +203,9 @@ netdev_vport_route_changed(void)
                 netdev_change_seq_changed(netdev_);
             }
         }
-        netdev_close(netdev_);
         ovs_mutex_unlock(&netdev->mutex);
+
+        netdev_close(netdev_);
     }
 
     free(vports);
@@ -492,12 +498,15 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args)
         }
     }
 
-    /* Add a default destination port for VXLAN if none specified. */
+    /* Add a default destination port for tunnel ports if none specified. */
+    if (!strcmp(type, "geneve") && !tnl_cfg.dst_port) {
+        tnl_cfg.dst_port = htons(GENEVE_DST_PORT);
+    }
+
     if (!strcmp(type, "vxlan") && !tnl_cfg.dst_port) {
         tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
     }
 
-    /* Add a default destination port for LISP if none specified. */
     if (!strcmp(type, "lisp") && !tnl_cfg.dst_port) {
         tnl_cfg.dst_port = htons(LISP_DST_PORT);
     }
@@ -625,7 +634,8 @@ get_tunnel_config(const struct netdev *dev, struct smap *args)
         uint16_t dst_port = ntohs(tnl_cfg.dst_port);
         const char *type = netdev_get_type(dev);
 
-        if ((!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) ||
+        if ((!strcmp("geneve", type) && dst_port != GENEVE_DST_PORT) ||
+            (!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) ||
             (!strcmp("lisp", type) && dst_port != LISP_DST_PORT)) {
             smap_add_format(args, "dst_port", "%d", dst_port);
         }
@@ -765,6 +775,8 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats)
     GET_CONFIG,                                             \
     SET_CONFIG,                                             \
     GET_TUNNEL_CONFIG,                                      \
+    NULL,                       /* get_numa_id */           \
+    NULL,                       /* set_multiq */            \
                                                             \
     NULL,                       /* send */                  \
     NULL,                       /* send_wait */             \
@@ -778,7 +790,6 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats)
     NULL,                       /* get_carrier_resets */    \
     NULL,                       /* get_miimon */            \
     get_stats,                                              \
-    NULL,                       /* set_stats */             \
                                                             \
     NULL,                       /* get_features */          \
     NULL,                       /* set_advertisements */    \
@@ -825,13 +836,16 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats)
 void
 netdev_vport_tunnel_register(void)
 {
+    /* The name of the dpif_port should be short enough to accomodate adding
+     * a port number to the end if one is necessary. */
     static const struct vport_class vport_classes[] = {
-        TUNNEL_CLASS("gre", "gre_system"),
-        TUNNEL_CLASS("ipsec_gre", "gre_system"),
-        TUNNEL_CLASS("gre64", "gre64_system"),
-        TUNNEL_CLASS("ipsec_gre64", "gre64_system"),
-        TUNNEL_CLASS("vxlan", "vxlan_system"),
-        TUNNEL_CLASS("lisp", "lisp_system")
+        TUNNEL_CLASS("geneve", "genev_sys"),
+        TUNNEL_CLASS("gre", "gre_sys"),
+        TUNNEL_CLASS("ipsec_gre", "gre_sys"),
+        TUNNEL_CLASS("gre64", "gre64_sys"),
+        TUNNEL_CLASS("ipsec_gre64", "gre64_sys"),
+        TUNNEL_CLASS("vxlan", "vxlan_sys"),
+        TUNNEL_CLASS("lisp", "lisp_sys")
     };
     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;