Skip to content

Commit

Permalink
Provide a separate port table for IPv6 and IPv4.
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Mar 3, 2016
1 parent d0ea18b commit 3e13d18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/main.c
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/rtpp_cfg_stable.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/rtpp_command.c
Expand Up @@ -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;
Expand All @@ -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));
}

Expand Down

0 comments on commit 3e13d18

Please sign in to comment.