|
|
@ -9,6 +9,7 @@ |
|
|
|
|
|
|
|
|
#include "poller.h" |
|
|
#include "poller.h" |
|
|
#include "control.h" |
|
|
#include "control.h" |
|
|
|
|
|
#include "control_udp.h" |
|
|
#include "aux.h" |
|
|
#include "aux.h" |
|
|
#include "log.h" |
|
|
#include "log.h" |
|
|
#include "call.h" |
|
|
#include "call.h" |
|
|
@ -28,6 +29,8 @@ static gboolean foreground; |
|
|
static u_int32_t ip; |
|
|
static u_int32_t ip; |
|
|
static u_int32_t listenp; |
|
|
static u_int32_t listenp; |
|
|
static u_int16_t listenport; |
|
|
static u_int16_t listenport; |
|
|
|
|
|
static u_int32_t udp_listenp; |
|
|
|
|
|
static u_int16_t udp_listenport; |
|
|
static int tos; |
|
|
static int tos; |
|
|
static int table; |
|
|
static int table; |
|
|
static int timeout; |
|
|
static int timeout; |
|
|
@ -62,13 +65,46 @@ static void resources(void) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int parse_ip_port(u_int32_t *ip, u_int16_t *port, char *s) { |
|
|
|
|
|
char *p = NULL; |
|
|
|
|
|
int ret = -1; |
|
|
|
|
|
|
|
|
|
|
|
p = strchr(s, ':'); |
|
|
|
|
|
if (p) { |
|
|
|
|
|
*p++ = 0; |
|
|
|
|
|
*ip = inet_addr(s); |
|
|
|
|
|
if (*ip == -1) |
|
|
|
|
|
goto out; |
|
|
|
|
|
*port = atoi(p); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
*ip = 0; |
|
|
|
|
|
if (strchr(s, '.')) |
|
|
|
|
|
goto out; |
|
|
|
|
|
*port = atoi(s); |
|
|
|
|
|
} |
|
|
|
|
|
if (!*port) |
|
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
ret = 0; |
|
|
|
|
|
|
|
|
|
|
|
out: |
|
|
|
|
|
if (p) |
|
|
|
|
|
*--p = ':'; |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void options(int *argc, char ***argv) { |
|
|
static void options(int *argc, char ***argv) { |
|
|
static char *ips; |
|
|
static char *ips; |
|
|
static char *listenps; |
|
|
static char *listenps; |
|
|
|
|
|
static char *listenudps; |
|
|
static GOptionEntry e[] = { |
|
|
static GOptionEntry e[] = { |
|
|
{ "table", 't', 0, G_OPTION_ARG_INT, &table, "Kernel table to use", "INT" }, |
|
|
{ "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", "IP" }, |
|
|
{ "listen", 'l', 0, G_OPTION_ARG_STRING, &listenps, "Port to listen on", "[IP:]PORT" }, |
|
|
|
|
|
|
|
|
{ "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" }, |
|
|
{ "tos", 'T', 0, G_OPTION_ARG_INT, &tos, "TOS value to set on streams", "INT" }, |
|
|
{ "timeout", 'o', 0, G_OPTION_ARG_INT, &timeout, "RTP timeout", "SECS" }, |
|
|
{ "timeout", 'o', 0, G_OPTION_ARG_INT, &timeout, "RTP timeout", "SECS" }, |
|
|
{ "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" }, |
|
|
{ "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" }, |
|
|
@ -79,7 +115,6 @@ static void options(int *argc, char ***argv) { |
|
|
|
|
|
|
|
|
GOptionContext *c; |
|
|
GOptionContext *c; |
|
|
GError *er = NULL; |
|
|
GError *er = NULL; |
|
|
char *p; |
|
|
|
|
|
|
|
|
|
|
|
c = g_option_context_new(" - next-generation media proxy"); |
|
|
c = g_option_context_new(" - next-generation media proxy"); |
|
|
g_option_context_add_main_entries(c, e, NULL); |
|
|
g_option_context_add_main_entries(c, e, NULL); |
|
|
@ -88,30 +123,21 @@ static void options(int *argc, char ***argv) { |
|
|
|
|
|
|
|
|
if (!ips) |
|
|
if (!ips) |
|
|
die("Missing option IP\n"); |
|
|
die("Missing option IP\n"); |
|
|
if (!listenps) |
|
|
|
|
|
die("Missing option LISTEN\n"); |
|
|
|
|
|
|
|
|
if (!listenps || !listenudps) |
|
|
|
|
|
die("Missing option LISTEN or LISTEN-UDP\n"); |
|
|
|
|
|
|
|
|
ip = inet_addr(ips); |
|
|
ip = inet_addr(ips); |
|
|
if (ip == -1) |
|
|
if (ip == -1) |
|
|
die("Invalid IP\n"); |
|
|
die("Invalid IP\n"); |
|
|
|
|
|
|
|
|
p = strchr(listenps, ':'); |
|
|
|
|
|
if (p) { |
|
|
|
|
|
*p++ = 0; |
|
|
|
|
|
listenp = inet_addr(listenps); |
|
|
|
|
|
if (listenp == -1) |
|
|
|
|
|
die("Invalid IP\n"); |
|
|
|
|
|
listenport = atoi(p); |
|
|
|
|
|
|
|
|
if (listenps) { |
|
|
|
|
|
if (parse_ip_port(&listenp, &listenport, listenps)) |
|
|
|
|
|
die("Invalid IP or port"); |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
if (strchr(listenps, '.')) |
|
|
|
|
|
die("Invalid port\n"); |
|
|
|
|
|
listenport = atoi(listenps); |
|
|
|
|
|
|
|
|
if (listenudps) { |
|
|
|
|
|
if (parse_ip_port(&udp_listenp, &udp_listenport, listenudps)) |
|
|
|
|
|
die("Invalid IP or port"); |
|
|
} |
|
|
} |
|
|
if (!listenport) |
|
|
|
|
|
die("Invalid port\n"); |
|
|
|
|
|
if (p) |
|
|
|
|
|
*--p = ':'; |
|
|
|
|
|
|
|
|
|
|
|
if (tos < 0 || tos > 255) |
|
|
if (tos < 0 || tos > 255) |
|
|
die("Invalid TOS value"); |
|
|
die("Invalid TOS value"); |
|
|
@ -151,6 +177,7 @@ int main(int argc, char **argv) { |
|
|
struct poller *p; |
|
|
struct poller *p; |
|
|
struct callmaster *m; |
|
|
struct callmaster *m; |
|
|
struct control *c; |
|
|
struct control *c; |
|
|
|
|
|
struct control_udp *cu; |
|
|
int kfd; |
|
|
int kfd; |
|
|
int ret; |
|
|
int ret; |
|
|
|
|
|
|
|
|
@ -179,9 +206,19 @@ int main(int argc, char **argv) { |
|
|
m->silent_timeout = silent_timeout; |
|
|
m->silent_timeout = silent_timeout; |
|
|
m->tos = tos; |
|
|
m->tos = tos; |
|
|
|
|
|
|
|
|
c = control_new(p, listenp, listenport, m); |
|
|
|
|
|
if (!c) |
|
|
|
|
|
die("Failed to open control connection port\n"); |
|
|
|
|
|
|
|
|
c = NULL; |
|
|
|
|
|
if (listenport) { |
|
|
|
|
|
c = control_new(p, listenp, listenport, m); |
|
|
|
|
|
if (!c) |
|
|
|
|
|
die("Failed to open TCP control connection port\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cu = NULL; |
|
|
|
|
|
if (udp_listenport) { |
|
|
|
|
|
cu = control_udp_new(p, udp_listenp, udp_listenport, m); |
|
|
|
|
|
if (!cu) |
|
|
|
|
|
die("Failed to open UDP control connection port\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
mylog(LOG_INFO, "Startup complete"); |
|
|
mylog(LOG_INFO, "Startup complete"); |
|
|
|
|
|
|
|
|
|