diff options
-rw-r--r-- | lib/stream-unix.c | 15 | ||||
-rw-r--r-- | tests/ofproto-macros.at | 1 | ||||
-rw-r--r-- | tests/ofproto.at | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/lib/stream-unix.c b/lib/stream-unix.c index f8c5ad046..d265efb83 100644 --- a/lib/stream-unix.c +++ b/lib/stream-unix.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include "ovs-atomic.h" #include "packets.h" #include "openvswitch/poll-loop.h" #include "socket-util.h" @@ -112,9 +113,17 @@ punix_accept(int fd, const struct sockaddr_storage *ss, size_t ss_len, { const struct sockaddr_un *sun = (const struct sockaddr_un *) ss; int name_len = get_unix_name_len(sun, ss_len); - char *bound_name = (name_len > 0 - ? xasprintf("unix:%.*s", name_len, sun->sun_path) - : xstrdup("unix")); + char *bound_name; + + if (name_len > 0) { + bound_name = xasprintf("unix:%.*s", name_len, sun->sun_path); + } else { + /* When a Unix socket connects to us without first binding a name, we + * don't get any name for it. It's useful nevertheless to be able to + * distinguish separate sockets in log messages, so use a counter. */ + static atomic_count next_idx = ATOMIC_COUNT_INIT(0); + bound_name = xasprintf("unix#%u", atomic_count_inc(&next_idx)); + } return new_fd_stream(bound_name, fd, 0, AF_UNIX, streamp); } diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index 4fbb10070..16b4e6820 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -32,6 +32,7 @@ prt==1 { sub(/[ \t]*$/, ""); print $0 } vconn_sub() { sed ' s/tcp:127.0.0.1:[0-9][0-9]*:/unix:/ +s/unix#[0-9]*:/unix:/ ' } ] diff --git a/tests/ofproto.at b/tests/ofproto.at index 17ede5d4a..c19a3d10d 100644 --- a/tests/ofproto.at +++ b/tests/ofproto.at @@ -5219,7 +5219,7 @@ vconn|DBG|unix: sent (Success): NXST_FLOW reply: in_port=2,dl_src=00:66:77:88:99:aa actions=drop ]) -AT_CHECK([grep " flow_mods in the last " ovs-vswitchd.log | sed -e 's/^.*connmgr|INFO|//'], [0], [dnl +AT_CHECK([grep " flow_mods in the last " ovs-vswitchd.log | sed -e 's/^.*connmgr|INFO|//' | vconn_sub], [0], [dnl br0<->unix: 1 flow_mods in the last 0 s (1 deletes) br0<->unix: 9 flow_mods in the last 0 s (7 adds, 2 deletes) br0<->unix: 2 flow_mods in the last 0 s (2 modifications) |