Change in osmo-mgw[master]: mgcp_protocol: Avoid code duplication between virtual + other trunks

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Sun Mar 8 12:23:51 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/17423 )


Change subject: mgcp_protocol: Avoid code duplication between virtual + other trunks
......................................................................

mgcp_protocol: Avoid code duplication between virtual + other trunks

There were two code paths that were supposed to do exactly the same,
but then in Change-Id I3994af016fb96427263edbba05f560743f85fdd4 only
one of the two was modified, resulting in OS#4034

Let's
* dynamically allocate the virtual trunk
* rename mgcp_config.trunk to mgcp_config.virt_trunk to clarify
* as a result, abolish copy+pasted code for trunk initialization

Change-Id: I54762af6d417b849a24b6e71b6c5c996a5cb3fa6
Related: OS#4034
---
M include/osmocom/mgcp/mgcp.h
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_msg.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_osmux.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_vty.c
7 files changed, 91 insertions(+), 87 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/23/17423/1

diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index a479fbb..380f2d1 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -251,7 +251,10 @@
 	uint32_t last_call_id;
 
 	/* trunk handling */
-	struct mgcp_trunk_config trunk;
+
+	/* virtual trunk for RTP - RTP endpoints */
+	struct mgcp_trunk_config *virt_trunk;
+	/* physical trunks with underlying E1 endpoints */
 	struct llist_head trunks;
 
 	enum mgcp_role role;
diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index e9d5d2d..782980a 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -282,7 +282,7 @@
 	return endpoint + 60;
 }
 
-struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index);
+struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int index);
 struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index);
 
 char *get_lco_identifier(const char *options);
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 3e95ed1..b0d1a9f 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -235,6 +235,7 @@
 	unsigned int gw = INT_MAX;
 	const char *endpoint_number_str;
 	struct mgcp_endpoint *endp;
+	struct mgcp_trunk_config *virt_trunk = cfg->virt_trunk;
 
 	*cause = 0;
 
@@ -259,15 +260,15 @@
 		endpoint_number_str =
 		    mgcp + strlen(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK);
 		if (endpoint_number_str[0] == '*') {
-			endp = find_free_endpoint(cfg->trunk.endpoints,
-						  cfg->trunk.number_endpoints);
+			endp = find_free_endpoint(virt_trunk->endpoints,
+						  virt_trunk->number_endpoints);
 			if (!endp)
 				*cause = -403;
 			return endp;
 		}
 		gw = strtoul(endpoint_number_str, &endptr, 16);
-		if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
-			endp = &cfg->trunk.endpoints[gw];
+		if (gw < virt_trunk->number_endpoints && endptr[0] == '@') {
+			endp = &virt_trunk->endpoints[gw];
 			endp->wildcarded_req = false;
 			return endp;
 		}
@@ -278,8 +279,8 @@
 	     "Addressing virtual trunk without prefix (deprecated), please use %s: '%s'\n",
 	     MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, mgcp);
 	gw = strtoul(mgcp, &endptr, 16);
