diff --git a/src/main.c b/src/main.c index bee35cfb0..e5d036ad5 100644 --- a/src/main.c +++ b/src/main.c @@ -706,8 +706,15 @@ main(int argc, char **argv) err(1, "can't allocate memory for the stats data"); /* NOTREACHED */ } - cf.stable->port_table = rtpp_port_table_ctor(cf.stable->port_min, - cf.stable->port_max, cf.stable->seq_ports, cf.stable->port_ctl); + + for (i = 0; i <= RTPP_PT_MAX; i++) { + cf.stable->port_table[i] = rtpp_port_table_ctor(cf.stable->port_min, + cf.stable->port_max, cf.stable->seq_ports, cf.stable->port_ctl); + if (cf.stable->port_table[i] == NULL) { + err(1, "can't allocate memory for the ports data"); + /* NOTREACHED */ + } + } if (rtpp_controlfd_init(&cf) != 0) { err(1, "can't inilialize control socket%s", @@ -905,7 +912,9 @@ main(int argc, char **argv) CALL_METHOD(cf.stable->rtpp_timed_cf->rcnt, decref); CALL_METHOD(cf.stable->rtpp_proc_cf, dtor); CALL_METHOD(cf.stable->sessinfo->rcnt, decref); - CALL_METHOD(cf.stable->port_table->rcnt, decref); + for (i = 0; i <= RTPP_PT_MAX; i++) { + CALL_METHOD(cf.stable->port_table[i]->rcnt, decref); + } #ifdef HAVE_SYSTEMD_DAEMON sd_notify(0, "STATUS=Exited"); #endif diff --git a/src/rtpp_cfg_stable.h b/src/rtpp_cfg_stable.h index 8adb5050e..27ac90c9f 100644 --- a/src/rtpp_cfg_stable.h +++ b/src/rtpp_cfg_stable.h @@ -46,6 +46,13 @@ struct rtpp_sessinfo; struct rtpp_log; struct rtpp_module_if; +#define RTPP_PT_INET 0 +#define RTPP_PT_INET6 1 +#define RTPP_PT_MAX RTPP_PT_INET6 +#define RTPP_PT_LEN (RTPP_PT_MAX + 1) +#define RTPP_PT_SELECT(cp, af) (((af) == AF_INET) ? \ + (cp)->port_table[RTPP_PT_INET] : (cp)->port_table[RTPP_PT_INET6]) + struct rtpp_cfg_stable { const char *pid_file; @@ -90,7 +97,7 @@ struct rtpp_cfg_stable { int log_level; int log_facility; - struct rtpp_port_table *port_table; + struct rtpp_port_table *port_table[RTPP_PT_LEN]; struct rtpp_hash_table *sessions_ht; struct rtpp_weakref_obj *sessions_wrt; diff --git a/src/rtpp_command.c b/src/rtpp_command.c index 91be8090e..c75e85045 100644 --- a/src/rtpp_command.c +++ b/src/rtpp_command.c @@ -180,6 +180,7 @@ rtpp_create_listener(struct cfg *cf, struct sockaddr *ia, int *port, { struct create_twinlistener_args cta; int i; + struct rtpp_port_table *rpp; memset(&cta, '\0', sizeof(cta)); cta.cfs = cf->stable; @@ -190,7 +191,8 @@ rtpp_create_listener(struct cfg *cf, struct sockaddr *ia, int *port, for (i = 0; i < 2; i++) fds[i] = NULL; - return (CALL_METHOD(cf->stable->port_table, get_port, create_twinlistener, + rpp = RTPP_PT_SELECT(cf->stable, ia->sa_family); + return (CALL_METHOD(rpp, get_port, create_twinlistener, &cta)); }