This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/2375 to look at the new patch set (#2). control_if: Add API to initialize control interface without TCP port bind When executing test cases, we don't want to bind to a local TCP port, as we cannot make assumptions as to which ports are actually free. Change-Id: I5717f9dd92d1f143f069cecd4b4c8ba3d03b25f8 --- M include/osmocom/ctrl/control_if.h M src/ctrl/control_if.c 2 files changed, 64 insertions(+), 27 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/75/2375/2 diff --git a/include/osmocom/ctrl/control_if.h b/include/osmocom/ctrl/control_if.h index a740a96..0d37959 100644 --- a/include/osmocom/ctrl/control_if.h +++ b/include/osmocom/ctrl/control_if.h @@ -21,6 +21,7 @@ int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd); int ctrl_cmd_send_trap(struct ctrl_handle *ctrl, const char *name, char *value); +struct ctrl_handle *ctrl_handle_alloc(void *ctx, void *data, ctrl_cmd_lookup lookup); struct ctrl_handle *ctrl_interface_setup(void *data, uint16_t port, ctrl_cmd_lookup lookup); struct ctrl_handle *ctrl_interface_setup_dynip(void *data, diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 5730850..e1b53b4 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -59,6 +59,8 @@ #include <osmocom/vty/command.h> #include <osmocom/vty/vector.h> +extern int osmo_fsm_ctrl_cmds_install(void); + vector ctrl_node_vec; /* global list of control interface lookup helpers */ @@ -694,6 +696,62 @@ return ctrl_interface_setup_dynip(data, "127.0.0.1", port, lookup); } +static int ctrl_initialized = 0; + +/* global ctrl initialization */ +static int ctrl_init(void) +{ + int ret; + + if (ctrl_initialized) + return 0; + + ctrl_node_vec = vector_init(5); + if (!ctrl_node_vec) + goto err; + + ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_rate_ctr); + if (ret) + goto err_vec; + ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter); + if (ret) + goto err_vec; + + ctrl_initialized = 1; + return 0; + +err_vec: + vector_free(ctrl_node_vec); + ctrl_node_vec = NULL; +err: + return -1; +} + +/*! \brief Allocate a CTRL interface handle + * \param[in] ctx Tallo callocation context to be used + * \param[in] data Pointer which will be made available to each + set_..() get_..() verify_..() control command function + * \param[in] lookup Lookup function pointer, can be NULL + * \returns ctrl_handle pointer or NULL in case of errors + */ +struct ctrl_handle *ctrl_handle_alloc(void *ctx, void *data, ctrl_cmd_lookup lookup) +{ + struct ctrl_handle *ctrl; + + ctrl_init(); + + ctrl = talloc_zero(ctx, struct ctrl_handle); + if (!ctrl) + return NULL; + + INIT_LLIST_HEAD(&ctrl->ccon_list); + + ctrl->data = data; + ctrl->lookup = lookup; + + return ctrl; +} + /*! \brief Setup CTRL interface on a given address * \param[in] data Pointer which will be made available to each set_..() get_..() verify_..() control command function @@ -710,44 +768,22 @@ int ret; struct ctrl_handle *ctrl; - ctrl = talloc_zero(data, struct ctrl_handle); + ctrl = ctrl_handle_alloc(data, data, lookup); if (!ctrl) return NULL; - - INIT_LLIST_HEAD(&ctrl->ccon_list); - - ctrl->data = data; - ctrl->lookup = lookup; - - ctrl_node_vec = vector_init(5); - if (!ctrl_node_vec) - goto err; /* Listen for control connections */ ctrl->listen_fd.cb = listen_fd_cb; ctrl->listen_fd.data = ctrl; ret = osmo_sock_init_ofd(&ctrl->listen_fd, AF_INET, SOCK_STREAM, IPPROTO_TCP, bind_addr, port, OSMO_SOCK_F_BIND); - if (ret < 0) - goto err_vec; - - ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_rate_ctr); - if (ret) - goto err_vec; - ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter); - if (ret) - goto err_vec; + if (ret < 0) { + talloc_free(ctrl); + return NULL; + } LOGP(DLCTRL, LOGL_NOTICE, "CTRL at %s %u\n", bind_addr, port); return ctrl; -err_vec: - vector_free(ctrl_node_vec); - ctrl_node_vec = NULL; -err: - LOGP(DLCTRL, LOGL_ERROR, "Cannot bind CTRL at %s %u\n", - bind_addr, port); - talloc_free(ctrl); - return NULL; } /*! \brief Install a lookup helper function for control nodes -- To view, visit https://gerrit.osmocom.org/2375 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I5717f9dd92d1f143f069cecd4b4c8ba3d03b25f8 Gerrit-PatchSet: 2 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder