2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 06:45:17 +00:00

socket-util: Log the kernel assigned port number when asked.

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 <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Gurucharan Shetty
2014-05-19 11:58:14 -07:00
parent 5e3ee29da1
commit b52ecd9610
10 changed files with 40 additions and 26 deletions

View File

@@ -552,10 +552,14 @@ inet_parse_passive(const char *target_, int default_port,
* *
* 'dscp' becomes the DSCP bits in the IP headers for the new connection. It * '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 * 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 int
inet_open_passive(int style, const char *target, int default_port, 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; bool kernel_chooses_port;
struct sockaddr_storage ss; struct sockaddr_storage ss;
@@ -616,7 +620,7 @@ inet_open_passive(int style, const char *target, int default_port,
VLOG_ERR("%s: getsockname: %s", target, sock_strerror(error)); VLOG_ERR("%s: getsockname: %s", target, sock_strerror(error));
goto error; goto error;
} }
if (kernel_chooses_port) { if (kernel_chooses_port && kernel_print_port) {
VLOG_INFO("%s: listening on port %"PRIu16, VLOG_INFO("%s: listening on port %"PRIu16,
target, ss_get_port(&ss)); target, ss_get_port(&ss));
} }

View File

@@ -49,7 +49,8 @@ int inet_open_active(int style, const char *target, uint16_t default_port,
bool inet_parse_passive(const char *target, int default_port, bool inet_parse_passive(const char *target, int default_port,
struct sockaddr_storage *ssp); struct sockaddr_storage *ssp);
int inet_open_passive(int style, const char *target, int default_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);
int read_fully(int fd, void *, size_t, size_t *bytes_read); 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); int write_fully(int fd, const void *, size_t, size_t *bytes_written);

View File

@@ -820,7 +820,7 @@ pssl_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
return retval; 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) { if (fd < 0) {
return -fd; return -fd;
} }

View File

