diff --git a/daemon/call.c b/daemon/call.c index 5c1ed02..82fe9b6 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -449,7 +449,7 @@ next: #undef DS -struct callmaster *callmaster_new(struct poller *p) { +struct callmaster *callmaster_new(struct poller *p, int min, int max) { struct callmaster *c; c = malloc(sizeof(*c)); @@ -459,6 +459,8 @@ struct callmaster *callmaster_new(struct poller *p) { if (!c->callhash) goto fail; c->poller = p; + c->port_min = min; + c->port_max = max; poller_timer(p, callmaster_timer, c); @@ -504,7 +506,7 @@ static void get_port_pair(struct peer *p) { struct call *c; struct callmaster *m; struct streamrelay *a, *b; - u_int16_t port; + u_int16_t port, min, max; c = p->up->call; m = c->callmaster; @@ -513,11 +515,18 @@ static void get_port_pair(struct peer *p) { assert(a->fd == -1 && b->fd == -1); + min = (m->port_min > 0 && m->port_min < 0xfff0) ? m->port_min : 1024; + max = (m->port_max > 0 && m->port_max > min && m->port_max < 0xfff0) ? m->port_max : 0; + + if (!m->lastport) + m->lastport = max; port = m->lastport + 1; for (;;) { - if (port < 1024) - port = 1024; + if (port < min) + port = min; + else if (max && port > max) + port = min; if (port == m->lastport) goto fail; diff --git a/daemon/call.h b/daemon/call.h index 4128f9e..304beda 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -68,6 +68,8 @@ struct call { struct callmaster { GHashTable *callhash; u_int16_t lastport; + int port_min; + int port_max; struct mediaproxy_stats statsps; struct mediaproxy_stats stats; @@ -83,7 +85,7 @@ struct callmaster { -struct callmaster *callmaster_new(struct poller *); +struct callmaster *callmaster_new(struct poller *, int, int); diff --git a/daemon/main.c b/daemon/main.c index 535e5b3..fcdb83f 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -35,6 +35,8 @@ static int tos; static int table; static int timeout; static int silent_timeout; +static int port_min; +static int port_max; @@ -110,6 +112,8 @@ static void options(int *argc, char ***argv) { { "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" }, { "pidfile", 'p', 0, G_OPTION_ARG_STRING, &pidfile, "Write PID to file", "FILE" }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL }, + { "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" }, + { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, { NULL, } }; @@ -196,7 +200,7 @@ int main(int argc, char **argv) { if (!p) die("poller creation failed\n"); - m = callmaster_new(p); + m = callmaster_new(p, port_min, port_max); if (!m) return -1; m->kernelfd = kfd; diff --git a/debian/ngcp-mediaproxy-ng-daemon.default b/debian/ngcp-mediaproxy-ng-daemon.default new file mode 100644 index 0000000..ca3ea0b --- /dev/null +++ b/debian/ngcp-mediaproxy-ng-daemon.default @@ -0,0 +1,12 @@ +RUN_MEDIAPROXY=no +LISTEN=25060 +LISTEN_UDP=12222 +# ADDRESS=... +TIMEOUT=60 +SILENT_TIMEOUT=3600 +PIDFILE=/var/run/ngcp-mediaproxy-ng-daemon.pid +FORK=yes +# TOS=184 +TABLE=0 +# PORT_MIN=30000 +# PORT_MAX=50000 diff --git a/debian/ngcp-mediaproxy-ng-daemon.init b/debian/ngcp-mediaproxy-ng-daemon.init index 6a23fbe..21e5571 100755 --- a/debian/ngcp-mediaproxy-ng-daemon.init +++ b/debian/ngcp-mediaproxy-ng-daemon.init @@ -50,6 +50,8 @@ OPTIONS="" [ -z "$SILENT_TIMEOUT" ] || OPTIONS="$OPTIONS --silent-timeout=$SILENT_TIMEOUT" [ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE" [ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS" +[ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN" +[ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX" OPTIONS="$OPTIONS --table=$TABLE" if test "$FORK" = "no" ; then OPTIONS="$OPTIONS --foreground"