Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 1 | /* Control Interface Implementation for the Gb-proxy */ |
| 2 | /* |
| 3 | * (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Daniel Willmann |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <osmocom/core/talloc.h> |
| 24 | |
| 25 | |
| 26 | #include <osmocom/gprs/gprs_bssgp.h> |
| 27 | #include <osmocom/gprs/gprs_ns.h> |
| 28 | |
| 29 | #include <osmocom/ctrl/control_if.h> |
| 30 | #include <osmocom/ctrl/control_cmd.h> |
| 31 | #include <osmocom/sgsn/gb_proxy.h> |
| 32 | #include <osmocom/sgsn/debug.h> |
| 33 | |
| 34 | extern vector ctrl_node_vec; |
| 35 | |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 36 | struct nsvc_cb_data { |
| 37 | struct ctrl_cmd *cmd; |
| 38 | uint16_t nsei; |
| 39 | bool is_sgsn; |
| 40 | }; |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 41 | |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 42 | static int ctrl_nsvc_state_cb(struct gprs_ns2_vc *nsvc, void *ctx) { |
| 43 | struct nsvc_cb_data *data = (struct nsvc_cb_data *)ctx; |
| 44 | struct ctrl_cmd *cmd = (struct ctrl_cmd *)data->cmd; |
| 45 | |
| 46 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%s,%s,%s\n", |
| 47 | data->nsei, gprs_ns2_ll_str(nsvc), gprs_ns2_nsvc_state_name(nsvc), |
| 48 | data->is_sgsn ? "SGSN" : "BSS" ); |
| 49 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 53 | static int get_nsvc_state(struct ctrl_cmd *cmd, void *data) |
| 54 | { |
| 55 | struct gbproxy_config *cfg = data; |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 56 | struct gprs_ns2_inst *nsi = cfg->nsi; |
| 57 | struct gprs_ns2_nse *nse; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 58 | struct gbproxy_nse *nse_peer; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 59 | int i; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 60 | |
| 61 | cmd->reply = talloc_strdup(cmd, ""); |
| 62 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 63 | /* NS-VCs for SGSN */ |
| 64 | nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn_nsei); |
| 65 | if (nse) |
| 66 | gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd); |
| 67 | /* NS-VCs for SGSN2 */ |
| 68 | nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn2_nsei); |
| 69 | if (nse) |
| 70 | gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 71 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 72 | /* NS-VCs for BSS peers */ |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 73 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 74 | nse = gprs_ns2_nse_by_nsei(nsi, nse_peer->nsei); |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 75 | if (nse) |
| 76 | gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 77 | } |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 78 | |
| 79 | return CTRL_CMD_REPLY; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | CTRL_CMD_DEFINE_RO(nsvc_state, "nsvc-state"); |
| 83 | |
| 84 | static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data) |
| 85 | { |
| 86 | struct gbproxy_config *cfg = data; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 87 | struct gbproxy_nse *nse_peer; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame^] | 88 | int i, j; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 89 | |
| 90 | cmd->reply = talloc_strdup(cmd, ""); |
| 91 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 92 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 93 | struct gbproxy_bvc *bvc; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame^] | 94 | hash_for_each(nse_peer->bvcs, j, bvc, list) { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 95 | struct gprs_ra_id raid; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 96 | gsm48_parse_ra(&raid, bvc->ra); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 97 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 98 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u,%u,%u,%u,%s\n", |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 99 | nse_peer->nsei, bvc->bvci, |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 100 | raid.mcc, raid.mnc, |
| 101 | raid.lac, raid.rac, |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 102 | bvc->blocked ? "BLOCKED" : "UNBLOCKED"); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 103 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | return CTRL_CMD_REPLY; |
| 107 | } |
| 108 | |
| 109 | CTRL_CMD_DEFINE_RO(gbproxy_state, "gbproxy-state"); |
| 110 | |
| 111 | static int get_num_peers(struct ctrl_cmd *cmd, void *data) |
| 112 | { |
| 113 | struct gbproxy_config *cfg = data; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 114 | struct gbproxy_nse *nse_peer; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame^] | 115 | struct gbproxy_bvc *bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 116 | uint32_t count = 0; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame^] | 117 | int i, j; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 118 | |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame^] | 119 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
| 120 | hash_for_each(nse_peer->bvcs, j, bvc, list) |
| 121 | count++; |
| 122 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 123 | |
| 124 | cmd->reply = talloc_strdup(cmd, ""); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 125 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u", count); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 126 | |
| 127 | return CTRL_CMD_REPLY; |
| 128 | } |
| 129 | CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers"); |
| 130 | |
| 131 | int gb_ctrl_cmds_install(void) |
| 132 | { |
| 133 | int rc = 0; |
| 134 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state); |
| 135 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state); |
| 136 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers); |
| 137 | |
| 138 | return rc; |
| 139 | } |