Don't differentiate between TCP and SSL ports for OpenFlow and OVSDB.
authorJustin Pettit <jpettit@nicira.com>
Mon, 23 Sep 2013 21:33:09 +0000 (14:33 -0700)
committerJustin Pettit <jpettit@nicira.com>
Tue, 1 Oct 2013 23:18:45 +0000 (16:18 -0700)
The OVS code has always made a distinction between the unencrypted (TCP)
and SSL port numbers for the OpenFlow and OVSDB protocols.  The default
port numbers for both protocols has changed, and there continues to be
no distinction between the unencrypted and SSL versions.  This
commit removes the distinction in port numbers.  A future patch will
recognize the change in default port number.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
include/openflow/openflow-common.h
lib/jsonrpc.c
lib/jsonrpc.h
lib/stream-ssl.c
lib/stream.c
lib/stream.h
lib/vconn-stream.c
lib/vconn.c
ofproto/connmgr.c
vswitchd/bridge.c

index 5018f85..5b0ccc5 100644 (file)
@@ -105,7 +105,6 @@ enum ofp_version {
 #define OFP_MAX_PORT_NAME_LEN  16
 
 #define OFP_TCP_PORT  6633
-#define OFP_SSL_PORT  6633
 
 #define OFP_ETH_ALEN 6          /* Bytes in an Ethernet address. */
 
index e02f035..b43b044 100644 (file)
@@ -59,22 +59,21 @@ static void jsonrpc_cleanup(struct jsonrpc *);
 static void jsonrpc_error(struct jsonrpc *, int error);
 
 /* This is just the same as stream_open() except that it uses the default
- * JSONRPC ports if none is specified. */
+ * JSONRPC port if none is specified. */
 int
 jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp)
 {
-    return stream_open_with_default_ports(name, JSONRPC_TCP_PORT,
-                                          JSONRPC_SSL_PORT, streamp,
-                                          dscp);
+    return stream_open_with_default_port(name, JSONRPC_TCP_PORT,
+                                         streamp, dscp);
 }
 
 /* This is just the same as pstream_open() except that it uses the default
- * JSONRPC ports if none is specified. */
+ * JSONRPC port if none is specified. */
 int
 jsonrpc_pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp)
 {
-    return pstream_open_with_default_ports(name, JSONRPC_TCP_PORT,
-                                           JSONRPC_SSL_PORT, pstreamp, dscp);
+    return pstream_open_with_default_port(name, JSONRPC_TCP_PORT,
+                                          pstreamp, dscp);
 }
 
 /* Returns a new JSON-RPC stream that uses 'stream' for input and output.  The
index 0ae205d..2c691cf 100644 (file)
@@ -32,12 +32,11 @@ struct stream;
 \f
 /* API for a JSON-RPC stream. */
 
-/* Default port numbers.
+/* Default port number.
  *
- * There is nothing standard about these port numbers.  They are simply what
+ * There is nothing standard about this port number.  It is simply what
  * we have chosen. */
 #define JSONRPC_TCP_PORT 6632
-#define JSONRPC_SSL_PORT 6632
 
 int jsonrpc_stream_open(const char *name, struct stream **, uint8_t dscp);
 int jsonrpc_pstream_open(const char *name, struct pstream **, uint8_t dscp);
index 3b9270f..1a77b79 100644 (file)
@@ -317,7 +317,7 @@ ssl_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp)
         return error;
     }
 
-    error = inet_open_active(SOCK_STREAM, suffix, OFP_SSL_PORT, &sin, &fd,
+    error = inet_open_active(SOCK_STREAM, suffix, OFP_TCP_PORT, &sin, &fd,
                              dscp);
     if (fd >= 0) {
         int state = error ? STATE_TCP_CONNECTING : STATE_SSL_CONNECTING;
@@ -797,7 +797,7 @@ pssl_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
         return retval;
     }
 
-    fd = inet_open_passive(SOCK_STREAM, suffix, OFP_SSL_PORT, &sin, dscp);
+    fd = inet_open_passive(SOCK_STREAM, suffix, OFP_TCP_PORT, &sin, dscp);
     if (fd < 0) {
         return -fd;
     }
@@ -846,7 +846,7 @@ pssl_accept(struct pstream *pstream, struct stream **new_streamp)
     }
 
     sprintf(name, "ssl:"IP_FMT, IP_ARGS(sin.sin_addr.s_addr));