@@ -154,17 +154,18 @@ static int ptcp_accept(int fd, const struct sockaddr_storage *,
size_t, struct stream **streamp); size_t, struct stream **streamp);
static int static int
ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp, new_pstream(char *suffix, struct pstream **pstreamp, int dscp,
uint8_t dscp) bool kernel_print_port)
{ {
char bound_name[SS_NTOP_BUFSIZE + 16]; char bound_name[SS_NTOP_BUFSIZE + 16];
char addrbuf[SS_NTOP_BUFSIZE]; char addrbuf[SS_NTOP_BUFSIZE];
struct sockaddr_storage ss; struct sockaddr_storage ss;
uint16_t port;
int error; int error;
uint16_t port;
int fd; int fd;
fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp); fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp,
kernel_print_port);
if (fd < 0) { if (fd < 0) {
return -fd; return -fd;
} }
@@ -181,6 +182,13 @@ ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
return error; return error;
} }
static int
ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
uint8_t dscp)
{
return new_pstream(suffix, pstreamp, dscp, true);
}
static int static int
ptcp_accept(int fd, const struct sockaddr_storage *ss, ptcp_accept(int fd, const struct sockaddr_storage *ss,
size_t ss_len OVS_UNUSED, struct stream **streamp) size_t ss_len OVS_UNUSED, struct stream **streamp)
@@ -215,7 +223,8 @@ pwindows_open(const char *name OVS_UNUSED, char *suffix,
struct pstream *listener; struct pstream *listener;
suffix_new = xstrdup("0:127.0.0.1"); suffix_new = xstrdup("0:127.0.0.1");
error = ptcp_open(name, suffix_new, pstreamp, dscp);
error = new_pstream(suffix_new, pstreamp, dscp, false);
if (error) { if (error) {
goto exit; goto exit;
} }

View File

@@ -3056,7 +3056,7 @@ m4_define([CHECK_SFLOW_SAMPLING_PACKET],
ON_EXIT([kill `cat test-sflow.pid`]) 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_CHECK([ovstest test-sflow --log-file --detach --no-chdir --pidfile 0:$1 > sflow.log], [0], [], [ignore])
AT_CAPTURE_FILE([sflow.log]) 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 ovs-appctl time/stop
ADD_OF_PORTS([br0], 1, 2) ADD_OF_PORTS([br0], 1, 2)
@@ -3363,7 +3363,7 @@ m4_define([CHECK_NETFLOW_EXPIRATION],
ON_EXIT([kill `cat test-netflow.pid`]) 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_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore])
AT_CAPTURE_FILE([netflow.log]) AT_CAPTURE_FILE([netflow.log])
NETFLOW_PORT=`parse_listening_port test-netflow.log` NETFLOW_PORT=`parse_listening_port < test-netflow.log`
ovs-vsctl \ ovs-vsctl \
set Bridge br0 netflow=@nf -- \ set Bridge br0 netflow=@nf -- \
@@ -3410,7 +3410,7 @@ m4_define([CHECK_NETFLOW_ACTIVE_EXPIRATION],
ON_EXIT([kill `cat test-netflow.pid`]) 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_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore])
AT_CAPTURE_FILE([netflow.log]) AT_CAPTURE_FILE([netflow.log])
NETFLOW_PORT=`parse_listening_port test-netflow.log` NETFLOW_PORT=`parse_listening_port < test-netflow.log`
ovs-vsctl \ ovs-vsctl \
set Bridge br0 netflow=@nf -- \ set Bridge br0 netflow=@nf -- \
@@ -4026,7 +4026,7 @@ m4_define([CHECK_MEGAFLOW_NETFLOW],
ON_EXIT([kill `cat test-netflow.pid`]) 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_CHECK([ovstest test-netflow --log-file --detach --no-chdir --pidfile 0:$1 > netflow.log], [0], [], [ignore])
AT_CAPTURE_FILE([netflow.log]) AT_CAPTURE_FILE([netflow.log])
NETFLOW_PORT=`parse_listening_port test-netflow.log` NETFLOW_PORT=`parse_listening_port < test-netflow.log`
ovs-vsctl \ ovs-vsctl \
set Bridge br0 netflow=@nf -- \ set Bridge br0 netflow=@nf -- \
--id=@nf create NetFlow targets=\"$1:$NETFLOW_PORT\" \ --id=@nf create NetFlow targets=\"$1:$NETFLOW_PORT\" \

View File

@@ -27,9 +27,9 @@ s/ hard_age=[0-9]*,//
# #
# OVS_LOGDIR=`pwd`; export OVS_LOGDIR # OVS_LOGDIR=`pwd`; export OVS_LOGDIR
# ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ... # 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 () { 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]) m4_divert_pop([PREPARE_TESTS])

View File

@@ -61,7 +61,7 @@ m4_define([OVSDB_CHECK_IDL_TCP_PY],
AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
[0], [stdout], [ignore]) [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]) 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], [], [], m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore], [kill `cat pid`])]) [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], AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
[0], [stdout], [ignore]) [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]) 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" echo "TCP_PORT=$TCP_PORT"
m4_if([$2], [], [], m4_if([$2], [], [],

View File

@@ -510,7 +510,7 @@ AT_CHECK(
--ca-cert=db:mydb,SSL,ca_cert \ --ca-cert=db:mydb,SSL,ca_cert \
--remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db], --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
[0], [ignore], [ignore]) [0], [ignore], [ignore])
SSL_PORT=`parse_listening_port ovsdb-server.log` SSL_PORT=`parse_listening_port < ovsdb-server.log`
AT_CHECK( AT_CHECK(
[[ovsdb-client \ [[ovsdb-client \
--private-key=$PKIDIR/testpki-privkey.pem \ --private-key=$PKIDIR/testpki-privkey.pem \
@@ -778,7 +778,7 @@ m4_define([OVSDB_CHECK_EXECUTION],
PKIDIR=$abs_top_builddir/tests PKIDIR=$abs_top_builddir/tests
AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) 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]) 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], 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], [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`]) [test ! -e pid || kill `cat pid`])
@@ -817,7 +817,7 @@ m4_define([OVSDB_CHECK_EXECUTION],
PKIDIR=$abs_top_builddir/tests PKIDIR=$abs_top_builddir/tests
AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) 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]) 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], 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], [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`]) [test ! -e pid || kill `cat pid`])
@@ -838,7 +838,7 @@ ordinal_schema > schema
AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore]) AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
OVS_LOGDIR=`pwd`; export OVS_LOGDIR 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]) 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 AT_CHECK([ovsdb-client get-schema-version tcp:127.0.0.1:$TCP_PORT ordinals], [0], [5.1.3
]) ])
OVSDB_SERVER_SHUTDOWN OVSDB_SERVER_SHUTDOWN
@@ -867,7 +867,7 @@ m4_define([OVSDB_CHECK_EXECUTION],
PKIDIR=$abs_top_builddir/tests PKIDIR=$abs_top_builddir/tests
AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) 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]) 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], m4_foreach([txn], [$3],
[AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore], [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT 'txn'], [0], [stdout], [ignore],
[test ! -e pid || kill `cat pid`]) [test ! -e pid || kill `cat pid`])
@@ -905,7 +905,7 @@ m4_define([OVSDB_CHECK_EXECUTION],
PKIDIR=$abs_top_builddir/tests PKIDIR=$abs_top_builddir/tests
AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore]) 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]) 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], m4_foreach([txn], [$3],
[AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore], [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT 'txn'], [0], [stdout], [ignore],
[test ! -e pid || kill `cat pid`]) [test ! -e pid || kill `cat pid`])

View File

@@ -189,7 +189,7 @@ test_netflow_main(int argc, char *argv[])
} }
target = argv[optind]; 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) { if (sock < 0) {
ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock)); ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock));
} }

View File

@@ -507,7 +507,7 @@ test_sflow_main(int argc, char *argv[])
} }
target = argv[optind]; 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) { if (sock < 0) {
ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock)); ovs_fatal(0, "%s: failed to open (%s)", argv[1], ovs_strerror(-sock));
} }