Change in osmo-cbc[master]: Make ECBE (REST interface) local bind IP + port VTY-configurable

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 Jan 24 13:40:43 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-cbc/+/22402 )

Change subject: Make ECBE (REST interface) local bind IP + port VTY-configurable
......................................................................

Make ECBE (REST interface) local bind IP + port VTY-configurable

Change-Id: I656d0d1c7b21db90b62e71109d9844476a2e3215
---
M doc/manuals/chapters/configuration.adoc
M src/cbc_data.h
M src/cbc_main.c
M src/cbc_vty.c
M src/internal.h
M src/rest_api.c
6 files changed, 110 insertions(+), 13 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/doc/manuals/chapters/configuration.adoc b/doc/manuals/chapters/configuration.adoc
index c205d91..095aed5 100644
--- a/doc/manuals/chapters/configuration.adoc
+++ b/doc/manuals/chapters/configuration.adoc
@@ -1,12 +1,14 @@
 [[configuration]]
-== CBSP / Peer Configuration
+== Configuration
+
+=== CBSP / Peer Configuration
 
 CBSP is the BSC-CBC interface within the 3GPP architecture.  It serves
 to communicate CSB and ETWS messages from the CBC to the BSC, who then
 subsequently distributes it among the (matching) cells within the BSC
 coverage area.
 
-=== Configuring the CBSP connections
+==== Configuring the CBSP connections
 
 According to 3GPP TS 48.049, a BSC typically operates as a TCP server,
 and the CBC connects as TCP client.  This would require the CBC to have
@@ -46,7 +48,7 @@
 
 For more details on the available configuration commands, please check the OsmoCBC VTY Reference.
 
-=== Configuring the IP/Port for CBSP to bind to
+==== Configuring the IP/Port for CBSP to bind to
 
 It can be configure to which IP and TCP port the CBSP protocol binds to.
 
@@ -60,3 +62,20 @@
   local-ip 127.0.0.1
   local-port 48049
 ----
+
+=== ECBE (REST Interface) Configuration
+
+==== Configuring the IP/Port for ECBE to bind to
+
+It can be configure to which IP and TCP port the ECBE REST Interface binds to.
+
+The default is to bind to is the non-standard port number 12349 at the
+loopback IP address 127.0.0.1.
+
+.Example: Configure ECBE REST interface to bind to 127.0.0.1:8080
+----
+cbc
+ ecbe
+  local-ip 127.0.0.1
+  local-port 8080
+----
diff --git a/src/cbc_data.h b/src/cbc_data.h
index 76fdfad..e88ae45 100644
--- a/src/cbc_data.h
+++ b/src/cbc_data.h
@@ -169,6 +169,10 @@
 			char *local_host;
 			int local_port;
 		} cbsp;
+		struct {
+			char *local_host;
+			int local_port;
+		} ecbe;
 	} config;
 
 	struct llist_head messages;	/* cbc_message.list */
diff --git a/src/cbc_main.c b/src/cbc_main.c
index 168fd7d..ff696bd 100644
--- a/src/cbc_main.c
+++ b/src/cbc_main.c
@@ -1,6 +1,6 @@
 /* Osmocom CBC (Cell Broacast Centre) */
 
