laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26659 )
Change subject: Add vty interface
......................................................................
Add vty interface
Related: OS#2545
Change-Id: I6f2d8d1d62b97be471ebcf1bb14aac0b895833d1
---
M include/osmocom/bsc_nat/Makefile.am
M include/osmocom/bsc_nat/bsc_nat.h
A include/osmocom/bsc_nat/logging.h
A include/osmocom/bsc_nat/vty.h
M src/osmo-bsc-nat/Makefile.am
A src/osmo-bsc-nat/bsc_nat.c
A src/osmo-bsc-nat/logging.c
M src/osmo-bsc-nat/main.c
A src/osmo-bsc-nat/vty.c
9 files changed, 297 insertions(+), 0 deletions(-)
Approvals:
laforge: Looks good to me, approved; Verified
pespin: Looks good to me, but someone else must approve
diff --git a/include/osmocom/bsc_nat/Makefile.am b/include/osmocom/bsc_nat/Makefile.am
index 158ca4b..f573dd9 100644
--- a/include/osmocom/bsc_nat/Makefile.am
+++ b/include/osmocom/bsc_nat/Makefile.am
@@ -1,3 +1,5 @@
noinst_HEADERS = \
bsc_nat.h \
+ logging.h \
+ vty.h \
$(NULL)
diff --git a/include/osmocom/bsc_nat/bsc_nat.h b/include/osmocom/bsc_nat/bsc_nat.h
index bbdf826..511d5a4 100644
--- a/include/osmocom/bsc_nat/bsc_nat.h
+++ b/include/osmocom/bsc_nat/bsc_nat.h
@@ -17,3 +17,12 @@
*
*/
#pragma once
+
+struct bsc_nat {
+};
+
+struct bsc_nat *bsc_nat_alloc(void *tall_ctx);
+void bsc_nat_free(struct bsc_nat *bsc_nat);
+
+extern void *tall_bsc_nat_ctx;
+extern struct bsc_nat *g_bsc_nat;
diff --git a/include/osmocom/bsc_nat/logging.h b/include/osmocom/bsc_nat/logging.h
new file mode 100644
index 0000000..88f67b0
--- /dev/null
+++ b/include/osmocom/bsc_nat/logging.h
@@ -0,0 +1,27 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later 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 PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+#pragma once
+
+#include <osmocom/core/logging.h>
+
+enum {
+ DMAIN,
+};
+
+extern const struct log_info bsc_nat_log_info;
diff --git a/include/osmocom/bsc_nat/vty.h b/include/osmocom/bsc_nat/vty.h
new file mode 100644
index 0000000..f882c23
--- /dev/null
+++ b/include/osmocom/bsc_nat/vty.h
@@ -0,0 +1,31 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later 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 PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/buffer.h>
+#include <osmocom/vty/command.h>
+
+enum bsc_nat_vty_nodes {
+ BSC_NAT_NODE = _LAST_OSMOVTY_NODE,
+};
+
+void bsc_nat_vty_init(void);
+int bsc_nat_vty_go_parent(struct vty *vty);
diff --git a/src/osmo-bsc-nat/Makefile.am b/src/osmo-bsc-nat/Makefile.am
index 9d0bf3e..9aa9524 100644
--- a/src/osmo-bsc-nat/Makefile.am
+++ b/src/osmo-bsc-nat/Makefile.am
@@ -25,7 +25,10 @@
$(NULL)
osmo_bsc_nat_SOURCES = \
+ bsc_nat.c \
+ logging.c \
main.c \
+ vty.c \
$(NULL)
osmo_bsc_nat_LDADD = \
diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
new file mode 100644
index 0000000..149e7cb
--- /dev/null
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -0,0 +1,38 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later 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 PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#include "config.h"
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/bsc_nat/bsc_nat.h>
+
+struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
+{
+ struct bsc_nat *bsc_nat;
+
+ bsc_nat = talloc_zero(tall_ctx, struct bsc_nat);
+ OSMO_ASSERT(bsc_nat);
+
+ return bsc_nat;
+}
+
+void bsc_nat_free(struct bsc_nat *bsc_nat)
+{
+ talloc_free(bsc_nat);
+}
diff --git a/src/osmo-bsc-nat/logging.c b/src/osmo-bsc-nat/logging.c
new file mode 100644
index 0000000..5ada8c2
--- /dev/null
+++ b/src/osmo-bsc-nat/logging.c
@@ -0,0 +1,37 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later 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 PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+
+#include <osmocom/bsc_nat/logging.h>
+
+static const struct log_info_cat log_cat[] = {
+ [DMAIN] = {
+ .name = "DMAIN",
+ .loglevel = LOGL_NOTICE,
+ .enabled = 1,
+ .color = "",
+ .description = "Main program",
+ },
+};
+
+const struct log_info bsc_nat_log_info = {
+ .cat = log_cat,
+ .num_cat = ARRAY_SIZE(log_cat),
+};
diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c
index 8775af1..813909b 100644
--- a/src/osmo-bsc-nat/main.c
+++ b/src/osmo-bsc-nat/main.c
@@ -19,7 +19,78 @@
#include "config.h"
+#include <osmocom/core/application.h>
+#include <osmocom/vty/cpu_sched_vty.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/misc.h>
+#include <osmocom/vty/ports.h>
+#include <osmocom/vty/telnet_interface.h>
+
+#include <osmocom/bsc_nat/bsc_nat.h>
+#include <osmocom/bsc_nat/logging.h>
+#include <osmocom/bsc_nat/vty.h>
+
+static const char *const copyright =
+ "OsmoBSCNAT - Osmocom BSC NAT\r\n"
+ "Copyright (C) 2021 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de>\r\n"
+ "Author: Oliver Smith\r\n"
+ "License AGPLv3+: GNU AGPL version 3 or later
<http://gnu.org/licenses/agpl-3.0.html>\r\n"
+ "This is free software: you are free to change and redistribute it.\r\n"
+ "There is NO WARRANTY, to the extent permitted by law.\r\n";
+
+void *tall_bsc_nat_ctx;
+struct bsc_nat *g_bsc_nat;
+
+static struct vty_app_info vty_info = {
+ .name = "OsmoBSCNAT",
+ .version = PACKAGE_VERSION,
+ .go_parent_cb = bsc_nat_vty_go_parent,
+};
+
+static void main_vty_init()
+{
+ int rc;
+
+ vty_info.copyright = copyright;
+ vty_info.tall_ctx = tall_bsc_nat_ctx;
+ vty_init(&vty_info);
+
+ bsc_nat_vty_init();
+
+ logging_vty_add_cmds();
+ osmo_talloc_vty_add_cmds();
+ osmo_cpu_sched_vty_init(tall_bsc_nat_ctx);
+
+ rc = telnet_init_dynif(tall_bsc_nat_ctx, g_bsc_nat, vty_get_bind_addr(),
OSMO_VTY_PORT_BSC_NAT);
+ if (rc < 0) {
+ perror("Error binding VTY port");
+ exit(1);
+ }
+}
+
int main(int argc, char **argv)
{
+ int rc;
+
+ talloc_enable_null_tracking();
+ tall_bsc_nat_ctx = talloc_named_const(NULL, 0, "bsc_nat");
+
+ rc = osmo_init_logging2(tall_bsc_nat_ctx, &bsc_nat_log_info);
+ if (rc < 0)
+ exit(1);
+
+ g_bsc_nat = bsc_nat_alloc(tall_bsc_nat_ctx);
+
+ main_vty_init();
+
+ while (!osmo_select_shutdown_done())
+ osmo_select_main_ctx(0);
+
+ talloc_report_full(tall_bsc_nat_ctx, stderr);
+ talloc_free(tall_bsc_nat_ctx);
+ talloc_free(tall_vty_ctx);
+ talloc_report_full(NULL, stderr);
+ talloc_disable_null_tracking();
+
return 0;
}
diff --git a/src/osmo-bsc-nat/vty.c b/src/osmo-bsc-nat/vty.c
new file mode 100644
index 0000000..089d27b
--- /dev/null
+++ b/src/osmo-bsc-nat/vty.c
@@ -0,0 +1,79 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later 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 PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#include "config.h"
+
+#include <unistd.h>
+
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/command.h>
+
+#include <osmocom/bsc_nat/bsc_nat.h>
+#include <osmocom/bsc_nat/vty.h>
+
+int bsc_nat_vty_go_parent(struct vty *vty)
+{
+ switch (vty->node) {
+ case BSC_NAT_NODE:
+ vty->node = CONFIG_NODE;
+ vty->index = g_bsc_nat;
+ break;
+ case CONFIG_NODE:
+ vty->node = ENABLE_NODE;
+ vty->index = NULL;
+ break;
+ default:
+ vty->node = CONFIG_NODE;
+ vty->index = NULL;
+ break;
+ }
+
+ return vty->node;
+}
+
+static struct cmd_node bsc_nat_node = {
+ BSC_NAT_NODE,
+ "%s(config-bsc-nat)# ",
+ 1,
+};
+
+DEFUN(cfg_bsc_nat,
+ cfg_bsc_nat_cmd,
+ "bsc-nat", "Configure the BSC NAT\n")
+{
+ OSMO_ASSERT(g_bsc_nat);
+ vty->index = g_bsc_nat;
+ vty->node = BSC_NAT_NODE;
+
+ return CMD_SUCCESS;
+}
+
+static int config_write_bsc_nat(struct vty *vty)
+{
+ vty_out(vty, "bsc-nat%s", VTY_NEWLINE);
+ return CMD_SUCCESS;
+}
+
+
+void bsc_nat_vty_init(void)
+{
+ install_element(CONFIG_NODE, &cfg_bsc_nat_cmd);
+ install_node(&bsc_nat_node, config_write_bsc_nat);
+}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26659
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: I6f2d8d1d62b97be471ebcf1bb14aac0b895833d1
Gerrit-Change-Number: 26659
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: merged