lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

May 2023

  • 1 participants
  • 2583 discussions
[L] Change in osmo-hnbgw[master]: move main() to separate file
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32620 ) Change subject: move main() to separate file ...................................................................... move main() to separate file Conform to recent osmocom practice by having an osmo_hnbgw_main.c file for main() and its immediate infrastructure. Prepares for adding a non-installed libhnbgw.la -- which must not contain a main() function -- so that linking regression tests is easy. Separating to a new file seems appropriate because hnbgw.c has gathered a bunch of stuff that is not strictly main() related / might be useful to access in a C test. Change-Id: I5f26a6b68f0d380617d73371f40f3b9055cac362 --- M include/osmocom/hnbgw/hnbgw.h M src/osmo-hnbgw/Makefile.am M src/osmo-hnbgw/hnbgw.c A src/osmo-hnbgw/osmo_hnbgw_main.c 4 files changed, 417 insertions(+), 379 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/20/32620/1 diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 954a356..e3ec38b 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -23,6 +23,9 @@ DCN, }; +extern const struct log_info hnbgw_log_info; +extern struct vty_app_info hnbgw_vty_info; + #define LOGHNB(HNB_CTX, ss, lvl, fmt, args ...) \ LOGP(ss, lvl, "(%s) " fmt, hnb_context_name(HNB_CTX), ## args) @@ -171,7 +174,13 @@ extern struct hnbgw *g_hnbgw; extern void *talloc_asn1_ctx; -struct hnb_context *hnb_context_by_id(uint32_t cid); +void g_hnbgw_alloc(void *ctx); + +int hnbgw_rua_accept_cb(struct osmo_stream_srv_link *srv, int fd); +int hnb_ctrl_cmds_install(void); +int hnb_ctrl_node_lookup(void *data, vector vline, int *node_type, void **node_data, int *i); +int hnbgw_mgw_setup(void); + struct hnb_context *hnb_context_by_identity_info(const char *identity_info); const char *hnb_context_name(struct hnb_context *ctx); @@ -182,7 +191,6 @@ uint32_t tmsi); void ue_context_free(struct ue_context *ue); -struct hnb_context *hnb_context_alloc(struct osmo_stream_srv_link *link, int new_fd); void hnb_context_release(struct hnb_context *ctx); void hnb_context_release_ue_state(struct hnb_context *ctx); diff --git a/src/osmo-hnbgw/Makefile.am b/src/osmo-hnbgw/Makefile.am index d1179e4..de96128 100644 --- a/src/osmo-hnbgw/Makefile.am +++ b/src/osmo-hnbgw/Makefile.am @@ -43,6 +43,7 @@ ranap_rab_ass.c \ mgw_fsm.c \ tdefs.c \ + osmo_hnbgw_main.c \ $(NULL) osmo_hnbgw_LDADD = \ diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index bad7064..8876580 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -1,7 +1,7 @@ -/* main application for hnb-gw part of osmo-iuh */ +/* kitchen sink for OsmoHNBGW implementation */ /* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> - * (C) 2016 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * (C) 2016-2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -19,49 +19,14 @@ * */ -#include "config.h" - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <getopt.h> -#include <errno.h> -#include <signal.h> -#include <stdbool.h> - -#include <sys/types.h> -#include <sys/socket.h> #include <netinet/in.h> #include <netinet/sctp.h> -#include <arpa/inet.h> -#include <osmocom/core/application.h> -#include <osmocom/core/talloc.h> -#include <osmocom/core/select.h> -#include <osmocom/core/logging.h> -#include <osmocom/core/socket.h> -#include <osmocom/core/msgb.h> -#include <osmocom/core/write_queue.h> -#include <osmocom/ctrl/control_if.h> -#include <osmocom/ctrl/control_cmd.h> -#include <osmocom/ctrl/control_vty.h> -#include <osmocom/ctrl/ports.h> -#include <osmocom/vty/telnet_interface.h> -#include <osmocom/vty/logging.h> -#include <osmocom/vty/misc.h> -#include <osmocom/vty/command.h> -#include <osmocom/vty/ports.h> - -#include <osmocom/mgcp_client/mgcp_client.h> +#include <osmocom/vty/vty.h> #include <osmocom/netif/stream.h> -#include <osmocom/ranap/ranap_common.h> - -#include <osmocom/sigtran/protocol/m3ua.h> -#include <osmocom/sigtran/sccp_sap.h> - +#include "config.h" #if ENABLE_PFCP #include <osmocom/pfcp/pfcp_proto.h> #endif @@ -69,21 +34,11 @@ #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/hnbgw_hnbap.h> #include <osmocom/hnbgw/hnbgw_rua.h> -#include <osmocom/hnbgw/hnbgw_cn.h> -#include <osmocom/hnbgw/hnbgw_pfcp.h> #include <osmocom/hnbgw/context_map.h> -static const char * const osmo_hnbgw_copyright = - "OsmoHNBGW - Osmocom Home Node B Gateway implementation\r\n" - "Copyright (C) 2016 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de>\r\n" - "Contributions by Daniel Willmann, Harald Welte, Neels Hofmeyr\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"; - struct hnbgw *g_hnbgw = NULL; -static void g_hnbgw_alloc(void *ctx) +void g_hnbgw_alloc(void *ctx) { OSMO_ASSERT(!g_hnbgw); g_hnbgw = talloc_zero(ctx, struct hnbgw); @@ -106,7 +61,7 @@ #endif } -struct hnb_context *hnb_context_by_id(uint32_t cid) +static struct hnb_context *hnb_context_by_id(uint32_t cid) { struct hnb_context *hnb; @@ -164,7 +119,7 @@ return NULL; } -void ue_context_free_by_hnb(const struct hnb_context *hnb) +static void ue_context_free_by_hnb(const struct hnb_context *hnb) { struct ue_context *ue, *tmp; @@ -334,7 +289,7 @@ return 0; } -struct hnb_context *hnb_context_alloc(struct osmo_stream_srv_link *link, int new_fd) +static struct hnb_context *hnb_context_alloc(struct osmo_stream_srv_link *link, int new_fd) { struct hnb_context *ctx; @@ -416,7 +371,7 @@ } /*! call-back when the listen FD has something to read */ -static int accept_cb(struct osmo_stream_srv_link *srv, int fd) +int hnbgw_rua_accept_cb(struct osmo_stream_srv_link *srv, int fd) { struct hnb_context *ctx; @@ -430,185 +385,6 @@ return 0; } -static const struct log_info_cat log_cat[] = { - [DMAIN] = { - .name = "DMAIN", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = "", - .description = "Main program", - }, - [DHNBAP] = { - .name = "DHNBAP", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = "", - .description = "Home Node B Application Part", - }, - [DRUA] = { - .name = "DRUA", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = "", - .description = "RANAP User Adaptation", - }, - [DRANAP] = { - .name = "DRANAP", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = "", - .description = "RAN Application Part", - }, - [DMGW] = { - .name = "DMGW", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = "\033[1;33m", - .description = "Media Gateway", - }, - [DHNB] = { - .name = "DHNB", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = OSMO_LOGCOLOR_CYAN, - .description = "HNB side (via RUA)", - }, - [DCN] = { - .name = "DCN", .loglevel = LOGL_NOTICE, .enabled = 1, - .color = OSMO_LOGCOLOR_DARKYELLOW, - .description = "Core Network side (via SCCP)", - }, -}; - -static const struct log_info hnbgw_log_info = { - .cat = log_cat, - .num_cat = ARRAY_SIZE(log_cat), -}; - -static struct vty_app_info vty_info = { - .name = "OsmoHNBGW", - .version = PACKAGE_VERSION, - .go_parent_cb = hnbgw_vty_go_parent, -}; - -static struct { - int daemonize; - const char *config_file; - bool log_disable_color; - bool log_enable_timestamp; - int log_level; - const char *log_category_mask; -} hnbgw_cmdline_config = { - 0, - "osmo-hnbgw.cfg", - false, - false, - 0, - NULL, -}; - -static void print_usage() -{ - printf("Usage: osmo-hnbgw\n"); -} - -static void print_help() -{ - printf(" -h --help This text.\n"); - printf(" -d option --debug=DHNBAP:DRUA:DRANAP:DMAIN Enable debugging.\n"); - printf(" -D --daemonize Fork the process into a background daemon.\n"); - printf(" -c --config-file filename The config file to use.\n"); - printf(" -s --disable-color\n"); - printf(" -T --timestamp Prefix every log line with a timestamp.\n"); - printf(" -V --version Print the version of OsmoHNBGW.\n"); - printf(" -e --log-level number Set a global loglevel.\n"); - - printf("\nVTY reference generation:\n"); - printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n"); - printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n"); -} - -static void handle_long_options(const char *prog_name, const int long_option) -{ - static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT; - - switch (long_option) { - case 1: - vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg); - if (vty_ref_mode < 0) { - fprintf(stderr, "%s: Unknown VTY reference generation " - "mode '%s'\n", prog_name, optarg); - exit(2); - } - break; - case 2: - fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n", - get_value_string(vty_ref_gen_mode_names, vty_ref_mode), - get_value_string(vty_ref_gen_mode_desc, vty_ref_mode)); - vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode); - exit(0); - default: - fprintf(stderr, "%s: error parsing cmdline options\n", prog_name); - exit(2); - } -} - -static void handle_options(int argc, char **argv) -{ - while (1) { - int option_index = 0, c; - static int long_option = 0; - static struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"debug", 1, 0, 'd'}, - {"daemonize", 0, 0, 'D'}, - {"config-file", 1, 0, 'c'}, - {"disable-color", 0, 0, 's'}, - {"timestamp", 0, 0, 'T'}, - {"version", 0, 0, 'V' }, - {"log-level", 1, 0, 'e'}, - {"vty-ref-mode", 1, &long_option, 1}, - {"vty-ref-xml", 0, &long_option, 2}, - {0, 0, 0, 0} - }; - - c = getopt_long(argc, argv, "hd:Dc:sTVe:", - long_options, &option_index); - if (c == -1) - break; - - switch (c) { - case 0: - handle_long_options(argv[0], long_option); - break; - case 'h': - print_usage(); - print_help(); - exit(0); - case 's': - hnbgw_cmdline_config.log_disable_color = true; - break; - case 'd': - hnbgw_cmdline_config.log_category_mask = optarg; - break; - case 'D': - hnbgw_cmdline_config.daemonize = 1; - break; - case 'c': - hnbgw_cmdline_config.config_file = optarg; - break; - case 'T': - hnbgw_cmdline_config.log_enable_timestamp = true; - break; - case 'e': - hnbgw_cmdline_config.log_level = atoi(optarg); - break; - case 'V': - print_version(1); - exit(0); - break; - default: - /* catch unknown options *as well as* missing arguments. */ - fprintf(stderr, "Error in command line options. Exiting.\n"); - exit(-1); - break; - } - } - - if (argc > optind) { - fprintf(stderr, "Unsupported positional arguments on command line\n"); - exit(2); - } -} - CTRL_CMD_DEFINE_RO(hnb_info, "info"); static int get_hnb_info(struct ctrl_cmd *cmd, void *data) { @@ -627,7 +403,7 @@ return CTRL_CMD_REPLY; } -int hnb_ctrl_cmds_install() +int hnb_ctrl_cmds_install(void) { int rc = 0; @@ -637,7 +413,7 @@ return rc; } -static int hnb_ctrl_node_lookup(void *data, vector vline, int *node_type, void **node_data, int *i) +int hnb_ctrl_node_lookup(void *data, vector vline, int *node_type, void **node_data, int *i) { const char *token = vector_slot(vline, *i); struct hnb_context *hnb; @@ -667,7 +443,7 @@ return 1; } -static int hnbgw_mgw_setup(void) +int hnbgw_mgw_setup(void) { struct mgcp_client *mgcp_client_single; unsigned int pool_members_initalized; @@ -706,147 +482,6 @@ return 0; } -int main(int argc, char **argv) -{ - struct osmo_stream_srv_link *srv; - int rc; - - talloc_enable_null_tracking(); - - /* g_hnbgw serves as the root talloc ctx, so allocate with NULL parent */ - g_hnbgw_alloc(NULL); - g_hnbgw->config.rnc_id = 23; - - talloc_asn1_ctx = talloc_named_const(g_hnbgw, 1, "asn1_context"); - msgb_talloc_ctx_init(g_hnbgw, 0); - - rc = osmo_init_logging2(g_hnbgw, &hnbgw_log_info); - if (rc < 0) - exit(1); - - osmo_fsm_log_timeouts(true); - - rc = osmo_ss7_init(); - if (rc < 0) { - LOGP(DMAIN, LOGL_FATAL, "osmo_ss7_init() failed with rc=%d\n", rc); - exit(1); - } - - vty_info.tall_ctx = g_hnbgw; - vty_info.copyright = osmo_hnbgw_copyright; - vty_init(&vty_info); - - osmo_ss7_vty_init_asp(g_hnbgw); - osmo_sccp_vty_init(); - hnbgw_vty_init(); - ctrl_vty_init(g_hnbgw); - logging_vty_add_cmds(); - osmo_talloc_vty_add_cmds(); - - /* Handle options after vty_init(), for --version */ - handle_options(argc, argv); - - rc = vty_read_config_file(hnbgw_cmdline_config.config_file, NULL); - if (rc < 0) { - LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n", - hnbgw_cmdline_config.config_file); - return 1; - } - - /* - * cmdline options take precedence over config file, but if no options - * were passed we must not override the config file. - */ - if (hnbgw_cmdline_config.log_disable_color) - log_set_use_color(osmo_stderr_target, 0); - if (hnbgw_cmdline_config.log_category_mask) - log_parse_category_mask(osmo_stderr_target, - hnbgw_cmdline_config.log_category_mask); - if (hnbgw_cmdline_config.log_enable_timestamp) - log_set_print_timestamp(osmo_stderr_target, 1); - if (hnbgw_cmdline_config.log_level) - log_set_log_level(osmo_stderr_target, - hnbgw_cmdline_config.log_level); - - rc = telnet_init_default(g_hnbgw, g_hnbgw, OSMO_VTY_PORT_HNBGW); - if (rc < 0) { - perror("Error binding VTY port"); - exit(1); - } - - g_hnbgw->ctrl = ctrl_interface_setup2(g_hnbgw, OSMO_CTRL_PORT_HNBGW, hnb_ctrl_node_lookup, - _LAST_CTRL_NODE_HNB); - if (!g_hnbgw->ctrl) { - LOGP(DMAIN, LOGL_ERROR, "Failed to create CTRL interface on %s:%u\n", - ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_HNBGW); - exit(1); - } else { - rc = hnb_ctrl_cmds_install(); - if (rc) { - LOGP(DMAIN, LOGL_ERROR, "Failed to install CTRL interface commands\n"); - return 2; - } - } - - ranap_set_log_area(DRANAP); - - rc = hnbgw_cnlink_init("localhost", M3UA_PORT, "localhost"); - if (rc < 0) { - LOGP(DMAIN, LOGL_ERROR, "Failed to initialize SCCP link to CN\n"); - exit(1); - } - - LOGP(DHNBAP, LOGL_NOTICE, "Using RNC-Id %u\n", g_hnbgw->config.rnc_id); - - OSMO_ASSERT(g_hnbgw->config.iuh_local_ip); - LOGP(DMAIN, LOGL_NOTICE, "Listening for Iuh at %s %d\n", - g_hnbgw->config.iuh_local_ip, - g_hnbgw->config.iuh_local_port); - srv = osmo_stream_srv_link_create(g_hnbgw); - if (!srv) { - perror("cannot create server"); - exit(1); - } - osmo_stream_srv_link_set_data(srv, g_hnbgw); - osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP); - osmo_stream_srv_link_set_nodelay(srv, true); - osmo_stream_srv_link_set_addr(srv, g_hnbgw->config.iuh_local_ip); - osmo_stream_srv_link_set_port(srv, g_hnbgw->config.iuh_local_port); - osmo_stream_srv_link_set_accept_cb(srv, accept_cb); - - if (osmo_stream_srv_link_open(srv) < 0) { - perror("Cannot open server"); - exit(1); - } - g_hnbgw->iuh = srv; - - /* Initialize and connect MGCP client. */ - if (hnbgw_mgw_setup() != 0) - return -EINVAL; - -#if ENABLE_PFCP - /* If UPF is configured, set up PFCP socket and send Association Setup Request to UPF */ - hnbgw_pfcp_init(); -#endif - - if (hnbgw_cmdline_config.daemonize) { - rc = osmo_daemonize(); - if (rc < 0) { - perror("Error during daemonize"); - exit(1); - } - } - - while (1) { - rc = osmo_select_main_ctx(0); - if (rc < 0) - exit(3); - } - - /* not reached */ - exit(0); -} - struct msgb *hnbgw_ranap_msg_alloc(const char *name) { struct msgb *ranap_msg; @@ -855,3 +490,61 @@ ranap_msg->l2h = ranap_msg->data; return ranap_msg; } + +static const char * const hnbgw_copyright = + "OsmoHNBGW - Osmocom Home Node B Gateway implementation\r\n" + "Copyright (C) 2016-2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de>\r\n" + "Contributions by Daniel Willmann, Harald Welte, Neels Hofmeyr\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"; + +static const struct log_info_cat hnbgw_log_cat[] = { + [DMAIN] = { + .name = "DMAIN", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = "", + .description = "Main program", + }, + [DHNBAP] = { + .name = "DHNBAP", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = "", + .description = "Home Node B Application Part", + }, + [DRUA] = { + .name = "DRUA", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = "", + .description = "RANAP User Adaptation", + }, + [DRANAP] = { + .name = "DRANAP", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = "", + .description = "RAN Application Part", + }, + [DMGW] = { + .name = "DMGW", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = "\033[1;33m", + .description = "Media Gateway", + }, + [DHNB] = { + .name = "DHNB", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = OSMO_LOGCOLOR_CYAN, + .description = "HNB side (via RUA)", + }, + [DCN] = { + .name = "DCN", .loglevel = LOGL_NOTICE, .enabled = 1, + .color = OSMO_LOGCOLOR_DARKYELLOW, + .description = "Core Network side (via SCCP)", + }, +}; + +const struct log_info hnbgw_log_info = { + .cat = hnbgw_log_cat, + .num_cat = ARRAY_SIZE(hnbgw_log_cat), +}; + +struct vty_app_info hnbgw_vty_info = { + .name = "OsmoHNBGW", + .version = PACKAGE_VERSION, + .go_parent_cb = hnbgw_vty_go_parent, + .copyright = hnbgw_copyright, +}; diff --git a/src/osmo-hnbgw/osmo_hnbgw_main.c b/src/osmo-hnbgw/osmo_hnbgw_main.c new file mode 100644 index 0000000..abb577c --- /dev/null +++ b/src/osmo-hnbgw/osmo_hnbgw_main.c @@ -0,0 +1,317 @@ +/* OsmoHNBGW main routine */ + +/* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> + * (C) 2016-2023 by sysmocom s.f.m.c. GmbH <info(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/licenses/>. + * + */ + +#include <getopt.h> + +#include "config.h" + +#include <osmocom/core/application.h> +#include <osmocom/core/logging.h> + +#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> +#include <osmocom/vty/logging.h> +#include <osmocom/vty/misc.h> +#include <osmocom/vty/telnet_interface.h> +#include <osmocom/vty/ports.h> + +#include <osmocom/ctrl/control_vty.h> +#include <osmocom/ctrl/ports.h> + +#include <osmocom/netif/stream.h> + +#include <osmocom/sigtran/protocol/m3ua.h> + +#include <osmocom/ranap/ranap_common.h> + +#include <osmocom/hnbgw/hnbgw.h> +#include <osmocom/hnbgw/hnbgw_cn.h> +#include <osmocom/hnbgw/hnbgw_pfcp.h> + +static struct { + int daemonize; + const char *config_file; + bool log_disable_color; + bool log_enable_timestamp; + int log_level; + const char *log_category_mask; +} hnbgw_cmdline_config = { + 0, + "osmo-hnbgw.cfg", + false, + false, + 0, + NULL, +}; + +static void print_usage() +{ + printf("Usage: osmo-hnbgw\n"); +} + +static void print_help() +{ + printf(" -h --help This text.\n"); + printf(" -d option --debug=DHNBAP:DRUA:DRANAP:DMAIN Enable debugging.\n"); + printf(" -D --daemonize Fork the process into a background daemon.\n"); + printf(" -c --config-file filename The config file to use.\n"); + printf(" -s --disable-color\n"); + printf(" -T --timestamp Prefix every log line with a timestamp.\n"); + printf(" -V --version Print the version of OsmoHNBGW.\n"); + printf(" -e --log-level number Set a global loglevel.\n"); + + printf("\nVTY reference generation:\n"); + printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n"); + printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n"); +} + +static void handle_long_options(const char *prog_name, const int long_option) +{ + static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT; + + switch (long_option) { + case 1: + vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg); + if (vty_ref_mode < 0) { + fprintf(stderr, "%s: Unknown VTY reference generation " + "mode '%s'\n", prog_name, optarg); + exit(2); + } + break; + case 2: + fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n", + get_value_string(vty_ref_gen_mode_names, vty_ref_mode), + get_value_string(vty_ref_gen_mode_desc, vty_ref_mode)); + vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode); + exit(0); + default: + fprintf(stderr, "%s: error parsing cmdline options\n", prog_name); + exit(2); + } +} + +static void handle_options(int argc, char **argv) +{ + while (1) { + int option_index = 0, c; + static int long_option = 0; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {"debug", 1, 0, 'd'}, + {"daemonize", 0, 0, 'D'}, + {"config-file", 1, 0, 'c'}, + {"disable-color", 0, 0, 's'}, + {"timestamp", 0, 0, 'T'}, + {"version", 0, 0, 'V' }, + {"log-level", 1, 0, 'e'}, + {"vty-ref-mode", 1, &long_option, 1}, + {"vty-ref-xml", 0, &long_option, 2}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "hd:Dc:sTVe:", + long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 0: + handle_long_options(argv[0], long_option); + break; + case 'h': + print_usage(); + print_help(); + exit(0); + case 's': + hnbgw_cmdline_config.log_disable_color = true; + break; + case 'd': + hnbgw_cmdline_config.log_category_mask = optarg; + break; + case 'D': + hnbgw_cmdline_config.daemonize = 1; + break; + case 'c': + hnbgw_cmdline_config.config_file = optarg; + break; + case 'T': + hnbgw_cmdline_config.log_enable_timestamp = true; + break; + case 'e': + hnbgw_cmdline_config.log_level = atoi(optarg); + break; + case 'V': + print_version(1); + exit(0); + break; + default: + /* catch unknown options *as well as* missing arguments. */ + fprintf(stderr, "Error in command line options. Exiting.\n"); + exit(-1); + break; + } + } + + if (argc > optind) { + fprintf(stderr, "Unsupported positional arguments on command line\n"); + exit(2); + } +} + +int main(int argc, char **argv) +{ + struct osmo_stream_srv_link *srv; + int rc; + + talloc_enable_null_tracking(); + + /* g_hnbgw serves as the root talloc ctx, so allocate with NULL parent */ + g_hnbgw_alloc(NULL); + g_hnbgw->config.rnc_id = 23; + + talloc_asn1_ctx = talloc_named_const(g_hnbgw, 1, "asn1_context"); + msgb_talloc_ctx_init(g_hnbgw, 0); + + rc = osmo_init_logging2(g_hnbgw, &hnbgw_log_info); + if (rc < 0) + exit(1); + + osmo_fsm_log_timeouts(true); + + rc = osmo_ss7_init(); + if (rc < 0) { + LOGP(DMAIN, LOGL_FATAL, "osmo_ss7_init() failed with rc=%d\n", rc); + exit(1); + } + + hnbgw_vty_info.tall_ctx = g_hnbgw; + vty_init(&hnbgw_vty_info); + + osmo_ss7_vty_init_asp(g_hnbgw); + osmo_sccp_vty_init(); + hnbgw_vty_init(); + ctrl_vty_init(g_hnbgw); + logging_vty_add_cmds(); + osmo_talloc_vty_add_cmds(); + + /* Handle options after vty_init(), for --version */ + handle_options(argc, argv); + + rc = vty_read_config_file(hnbgw_cmdline_config.config_file, NULL); + if (rc < 0) { + LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n", + hnbgw_cmdline_config.config_file); + return 1; + } + + /* + * cmdline options take precedence over config file, but if no options + * were passed we must not override the config file. + */ + if (hnbgw_cmdline_config.log_disable_color) + log_set_use_color(osmo_stderr_target, 0); + if (hnbgw_cmdline_config.log_category_mask) + log_parse_category_mask(osmo_stderr_target, + hnbgw_cmdline_config.log_category_mask); + if (hnbgw_cmdline_config.log_enable_timestamp) + log_set_print_timestamp(osmo_stderr_target, 1); + if (hnbgw_cmdline_config.log_level) + log_set_log_level(osmo_stderr_target, + hnbgw_cmdline_config.log_level); + + rc = telnet_init_default(g_hnbgw, g_hnbgw, OSMO_VTY_PORT_HNBGW); + if (rc < 0) { + perror("Error binding VTY port"); + exit(1); + } + + g_hnbgw->ctrl = ctrl_interface_setup2(g_hnbgw, OSMO_CTRL_PORT_HNBGW, hnb_ctrl_node_lookup, + _LAST_CTRL_NODE_HNB); + if (!g_hnbgw->ctrl) { + LOGP(DMAIN, LOGL_ERROR, "Failed to create CTRL interface on %s:%u\n", + ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_HNBGW); + exit(1); + } else { + rc = hnb_ctrl_cmds_install(); + if (rc) { + LOGP(DMAIN, LOGL_ERROR, "Failed to install CTRL interface commands\n"); + return 2; + } + } + + ranap_set_log_area(DRANAP); + + rc = hnbgw_cnlink_init("localhost", M3UA_PORT, "localhost"); + if (rc < 0) { + LOGP(DMAIN, LOGL_ERROR, "Failed to initialize SCCP link to CN\n"); + exit(1); + } + + LOGP(DHNBAP, LOGL_NOTICE, "Using RNC-Id %u\n", g_hnbgw->config.rnc_id); + + OSMO_ASSERT(g_hnbgw->config.iuh_local_ip); + LOGP(DMAIN, LOGL_NOTICE, "Listening for Iuh at %s %d\n", + g_hnbgw->config.iuh_local_ip, + g_hnbgw->config.iuh_local_port); + srv = osmo_stream_srv_link_create(g_hnbgw); + if (!srv) { + perror("cannot create server"); + exit(1); + } + osmo_stream_srv_link_set_data(srv, g_hnbgw); + osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP); + osmo_stream_srv_link_set_nodelay(srv, true); + osmo_stream_srv_link_set_addr(srv, g_hnbgw->config.iuh_local_ip); + osmo_stream_srv_link_set_port(srv, g_hnbgw->config.iuh_local_port); + osmo_stream_srv_link_set_accept_cb(srv, hnbgw_rua_accept_cb); + + if (osmo_stream_srv_link_open(srv) < 0) { + perror("Cannot open server"); + exit(1); + } + g_hnbgw->iuh = srv; + + /* Initialize and connect MGCP client. */ + if (hnbgw_mgw_setup() != 0) + return -EINVAL; + +#if ENABLE_PFCP + /* If UPF is configured, set up PFCP socket and send Association Setup Request to UPF */ + hnbgw_pfcp_init(); +#endif + + if (hnbgw_cmdline_config.daemonize) { + rc = osmo_daemonize(); + if (rc < 0) { + perror("Error during daemonize"); + exit(1); + } + } + + while (1) { + rc = osmo_select_main_ctx(0); + if (rc < 0) + exit(3); + } + + /* not reached */ + exit(0); +} -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32620 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I5f26a6b68f0d380617d73371f40f3b9055cac362 Gerrit-Change-Number: 32620 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in osmo-hnbgw[master]: add non-installed libhnbgw.la for test linkage
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32621 ) Change subject: add non-installed libhnbgw.la for test linkage ...................................................................... add non-installed libhnbgw.la for test linkage To ease linking C tests, introduce a libhnbgw.la that contains all of osmo-hnbgw except the main() and friends. (I wrote a test that I was going to add, but it turned out to be obsolete -- now at least we may keep this preparation to add C tests more easily.) Change-Id: Id2a706a30fb459005c676bb29c196cf3a582fa01 --- M src/osmo-hnbgw/Makefile.am M tests/ranap_rab_ass/Makefile.am 2 files changed, 35 insertions(+), 17 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/21/32621/1 diff --git a/src/osmo-hnbgw/Makefile.am b/src/osmo-hnbgw/Makefile.am index de96128..e8b4966 100644 --- a/src/osmo-hnbgw/Makefile.am +++ b/src/osmo-hnbgw/Makefile.am @@ -26,11 +26,11 @@ $(COVERAGE_LDFLAGS) \ $(NULL) -bin_PROGRAMS = \ - osmo-hnbgw \ +noinst_LTLIBRARIES = \ + libhnbgw.la \ $(NULL) -osmo_hnbgw_SOURCES = \ +libhnbgw_la_SOURCES = \ hnbgw.c \ hnbgw_hnbap.c \ hnbgw_rua.c \ @@ -43,10 +43,9 @@ ranap_rab_ass.c \ mgw_fsm.c \ tdefs.c \ - osmo_hnbgw_main.c \ $(NULL) -osmo_hnbgw_LDADD = \ +libhnbgw_la_LIBADD = \ $(LIBASN1C_LIBS) \ $(LIBOSMOCORE_LIBS) \ $(LIBOSMOGSM_LIBS) \ @@ -64,16 +63,26 @@ if ENABLE_PFCP AM_CFLAGS += \ - $(LIBOSMOGTLV_CFLAGS) \ $(LIBOSMOPFCP_CFLAGS) \ $(NULL) -osmo_hnbgw_LDADD += \ - $(LIBOSMOGTLV_LIBS) \ +libhnbgw_la_LIBADD += \ $(LIBOSMOPFCP_LIBS) \ $(NULL) -osmo_hnbgw_SOURCES += \ +libhnbgw_la_SOURCES += \ hnbgw_pfcp.c \ ps_rab_ass_fsm.c \ ps_rab_fsm.c \ $(NULL) endif + +bin_PROGRAMS = \ + osmo-hnbgw \ + $(NULL) + +osmo_hnbgw_SOURCES = \ + osmo_hnbgw_main.c \ + $(NULL) + +osmo_hnbgw_LDADD = \ + libhnbgw.la \ + $(NULL) diff --git a/tests/ranap_rab_ass/Makefile.am b/tests/ranap_rab_ass/Makefile.am index 918682c..4757337 100644 --- a/tests/ranap_rab_ass/Makefile.am +++ b/tests/ranap_rab_ass/Makefile.am @@ -30,14 +30,7 @@ $(NULL) ranap_rab_ass_test_LDADD = \ - $(LIBASN1C_LIBS) \ - $(LIBOSMOCORE_LIBS) \ - $(LIBOSMOVTY_LIBS) \ - $(LIBOSMORANAP_LIBS) \ - $(LIBOSMOSIGTRAN_LIBS) \ - $(LIBOSMOMGCPCLIENT_LIBS) \ - $(COVERAGE_LDFLAGS) \ - $(top_builddir)/src/osmo-hnbgw/ranap_rab_ass.o \ + $(top_builddir)/src/osmo-hnbgw/libhnbgw.la \ $(NULL) .PHONY: update_exp -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32621 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: Id2a706a30fb459005c676bb29c196cf3a582fa01 Gerrit-Change-Number: 32621 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-hnbgw[master]: ranap_rab_ass_test.c: clarify talloc contexts
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32619 ) Change subject: ranap_rab_ass_test.c: clarify talloc contexts ...................................................................... ranap_rab_ass_test.c: clarify talloc contexts Change-Id: I4256e0d94a7e7fbba236aa92c44229c12cf17313 --- M tests/ranap_rab_ass/ranap_rab_ass_test.c 1 file changed, 14 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/19/32619/1 diff --git a/tests/ranap_rab_ass/ranap_rab_ass_test.c b/tests/ranap_rab_ass/ranap_rab_ass_test.c index 03b0836..fc2992d 100644 --- a/tests/ranap_rab_ass/ranap_rab_ass_test.c +++ b/tests/ranap_rab_ass/ranap_rab_ass_test.c @@ -33,7 +33,6 @@ #include <osmocom/ranap/ranap_common_cn.h> #include <osmocom/ranap/ranap_common_ran.h> -static void *tall_hnb_ctx; static void *msgb_ctx; extern void *talloc_asn1_ctx; @@ -368,12 +367,13 @@ int test_init(void) { int rc; + void *root_ctx; - tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); - msgb_ctx = msgb_talloc_ctx_init(NULL, 0); - talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context"); + root_ctx = talloc_named_const(NULL, 0, "ranap_rab_ass_test"); + msgb_ctx = msgb_talloc_ctx_init(root_ctx, 0); + talloc_asn1_ctx = talloc_named_const(root_ctx, 0, "asn1_context"); - rc = osmo_init_logging2(tall_hnb_ctx, &test_log_info); + rc = osmo_init_logging2(root_ctx, &test_log_info); if (rc < 0) exit(1); -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32619 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I4256e0d94a7e7fbba236aa92c44229c12cf17313 Gerrit-Change-Number: 32619 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-hnbgw[master]: drop empty hnbgw_rua_init()
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32616 ) Change subject: drop empty hnbgw_rua_init() ...................................................................... drop empty hnbgw_rua_init() Change-Id: I8e3ff452242d8baa527c2a61d182bbe9786341e3 --- M include/osmocom/hnbgw/hnbgw_rua.h M src/osmo-hnbgw/hnbgw_rua.c 2 files changed, 9 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/16/32616/1 diff --git a/include/osmocom/hnbgw/hnbgw_rua.h b/include/osmocom/hnbgw/hnbgw_rua.h index 4b65115..1526f11 100644 --- a/include/osmocom/hnbgw/hnbgw_rua.h +++ b/include/osmocom/hnbgw/hnbgw_rua.h @@ -4,7 +4,6 @@ #include <osmocom/rua/RUA_Cause.h> int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg); -int hnbgw_rua_init(void); int rua_tx_udt(struct hnb_context *hnb, const uint8_t *data, unsigned int len); int rua_tx_dt(struct hnb_context *hnb, int is_ps, uint32_t context_id, diff --git a/src/osmo-hnbgw/hnbgw_rua.c b/src/osmo-hnbgw/hnbgw_rua.c index 5e68e32..a8dc458 100644 --- a/src/osmo-hnbgw/hnbgw_rua.c +++ b/src/osmo-hnbgw/hnbgw_rua.c @@ -540,9 +540,3 @@ return rc; } - - -int hnbgw_rua_init(void) -{ - return 0; -} -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32616 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I8e3ff452242d8baa527c2a61d182bbe9786341e3 Gerrit-Change-Number: 32616 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-hnbgw[master]: eliminate function hnb_contexts()
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32617 ) Change subject: eliminate function hnb_contexts() ...................................................................... eliminate function hnb_contexts() It's really just a bloated llist_count() wrapper. (Cosmetic preparation for separate osmo_hnbgw_main.c file) Change-Id: Icd4100ddeb98f4dc2e2ec6de2d44a4b861a66078 --- M include/osmocom/hnbgw/hnbgw.h M src/osmo-hnbgw/hnbgw.c 2 files changed, 14 insertions(+), 15 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/17/32617/1 diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 1bf140a..1d46cda 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -178,7 +178,6 @@ struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid); struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info); const char *hnb_context_name(struct hnb_context *ctx); -unsigned hnb_contexts(const struct hnb_gw *gw); struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id); struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi); diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index 4885a2c..8c6a293 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -133,19 +133,6 @@ return NULL; } - -unsigned hnb_contexts(const struct hnb_gw *gw) -{ - unsigned num_ctx = 0; - struct hnb_context *hnb; - - llist_for_each_entry(hnb, &gw->hnb_list, list) { - num_ctx++; - } - - return num_ctx; -} - struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id) { struct ue_context *ue; @@ -640,7 +627,8 @@ CTRL_CMD_DEFINE_RO(hnbs, "num-hnb"); static int get_hnbs(struct ctrl_cmd *cmd, void *data) { - cmd->reply = talloc_asprintf(cmd, "%u", hnb_contexts(data)); + struct hnb_gw *gw = data; + cmd->reply = talloc_asprintf(cmd, "%u", llist_count(&gw->hnb_list)); return CTRL_CMD_REPLY; } -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32617 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: Icd4100ddeb98f4dc2e2ec6de2d44a4b861a66078 Gerrit-Change-Number: 32617 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[L] Change in osmo-hnbgw[master]: simplify: one g_hnbgw as global state and root ctx
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32618 ) Change subject: simplify: one g_hnbgw as global state and root ctx ...................................................................... simplify: one g_hnbgw as global state and root ctx So far we jump through hoops everywhere to pass around osmo-hnbgw's global singleton state to all code paths. Some files choose to spawn a static "global" pointer. And we also have the talloc root tall_hnb_ctx. Simplify: - Have a single global g_hnbgw pointer. Drop all function args and backpointers to the global state. - Use that global g_hnbgw as talloc root context, instead of passing a separate tall_hnb_ctx around. (Cosmetic preparation for separate osmo_hnbgw_main.c file) Change-Id: I3d54a5bb30c16a990c6def2a0ed207f60a95ef5d --- M include/osmocom/hnbgw/context_map.h M include/osmocom/hnbgw/hnbgw.h M include/osmocom/hnbgw/hnbgw_cn.h M include/osmocom/hnbgw/hnbgw_pfcp.h M include/osmocom/hnbgw/ps_rab_fsm.h M src/osmo-hnbgw/context_map.c M src/osmo-hnbgw/context_map_rua.c M src/osmo-hnbgw/context_map_sccp.c M src/osmo-hnbgw/hnbgw.c M src/osmo-hnbgw/hnbgw_cn.c M src/osmo-hnbgw/hnbgw_hnbap.c M src/osmo-hnbgw/hnbgw_pfcp.c M src/osmo-hnbgw/hnbgw_rua.c M src/osmo-hnbgw/hnbgw_vty.c M src/osmo-hnbgw/mgw_fsm.c M src/osmo-hnbgw/ps_rab_ass_fsm.c M src/osmo-hnbgw/ps_rab_fsm.c 17 files changed, 234 insertions(+), 255 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/18/32618/1 diff --git a/include/osmocom/hnbgw/context_map.h b/include/osmocom/hnbgw/context_map.h index b64358a..2b60958 100644 --- a/include/osmocom/hnbgw/context_map.h +++ b/include/osmocom/hnbgw/context_map.h @@ -77,9 +77,6 @@ * must not be used. */ struct llist_head hnb_list; - /* Backpointer to global hnb_gw. */ - struct hnb_gw *gw; - /* Pointer to HNB for this map, to transceive RUA. If the HNB has disconnected without releasing the RUA * context, this is NULL. */ struct hnb_context *hnb_ctx; diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 1d46cda..954a356 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -58,8 +58,6 @@ uint32_t cid; /*!< Cell ID */ }; -struct hnb_gw; - enum hnbgw_cnlink_state { /* we have just been initialized or were disconnected */ CNLINK_S_NULL, @@ -76,7 +74,6 @@ struct hnbgw_cnlink { struct llist_head list; enum hnbgw_cnlink_state state; - struct hnb_gw *gw; /* timer for re-transmitting the RANAP Reset */ struct osmo_timer_list T_RafC; /* reference to the SCCP User SAP by which we communicate */ @@ -92,8 +89,6 @@ struct hnb_context { /*! Entry in HNB-global list of HNB */ struct llist_head list; - /*! HNB-GW we are part of */ - struct hnb_gw *gw; /*! SCTP socket + write queue for Iuh to this specific HNB */ struct osmo_stream_srv *conn; /*! copied from HNB-Identity-Info IE */ @@ -124,7 +119,7 @@ struct hnb_context *hnb; }; -struct hnb_gw { +struct hnbgw { struct { const char *iuh_local_ip; /*! SCTP port for Iuh listening */ @@ -173,24 +168,25 @@ } pfcp; }; +extern struct hnbgw *g_hnbgw; extern void *talloc_asn1_ctx; -struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid); -struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info); +struct hnb_context *hnb_context_by_id(uint32_t cid); +struct hnb_context *hnb_context_by_identity_info(const char *identity_info); const char *hnb_context_name(struct hnb_context *ctx); -struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id); -struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi); -struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi); +struct ue_context *ue_context_by_id(uint32_t id); +struct ue_context *ue_context_by_imsi(const char *imsi); +struct ue_context *ue_context_by_tmsi(uint32_t tmsi); struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi, uint32_t tmsi); void ue_context_free(struct ue_context *ue); -struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd); +struct hnb_context *hnb_context_alloc(struct osmo_stream_srv_link *link, int new_fd); void hnb_context_release(struct hnb_context *ctx); void hnb_context_release_ue_state(struct hnb_context *ctx); -void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx); +void hnbgw_vty_init(void); int hnbgw_vty_go_parent(struct vty *vty); /* Return true when the user configured GTP mapping to be enabled, by configuring a PFCP link to a UPF. @@ -198,9 +194,9 @@ * 1:1. * GTP mapping means that there are two GTP tunnels, one towards HNB and one towards CN, and we forward payloads between * the two tunnels, mapping the TEIDs and GTP addresses. */ -static inline bool hnb_gw_is_gtp_mapping_enabled(const struct hnb_gw *gw) +static inline bool hnb_gw_is_gtp_mapping_enabled(void) { - return gw->config.pfcp.remote_addr != NULL; + return g_hnbgw->config.pfcp.remote_addr != NULL; } struct msgb *hnbgw_ranap_msg_alloc(const char *name); diff --git a/include/osmocom/hnbgw/hnbgw_cn.h b/include/osmocom/hnbgw/hnbgw_cn.h index 0df2716..5711c5e 100644 --- a/include/osmocom/hnbgw/hnbgw_cn.h +++ b/include/osmocom/hnbgw/hnbgw_cn.h @@ -2,6 +2,6 @@ #include <osmocom/hnbgw/hnbgw.h> -int hnbgw_cnlink_init(struct hnb_gw *gw, const char *stp_host, uint16_t stp_port, const char *local_ip); +int hnbgw_cnlink_init(const char *stp_host, uint16_t stp_port, const char *local_ip); -const struct osmo_sccp_addr *hnbgw_cn_get_remote_addr(struct hnb_gw *gw, bool is_ps); +const struct osmo_sccp_addr *hnbgw_cn_get_remote_addr(bool is_ps); diff --git a/include/osmocom/hnbgw/hnbgw_pfcp.h b/include/osmocom/hnbgw/hnbgw_pfcp.h index f3f5bb4..585d3f7 100644 --- a/include/osmocom/hnbgw/hnbgw_pfcp.h +++ b/include/osmocom/hnbgw/hnbgw_pfcp.h @@ -1,5 +1,3 @@ #pragma once -struct hnb_gw; - -int hnbgw_pfcp_init(struct hnb_gw *hnb_gw); +int hnbgw_pfcp_init(void); diff --git a/include/osmocom/hnbgw/ps_rab_fsm.h b/include/osmocom/hnbgw/ps_rab_fsm.h index e52c2ca..e8dddbe 100644 --- a/include/osmocom/hnbgw/ps_rab_fsm.h +++ b/include/osmocom/hnbgw/ps_rab_fsm.h @@ -49,9 +49,6 @@ /* Instance of ps_rab_fsm. */ struct osmo_fsm_inst *fi; - /* backpointer */ - struct hnb_gw *hnb_gw; - /* List entry and backpointer. * If map == NULL, do not call llist_del(&entry): the hnbgw_context_map may deallocate before the PFCP release * is complete, in which case it sets map = NULL. */ @@ -98,5 +95,5 @@ int ps_rab_rx_access_remote_f_teid(struct hnbgw_context_map *map, uint8_t rab_id, const struct ps_rab_rx_args *args); -struct ps_rab *ps_rab_find_by_seid(struct hnb_gw *hnb_gw, uint64_t seid, bool is_cp_seid); +struct ps_rab *ps_rab_find_by_seid(uint64_t seid, bool is_cp_seid); void ps_rab_pfcp_set_msg_ctx(struct ps_rab *rab, struct osmo_pfcp_msg *m); diff --git a/src/osmo-hnbgw/context_map.c b/src/osmo-hnbgw/context_map.c index 31f635d..c9507be 100644 --- a/src/osmo-hnbgw/context_map.c +++ b/src/osmo-hnbgw/context_map.c @@ -128,7 +128,6 @@ /* allocate a new map entry. */ map = talloc_zero(hnb, struct hnbgw_context_map); - map->gw = hnb->gw; map->cn_link = cn_if_new; map->hnb_ctx = hnb; map->rua_ctx_id = rua_ctx_id; @@ -208,7 +207,7 @@ * We could also always allocate hnbgw_context_map under hnb_gw, but it is nice to see which hnb_context owns * which hnbgw_context_map in a talloc report. */ - talloc_steal(map->gw, map); + talloc_steal(g_hnbgw, map); /* Tell RUA that the HNB is gone. SCCP release will follow via FSM events. */ map_rua_dispatch(map, MAP_RUA_EV_HNB_LINK_LOST, NULL); diff --git a/src/osmo-hnbgw/context_map_rua.c b/src/osmo-hnbgw/context_map_rua.c index 12a428b..f5537f3 100644 --- a/src/osmo-hnbgw/context_map_rua.c +++ b/src/osmo-hnbgw/context_map_rua.c @@ -154,7 +154,7 @@ } } #if ENABLE_PFCP - } else if (hnb_gw_is_gtp_mapping_enabled(map->gw)) { + } else if (hnb_gw_is_gtp_mapping_enabled()) { /* map->is_ps == true and PFCP is enabled in osmo-hnbgw.cfg */ ranap_message *message = talloc_zero(OTC_SELECT, ranap_message); rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); diff --git a/src/osmo-hnbgw/context_map_sccp.c b/src/osmo-hnbgw/context_map_sccp.c index 65939f3..47297e7 100644 --- a/src/osmo-hnbgw/context_map_sccp.c +++ b/src/osmo-hnbgw/context_map_sccp.c @@ -130,8 +130,8 @@ prim = (struct osmo_scu_prim *)msgb_push(ranap_msg, sizeof(*prim)); osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_REQUEST, ranap_msg); - prim->u.connect.called_addr = *hnbgw_cn_get_remote_addr(map->gw, map->is_ps); - prim->u.connect.calling_addr = map->gw->sccp.local_addr; + prim->u.connect.called_addr = *hnbgw_cn_get_remote_addr(map->is_ps); + prim->u.connect.calling_addr = g_hnbgw->sccp.local_addr; prim->u.connect.sccp_class = 2; prim->u.connect.conn_id = map->scu_conn_id; @@ -224,10 +224,10 @@ case RANAP_ProcedureCode_id_RAB_Assignment: /* If a UPF is configured, handle the RAB Assignment via ps_rab_ass_fsm, and replace the * GTP F-TEIDs in the RAB Assignment message before passing it on to RUA. */ - if (hnb_gw_is_gtp_mapping_enabled(map->gw)) { + if (hnb_gw_is_gtp_mapping_enabled()) { LOGP(DMAIN, LOGL_DEBUG, "RAB Assignment: setting up GTP tunnel mapping via UPF %s\n", - osmo_sockaddr_to_str_c(OTC_SELECT, &map->gw->pfcp.cp_peer->remote_addr)); + osmo_sockaddr_to_str_c(OTC_SELECT, &g_hnbgw->pfcp.cp_peer->remote_addr)); return hnbgw_gtpmap_rx_rab_ass_req(map, ranap_msg, message); } /* If no UPF is configured, directly forward the message as-is (no GTP mapping). */ diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index 8c6a293..bad7064 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -81,39 +81,36 @@ "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"; -static void *tall_hnb_ctx; +struct hnbgw *g_hnbgw = NULL; -static struct hnb_gw *g_hnb_gw; - -static struct hnb_gw *hnb_gw_create(void *ctx) +static void g_hnbgw_alloc(void *ctx) { - struct hnb_gw *gw = talloc_zero(ctx, struct hnb_gw); + OSMO_ASSERT(!g_hnbgw); + g_hnbgw = talloc_zero(ctx, struct hnbgw); /* strdup so we can easily talloc_free in the VTY code */ - gw->config.iuh_local_ip = talloc_strdup(gw, HNBGW_LOCAL_IP_DEFAULT); - gw->config.iuh_local_port = IUH_DEFAULT_SCTP_PORT; - gw->config.log_prefix_hnb_id = true; + g_hnbgw->config.iuh_local_ip = talloc_strdup(g_hnbgw, HNBGW_LOCAL_IP_DEFAULT); + g_hnbgw->config.iuh_local_port = IUH_DEFAULT_SCTP_PORT; + g_hnbgw->config.log_prefix_hnb_id = true; - gw->next_ue_ctx_id = 23; - INIT_LLIST_HEAD(&gw->hnb_list); - INIT_LLIST_HEAD(&gw->ue_list); + g_hnbgw->next_ue_ctx_id = 23; + INIT_LLIST_HEAD(&g_hnbgw->hnb_list); + INIT_LLIST_HEAD(&g_hnbgw->ue_list); - gw->mgw_pool = mgcp_client_pool_alloc(gw); - gw->config.mgcp_client = talloc_zero(tall_hnb_ctx, struct mgcp_client_conf); - mgcp_client_conf_init(gw->config.mgcp_client); + g_hnbgw->mgw_pool = mgcp_client_pool_alloc(g_hnbgw); + g_hnbgw->config.mgcp_client = talloc_zero(g_hnbgw, struct mgcp_client_conf); + mgcp_client_conf_init(g_hnbgw->config.mgcp_client); #if ENABLE_PFCP - gw->config.pfcp.remote_port = OSMO_PFCP_PORT; + g_hnbgw->config.pfcp.remote_port = OSMO_PFCP_PORT; #endif - - return gw; } -struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid) +struct hnb_context *hnb_context_by_id(uint32_t cid) { struct hnb_context *hnb; - llist_for_each_entry(hnb, &gw->hnb_list, list) { + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { if (hnb->id.cid == cid) return hnb; } @@ -121,11 +118,11 @@ return NULL; } -struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info) +struct hnb_context *hnb_context_by_identity_info(const char *identity_info) { struct hnb_context *hnb; - llist_for_each_entry(hnb, &gw->hnb_list, list) { + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { if (strcmp(identity_info, hnb->identity_info) == 0) return hnb; } @@ -133,11 +130,11 @@ return NULL; } -struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id) +struct ue_context *ue_context_by_id(uint32_t id) { struct ue_context *ue; - llist_for_each_entry(ue, &gw->ue_list, list) { + llist_for_each_entry(ue, &g_hnbgw->ue_list, list) { if (ue->context_id == id) return ue; } @@ -145,45 +142,45 @@ } -struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi) +struct ue_context *ue_context_by_imsi(const char *imsi) { struct ue_context *ue; - llist_for_each_entry(ue, &gw->ue_list, list) { + llist_for_each_entry(ue, &g_hnbgw->ue_list, list) { if (!strcmp(ue->imsi, imsi)) return ue; } return NULL; } -struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi) +struct ue_context *ue_context_by_tmsi(uint32_t tmsi) { struct ue_context *ue; - llist_for_each_entry(ue, &gw->ue_list, list) { + llist_for_each_entry(ue, &g_hnbgw->ue_list, list) { if (ue->tmsi == tmsi) return ue; } return NULL; } -void ue_context_free_by_hnb(struct hnb_gw *gw, const struct hnb_context *hnb) +void ue_context_free_by_hnb(const struct hnb_context *hnb) { struct ue_context *ue, *tmp; - llist_for_each_entry_safe(ue, tmp, &gw->ue_list, list) { + llist_for_each_entry_safe(ue, tmp, &g_hnbgw->ue_list, list) { if (ue->hnb == hnb) ue_context_free(ue); } } -static uint32_t get_next_ue_ctx_id(struct hnb_gw *gw) +static uint32_t get_next_ue_ctx_id(void) { uint32_t id; do { - id = gw->next_ue_ctx_id++; - } while (ue_context_by_id(gw, id)); + id = g_hnbgw->next_ue_ctx_id++; + } while (ue_context_by_id(id)); return id; } @@ -193,7 +190,7 @@ { struct ue_context *ue; - ue = talloc_zero(tall_hnb_ctx, struct ue_context); + ue = talloc_zero(g_hnbgw, struct ue_context); if (!ue) return NULL; @@ -203,8 +200,8 @@ else ue->imsi[0] = '\0'; ue->tmsi = tmsi; - ue->context_id = get_next_ue_ctx_id(hnb->gw); - llist_add_tail(&ue->list, &hnb->gw->ue_list); + ue->context_id = get_next_ue_ctx_id(); + llist_add_tail(&ue->list, &g_hnbgw->ue_list); LOGP(DHNBAP, LOGL_INFO, "created UE context: id 0x%x, imsi %s, tmsi 0x%x\n", ue->context_id, imsi? imsi : "-", tmsi); @@ -337,24 +334,23 @@ return 0; } -struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd) +struct hnb_context *hnb_context_alloc(struct osmo_stream_srv_link *link, int new_fd) { struct hnb_context *ctx; - ctx = talloc_zero(tall_hnb_ctx, struct hnb_context); + ctx = talloc_zero(g_hnbgw, struct hnb_context); if (!ctx) return NULL; INIT_LLIST_HEAD(&ctx->map_list); - ctx->gw = gw; - ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, hnb_closed_cb, ctx); + ctx->conn = osmo_stream_srv_create(g_hnbgw, link, new_fd, hnb_read_cb, hnb_closed_cb, ctx); if (!ctx->conn) { LOGP(DMAIN, LOGL_INFO, "error while creating connection\n"); talloc_free(ctx); return NULL; } - llist_add_tail(&ctx->list, &gw->hnb_list); + llist_add_tail(&ctx->list, &g_hnbgw->hnb_list); return ctx; } @@ -371,7 +367,7 @@ if (!ctx) return "NULL"; - if (ctx->gw->config.log_prefix_hnb_id) + if (g_hnbgw->config.log_prefix_hnb_id) return ctx->identity_info; else return umts_cell_id_name(&ctx->id); @@ -386,7 +382,7 @@ context_map_hnb_released(map); /* hnbgw_context_map will remove itself from lists when it is ready. */ } - ue_context_free_by_hnb(ctx->gw, ctx); + ue_context_free_by_hnb(ctx); } void hnb_context_release(struct hnb_context *ctx) @@ -422,13 +418,12 @@ /*! call-back when the listen FD has something to read */ static int accept_cb(struct osmo_stream_srv_link *srv, int fd) { - struct hnb_gw *gw = osmo_stream_srv_link_get_data(srv); struct hnb_context *ctx; LOGP(DMAIN, LOGL_INFO, "New HNB SCTP connection %s\n", osmo_sock_get_name2(fd)); - ctx = hnb_context_alloc(gw, srv, fd); + ctx = hnb_context_alloc(srv, fd); if (!ctx) return -ENOMEM; @@ -627,8 +622,7 @@ CTRL_CMD_DEFINE_RO(hnbs, "num-hnb"); static int get_hnbs(struct ctrl_cmd *cmd, void *data) { - struct hnb_gw *gw = data; - cmd->reply = talloc_asprintf(cmd, "%u", llist_count(&gw->hnb_list)); + cmd->reply = talloc_asprintf(cmd, "%u", llist_count(&g_hnbgw->hnb_list)); return CTRL_CMD_REPLY; } @@ -659,7 +653,7 @@ if (!ctrl_parse_get_num(vline, *i, &num)) return -ERANGE; - hnb = hnb_context_by_id(data, num); + hnb = hnb_context_by_id(num); if (!hnb) return -ENODEV; @@ -681,8 +675,8 @@ /* Initialize MGW pool. This initalizes and connects all MGCP clients that are currently configured in * the pool. Adding additional MGCP clients to the pool is possible but the user has to configure and * (re)connect them manually from the VTY. */ - if (!mgcp_client_pool_empty(g_hnb_gw->mgw_pool)) { - pool_members_initalized = mgcp_client_pool_connect(g_hnb_gw->mgw_pool); + if (!mgcp_client_pool_empty(g_hnbgw->mgw_pool)) { + pool_members_initalized = mgcp_client_pool_connect(g_hnbgw->mgw_pool); if (!pool_members_initalized) { LOGP(DMGW, LOGL_ERROR, "MGW pool failed to initialize any pool members\n"); return -EINVAL; @@ -696,18 +690,18 @@ /* Initialize and connect a single MGCP client. This MGCP client will appear as the one and only pool * member if there is no MGW pool configured. */ LOGP(DMGW, LOGL_NOTICE, "No MGW pool configured, using MGW configuration in VTY node 'mgcp'\n"); - mgcp_client_single = mgcp_client_init(tall_hnb_ctx, g_hnb_gw->config.mgcp_client); + mgcp_client_single = mgcp_client_init(g_hnbgw, g_hnbgw->config.mgcp_client); if (!mgcp_client_single) { LOGP(DMGW, LOGL_ERROR, "MGW (single) client initalization failed\n"); return -EINVAL; } if (mgcp_client_connect(mgcp_client_single)) { LOGP(DMGW, LOGL_ERROR, "MGW (single) connect failed at (%s:%u)\n", - g_hnb_gw->config.mgcp_client->remote_addr, - g_hnb_gw->config.mgcp_client->remote_port); + g_hnbgw->config.mgcp_client->remote_addr, + g_hnbgw->config.mgcp_client->remote_port); return -EINVAL; } - mgcp_client_pool_register_single(g_hnb_gw->mgw_pool, mgcp_client_single); + mgcp_client_pool_register_single(g_hnbgw->mgw_pool, mgcp_client_single); return 0; } @@ -719,14 +713,14 @@ talloc_enable_null_tracking(); - tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); - talloc_asn1_ctx = talloc_named_const(tall_hnb_ctx, 1, "asn1_context"); - msgb_talloc_ctx_init(tall_hnb_ctx, 0); + /* g_hnbgw serves as the root talloc ctx, so allocate with NULL parent */ + g_hnbgw_alloc(NULL); + g_hnbgw->config.rnc_id = 23; - g_hnb_gw = hnb_gw_create(tall_hnb_ctx); - g_hnb_gw->config.rnc_id = 23; + talloc_asn1_ctx = talloc_named_const(g_hnbgw, 1, "asn1_context"); + msgb_talloc_ctx_init(g_hnbgw, 0); - rc = osmo_init_logging2(tall_hnb_ctx, &hnbgw_log_info); + rc = osmo_init_logging2(g_hnbgw, &hnbgw_log_info); if (rc < 0) exit(1); @@ -738,14 +732,14 @@ exit(1); } - vty_info.tall_ctx = tall_hnb_ctx; + vty_info.tall_ctx = g_hnbgw; vty_info.copyright = osmo_hnbgw_copyright; vty_init(&vty_info); - osmo_ss7_vty_init_asp(tall_hnb_ctx); + osmo_ss7_vty_init_asp(g_hnbgw); osmo_sccp_vty_init(); - hnbgw_vty_init(g_hnb_gw, tall_hnb_ctx); - ctrl_vty_init(tall_hnb_ctx); + hnbgw_vty_init(); + ctrl_vty_init(g_hnbgw); logging_vty_add_cmds(); osmo_talloc_vty_add_cmds(); @@ -774,15 +768,15 @@ log_set_log_level(osmo_stderr_target, hnbgw_cmdline_config.log_level); - rc = telnet_init_default(tall_hnb_ctx, g_hnb_gw, OSMO_VTY_PORT_HNBGW); + rc = telnet_init_default(g_hnbgw, g_hnbgw, OSMO_VTY_PORT_HNBGW); if (rc < 0) { perror("Error binding VTY port"); exit(1); } - g_hnb_gw->ctrl = ctrl_interface_setup2(g_hnb_gw, OSMO_CTRL_PORT_HNBGW, hnb_ctrl_node_lookup, + g_hnbgw->ctrl = ctrl_interface_setup2(g_hnbgw, OSMO_CTRL_PORT_HNBGW, hnb_ctrl_node_lookup, _LAST_CTRL_NODE_HNB); - if (!g_hnb_gw->ctrl) { + if (!g_hnbgw->ctrl) { LOGP(DMAIN, LOGL_ERROR, "Failed to create CTRL interface on %s:%u\n", ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_HNBGW); exit(1); @@ -796,35 +790,35 @@ ranap_set_log_area(DRANAP); - rc = hnbgw_cnlink_init(g_hnb_gw, "localhost", M3UA_PORT, "localhost"); + rc = hnbgw_cnlink_init("localhost", M3UA_PORT, "localhost"); if (rc < 0) { LOGP(DMAIN, LOGL_ERROR, "Failed to initialize SCCP link to CN\n"); exit(1); } - LOGP(DHNBAP, LOGL_NOTICE, "Using RNC-Id %u\n", g_hnb_gw->config.rnc_id); + LOGP(DHNBAP, LOGL_NOTICE, "Using RNC-Id %u\n", g_hnbgw->config.rnc_id); - OSMO_ASSERT(g_hnb_gw->config.iuh_local_ip); + OSMO_ASSERT(g_hnbgw->config.iuh_local_ip); LOGP(DMAIN, LOGL_NOTICE, "Listening for Iuh at %s %d\n", - g_hnb_gw->config.iuh_local_ip, - g_hnb_gw->config.iuh_local_port); - srv = osmo_stream_srv_link_create(tall_hnb_ctx); + g_hnbgw->config.iuh_local_ip, + g_hnbgw->config.iuh_local_port); + srv = osmo_stream_srv_link_create(g_hnbgw); if (!srv) { perror("cannot create server"); exit(1); } - osmo_stream_srv_link_set_data(srv, g_hnb_gw); + osmo_stream_srv_link_set_data(srv, g_hnbgw); osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP); osmo_stream_srv_link_set_nodelay(srv, true); - osmo_stream_srv_link_set_addr(srv, g_hnb_gw->config.iuh_local_ip); - osmo_stream_srv_link_set_port(srv, g_hnb_gw->config.iuh_local_port); + osmo_stream_srv_link_set_addr(srv, g_hnbgw->config.iuh_local_ip); + osmo_stream_srv_link_set_port(srv, g_hnbgw->config.iuh_local_port); osmo_stream_srv_link_set_accept_cb(srv, accept_cb); if (osmo_stream_srv_link_open(srv) < 0) { perror("Cannot open server"); exit(1); } - g_hnb_gw->iuh = srv; + g_hnbgw->iuh = srv; /* Initialize and connect MGCP client. */ if (hnbgw_mgw_setup() != 0) @@ -832,7 +826,7 @@ #if ENABLE_PFCP /* If UPF is configured, set up PFCP socket and send Association Setup Request to UPF */ - hnbgw_pfcp_init(g_hnb_gw); + hnbgw_pfcp_init(); #endif if (hnbgw_cmdline_config.daemonize) { diff --git a/src/osmo-hnbgw/hnbgw_cn.c b/src/osmo-hnbgw/hnbgw_cn.c index fdc5cde..4c8273b 100644 --- a/src/osmo-hnbgw/hnbgw_cn.c +++ b/src/osmo-hnbgw/hnbgw_cn.c @@ -43,7 +43,7 @@ void hnbgw_cnlink_change_state(struct hnbgw_cnlink *cnlink, enum hnbgw_cnlink_state state); -static int transmit_rst(struct hnb_gw *gw, RANAP_CN_DomainIndicator_t domain, +static int transmit_rst(RANAP_CN_DomainIndicator_t domain, struct osmo_sccp_addr *remote_addr) { struct msgb *msg; @@ -54,41 +54,39 @@ LOGP(DRANAP, LOGL_NOTICE, "Tx RESET to %s %s\n", domain == RANAP_CN_DomainIndicator_cs_domain ? "IuCS" : "IuPS", - osmo_sccp_inst_addr_name(gw->sccp.cnlink->sccp, remote_addr)); + osmo_sccp_inst_addr_name(g_hnbgw->sccp.cnlink->sccp, remote_addr)); msg = ranap_new_msg_reset(domain, &cause); - return osmo_sccp_tx_unitdata_msg(gw->sccp.cnlink->sccp_user, - &gw->sccp.local_addr, + return osmo_sccp_tx_unitdata_msg(g_hnbgw->sccp.cnlink->sccp_user, + &g_hnbgw->sccp.local_addr, remote_addr, msg); } -static int transmit_reset_ack(struct hnb_gw *gw, RANAP_CN_DomainIndicator_t domain, +static int transmit_reset_ack(RANAP_CN_DomainIndicator_t domain, const struct osmo_sccp_addr *remote_addr) { struct msgb *msg; LOGP(DRANAP, LOGL_NOTICE, "Tx RESET ACK to %s %s\n", domain == RANAP_CN_DomainIndicator_cs_domain ? "IuCS" : "IuPS", - osmo_sccp_inst_addr_name(gw->sccp.cnlink->sccp, remote_addr)); + osmo_sccp_inst_addr_name(g_hnbgw->sccp.cnlink->sccp, remote_addr)); msg = ranap_new_msg_reset_ack(domain, NULL); - return osmo_sccp_tx_unitdata_msg(gw->sccp.cnlink->sccp_user, - &gw->sccp.local_addr, + return osmo_sccp_tx_unitdata_msg(g_hnbgw->sccp.cnlink->sccp_user, + &g_hnbgw->sccp.local_addr, remote_addr, msg); } /* Timer callback once T_RafC expires */ -static void cnlink_trafc_cb(void *data) +static void cnlink_trafc_cb(void *) { - struct hnb_gw *gw = data; - - transmit_rst(gw, RANAP_CN_DomainIndicator_cs_domain, &gw->sccp.iucs_remote_addr); - transmit_rst(gw, RANAP_CN_DomainIndicator_ps_domain, &gw->sccp.iups_remote_addr); - hnbgw_cnlink_change_state(gw->sccp.cnlink, CNLINK_S_EST_RST_TX_WAIT_ACK); + transmit_rst(RANAP_CN_DomainIndicator_cs_domain, &g_hnbgw->sccp.iucs_remote_addr); + transmit_rst(RANAP_CN_DomainIndicator_ps_domain, &g_hnbgw->sccp.iups_remote_addr); + hnbgw_cnlink_change_state(g_hnbgw->sccp.cnlink, CNLINK_S_EST_RST_TX_WAIT_ACK); /* The spec states that we should abandon after a configurable * number of times. We decide to simply continue trying */ } @@ -101,7 +99,7 @@ case CNLINK_S_EST_PEND: break; case CNLINK_S_EST_CONF: - cnlink_trafc_cb(cnlink->gw); + cnlink_trafc_cb(NULL); break; case CNLINK_S_EST_RST_TX_WAIT_ACK: osmo_timer_schedule(&cnlink->T_RafC, 5, 0); @@ -134,7 +132,7 @@ /* FIXME: actually reset connections, if any */ - if (transmit_reset_ack(cnlink->gw, domain, &unitdata->calling_addr)) + if (transmit_reset_ack(domain, &unitdata->calling_addr)) LOGP(DRANAP, LOGL_ERROR, "Error: cannot send RESET ACK to %s %s\n", domain == RANAP_CN_DomainIndicator_cs_domain ? "IuCS" : "IuPS", osmo_sccp_inst_addr_name(cnlink->sccp, &unitdata->calling_addr)); @@ -160,7 +158,6 @@ RANAP_InitiatingMessage_t *imsg, const uint8_t *data, unsigned int len) { - struct hnb_gw *gw = cnlink->gw; struct hnb_context *hnb; RANAP_PagingIEs_t ies; int rc; @@ -171,7 +168,7 @@ /* FIXME: determine which HNBs to send this Paging command, * rather than broadcasting to all HNBs */ - llist_for_each_entry(hnb, &gw->hnb_list, list) { + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { rc = rua_tx_udt(hnb, data, len); } @@ -288,16 +285,15 @@ && (a->ssn == b->ssn)); } -static int classify_cn_remote_addr(const struct hnb_gw *gw, - const struct osmo_sccp_addr *cn_remote_addr, +static int classify_cn_remote_addr(const struct osmo_sccp_addr *cn_remote_addr, bool *is_ps) { - if (pc_and_ssn_match(cn_remote_addr, &gw->sccp.iucs_remote_addr)) { + if (pc_and_ssn_match(cn_remote_addr, &g_hnbgw->sccp.iucs_remote_addr)) { if (is_ps) *is_ps = false; return 0; } - if (pc_and_ssn_match(cn_remote_addr, &gw->sccp.iups_remote_addr)) { + if (pc_and_ssn_match(cn_remote_addr, &g_hnbgw->sccp.iups_remote_addr)) { if (is_ps) *is_ps = true; return 0; @@ -317,7 +313,7 @@ return -1; } - if (classify_cn_remote_addr(cnlink->gw, &param->calling_addr, NULL) < 0) + if (classify_cn_remote_addr(&param->calling_addr, NULL) < 0) return -1; return handle_cn_ranap(cnlink, param, msgb_l2(oph->msg), msgb_l2len(oph->msg)); @@ -327,7 +323,7 @@ const struct osmo_scu_connect_param *param, struct osmo_prim_hdr *oph) { - struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(cnlink->gw->sccp.client); + struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(g_hnbgw->sccp.client); struct hnbgw_context_map *map; LOGP(DMAIN, LOGL_DEBUG, "handle_cn_conn_conf() conn_id=%d, addrs: called=%s calling=%s responding=%s\n", @@ -485,27 +481,27 @@ return 0; } -int hnbgw_cnlink_init(struct hnb_gw *gw, const char *stp_host, uint16_t stp_port, const char *local_ip) +int hnbgw_cnlink_init(const char *stp_host, uint16_t stp_port, const char *local_ip) { struct hnbgw_cnlink *cnlink; struct osmo_ss7_instance *ss7; uint32_t local_pc; - OSMO_ASSERT(!gw->sccp.client); - OSMO_ASSERT(!gw->sccp.cnlink); + OSMO_ASSERT(!g_hnbgw->sccp.client); + OSMO_ASSERT(!g_hnbgw->sccp.cnlink); ss7 = NULL; - if (resolve_addr_name(&gw->sccp.iucs_remote_addr, &ss7, - gw->config.iucs_remote_addr_name, "IuCS", (23 << 3) + 1)) + if (resolve_addr_name(&g_hnbgw->sccp.iucs_remote_addr, &ss7, + g_hnbgw->config.iucs_remote_addr_name, "IuCS", (23 << 3) + 1)) return -1; - if (resolve_addr_name(&gw->sccp.iups_remote_addr, &ss7, - gw->config.iups_remote_addr_name, "IuPS", (23 << 3) + 4)) + if (resolve_addr_name(&g_hnbgw->sccp.iups_remote_addr, &ss7, + g_hnbgw->config.iups_remote_addr_name, "IuPS", (23 << 3) + 4)) return -1; if (!ss7) { LOGP(DRANAP, LOGL_NOTICE, "No cs7 instance configured for IuCS nor IuPS," " creating default instance\n"); - ss7 = osmo_ss7_instance_find_or_create(gw, 0); + ss7 = osmo_ss7_instance_find_or_create(g_hnbgw, 0); if (!ss7) return -1; ss7->cfg.primary_pc = (23 << 3) + 5; @@ -518,45 +514,43 @@ } local_pc = ss7->cfg.primary_pc; - osmo_sccp_make_addr_pc_ssn(&gw->sccp.local_addr, local_pc, OSMO_SCCP_SSN_RANAP); - LOGP(DRANAP, LOGL_NOTICE, "Local SCCP addr: %s\n", osmo_sccp_addr_name(ss7, &gw->sccp.local_addr)); + osmo_sccp_make_addr_pc_ssn(&g_hnbgw->sccp.local_addr, local_pc, OSMO_SCCP_SSN_RANAP); + LOGP(DRANAP, LOGL_NOTICE, "Local SCCP addr: %s\n", osmo_sccp_addr_name(ss7, &g_hnbgw->sccp.local_addr)); - gw->sccp.client = osmo_sccp_simple_client_on_ss7_id(gw, ss7->cfg.id, "OsmoHNBGW", - local_pc, OSMO_SS7_ASP_PROT_M3UA, - 0, local_ip, stp_port, stp_host); - if (!gw->sccp.client) { + g_hnbgw->sccp.client = osmo_sccp_simple_client_on_ss7_id(g_hnbgw, ss7->cfg.id, "OsmoHNBGW", + local_pc, OSMO_SS7_ASP_PROT_M3UA, + 0, local_ip, stp_port, stp_host); + if (!g_hnbgw->sccp.client) { LOGP(DMAIN, LOGL_ERROR, "Failed to init SCCP Client\n"); return -1; } - cnlink = talloc_zero(gw, struct hnbgw_cnlink); - cnlink->gw = gw; + cnlink = talloc_zero(g_hnbgw, struct hnbgw_cnlink); INIT_LLIST_HEAD(&cnlink->map_list); cnlink->T_RafC.cb = cnlink_trafc_cb; - cnlink->T_RafC.data = gw; cnlink->next_conn_id = 1000; - cnlink->sccp_user = osmo_sccp_user_bind_pc(gw->sccp.client, "OsmoHNBGW", sccp_sap_up, - OSMO_SCCP_SSN_RANAP, gw->sccp.local_addr.pc); + cnlink->sccp_user = osmo_sccp_user_bind_pc(g_hnbgw->sccp.client, "OsmoHNBGW", sccp_sap_up, + OSMO_SCCP_SSN_RANAP, g_hnbgw->sccp.local_addr.pc); if (!cnlink->sccp_user) { LOGP(DMAIN, LOGL_ERROR, "Failed to init SCCP User\n"); return -1; } LOGP(DRANAP, LOGL_NOTICE, "Remote SCCP addr: IuCS: %s\n", - osmo_sccp_addr_name(ss7, &gw->sccp.iucs_remote_addr)); + osmo_sccp_addr_name(ss7, &g_hnbgw->sccp.iucs_remote_addr)); LOGP(DRANAP, LOGL_NOTICE, "Remote SCCP addr: IuPS: %s\n", - osmo_sccp_addr_name(ss7, &gw->sccp.iups_remote_addr)); + osmo_sccp_addr_name(ss7, &g_hnbgw->sccp.iups_remote_addr)); /* In sccp_sap_up() we expect the cnlink in the user's priv. */ osmo_sccp_user_set_priv(cnlink->sccp_user, cnlink); - gw->sccp.cnlink = cnlink; + g_hnbgw->sccp.cnlink = cnlink; return 0; } -const struct osmo_sccp_addr *hnbgw_cn_get_remote_addr(struct hnb_gw *gw, bool is_ps) +const struct osmo_sccp_addr *hnbgw_cn_get_remote_addr(bool is_ps) { - return is_ps ? &gw->sccp.iups_remote_addr : &gw->sccp.iucs_remote_addr; + return is_ps ? &g_hnbgw->sccp.iups_remote_addr : &g_hnbgw->sccp.iucs_remote_addr; } diff --git a/src/osmo-hnbgw/hnbgw_hnbap.c b/src/osmo-hnbgw/hnbgw_hnbap.c index 395cca7..85adccd 100644 --- a/src/osmo-hnbgw/hnbgw_hnbap.c +++ b/src/osmo-hnbgw/hnbgw_hnbap.c @@ -99,7 +99,7 @@ /* Single required response IE: RNC-ID */ HNBAP_HNBRegisterAcceptIEs_t accept = { - .rnc_id = ctx->gw->config.rnc_id + .rnc_id = g_hnbgw->config.rnc_id }; /* encode the Information Elements */ @@ -330,7 +330,7 @@ tmsi = ntohl(tmsi); LOGHNB(hnb, DHNBAP, LOGL_DEBUG, "HNBAP register with TMSI %x\n", tmsi); - ue = ue_context_by_tmsi(hnb->gw, tmsi); + ue = ue_context_by_tmsi(tmsi); if (!ue) ue = ue_allocated = ue_context_alloc(hnb, NULL, tmsi); @@ -431,7 +431,7 @@ ctx->id.mcc = plmn.mcc; ctx->id.mnc = plmn.mnc; - llist_for_each_entry_safe(hnb, tmp, &ctx->gw->hnb_list, list) { + llist_for_each_entry_safe(hnb, tmp, &g_hnbgw->hnb_list, list) { if (hnb->hnb_registered && ctx != hnb && memcmp(&ctx->id, &hnb->id, sizeof(ctx->id)) == 0) { /* If it's coming from the same remote IP addr+port, then it must be our internal * fault (bug), and we release the old context to keep going... */ @@ -513,7 +513,7 @@ break; case HNBAP_UE_Identity_PR_tMSILAI: case HNBAP_UE_Identity_PR_pTMSIRAI: - if (ctx->gw->config.hnbap_allow_tmsi) + if (g_hnbgw->config.hnbap_allow_tmsi) rc = hnbgw_tx_ue_register_acc_tmsi(ctx, &ies.uE_Identity); else rc = hnbgw_tx_ue_register_rej_tmsi(ctx, &ies.uE_Identity); @@ -529,7 +529,7 @@ LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "UE-REGISTER-REQ ID_type=%d imsi=%s cause=%ld\n", ies.uE_Identity.present, imsi, ies.registration_Cause); - ue = ue_context_by_imsi(ctx->gw, imsi); + ue = ue_context_by_imsi(imsi); if (!ue) ue = ue_allocated = ue_context_alloc(ctx, imsi, 0); @@ -561,7 +561,7 @@ LOGHNB(ctx, DHNBAP, LOGL_DEBUG, "UE-DE-REGISTER context=%u cause=%s\n", ctxid, hnbap_cause_str(&ies.cause)); - ue = ue_context_by_id(ctx->gw, ctxid); + ue = ue_context_by_id(ctxid); if (ue) ue_context_free(ue); diff --git a/src/osmo-hnbgw/hnbgw_pfcp.c b/src/osmo-hnbgw/hnbgw_pfcp.c index 6973a1b..c7b2b08 100644 --- a/src/osmo-hnbgw/hnbgw_pfcp.c +++ b/src/osmo-hnbgw/hnbgw_pfcp.c @@ -29,10 +29,8 @@ static void pfcp_set_msg_ctx(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m, struct osmo_pfcp_msg *req) { - struct hnb_gw *hnb_gw = osmo_pfcp_endpoint_get_priv(ep); - if (!m->ctx.peer_fi) - osmo_pfcp_cp_peer_set_msg_ctx(hnb_gw->pfcp.cp_peer, m); + osmo_pfcp_cp_peer_set_msg_ctx(g_hnbgw->pfcp.cp_peer, m); /* If this is a response to an earlier request, just take the msg context from the request message. * In osmo-hnbgw, a session_fi always points at a ps_rab FSM. */ @@ -43,7 +41,7 @@ * ps_rab_new_pfcp_msg_tx() already sets the msg ctx, and for rx, we only expect to receive PFCP Responses, * which are handled above. The only time this will happen is when the UPF shuts down and sends a Deletion. */ if (!m->ctx.session_fi && m->h.seid_present && m->h.seid != 0) { - struct ps_rab *rab = ps_rab_find_by_seid(hnb_gw, m->h.seid, m->rx); + struct ps_rab *rab = ps_rab_find_by_seid(m->h.seid, m->rx); if (rab) ps_rab_pfcp_set_msg_ctx(rab, m); } @@ -64,7 +62,7 @@ } } -int hnbgw_pfcp_init(struct hnb_gw *hnb_gw) +int hnbgw_pfcp_init(void) { struct osmo_pfcp_endpoint_cfg cfg; struct osmo_pfcp_endpoint *ep; @@ -72,13 +70,13 @@ struct osmo_sockaddr_str upf_addr_str; struct osmo_sockaddr upf_addr; - if (!hnb_gw_is_gtp_mapping_enabled(hnb_gw)) { + if (!hnb_gw_is_gtp_mapping_enabled()) { LOGP(DLPFCP, LOGL_NOTICE, "No UPF configured, NOT setting up PFCP, NOT mapping GTP via UPF\n"); return 0; } - LOGP(DLPFCP, LOGL_DEBUG, "%p cfg: pfcp remote-addr %s\n", hnb_gw, hnb_gw->config.pfcp.remote_addr); + LOGP(DLPFCP, LOGL_DEBUG, "%p cfg: pfcp remote-addr %s\n", g_hnbgw, g_hnbgw->config.pfcp.remote_addr); - if (!hnb_gw->config.pfcp.local_addr) { + if (!g_hnbgw->config.pfcp.local_addr) { LOGP(DLPFCP, LOGL_ERROR, "Configuration error: missing local PFCP address, required for Node Id\n"); return -1; } @@ -86,44 +84,43 @@ cfg = (struct osmo_pfcp_endpoint_cfg){ .set_msg_ctx_cb = pfcp_set_msg_ctx, .rx_msg_cb = pfcp_rx_msg, - .priv = hnb_gw, }; /* Set up PFCP endpoint's local node id from local IP address. Parse address string into local_addr_str... */ - if (osmo_sockaddr_str_from_str(&local_addr_str, hnb_gw->config.pfcp.local_addr, hnb_gw->config.pfcp.local_port)) { + if (osmo_sockaddr_str_from_str(&local_addr_str, g_hnbgw->config.pfcp.local_addr, g_hnbgw->config.pfcp.local_port)) { LOGP(DLPFCP, LOGL_ERROR, "Error in PFCP local IP: %s\n", - osmo_quote_str_c(OTC_SELECT, hnb_gw->config.pfcp.local_addr, -1)); + osmo_quote_str_c(OTC_SELECT, g_hnbgw->config.pfcp.local_addr, -1)); return -1; } /* ...and convert to osmo_sockaddr, write to ep->cfg */ if (osmo_sockaddr_str_to_sockaddr(&local_addr_str, &cfg.local_addr.u.sas)) { LOGP(DLPFCP, LOGL_ERROR, "Error in PFCP local IP: %s\n", - osmo_quote_str_c(OTC_SELECT, hnb_gw->config.pfcp.local_addr, -1)); + osmo_quote_str_c(OTC_SELECT, g_hnbgw->config.pfcp.local_addr, -1)); return -1; } /* also store the local addr as local Node ID */ if (osmo_pfcp_ie_node_id_from_osmo_sockaddr(&cfg.local_node_id, &cfg.local_addr)) { LOGP(DLPFCP, LOGL_ERROR, "Error in PFCP local IP: %s\n", - osmo_quote_str_c(OTC_SELECT, hnb_gw->config.pfcp.local_addr, -1)); + osmo_quote_str_c(OTC_SELECT, g_hnbgw->config.pfcp.local_addr, -1)); return -1; } - hnb_gw->pfcp.ep = ep = osmo_pfcp_endpoint_create(hnb_gw, &cfg); + g_hnbgw->pfcp.ep = ep = osmo_pfcp_endpoint_create(g_hnbgw, &cfg); if (!ep) { LOGP(DLPFCP, LOGL_ERROR, "Failed to allocate PFCP endpoint\n"); return -1; } /* Set up remote PFCP address to reach UPF at. First parse the string into upf_addr_str. */ - if (osmo_sockaddr_str_from_str(&upf_addr_str, hnb_gw->config.pfcp.remote_addr, hnb_gw->config.pfcp.remote_port)) { + if (osmo_sockaddr_str_from_str(&upf_addr_str, g_hnbgw->config.pfcp.remote_addr, g_hnbgw->config.pfcp.remote_port)) { LOGP(DLPFCP, LOGL_ERROR, "Error in PFCP remote IP: %s\n", - osmo_quote_str_c(OTC_SELECT, hnb_gw->config.pfcp.remote_addr, -1)); + osmo_quote_str_c(OTC_SELECT, g_hnbgw->config.pfcp.remote_addr, -1)); return -1; } /* then convert upf_addr_str to osmo_sockaddr */ if (osmo_sockaddr_str_to_sockaddr(&upf_addr_str, &upf_addr.u.sas)) { LOGP(DLPFCP, LOGL_ERROR, "Error in PFCP remote IP: %s\n", - osmo_quote_str_c(OTC_SELECT, hnb_gw->config.pfcp.remote_addr, -1)); + osmo_quote_str_c(OTC_SELECT, g_hnbgw->config.pfcp.remote_addr, -1)); return -1; } @@ -134,12 +131,12 @@ } /* Associate with UPF */ - hnb_gw->pfcp.cp_peer = osmo_pfcp_cp_peer_alloc(hnb_gw, ep, &upf_addr); - if (!hnb_gw->pfcp.cp_peer) { + g_hnbgw->pfcp.cp_peer = osmo_pfcp_cp_peer_alloc(g_hnbgw, ep, &upf_addr); + if (!g_hnbgw->pfcp.cp_peer) { LOGP(DLPFCP, LOGL_ERROR, "Cannot allocate PFCP CP Peer FSM\n"); return -1; } - if (osmo_pfcp_cp_peer_associate(hnb_gw->pfcp.cp_peer)) { + if (osmo_pfcp_cp_peer_associate(g_hnbgw->pfcp.cp_peer)) { LOGP(DLPFCP, LOGL_ERROR, "Cannot start PFCP CP Peer FSM\n"); return -1; } diff --git a/src/osmo-hnbgw/hnbgw_rua.c b/src/osmo-hnbgw/hnbgw_rua.c index a8dc458..2e03e01 100644 --- a/src/osmo-hnbgw/hnbgw_rua.c +++ b/src/osmo-hnbgw/hnbgw_rua.c @@ -200,7 +200,7 @@ { struct msgb *ranap_msg = NULL; struct hnbgw_context_map *map = NULL; - struct hnbgw_cnlink *cn = hnb->gw->sccp.cnlink; + struct hnbgw_cnlink *cn = g_hnbgw->sccp.cnlink; bool is_ps; switch (cN_DomainIndicator) { diff --git a/src/osmo-hnbgw/hnbgw_vty.c b/src/osmo-hnbgw/hnbgw_vty.c index 8d2366f..30c0d9a 100644 --- a/src/osmo-hnbgw/hnbgw_vty.c +++ b/src/osmo-hnbgw/hnbgw_vty.c @@ -37,9 +37,6 @@ #include <osmocom/mgcp_client/mgcp_client.h> -static void *tall_hnb_ctx = NULL; -static struct hnb_gw *g_hnb_gw = NULL; - static struct cmd_node hnbgw_node = { HNBGW_NODE, "%s(config-hnbgw)# ", @@ -138,29 +135,29 @@ SHOW_STR "Display information on core network link\n") { struct osmo_ss7_route *rt; - struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(g_hnb_gw->sccp.client); + struct osmo_ss7_instance *ss7 = osmo_sccp_get_ss7(g_hnbgw->sccp.client); #define GUARD(STR) \ STR ? STR : "", \ STR ? ":" : "" vty_out(vty, "IuCS: %s <->", - osmo_sccp_user_name(g_hnb_gw->sccp.cnlink->sccp_user)); + osmo_sccp_user_name(g_hnbgw->sccp.cnlink->sccp_user)); vty_out(vty, " %s%s%s%s", - GUARD(g_hnb_gw->config.iucs_remote_addr_name), - osmo_sccp_inst_addr_name(g_hnb_gw->sccp.client, &g_hnb_gw->sccp.iucs_remote_addr), + GUARD(g_hnbgw->config.iucs_remote_addr_name), + osmo_sccp_inst_addr_name(g_hnbgw->sccp.client, &g_hnbgw->sccp.iucs_remote_addr), VTY_NEWLINE); - rt = osmo_ss7_route_lookup(ss7, g_hnb_gw->sccp.iucs_remote_addr.pc); + rt = osmo_ss7_route_lookup(ss7, g_hnbgw->sccp.iucs_remote_addr.pc); vty_out(vty, " SS7 route: %s%s", osmo_ss7_route_name(rt, true), VTY_NEWLINE); vty_out(vty, "IuPS: %s <->", - osmo_sccp_user_name(g_hnb_gw->sccp.cnlink->sccp_user)); + osmo_sccp_user_name(g_hnbgw->sccp.cnlink->sccp_user)); vty_out(vty, " %s%s%s%s", - GUARD(g_hnb_gw->config.iups_remote_addr_name), - osmo_sccp_inst_addr_name(g_hnb_gw->sccp.client, &g_hnb_gw->sccp.iups_remote_addr), + GUARD(g_hnbgw->config.iups_remote_addr_name), + osmo_sccp_inst_addr_name(g_hnbgw->sccp.client, &g_hnbgw->sccp.iups_remote_addr), VTY_NEWLINE); - rt = osmo_ss7_route_lookup(ss7, g_hnb_gw->sccp.iups_remote_addr.pc); + rt = osmo_ss7_route_lookup(ss7, g_hnbgw->sccp.iups_remote_addr.pc); vty_out(vty, " SS7 route: %s%s", osmo_ss7_route_name(rt, true), VTY_NEWLINE); #undef GUARD @@ -226,12 +223,12 @@ struct hnb_context *hnb; unsigned int count = 0; - if (llist_empty(&g_hnb_gw->hnb_list)) { + if (llist_empty(&g_hnbgw->hnb_list)) { vty_out(vty, "No HNB connected%s", VTY_NEWLINE); return CMD_SUCCESS; } - llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) { + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { vty_dump_hnb_info(vty, hnb); count++; } @@ -246,12 +243,12 @@ struct hnb_context *hnb; const char *identity_info = argv[0]; - if (llist_empty(&g_hnb_gw->hnb_list)) { + if (llist_empty(&g_hnbgw->hnb_list)) { vty_out(vty, "No HNB connected%s", VTY_NEWLINE); return CMD_SUCCESS; } - hnb = hnb_context_by_identity_info(g_hnb_gw, identity_info); + hnb = hnb_context_by_identity_info(identity_info); if (hnb == NULL) { vty_out(vty, "No HNB found with identity '%s'%s", identity_info, VTY_NEWLINE); return CMD_SUCCESS; @@ -265,7 +262,7 @@ { struct ue_context *ue; - llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) { + llist_for_each_entry(ue, &g_hnbgw->ue_list, list) { vty_dump_ue_info(vty, ue); } @@ -274,8 +271,7 @@ DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info") { - talloc_report_full(tall_hnb_ctx, stderr); - talloc_report_full(talloc_asn1_ctx, stderr); + talloc_report_full(g_hnbgw, stderr); return CMD_SUCCESS; } @@ -287,7 +283,7 @@ " RANAP InitialUE Messages' GlobalRNC-ID IE. Takes effect as soon as the hNodeB re-registers.\n" "RNC Id value\n") { - g_hnb_gw->config.rnc_id = atoi(argv[0]); + g_hnbgw->config.rnc_id = atoi(argv[0]); return CMD_SUCCESS; } @@ -295,8 +291,8 @@ "Accept Iuh connections on local interface\n" "Local interface IP address (default: " HNBGW_LOCAL_IP_DEFAULT ")") { - talloc_free((void*)g_hnb_gw->config.iuh_local_ip); - g_hnb_gw->config.iuh_local_ip = talloc_strdup(tall_hnb_ctx, argv[0]); + talloc_free((void*)g_hnbgw->config.iuh_local_ip); + g_hnbgw->config.iuh_local_ip = talloc_strdup(g_hnbgw, argv[0]); return CMD_SUCCESS; } @@ -304,7 +300,7 @@ "Accept Iuh connections on local port\n" "Local interface port (default: 29169)") { - g_hnb_gw->config.iuh_local_port = atoi(argv[0]); + g_hnbgw->config.iuh_local_port = atoi(argv[0]); return CMD_SUCCESS; } @@ -314,7 +310,7 @@ "Only accept IMSI identity, reject TMSI or PTMSI\n" "Accept IMSI, TMSI or PTMSI as UE identity\n") { - g_hnb_gw->config.hnbap_allow_tmsi = (*argv[0] == '1'); + g_hnbgw->config.hnbap_allow_tmsi = (*argv[0] == '1'); return CMD_SUCCESS; } @@ -325,9 +321,9 @@ "Use the UMTS Cell ID as log message prefix\n") { if (!strcmp(argv[0], "hnb-id")) - g_hnb_gw->config.log_prefix_hnb_id = true; + g_hnbgw->config.log_prefix_hnb_id = true; else - g_hnb_gw->config.log_prefix_hnb_id = false; + g_hnbgw->config.log_prefix_hnb_id = false; return CMD_SUCCESS; } @@ -351,7 +347,7 @@ "SCCP address to send IuCS to (MSC)\n" "SCCP address book entry name (see 'cs7-instance')\n") { - g_hnb_gw->config.iucs_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]); + g_hnbgw->config.iucs_remote_addr_name = talloc_strdup(g_hnbgw, argv[0]); return CMD_SUCCESS; } @@ -361,7 +357,7 @@ "SCCP address to send IuPS to (SGSN)\n" "SCCP address book entry name (see 'cs7-instance')\n") { - g_hnb_gw->config.iups_remote_addr_name = talloc_strdup(g_hnb_gw, argv[0]); + g_hnbgw->config.iups_remote_addr_name = talloc_strdup(g_hnbgw, argv[0]); return CMD_SUCCESS; } @@ -385,8 +381,8 @@ "Remote UPF's listen IP address; where to send PFCP requests\n" "IP address\n") { - osmo_talloc_replace_string(g_hnb_gw, &g_hnb_gw->config.pfcp.remote_addr, argv[0]); - LOGP(DLPFCP, LOGL_NOTICE, "%p cfg: pfcp remote-addr %s\n", g_hnb_gw, g_hnb_gw->config.pfcp.remote_addr); + osmo_talloc_replace_string(g_hnbgw, &g_hnbgw->config.pfcp.remote_addr, argv[0]); + LOGP(DLPFCP, LOGL_NOTICE, "%p cfg: pfcp remote-addr %s\n", g_hnbgw, g_hnbgw->config.pfcp.remote_addr); return CMD_SUCCESS; } @@ -395,7 +391,7 @@ "Local address for PFCP\n" "IP address\n") { - osmo_talloc_replace_string(g_hnb_gw, &g_hnb_gw->config.pfcp.local_addr, argv[0]); + osmo_talloc_replace_string(g_hnbgw, &g_hnbgw->config.pfcp.local_addr, argv[0]); return CMD_SUCCESS; } @@ -404,7 +400,7 @@ "Local port for PFCP\n" "IP port\n") { - g_hnb_gw->config.pfcp.local_port = atoi(argv[0]); + g_hnbgw->config.pfcp.local_port = atoi(argv[0]); return CMD_SUCCESS; } @@ -413,7 +409,7 @@ static int config_write_hnbgw(struct vty *vty) { vty_out(vty, "hnbgw%s", VTY_NEWLINE); - vty_out(vty, " log-prefix %s%s", g_hnb_gw->config.log_prefix_hnb_id ? "hnb-id" : "umts-cell-id", + vty_out(vty, " log-prefix %s%s", g_hnbgw->config.log_prefix_hnb_id ? "hnb-id" : "umts-cell-id", VTY_NEWLINE); osmo_tdef_vty_groups_write(vty, " "); return CMD_SUCCESS; @@ -426,15 +422,15 @@ vty_out(vty, " iuh%s", VTY_NEWLINE); - addr = g_hnb_gw->config.iuh_local_ip; + addr = g_hnbgw->config.iuh_local_ip; if (addr && (strcmp(addr, HNBGW_LOCAL_IP_DEFAULT) != 0)) vty_out(vty, " local-ip %s%s", addr, VTY_NEWLINE); - port = g_hnb_gw->config.iuh_local_port; + port = g_hnbgw->config.iuh_local_port; if (port && port != IUH_DEFAULT_SCTP_PORT) vty_out(vty, " local-port %u%s", port, VTY_NEWLINE); - if (g_hnb_gw->config.hnbap_allow_tmsi) + if (g_hnbgw->config.hnbap_allow_tmsi) vty_out(vty, " hnbap-allow-tmsi 1%s", VTY_NEWLINE); return CMD_SUCCESS; @@ -442,11 +438,11 @@ static int config_write_hnbgw_iucs(struct vty *vty) { - if (!g_hnb_gw->config.iucs_remote_addr_name) + if (!g_hnbgw->config.iucs_remote_addr_name) return CMD_SUCCESS; vty_out(vty, " iucs%s", VTY_NEWLINE); - vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iucs_remote_addr_name, + vty_out(vty, " remote-addr %s%s", g_hnbgw->config.iucs_remote_addr_name, VTY_NEWLINE); return CMD_SUCCESS; @@ -454,11 +450,11 @@ static int config_write_hnbgw_iups(struct vty *vty) { - if (!g_hnb_gw->config.iups_remote_addr_name) + if (!g_hnbgw->config.iups_remote_addr_name) return CMD_SUCCESS; vty_out(vty, " iups%s", VTY_NEWLINE); - vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.iups_remote_addr_name, + vty_out(vty, " remote-addr %s%s", g_hnbgw->config.iups_remote_addr_name, VTY_NEWLINE); return CMD_SUCCESS; @@ -468,20 +464,17 @@ static int config_write_hnbgw_pfcp(struct vty *vty) { vty_out(vty, " pfcp%s", VTY_NEWLINE); - if (g_hnb_gw->config.pfcp.local_addr) - vty_out(vty, " local-addr %s%s", g_hnb_gw->config.pfcp.local_addr, VTY_NEWLINE); - if (g_hnb_gw->config.pfcp.remote_addr) - vty_out(vty, " remote-addr %s%s", g_hnb_gw->config.pfcp.remote_addr, VTY_NEWLINE); + if (g_hnbgw->config.pfcp.local_addr) + vty_out(vty, " local-addr %s%s", g_hnbgw->config.pfcp.local_addr, VTY_NEWLINE); + if (g_hnbgw->config.pfcp.remote_addr) + vty_out(vty, " remote-addr %s%s", g_hnbgw->config.pfcp.remote_addr, VTY_NEWLINE); return CMD_SUCCESS; } #endif -void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx) +void hnbgw_vty_init(void) { - g_hnb_gw = gw; - tall_hnb_ctx = tall_ctx; - install_element(CONFIG_NODE, &cfg_hnbgw_cmd); install_node(&hnbgw_node, config_write_hnbgw); @@ -515,9 +508,9 @@ install_element(HNBGW_NODE, &cfg_hnbgw_mgcp_cmd); /* Deprecated: Old MGCP config without pooling support in MSC node: */ install_node(&mgcp_node, NULL); - mgcp_client_vty_init(tall_hnb_ctx, MGCP_NODE, g_hnb_gw->config.mgcp_client); + mgcp_client_vty_init(g_hnbgw, MGCP_NODE, g_hnbgw->config.mgcp_client); - mgcp_client_pool_vty_init(HNBGW_NODE, MGW_NODE, " ", g_hnb_gw->mgw_pool); + mgcp_client_pool_vty_init(HNBGW_NODE, MGW_NODE, " ", g_hnbgw->mgw_pool); #if ENABLE_PFCP install_node(&pfcp_node, config_write_hnbgw_pfcp); diff --git a/src/osmo-hnbgw/mgw_fsm.c b/src/osmo-hnbgw/mgw_fsm.c index e07ea3b..f6f1089 100644 --- a/src/osmo-hnbgw/mgw_fsm.c +++ b/src/osmo-hnbgw/mgw_fsm.c @@ -167,7 +167,7 @@ mgw_info.codecs[0] = CODEC_IUFP; mgw_info.codecs_len = 1; - mgw_fsm_priv->mgcpc = mgcp_client_pool_get(map->gw->mgw_pool); + mgw_fsm_priv->mgcpc = mgcp_client_pool_get(g_hnbgw->mgw_pool); if (!mgw_fsm_priv->mgcpc) { LOGPFSML(fi, LOGL_ERROR, "cannot ensure MGW endpoint -- no MGW configured, check configuration!\n"); diff --git a/src/osmo-hnbgw/ps_rab_ass_fsm.c b/src/osmo-hnbgw/ps_rab_ass_fsm.c index 3e4c54a..aa1fe74 100644 --- a/src/osmo-hnbgw/ps_rab_ass_fsm.c +++ b/src/osmo-hnbgw/ps_rab_ass_fsm.c @@ -220,7 +220,6 @@ RANAP_RAB_AssignmentRequestIEs_t *ies = &message->msg.raB_AssignmentRequestIEs; int i; - struct hnb_gw *hnb_gw = map->gw; struct ps_rab_ass *rab_ass; struct osmo_fsm_inst *fi; @@ -230,7 +229,7 @@ rab_ass->ranap_rab_ass_req_message = message; /* Now rab_ass owns message and will clean it up */ - if (!osmo_pfcp_cp_peer_is_associated(hnb_gw->pfcp.cp_peer)) { + if (!osmo_pfcp_cp_peer_is_associated(g_hnbgw->pfcp.cp_peer)) { LOG_MAP(map, DLPFCP, LOGL_ERROR, "PFCP is not associated, cannot set up GTP mapping\n"); goto no_rab; } @@ -413,7 +412,6 @@ struct ps_rab_ass *rab_ass; struct osmo_fsm_inst *fi; RANAP_RAB_AssignmentResponseIEs_t *ies; - struct hnb_gw *hnb_gw = map->gw; /* Make sure we indeed deal with a setup-or-modify list */ ies = &message->msg.raB_AssignmentResponseIEs; @@ -431,7 +429,7 @@ rab_ass->ranap_rab_ass_resp_msgb = ranap_msg; /* Now rab_ass owns message and will clean it up */ - if (!osmo_pfcp_cp_peer_is_associated(hnb_gw->pfcp.cp_peer)) { + if (!osmo_pfcp_cp_peer_is_associated(g_hnbgw->pfcp.cp_peer)) { LOG_PS_RAB_ASS(rab_ass, LOGL_ERROR, "PFCP is not associated, cannot set up GTP mapping\n"); ps_rab_ass_failure(rab_ass); return -1; diff --git a/src/osmo-hnbgw/ps_rab_fsm.c b/src/osmo-hnbgw/ps_rab_fsm.c index f4a1f12..bcf097d 100644 --- a/src/osmo-hnbgw/ps_rab_fsm.c +++ b/src/osmo-hnbgw/ps_rab_fsm.c @@ -87,7 +87,7 @@ /* Allocate with the global hnb_gw, so that we can gracefully handle PFCP release even if a hnb_ctx gets * deallocated. */ - fi = osmo_fsm_inst_alloc(&ps_rab_fsm, map->gw, NULL, LOGL_DEBUG, NULL); + fi = osmo_fsm_inst_alloc(&ps_rab_fsm, g_hnbgw, NULL, LOGL_DEBUG, NULL); OSMO_ASSERT(fi); osmo_fsm_inst_update_id_f_sanitize(fi, '-', "%s-RUA-%u-RAB-%u", hnb_context_name(map->hnb_ctx), map->rua_ctx_id, rab_id); @@ -96,7 +96,6 @@ OSMO_ASSERT(rab); *rab = (struct ps_rab){ .fi = fi, - .hnb_gw = map->gw, .map = map, .rab_id = rab_id, .use_count = { @@ -115,10 +114,10 @@ /* Iterate all ps_rab instances of all context maps and return the one matching the given SEID. * If is_cp_seid == true, match seid with rab->cp_seid (e.g. for received PFCP messages). * Otherwise match seid with rab->up_f_seid.seid (e.g. for sent PFCP messages). */ -struct ps_rab *ps_rab_find_by_seid(struct hnb_gw *hnb_gw, uint64_t seid, bool is_cp_seid) +struct ps_rab *ps_rab_find_by_seid(uint64_t seid, bool is_cp_seid) { struct hnb_context *hnb; - llist_for_each_entry(hnb, &hnb_gw->hnb_list, list) { + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { struct hnbgw_context_map *map; llist_for_each_entry(map, &hnb->map_list, hnb_list) { struct ps_rab *rab; @@ -144,8 +143,7 @@ static struct osmo_pfcp_msg *ps_rab_new_pfcp_msg_req(struct ps_rab *rab, enum osmo_pfcp_message_type msg_type) { - struct hnb_gw *hnb_gw = rab->hnb_gw; - struct osmo_pfcp_msg *m = osmo_pfcp_cp_peer_new_req(hnb_gw->pfcp.cp_peer, msg_type); + struct osmo_pfcp_msg *m = osmo_pfcp_cp_peer_new_req(g_hnbgw->pfcp.cp_peer, msg_type); m->h.seid_present = true; m->h.seid = rab->up_f_seid.seid; @@ -300,7 +298,6 @@ static void ps_rab_fsm_wait_pfcp_est_resp_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) { struct ps_rab *rab = fi->priv; - struct hnb_gw *hnb_gw = rab->hnb_gw; struct osmo_pfcp_msg *m; struct osmo_pfcp_ie_f_seid cp_f_seid; struct osmo_pfcp_msg_session_est_req *ser; @@ -313,11 +310,11 @@ m->h.seid = 0; /* Make a new CP-SEID, our local reference for the PFCP session. */ - rab->cp_seid = osmo_pfcp_next_seid(&hnb_gw->pfcp.cp_peer->next_seid_state); + rab->cp_seid = osmo_pfcp_next_seid(&g_hnbgw->pfcp.cp_peer->next_seid_state); cp_f_seid = (struct osmo_pfcp_ie_f_seid){ .seid = rab->cp_seid, }; - osmo_pfcp_ip_addrs_set(&cp_f_seid.ip_addr, &osmo_pfcp_endpoint_get_cfg(hnb_gw->pfcp.ep)->local_addr); + osmo_pfcp_ip_addrs_set(&cp_f_seid.ip_addr, &osmo_pfcp_endpoint_get_cfg(g_hnbgw->pfcp.ep)->local_addr); m->ies.session_est_req = (struct osmo_pfcp_msg_session_est_req){ .node_id = m->ies.session_est_req.node_id, @@ -336,7 +333,7 @@ /* Send PFCP Session Establishment Request to UPF, wait for response. */ m->ctx.resp_cb = on_pfcp_est_resp; - if (osmo_pfcp_endpoint_tx(hnb_gw->pfcp.ep, m)) { + if (osmo_pfcp_endpoint_tx(g_hnbgw->pfcp.ep, m)) { LOG_PS_RAB(rab, LOGL_ERROR, "Failed to send PFCP message\n"); ps_rab_failure(rab); } @@ -524,7 +521,6 @@ /* We have been given the Access side's remote F-TEID, now in rab->access.remote, and we need to tell the UPF * about it. */ struct ps_rab *rab = fi->priv; - struct hnb_gw *hnb_gw = rab->hnb_gw; struct osmo_pfcp_msg *m; if (!(rab->up_f_seid.ip_addr.v4_present /* || rab->up_f_seid.ip_addr.v6_present */)) { @@ -542,7 +538,7 @@ } m->ctx.resp_cb = on_pfcp_mod_resp; - if (osmo_pfcp_endpoint_tx(hnb_gw->pfcp.ep, m)) { + if (osmo_pfcp_endpoint_tx(g_hnbgw->pfcp.ep, m)) { LOG_PS_RAB(rab, LOGL_ERROR, "Failed to send PFCP message\n"); ps_rab_failure(rab); } @@ -611,7 +607,6 @@ /* If a PFCP session has been established, send a Session Deletion Request and wait for the response. * If no session is established, just terminate. */ struct ps_rab *rab = fi->priv; - struct hnb_gw *hnb_gw = rab->hnb_gw; struct osmo_pfcp_msg *m; if (!(rab->up_f_seid.ip_addr.v4_present /* || rab->up_f_seid.ip_addr.v6_present */)) { @@ -622,7 +617,7 @@ m = ps_rab_new_pfcp_msg_req(rab, OSMO_PFCP_MSGT_SESSION_DEL_REQ); m->ctx.resp_cb = on_pfcp_del_resp; - if (osmo_pfcp_endpoint_tx(hnb_gw->pfcp.ep, m)) { + if (osmo_pfcp_endpoint_tx(g_hnbgw->pfcp.ep, m)) { LOG_PS_RAB(rab, LOGL_ERROR, "Failed to send PFCP message\n"); ps_rab_failure(rab); } -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32618 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I3d54a5bb30c16a990c6def2a0ed207f60a95ef5d Gerrit-Change-Number: 32618 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-hnbgw[master]: rab_ass_fsm.c: fix asn1 memleak when replacing GTP address
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32614 ) Change subject: rab_ass_fsm.c: fix asn1 memleak when replacing GTP address ...................................................................... rab_ass_fsm.c: fix asn1 memleak when replacing GTP address This fix is really weird: by *removing* a FREE() call, fix a leak of the replaced transportLayerAddress. (An in-code comment says some more.) Also remove the other FREE() call that turns out to not be necessary. This has been verified with a ttcn3 test that is not yet submitted, which ensures an empty talloc_asn1_ctx at the end of every test (osmo-ttcn3-hacks I2948ee6f167369a2252f85b493e9653b93c7e4e9 ). Change-Id: I315d04a07b7dfd4dce26e5b5f871318e27e2bdf6 --- M src/osmo-hnbgw/ps_rab_ass_fsm.c 1 file changed, 29 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/14/32614/1 diff --git a/src/osmo-hnbgw/ps_rab_ass_fsm.c b/src/osmo-hnbgw/ps_rab_ass_fsm.c index 464c4d0..2b7b940 100644 --- a/src/osmo-hnbgw/ps_rab_ass_fsm.c +++ b/src/osmo-hnbgw/ps_rab_ass_fsm.c @@ -547,7 +547,15 @@ return; } - /* Replace GTP endpoint */ + /* Replace GTP endpoint. + * memory: ranap_new_transp_layer_addr() frees previous buffer in transportLayerAddress, if any. The + * entire rab_item is freed along with item_ies. + * + * BTW, If I free this explicitly below with + * ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, &rab_item->transportLayerAddress); + * that causes a leak in talloc_asn1_ctx: "iu_helpers.c:205 contains 20 bytes in 1 blocks". + * I couldn't figure out why, but things are freed properly when leaving it all up to item_ies. + */ if (ranap_new_transp_layer_addr(rab_item->transportLayerAddress, &rab->core.local.addr, rab->access.use_x213_nsap) < 0) { ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifiedItem, &item_ies); @@ -564,13 +572,13 @@ teid_be = htonl(rab->core.local.teid); rab_item->iuTransportAssociation->present = RANAP_IuTransportAssociation_PR_gTP_TEI; + /* memory: OCTET_STRING_fromBuf() frees previous buffer in gTP_TEI, if any. The entire rab_item is freed + * along with item_ies. */ OCTET_STRING_fromBuf(&rab_item->iuTransportAssociation->choice.gTP_TEI, (const char *)&teid_be, sizeof(teid_be)); /* Reencode this list item in the RANAP message */ rc = ANY_fromType_aper(&list_ie->value, &asn_DEF_RANAP_RAB_SetupOrModifiedItem, rab_item); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_BIT_STRING, &rab_item->transportLayerAddress); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_OCTET_STRING, &rab_item->iuTransportAssociation->choice.gTP_TEI); if (rc < 0) { ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RAB_SetupOrModifiedItem, &item_ies); LOG_PS_RAB_ASS(rab_ass, LOGL_ERROR, "Re-encoding RANAP PS RAB-AssignmentResponse failed\n"); -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32614 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I315d04a07b7dfd4dce26e5b5f871318e27e2bdf6 Gerrit-Change-Number: 32614 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-hnbgw[master]: ps_rab_ass_fsm.h: fix dup of FSM event enum
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/32615 ) Change subject: ps_rab_ass_fsm.h: fix dup of FSM event enum ...................................................................... ps_rab_ass_fsm.h: fix dup of FSM event enum Change-Id: I20d5fc6d52d08b185ef3aa4f7a59fa0ebb202b18 --- M src/osmo-hnbgw/ps_rab_ass_fsm.c 1 file changed, 10 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/15/32615/1 diff --git a/src/osmo-hnbgw/ps_rab_ass_fsm.c b/src/osmo-hnbgw/ps_rab_ass_fsm.c index 2b7b940..3e4c54a 100644 --- a/src/osmo-hnbgw/ps_rab_ass_fsm.c +++ b/src/osmo-hnbgw/ps_rab_ass_fsm.c @@ -45,6 +45,7 @@ #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/context_map.h> #include <osmocom/hnbgw/ranap_rab_ass.h> +#include <osmocom/hnbgw/ps_rab_ass_fsm.h> #include <osmocom/hnbgw/ps_rab_fsm.h> #include <osmocom/hnbgw/hnbgw_rua.h> @@ -56,13 +57,6 @@ #define LOG_PS_RAB_ASS(RAB_ASS, LOGL, FMT, ARGS...) \ LOGPFSML((RAB_ASS) ? (RAB_ASS)->fi : NULL, LOGL, FMT, ##ARGS) -enum ps_rab_ass_fsm_event { - PS_RAB_ASS_EV_LOCAL_F_TEIDS_RX, - PS_RAB_ASS_EV_RAB_ASS_RESP, - PS_RAB_ASS_EV_RAB_ESTABLISHED, - PS_RAB_ASS_EV_RAB_FAIL, -}; - static const struct value_string ps_rab_ass_fsm_event_names[] = { OSMO_VALUE_STRING(PS_RAB_ASS_EV_LOCAL_F_TEIDS_RX), OSMO_VALUE_STRING(PS_RAB_ASS_EV_RAB_ASS_RESP), -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/32615 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I20d5fc6d52d08b185ef3aa4f7a59fa0ebb202b18 Gerrit-Change-Number: 32615 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in osmo-iuh[master]: fix leak in ranap_new_transp_layer_addr()
by neels 04 May '23