-	if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
-		endp = &cfg->trunk.endpoints[gw];
+	if (gw < virt_trunk->number_endpoints && endptr[0] == '@') {
+		endp = &virt_trunk->endpoints[gw];
 		endp->wildcarded_req = false;
 		return endp;
 	}
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 53cdc06..cb98ecb 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -1424,7 +1424,7 @@
 {
 	/* NOTE: The port that is used for RTCP is the RTP port incremented by one
 	 * (e.g. RTP-Port = 16000 ==> RTCP-Port = 16001) */
-	 struct mgcp_endpoint *endp = &cfg->trunk.endpoints[endpno];
+	 struct mgcp_endpoint *endp = &cfg->virt_trunk->endpoints[endpno];
 
 	if (mgcp_create_bind(source_addr, &rtp_end->rtp,
 			     rtp_end->local_port) != 0) {
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index 72d3b91..9f3a05f 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -202,9 +202,9 @@
 	struct mgcp_conn_rtp * conn_rtp;
 	int i;
 
-	for (i=0; i<cfg->trunk.number_endpoints; i++) {
+	for (i=0; i<cfg->virt_trunk->number_endpoints; i++) {
 
-		endp = &cfg->trunk.endpoints[i];
+		endp = &cfg->virt_trunk->endpoints[i];
 
 		llist_for_each_entry(conn, &endp->conns, entry) {
 			if (conn->type != MGCP_CONN_TYPE_RTP)
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 12fea1d..4021be6 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -1620,33 +1620,23 @@
 
 	cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default;
 
-	/* default trunk handling; TODO: avoid duplication with mgcp_trunk_alloc() below */
-	cfg->trunk.cfg = cfg;
-	cfg->trunk.trunk_nr = 0;
-	cfg->trunk.trunk_type = MGCP_TRUNK_VIRTUAL;
-	cfg->trunk.audio_name = talloc_strdup(cfg, "AMR/8000");
-	cfg->trunk.audio_payload = 126;
-	cfg->trunk.audio_send_ptime = 1;
-	cfg->trunk.audio_send_name = 1;
-	cfg->trunk.vty_number_endpoints = 33;
-	cfg->trunk.omit_rtcp = 0;
-	mgcp_trunk_set_keepalive(&cfg->trunk, MGCP_KEEPALIVE_ONCE);
-	if (alloc_mgcp_rate_counters(&cfg->trunk, cfg) < 0) {
+	/* default trunk handling */
+	cfg->virt_trunk = mgcp_trunk_alloc(cfg, MGCP_TRUNK_VIRTUAL, 0);
+	if (!cfg->virt_trunk) {
 		talloc_free(cfg);
 		return NULL;
 	}
-
 	INIT_LLIST_HEAD(&cfg->trunks);
 
 	return cfg;
 }
 
-/*! allocate configuration with default values.
+/*! allocate configuration with default values. Do not link it into global list yet!
  *  (called once at startup by VTY)
  *  \param[in] cfg mgcp configuration
  *  \param[in] nr trunk number
  *  \returns pointer to allocated trunk configuration */
-struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int nr)
+struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, enum mgcp_trunk_type ttype, int nr)
 {
 	struct mgcp_trunk_config *trunk;
 
@@ -1657,17 +1647,21 @@
 	}
 
 	trunk->cfg = cfg;
-	trunk->trunk_type = MGCP_TRUNK_E1;
+	trunk->trunk_type = ttype;
 	trunk->trunk_nr = nr;
-	trunk->audio_name = talloc_strdup(cfg, "AMR/8000");
+	trunk->audio_name = talloc_strdup(trunk, "AMR/8000");
 	trunk->audio_payload = 126;
 	trunk->audio_send_ptime = 1;
 	trunk->audio_send_name = 1;
 	trunk->vty_number_endpoints = 33;
 	trunk->omit_rtcp = 0;
 	mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
-	alloc_mgcp_rate_counters(trunk, trunk);
-	llist_add_tail(&trunk->entry, &cfg->trunks);
+	if (alloc_mgcp_rate_counters(trunk, trunk) < 0) {
+		talloc_free(trunk);
+		return NULL;
+	}
+	/* we don't add it to the list of trunks so this function can be used
+	 * for both the virtual as well as for further trunks */
 
 	return trunk;
 }
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 5f9853b..c9bb6b8 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -47,7 +47,7 @@
 	struct mgcp_trunk_config *trunk;
 
 	if (nr == 0)
-		trunk = &cfg->trunk;
+		trunk = cfg->virt_trunk;
 	else
 		trunk = mgcp_trunk_num(cfg, nr);
 
@@ -68,6 +68,8 @@
 
 static int config_write_mgcp(struct vty *vty)
 {
+	struct mgcp_trunk_config *trunk = g_cfg->virt_trunk;
+
 	vty_out(vty, "mgcp%s", VTY_NEWLINE);
 	vty_out(vty, "  domain %s%s", g_cfg->domain, VTY_NEWLINE);
 	if (g_cfg->local_ip)
@@ -85,50 +87,50 @@
 	else
 		vty_out(vty, "  no rtp ip-probing%s", VTY_NEWLINE);
 	vty_out(vty, "  rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
-	if (g_cfg->trunk.keepalive_interval == MGCP_KEEPALIVE_ONCE)
+	if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE)
 		vty_out(vty, "  rtp keep-alive once%s", VTY_NEWLINE);
-	else if (g_cfg->trunk.keepalive_interval)
+	else if (trunk->keepalive_interval)
 		vty_out(vty, "  rtp keep-alive %d%s",
-			g_cfg->trunk.keepalive_interval, VTY_NEWLINE);
+			trunk->keepalive_interval, VTY_NEWLINE);
 	else
 		vty_out(vty, "  no rtp keep-alive%s", VTY_NEWLINE);
 
-	if (g_cfg->trunk.omit_rtcp)
+	if (trunk->omit_rtcp)
 		vty_out(vty, "  rtcp-omit%s", VTY_NEWLINE);
 	else
 		vty_out(vty, "  no rtcp-omit%s", VTY_NEWLINE);
-	if (g_cfg->trunk.force_constant_ssrc
-	    || g_cfg->trunk.force_aligned_timing
-	    || g_cfg->trunk.rfc5993_hr_convert) {
+	if (trunk->force_constant_ssrc
+	    || trunk->force_aligned_timing
+	    || trunk->rfc5993_hr_convert) {
 		vty_out(vty, "  %srtp-patch ssrc%s",
-			g_cfg->trunk.force_constant_ssrc ? "" : "no ",
+			trunk->force_constant_ssrc ? "" : "no ",
 			VTY_NEWLINE);
 		vty_out(vty, "  %srtp-patch timestamp%s",
-			g_cfg->trunk.force_aligned_timing ? "" : "no ",
+			trunk->force_aligned_timing ? "" : "no ",
 			VTY_NEWLINE);
 		vty_out(vty, "  %srtp-patch rfc5993hr%s",
-			g_cfg->trunk.rfc5993_hr_convert ? "" : "no ",
+			trunk->rfc5993_hr_convert ? "" : "no ",
 			VTY_NEWLINE);
 	} else
 		vty_out(vty, "  no rtp-patch%s", VTY_NEWLINE);
-	if (g_cfg->trunk.audio_payload != -1)
+	if (trunk->audio_payload != -1)
 		vty_out(vty, "  sdp audio-payload number %d%s",
-			g_cfg->trunk.audio_payload, VTY_NEWLINE);
-	if (g_cfg->trunk.audio_name)
+			trunk->audio_payload, VTY_NEWLINE);
+	if (trunk->audio_name)
 		vty_out(vty, "  sdp audio-payload name %s%s",
-			g_cfg->trunk.audio_name, VTY_NEWLINE);
-	if (g_cfg->trunk.audio_fmtp_extra)
+			trunk->audio_name, VTY_NEWLINE);
+	if (trunk->audio_fmtp_extra)
 		vty_out(vty, "  sdp audio fmtp-extra %s%s",
-			g_cfg->trunk.audio_fmtp_extra, VTY_NEWLINE);
+			trunk->audio_fmtp_extra, VTY_NEWLINE);
 	vty_out(vty, "  %ssdp audio-payload send-ptime%s",
-		g_cfg->trunk.audio_send_ptime ? "" : "no ", VTY_NEWLINE);
+		trunk->audio_send_ptime ? "" : "no ", VTY_NEWLINE);
 	vty_out(vty, "  %ssdp audio-payload send-name%s",
-		g_cfg->trunk.audio_send_name ? "" : "no ", VTY_NEWLINE);
-	vty_out(vty, "  loop %u%s", ! !g_cfg->trunk.audio_loop, VTY_NEWLINE);
+		trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
+	vty_out(vty, "  loop %u%s", ! !trunk->audio_loop, VTY_NEWLINE);
 	vty_out(vty, "  number endpoints %u%s",
-		g_cfg->trunk.vty_number_endpoints - 1, VTY_NEWLINE);
+		trunk->vty_number_endpoints - 1, VTY_NEWLINE);
 	vty_out(vty, "  %sallow-transcoding%s",
-		g_cfg->trunk.no_audio_transcoding ? "no " : "", VTY_NEWLINE);
+		trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
 	if (g_cfg->call_agent_addr)
 		vty_out(vty, "  call-agent ip %s%s", g_cfg->call_agent_addr,
 			VTY_NEWLINE);
