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 <gshe...@nicira.com> --- 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, -1, &ss, dscp, true); + if (fd < 0) { + return -fd; + } + + return new_pstream(fd, &ss, pstreamp); +} + +static int ptcp_accept(int fd, const struct sockaddr_storage *ss, size_t ss_len OVS_UNUSED, struct stream **streamp) { @@ -213,9 +220,17 @@ pwindows_open(const char *name OVS_UNUSED, char *suffix, char *suffix_new, *path; FILE *file; struct pstream *listener; + struct sockaddr_storage ss; + int fd; suffix_new = xstrdup("0:127.0.0.1"); - error = ptcp_open(name, suffix_new, pstreamp, dscp); + + 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; } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index caf00f3..3d29d6a 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -3066,7 +3066,7 @@ m4_define([CHECK_SFLOW_SAMPLING_PACKET], ON_EXIT([kill `cat test-sflow.pid`]) AT_CHECK([ovstest test-sflow --log-file --detach --no-chdir --pidfile 0:$1 > sflow.log], [0], [], [ignore]) AT_CAPTURE_FILE([sflow.log]) - SFLOW_PORT=`parse_listening_port test-sflow.log` + SFLOW_PORT=`parse_listening_port < test-sflow.log` ovs-appctl time/stop ADD_OF_PORTS([br0], 1, 2) @@ -3373,7 +3373,7 @@ m4_define([CHECK_NETFLOW_EXPIRATION], ON_EXIT([kill `cat test-netflow.pid`]) AT_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore]) AT_CAPTURE_FILE([netflow.log]) - NETFLOW_PORT=`parse_listening_port test-netflow.log` + NETFLOW_PORT=`parse_listening_port < test-netflow.log` ovs-vsctl \ set Bridge br0 netflow=@nf -- \ @@ -3420,7 +3420,7 @@ m4_define([CHECK_NETFLOW_ACTIVE_EXPIRATION], ON_EXIT([kill `cat test-netflow.pid`]) AT_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore]) AT_CAPTURE_FILE([netflow.log]) - NETFLOW_PORT=`parse_listening_port test-netflow.log` + NETFLOW_PORT=`parse_listening_port < test-netflow.log` ovs-vsctl \ set Bridge br0 netflow=@nf -- \ @@ -4036,7 +4036,7 @@ m4_define([CHECK_MEGAFLOW_NETFLOW], ON_EXIT([kill `cat test-netflow.pid`]) AT_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore]) AT_CAPTURE_FILE([netflow.log]) - NETFLOW_PORT=`parse_listening_port test-netflow.log` + NETFLOW_PORT=`parse_listening_port < test-netflow.log` ovs-vsctl \ set Bridge br0 netflow=@nf -- \ --id=@nf create NetFlow targets=\"$1:$NETFLOW_PORT\" \ diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index 4b16907..b4b6dab 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -27,9 +27,9 @@ s/ hard_age=[0-9]*,// # # OVS_LOGDIR=`pwd`; export OVS_LOGDIR # ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ... -# TCP_PORT=`parse_listening_port ovsdb-server.log` +# TCP_PORT=`parse_listening_port < ovsdb-server.log` parse_listening_port () { - sed -n 's/.*0:.*: listening on port \([0-9]*\)$/\1/p' "$1" | head -1 + sed -n 's/.*0:.*: listening on port \([0-9]*\)$/\1/p' }] m4_divert_pop([PREPARE_TESTS]) diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index d656ed4..89752f0 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -61,7 +61,7 @@ m4_define([OVSDB_CHECK_IDL_TCP_PY], AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --remote=ptcp:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - TCP_PORT=`parse_listening_port ovsdb-server.log` + TCP_PORT=`parse_listening_port < ovsdb-server.log` m4_if([$2], [], [], [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore], [kill `cat pid`])]) @@ -82,7 +82,7 @@ m4_define([OVSDB_CHECK_IDL_TCP6_PY], AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - TCP_PORT=`parse_listening_port ovsdb-server.log` + TCP_PORT=`parse_listening_port < ovsdb-server.log` echo "TCP_PORT=$TCP_PORT" m4_if([$2], [], [], diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index 18dc7e0..08c56ca 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -510,7 +510,7 @@ AT_CHECK( --ca-cert=db:mydb,SSL,ca_cert \ --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) -SSL_PORT=`parse_listening_port ovsdb-server.log` +SSL_PORT=`parse_listening_port < ovsdb-server.log` AT_CHECK( [[ovsdb-client \ --private-key=$PKIDIR/testpki-privkey.pem \ @@ -778,7 +778,7 @@ m4_define([OVSDB_CHECK_EXECUTION], PKIDIR=$abs_top_builddir/tests AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - SSL_PORT=`parse_listening_port ovsdb-server.log` + SSL_PORT=`parse_listening_port < ovsdb-server.log` m4_foreach([txn], [$3], [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:127.0.0.1:$SSL_PORT 'txn'], [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`]) @@ -817,7 +817,7 @@ m4_define([OVSDB_CHECK_EXECUTION], PKIDIR=$abs_top_builddir/tests AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --private-key=$PKIDIR/testpki-privkey2.pem --certificate=$PKIDIR/testpki-cert2.pem --ca-cert=$PKIDIR/testpki-cacert.pem --remote=pssl:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - SSL_PORT=`parse_listening_port ovsdb-server.log` + SSL_PORT=`parse_listening_port < ovsdb-server.log` m4_foreach([txn], [$3], [AT_CHECK([ovsdb-client --private-key=$PKIDIR/testpki-privkey.pem --certificate=$PKIDIR/testpki-cert.pem --ca-cert=$PKIDIR/testpki-cacert.pem transact ssl:[[::1]]:$SSL_PORT 'txn'], [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`]) @@ -838,7 +838,7 @@ ordinal_schema > schema AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore]) OVS_LOGDIR=`pwd`; export OVS_LOGDIR AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --unixctl="`pwd`"/unixctl --remote=ptcp:0:127.0.0.1 db], [0], [ignore], [ignore]) -TCP_PORT=`parse_listening_port ovsdb-server.log` +TCP_PORT=`parse_listening_port < ovsdb-server.log` AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3 ]) OVSDB_SERVER_SHUTDOWN @@ -867,7 +867,7 @@ m4_define([OVSDB_CHECK_EXECUTION], PKIDIR=$abs_top_builddir/tests AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - TCP_PORT=`parse_listening_port ovsdb-server.log` + TCP_PORT=`parse_listening_port < ovsdb-server.log` m4_foreach([txn], [$3], [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`]) @@ -905,7 +905,7 @@ m4_define([OVSDB_CHECK_EXECUTION], PKIDIR=$abs_top_builddir/tests AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) AT_CHECK([ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid --remote=ptcp:0:[[::1]] --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) - TCP_PORT=`parse_listening_port ovsdb-server.log` + TCP_PORT=`parse_listening_port < ovsdb-server.log` m4_foreach([txn], [$3], [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`]) diff --git a/tests/test-netflow.c b/tests/test-netflow.c index a727f53..1243f83 100644 --- a/tests/test-netflow.c +++ b/tests/test-netflow.c @@ -189,7 +189,7 @@ test_netflow_main(int argc, char *argv[]) } target = argv[optind]; - sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0); + sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0, true); if (sock < 0) { ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock)); } diff --git a/tests/test-sflow.c b/tests/test-sflow.c index a028ac7..fa8b5c5 100644 --- a/tests/test-sflow.c +++ b/tests/test-sflow.c @@ -507,7 +507,7 @@ test_sflow_main(int argc, char *argv[]) } target = argv[optind]; - sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0); + sock = inet_open_passive(SOCK_DGRAM, target, 0, NULL, 0, true); if (sock < 0) { ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock)); } -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev