From ca843648e3b4181a52a398b902e5e69221976476 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Mon, 23 Sep 2013 14:33:09 -0700 Subject: [PATCH] Don't differentiate between TCP and SSL ports for OpenFlow and OVSDB. 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 Acked-by: Ben Pfaff --- include/openflow/openflow-common.h | 1 - lib/jsonrpc.c | 13 ++++--- lib/jsonrpc.h | 5 ++- lib/stream-ssl.c | 6 ++-- lib/stream.c | 57 +++++++++++++----------------- lib/stream.h | 21 +++++------ lib/vconn-stream.c | 7 ++-- lib/vconn.c | 4 +-- ofproto/connmgr.c | 7 ++-- vswitchd/bridge.c | 7 ++-- 10 files changed, 55 insertions(+), 73 deletions(-) diff --git a/include/openflow/openflow-common.h b/include/openflow/openflow-common.h index 5018f8500..5b0ccc5f9 100644 --- a/include/openflow/openflow-common.h +++ b/include/openflow/openflow-common.h @@ -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. */ diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index e02f03579..b43b04423 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -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 diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h index 0ae205d32..2c691cf2d 100644 --- a/lib/jsonrpc.h +++ b/lib/jsonrpc.h @@ -32,12 +32,11 @@ struct stream; /* 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); diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c index 3b9270f93..1a77b7955 100644 --- a/lib/stream-ssl.c +++ b/lib/stream-ssl.c @@ -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, diff --git a/lib/stream.c b/lib/stream.c index bba63083c..5bf42ce87 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -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 diff --git a/lib/stream.h b/lib/stream.h index aa3fa9d48..d966cde81 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -71,19 +71,16 @@ ovs_be16 pstream_get_bound_port(const struct pstream *); /* 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); diff --git a/lib/vconn-stream.c b/lib/vconn-stream.c index 92076d999..23145ea08 100644 --- a/lib/vconn-stream.c +++ b/lib/vconn-stream.c @@ -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; } diff --git a/lib/vconn.c b/lib/vconn.c index 15ac11909..8a064851c 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -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"); diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 4a370eba7..2fd94e212 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -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++; } } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index da2dc4240..423da10ff 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -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++; } } -- 2.43.0