pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39223?usp=email )
Change subject: Rename and cleanup code allocating rtp/rtcp ports in trunk
......................................................................
Rename and cleanup code allocating rtp/rtcp ports in trunk
Clean up pointers passed. Rename function since it's clearly operating
on trunk related fields through mutexes.
Change-Id: Ib894afcb61609c247883d5ccdd7b8fbf29b2cbf8
---
M include/osmocom/mgcp/mgcp_trunk.h
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_trunk.c
3 files changed, 45 insertions(+), 43 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/23/39223/1
diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h
index 68d37dd..8d87954 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -2,9 +2,10 @@
#include <osmocom/gsm/i460_mux.h>
#include <osmocom/abis/e1_input.h>
+#include <osmocom/mgcp/mgcp_conn.h>
+#include <osmocom/mgcp/mgcp_network.h>
#include <osmocom/mgcp/mgcp_ratectr.h>
-
#define LOGPTRUNK(trunk, cat, level, fmt, args...) \
LOGP(cat, level, "trunk:%u " fmt, \
trunk ? trunk->trunk_nr : 0, \
@@ -78,6 +79,7 @@
struct mgcp_trunk *mgcp_trunk_by_name(const struct mgcp_config *cfg, const char *epname);
int e1_trunk_nr_from_epname(unsigned int *trunk_nr, const char *epname);
struct mgcp_trunk *mgcp_trunk_by_line_num(const struct mgcp_config *cfg, unsigned int num);
+int mgcp_trunk_allocate_conn_rtp_ports(struct mgcp_trunk *trunk, struct mgcp_conn_rtp *conn);
/* The virtual trunk is always created on trunk id 0 for historical reasons,
* use this define constant as ID when allocating a virtual trunk. Other
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 3efa0e0..32fbd43 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -489,46 +489,6 @@
return create_ok_response(rq->trunk, rq->endp, 200, "AUEP", rq->pdata->trans);
}
-/* Try to find a free port by attempting to bind on it. Also handle the
- * counter that points on the next free port. Since we have a pointer
- * to the next free port, binding should in work on the first attempt in
- * general. In case of failure the next port is tried until the whole port
- * range is tried once. */
-static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
-{
- int i;
- struct mgcp_port_range *range;
- unsigned int tries;
-
- OSMO_ASSERT(conn);
-
- range = &endp->trunk->cfg->net_ports;
-
- pthread_mutex_lock(&range->lock);
- /* attempt to find a port */
- tries = (range->range_end - range->range_start) / 2;
- for (i = 0; i < tries; ++i) {
- int rc;
-
- if (range->last_port >= range->range_end)
- range->last_port = range->range_start;
-
- rc = mgcp_conn_rtp_bind_rtp_ports(conn, range->last_port);
-
- range->last_port += 2;
- if (rc == 0) {
- pthread_mutex_unlock(&range->lock);
- return 0;
- }
-
- }
- pthread_mutex_unlock(&range->lock);
- LOGPENDP(endp, DLMGCP, LOGL_ERROR,
- "Allocating a RTP/RTCP port failed %u times.\n",
- tries);
- return -1;
-}
-
/*! Helper function for check_local_cx_options() to get a pointer of the next
* lco option identifier
* \param[in] lco string
@@ -1077,7 +1037,7 @@
rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BIND_PORT));
goto error2;
}
- if (allocate_port(endp, conn_rtp) != 0) {
+ if (mgcp_trunk_allocate_conn_rtp_ports(trunk, conn_rtp) != 0) {
rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BIND_PORT));
goto error2;
}
@@ -1311,7 +1271,7 @@
if (strcmp(new_local_addr, conn_rtp->end.local_addr)) {
osmo_strlcpy(conn_rtp->end.local_addr, new_local_addr, sizeof(conn_rtp->end.local_addr));
mgcp_rtp_end_free_port(&conn_rtp->end);
- if (allocate_port(endp, conn_rtp) != 0) {
+ if (mgcp_trunk_allocate_conn_rtp_ports(trunk, conn_rtp) != 0) {
rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BIND_PORT));
goto error3;
}
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 69750f8..8d258e2 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -306,3 +306,43 @@
return NULL;
}
+
+/* Try to find a free port by attempting to bind on it. Also handle the
+ * counter that points on the next free port. Since we have a pointer
+ * to the next free port, binding should in work on the first attempt in
+ * general. In case of failure the next port is tried until the whole port
+ * range is tried once. */
+int mgcp_trunk_allocate_conn_rtp_ports(struct mgcp_trunk *trunk, struct mgcp_conn_rtp *conn)
+{
+ int i;
+ struct mgcp_port_range *range;
+ unsigned int tries;
+
+ OSMO_ASSERT(trunk);
+ OSMO_ASSERT(conn);
+
+ range = &trunk->cfg->net_ports;
+
+ pthread_mutex_lock(&range->lock);
+ /* attempt to find a port */
+ tries = (range->range_end - range->range_start) / 2;
+ for (i = 0; i < tries; ++i) {
+ int rc;
+
+ if (range->last_port >= range->range_end)
+ range->last_port = range->range_start;
+
+ rc = mgcp_conn_rtp_bind_rtp_ports(conn, range->last_port);
+
+ range->last_port += 2;
+ if (rc == 0) {
+ pthread_mutex_unlock(&range->lock);
+ return 0;
+ }
+
+ }
+ pthread_mutex_unlock(&range->lock);
+ LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
+ "Allocating a RTP/RTCP port failed %u times.\n", tries);
+ return -1;
+}
--
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39223?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: Ib894afcb61609c247883d5ccdd7b8fbf29b2cbf8
Gerrit-Change-Number: 39223
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39200?usp=email )
(
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
)Change subject: pcap-server: Resolve real path of pcap file before opening
......................................................................
pcap-server: Resolve real path of pcap file before opening
This means we always end up with a canonicalized absolute path.
While at it, also valdiate that we can indeed resolve the path (eg. it
exists and is reachable with current process permissions) during
startup.
It is preferrable to resolve it everytime a file is opened, this allows
the user to eg. change the base-path to a different symlink it they wish
to change the base-path for new pcaps without restarting osmo-pcap.
Change-Id: I8d161010dc8b480dd4cf90e19ca28a77914a50ad
---
M include/osmo-pcap/osmo_pcap_server.h
M src/osmo_server_network.c
M src/osmo_server_vty.c
3 files changed, 19 insertions(+), 4 deletions(-)
Approvals:
fixeria: Looks good to me, approved
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h
index 0a43a69..50bb121 100644
--- a/include/osmo-pcap/osmo_pcap_server.h
+++ b/include/osmo-pcap/osmo_pcap_server.h
@@ -87,6 +87,7 @@
/* Remote connection */
struct osmo_wqueue rem_wq;
int local_fd;
+ /* canonicalized absolute pathname of pcap file we write to */
char *curr_filename;
/* pcap stuff */
diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c
index 0b0073f..8747091 100644
--- a/src/osmo_server_network.c
+++ b/src/osmo_server_network.c
@@ -166,6 +166,7 @@
time_t now = time(NULL);
struct tm tm;
int rc;
+ char *real_base_path;
osmo_pcap_server_close_trace(conn);
@@ -178,11 +179,17 @@
}
localtime_r(&now, &tm);
+ real_base_path = realpath(conn->server->base_path, NULL);
+ if (!real_base_path) {
+ LOGP(DSERVER, LOGL_ERROR, "Failed to resolve real path '%s': %s\n",
+ conn->server->base_path, strerror(errno));
+ return;
+ }
conn->curr_filename = talloc_asprintf(conn, "%s/trace-%s-%d%.2d%.2d_%.2d%.2d%.2d.pcap",
- conn->server->base_path, conn->name,
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-
+ real_base_path, conn->name,
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
+ free(real_base_path);
if (!conn->curr_filename) {
LOGP(DSERVER, LOGL_ERROR, "Failed to assemble filename for %s.\n", conn->name);
return;
diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c
index c3014c9..ee3f995 100644
--- a/src/osmo_server_vty.c
+++ b/src/osmo_server_vty.c
@@ -148,6 +148,13 @@
"base-path PATH",
"Base path for log files\n" "Path\n")
{
+ /* Validate we can resolve path: */
+ char *tmp = realpath(argv[0], NULL);
+ if (!tmp) {
+ vty_out(vty, "%% Failed to resolve path '%s': %s%s", argv[0], strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ free(tmp);
osmo_talloc_replace_string(pcap_server, &pcap_server->base_path, argv[0]);
return CMD_SUCCESS;
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/39200?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I8d161010dc8b480dd4cf90e19ca28a77914a50ad
Gerrit-Change-Number: 39200
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39192?usp=email )
Change subject: pcap-server: remove unneeded check for null base_path
......................................................................
pcap-server: remove unneeded check for null base_path
It cannot be ever NULL. It is set to a non-null path during alloc(), and
it can only be replaced with another string through VTY.
Change-Id: I2f503f6f9af35d6ae6fbd03e85cade4f0eb93df2
---
M src/osmo_server_vty.c
1 file changed, 1 insertion(+), 2 deletions(-)
Approvals:
pespin: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c
index 6a44da6..c3014c9 100644
--- a/src/osmo_server_vty.c
+++ b/src/osmo_server_vty.c
@@ -96,8 +96,7 @@
vty_out(vty, "server%s", VTY_NEWLINE);
- if (pcap_server->base_path)
- vty_out(vty, " base-path %s%s", pcap_server->base_path, VTY_NEWLINE);
+ vty_out(vty, " base-path %s%s", pcap_server->base_path, VTY_NEWLINE);
vty_out(vty, " file-permission-mask 0%o%s", pcap_server->permission_mask, VTY_NEWLINE);
if (pcap_server->addr)
vty_out(vty, " server ip %s%s", pcap_server->addr, VTY_NEWLINE);
--
To view, visit https://gerrit.osmocom.org/c/osmo-pcap/+/39192?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I2f503f6f9af35d6ae6fbd03e85cade4f0eb93df2
Gerrit-Change-Number: 39192
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: laforge <laforge(a)osmocom.org>