-/* (C) 2019 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2019-2021 by Harald Welte <laforge at gnumonks.org>
  * All Rights Reserved
  *
  * SPDX-License-Identifier: AGPL-3.0+
@@ -221,6 +221,8 @@
 	INIT_LLIST_HEAD(&g_cbc->expired_messages);
 	g_cbc->config.cbsp.local_host = talloc_strdup(g_cbc, "127.0.0.1");
 	g_cbc->config.cbsp.local_port = CBSP_TCP_PORT;
+	g_cbc->config.ecbe.local_host = talloc_strdup(g_cbc, "127.0.0.1");
+	g_cbc->config.ecbe.local_port = 12345;
 
 	cbc_vty_init();
 
@@ -245,7 +247,7 @@
 	cbsp_cbc_create(tall_cbc_ctx, g_cbc->config.cbsp.local_host, g_cbc->config.cbsp.local_port,
 			&cbc_client_rx_cb);
 
-	rest_api_init(tall_rest_ctx, 12345);
+	rest_api_init(tall_rest_ctx, g_cbc->config.ecbe.local_host, g_cbc->config.ecbe.local_port);
 
 	LOGP(DREST, LOGL_INFO, "Main thread tid: %lu\n", pthread_self());
 	g_cbc->it_q.rest2main = osmo_it_q_alloc(g_cbc, "rest2main", 10, rest2main_read_cb, NULL);
diff --git a/src/cbc_vty.c b/src/cbc_vty.c
index b1aa34f..98e2703 100644
--- a/src/cbc_vty.c
+++ b/src/cbc_vty.c
@@ -1,6 +1,6 @@
 /* Osmocom CBC (Cell Broacast Centre) */
 
-/* (C) 2019 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2019-2021 by Harald Welte <laforge at gnumonks.org>
  * All Rights Reserved
  *
  * SPDX-License-Identifier: AGPL-3.0+
@@ -268,6 +268,7 @@
 	CBC_NODE = _LAST_OSMOVTY_NODE + 1,
 	PEER_NODE,
 	CBSP_NODE,
+	ECBE_NODE,
 };
 
 static struct cmd_node cbc_node = {
@@ -319,6 +320,14 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_ecbe, cfg_ecbe_cmd,
+	"ecbe",
+	"External CBS Entity (REST Interface)\n")
+{
+	vty->node = ECBE_NODE;
+	return CMD_SUCCESS;
+}
+
 
 /* CBSP */
 
@@ -356,6 +365,43 @@
 }
 
 
