-/* Copyright (C) 2007 Board of Trustees, Leland Stanford Jr. University.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
+ * Junior University
+ *
+ * We are making the OpenFlow specification and associated documentation
+ * (Software) available for public use and benefit with the expectation
+ * that others will use, modify and enhance the Software and contribute
+ * those enhancements back to the community. However, since we would
+ * like to make the Software available for broadest use, with as few
+ * restrictions as possible permission is hereby granted, free of
+ * charge, to any person obtaining a copy of this Software to deal in
+ * the Software under the copyrights without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * The name and trademarks of copyright holder(s) may NOT be used in
+ * advertising or publicity pertaining to the Software or any
+ * derivatives without specific, written prior permission.
*/
#include "vconn.h"
#include <assert.h>
#include <errno.h>
+#include <inttypes.h>
#include <netdb.h>
#include <poll.h>
#include <sys/types.h>
#include "util.h"
#include "openflow.h"
#include "ofp-print.h"
+#include "packets.h"
#include "poll-loop.h"
#include "vlog.h"
static int
new_tcp_vconn(const char *name, int fd, int connect_status,
- struct vconn **vconnp)
+ const struct sockaddr_in *sin, struct vconn **vconnp)
{
struct tcp_vconn *tcp;
int on = 1;
tcp = xmalloc(sizeof *tcp);
tcp->vconn.class = &tcp_vconn_class;
tcp->vconn.connect_status = connect_status;
+ tcp->vconn.ip = sin->sin_addr.s_addr;
tcp->fd = fd;
tcp->txbuf = NULL;
tcp->tx_waiter = NULL;
host_name = strtok_r(suffix, "::", &save_ptr);
port_string = strtok_r(NULL, "::", &save_ptr);
if (!host_name) {
- fatal(0, "%s: bad peer name format", name);
+ error(0, "%s: bad peer name format", name);
+ return EAFNOSUPPORT;
}
memset(&sin, 0, sizeof sin);
retval = connect(fd, (struct sockaddr *) &sin, sizeof sin);
if (retval < 0) {
if (errno == EINPROGRESS) {
- return new_tcp_vconn(name, fd, EAGAIN, vconnp);
+ return new_tcp_vconn(name, fd, EAGAIN, &sin, vconnp);
} else {
int error = errno;
VLOG_ERR("%s: connect: %s", name, strerror(error));
return error;
}
} else {
- return new_tcp_vconn(name, fd, 0, vconnp);
+ return new_tcp_vconn(name, fd, 0, &sin, vconnp);
}
}
return EPROTO;
}
want_bytes = length - rx->size;
+ if (!want_bytes) {
+ *bufferp = rx;
+ tcp->rxbuf = NULL;
+ return 0;
+ }
}
- buffer_reserve_tailroom(rx, want_bytes);
+ buffer_prealloc_tailroom(rx, want_bytes);
retval = read(tcp->fd, buffer_tail(rx), want_bytes);
if (retval > 0) {
}
return EAGAIN;
} else if (retval == 0) {
- return rx->size ? EPROTO : EOF;
+ if (rx->size) {
+ VLOG_ERR("connection dropped mid-packet");
+ return EPROTO;
+ } else {
+ return EOF;
+ }
} else {
return retval ? errno : EAGAIN;
}
struct tcp_vconn *tcp = tcp_vconn_cast(vconn);
switch (wait) {
case WAIT_CONNECT:
- poll_fd_wait(tcp->fd, POLLOUT, NULL);
+ poll_fd_wait(tcp->fd, POLLOUT);
break;
case WAIT_SEND:
if (!tcp->txbuf) {
- poll_fd_wait(tcp->fd, POLLOUT, NULL);
+ poll_fd_wait(tcp->fd, POLLOUT);
} else {
/* Nothing to do: need to drain txbuf first. */
}
break;
case WAIT_RECV:
- poll_fd_wait(tcp->fd, POLLIN, NULL);
+ poll_fd_wait(tcp->fd, POLLIN);
break;
default:
ptcp_accept(struct vconn *vconn, struct vconn **new_vconnp)
{
struct ptcp_vconn *ptcp = ptcp_vconn_cast(vconn);
+ struct sockaddr_in sin;
+ socklen_t sin_len = sizeof sin;
+ char name[128];
int new_fd;
int error;
- new_fd = accept(ptcp->fd, NULL, NULL);
+ new_fd = accept(ptcp->fd, &sin, &sin_len);
if (new_fd < 0) {
int error = errno;
if (error != EAGAIN) {
return error;
}
- return new_tcp_vconn("tcp" /* FIXME */, new_fd, 0, new_vconnp);
+ sprintf(name, "tcp:"IP_FMT, IP_ARGS(&sin.sin_addr));
+ if (sin.sin_port != htons(OFP_TCP_PORT)) {
+ sprintf(strchr(name, '\0'), ":%"PRIu16, ntohs(sin.sin_port));
+ }
+ return new_tcp_vconn(name, new_fd, 0, &sin, new_vconnp);
}
static void
{
struct ptcp_vconn *ptcp = ptcp_vconn_cast(vconn);
assert(wait == WAIT_ACCEPT);
- poll_fd_wait(ptcp->fd, POLLIN, NULL);
+ poll_fd_wait(ptcp->fd, POLLIN);
}
struct vconn_class ptcp_vconn_class = {