diff options
Diffstat (limited to 'src/dgsm_vty.c')
-rw-r--r-- | src/dgsm_vty.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/dgsm_vty.c b/src/dgsm_vty.c index 4c686da..d204a4a 100644 --- a/src/dgsm_vty.c +++ b/src/dgsm_vty.c @@ -22,9 +22,11 @@ #include <osmocom/mslookup/mslookup_client_mdns.h> #include <osmocom/mslookup/mdns.h> #include <osmocom/hlr/hlr_vty.h> +#include <osmocom/hlr/proxy.h> #include <osmocom/hlr/mslookup_server.h> #include <osmocom/hlr/mslookup_server_mdns.h> #include <osmocom/gsupclient/cni_peer_id.h> +#include <osmocom/gsm/gsm23003.h> struct cmd_node mslookup_node = { MSLOOKUP_NODE, @@ -606,6 +608,101 @@ DEFUN(do_mslookup_show_services, return CMD_SUCCESS; } +struct proxy_subscr_listentry { + struct llist_head entry; + timestamp_t last_update; + struct proxy_subscr data; +}; + +struct proxy_pending_gsup_req { + struct llist_head entry; + struct osmo_gsup_req *req; + timestamp_t received_at; +}; + +static void write_one_proxy(struct vty *vty, struct proxy_subscr_listentry *e) +{ + struct proxy_subscr p = e->data; + uint32_t age; + + vty_out(vty, "%-12s %-16s %-12s:%-4u ", + strlen(p.msisdn) == 0 ? "Unknown" : p.msisdn, + strlen(p.imsi) == 0 ? "Unknown" : p.imsi, + p.remote_hlr_addr.ip ? p.remote_hlr_addr.ip : "Unknown", + p.remote_hlr_addr.port); + + if (!timestamp_age(&e->last_update, &age)) { + vty_out(vty, "Invalid%s", VTY_NEWLINE); + return; + } + +#define UNIT_AGO(UNITNAME, UNITVAL) \ + if (age >= (UNITVAL)) { \ + vty_out(vty, "%u%s", age / (UNITVAL), UNITNAME); \ + age = age % (UNITVAL); \ + } + UNIT_AGO("d", 60*60*24); + UNIT_AGO("h", 60*60); + UNIT_AGO("m", 60); + UNIT_AGO("s", 1); + vty_out(vty, "%s", VTY_NEWLINE); +#undef UNIT_AGO +} + +static void write_one_proxy_request(struct vty *vty, struct osmo_gsup_req *r) +{ + vty_out(vty, "IMSI: %s TYPE: %s%s", + r->gsup.imsi, + osmo_gsup_message_type_name(r->gsup.message_type), + VTY_NEWLINE); +} + +DEFUN(do_proxy_del_sub, + do_proxy_del_sub_cmd, + "proxy subscriber-delete [IMSI]", + "Subscriber Proxy \n" + "Delete by IMSI\n" + "IMSI of subscriber to delete from the Proxy" + ) +{ + const char *imsi = argv[0]; + if (!osmo_imsi_str_valid(imsi)) { + vty_out(vty, "%% Not a valid IMSI: %s%s", imsi, VTY_NEWLINE); + return CMD_WARNING; + } + if (proxy_subscr_del(g_hlr->gs->proxy, imsi) == 0) + return CMD_SUCCESS; + vty_out(vty, "%% Unable to delete a Proxy for: %s%s", imsi, VTY_NEWLINE); + return CMD_WARNING; +} + +DEFUN(do_proxy_show, + do_proxy_show_cmd, + "show proxy", + SHOW_STR "Proxy Entries\n") +{ + struct proxy_subscr_listentry *e; + struct proxy_pending_gsup_req *p; + unsigned int count = 0; + + vty_out(vty, "MSISDN IMSI HLR AGE%s", VTY_NEWLINE); + vty_out(vty, "------------ ---------------- -------------------- ------%s", VTY_NEWLINE); + llist_for_each_entry(e, &g_hlr->gs->proxy->subscr_list, entry) { + count++; + write_one_proxy(vty, e); + } + + vty_out(vty, "%s%s", + (count == 0) ? "% No proxy subscribers" : "", VTY_NEWLINE); + if (!llist_count(&g_hlr->gs->proxy->pending_gsup_reqs)) + return CMD_SUCCESS; + vty_out(vty, "In-flight Proxy Subscribers Requests:%s", VTY_NEWLINE); + llist_for_each_entry(p, &g_hlr->gs->proxy->pending_gsup_reqs, entry) { + write_one_proxy_request(vty, p->req); + } + return CMD_SUCCESS; +} + void dgsm_vty_init(void) { install_element(CONFIG_NODE, &cfg_mslookup_cmd); @@ -648,4 +745,6 @@ void dgsm_vty_init(void) install_element(MSLOOKUP_CLIENT_NODE, &cfg_mslookup_client_no_gateway_proxy_cmd); install_element_ve(&do_mslookup_show_services_cmd); + install_element_ve(&do_proxy_show_cmd); + install_element_ve(&do_proxy_del_sub_cmd); } |