+/* ECBE */
+
+static struct cmd_node ecbe_node = {
+	ECBE_NODE,
+	"%s(config-ecbe)# ",
+	1,
+};
+
+static int config_write_ecbe(struct vty *vty)
+{
+	vty_out(vty, " ecbe%s", VTY_NEWLINE);
+	vty_out(vty, "  local-ip %s%s", g_cbc->config.ecbe.local_host, VTY_NEWLINE);
+	vty_out(vty, "  local-port %u%s", g_cbc->config.ecbe.local_port, VTY_NEWLINE);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ecbe_local_ip, cfg_ecbe_local_ip_cmd,
+	"local-ip (A.B.C.D|X:X::X:X)",
+	"Local IP address for CBSP\n"
+	"Local IPv4 address for ECBE REST Interface\n"
+	"Local IPv6 address for ECBE REST Interface\n")
+{
+	osmo_talloc_replace_string(g_cbc, &g_cbc->config.ecbe.local_host, argv[0]);
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ecbe_local_port, cfg_ecbe_local_port_cmd,
+	"local-port <0-65535>",
+	"Local TCP port for ECBE RESET Interface\n"
+	"Local TCP port for ECBE RESET Interface\n")
+{
+	g_cbc->config.ecbe.local_port = atoi(argv[0]);
+	return CMD_SUCCESS;
+}
+
+
 /* PEER */
 
 DEFUN(cfg_cbc_peer, cfg_cbc_peer_cmd,
@@ -469,6 +515,11 @@
 	install_lib_element(CBSP_NODE, &cfg_cbsp_local_ip_cmd);
 	install_lib_element(CBSP_NODE, &cfg_cbsp_local_port_cmd);
 
+	install_lib_element(CBC_NODE, &cfg_ecbe_cmd);
+	install_node(&ecbe_node, config_write_ecbe);
+	install_lib_element(ECBE_NODE, &cfg_ecbe_local_ip_cmd);
+	install_lib_element(ECBE_NODE, &cfg_ecbe_local_port_cmd);
+
 	install_lib_element(CBC_NODE, &cfg_cbc_peer_cmd);
 	install_lib_element(CBC_NODE, &cfg_cbc_no_peer_cmd);
 	install_node(&peer_node, config_write_peer);
diff --git a/src/internal.h b/src/internal.h
index e493c86..29093b5 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -25,7 +25,7 @@
 
 
 /* rest_api.c */
-int rest_api_init(void *ctx, uint16_t port);
+int rest_api_init(void *ctx, const char *bind_addr, uint16_t port);
 void rest_api_fin(void);
 
 /* cbc_vty.c */
diff --git a/src/rest_api.c b/src/rest_api.c
index 9473a01..91e7d40 100644
--- a/src/rest_api.c
+++ b/src/rest_api.c
@@ -1,6 +1,6 @@
 /* Osmocom CBC (Cell Broacast Centre) */
 
-/* (C) 2019-2020 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2019-2021 by Harald Welte <laforge at gnumonks.org>
  * All Rights Reserved
  *
  * SPDX-License-Identifier: AGPL-3.0+
@@ -31,6 +31,7 @@
 
 #include <osmocom/core/utils.h>
 #include <osmocom/core/linuxlist.h>
+#include <osmocom/core/sockaddr_str.h>
 
 #include <osmocom/gsm/protocol/gsm_48_049.h>
 
@@ -677,8 +678,9 @@
 }
 #endif
 
-int rest_api_init(void *ctx, uint16_t port)
+int rest_api_init(void *ctx, const char *bind_addr, uint16_t port)
 {
+	struct osmo_sockaddr_str sastr;
 	int i;
 
 #ifdef ULFIUS_MALLOC_NOT_BROKEN
@@ -687,18 +689,37 @@
 	o_set_alloc_funcs(my_o_malloc, my_o_realloc, my_o_free);
 #endif
 
-	if (ulfius_init_instance(&g_instance, port, NULL, NULL) != U_OK)
-		return -1;
+	OSMO_STRLCPY_ARRAY(sastr.ip, bind_addr);
+	sastr.port = port;
+
+	if (strchr(bind_addr, ':')) {
+#if (ULFIUS_VERSION_MAJOR > 2) || (ULFIUS_VERSION_MAJOR == 2) && (ULFIUS_VERSION_MINOR >= 6)
+		struct sockaddr_in6 sin6;
+		sastr.af = AF_INET6;
+		osmo_sockaddr_str_to_sockaddr_in6(&sastr, &sin6);
+		if (ulfius_init_instance_ipv6(&g_instance, port, &sin6, U_USE_IPV6, NULL) != U_OK)
+			return -1;
+#else
+		LOGP(DREST, LOGL_FATAL, "IPv6 requires ulfius version >= 2.6\n");
+		return -2;
+#endif
+	} else {
+		struct sockaddr_in sin;
+		sastr.af = AF_INET;
+		osmo_sockaddr_str_to_sockaddr_in(&sastr, &sin);
+		if (ulfius_init_instance(&g_instance, port, &sin, NULL) != U_OK)
+			return -1;
+	}
 	g_instance.mhd_response_copy_data = 1;
 
 	for (i = 0; i < ARRAY_SIZE(api_endpoints); i++)
 		ulfius_add_endpoint(&g_instance, &api_endpoints[i]);
 
 	if (ulfius_start_framework(&g_instance) != U_OK) {
-		LOGP(DREST, LOGL_FATAL, "Cannot start REST API on port %u\n", port);
+		LOGP(DREST, LOGL_FATAL, "Cannot start ECBE REST API at %s:%u\n", bind_addr, port);
 		return -1;
 	}
-	LOGP(DREST, LOGL_NOTICE, "Started REST API on port %u\n", port);
+	LOGP(DREST, LOGL_NOTICE, "Started ECBE REST API at %s:%u\n", bind_addr, port);
 	return 0;
 }
 

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

Gerrit-Project: osmo-cbc
Gerrit-Branch: master
Gerrit-Change-Id: I656d0d1c7b21db90b62e71109d9844476a2e3215
Gerrit-Change-Number: 22402
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210124/c747e1f3/attachment.htm>


More information about the gerrit-log mailing list