@@ -291,7 +293,7 @@
 	struct mgcp_trunk_config *trunk;
 	int show_stats = argc >= 1;
 
-	dump_trunk(vty, &g_cfg->trunk, show_stats);
+	dump_trunk(vty, g_cfg->virt_trunk, show_stats);
 
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry)
 	    dump_trunk(vty, trunk, show_stats);
@@ -342,7 +344,7 @@
 {
 	struct mgcp_trunk_config *trunk;
 
-	dump_mgcp_endpoint(vty, &g_cfg->trunk, argv[0]);
+	dump_mgcp_endpoint(vty, g_cfg->virt_trunk, argv[0]);
 	llist_for_each_entry(trunk, &g_cfg->trunks, entry)
 		dump_mgcp_endpoint(vty, trunk, argv[0]);
 
@@ -553,7 +555,7 @@
 	if (!txt)
 		return CMD_WARNING;
 
-	osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_fmtp_extra, txt);
+	osmo_talloc_replace_string(g_cfg, &g_cfg->virt_trunk->audio_fmtp_extra, txt);
 	talloc_free(txt);
 	return CMD_SUCCESS;
 }
@@ -562,7 +564,7 @@
       cfg_mgcp_allow_transcoding_cmd,
       "allow-transcoding", "Allow transcoding\n")
 {
-	g_cfg->trunk.no_audio_transcoding = 0;
+	g_cfg->virt_trunk->no_audio_transcoding = 0;
 	return CMD_SUCCESS;
 }
 
