From 3ae125aa9130cb6c8f4fac606bd2f4ab7ce21a54 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 3 May 2011 14:41:59 +0000 Subject: [PATCH] introduce --advertised-ip parameter clear up some of the --help text make callmaster creation more consistent --- daemon/call.c | 12 +++++++----- daemon/call.h | 7 ++++--- daemon/main.c | 26 +++++++++++++++++++------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index ddaae0026..13c44562d 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -449,7 +449,7 @@ next: #undef DS -struct callmaster *callmaster_new(struct poller *p, int min, int max) { +struct callmaster *callmaster_new(struct poller *p) { struct callmaster *c; c = malloc(sizeof(*c)); @@ -459,8 +459,6 @@ struct callmaster *callmaster_new(struct poller *p, int min, int max) { if (!c->callhash) goto fail; c->poller = p; - c->port_min = min; - c->port_max = max; poller_timer(p, callmaster_timer, c); @@ -859,6 +857,7 @@ static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const GList *l; struct callstream *t; struct streamrelay *x; + u_int32_t ip; o = g_string_new(""); if (prefix) @@ -868,8 +867,11 @@ static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const goto out; t = s->head->data; + ip = t->call->callmaster->ip; + if (t->call->callmaster->adv_ip) + ip = t->call->callmaster->adv_ip; if (!swap) - g_string_append_printf(o, IPF, IPP(t->call->callmaster->ip)); + g_string_append_printf(o, IPF, IPP(ip)); for (i = 0, l = s->head; i < num && l; i++, l = l->next) { t = l->data; @@ -878,7 +880,7 @@ static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const } if (swap) - g_string_append_printf(o, IPF, IPP(t->call->callmaster->ip)); + g_string_append_printf(o, IPF, IPP(ip)); out: g_string_append(o, "\n"); diff --git a/daemon/call.h b/daemon/call.h index 304bedaa6..6c6baef74 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -68,8 +68,6 @@ struct call { struct callmaster { GHashTable *callhash; u_int16_t lastport; - int port_min; - int port_max; struct mediaproxy_stats statsps; struct mediaproxy_stats stats; @@ -77,6 +75,9 @@ struct callmaster { int kernelfd; unsigned int kernelid; u_int32_t ip; + u_int32_t adv_ip; + int port_min; + int port_max; unsigned int timeout; unsigned int silent_timeout; unsigned char tos; @@ -85,7 +86,7 @@ struct callmaster { -struct callmaster *callmaster_new(struct poller *, int, int); +struct callmaster *callmaster_new(struct poller *); diff --git a/daemon/main.c b/daemon/main.c index fcdb83fdd..f4d0a64eb 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -27,6 +27,7 @@ static char *pidfile; static gboolean foreground; static u_int32_t ip; +static u_int32_t adv_ip; static u_int32_t listenp; static u_int16_t listenport; static u_int32_t udp_listenp; @@ -100,11 +101,13 @@ out: static void options(int *argc, char ***argv) { static char *ips; + static char *adv_ips; static char *listenps; static char *listenudps; static GOptionEntry e[] = { { "table", 't', 0, G_OPTION_ARG_INT, &table, "Kernel table to use", "INT" }, - { "ip", 'i', 0, G_OPTION_ARG_STRING, &ips, "Local IP address", "IP" }, + { "ip", 'i', 0, G_OPTION_ARG_STRING, &ips, "Local IP address for RTP", "IP" }, + { "advertised-ip", 'a', 0, G_OPTION_ARG_STRING, &adv_ips, "IP address to advertise", "IP" }, { "listen", 'l', 0, G_OPTION_ARG_STRING, &listenps, "TCP port to listen on", "[IP:]PORT" }, { "listen-udp", 'u', 0, G_OPTION_ARG_STRING, &listenudps, "UDP port to listen on", "[IP:]PORT" }, { "tos", 'T', 0, G_OPTION_ARG_INT, &tos, "TOS value to set on streams", "INT" }, @@ -126,21 +129,27 @@ static void options(int *argc, char ***argv) { die("Bad command line: %s\n", er->message); if (!ips) - die("Missing option IP\n"); + die("Missing option --ip\n"); if (!listenps && !listenudps) - die("Missing option LISTEN or LISTEN-UDP\n"); + die("Missing option --listen or --listen-udp\n"); ip = inet_addr(ips); if (ip == -1) - die("Invalid IP\n"); + die("Invalid IP (--ip)\n"); + + if (adv_ips) { + adv_ip = inet_addr(adv_ips); + if (adv_ip == -1) + die("Invalid IP (--advertised-ip)\n"); + } if (listenps) { if (parse_ip_port(&listenp, &listenport, listenps)) - die("Invalid IP or port"); + die("Invalid IP or port (--listen)"); } if (listenudps) { if (parse_ip_port(&udp_listenp, &udp_listenport, listenudps)) - die("Invalid IP or port"); + die("Invalid IP or port (--listen-udp)"); } if (tos < 0 || tos > 255) @@ -200,12 +209,15 @@ int main(int argc, char **argv) { if (!p) die("poller creation failed\n"); - m = callmaster_new(p, port_min, port_max); + m = callmaster_new(p); if (!m) return -1; m->kernelfd = kfd; m->kernelid = table; m->ip = ip; + m->adv_ip = adv_ip; + m->port_min = port_min; + m->port_max = port_max; m->timeout = timeout; m->silent_timeout = silent_timeout; m->tos = tos;