aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorliuyacan <liuyacan@corp.netease.com>2021-04-30 08:57:37 +0000
committerFlorin Coras <florin.coras@gmail.com>2021-05-03 15:13:32 +0000
commit694046cf8eef9c8ec1313ebe8327bfebc2a11522 (patch)
treed844a9be749dfb6633918f8c8e3f46ff7e0819cf /src
parent94b80770ffd35c20beb303bc2a6e81b2c6163ba6 (diff)
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 <liuyacan@corp.netease.com> Change-Id: I86f36475c16e217c6c5293a62c4fb5c9477a191e
Diffstat (limited to 'src')
-rw-r--r--src/vnet/session/application.c26
1 files changed, 26 insertions, 0 deletions
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;
}