@@ -570,7 +572,7 @@
       cfg_mgcp_no_allow_transcoding_cmd,
       "no allow-transcoding", NO_STR "Allow transcoding\n")
 {
-	g_cfg->trunk.no_audio_transcoding = 1;
+	g_cfg->virt_trunk->no_audio_transcoding = 1;
 	return CMD_SUCCESS;
 }
 
@@ -582,7 +584,7 @@
       SDP_STR AUDIO_STR "Number\n" "Payload number\n")
 {
 	unsigned int payload = atoi(argv[0]);
-	g_cfg->trunk.audio_payload = payload;
+	g_cfg->virt_trunk->audio_payload = payload;
 	return CMD_SUCCESS;
 }
 
@@ -596,7 +598,7 @@
       "sdp audio-payload name NAME",
       SDP_STR AUDIO_STR "Name\n" "Payload name\n")
 {
-	osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]);
+	osmo_talloc_replace_string(g_cfg, &g_cfg->virt_trunk->audio_name, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -609,7 +611,7 @@
       "sdp audio-payload send-ptime",
       SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
 {
-	g_cfg->trunk.audio_send_ptime = 1;
+	g_cfg->virt_trunk->audio_send_ptime = 1;
 	return CMD_SUCCESS;
 }
 
@@ -618,7 +620,7 @@
       "no sdp audio-payload send-ptime",
       NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
 {
-	g_cfg->trunk.audio_send_ptime = 0;
+	g_cfg->virt_trunk->audio_send_ptime = 0;
 	return CMD_SUCCESS;
 }
 
@@ -627,7 +629,7 @@
       "sdp audio-payload send-name",
       SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
 {
-	g_cfg->trunk.audio_send_name = 1;
+	g_cfg->virt_trunk->audio_send_name = 1;
 	return CMD_SUCCESS;
 }
 
@@ -636,7 +638,7 @@
       "no sdp audio-payload send-name",
       NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
 {
-	g_cfg->trunk.audio_send_name = 0;
+	g_cfg->virt_trunk->audio_send_name = 0;
 	return CMD_SUCCESS;
 }
 
@@ -649,7 +651,7 @@
 		vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
 		return CMD_WARNING;
 	}