04 May '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-iuh/+/32613 ) Change subject: fix leak in ranap_new_transp_layer_addr() ...................................................................... fix leak in ranap_new_transp_layer_addr() Like BIT_STRING_fromBuf(), free any buffer previously kept in the target BIT_STRING_t. Context: osmo-hnbgw calls ranap_new_transp_layer_addr() to replace an address in a decoded message, before re-encoding it. So far doing so leaked the previous buffer. Change-Id: Ic92fa317644c3a1f2be9badf455d34fe0b8ea2a4 --- M src/iu_helpers.c 1 file changed, 18 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-iuh refs/changes/13/32613/1 diff --git a/src/iu_helpers.c b/src/iu_helpers.c index 6e2c203..718c30a 100644 --- a/src/iu_helpers.c +++ b/src/iu_helpers.c @@ -217,6 +217,8 @@ buf = CALLOC(len, sizeof(uint8_t)); memcpy(buf, ip_addr, ip_len); } + if (out->buf) + FREEMEM(out->buf); out->buf = buf; out->size = len; out->bits_unused = 0; -- To view, visit https://gerrit.osmocom.org/c/osmo-iuh/+/32613 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-iuh Gerrit-Branch: master Gerrit-Change-Id: Ic92fa317644c3a1f2be9badf455d34fe0b8ea2a4 Gerrit-Change-Number: 32613 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in libosmocore[master]: ns2: Count transmitted/dropped in each layer implementation
by lynxis lazus 04 May '23

04 May '23
Attention is currently required from: pespin. lynxis lazus has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/32535 ) Change subject: ns2: Count transmitted/dropped in each layer implementation ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/32535 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I8109cee07f157ebf1806f82a071f58de3a2dcc9c Gerrit-Change-Number: 32535 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 04 May 2023 18:55:25 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • ...
  • 259
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.