@@ -466,10 +466,7 @@ static int open_endpoint(const char *addr_str,
466466 return kr_error (ret );
467467}
468468
469- /** @internal Fetch a pointer to endpoint of given parameters (or NULL).
470- * Beware that there might be multiple matches, though that's not common.
471- * The matching isn't really precise in the sense that it might not find
472- * and endpoint that would *collide* the passed one. */
469+ /** Fetch a pointer to endpoint of given parameters or a colliding one (or NULL). */
473470static struct endpoint * endpoint_get (const char * addr_str ,
474471 const struct sockaddr * sa ,
475472 endpoint_flags_t flags )
@@ -483,12 +480,23 @@ static struct endpoint * endpoint_get(const char *addr_str,
483480 return NULL ;
484481 endpoint_array_t * ep_array = * val ;
485482
486- uint16_t port = kr_inaddr_port (sa );
487483 for (int i = 0 ; i < ep_array -> len ; ++ i ) {
488484 struct endpoint * ep = & ep_array -> at [i ];
489- if ((flags .xdp || ep -> port == port ) && endpoint_flags_eq (ep -> flags , flags )) {
485+ if (flags .xdp ) {
486+ /* `key` matched by interface name */
487+ kr_assert (ep_array -> len == 1 );
490488 return ep ;
491489 }
490+ if (kr_straddr_family (addr_str ) == AF_UNIX ) {
491+ /* `key` matched by path */
492+ kr_assert (ep_array -> len == 1 );
493+ return ep ;
494+ }
495+ /* else `key` already matched IP address + port,
496+ * so the only remaining distinction is UDP vs. TCP */
497+ kr_assert (ep_array -> len <= 2 );
498+ if (ep -> flags .sock_type == flags .sock_type )
499+ return ep ;
492500 }
493501 return NULL ;
494502}
0 commit comments