Re: [ovs-dev] [PATCH 5/5] socket-util: Log the kernel assigned port number when asked.

2014-05-28 Thread Gurucharan Shetty
On Tue, May 27, 2014 at 5:12 PM, Ben Pfaff  wrote:
> On Mon, May 19, 2014 at 12:52:26PM -0700, Gurucharan Shetty wrote:
>> So far, we log the kernel assigned port number when the port number is
>> not specified. On Windows, this happens multiple times because "unix"
>> sockets are implemented internally via TCP ports. This means that many tests,
>> specially the ovs-ofctl monitor tests, need to filter out the
>> additional messages. Doing that is not a big deal, but I think it will
>> keep manifesting in future tests added by Linux developers.
>>
>> With this commit, we simply don't print the kernel assigned TCP ports
>> on windows when done for "unix" sockets.
>>
>> Signed-off-by: Gurucharan Shetty 
>
> new_pstream() looks like it has two callers with similar code:
> fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp, true);
> if (fd < 0) {
> return -fd;
> }
>
> return new_pstream(fd, &ss, pstreamp);
> and
> fd = inet_open_passive(SOCK_STREAM, suffix_new, -1, &ss, dscp, false);
> if (fd < 0) {
> return -fd;
> }
>
> error = new_pstream(fd, &ss, pstreamp);
> if (error) {
> goto exit;
> }
>
> Can we move the inet_open_passive() call into new_pstream() and add a
> kernel_print_port parameter to new_pstream()?
I made the changes as you suggested and pushed the series.
Thank you!
>
> Acked-by: Ben Pfaff 
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 5/5] socket-util: Log the kernel assigned port number when asked.

2014-05-27 Thread Ben Pfaff
On Mon, May 19, 2014 at 12:52:26PM -0700, Gurucharan Shetty wrote:
> So far, we log the kernel assigned port number when the port number is
> not specified. On Windows, this happens multiple times because "unix"
> sockets are implemented internally via TCP ports. This means that many tests,
> specially the ovs-ofctl monitor tests, need to filter out the
> additional messages. Doing that is not a big deal, but I think it will
> keep manifesting in future tests added by Linux developers.
> 
> With this commit, we simply don't print the kernel assigned TCP ports
> on windows when done for "unix" sockets.
> 
> Signed-off-by: Gurucharan Shetty 

new_pstream() looks like it has two callers with similar code:
fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp, true);
if (fd < 0) {
return -fd;
}

return new_pstream(fd, &ss, pstreamp);
and
fd = inet_open_passive(SOCK_STREAM, suffix_new, -1, &ss, dscp, false);
if (fd < 0) {
return -fd;
}

error = new_pstream(fd, &ss, pstreamp);
if (error) {
goto exit;
}

Can we move the inet_open_passive() call into new_pstream() and add a
kernel_print_port parameter to new_pstream()?

Acked-by: Ben Pfaff 
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 5/5] socket-util: Log the kernel assigned port number when asked.

2014-05-19 Thread Gurucharan Shetty
So far, we log the kernel assigned port number when the port number is
not specified. On Windows, this happens multiple times because "unix"
sockets are implemented internally via TCP ports. This means that many tests,
specially the ovs-ofctl monitor tests, need to filter out the
additional messages. Doing that is not a big deal, but I think it will
keep manifesting in future tests added by Linux developers.

With this commit, we simply don't print the kernel assigned TCP ports
on windows when done for "unix" sockets.

Signed-off-by: Gurucharan Shetty 
---
 lib/socket-util.c   |   10 +++---
 lib/socket-util.h   |3 ++-
 lib/stream-ssl.c|2 +-
 lib/stream-tcp.c|   41 -
 tests/ofproto-dpif.at   |8 
 tests/ofproto-macros.at |4 ++--
 tests/ovsdb-idl.at  |4 ++--
 tests/ovsdb-server.at   |   12 ++--
 tests/test-netflow.c|2 +-
 tests/test-sflow.c  |2 +-
 10 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/lib/socket-util.c b/lib/socket-util.c
