From: Ben Pfaff Date: Thu, 7 Jan 2010 21:55:35 +0000 (-0800) Subject: stream: Make passive SSL and TCP streams report bound addresses as names. X-Git-Tag: v1.0.0~259^2~332 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=42967038cbbb56b894e99eb17e5de7cfb11de9cf;p=sliver-openvswitch.git stream: Make passive SSL and TCP streams report bound addresses as names. The names of passive SSL and TCP streams were being poorly reported: TCP always simply reported "ptcp", and SSL reported whatever was passed in. This commit makes them report the addresses that were actually bound by the TCP/IP stack, which is more useful for testing, debugging, and logging. --- diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c index 442a1e6a5..11bbf4ada 100644 --- a/lib/stream-ssl.c +++ b/lib/stream-ssl.c @@ -710,9 +710,11 @@ pssl_pstream_cast(struct pstream *pstream) } static int -pssl_open(const char *name, char *suffix, struct pstream **pstreamp) +pssl_open(const char *name UNUSED, char *suffix, struct pstream **pstreamp) { struct pssl_pstream *pssl; + struct sockaddr_in sin; + char bound_name[128]; int retval; int fd; @@ -725,9 +727,11 @@ pssl_open(const char *name, char *suffix, struct pstream **pstreamp) if (fd < 0) { return -fd; } + sprintf(bound_name, "pssl:%"PRIu16":"IP_FMT, + ntohs(sin.sin_port), IP_ARGS(&sin.sin_addr.s_addr)); pssl = xmalloc(sizeof *pssl); - pstream_init(&pssl->pstream, &pssl_pstream_class, name); + pstream_init(&pssl->pstream, &pssl_pstream_class, bound_name); pssl->fd = fd; *pstreamp = &pssl->pstream; return 0; diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c index dd55845fc..e690e9c56 100644 --- a/lib/stream-tcp.c +++ b/lib/stream-tcp.c @@ -103,14 +103,18 @@ static int ptcp_accept(int fd, const struct sockaddr *sa, size_t sa_len, static int ptcp_open(const char *name UNUSED, char *suffix, struct pstream **pstreamp) { + struct sockaddr_in sin; + char bound_name[128]; int fd; - fd = inet_open_passive(SOCK_STREAM, suffix, -1, NULL); + fd = inet_open_passive(SOCK_STREAM, suffix, -1, &sin); if (fd < 0) { return -fd; - } else { - return new_fd_pstream("ptcp", fd, ptcp_accept, NULL, pstreamp); } + + sprintf(bound_name, "ptcp:%"PRIu16":"IP_FMT, + ntohs(sin.sin_port), IP_ARGS(&sin.sin_addr.s_addr)); + return new_fd_pstream(bound_name, fd, ptcp_accept, NULL, pstreamp); } static int