From 1e2d3e4d3b25c5691a7a0c5c791d53841a26eed2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 22 Feb 2022 10:06:21 -0500 Subject: [PATCH] TT#14008 return logical interface matching the address family Change-Id: I724c4244265b2c061d20f8faea6c249f169943d3 (cherry picked from commit 9b6c54542686fac394abf4236bb79ec7f82db399) --- daemon/media_socket.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 9359313c8..68a40063d 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -506,10 +506,10 @@ struct logical_intf *get_logical_interface(const str *name, sockfamily_t *fam, i if (G_UNLIKELY(!name || !name->s)) { // trivial case: no interface given. just pick one suitable for the address family. // always used for legacy TCP and UDP protocols. - GQueue *q; + GQueue *q = NULL; if (fam) q = __interface_list_for_family(fam); - else { + if (!q) { for (int i = 0; i < __SF_LAST; i++) { q = &__preferred_lists_for_family[i]; if (q->length) @@ -540,6 +540,15 @@ got_some: key.preferred_family = fam; struct intf_rr *rr = g_hash_table_lookup(__logical_intf_name_family_rr_hash, &key); + if (!rr) { + // try other socket families + for (int i = 0; i < __SF_LAST; i++) { + key.preferred_family = get_socket_family_enum(i); + rr = g_hash_table_lookup(__logical_intf_name_family_rr_hash, &key); + if (rr) + break; + } + } if (!rr) return name ? __get_logical_interface(name, fam) : log; if (rr->singular) { @@ -648,7 +657,7 @@ static GQueue *__interface_list_for_family(sockfamily_t *fam) { return &__preferred_lists_for_family[fam->idx]; } // called during single-threaded startup only -static void __interface_append(struct intf_config *ifa, sockfamily_t *fam) { +static void __interface_append(struct intf_config *ifa, sockfamily_t *fam, bool create) { struct logical_intf *lif; GQueue *q; struct local_intf *ifc; @@ -657,6 +666,9 @@ static void __interface_append(struct intf_config *ifa, sockfamily_t *fam) { lif = __get_logical_interface(&ifa->name, fam); if (!lif) { + if (!create) + return; + lif = g_slice_alloc0(sizeof(*lif)); g_queue_init(&lif->list); lif->name = ifa->name; @@ -715,7 +727,7 @@ void interfaces_init(GQueue *interfaces) { /* build primary lists first */ for (l = interfaces->head; l; l = l->next) { ifa = l->data; - __interface_append(ifa, ifa->local_address.addr.family); + __interface_append(ifa, ifa->local_address.addr.family, true); } /* then append to each other as lower-preference alternatives */ @@ -725,7 +737,7 @@ void interfaces_init(GQueue *interfaces) { ifa = l->data; if (ifa->local_address.addr.family == fam) continue; - __interface_append(ifa, fam); + __interface_append(ifa, fam, false); } } }