From c00c06ea7a1f05b40c5521efff6064f0cf382348 Mon Sep 17 00:00:00 2001 From: Peter Dunkley Date: Mon, 11 Nov 2013 11:24:49 +0000 Subject: [PATCH 01/11] Updated version and license in .spec --- el/mediaproxy-ng.spec | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/el/mediaproxy-ng.spec b/el/mediaproxy-ng.spec index 308e77a4f..4893b7ec8 100644 --- a/el/mediaproxy-ng.spec +++ b/el/mediaproxy-ng.spec @@ -1,10 +1,10 @@ Name: ngcp-mediaproxy-ng -Version: 2.3.0 -Release: 3%{?dist} +Version: 2.3.2 +Release: 0%{?dist} Summary: The Sipwise NGCP mediaproxy-ng Group: System Environment/Daemons -License: unknown +License: GPLv3 URL: https://github.com/crocodilertc/mediaproxy-ng Source: %{name}-%{version}.tar.gz Conflicts: %{name}-kernel < %{version} @@ -165,6 +165,9 @@ true %changelog +* Mon Nov 11 2013 Peter Dunkley + - Updated version to 2.3.2 + - Set license to GPLv3 * Thu Aug 15 2013 Peter Dunkley - init.d scripts and configuration file * Wed Aug 14 2013 Peter Dunkley From 162ff026abcd04d091fe2c5b9b3e61e47a6cd5c6 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 10 Dec 2013 05:37:19 -0500 Subject: [PATCH 02/11] kernel module compile fixes for kernels >= 3.10 --- kernel-module/Makefile | 2 +- kernel-module/xt_MEDIAPROXY.c | 106 +++++++++++++++++----------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/kernel-module/Makefile b/kernel-module/Makefile index 6394c5fdf..98437ec36 100644 --- a/kernel-module/Makefile +++ b/kernel-module/Makefile @@ -7,7 +7,7 @@ ifneq ($(MEDIAPROXY_VERSION),) else DPKG_PRSCHNGLG= $(shell which dpkg-parsechangelog 2>/dev/null) ifneq ($(DPKG_PRSCHNGLG),) - EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\"" + EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l$(M)/../debian/changelog | awk '/^Version: / {print $$2}')\"" else EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"undefined\"" endif diff --git a/kernel-module/xt_MEDIAPROXY.c b/kernel-module/xt_MEDIAPROXY.c index debf5057b..383e3a151 100644 --- a/kernel-module/xt_MEDIAPROXY.c +++ b/kernel-module/xt_MEDIAPROXY.c @@ -63,6 +63,12 @@ MODULE_LICENSE("GPL"); +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +#define PDE_DATA(i) (PDE(i)->data) +#endif + + + struct mp_hmac; struct mp_cipher; @@ -84,7 +90,8 @@ static rwlock_t table_lock; static ssize_t proc_control_write(struct file *, const char __user *, size_t, loff_t *); static int proc_control_open(struct inode *, struct file *); static int proc_control_close(struct inode *, struct file *); -static int proc_status(char *, char **, off_t, int, int *, void *); + +static ssize_t proc_status(struct file *, char __user *, size_t, loff_t *); static ssize_t proc_main_control_write(struct file *, const char __user *, size_t, loff_t *); static int proc_main_control_open(struct inode *, struct file *); @@ -222,6 +229,10 @@ static const struct file_operations proc_main_control_ops = { .release = proc_main_control_close, }; +static const struct file_operations proc_status_ops = { + .read = proc_status, +}; + static const struct file_operations proc_list_ops = { .open = proc_list_open, .read = seq_read, @@ -341,38 +352,29 @@ static int table_create_proc(struct mediaproxy_table *t, u_int32_t id) { sprintf(num, "%u", id); - t->proc = create_proc_entry(num, S_IFDIR | S_IRUGO | S_IXUGO, my_proc_root); + t->proc = proc_mkdir_mode(num, S_IRUGO | S_IXUGO, my_proc_root); if (!t->proc) return -1; - /* t->proc->owner = THIS_MODULE; */ - t->status = create_proc_entry("status", S_IFREG | S_IRUGO, t->proc); + t->status = proc_create_data("status", S_IFREG | S_IRUGO, t->proc, &proc_status_ops, + (void *) (unsigned long) id); if (!t->status) return -1; - /* t->status->owner = THIS_MODULE; */ - t->status->read_proc = proc_status; - t->status->data = (void *) (unsigned long) id; - t->control = create_proc_entry("control", S_IFREG | S_IWUSR | S_IWGRP, t->proc); + t->control = proc_create_data("control", S_IFREG | S_IWUSR | S_IWGRP, t->proc, + &proc_control_ops, (void *) (unsigned long) id); if (!t->control) return -1; - /* t->control->owner = THIS_MODULE; */ - t->control->proc_fops = &proc_control_ops; - t->control->data = (void *) (unsigned long) id; - t->list = create_proc_entry("list", S_IFREG | S_IRUGO, t->proc); + t->list = proc_create_data("list", S_IFREG | S_IRUGO, t->proc, + &proc_list_ops, (void *) (unsigned long) id); if (!t->list) return -1; - /* t->list->owner = THIS_MODULE; */ - t->list->proc_fops = &proc_list_ops; - t->list->data = (void *) (unsigned long) id; - t->blist = create_proc_entry("blist", S_IFREG | S_IRUGO, t->proc); + t->blist = proc_create_data("blist", S_IFREG | S_IRUGO, t->proc, + &proc_blist_ops, (void *) (unsigned long) id); if (!t->blist) return -1; - /* t->blist->owner = THIS_MODULE; */ - t->blist->proc_fops = &proc_blist_ops; - t->blist->data = (void *) (unsigned long) id; return 0; } @@ -461,7 +463,11 @@ static void clear_proc(struct proc_dir_entry **e) { if (!e || !*e) return; +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) remove_proc_entry((*e)->name, (*e)->parent); +#else + proc_remove(*e); +#endif *e = NULL; } @@ -564,31 +570,42 @@ static struct mediaproxy_table *get_table(u_int32_t id) { -static int proc_status(char *page, char **start, off_t off, int count, int *eof, void *data) { +static ssize_t proc_status(struct file *f, char __user *b, size_t l, loff_t *o) { + struct inode *inode; + char buf[256]; struct mediaproxy_table *t; int len = 0; unsigned long flags; + u_int32_t id; + + if (*o) + return -EINVAL; + if (l < sizeof(buf)) + return -EINVAL; - u_int32_t id = (u_int32_t) (unsigned long) data; + inode = f->f_path.dentry->d_inode; + id = (u_int32_t) (unsigned long) PDE_DATA(inode); t = get_table(id); if (!t) return -ENOENT; read_lock_irqsave(&t->target_lock, flags); - len += sprintf(page + len, "Refcount: %u\n", atomic_read(&t->refcnt) - 1); - len += sprintf(page + len, "Control PID: %u\n", t->pid); - len += sprintf(page + len, "Targets: %u\n", t->targets); - len += sprintf(page + len, "Buckets: %u\n", t->buckets); + len += sprintf(buf + len, "Refcount: %u\n", atomic_read(&t->refcnt) - 1); + len += sprintf(buf + len, "Control PID: %u\n", t->pid); + len += sprintf(buf + len, "Targets: %u\n", t->targets); + len += sprintf(buf + len, "Buckets: %u\n", t->buckets); read_unlock_irqrestore(&t->target_lock, flags); table_push(t); + if (copy_to_user(b, buf, len)) + return -EFAULT; + return len; } - static int proc_main_list_open(struct inode *i, struct file *f) { return seq_open(f, &proc_main_list_seq_ops); } @@ -641,12 +658,10 @@ static int proc_main_list_show(struct seq_file *f, void *v) { static int proc_blist_open(struct inode *i, struct file *f) { - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; - pde = PDE(i); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(i); t = get_table(id); if (!t) return -ENOENT; @@ -657,12 +672,10 @@ static int proc_blist_open(struct inode *i, struct file *f) { } static int proc_blist_close(struct inode *i, struct file *f) { - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; - pde = PDE(i); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(i); t = get_table(id); if (!t) return 0; @@ -674,7 +687,6 @@ static int proc_blist_close(struct inode *i, struct file *f) { static ssize_t proc_blist_read(struct file *f, char __user *b, size_t l, loff_t *o) { struct inode *inode; - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; struct mediaproxy_list_entry op; @@ -688,8 +700,7 @@ static ssize_t proc_blist_read(struct file *f, char __user *b, size_t l, loff_t return -EINVAL; inode = f->f_path.dentry->d_inode; - pde = PDE(inode); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(inode); t = get_table(id); if (!t) return -ENOENT; @@ -740,12 +751,10 @@ err: static int proc_list_open(struct inode *i, struct file *f) { int err; struct seq_file *p; - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; - pde = PDE(i); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(i); t = get_table(id); if (!t) return -ENOENT; @@ -1439,13 +1448,11 @@ static ssize_t proc_main_control_write(struct file *file, const char __user *buf static int proc_control_open(struct inode *inode, struct file *file) { - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; unsigned long flags; - pde = PDE(inode); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(inode); t = get_table(id); if (!t) return -ENOENT; @@ -1464,13 +1471,11 @@ static int proc_control_open(struct inode *inode, struct file *file) { } static int proc_control_close(struct inode *inode, struct file *file) { - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; unsigned long flags; - pde = PDE(inode); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(inode); t = get_table(id); if (!t) return 0; @@ -1486,7 +1491,6 @@ static int proc_control_close(struct inode *inode, struct file *file) { static ssize_t proc_control_write(struct file *file, const char __user *buf, size_t buflen, loff_t *off) { struct inode *inode; - struct proc_dir_entry *pde; u_int32_t id; struct mediaproxy_table *t; struct mediaproxy_message msg; @@ -1496,8 +1500,7 @@ static ssize_t proc_control_write(struct file *file, const char __user *buf, siz return -EIO; inode = file->f_path.dentry->d_inode; - pde = PDE(inode); - id = (u_int32_t) (unsigned long) pde->data; + id = (u_int32_t) (unsigned long) PDE_DATA(inode); t = get_table(id); if (!t) return -ENOENT; @@ -2234,17 +2237,14 @@ static int __init init(void) { goto fail; /* my_proc_root->owner = THIS_MODULE; */ - proc_control = create_proc_entry("control", S_IFREG | S_IWUSR | S_IWGRP, my_proc_root); + proc_control = proc_create("control", S_IFREG | S_IWUSR | S_IWGRP, my_proc_root, + &proc_main_control_ops); if (!proc_control) goto fail; - /* proc_control->owner = THIS_MODULE; */ - proc_control->proc_fops = &proc_main_control_ops; - proc_list = create_proc_entry("list", S_IFREG | S_IRUGO, my_proc_root); + proc_list = proc_create("list", S_IFREG | S_IRUGO, my_proc_root, &proc_main_list_ops); if (!proc_list) goto fail; - /* proc_list->owner = THIS_MODULE; */ - proc_list->proc_fops = &proc_main_list_ops; err = "could not register xtables target"; ret = xt_register_targets(xt_mediaproxy_regs, ARRAY_SIZE(xt_mediaproxy_regs)); From e0e98bb31f5cbb75cd8efb4d7585eac4af423498 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 10 Dec 2013 05:43:49 -0500 Subject: [PATCH 03/11] prevent endless read of proc/status file --- kernel-module/xt_MEDIAPROXY.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel-module/xt_MEDIAPROXY.c b/kernel-module/xt_MEDIAPROXY.c index 383e3a151..01104e8d7 100644 --- a/kernel-module/xt_MEDIAPROXY.c +++ b/kernel-module/xt_MEDIAPROXY.c @@ -578,7 +578,9 @@ static ssize_t proc_status(struct file *f, char __user *b, size_t l, loff_t *o) unsigned long flags; u_int32_t id; - if (*o) + if (*o > 0) + return 0; + if (*o < 0) return -EINVAL; if (l < sizeof(buf)) return -EINVAL; @@ -600,6 +602,7 @@ static ssize_t proc_status(struct file *f, char __user *b, size_t l, loff_t *o) if (copy_to_user(b, buf, len)) return -EFAULT; + *o += len; return len; } From bda8c543b8a218b4b4007ba49d38b2071d2ee29c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 10 Dec 2013 06:22:33 -0500 Subject: [PATCH 04/11] re-learn peer addresses after each signalling --- daemon/call.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index e23c36765..b5d11e25f 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -191,6 +191,8 @@ static const struct mediaproxy_srtp __mps_null = { static void call_destroy(struct call *); static void unkernelize(struct peer *); +static void unconfirm(struct peer *); +static void unconfirm_cs(struct callstream *); static void relays_cache_port_used(struct relays_cache *c); static void ng_call_stats(struct call *call, const str *fromtag, const str *totag, bencode_item_t *output); @@ -1307,12 +1309,8 @@ static int setup_peer(struct peer *p, struct stream_input *s, const str *tag) { b = &p->rtps[1]; if (a->peer_advertised.port != s->stream.port - || !IN6_ARE_ADDR_EQUAL(&a->peer_advertised.ip46, &s->stream.ip46)) { - cs->peers[0].confirmed = 0; - unkernelize(&cs->peers[0]); - cs->peers[1].confirmed = 0; - unkernelize(&cs->peers[1]); - } + || !IN6_ARE_ADDR_EQUAL(&a->peer_advertised.ip46, &s->stream.ip46)) + unconfirm_cs(cs); a->peer = s->stream; b->peer = s->stream; @@ -1364,10 +1362,8 @@ static void steal_peer(struct peer *dest, struct peer *src) { mylog(LOG_DEBUG, LOG_PREFIX_CI "Re-using existing open RTP port %u", LOG_PARAMS_CI(c), r->fd.localport); - dest->confirmed = 0; - unkernelize(dest); - src->confirmed = 0; - unkernelize(src); + unconfirm(dest); + unconfirm(src); dest->filled = src->filled; dest->tag = src->tag; @@ -1590,6 +1586,7 @@ static int call_streams(struct call *c, GQueue *s, const str *tag, enum call_opm if (str_cmp_str0(&cs_o->peers[x].tag, tag)) continue; DBG("found existing call stream to steal"); + unconfirm_cs(cs_o); goto found; } mutex_unlock(&cs_o->lock); @@ -1658,6 +1655,7 @@ found: got_cs: /* cs and cs_o remain locked, and maybe cs == cs_o */ /* matched_relay == peer[x].rtp[0] of cs_o */ + unconfirm_cs(cs); g_queue_delete_link(c->callstreams, l); /* steal cs ref */ p = &cs->peers[1]; p2 = &cs->peers[0]; @@ -1713,9 +1711,8 @@ got_cs: g_queue_push_tail(c->callstreams, cs_o); /* hand over ref to original cs */ } - time(&c->lookup_done); - skip: + time(&c->lookup_done); g_queue_push_tail(q, p->up); /* hand over ref to cs */ mutex_unlock(&cs->lock); if (cs_o && cs_o != cs) @@ -1746,6 +1743,15 @@ skip: +static void unconfirm(struct peer *p) { + p->confirmed = 0; + unkernelize(p); +} +static void unconfirm_cs(struct callstream *cs) { + unconfirm(&cs->peers[0]); + unconfirm(&cs->peers[1]); +} + static void unkernelize(struct peer *p) { struct streamrelay *r; int i; @@ -1754,8 +1760,6 @@ static void unkernelize(struct peer *p) { return; for (i = 0; i < 2; i++) { - if (!p->kernelized) - continue; r = &p->rtps[i]; if (r->no_kernel_support) continue; From b14908e59ecf0174f2cfb164809e8bf9cf5b5850 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 12 Dec 2013 05:21:11 -0500 Subject: [PATCH 05/11] additional debug for double lookup case --- daemon/call.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/call.c b/daemon/call.c index b5d11e25f..673d7e716 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1666,9 +1666,12 @@ got_cs: the appropriate details. if no matching stream was found, results are undefined. */ DBG("double lookup"); - if (p == matched_relay->up) + if (p == matched_relay->up) { + DBG("forward direction"); goto skip; + } if (p2 == matched_relay->up) { + DBG("backward direction"); ret = -1; goto skip; } From 5c616c27af95d73eb275a20d9aecdd82b0bdced0 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 12 Dec 2013 05:36:18 -0500 Subject: [PATCH 06/11] fix erroneous double lookup detection --- daemon/call.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/call.c b/daemon/call.c index 673d7e716..0389b2074 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1660,7 +1660,10 @@ got_cs: p = &cs->peers[1]; p2 = &cs->peers[0]; - if (c->lookup_done && matched_relay) { + if (c->lookup_done && matched_relay + && t->stream.port == matched_relay->peer_advertised.port + && IN6_ARE_ADDR_EQUAL(&t->stream.ip46, &matched_relay->peer_advertised.ip46)) + { /* duplicate/stray lookup. don't do anything except replying with something we already have. check whether the direction is reversed or not and return the appropriate details. if no matching stream was found, results are From 9fe79ddf25b56572e14c12af2c1ccb518975cf35 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 12 Dec 2013 05:49:20 -0500 Subject: [PATCH 07/11] 2.3.4 --- debian/changelog | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/debian/changelog b/debian/changelog index 45e957c6f..b136900a6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ngcp-mediaproxy-ng (2.3.4) unstable; urgency=low + + * Kernel module compile fixes for kernels >= 3.10 + * Re-learn peer addresses after each signalling + * Fix erroneous double lookup detection + + -- Richard Fuchs Thu, 12 Dec 2013 05:48:12 -0500 + ngcp-mediaproxy-ng (2.3.3) unstable; urgency=low * fix possible segfault on incorrect sp/SP flag usage From 821437f470e8e6a2c33c6f6b6537bbaba5046d49 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 13 Dec 2013 06:57:31 -0500 Subject: [PATCH 08/11] fix iptables module printing format --- iptables-extension/libxt_MEDIAPROXY.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iptables-extension/libxt_MEDIAPROXY.c b/iptables-extension/libxt_MEDIAPROXY.c index c307c991b..89973782a 100644 --- a/iptables-extension/libxt_MEDIAPROXY.c +++ b/iptables-extension/libxt_MEDIAPROXY.c @@ -90,7 +90,7 @@ static void print(const void *ip, const struct xt_entry_target *target, int nume #endif struct xt_mediaproxy_info *info = (void *) target->data; - printf("id %u", info->id); + printf(" MEDIAPROXY id:%u", info->id); } #if defined(__ipt) @@ -102,7 +102,7 @@ static void save(const void *ip, const struct xt_entry_target *target) { #endif struct xt_mediaproxy_info *info = (void *) target->data; - printf("--id %u", info->id); + printf(" --id %u", info->id); } static struct option opts[] = { From 843a7c8572437cc4ab5bf357a132daeb5f7ae317 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 13 Dec 2013 07:10:56 -0500 Subject: [PATCH 09/11] add openssl exception to debian/copyright --- debian/copyright | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/debian/copyright b/debian/copyright index a8f3e5108..bad3fe81c 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,12 +1,24 @@ Upstream Author: The Sipwise Team - http://sipwise.com Copyright: 2007-2013, Sipwise GmbH, Austria -License: GPL-3+ +License: GPL-3+ with OpenSSL exception This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. . + In addition, as a special exception, the author of this + program gives permission to link the code of its + release with the OpenSSL project's "OpenSSL" library (or + with modified versions of it that use the same license as + the "OpenSSL" library), and distribute the linked + executables. You must obey the GNU General Public + License in all respects for all of the code used other + than "OpenSSL". If you modify this file, you may extend + this exception to your version of the file, but you are + not obligated to do so. If you do not wish to do so, + delete this exception statement from your version. + . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR From ef7e5bb4f765c0e66b0d4824ffd04c87dd9d995f Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 17 Dec 2013 08:31:57 -0500 Subject: [PATCH 10/11] compile fix for kernels < 3.0.0 --- kernel-module/xt_MEDIAPROXY.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel-module/xt_MEDIAPROXY.c b/kernel-module/xt_MEDIAPROXY.c index 01104e8d7..e3671fb82 100644 --- a/kernel-module/xt_MEDIAPROXY.c +++ b/kernel-module/xt_MEDIAPROXY.c @@ -352,7 +352,11 @@ static int table_create_proc(struct mediaproxy_table *t, u_int32_t id) { sprintf(num, "%u", id); +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) + t->proc = create_proc_entry(num, S_IFDIR | S_IRUGO | S_IXUGO, my_proc_root); +#else t->proc = proc_mkdir_mode(num, S_IRUGO | S_IXUGO, my_proc_root); +#endif if (!t->proc) return -1; From 059781781605105836d7f91a231f259ae8179f5c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Sun, 5 Jan 2014 16:46:40 -0500 Subject: [PATCH 11/11] update desired address family (based on "direction") when branching --- daemon/call.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 0389b2074..27d730c8d 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1296,12 +1296,28 @@ fail: return -1; } +static void setup_stream_families(struct callstream *cs, struct stream_input *s, int idx) { + int i; + + for (i = 0; i < 2; i++) { + switch (s->direction[i]) { + case DIR_INTERNAL: + cs->peers[i ^ idx].desired_family = AF_INET; + break; + case DIR_EXTERNAL: + cs->peers[i ^ idx].desired_family = AF_INET6; + break; + default: + break; + } + } +} + /* caller is responsible for appropriate locking */ static int setup_peer(struct peer *p, struct stream_input *s, const str *tag) { struct streamrelay *a, *b; struct callstream *cs; struct call *ca; - int i; cs = p->up; ca = cs->call; @@ -1324,18 +1340,7 @@ static int setup_peer(struct peer *p, struct stream_input *s, const str *tag) { a->other->crypto.in = s->crypto; b->other->crypto.in = s->crypto; - 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; - } - } + setup_stream_families(cs, s, p->idx); call_str_cpy(ca, &p->tag, tag); p->filled = 1; @@ -1625,6 +1630,7 @@ found: steal_peer(&cs->peers[0], &cs_o->peers[1]); steal_peer(&cs->peers[1], &cs_o->peers[0]); } + setup_stream_families(cs, t, 0); mutex_unlock(&cs_o->lock); }