#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. */
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
\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);
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;
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;
}
}
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,
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_);
}
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_);
}
* - 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
\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);
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) {
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;
}
"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");
}
#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");
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++;
}
}
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++;
}
}