From: liuyacan Date: Fri, 30 Apr 2021 08:57:37 +0000 (+0000) Subject: session: lookup listener with iface address X-Git-Tag: v21.10-rc0~148 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=694046cf8eef9c8ec1313ebe8327bfebc2a11522;p=vpp.git session: lookup listener with iface address We add interface address to the global lookup table, so we should use it as the key when lookup listener. Otherwise, when multiple threads listen on 0.0.0.0 (local scope disable), duplicate listeners and sessions would be allocated but only one works. Type: fix Signed-off-by: liuyacan Change-Id: I86f36475c16e217c6c5293a62c4fb5c9477a191e --- diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c index 56a514192af..2f6bfa97892 100644 --- a/src/vnet/session/application.c +++ b/src/vnet/session/application.c @@ -101,6 +101,8 @@ app_listener_lookup (application_t * app, session_endpoint_cfg_t * sep_ext) session_endpoint_t *sep; session_handle_t handle; session_t *ls; + void *iface_ip; + ip46_address_t original_ip; sep = (session_endpoint_t *) sep_ext; if (application_has_local_scope (app) && session_endpoint_is_local (sep)) @@ -123,6 +125,30 @@ app_listener_lookup (application_t * app, session_endpoint_cfg_t * sep_ext) return app_listener_get_w_session ((session_t *) ls); } + /* + * When binds to "inaddr_any", we add zero address in the local lookup table + * and interface address in the global lookup table. If local scope disable, + * the latter is the only clue to find the listener. + */ + if (!application_has_local_scope (app) && + ip_is_zero (&sep_ext->ip, sep_ext->is_ip4) && + sep_ext->sw_if_index != ENDPOINT_INVALID_INDEX) + { + if ((iface_ip = ip_interface_get_first_ip (sep_ext->sw_if_index, + sep_ext->is_ip4))) + { + ip_copy (&original_ip, &sep_ext->ip, sep_ext->is_ip4); + ip_set (&sep_ext->ip, iface_ip, sep_ext->is_ip4); + handle = session_lookup_endpoint_listener (table_index, sep, 1); + ip_copy (&sep_ext->ip, &original_ip, sep_ext->is_ip4); + if (handle != SESSION_INVALID_HANDLE) + { + ls = listen_session_get_from_handle (handle); + return app_listener_get_w_session ((session_t *) ls); + } + } + } + return 0; }