-    if (sin.sin_port != htons(OFP_SSL_PORT)) {
+    if (sin.sin_port != htons(OFP_TCP_PORT)) {
         sprintf(strchr(name, '\0'), ":%"PRIu16, ntohs(sin.sin_port));
     }
     return new_ssl_stream(name, new_fd, SERVER, STATE_SSL_CONNECTING, &sin,
index bba6308..5bf42ce 100644 (file)
@@ -714,23 +714,20 @@ count_fields(const char *s_)
     return n;
 }
 
-/* Like stream_open(), but for tcp streams the port defaults to
- * 'default_tcp_port' if no port number is given and for SSL streams the port
- * defaults to 'default_ssl_port' if no port number is given. */
+/* Like stream_open(), but the port defaults to 'default_port' if no port
+ * number is given. */
 int
-stream_open_with_default_ports(const char *name_,
-                               uint16_t default_tcp_port,
-                               uint16_t default_ssl_port,
-                               struct stream **streamp,
-                               uint8_t dscp)
+stream_open_with_default_port(const char *name_,
+                              uint16_t default_port,
+                              struct stream **streamp,
+                              uint8_t dscp)
 {
     char *name;
     int error;
 
-    if (!strncmp(name_, "tcp:", 4) && count_fields(name_) < 3) {
-        name = xasprintf("%s:%d", name_, default_tcp_port);
-    } else if (!strncmp(name_, "ssl:", 4) && count_fields(name_) < 3) {
-        name = xasprintf("%s:%d", name_, default_ssl_port);
+    if ((!strncmp(name_, "tcp:", 4) || !strncmp(name_, "ssl:", 4))
+        && count_fields(name_) < 3) {
+        name = xasprintf("%s:%d", name_, default_port);
     } else {
         name = xstrdup(name_);
     }
@@ -740,23 +737,20 @@ stream_open_with_default_ports(const char *name_,
     return error;
 }
 
-/* Like pstream_open(), but for ptcp streams the port defaults to
- * 'default_ptcp_port' if no port number is given and for passive SSL streams
- * the port defaults to 'default_pssl_port' if no port number is given. */
+/* Like pstream_open(), but port defaults to 'default_port' if no port
+ * number is given. */
 int
-pstream_open_with_default_ports(const char *name_,
-                                uint16_t default_ptcp_port,
-                                uint16_t default_pssl_port,
-                                struct pstream **pstreamp,
-                                uint8_t dscp)
+pstream_open_with_default_port(const char *name_,
+                               uint16_t default_port,
+                               struct pstream **pstreamp,
+                               uint8_t dscp)
 {
     char *name;
     int error;
 
-    if (!strncmp(name_, "ptcp:", 5) && count_fields(name_) < 2) {
-        name = xasprintf("%s%d", name_, default_ptcp_port);
-    } else if (!strncmp(name_, "pssl:", 5) && count_fields(name_) < 2) {
-        name = xasprintf("%s%d", name_, default_pssl_port);
+    if ((!strncmp(name_, "ptcp:", 5) || !strncmp(name_, "pssl:", 5))
+        && count_fields(name_) < 2) {
+        name = xasprintf("%s%d", name_, default_port);
     } else {
         name = xstrdup(name_);
     }
@@ -775,15 +769,12 @@ pstream_open_with_default_ports(const char *name_,
  *     - On error, function returns false and *sin contains garbage.
  */
 bool
-stream_parse_target_with_default_ports(const char *target,
-                                       uint16_t default_tcp_port,
-                                       uint16_t default_ssl_port,
-                                       struct sockaddr_in *sin)
-{
-    return (!strncmp(target, "tcp:", 4)
-             && inet_parse_active(target + 4, default_tcp_port, sin)) ||
-            (!strncmp(target, "ssl:", 4)
-             && inet_parse_active(target + 4, default_ssl_port, sin));
+stream_parse_target_with_default_port(const char *target,
+                                      uint16_t default_port,
+                                      struct sockaddr_in *sin)
+{
+    return ((!strncmp(target, "tcp:", 4) || !strncmp(target, "ssl:", 4))
+             && inet_parse_active(target + 4, default_port, sin));
 }
 
 /* Attempts to guess the content type of a stream whose first few bytes were
index aa3fa9d..d966cde 100644 (file)
@@ -71,19 +71,16 @@ ovs_be16 pstream_get_bound_port(const struct pstream *);
 \f
 /* Convenience functions. */
 
-int stream_open_with_default_ports(const char *name,
-                                   uint16_t default_tcp_port,
-                                   uint16_t default_ssl_port,
-                                   struct stream **,
+int stream_open_with_default_port(const char *name,
+                                  uint16_t default_port,
+                                  struct stream **,
+                                  uint8_t dscp);
+int pstream_open_with_default_port(const char *name,
+                                   uint16_t default_port,
+                                   struct pstream **,
                                    uint8_t dscp);
-int pstream_open_with_default_ports(const char *name,
-                                    uint16_t default_ptcp_port,
-                                    uint16_t default_pssl_port,
-                                    struct pstream **,
-                                    uint8_t dscp);
-bool stream_parse_target_with_default_ports(const char *target,
-                                           uint16_t default_tcp_port,
-                                           uint16_t default_ssl_port,
+bool stream_parse_target_with_default_port(const char *target,
+                                           uint16_t default_port,
                                            struct sockaddr_in *sin);
 int stream_or_pstream_needs_probes(const char *name);
 
index 92076d9..23145ea 100644 (file)
@@ -82,8 +82,7 @@ vconn_stream_open(const char *name, uint32_t allowed_versions,
     struct stream *stream;
     int error;
 
-    error = stream_open_with_default_ports(name, OFP_TCP_PORT, OFP_SSL_PORT,
-                                           &stream, dscp);
+    error = stream_open_with_default_port(name, OFP_TCP_PORT, &stream, dscp);
     if (!error) {
         error = stream_connect(stream);
         if (!error || error == EAGAIN) {
@@ -316,8 +315,8 @@ pvconn_pstream_listen(const char *name, uint32_t allowed_versions,
     struct pstream *pstream;
     int error;
 
-    error = pstream_open_with_default_ports(name, OFP_TCP_PORT, OFP_SSL_PORT,
-                                            &pstream, dscp);
+    error = pstream_open_with_default_port(name, OFP_TCP_PORT,
+                                           &pstream, dscp);
     if (error) {
         return error;
     }
index 15ac119..8a06485 100644 (file)
@@ -141,7 +141,7 @@ vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
                "PORT (default: %d) at remote IP\n", OFP_TCP_PORT);
 #ifdef HAVE_OPENSSL
         printf("  ssl:IP[:PORT]           "
-               "SSL PORT (default: %d) at remote IP\n", OFP_SSL_PORT);
+               "SSL PORT (default: %d) at remote IP\n", OFP_TCP_PORT);
 #endif
         printf("  unix:FILE               Unix domain socket named FILE\n");
     }
@@ -154,7 +154,7 @@ vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
 #ifdef HAVE_OPENSSL
         printf("  pssl:[PORT][:IP]        "
                "listen for SSL on PORT (default: %d) on IP\n",
-               OFP_SSL_PORT);
+               OFP_TCP_PORT);
 #endif
         printf("  punix:FILE              "
                "listen on Unix domain socket FILE\n");
index 4a370eb..2fd94e2 100644 (file)
@@ -692,10 +692,9 @@ update_in_band_remotes(struct connmgr *mgr)
             continue;
         }
 
-        if (stream_parse_target_with_default_ports(target,
-                                                   OFP_TCP_PORT,
-                                                   OFP_SSL_PORT,
-                                                   sin)) {
+        if (stream_parse_target_with_default_port(target,
+                                                  OFP_TCP_PORT,
+                                                  sin)) {
             n_addrs++;
         }
     }
index da2dc42..423da10 100644 (file)
@@ -473,10 +473,9 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
         SSET_FOR_EACH (target, &targets) {
             struct sockaddr_in *sin = &managers[n_managers];
 
-            if (stream_parse_target_with_default_ports(target,
-                                                       JSONRPC_TCP_PORT,
-                                                       JSONRPC_SSL_PORT,
-                                                       sin)) {
+            if (stream_parse_target_with_default_port(target,
+                                                      JSONRPC_TCP_PORT,
+                                                      sin)) {
                 n_managers++;
             }
         }