-	g_cfg->trunk.audio_loop = atoi(argv[0]);
+	g_cfg->virt_trunk->audio_loop = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -659,7 +661,7 @@
       "Force endpoint reallocation when the endpoint is still seized\n"
       "Don't force reallocation\n" "force reallocation\n")
 {
-	g_cfg->trunk.force_realloc = atoi(argv[0]);
+	g_cfg->virt_trunk->force_realloc = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -669,7 +671,7 @@
       "Accept all RTP packets, even when the originating IP/Port does not match\n"
       "enable filter\n" "disable filter\n")
 {
-	g_cfg->trunk.rtp_accept_all = atoi(argv[0]);
+	g_cfg->virt_trunk->rtp_accept_all = atoi(argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -679,20 +681,20 @@
       "Number options\n" "Endpoints available\n" "Number endpoints\n")
 {
 	/* + 1 as we start counting at one */
-	g_cfg->trunk.vty_number_endpoints = atoi(argv[0]) + 1;
+	g_cfg->virt_trunk->vty_number_endpoints = atoi(argv[0]) + 1;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_omit_rtcp, cfg_mgcp_omit_rtcp_cmd, "rtcp-omit", RTCP_OMIT_STR)
 {
-	g_cfg->trunk.omit_rtcp = 1;
+	g_cfg->virt_trunk->omit_rtcp = 1;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_no_omit_rtcp,
       cfg_mgcp_no_omit_rtcp_cmd, "no rtcp-omit", NO_STR RTCP_OMIT_STR)
 {
-	g_cfg->trunk.omit_rtcp = 0;
+	g_cfg->virt_trunk->omit_rtcp = 0;
 	return CMD_SUCCESS;
 }
 
@@ -700,7 +702,7 @@
       cfg_mgcp_patch_rtp_ssrc_cmd,
       "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
 {
-	g_cfg->trunk.force_constant_ssrc = 1;
+	g_cfg->virt_trunk->force_constant_ssrc = 1;
 	return CMD_SUCCESS;
 }
 
@@ -708,7 +710,7 @@
       cfg_mgcp_no_patch_rtp_ssrc_cmd,
       "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
 {
-	g_cfg->trunk.force_constant_ssrc = 0;
+	g_cfg->virt_trunk->force_constant_ssrc = 0;
 	return CMD_SUCCESS;
 }
 
@@ -716,7 +718,7 @@
       cfg_mgcp_patch_rtp_ts_cmd,
       "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
 {
-	g_cfg->trunk.force_aligned_timing = 1;
+	g_cfg->virt_trunk->force_aligned_timing = 1;
 	return CMD_SUCCESS;
 }
 
@@ -724,7 +726,7 @@
       cfg_mgcp_no_patch_rtp_ts_cmd,
       "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
 {
-	g_cfg->trunk.force_aligned_timing = 0;
+	g_cfg->virt_trunk->force_aligned_timing = 0;
 	return CMD_SUCCESS;
 }
 
@@ -732,7 +734,7 @@
       cfg_mgcp_patch_rtp_rfc5993hr_cmd,
       "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
 {
-	g_cfg->trunk.rfc5993_hr_convert = true;
+	g_cfg->virt_trunk->rfc5993_hr_convert = true;
 	return CMD_SUCCESS;
 }
 
@@ -740,16 +742,16 @@
       cfg_mgcp_no_patch_rtp_rfc5993hr_cmd,
       "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
 {
-	g_cfg->trunk.rfc5993_hr_convert = false;
+	g_cfg->virt_trunk->rfc5993_hr_convert = false;
 	return CMD_SUCCESS;
 }
 
 DEFUN(cfg_mgcp_no_patch_rtp,
       cfg_mgcp_no_patch_rtp_cmd, "no rtp-patch", NO_STR RTP_PATCH_STR)
 {
-	g_cfg->trunk.force_constant_ssrc = 0;
-	g_cfg->trunk.force_aligned_timing = 0;
-	g_cfg->trunk.rfc5993_hr_convert = false;
+	g_cfg->virt_trunk->force_constant_ssrc = 0;
+	g_cfg->virt_trunk->force_aligned_timing = 0;
+	g_cfg->virt_trunk->rfc5993_hr_convert = false;
 	return CMD_SUCCESS;
 }
 
@@ -758,7 +760,7 @@
       "rtp keep-alive <1-120>",
       RTP_STR RTP_KEEPALIVE_STR "Keep alive interval in secs\n")
 {
-	mgcp_trunk_set_keepalive(&g_cfg->trunk, atoi(argv[0]));
+	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, atoi(argv[0]));
 	return CMD_SUCCESS;
 }
 
