struct vconn {
struct vconn_class *class;
int connect_status;
+ uint32_t ip;
};
void vconn_usage(bool active, bool passive);
int vconn_open(const char *name, struct vconn **);
void vconn_close(struct vconn *);
bool vconn_is_passive(const struct vconn *);
+uint32_t vconn_get_ip(const struct vconn *);
int vconn_connect(struct vconn *);
int vconn_accept(struct vconn *, struct vconn **);
int vconn_recv(struct vconn *, struct buffer **);
netlink = xmalloc(sizeof *netlink);
netlink->vconn.class = &netlink_vconn_class;
netlink->vconn.connect_status = 0;
+ netlink->vconn.ip = 0;
retval = dpif_open(dp_idx, subscribe, &netlink->dp);
if (retval) {
free(netlink);
#include "dhparams.h"
#include <assert.h>
#include <errno.h>
+#include <inttypes.h>
#include <string.h>
#include <netinet/tcp.h>
#include <openssl/err.h>
#include "socket-util.h"
#include "util.h"
#include "openflow.h"
+#include "packets.h"
#include "poll-loop.h"
#include "ofp-print.h"
#include "socket-util.h"
static int
new_ssl_vconn(const char *name, int fd, enum session_type type,
- enum ssl_state state, struct vconn **vconnp)
+ enum ssl_state state, const struct sockaddr_in *sin,
+ struct vconn **vconnp)
{
struct ssl_vconn *sslv;
SSL *ssl = NULL;
sslv = xmalloc(sizeof *sslv);
sslv->vconn.class = &ssl_vconn_class;
sslv->vconn.connect_status = EAGAIN;
+ sslv->vconn.ip = sin->sin_addr.s_addr;
sslv->state = state;
sslv->type = type;
sslv->fd = fd;
if (retval < 0) {
if (errno == EINPROGRESS) {
return new_ssl_vconn(name, fd, CLIENT, STATE_TCP_CONNECTING,
- vconnp);
+ &sin, vconnp);
} else {
int error = errno;
VLOG_ERR("%s: connect: %s", name, strerror(error));
}
} else {
return new_ssl_vconn(name, fd, CLIENT, STATE_SSL_CONNECTING,
- vconnp);
+ &sin, vconnp);
}
}
pssl_accept(struct vconn *vconn, struct vconn **new_vconnp)
{
struct pssl_vconn *pssl = pssl_vconn_cast(vconn);
+ struct sockaddr_in sin;
+ socklen_t sin_len = sizeof sin;
+ char name[128];
int new_fd;
int error;
- new_fd = accept(pssl->fd, NULL, NULL);
+ new_fd = accept(pssl->fd, &sin, &sin_len);
if (new_fd < 0) {
int error = errno;
if (error != EAGAIN) {
return error;
}
- return new_ssl_vconn("ssl" /* FIXME */, new_fd,
- SERVER, STATE_SSL_CONNECTING, new_vconnp);
+ sprintf(name, "ssl:"IP_FMT, IP_ARGS(&sin.sin_addr));
+ if (sin.sin_port != htons(OFP_SSL_PORT)) {
+ sprintf(strchr(name, '\0'), ":%"PRIu16, ntohs(sin.sin_port));
+ }
+ return new_ssl_vconn(name, new_fd, SERVER, STATE_SSL_CONNECTING, &sin,
+ new_vconnp);
}
static void
#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;
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);
}
}
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
return vconn->class->accept != NULL;
}
+/* Returns the IP address of the peer, or 0 if the peer is not connected over
+ * an IP-based protocol or if its IP address is not yet known. */
+uint32_t
+vconn_get_ip(const struct vconn *vconn)
+{
+ return vconn->ip;
+}
+
/* Tries to complete the connection on 'vconn', which must be an active
* vconn. If 'vconn''s connection is complete, returns 0 if the connection
* was successful or a positive errno value if it failed. If the