From b6c2db569f03bf5eb0f9a12a9bca5c0d7637beca Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 18 Nov 2015 18:11:32 +0100 Subject: [PATCH] gtphub: ares vty and init From sgsn_vty.c, copy the cfg_grx_ggsn_cmd to add an ares server to the static sgsn_instance. This is sort of preliminary. As described in comments, the sgsn_ares functions should actually be separated from the static sgsn structure. gtphub keeps such an sgsn structure just for the sgsn_ares functions. Sponsored-by: On-Waves ehi --- .../doc/examples/osmo-gtphub/osmo-gtphub.cfg | 2 ++ openbsc/src/gprs/gtphub.c | 10 ++++-- openbsc/src/gprs/gtphub_ares.c | 2 +- openbsc/src/gprs/gtphub_vty.c | 31 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/openbsc/doc/examples/osmo-gtphub/osmo-gtphub.cfg b/openbsc/doc/examples/osmo-gtphub/osmo-gtphub.cfg index c9bb4cf42..0dc415047 100644 --- a/openbsc/doc/examples/osmo-gtphub/osmo-gtphub.cfg +++ b/openbsc/doc/examples/osmo-gtphub/osmo-gtphub.cfg @@ -21,3 +21,5 @@ gtphub ! Proxy with nonstandard ports or separate IPs: !ggsn-proxy ctrl 127.0.0.3 2123 user 127.0.0.5 2152 + ! Add a name server for GGSN resolution + !grx-dns-add 192.168.0.1 diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c index 8af3ff7ec..8e1649734 100644 --- a/openbsc/src/gprs/gtphub.c +++ b/openbsc/src/gprs/gtphub.c @@ -1781,7 +1781,14 @@ int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg) int rc; gtphub_init(hub); - gtphub_ares_init(hub); + + /* If a Ctrl plane proxy is configured, ares will never be used. */ + if (!cfg->ggsn_proxy[GTPH_PLANE_CTRL].addr_str) { + if (gtphub_ares_init(hub) != 0) { + LOG(LOGL_FATAL, "Failed to initialize ares\n"); + return -1; + } + } /* TODO set hub->restart_counter from external file. */ @@ -1806,7 +1813,6 @@ int gtphub_start(struct gtphub *hub, struct gtphub_cfg *cfg) } } - for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) { if (gtphub_make_proxy(hub, &hub->sgsn_proxy[plane_idx], diff --git a/openbsc/src/gprs/gtphub_ares.c b/openbsc/src/gprs/gtphub_ares.c index 852255639..7688b4788 100644 --- a/openbsc/src/gprs/gtphub_ares.c +++ b/openbsc/src/gprs/gtphub_ares.c @@ -197,7 +197,7 @@ struct gtphub_peer_port *gtphub_resolve_ggsn_addr(struct gtphub *hub, LOGP(DGTPHUB, LOGL_DEBUG, "GGSN resolved from cache: %s -> %s\n", lookup->apn_oi_str, - gtphub_peer_str(resolved->peer)); + gtphub_port_str(resolved->peer)); return resolved->peer; } } diff --git a/openbsc/src/gprs/gtphub_vty.c b/openbsc/src/gprs/gtphub_vty.c index aead17878..29a731600 100644 --- a/openbsc/src/gprs/gtphub_vty.c +++ b/openbsc/src/gprs/gtphub_vty.c @@ -20,12 +20,22 @@ #include +#include +#include +#include +#include + #include #include #include #include +/* TODO split GRX ares from sgsn into a separate struct and allow use without + * globals. */ +#include +extern struct sgsn_instance *sgsn; + static struct gtphub_cfg *g_cfg = 0; static struct cmd_node gtphub_node = { @@ -57,6 +67,10 @@ static void write_addrs(struct vty *vty, const char *name, c->addr_str, (int)c->port, u->addr_str, (int)u->port, VTY_NEWLINE); + + struct ares_addr_node *server; + for (server = sgsn->ares_servers; server; server = server->next) + vty_out(vty, " grx-dns-add %s%s", inet_ntoa(server->addr.addr4), VTY_NEWLINE); } static int config_write_gtphub(struct vty *vty) @@ -214,6 +228,22 @@ DEFUN(cfg_gtphub_sgsn_proxy, cfg_gtphub_sgsn_proxy_cmd, return CMD_SUCCESS; } + +/* Copied from sgsn_vty.h */ +DEFUN(cfg_grx_ggsn, cfg_grx_ggsn_cmd, + "grx-dns-add A.B.C.D", + "Add DNS server\nIPv4 address\n") +{ + struct ares_addr_node *node = talloc_zero(tall_bsc_ctx, struct ares_addr_node); + node->family = AF_INET; + inet_aton(argv[0], &node->addr.addr4); + + node->next = sgsn->ares_servers; + sgsn->ares_servers = node; + return CMD_SUCCESS; +} + + DEFUN(show_gtphub, show_gtphub_cmd, "show gtphub", SHOW_STR "Display information about the GTP hub") { @@ -238,6 +268,7 @@ int gtphub_vty_init(void) install_element(GTPHUB_NODE, &cfg_gtphub_ggsn_proxy_cmd); install_element(GTPHUB_NODE, &cfg_gtphub_sgsn_proxy_short_cmd); install_element(GTPHUB_NODE, &cfg_gtphub_sgsn_proxy_cmd); + install_element(GTPHUB_NODE, &cfg_grx_ggsn_cmd); return 0; }