2009-07-08 13:19:16 -07:00
|
|
|
|
/*
|
2013-06-24 10:54:49 -07:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07: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:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* 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.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
2009-09-21 13:07:10 -07:00
|
|
|
|
#include "fatal-signal.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "ofpbuf.h"
|
|
|
|
|
#include "openflow/openflow.h"
|
|
|
|
|
#include "poll-loop.h"
|
|
|
|
|
#include "socket-util.h"
|
2010-01-06 14:35:20 -08:00
|
|
|
|
#include "stream.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "vconn-provider.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
|
#include "openvswitch/vconn.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
|
#include "openvswitch/vlog.h"
|
2010-07-16 11:02:49 -07:00
|
|
|
|
|
2010-10-19 14:47:01 -07:00
|
|
|
|
VLOG_DEFINE_THIS_MODULE(vconn_stream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Active stream socket vconn. */
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
|
|
|
|
struct vconn vconn;
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct stream *stream;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct ofpbuf *rxbuf;
|
|
|
|
|
struct ofpbuf *txbuf;
|
2010-05-05 10:31:44 -07:00
|
|
|
|
int n_packets;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
};
|
|
|
|
|
|
2013-04-26 13:25:32 -07:00
|
|
|
|
static const struct vconn_class stream_vconn_class;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 25);
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
static void vconn_stream_clear_txbuf(struct vconn_stream *);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
static struct vconn *
|
2012-11-04 21:41:02 -08:00
|
|
|
|
vconn_stream_new(struct stream *stream, int connect_status,
|
|
|
|
|
uint32_t allowed_versions)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
s = xmalloc(sizeof *s);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_init(&s->vconn, &stream_vconn_class, connect_status,
|
2012-11-04 21:41:02 -08:00
|
|
|
|
stream_get_name(stream), allowed_versions);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
s->stream = stream;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->txbuf = NULL;
|
|
|
|
|
s->rxbuf = NULL;
|
2010-05-05 10:31:44 -07:00
|
|
|
|
s->n_packets = 0;
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return &s->vconn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Creates a new vconn that will send and receive data on a stream named 'name'
|
|
|
|
|
* and stores a pointer to the vconn in '*vconnp'.
|
|
|
|
|
*
|
|
|
|
|
* Returns 0 if successful, otherwise a positive errno value. */
|
|
|
|
|
static int
|
2012-11-04 21:41:02 -08:00
|
|
|
|
vconn_stream_open(const char *name, uint32_t allowed_versions,
|
|
|
|
|
char *suffix OVS_UNUSED, struct vconn **vconnp, uint8_t dscp)
|
2010-01-06 14:35:20 -08:00
|
|
|
|
{
|
|
|
|
|
struct stream *stream;
|
|
|
|
|
int error;
|
|
|
|
|
|
2013-08-30 17:26:56 -07:00
|
|
|
|
error = stream_open_with_default_port(name, OFP_OLD_PORT, &stream, dscp);
|
2010-06-11 15:58:14 -07:00
|
|
|
|
if (!error) {
|
|
|
|
|
error = stream_connect(stream);
|
|
|
|
|
if (!error || error == EAGAIN) {
|
2012-11-04 21:41:02 -08:00
|
|
|
|
*vconnp = vconn_stream_new(stream, error, allowed_versions);
|
2010-06-11 15:58:14 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-01-06 14:35:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-11 15:58:14 -07:00
|
|
|
|
stream_close(stream);
|
|
|
|
|
return error;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
static struct vconn_stream *
|
|
|
|
|
vconn_stream_cast(struct vconn *vconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return CONTAINER_OF(vconn, struct vconn_stream, vconn);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_close(struct vconn *vconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
2010-05-05 10:31:44 -07:00
|
|
|
|
|
|
|
|
|
if ((vconn->error == EPROTO || s->n_packets < 1) && s->rxbuf) {
|
2015-03-02 17:29:44 -08:00
|
|
|
|
stream_report_content(s->rxbuf->data, s->rxbuf->size, STREAM_OPENFLOW,
|
2010-05-05 10:31:44 -07:00
|
|
|
|
THIS_MODULE, vconn_get_name(vconn));
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_close(s->stream);
|
|
|
|
|
vconn_stream_clear_txbuf(s);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ofpbuf_delete(s->rxbuf);
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_connect(struct vconn *vconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
|
|
|
|
return stream_connect(s->stream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2010-05-10 15:01:25 -07:00
|
|
|
|
vconn_stream_recv__(struct vconn_stream *s, int rx_len)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-05-10 15:01:25 -07:00
|
|
|
|
struct ofpbuf *rx = s->rxbuf;
|
|
|
|
|
int want_bytes, retval;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2015-03-02 17:29:44 -08:00
|
|
|
|
want_bytes = rx_len - rx->size;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ofpbuf_prealloc_tailroom(rx, want_bytes);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
retval = stream_recv(s->stream, ofpbuf_tail(rx), want_bytes);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
if (retval > 0) {
|
2015-03-02 17:29:44 -08:00
|
|
|
|
rx->size += retval;
|
2010-05-10 15:01:25 -07:00
|
|
|
|
return retval == want_bytes ? 0 : EAGAIN;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
} else if (retval == 0) {
|
2015-03-02 17:29:44 -08:00
|
|
|
|
if (rx->size) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
VLOG_ERR_RL(&rl, "connection dropped mid-packet");
|
|
|
|
|
return EPROTO;
|
|
|
|
|
}
|
2010-05-10 15:01:25 -07:00
|
|
|
|
return EOF;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
} else {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return -retval;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-10 15:01:25 -07:00
|
|
|
|
static int
|
|
|
|
|
vconn_stream_recv(struct vconn *vconn, struct ofpbuf **bufferp)
|
|
|
|
|
{
|
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
|
|
|
|
const struct ofp_header *oh;
|
|
|
|
|
int rx_len;
|
|
|
|
|
|
|
|
|
|
/* Allocate new receive buffer if we don't have one. */
|
|
|
|
|
if (s->rxbuf == NULL) {
|
|
|
|
|
s->rxbuf = ofpbuf_new(1564);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read ofp_header. */
|
2015-03-02 17:29:44 -08:00
|
|
|
|
if (s->rxbuf->size < sizeof(struct ofp_header)) {
|
2010-05-10 15:01:25 -07:00
|
|
|
|
int retval = vconn_stream_recv__(s, sizeof(struct ofp_header));
|
|
|
|
|
if (retval) {
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read payload. */
|
2015-03-02 17:29:44 -08:00
|
|
|
|
oh = s->rxbuf->data;
|
2010-05-10 15:01:25 -07:00
|
|
|
|
rx_len = ntohs(oh->length);
|
|
|
|
|
if (rx_len < sizeof(struct ofp_header)) {
|
2010-08-20 09:25:34 -07:00
|
|
|
|
VLOG_ERR_RL(&rl, "received too-short ofp_header (%d bytes)", rx_len);
|
2010-05-10 15:01:25 -07:00
|
|
|
|
return EPROTO;
|
2015-03-02 17:29:44 -08:00
|
|
|
|
} else if (s->rxbuf->size < rx_len) {
|
2010-05-10 15:01:25 -07:00
|
|
|
|
int retval = vconn_stream_recv__(s, rx_len);
|
|
|
|
|
if (retval) {
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-05 10:31:44 -07:00
|
|
|
|
s->n_packets++;
|
2010-05-10 15:01:25 -07:00
|
|
|
|
*bufferp = s->rxbuf;
|
|
|
|
|
s->rxbuf = NULL;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_clear_txbuf(struct vconn_stream *s)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
|
|
|
|
ofpbuf_delete(s->txbuf);
|
|
|
|
|
s->txbuf = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_send(struct vconn *vconn, struct ofpbuf *buffer)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ssize_t retval;
|
|
|
|
|
|
|
|
|
|
if (s->txbuf) {
|
|
|
|
|
return EAGAIN;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 17:29:44 -08:00
|
|
|
|
retval = stream_send(s->stream, buffer->data, buffer->size);
|
|
|
|
|
if (retval == buffer->size) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ofpbuf_delete(buffer);
|
|
|
|
|
return 0;
|
2010-01-06 14:35:20 -08:00
|
|
|
|
} else if (retval >= 0 || retval == -EAGAIN) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->txbuf = buffer;
|
|
|
|
|
if (retval > 0) {
|
|
|
|
|
ofpbuf_pull(buffer, retval);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return -retval;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:27:46 -08:00
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_run(struct vconn *vconn)
|
2010-01-06 14:27:46 -08:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
|
|
|
|
ssize_t retval;
|
2010-01-06 14:27:46 -08:00
|
|
|
|
|
2011-07-08 09:11:55 -07:00
|
|
|
|
stream_run(s->stream);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
if (!s->txbuf) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 17:29:44 -08:00
|
|
|
|
retval = stream_send(s->stream, s->txbuf->data, s->txbuf->size);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
if (retval < 0) {
|
|
|
|
|
if (retval != -EAGAIN) {
|
2013-06-24 10:54:49 -07:00
|
|
|
|
VLOG_ERR_RL(&rl, "send: %s", ovs_strerror(-retval));
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_clear_txbuf(s);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-01-06 14:35:20 -08:00
|
|
|
|
} else if (retval > 0) {
|
|
|
|
|
ofpbuf_pull(s->txbuf, retval);
|
2015-03-02 17:29:44 -08:00
|
|
|
|
if (!s->txbuf->size) {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_clear_txbuf(s);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_run_wait(struct vconn *vconn)
|
2010-01-06 14:27:46 -08:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
|
2011-07-08 09:11:55 -07:00
|
|
|
|
stream_run_wait(s->stream);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
if (s->txbuf) {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_send_wait(s->stream);
|
2010-01-06 14:27:46 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_wait(struct vconn *vconn, enum vconn_wait_type wait)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct vconn_stream *s = vconn_stream_cast(vconn);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
switch (wait) {
|
|
|
|
|
case WAIT_CONNECT:
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_connect_wait(s->stream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WAIT_SEND:
|
|
|
|
|
if (!s->txbuf) {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_send_wait(s->stream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
} else {
|
2010-01-06 14:35:20 -08:00
|
|
|
|
/* Nothing to do: need to drain txbuf first.
|
|
|
|
|
* vconn_stream_run_wait() will arrange to wake up when there room
|
|
|
|
|
* to send data, so there's no point in calling poll_fd_wait()
|
|
|
|
|
* redundantly here. */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WAIT_RECV:
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_recv_wait(s->stream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2013-12-17 10:32:12 -08:00
|
|
|
|
OVS_NOT_REACHED();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Passive stream socket vconn. */
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pvconn_pstream
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
|
|
|
|
struct pvconn pvconn;
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pstream *pstream;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
};
|
|
|
|
|
|
2013-04-26 13:25:32 -07:00
|
|
|
|
static const struct pvconn_class pstream_pvconn_class;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
static struct pvconn_pstream *
|
|
|
|
|
pvconn_pstream_cast(struct pvconn *pvconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return CONTAINER_OF(pvconn, struct pvconn_pstream, pvconn);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
/* Creates a new pvconn named 'name' that will accept new connections using
|
|
|
|
|
* pstream_accept() and stores a pointer to the pvconn in '*pvconnp'.
|
2009-09-21 13:07:10 -07:00
|
|
|
|
*
|
|
|
|
|
* Returns 0 if successful, otherwise a positive errno value. (The current
|
|
|
|
|
* implementation never fails.) */
|
2010-01-06 14:35:20 -08:00
|
|
|
|
static int
|
2012-11-04 21:41:02 -08:00
|
|
|
|
pvconn_pstream_listen(const char *name, uint32_t allowed_versions,
|
|
|
|
|
char *suffix OVS_UNUSED, struct pvconn **pvconnp,
|
|
|
|
|
uint8_t dscp)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pvconn_pstream *ps;
|
|
|
|
|
struct pstream *pstream;
|
|
|
|
|
int error;
|
|
|
|
|
|
2013-08-30 17:26:56 -07:00
|
|
|
|
error = pstream_open_with_default_port(name, OFP_OLD_PORT,
|
2013-09-23 14:33:09 -07:00
|
|
|
|
&pstream, dscp);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ps = xmalloc(sizeof *ps);
|
2012-11-04 21:41:02 -08:00
|
|
|
|
pvconn_init(&ps->pvconn, &pstream_pvconn_class, name, allowed_versions);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
ps->pstream = pstream;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*pvconnp = &ps->pvconn;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
pvconn_pstream_close(struct pvconn *pvconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pvconn_pstream *ps = pvconn_pstream_cast(pvconn);
|
|
|
|
|
pstream_close(ps->pstream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
free(ps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2010-01-06 14:35:20 -08:00
|
|
|
|
pvconn_pstream_accept(struct pvconn *pvconn, struct vconn **new_vconnp)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pvconn_pstream *ps = pvconn_pstream_cast(pvconn);
|
|
|
|
|
struct stream *stream;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
error = pstream_accept(ps->pstream, &stream);
|
|
|
|
|
if (error) {
|
|
|
|
|
if (error != EAGAIN) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: accept: %s",
|
2013-06-24 10:54:49 -07:00
|
|
|
|
pstream_get_name(ps->pstream), ovs_strerror(error));
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return error;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-04 21:41:02 -08:00
|
|
|
|
*new_vconnp = vconn_stream_new(stream, 0, pvconn->allowed_versions);
|
2010-01-06 14:35:20 -08:00
|
|
|
|
return 0;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-01-06 14:35:20 -08:00
|
|
|
|
pvconn_pstream_wait(struct pvconn *pvconn)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2010-01-06 14:35:20 -08:00
|
|
|
|
struct pvconn_pstream *ps = pvconn_pstream_cast(pvconn);
|
|
|
|
|
pstream_wait(ps->pstream);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
2009-09-21 13:07:10 -07:00
|
|
|
|
|
2010-01-06 14:35:20 -08:00
|
|
|
|
/* Stream-based vconns and pvconns. */
|
|
|
|
|
|
2011-02-04 15:10:27 -08:00
|
|
|
|
#define STREAM_INIT(NAME) \
|
|
|
|
|
{ \
|
|
|
|
|
NAME, \
|
2010-01-06 14:35:20 -08:00
|
|
|
|
vconn_stream_open, \
|
|
|
|
|
vconn_stream_close, \
|
|
|
|
|
vconn_stream_connect, \
|
|
|
|
|
vconn_stream_recv, \
|
|
|
|
|
vconn_stream_send, \
|
|
|
|
|
vconn_stream_run, \
|
|
|
|
|
vconn_stream_run_wait, \
|
|
|
|
|
vconn_stream_wait, \
|
2011-02-04 15:10:27 -08:00
|
|
|
|
}
|
2010-01-06 14:35:20 -08:00
|
|
|
|
|
2011-02-04 15:10:27 -08:00
|
|
|
|
#define PSTREAM_INIT(NAME) \
|
|
|
|
|
{ \
|
|
|
|
|
NAME, \
|
2010-01-06 14:35:20 -08:00
|
|
|
|
pvconn_pstream_listen, \
|
|
|
|
|
pvconn_pstream_close, \
|
|
|
|
|
pvconn_pstream_accept, \
|
|
|
|
|
pvconn_pstream_wait \
|
2011-02-04 15:10:27 -08:00
|
|
|
|
}
|
2010-01-06 14:35:20 -08:00
|
|
|
|
|
2013-04-26 13:25:32 -07:00
|
|
|
|
static const struct vconn_class stream_vconn_class = STREAM_INIT("stream");
|
|
|
|
|
static const struct pvconn_class pstream_pvconn_class = PSTREAM_INIT("pstream");
|
2010-01-06 14:35:20 -08:00
|
|
|
|
|
2013-04-26 13:25:32 -07:00
|
|
|
|
const struct vconn_class tcp_vconn_class = STREAM_INIT("tcp");
|
|
|
|
|
const struct pvconn_class ptcp_pvconn_class = PSTREAM_INIT("ptcp");
|
2010-01-06 14:35:20 -08:00
|
|
|
|
|
2013-04-26 13:25:32 -07:00
|
|
|
|
const struct vconn_class unix_vconn_class = STREAM_INIT("unix");
|
|
|
|
|
const struct pvconn_class punix_pvconn_class = PSTREAM_INIT("punix");
|
2010-01-06 14:35:20 -08:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
2013-04-26 13:25:32 -07:00
|
|
|
|
const struct vconn_class ssl_vconn_class = STREAM_INIT("ssl");
|
|
|
|
|
const struct pvconn_class pssl_pvconn_class = PSTREAM_INIT("pssl");
|
2010-01-06 14:35:20 -08:00
|
|
|
|
#endif
|