VTY: implement 'no log gsmtap [HOSTNAME]' command

Change-Id: I9a4efa1e35cbc22cea06a64a15a369522c32d3c4
This commit is contained in:
Vadim Yanitskiy 2021-12-29 21:58:19 +06:00 committed by fixeria
parent beaf2a2839
commit 2f4186a3d2
4 changed files with 43 additions and 0 deletions

View File

@ -44,6 +44,7 @@ int gsmtap_source_add_sink_fd(int gsmtap_fd);
struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port,
int ofd_wq_mode);
void gsmtap_source_free(struct gsmtap_inst *gti);
int gsmtap_source_add_sink(struct gsmtap_inst *gti);

View File

@ -486,6 +486,22 @@ struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port,
return gti;
}
void gsmtap_source_free(struct gsmtap_inst *gti)
{
if (gti->ofd_wq_mode) {
osmo_fd_unregister(&gti->wq.bfd);
osmo_wqueue_clear(&gti->wq);
if (gti->sink_ofd.fd != -1) {
osmo_fd_unregister(&gti->sink_ofd);
close(gti->sink_ofd.fd);
}
}
close(gti->wq.bfd.fd);
talloc_free(gti);
}
#endif /* HAVE_SYS_SOCKET_H */
const struct value_string gsmtap_gsm_channel_names[] = {

View File

@ -67,6 +67,7 @@
#include <osmocom/core/thread.h>
#include <osmocom/core/select.h>
#include <osmocom/core/write_queue.h>
#include <osmocom/core/gsmtap_util.h>
#include <osmocom/vty/logging.h> /* for LOGGING_STR. */
@ -1313,6 +1314,9 @@ void log_target_destroy(struct log_target *target)
talloc_free((void *)target->tgt_file.fname);
target->tgt_file.fname = NULL;
break;
case LOG_TGT_TYPE_GSMTAP:
gsmtap_source_free(target->tgt_gsmtap.gsmtap_inst);
break;
#ifdef HAVE_SYSLOG_H
case LOG_TGT_TYPE_SYSLOG:
closelog();

View File

@ -830,6 +830,27 @@ DEFUN(cfg_log_gsmtap, cfg_log_gsmtap_cmd,
RET_WITH_UNLOCK(CMD_SUCCESS);
}
DEFUN(cfg_no_log_gsmtap, cfg_no_log_gsmtap_cmd,
"no log gsmtap [HOSTNAME]",
NO_STR LOG_STR "Logging via GSMTAP\n"
"Host name to send the GSMTAP logging to (UDP port 4729)\n")
{
const char *hostname = argc ? argv[0] : "127.0.0.1";
struct log_target *tgt;
log_tgt_mutex_lock();
tgt = log_target_find(LOG_TGT_TYPE_GSMTAP, hostname);
if (tgt == NULL) {
vty_out(vty, "%% Unable to find GSMTAP log target for %s%s",
hostname, VTY_NEWLINE);
RET_WITH_UNLOCK(CMD_WARNING);
}
log_target_destroy(tgt);
RET_WITH_UNLOCK(CMD_SUCCESS);
}
DEFUN(cfg_log_stderr, cfg_log_stderr_cmd,
"log stderr [blocking-io]",
LOG_STR "Logging via STDERR of the process\n"
@ -1245,4 +1266,5 @@ void logging_vty_add_cmds()
install_lib_element(CONFIG_NODE, &cfg_log_systemd_journal_cmd);
install_lib_element(CONFIG_NODE, &cfg_no_log_systemd_journal_cmd);
install_lib_element(CONFIG_NODE, &cfg_log_gsmtap_cmd);
install_lib_element(CONFIG_NODE, &cfg_no_log_gsmtap_cmd);
}