From b82812260dcb2f1366b55dc06eecd49966a5a1a6 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 8 Feb 2016 14:13:43 -0500 Subject: [PATCH] move advertised_address out of intf_spec into local_intf supports aliasing a local interface multiple times with the same local address for different advertised addresses closes #216 Change-Id: I6f98d1a17290b0bb1831e48ad89fc61d8b2d7914 --- daemon/call.c | 4 ++-- daemon/ice.c | 10 +++++----- daemon/main.c | 4 ++-- daemon/media_socket.c | 30 ++++++++++++++++-------------- daemon/media_socket.h | 11 ++++++----- daemon/sdp.c | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index c90a53696..36dac17d6 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2176,7 +2176,7 @@ int call_stream_address46(char *o, struct packet_stream *ps, enum stream_address else ifa = get_any_interface_address(ps->media->logical_intf, ps->media->desired_family); } - ifa_addr = &ifa->spec->address; + ifa_addr = &ifa->spec->local_address; sink = packet_stream_sink(ps); @@ -2187,7 +2187,7 @@ int call_stream_address46(char *o, struct packet_stream *ps, enum stream_address && !is_trickle_ice_address(&sink->advertised_endpoint)) l += sprintf(o + l, "%s", ifa_addr->addr.family->unspec_string); else - l += sprintf(o + l, "%s", sockaddr_print_buf(&ifa_addr->advertised)); + l += sprintf(o + l, "%s", sockaddr_print_buf(&ifa->advertised_address)); *len = l; return ifa_addr->addr.family->af; diff --git a/daemon/ice.c b/daemon/ice.c index fbf50c544..c822b4782 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -28,7 +28,7 @@ #define PAIR_FORMAT STR_FORMAT":"STR_FORMAT":%lu" #define PAIR_FMT(p) \ - STR_FMT(&(p)->local_intf->spec->ice_foundation), \ + STR_FMT(&(p)->local_intf->ice_foundation), \ STR_FMT(&(p)->remote_candidate->foundation), \ (p)->remote_candidate->component_id @@ -646,7 +646,7 @@ static void __do_ice_check(struct ice_candidate_pair *pair) { ilog(LOG_DEBUG, "Sending %sICE/STUN request for candidate pair "PAIR_FORMAT" from %s to %s", PAIR_ISSET(pair, TO_USE) ? "nominating " : "", - PAIR_FMT(pair), sockaddr_print_buf(&pair->local_intf->spec->address.addr), + PAIR_FMT(pair), sockaddr_print_buf(&pair->local_intf->spec->local_address.addr), endpoint_print_buf(&pair->remote_candidate->endpoint)); stun_binding_request(&pair->remote_candidate->endpoint, transact, &ag->pwd[0], ag->ufrag, @@ -868,7 +868,7 @@ static struct ice_candidate_pair *__learned_candidate(struct ice_agent *ag, stru cand = g_slice_alloc0(sizeof(*cand)); cand->component_id = ps->component; - cand->transport = sfd->local_intf->spec->address.type; // XXX add socket type into socket_t? + cand->transport = sfd->local_intf->spec->local_address.type; // XXX add socket type into socket_t? cand->priority = priority; cand->endpoint = *src; cand->type = ICT_PRFLX; @@ -1050,7 +1050,7 @@ static int __check_valid(struct ice_agent *ag) { ps->selected_sfd = sfd; if (ps->component == 1) ilog(LOG_INFO, "ICE negotiated: local interface %s", - sockaddr_print_buf(&pair->local_intf->spec->address.addr)); + sockaddr_print_buf(&pair->local_intf->spec->local_address.addr)); } } @@ -1210,7 +1210,7 @@ int ice_response(struct stream_fd *sfd, const endpoint_t *src, ilog(LOG_DEBUG, "Received ICE/STUN response code %u for candidate pair "PAIR_FORMAT" from %s to %s", attrs->error_code, PAIR_FMT(pair), endpoint_print_buf(&pair->remote_candidate->endpoint), - sockaddr_print_buf(&ifa->spec->address.addr)); + sockaddr_print_buf(&ifa->spec->local_address.addr)); /* verify endpoints */ err = "ICE/STUN response received, but source address didn't match remote candidate address"; diff --git a/daemon/main.c b/daemon/main.c index dd9641afe..6684af0d1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -212,8 +212,8 @@ static struct intf_config *if_addr_parse(char *s) { ifa = g_slice_alloc0(sizeof(*ifa)); ifa->name = name; - ifa->address.addr = addr; - ifa->address.advertised = adv; + ifa->local_address.addr = addr; + ifa->advertised_address = adv; ifa->port_min = port_min; ifa->port_max = port_max; diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 2a248eaa7..d4dc7db64 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -239,13 +239,13 @@ static int has_free_ports_loc(struct local_intf *loc, unsigned int num_ports) { if (num_ports > loc->spec->port_pool.free_ports) { ilog(LOG_ERR, "Didn't found %d ports available for %.*s/%s", num_ports, loc->logical->name.len, loc->logical->name.s, - sockaddr_print_buf(&loc->spec->address.addr)); + sockaddr_print_buf(&loc->spec->local_address.addr)); return 0; } __C_DBG("Found %d ports available for %.*s/%s from total of %d free ports", num_ports, loc->logical->name.len, loc->logical->name.s, - sockaddr_print_buf(&loc->spec->address.addr), + sockaddr_print_buf(&loc->spec->local_address.addr), loc->spec->port_pool.free_ports); return 1; @@ -437,28 +437,29 @@ static void __interface_append(struct intf_config *ifa, sockfamily_t *fam) { lif->preferred_family = fam; lif->addr_hash = g_hash_table_new(__addr_type_hash, __addr_type_eq); g_hash_table_insert(__logical_intf_name_family_hash, lif, lif); - if (ifa->address.addr.family == fam) { + if (ifa->local_address.addr.family == fam) { q = __interface_list_for_family(fam); g_queue_push_tail(q, lif); } } - spec = g_hash_table_lookup(__intf_spec_addr_type_hash, &ifa->address); + spec = g_hash_table_lookup(__intf_spec_addr_type_hash, &ifa->local_address); if (!spec) { spec = g_slice_alloc0(sizeof(*spec)); - spec->address = ifa->address; - ice_foundation(&spec->ice_foundation); + spec->local_address = ifa->local_address; spec->port_pool.min = ifa->port_min; spec->port_pool.max = ifa->port_max; spec->port_pool.free_ports = spec->port_pool.max - spec->port_pool.min + 1; - g_hash_table_insert(__intf_spec_addr_type_hash, &spec->address, spec); + g_hash_table_insert(__intf_spec_addr_type_hash, &spec->local_address, spec); } ifc = uid_slice_alloc(ifc, &lif->list); + ice_foundation(&ifc->ice_foundation); + ifc->advertised_address = ifa->advertised_address; ifc->spec = spec; ifc->logical = lif; - g_hash_table_insert(lif->addr_hash, (void *) &ifc->spec->address, ifc); + g_hash_table_insert(lif->addr_hash, (void *) &ifc->spec->local_address, ifc); } void interfaces_init(GQueue *interfaces) { @@ -477,7 +478,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->address.addr.family); + __interface_append(ifa, ifa->local_address.addr.family); } /* then append to each other as lower-preference alternatives */ @@ -485,7 +486,7 @@ void interfaces_init(GQueue *interfaces) { fam = get_socket_family_enum(i); for (l = interfaces->head; l; l = l->next) { ifa = l->data; - if (ifa->address.addr.family == fam) + if (ifa->local_address.addr.family == fam) continue; __interface_append(ifa, fam); } @@ -534,7 +535,7 @@ struct local_intf *get_any_interface_address(const struct logical_intf *lif, soc /* XXX family specific? unify? */ static int get_port6(socket_t *r, unsigned int port, struct intf_spec *spec) { - if (open_socket(r, SOCK_DGRAM, port, &spec->address.addr)) + if (open_socket(r, SOCK_DGRAM, port, &spec->local_address.addr)) return -1; return 0; @@ -563,7 +564,8 @@ static int get_port(socket_t *r, unsigned int port, struct intf_spec *spec) { } g_atomic_int_dec_and_test(&pp->free_ports); - __C_DBG("%d free ports remaining on interface %s", pp->free_ports, sockaddr_print_buf(&spec->address.addr)); + __C_DBG("%d free ports remaining on interface %s", pp->free_ports, + sockaddr_print_buf(&spec->local_address.addr)); return 0; } @@ -662,12 +664,12 @@ release_restart: g_atomic_int_set(&pp->last_used, port); __C_DBG("Opened ports %u.. on interface %s for media relay", - ((socket_t *) out->head->data)->local.port, sockaddr_print_buf(&spec->address.addr)); + ((socket_t *) out->head->data)->local.port, sockaddr_print_buf(&spec->local_address.addr)); return 0; fail: ilog(LOG_ERR, "Failed to get %u consecutive ports on interface %s for media relay", - num_ports, sockaddr_print_buf(&spec->address.addr)); + num_ports, sockaddr_print_buf(&spec->local_address.addr)); return -1; } diff --git a/daemon/media_socket.h b/daemon/media_socket.h index 04e96682b..44277dfca 100644 --- a/daemon/media_socket.h +++ b/daemon/media_socket.h @@ -33,22 +33,23 @@ struct port_pool { struct intf_address { socktype_t *type; sockaddr_t addr; - sockaddr_t advertised; }; struct intf_config { str name; - struct intf_address address; + struct intf_address local_address; + sockaddr_t advertised_address; unsigned int port_min, port_max; }; struct intf_spec { - struct intf_address address; - str ice_foundation; + struct intf_address local_address; struct port_pool port_pool; }; struct local_intf { struct intf_spec *spec; + sockaddr_t advertised_address; unsigned int unique_id; /* starting with 0 - serves as preference */ const struct logical_intf *logical; + str ice_foundation; }; struct intf_list { const struct local_intf *local_intf; @@ -88,7 +89,7 @@ void free_intf_list(struct intf_list *il); void free_socket_intf_list(struct intf_list *il); INLINE int open_intf_socket(socket_t *r, unsigned int port, const struct local_intf *lif) { - return open_socket(r, SOCK_DGRAM, port, &lif->spec->address.addr); + return open_socket(r, SOCK_DGRAM, port, &lif->spec->local_address.addr); } void kernelize(struct packet_stream *); diff --git a/daemon/sdp.c b/daemon/sdp.c index dc11e80ef..454fac211 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1699,7 +1699,7 @@ static void insert_candidate(struct sdp_chopper *chop, struct stream_fd *sfd, priority = ice_priority_pref(type_pref, local_pref, ps->component); chopper_append_c(chop, "a=candidate:"); - chopper_append_str(chop, &ifa->spec->ice_foundation); + chopper_append_str(chop, &ifa->ice_foundation); chopper_append_printf(chop, " %u UDP %lu ", ps->component, priority); insert_ice_address(chop, sfd); chopper_append_c(chop, " typ ");