@@ -767,7 +769,7 @@
       "rtp keep-alive once",
       RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n")
 {
-	mgcp_trunk_set_keepalive(&g_cfg->trunk, MGCP_KEEPALIVE_ONCE);
+	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, MGCP_KEEPALIVE_ONCE);
 	return CMD_SUCCESS;
 }
 
@@ -775,7 +777,7 @@
       cfg_mgcp_no_rtp_keepalive_cmd,
       "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR)
 {
-	mgcp_trunk_set_keepalive(&g_cfg->trunk, MGCP_KEEPALIVE_NEVER);
+	mgcp_trunk_set_keepalive(g_cfg->virt_trunk, MGCP_KEEPALIVE_NEVER);
 	return CMD_SUCCESS;
 }
 
@@ -801,8 +803,12 @@
 	int index = atoi(argv[0]);
 
 	trunk = mgcp_trunk_num(g_cfg, index);
-	if (!trunk)
-		trunk = mgcp_trunk_alloc(g_cfg, index);
+	if (!trunk) {
+		trunk = mgcp_trunk_alloc(g_cfg, MGCP_TRUNK_E1, index);
+		if (!trunk)
+			return CMD_WARNING;
+		llist_add_tail(&trunk->entry, &g_cfg->trunks);
+	}
 
 	if (!trunk) {
 		vty_out(vty, "%%Unable to allocate trunk %u.%s",
@@ -847,7 +853,7 @@
 		else
 			vty_out(vty, "  no rtcp-omit%s", VTY_NEWLINE);
 		if (trunk->force_constant_ssrc || trunk->force_aligned_timing
-		    || g_cfg->trunk.rfc5993_hr_convert) {
+		    || g_cfg->virt_trunk->rfc5993_hr_convert) {
 			vty_out(vty, "  %srtp-patch ssrc%s",
 				trunk->force_constant_ssrc ? "" : "no ",
 				VTY_NEWLINE);
@@ -1310,7 +1316,7 @@
 	else if (strcmp(argv[0], "only") == 0)
 		g_cfg->osmux = OSMUX_USAGE_ONLY;
 
-	if (g_cfg->trunk.audio_loop) {
+	if (g_cfg->virt_trunk->audio_loop) {
 		vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
 		return CMD_WARNING;
 	}
@@ -1511,10 +1517,10 @@
 		return -1;
 	}
 
-	if (mgcp_endpoints_allocate(&g_cfg->trunk) != 0) {
+	if (mgcp_endpoints_allocate(g_cfg->virt_trunk) != 0) {
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "Failed to initialize the virtual trunk (%d endpoints)\n",
-		     g_cfg->trunk.number_endpoints);
+		     g_cfg->virt_trunk->number_endpoints);
 		return -1;
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/17423
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I54762af6d417b849a24b6e71b6c5c996a5cb3fa6
Gerrit-Change-Number: 17423
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200308/3070710a/attachment.htm>


More information about the gerrit-log mailing list