From 01420a2cddd7b5cf0a8ac59a4d60ce9d3b328d97 Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Wed, 1 Oct 2014 10:38:23 -0700 Subject: [PATCH] stream-tcp: Change the connection name for pwindows. As of now, when someone passes a punix:foo/bar as a connection type in Windows, we create a TCP server using 127.0.0.1 and save the kernel assigned port number in the file foo/bar. The connection name as obtained through pstream_get_name() would be ptcp:127.0.0.1:$PORT. This was okay if pstream_get_name() was only used for logging purposes. But netdev-dummy uses it to close active connections when the passed name and created name are different. This causes transient connection teardowns while using patch ports in Windows unit tests causing occasional packet loss. This commit sets the connection name to be punix:foo/bar instead of ptcp:127.0.0.1:$PORT for pwindows. Signed-off-by: Gurucharan Shetty Acked-by: Ben Pfaff --- lib/stream-tcp.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c index 5d0602a5854..ea6ef696a68 100644 --- a/lib/stream-tcp.c +++ b/lib/stream-tcp.c @@ -154,8 +154,8 @@ static int ptcp_accept(int fd, const struct sockaddr_storage *, size_t, struct stream **streamp); static int -new_pstream(char *suffix, struct pstream **pstreamp, int dscp, - char *unlink_path, bool kernel_print_port) +new_pstream(char *suffix, const char *name, struct pstream **pstreamp, + int dscp, char *unlink_path, bool kernel_print_port) { char bound_name[SS_NTOP_BUFSIZE + 16]; char addrbuf[SS_NTOP_BUFSIZE]; @@ -163,6 +163,7 @@ new_pstream(char *suffix, struct pstream **pstreamp, int dscp, int error; uint16_t port; int fd; + char *conn_name = CONST_CAST(char *, name); fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp, kernel_print_port); @@ -171,10 +172,13 @@ new_pstream(char *suffix, struct pstream **pstreamp, int dscp, } port = ss_get_port(&ss); - snprintf(bound_name, sizeof bound_name, "ptcp:%"PRIu16":%s", - port, ss_format_address(&ss, addrbuf, sizeof addrbuf)); + if (!conn_name) { + snprintf(bound_name, sizeof bound_name, "ptcp:%"PRIu16":%s", + port, ss_format_address(&ss, addrbuf, sizeof addrbuf)); + conn_name = bound_name; + } - error = new_fd_pstream(bound_name, fd, ptcp_accept, set_dscp, unlink_path, + error = new_fd_pstream(conn_name, fd, ptcp_accept, set_dscp, unlink_path, pstreamp); if (!error) { pstream_set_bound_port(*pstreamp, htons(port)); @@ -186,7 +190,7 @@ static int ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp, uint8_t dscp) { - return new_pstream(suffix, pstreamp, dscp, NULL, true); + return new_pstream(suffix, NULL, pstreamp, dscp, NULL, true); } static int @@ -214,8 +218,8 @@ const struct pstream_class ptcp_pstream_class = { #ifdef _WIN32 static int -pwindows_open(const char *name OVS_UNUSED, char *suffix, - struct pstream **pstreamp, uint8_t dscp) +pwindows_open(const char *name, char *suffix, struct pstream **pstreamp, + uint8_t dscp) { int error; char *suffix_new, *path; @@ -232,7 +236,7 @@ pwindows_open(const char *name OVS_UNUSED, char *suffix, path = xstrdup(suffix); } - error = new_pstream(suffix_new, pstreamp, dscp, path, false); + error = new_pstream(suffix_new, name, pstreamp, dscp, path, false); if (error) { goto exit; }