2009-11-04 15:02:32 -08:00
|
|
|
|
/*
|
2013-04-18 16:37:05 -07:00
|
|
|
|
* Copyright (c) 2009, 2010, 2012, 2013 Nicira, Inc.
|
2009-11-04 15:02:32 -08:00
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef STREAM_PROVIDER_H
|
|
|
|
|
#define STREAM_PROVIDER_H 1
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
|
|
/* Active stream connection. */
|
|
|
|
|
|
|
|
|
|
/* Active stream connection.
|
|
|
|
|
*
|
|
|
|
|
* This structure should be treated as opaque by implementation. */
|
|
|
|
|
struct stream {
|
2011-11-24 10:22:22 +09:00
|
|
|
|
const struct stream_class *class;
|
2009-11-04 15:02:32 -08:00
|
|
|
|
int state;
|
|
|
|
|
int error;
|
|
|
|
|
char *name;
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-24 10:22:22 +09:00
|
|
|
|
void stream_init(struct stream *, const struct stream_class *,
|
|
|
|
|
int connect_status, const char *name);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
static inline void stream_assert_class(const struct stream *stream,
|
|
|
|
|
const struct stream_class *class)
|
|
|
|
|
{
|
2012-11-06 13:14:55 -08:00
|
|
|
|
ovs_assert(stream->class == class);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct stream_class {
|
|
|
|
|
/* Prefix for connection names, e.g. "tcp", "ssl", "unix". */
|
|
|
|
|
const char *name;
|
|
|
|
|
|
2012-07-23 00:24:30 -07:00
|
|
|
|
/* True if this stream needs periodic probes to verify connectivity. For
|
2012-04-11 20:18:34 -07:00
|
|
|
|
* streams which need probes, it can take a long time to notice the
|
|
|
|
|
* connection was dropped. */
|
|
|
|
|
bool needs_probes;
|
|
|
|
|
|
2009-11-04 15:02:32 -08:00
|
|
|
|
/* Attempts to connect to a peer. 'name' is the full connection name
|
|
|
|
|
* provided by the user, e.g. "tcp:1.2.3.4". This name is useful for error
|
|
|
|
|
* messages but must not be modified.
|
|
|
|
|
*
|
|
|
|
|
* 'suffix' is a copy of 'name' following the colon and may be modified.
|
2012-03-10 15:58:10 -08:00
|
|
|
|
* 'dscp' is the DSCP value that the new connection should use in the IP
|
2012-04-16 13:56:58 -07:00
|
|
|
|
* packets it sends.
|
2009-11-04 15:02:32 -08:00
|
|
|
|
*
|
|
|
|
|
* Returns 0 if successful, otherwise a positive errno value. If
|
|
|
|
|
* successful, stores a pointer to the new connection in '*streamp'.
|
|
|
|
|
*
|
|
|
|
|
* The open function must not block waiting for a connection to complete.
|
|
|
|
|
* If the connection cannot be completed immediately, it should return
|
|
|
|
|
* EAGAIN (not EINPROGRESS, as returned by the connect system call) and
|
|
|
|
|
* continue the connection in the background. */
|
2012-03-10 15:58:10 -08:00
|
|
|
|
int (*open)(const char *name, char *suffix, struct stream **streamp,
|
|
|
|
|
uint8_t dscp);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
|
|
|
|
|
/* Closes 'stream' and frees associated memory. */
|
|
|
|
|
void (*close)(struct stream *stream);
|
|
|
|
|
|
|
|
|
|
/* Tries to complete the connection on 'stream'. If 'stream''s connection
|
|
|
|
|
* is complete, returns 0 if the connection was successful or a positive
|
|
|
|
|
* errno value if it failed. If the connection is still in progress,
|
|
|
|
|
* returns EAGAIN.
|
|
|
|
|
*
|
|
|
|
|
* The connect function must not block waiting for the connection to
|
|
|
|
|
* complete; instead, it should return EAGAIN immediately. */
|
|
|
|
|
int (*connect)(struct stream *stream);
|
|
|
|
|
|
|
|
|
|
/* Tries to receive up to 'n' bytes from 'stream' into 'buffer', and
|
|
|
|
|
* returns:
|
|
|
|
|
*
|
|
|
|
|
* - If successful, the number of bytes received (between 1 and 'n').
|
|
|
|
|
*
|
|
|
|
|
* - On error, a negative errno value.
|
|
|
|
|
*
|
|
|
|
|
* - 0, if the connection has been closed in the normal fashion.
|
|
|
|
|
*
|
|
|
|
|
* The recv function will not be passed a zero 'n'.
|
|
|
|
|
*
|
|
|
|
|
* The recv function must not block waiting for data to arrive. If no data
|
|
|
|
|
* have been received, it should return -EAGAIN immediately. */
|
|
|
|
|
ssize_t (*recv)(struct stream *stream, void *buffer, size_t n);
|
|
|
|
|
|
|
|
|
|
/* Tries to send up to 'n' bytes of 'buffer' on 'stream', and returns:
|
|
|
|
|
*
|
|
|
|
|
* - If successful, the number of bytes sent (between 1 and 'n').
|
|
|
|
|
*
|
|
|
|
|
* - On error, a negative errno value.
|
|
|
|
|
*
|
|
|
|
|
* - Never returns 0.
|
|
|
|
|
*
|
|
|
|
|
* The send function will not be passed a zero 'n'.
|
|
|
|
|
*
|
|
|
|
|
* The send function must not block. If no bytes can be immediately
|
|
|
|
|
* accepted for transmission, it should return -EAGAIN immediately. */
|
|
|
|
|
ssize_t (*send)(struct stream *stream, const void *buffer, size_t n);
|
|
|
|
|
|
2010-01-06 14:26:48 -08:00
|
|
|
|
/* Allows 'stream' to perform maintenance activities, such as flushing
|
|
|
|
|
* output buffers.
|
|
|
|
|
*
|
|
|
|
|
* May be null if 'stream' doesn't have anything to do here. */
|
|
|
|
|
void (*run)(struct stream *stream);
|
|
|
|
|
|
|
|
|
|
/* Arranges for the poll loop to wake up when 'stream' needs to perform
|
|
|
|
|
* maintenance activities.
|
|
|
|
|
*
|
|
|
|
|
* May be null if 'stream' doesn't have anything to do here. */
|
|
|
|
|
void (*run_wait)(struct stream *stream);
|
|
|
|
|
|
2009-11-04 15:02:32 -08:00
|
|
|
|
/* Arranges for the poll loop to wake up when 'stream' is ready to take an
|
|
|
|
|
* action of the given 'type'. */
|
|
|
|
|
void (*wait)(struct stream *stream, enum stream_wait_type type);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Passive listener for incoming stream connections.
|
|
|
|
|
*
|
|
|
|
|
* This structure should be treated as opaque by stream implementations. */
|
|
|
|
|
struct pstream {
|
2011-11-24 10:22:22 +09:00
|
|
|
|
const struct pstream_class *class;
|
2009-11-04 15:02:32 -08:00
|
|
|
|
char *name;
|
2013-04-18 16:37:05 -07:00
|
|
|
|
ovs_be16 bound_port;
|
2009-11-04 15:02:32 -08:00
|
|
|
|
};
|
|
|
|
|
|
2011-11-24 10:22:22 +09:00
|
|
|
|
void pstream_init(struct pstream *, const struct pstream_class *, const char *name);
|
2013-04-18 16:37:05 -07:00
|
|
|
|
void pstream_set_bound_port(struct pstream *, ovs_be16 bound_port);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
static inline void pstream_assert_class(const struct pstream *pstream,
|
|
|
|
|
const struct pstream_class *class)
|
|
|
|
|
{
|
2012-11-06 13:14:55 -08:00
|
|
|
|
ovs_assert(pstream->class == class);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct pstream_class {
|
|
|
|
|
/* Prefix for connection names, e.g. "ptcp", "pssl", "punix". */
|
|
|
|
|
const char *name;
|
|
|
|
|
|
2012-07-23 00:24:30 -07:00
|
|
|
|
/* True if this pstream needs periodic probes to verify connectivity. For
|
2012-04-11 20:18:34 -07:00
|
|
|
|
* pstreams which need probes, it can take a long time to notice the
|
|
|
|
|
* connection was dropped. */
|
|
|
|
|
bool needs_probes;
|
|
|
|
|
|
2009-11-04 15:02:32 -08:00
|
|
|
|
/* Attempts to start listening for stream connections. 'name' is the full
|
|
|
|
|
* connection name provided by the user, e.g. "ptcp:1234". This name is
|
|
|
|
|
* useful for error messages but must not be modified.
|
|
|
|
|
*
|
|
|
|
|
* 'suffix' is a copy of 'name' following the colon and may be modified.
|
2012-03-10 15:58:10 -08:00
|
|
|
|
* 'dscp' is the DSCP value that the new connection should use in the IP
|
2012-04-16 13:56:58 -07:00
|
|
|
|
* packets it sends.
|
2009-11-04 15:02:32 -08:00
|
|
|
|
*
|
|
|
|
|
* Returns 0 if successful, otherwise a positive errno value. If
|
|
|
|
|
* successful, stores a pointer to the new connection in '*pstreamp'.
|
|
|
|
|
*
|
|
|
|
|
* The listen function must not block. If the connection cannot be
|
|
|
|
|
* completed immediately, it should return EAGAIN (not EINPROGRESS, as
|
|
|
|
|
* returned by the connect system call) and continue the connection in the
|
|
|
|
|
* background. */
|
2012-03-10 15:58:10 -08:00
|
|
|
|
int (*listen)(const char *name, char *suffix, struct pstream **pstreamp,
|
|
|
|
|
uint8_t dscp);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
|
|
|
|
|
/* Closes 'pstream' and frees associated memory. */
|
|
|
|
|
void (*close)(struct pstream *pstream);
|
|
|
|
|
|
|
|
|
|
/* Tries to accept a new connection on 'pstream'. If successful, stores
|
|
|
|
|
* the new connection in '*new_streamp' and returns 0. Otherwise, returns
|
|
|
|
|
* a positive errno value.
|
|
|
|
|
*
|
|
|
|
|
* The accept function must not block waiting for a connection. If no
|
|
|
|
|
* connection is ready to be accepted, it should return EAGAIN. */
|
|
|
|
|
int (*accept)(struct pstream *pstream, struct stream **new_streamp);
|
|
|
|
|
|
|
|
|
|
/* Arranges for the poll loop to wake up when a connection is ready to be
|
|
|
|
|
* accepted on 'pstream'. */
|
|
|
|
|
void (*wait)(struct pstream *pstream);
|
2012-09-27 11:18:16 +09:00
|
|
|
|
|
|
|
|
|
/* Set DSCP value of the listening socket. */
|
|
|
|
|
int (*set_dscp)(struct pstream *pstream, uint8_t dscp);
|
2009-11-04 15:02:32 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Active and passive stream classes. */
|
2011-11-24 10:22:22 +09:00
|
|
|
|
extern const struct stream_class tcp_stream_class;
|
|
|
|
|
extern const struct pstream_class ptcp_pstream_class;
|
stream: Introduce [p]windows_[p]stream_class.
On Linux, we heavily use --remote=punix:* to listen for
connections through unix domain sockets. We also use, unix:*
to connect to a daemon that is listening on unix domain sockets.
Many times, we create default unix domain sockets for listening
and many utilities connect to these sockets by default.
Windows does not have unix domain sockets. So far, we could just use
ptcp:* and tcp:* for listening and initiating connections respectively.
The drawback here is that one has to provide a specific TCP port.
For unit tests, it looks useful to let kernel choose that port.
As such, we can let that chosen kernel port be stored in the
file specified with punix:* and unix:*. For this purpose, introduce
a new [p]windows_[p]stream_class. Since it is just a wrapper around
[p]tcp_[p]stream_class, add it to stream-tcp.c.
commit cb54a8c (unixctl: Add support for Windows.) used the above concept
for only control channel connections (i.e., --unixctl for daemons and its
interaction with ovs-appctl). This commit adds the same support for
all unix domain sockets. Now that we have a separate class
[p]stream_class for hiding kernel assigned TCP port inside a file meant for
unix domain sockets in windows, make unixctl use it.
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-04-04 14:13:32 -07:00
|
|
|
|
#ifndef _WIN32
|
2011-11-24 10:22:22 +09:00
|
|
|
|
extern const struct stream_class unix_stream_class;
|
|
|
|
|
extern const struct pstream_class punix_pstream_class;
|
stream: Introduce [p]windows_[p]stream_class.
On Linux, we heavily use --remote=punix:* to listen for
connections through unix domain sockets. We also use, unix:*
to connect to a daemon that is listening on unix domain sockets.
Many times, we create default unix domain sockets for listening
and many utilities connect to these sockets by default.
Windows does not have unix domain sockets. So far, we could just use
ptcp:* and tcp:* for listening and initiating connections respectively.
The drawback here is that one has to provide a specific TCP port.
For unit tests, it looks useful to let kernel choose that port.
As such, we can let that chosen kernel port be stored in the
file specified with punix:* and unix:*. For this purpose, introduce
a new [p]windows_[p]stream_class. Since it is just a wrapper around
[p]tcp_[p]stream_class, add it to stream-tcp.c.
commit cb54a8c (unixctl: Add support for Windows.) used the above concept
for only control channel connections (i.e., --unixctl for daemons and its
interaction with ovs-appctl). This commit adds the same support for
all unix domain sockets. Now that we have a separate class
[p]stream_class for hiding kernel assigned TCP port inside a file meant for
unix domain sockets in windows, make unixctl use it.
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-04-04 14:13:32 -07:00
|
|
|
|
#else
|
|
|
|
|
extern const struct stream_class windows_stream_class;
|
|
|
|
|
extern const struct pstream_class pwindows_pstream_class;
|
|
|
|
|
#endif
|
2009-12-21 13:13:48 -08:00
|
|
|
|
#ifdef HAVE_OPENSSL
|
2011-11-24 10:22:22 +09:00
|
|
|
|
extern const struct stream_class ssl_stream_class;
|
|
|
|
|
extern const struct pstream_class pssl_pstream_class;
|
2009-12-21 13:13:48 -08:00
|
|
|
|
#endif
|
2009-11-04 15:02:32 -08:00
|
|
|
|
|
|
|
|
|
#endif /* stream-provider.h */
|