stream: Make passive SSL and TCP streams report bound addresses as names.
authorBen Pfaff <blp@nicira.com>
Thu, 7 Jan 2010 21:55:35 +0000 (13:55 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 7 Jan 2010 23:00:51 +0000 (15:00 -0800)
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.

lib/stream-ssl.c
lib/stream-tcp.c

index 442a1e6..11bbf4a 100644 (file)
@@ -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;
index dd55845..e690e9c 100644 (file)
@@ -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