USSD: Add Core USSD handling + VTY routing config to HLR

Change-Id: I3cfd7cd401ea32b7e92f1124d129099d9f7dc6e6
This commit is contained in:
Harald Welte 2018-06-15 22:04:28 +02:00
parent d5807b8c87
commit 4956ae1f70
8 changed files with 288 additions and 0 deletions

View File

@ -32,6 +32,7 @@ noinst_HEADERS = \
ctrl.h \
hlr_vty.h \
hlr_vty_subscr.h \
hlr_ussd.h \
db_bootstrap.h \
$(NULL)
@ -55,6 +56,7 @@ osmo_hlr_SOURCES = \
hlr_vty.c \
hlr_vty_subscr.c \
gsup_send.c \
hlr_ussd.c \
$(NULL)
osmo_hlr_LDADD = \

View File

@ -559,6 +559,7 @@ int main(int argc, char **argv)
vty_info.tall_ctx = hlr_ctx;
g_hlr = talloc_zero(hlr_ctx, struct hlr);
INIT_LLIST_HEAD(&g_hlr->euse_list);
rc = osmo_init_logging2(hlr_ctx, &hlr_log_info);
if (rc < 0) {

View File

@ -23,6 +23,9 @@
#pragma once
#include <stdbool.h>
#include <osmocom/core/linuxlist.h>
struct hlr_euse;
struct hlr {
/* GSUP server pointer */
@ -37,6 +40,9 @@ struct hlr {
/* Local bind addr */
char *gsup_bind_addr;
struct llist_head euse_list;
struct hlr_euse *euse_default;
};
extern struct hlr *g_hlr;

93
src/hlr_ussd.c Normal file
View File

@ -0,0 +1,93 @@
/* OsmoHLR VTY implementation */
/* (C) 2018 Harald Welte <laforge@gnumonks.org>
*
* 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 <osmocom/core/talloc.h>
#include <stdint.h>
#include <string.h>
#include "hlr.h"
#include "hlr_ussd.h"
struct hlr_euse *euse_find(struct hlr *hlr, const char *name)
{
struct hlr_euse *euse;
llist_for_each_entry(euse, &hlr->euse_list, list) {
if (!strcmp(euse->name, name))
return euse;
}
return NULL;
}
struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name)
{
struct hlr_euse *euse = euse_find(hlr, name);
if (euse)
return NULL;
euse = talloc_zero(hlr, struct hlr_euse);
euse->name = talloc_strdup(euse, name);
euse->hlr = hlr;
INIT_LLIST_HEAD(&euse->routes);
llist_add_tail(&euse->list, &hlr->euse_list);
return euse;
}
void euse_del(struct hlr_euse *euse)
{
llist_del(&euse->list);
talloc_free(euse);
}
struct hlr_euse_route *euse_route_find(struct hlr_euse *euse, const char *prefix)
{
struct hlr_euse_route *rt;
llist_for_each_entry(rt, &euse->routes, list) {
if (!strcmp(rt->prefix, prefix))
return rt;
}
return NULL;
}
struct hlr_euse_route *euse_route_prefix_alloc(struct hlr_euse *euse, const char *prefix)
{
struct hlr_euse_route *rt;
if (euse_route_find(euse, prefix))
return NULL;
rt = talloc_zero(euse, struct hlr_euse_route);
rt->prefix = talloc_strdup(rt, prefix);
rt->euse = euse;
llist_add_tail(&rt->list, &euse->routes);
return rt;
}
void euse_route_del(struct hlr_euse_route *rt)
{
llist_del(&rt->list);
talloc_free(rt);
}

30
src/hlr_ussd.h Normal file
View File

@ -0,0 +1,30 @@
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
struct hlr_euse_route {
/* hlr_euse.routes */
struct llist_head list;
struct hlr_euse *euse;
const char *prefix;
};
struct hlr_euse {
/* list in the per-hlr list of EUSEs */
struct llist_head list;
struct hlr *hlr;
/* name (must match the IPA ID tag) */
const char *name;
/* human-readable description */
const char *description;
/* list of hlr_euse_route */
struct llist_head routes;
};
struct hlr_euse *euse_find(struct hlr *hlr, const char *name);
struct hlr_euse *euse_alloc(struct hlr *hlr, const char *name);
void euse_del(struct hlr_euse *euse);
struct hlr_euse_route *euse_route_find(struct hlr_euse *euse, const char *prefix);
struct hlr_euse_route *euse_route_prefix_alloc(struct hlr_euse *euse, const char *prefix);
void euse_route_del(struct hlr_euse_route *rt);

View File

@ -6,6 +6,10 @@
*
* All Rights Reserved
*
* (C) 2018 Harald Welte <laforge@gnumonks.org>
*
* 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
@ -117,12 +121,153 @@ DEFUN(cfg_hlr_gsup_bind_ip,
return CMD_SUCCESS;
}
/***********************************************************************
* External USSD Entity
***********************************************************************/
#include "hlr_ussd.h"
DEFUN(cfg_euse_route_pfx, cfg_euse_route_pfx_cmd,
"route prefix PREFIX",
"")
{
struct hlr_euse *euse = vty->index;
struct hlr_euse_route *rt = euse_route_find(euse, argv[0]);
if (rt) {
vty_out(vty, "%% Cannot add [another?] route for prefix %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
euse_route_prefix_alloc(euse, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_euse_no_route_pfx, cfg_euse_no_route_pfx_cmd,
"no route prefix PREFIX",
NO_STR "")
{
struct hlr_euse *euse = vty->index;
struct hlr_euse_route *rt = euse_route_find(euse, argv[0]);
if (!rt) {
vty_out(vty, "%% Cannot find route for prefix %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
euse_route_del(rt);
return CMD_SUCCESS;
}
DEFUN(cfg_euse_defaultroute, cfg_euse_defaultroute_cmd,
"default-route",
"Set this EUSE as default-route for all USSD to unknown destinations\n")
{
struct hlr_euse *euse = vty->index;
if (g_hlr->euse_default != euse) {
vty_out(vty, "Switching default route from %s to %s%s",
g_hlr->euse_default->name, euse->name, VTY_NEWLINE);
g_hlr->euse_default = euse;
}
return CMD_SUCCESS;
}
DEFUN(cfg_euse_no_defaultroute, cfg_euse_no_defaultroute_cmd,
"no default-route",
NO_STR "Remove this EUSE as default-route for all USSD to unknown destinations\n")
{
struct hlr_euse *euse = vty->index;
if (g_hlr->euse_default != euse) {
vty_out(vty, "%% Current EUSE is no default route, cannot delete it%s", VTY_NEWLINE);
return CMD_WARNING;
}
g_hlr->euse_default = NULL;
return CMD_SUCCESS;
}
struct cmd_node euse_node = {
EUSE_NODE,
"%s(config-hlr-euse)# ",
1,
};
DEFUN(cfg_euse, cfg_euse_cmd,
"euse NAME",
"Configure a particular External USSD Entity\n"
"Alphanumeric name of the External USSD Entity\n")
{
struct hlr_euse *euse;
const char *id = argv[0];
euse = euse_find(g_hlr, id);
if (!euse) {
euse = euse_alloc(g_hlr, id);
if (!euse)
return CMD_WARNING;
}
vty->index = euse;
vty->index_sub = &euse->description;
vty->node = EUSE_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_no_euse, cfg_no_euse_cmd,
"no euse NAME",
NO_STR "Remove a particular External USSD Entity\n"
"Alphanumeric name of the External USSD Entity\n")
{
struct hlr_euse *euse = euse_find(g_hlr, argv[0]);
if (!euse) {
vty_out(vty, "%% Cannot remove non-existant EUSE %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (g_hlr->euse_default == euse) {
vty_out(vty, "%% Cannot remove EUSE %s, it is the default route%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
euse_del(euse);
return CMD_SUCCESS;
}
static void dump_one_euse(struct vty *vty, struct hlr_euse *euse)
{
struct hlr_euse_route *er;
vty_out(vty, " euse %s%s", euse->name, VTY_NEWLINE);
llist_for_each_entry(er, &euse->routes, list)
vty_out(vty, " route prefix %s%s", er->prefix, VTY_NEWLINE);
if (g_hlr->euse_default == euse)
vty_out(vty, " default-route%s", VTY_NEWLINE);
}
static int config_write_euse(struct vty *vty)
{
struct hlr_euse *euse;
llist_for_each_entry(euse, &g_hlr->euse_list, list)
dump_one_euse(vty, euse);
return 0;
}
/***********************************************************************
* Common Code
***********************************************************************/
int hlr_vty_go_parent(struct vty *vty)
{
switch (vty->node) {
case GSUP_NODE:
case EUSE_NODE:
vty->node = HLR_NODE;
vty->index = NULL;
vty->index_sub = NULL;
break;
default:
case HLR_NODE:
@ -165,5 +310,13 @@ void hlr_vty_init(const struct log_info *cat)
install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
install_element(HLR_NODE, &cfg_euse_cmd);
install_element(HLR_NODE, &cfg_no_euse_cmd);
install_node(&euse_node, config_write_euse);
install_element(EUSE_NODE, &cfg_euse_route_pfx_cmd);
install_element(EUSE_NODE, &cfg_euse_no_route_pfx_cmd);
install_element(EUSE_NODE, &cfg_euse_defaultroute_cmd);
install_element(EUSE_NODE, &cfg_euse_no_defaultroute_cmd);
hlr_vty_subscriber_init();
}

View File

@ -30,6 +30,7 @@
enum hlr_vty_node {
HLR_NODE = _LAST_OSMOVTY_NODE + 1,
GSUP_NODE,
EUSE_NODE,
};
int hlr_vty_is_config_node(struct vty *vty, int node);

View File

@ -70,6 +70,8 @@ OsmoHLR(config-hlr)# list
exit
end
gsup
euse NAME
no euse NAME
OsmoHLR(config-hlr)# gsup
OsmoHLR(config-hlr-gsup)# list