aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-05-22 13:44:34 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2018-05-24 10:21:31 +0200
commita19547b7a1f81ac2efe896983d2a4fa9169ec506 (patch)
treea6083af469ee8338548f60b0c1b6b18cf56be87f
parent06823731d819646e87e243e45373b83fd4b4445e (diff)
vty: clean up rtp port-range command
The VTY command that sets the RTP port range does not check if the data entered by the user actually makes sens. Also it allwos to configur a range that starts at 0. - Make sure 0 can not be used as start or end of the range - make sure the end port number is always greater then the begin port number - Autocorrect uneaven port range beginnings to one port number before to ensure the range starts at an even port number - Autocorrect even port range ends to the next odd port number to ensure the range ends at an odd port number. Change-Id: Ib1312acba4f03f378594dbbeb4f31afd891d68d7 Related: OS#2825
-rw-r--r--src/libosmo-mgcp/mgcp_vty.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 392a1762c..3c1b59679 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -282,13 +282,6 @@ DEFUN(cfg_mgcp_bind_early,
return CMD_WARNING;
}
-static void parse_range(struct mgcp_port_range *range, const char **argv)
-{
- range->range_start = atoi(argv[0]);
- range->range_end = atoi(argv[1]);
- range->last_port = g_cfg->net_ports.range_start;
-}
-
#define RTP_STR "RTP configuration\n"
#define UDP_PORT_STR "UDP Port number\n"
#define NET_START_STR "First UDP port allocated\n"
@@ -297,11 +290,38 @@ static void parse_range(struct mgcp_port_range *range, const char **argv)
DEFUN(cfg_mgcp_rtp_port_range,
cfg_mgcp_rtp_port_range_cmd,
- "rtp port-range <0-65534> <0-65534>",
+ "rtp port-range <1024-65534> <1025-65535>",
RTP_STR "Range of ports to use for the NET side\n"
RANGE_START_STR RANGE_END_STR)
{
- parse_range(&g_cfg->net_ports, argv);
+ int start;
+ int end;
+
+ start = atoi(argv[0]);
+ end = atoi(argv[1]);
+
+ if (end < start) {
+ vty_out(vty, "range end port (%i) must be greater than the range start port (%i)!%s",
+ end, start, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (start & 1) {
+ vty_out(vty, "range must begin at an even port number, autocorrecting port (%i) to: %i%s",
+ start, start & 0xFFFE, VTY_NEWLINE);
+ start &= 0xFFFE;
+ }
+
+ if ((end & 1) == 0) {
+ vty_out(vty, "range must end at an odd port number, autocorrecting port (%i) to: %i%s",
+ end, end | 1, VTY_NEWLINE);
+ end |= 1;
+ }
+
+ g_cfg->net_ports.range_start = start;
+ g_cfg->net_ports.range_end = end;
+ g_cfg->net_ports.last_port = g_cfg->net_ports.range_start;
+
return CMD_SUCCESS;
}
ALIAS_DEPRECATED(cfg_mgcp_rtp_port_range,