From 0c23b07db6b41c1590d54ba0c66795627d881e78 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 19 Dec 2011 15:21:14 +0000 Subject: [PATCH] ignore user-supplied addresses and use proxy-supplied hints as only determining factor between ipv4 and ipv6 --- daemon/call.c | 29 ++++++++++++++++++++++------- daemon/call.h | 1 + daemon/main.c | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index d444748ef..6cfb3a40e 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -708,6 +708,7 @@ fail: static int setup_peer(struct peer *p, struct stream *s, const char *tag) { struct streamrelay *a, *b; struct callstream *cs; + int i; cs = p->up; a = &p->rtps[0]; @@ -728,6 +729,19 @@ static int setup_peer(struct peer *p, struct stream *s, const char *tag) { a->peer_advertised = a->peer; b->peer_advertised = b->peer; + for (i = 0; i < 2; i++) { + switch (s->direction[i]) { + case DIR_INTERNAL: + cs->peers[i ^ p->idx].desired_family = AF_INET; + break; + case DIR_EXTERNAL: + cs->peers[i ^ p->idx].desired_family = AF_INET6; + break; + default: + break; + } + } + strdupfree(&p->mediatype, s->mediatype); strdupfree(&p->tag, tag); p->filled = 1; @@ -1095,7 +1109,7 @@ static void call_destroy(struct call *c) { -static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const char *prefix, int swap, int family) { +static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const char *prefix, int swap) { GString *o; int i; GList *l; @@ -1115,8 +1129,9 @@ static char *streams_print(GQueue *s, unsigned int num, unsigned int off, const t = s->head->data; other_off = (off == 0) ? 1 : 0; - if (family == AF_INET - || (family == 0 && IN6_IS_ADDR_V4MAPPED(&t->peers[other_off].rtps[0].peer.ip46)) + if (t->peers[other_off].desired_family == AF_INET + || (t->peers[other_off].desired_family == 0 + && IN6_IS_ADDR_V4MAPPED(&t->peers[other_off].rtps[0].peer.ip46)) || IN6_IS_ADDR_UNSPECIFIED(&t->call->callmaster->ipv6)) { ip4 = t->peers[off].rtps[0].peer.ip46.s6_addr32[3]; if (!ip4) @@ -1236,7 +1251,7 @@ char *call_update_udp(const char **o, struct callmaster *m) { redis_update(c); #endif - ret = streams_print(c->callstreams, 1, (num >= 0) ? 0 : 1, o[1], 1, (st.direction[1] == DIR_EXTERNAL) ? AF_INET6 : AF_INET); + ret = streams_print(c->callstreams, 1, (num >= 0) ? 0 : 1, o[1], 1); mylog(LOG_INFO, "[%s] Returning to SIP proxy: %s", c->callid, ret); return ret; @@ -1274,7 +1289,7 @@ char *call_lookup_udp(const char **o, struct callmaster *m) { redis_update(c); #endif - ret = streams_print(c->callstreams, 1, (num >= 0) ? 1 : 0, o[1], 1, 0); + ret = streams_print(c->callstreams, 1, (num >= 0) ? 1 : 0, o[1], 1); mylog(LOG_INFO, "[%s] Returning to SIP proxy: %s", c->callid, ret); return ret; @@ -1302,7 +1317,7 @@ char *call_request(const char **o, struct callmaster *m) { redis_update(c); #endif - ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 0 : 1, NULL, 0, 0); + ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 0 : 1, NULL, 0); mylog(LOG_INFO, "[%s] Returning to SIP proxy: %s", c->callid, ret); return ret; } @@ -1329,7 +1344,7 @@ char *call_lookup(const char **o, struct callmaster *m) { redis_update(c); #endif - ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 1 : 0, NULL, 0, 0); + ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 1 : 0, NULL, 0); mylog(LOG_INFO, "[%s] Returning to SIP proxy: %s", c->callid, ret); return ret; } diff --git a/daemon/call.h b/daemon/call.h index c39415d66..5f9399cc6 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -59,6 +59,7 @@ struct peer { char *codec; unsigned char idx; struct callstream *up; + int desired_family; int kernelized:1; int filled:1; int confirmed:1; diff --git a/daemon/main.c b/daemon/main.c index 51070ce1e..d125fbbfa 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -127,6 +127,7 @@ static int parse_ip6_port(struct in6_addr *ip6, u_int16_t *port, char *s) { *p = '\0'; if (inet_pton(AF_INET6, s+1, ip6) != 1) goto fail; + *p = ']'; *port = atoi(p+2); if (!*port) return -1;