index aa0c719..012e4cd 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -871,10 +871,14 @@ inet_parse_passive(const char *target_, int default_port,
  *
  * 'dscp' becomes the DSCP bits in the IP headers for the new connection.  It
  * should be in the range [0, 63] and will automatically be shifted to the
- * appropriately place in the IP tos field. */
+ * appropriately place in the IP tos field.
+ *
+ * If 'kernel_print_port' is true and the port is dynamically assigned by
+ * the kernel, print the chosen port. */
 int
 inet_open_passive(int style, const char *target, int default_port,
-  struct sockaddr_storage *ssp, uint8_t dscp)
+  struct sockaddr_storage *ssp, uint8_t dscp,
+  bool kernel_print_port)
 {
 bool kernel_chooses_port;
 struct sockaddr_storage ss;
@@ -935,7 +939,7 @@ inet_open_passive(int style, const char *target, int 
default_port,
 VLOG_ERR("%s: getsockname: %s", target, sock_strerror(error));
 goto error;
 }
-if (kernel_chooses_port) {
+if (kernel_chooses_port && kernel_print_port) {
 VLOG_INFO("%s: listening on port %"PRIu16,
   target, ss_get_port(&ss));
 }
diff --git a/lib/socket-util.h b/lib/socket-util.h
index 2acc974..a0132d9 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -57,7 +57,8 @@ int inet_open_active(int style, const char *target, uint16_t 
default_port,
 bool inet_parse_passive(const char *target, int default_port,
 struct sockaddr_storage *ssp);
 int inet_open_passive(int style, const char *target, int default_port,
-  struct sockaddr_storage *ssp, uint8_t dscp);
+  struct sockaddr_storage *ssp, uint8_t dscp,
+  bool kernel_print_port);
 
 int read_fully(int fd, void *, size_t, size_t *bytes_read);
 int write_fully(int fd, const void *, size_t, size_t *bytes_written);
diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index 7a0d218..a130aec 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -820,7 +820,7 @@ pssl_open(const char *name OVS_UNUSED, char *suffix, struct 
pstream **pstreamp,
 return retval;
 }
 
-fd = inet_open_passive(SOCK_STREAM, suffix, OFP_OLD_PORT, &ss, dscp);
+fd = inet_open_passive(SOCK_STREAM, suffix, OFP_OLD_PORT, &ss, dscp, true);
 if (fd < 0) {
 return -fd;
 }
diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c
index 74db2f1..60707f3 100644
--- a/lib/stream-tcp.c
+++ b/lib/stream-tcp.c
@@ -154,24 +154,16 @@ static int ptcp_accept(int fd, const struct 
sockaddr_storage *,
size_t, struct stream **streamp);
 
 static int
-ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
-  uint8_t dscp)
+new_pstream(int fd, struct sockaddr_storage *ss, struct pstream **pstreamp)
 {
 char bound_name[SS_NTOP_BUFSIZE + 16];
 char addrbuf[SS_NTOP_BUFSIZE];
-struct sockaddr_storage ss;
-uint16_t port;
 int error;
-int fd;
-
-fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp);
-if (fd < 0) {
-return -fd;
-}
+uint16_t port;
 
-port = ss_get_port(&ss);
+port = ss_get_port(ss);
 snprintf(bound_name, sizeof bound_name, "ptcp:%"PRIu16":%s",
- port, ss_format_address(&ss, addrbuf, sizeof addrbuf));
+ port, ss_format_address(ss, addrbuf, sizeof addrbuf));
 
 error = new_fd_pstream(bound_name, fd, ptcp_accept, set_dscp, NULL,
pstreamp);
@@ -182,6 +174,21 @@ ptcp_open(const char *name OVS_UNUSED, char *suffix, 
struct pstream **pstreamp,
 }
 
 static int
+ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
+  uint8_t dscp)
+{
+struct sockaddr_storage ss;
+int fd;
+
+fd = inet_open_passive(SOCK_STREAM, suffix,