diff --git a/daemon/call.c b/daemon/call.c index 32c358b7d..3262e7ab3 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -863,7 +863,7 @@ static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigne if (num_ports > 16) return NULL; - if (get_consecutive_ports(&intf_sockets, num_ports, want_interfaces, media)) + if (!get_consecutive_ports(&intf_sockets, num_ports, want_interfaces, media)) return NULL; __C_DBG("allocating stream_fds for %u ports", num_ports); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 03b00ac02..694ebc41f 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1149,7 +1149,7 @@ void append_thread_lpr_to_glob_lpr(void) { * @param spec, interface specifications * @param out, a list of sockets for this particular session (not a global list) */ -int __get_consecutive_ports(socket_port_q *out, unsigned int num_ports, unsigned int wanted_start_port, +bool __get_consecutive_ports(socket_port_q *out, unsigned int num_ports, unsigned int wanted_start_port, struct intf_spec *spec, const str *label) { unsigned int allocation_attempts = 0, available_ports = 0, additional_port = 0, port = 0; @@ -1327,16 +1327,17 @@ release_restart: /* success */ ilog(LOG_DEBUG, "Opened a socket on port '%u' (on interface '%s') for a media relay", ((socket_t *) out->head->data)->local.port, sockaddr_print_buf(&spec->local_address.addr)); - return 0; + return true; fail: ilog(LOG_ERR, "Failed to get %u consecutive ports on interface %s for media relay (last error: %s)", num_ports, sockaddr_print_buf(&spec->local_address.addr), strerror(errno)); - return -1; + return false; } /* puts a list of "struct intf_list" into "out", containing socket_t list */ -int get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsigned int num_intfs, struct call_media *media) +bool get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsigned int num_intfs, + struct call_media *media) { struct socket_intf_list *il; struct local_intf *loc; @@ -1363,7 +1364,7 @@ int get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsig il = g_slice_alloc0(sizeof(*il)); il->local_intf = loc; t_queue_push_tail(out, il); - if (G_LIKELY(!__get_consecutive_ports(&il->list, num_ports, 0, loc->spec, label))) { + if (G_LIKELY(__get_consecutive_ports(&il->list, num_ports, 0, loc->spec, label))) { // success - found available ports on local interfaces, so far continue; } else { @@ -1372,7 +1373,7 @@ int get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsig } } - return 0; + return true; error_ports: ilog(LOG_ERR, "Failed to get %d consecutive ports on all locals of logical '"STR_FORMAT"'", @@ -1383,7 +1384,7 @@ error_ports: free_socket_intf_list(il); } - return -1; + return false; } void free_socket_intf_list(struct socket_intf_list *il) { diff --git a/daemon/redis.c b/daemon/redis.c index 5c10dfba0..16f0f85c0 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1418,7 +1418,7 @@ static int redis_sfds(call_t *c, struct redis_list *sfds) { if (fd != -1) { err = "failed to open ports"; - if (__get_consecutive_ports(&q, 1, port, loc->spec, &c->callid)) + if (!__get_consecutive_ports(&q, 1, port, loc->spec, &c->callid)) goto err; err = "no port returned"; struct socket_port_link *spl = t_queue_pop_head(&q); diff --git a/include/media_socket.h b/include/media_socket.h index cb63895fb..ec4ce6f86 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -296,9 +296,10 @@ struct local_intf *get_any_interface_address(const struct logical_intf *lif, soc void interfaces_exclude_port(endpoint_t *); int is_local_endpoint(const struct intf_address *addr, unsigned int port); -int __get_consecutive_ports(socket_port_q *out, unsigned int num_ports, unsigned int wanted_start_port, +bool __get_consecutive_ports(socket_port_q *out, unsigned int num_ports, unsigned int wanted_start_port, struct intf_spec *spec, const str *); -int get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsigned int num_intfs, struct call_media *media); +bool get_consecutive_ports(socket_intf_list_q *out, unsigned int num_ports, unsigned int num_intfs, + struct call_media *media); stream_fd *stream_fd_new(struct socket_port_link *, call_t *call, struct local_intf *lif); stream_fd *stream_fd_lookup(const endpoint_t *); void stream_fd_release(stream_fd *);