Skip to content

Commit

Permalink
stream-tcp: Change the connection name for pwindows.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
shettyg committed Oct 2, 2014
1 parent 55eebc0 commit 01420a2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/stream-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ 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];
struct sockaddr_storage ss;
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);
Expand All @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 01420a2

Please sign in to comment.