Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 1 | /* VTY interface for our GPRS Networks Service (NS) implementation */ |
| 2 | |
| 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 15 | * GNU General Public License for more details. |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <errno.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | #include <arpa/inet.h> |
| 28 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/msgb.h> |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 30 | #include <osmocom/core/byteswap.h> |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 31 | #include <osmocom/gsm/tlv.h> |
| 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/select.h> |
| 34 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 35 | #include <osmocom/gprs/gprs_ns.h> |
| 36 | #include <osmocom/gprs/gprs_bssgp.h> |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 37 | |
Harald Welte | ac1a715 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 38 | #include <osmocom/vty/vty.h> |
| 39 | #include <osmocom/vty/command.h> |
| 40 | #include <osmocom/vty/logging.h> |
| 41 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 167281e | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 42 | #include <osmocom/vty/misc.h> |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 43 | |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 44 | #include "common_vty.h" |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 45 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 46 | static struct gprs_ns_inst *vty_nsi = NULL; |
| 47 | |
| 48 | /* FIXME: this should go to some common file as it is copied |
| 49 | * in vty_interface.c of the BSC */ |
| 50 | static const struct value_string gprs_ns_timer_strs[] = { |
| 51 | { 0, "tns-block" }, |
| 52 | { 1, "tns-block-retries" }, |
| 53 | { 2, "tns-reset" }, |
| 54 | { 3, "tns-reset-retries" }, |
| 55 | { 4, "tns-test" }, |
| 56 | { 5, "tns-alive" }, |
| 57 | { 6, "tns-alive-retries" }, |
| 58 | { 0, NULL } |
| 59 | }; |
| 60 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 61 | static void log_set_nsvc_filter(struct log_target *target, |
| 62 | struct gprs_nsvc *nsvc) |
| 63 | { |
| 64 | if (nsvc) { |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 65 | target->filter_map |= (1 << LOG_FLT_GB_NSVC); |
| 66 | target->filter_data[LOG_FLT_GB_NSVC] = nsvc; |
| 67 | } else if (target->filter_data[LOG_FLT_GB_NSVC]) { |
| 68 | target->filter_map = ~(1 << LOG_FLT_GB_NSVC); |
| 69 | target->filter_data[LOG_FLT_GB_NSVC] = NULL; |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 73 | static struct cmd_node ns_node = { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 74 | L_NS_NODE, |
Jacob Erlbeck | 35fe87c | 2013-10-24 01:33:20 +0200 | [diff] [blame] | 75 | "%s(config-ns)# ", |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 76 | 1, |
| 77 | }; |
| 78 | |
| 79 | static int config_write_ns(struct vty *vty) |
| 80 | { |
| 81 | struct gprs_nsvc *nsvc; |
| 82 | unsigned int i; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 83 | struct in_addr ia; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 84 | |
| 85 | vty_out(vty, "ns%s", VTY_NEWLINE); |
| 86 | |
| 87 | llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) { |
| 88 | if (!nsvc->persistent) |
| 89 | continue; |
| 90 | vty_out(vty, " nse %u nsvci %u%s", |
| 91 | nsvc->nsei, nsvc->nsvci, VTY_NEWLINE); |
| 92 | vty_out(vty, " nse %u remote-role %s%s", |
| 93 | nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss", |
| 94 | VTY_NEWLINE); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 95 | switch (nsvc->ll) { |
| 96 | case GPRS_NS_LL_UDP: |
| 97 | vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei, |
| 98 | VTY_NEWLINE); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 99 | vty_out(vty, " nse %u remote-ip %s%s", |
| 100 | nsvc->nsei, |
| 101 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 102 | VTY_NEWLINE); |
| 103 | vty_out(vty, " nse %u remote-port %u%s", |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 104 | nsvc->nsei, osmo_ntohs(nsvc->ip.bts_addr.sin_port), |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 105 | VTY_NEWLINE); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 106 | break; |
| 107 | case GPRS_NS_LL_FR_GRE: |
| 108 | vty_out(vty, " nse %u encapsulation framerelay-gre%s", |
| 109 | nsvc->nsei, VTY_NEWLINE); |
| 110 | vty_out(vty, " nse %u remote-ip %s%s", |
| 111 | nsvc->nsei, |
| 112 | inet_ntoa(nsvc->frgre.bts_addr.sin_addr), |
| 113 | VTY_NEWLINE); |
| 114 | vty_out(vty, " nse %u fr-dlci %u%s", |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 115 | nsvc->nsei, osmo_ntohs(nsvc->frgre.bts_addr.sin_port), |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 116 | VTY_NEWLINE); |
| 117 | default: |
| 118 | break; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++) |
| 123 | vty_out(vty, " timer %s %u%s", |
| 124 | get_value_string(gprs_ns_timer_strs, i), |
| 125 | vty_nsi->timeout[i], VTY_NEWLINE); |
| 126 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 127 | if (vty_nsi->nsip.local_ip) { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 128 | ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 129 | vty_out(vty, " encapsulation udp local-ip %s%s", |
| 130 | inet_ntoa(ia), VTY_NEWLINE); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 131 | } |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 132 | if (vty_nsi->nsip.local_port) |
| 133 | vty_out(vty, " encapsulation udp local-port %u%s", |
| 134 | vty_nsi->nsip.local_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 135 | if (vty_nsi->nsip.dscp) |
| 136 | vty_out(vty, " encapsulation udp dscp %d%s", |
| 137 | vty_nsi->nsip.dscp, VTY_NEWLINE); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 138 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 139 | vty_out(vty, " encapsulation framerelay-gre enabled %u%s", |
| 140 | vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 141 | if (vty_nsi->frgre.local_ip) { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 142 | ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 143 | vty_out(vty, " encapsulation framerelay-gre local-ip %s%s", |
| 144 | inet_ntoa(ia), VTY_NEWLINE); |
| 145 | } |
| 146 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 147 | return CMD_SUCCESS; |
| 148 | } |
| 149 | |
| 150 | DEFUN(cfg_ns, cfg_ns_cmd, |
| 151 | "ns", |
| 152 | "Configure the GPRS Network Service") |
| 153 | { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 154 | vty->node = L_NS_NODE; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 158 | static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats) |
| 159 | { |
| 160 | vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s", |
| 161 | nsvc->nsei, nsvc->nsvci, |
| 162 | nsvc->remote_end_is_sgsn ? "SGSN" : "BSS", |
| 163 | nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD", |
| 164 | nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED"); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 165 | if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE) |
| 166 | vty_out(vty, ", %s %15s:%u", |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 167 | nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE", |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 168 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 169 | osmo_ntohs(nsvc->ip.bts_addr.sin_port)); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 170 | vty_out(vty, "%s", VTY_NEWLINE); |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 171 | if (stats) { |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 172 | vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 173 | vty_out_stat_item_group(vty, " ", nsvc->statg); |
| 174 | } |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 177 | static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats) |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 178 | { |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 179 | struct gprs_nsvc *nsvc; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 180 | struct in_addr ia; |
| 181 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 182 | ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 183 | vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s", |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 184 | inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE); |
| 185 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 186 | ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 187 | vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s", |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 188 | inet_ntoa(ia), VTY_NEWLINE); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 189 | |
| 190 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
Harald Welte | dd1c83c | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 191 | if (nsvc == nsi->unknown_nsvc) |
| 192 | continue; |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 193 | dump_nse(vty, nsvc, stats); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 194 | } |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 195 | } |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 196 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 197 | DEFUN(show_ns, show_ns_cmd, "show ns", |
| 198 | SHOW_STR "Display information about the NS protocol") |
| 199 | { |
| 200 | struct gprs_ns_inst *nsi = vty_nsi; |
| 201 | dump_ns(vty, nsi, 0); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 202 | return CMD_SUCCESS; |
| 203 | } |
| 204 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 205 | DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats", |
| 206 | SHOW_STR |
| 207 | "Display information about the NS protocol\n" |
| 208 | "Include statistics\n") |
| 209 | { |
| 210 | struct gprs_ns_inst *nsi = vty_nsi; |
| 211 | dump_ns(vty, nsi, 1); |
| 212 | return CMD_SUCCESS; |
| 213 | } |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 214 | |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 215 | DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]", |
| 216 | SHOW_STR "Display information about the NS protocol\n" |
| 217 | "Select one NSE by its NSE Identifier\n" |
| 218 | "Select one NSE by its NS-VC Identifier\n" |
| 219 | "The Identifier of selected type\n" |
| 220 | "Include Statistics\n") |
| 221 | { |
| 222 | struct gprs_ns_inst *nsi = vty_nsi; |
| 223 | struct gprs_nsvc *nsvc; |
| 224 | uint16_t id = atoi(argv[1]); |
| 225 | int show_stats = 0; |
| 226 | |
| 227 | if (!strcmp(argv[0], "nsei")) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 228 | nsvc = gprs_nsvc_by_nsei(nsi, id); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 229 | else |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 230 | nsvc = gprs_nsvc_by_nsvci(nsi, id); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 231 | |
| 232 | if (!nsvc) { |
| 233 | vty_out(vty, "No such NS Entity%s", VTY_NEWLINE); |
| 234 | return CMD_WARNING; |
| 235 | } |
| 236 | |
| 237 | if (argc >= 3) |
| 238 | show_stats = 1; |
| 239 | |
| 240 | dump_nse(vty, nsvc, show_stats); |
| 241 | return CMD_SUCCESS; |
| 242 | } |
| 243 | |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 244 | #define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n" |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 245 | |
| 246 | DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, |
| 247 | "nse <0-65535> nsvci <0-65534>", |
| 248 | NSE_CMD_STR |
| 249 | "NS Virtual Connection\n" |
| 250 | "NS Virtual Connection ID (NSVCI)\n" |
| 251 | ) |
| 252 | { |
| 253 | uint16_t nsei = atoi(argv[0]); |
| 254 | uint16_t nsvci = atoi(argv[1]); |
| 255 | struct gprs_nsvc *nsvc; |
| 256 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 257 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 258 | if (!nsvc) { |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 259 | nsvc = gprs_nsvc_create(vty_nsi, nsvci); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 260 | nsvc->nsei = nsei; |
| 261 | } |
| 262 | nsvc->nsvci = nsvci; |
| 263 | /* All NSVCs that are explicitly configured by VTY are |
| 264 | * marked as persistent so we can write them to the config |
| 265 | * file at some later point */ |
| 266 | nsvc->persistent = 1; |
| 267 | |
| 268 | return CMD_SUCCESS; |
| 269 | } |
| 270 | |
| 271 | DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd, |
| 272 | "nse <0-65535> remote-ip A.B.C.D", |
| 273 | NSE_CMD_STR |
| 274 | "Remote IP Address\n" |
| 275 | "Remote IP Address\n") |
| 276 | { |
| 277 | uint16_t nsei = atoi(argv[0]); |
| 278 | struct gprs_nsvc *nsvc; |
| 279 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 280 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 281 | if (!nsvc) { |
| 282 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 283 | return CMD_WARNING; |
| 284 | } |
| 285 | inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr); |
| 286 | |
| 287 | return CMD_SUCCESS; |
| 288 | |
| 289 | } |
| 290 | |
| 291 | DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, |
| 292 | "nse <0-65535> remote-port <0-65535>", |
| 293 | NSE_CMD_STR |
| 294 | "Remote UDP Port\n" |
| 295 | "Remote UDP Port Number\n") |
| 296 | { |
| 297 | uint16_t nsei = atoi(argv[0]); |
| 298 | uint16_t port = atoi(argv[1]); |
| 299 | struct gprs_nsvc *nsvc; |
| 300 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 301 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 302 | if (!nsvc) { |
| 303 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 304 | return CMD_WARNING; |
| 305 | } |
| 306 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 307 | if (nsvc->ll != GPRS_NS_LL_UDP) { |
| 308 | vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s", |
| 309 | VTY_NEWLINE); |
| 310 | return CMD_WARNING; |
| 311 | } |
| 312 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 313 | nsvc->ip.bts_addr.sin_port = osmo_htons(port); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 314 | |
| 315 | return CMD_SUCCESS; |
| 316 | } |
| 317 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 318 | DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, |
Harald Welte | 188bda6 | 2010-05-28 14:11:49 +0200 | [diff] [blame] | 319 | "nse <0-65535> fr-dlci <16-1007>", |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 320 | NSE_CMD_STR |
| 321 | "Frame Relay DLCI\n" |
| 322 | "Frame Relay DLCI Number\n") |
| 323 | { |
| 324 | uint16_t nsei = atoi(argv[0]); |
| 325 | uint16_t dlci = atoi(argv[1]); |
| 326 | struct gprs_nsvc *nsvc; |
| 327 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 328 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 329 | if (!nsvc) { |
| 330 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 331 | return CMD_WARNING; |
| 332 | } |
| 333 | |
| 334 | if (nsvc->ll != GPRS_NS_LL_FR_GRE) { |
| 335 | vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s", |
| 336 | VTY_NEWLINE); |
| 337 | return CMD_WARNING; |
| 338 | } |
| 339 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 340 | nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 341 | |
| 342 | return CMD_SUCCESS; |
| 343 | } |
| 344 | |
| 345 | DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, |
| 346 | "nse <0-65535> encapsulation (udp|framerelay-gre)", |
| 347 | NSE_CMD_STR |
| 348 | "Encapsulation for NS\n" |
| 349 | "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n") |
| 350 | { |
| 351 | uint16_t nsei = atoi(argv[0]); |
| 352 | struct gprs_nsvc *nsvc; |
| 353 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 354 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 355 | if (!nsvc) { |
| 356 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 357 | return CMD_WARNING; |
| 358 | } |
| 359 | |
| 360 | if (!strcmp(argv[1], "udp")) |
| 361 | nsvc->ll = GPRS_NS_LL_UDP; |
| 362 | else |
| 363 | nsvc->ll = GPRS_NS_LL_FR_GRE; |
| 364 | |
| 365 | return CMD_SUCCESS; |
| 366 | } |
| 367 | |
| 368 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 369 | DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, |
| 370 | "nse <0-65535> remote-role (sgsn|bss)", |
| 371 | NSE_CMD_STR |
| 372 | "Remote NSE Role\n" |
| 373 | "Remote Peer is SGSN\n" |
| 374 | "Remote Peer is BSS\n") |
| 375 | { |
| 376 | uint16_t nsei = atoi(argv[0]); |
| 377 | struct gprs_nsvc *nsvc; |
| 378 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 379 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 380 | if (!nsvc) { |
| 381 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 382 | return CMD_WARNING; |
| 383 | } |
| 384 | |
| 385 | if (!strcmp(argv[1], "sgsn")) |
| 386 | nsvc->remote_end_is_sgsn = 1; |
| 387 | else |
| 388 | nsvc->remote_end_is_sgsn = 0; |
| 389 | |
| 390 | return CMD_SUCCESS; |
| 391 | } |
| 392 | |
| 393 | DEFUN(cfg_no_nse, cfg_no_nse_cmd, |
| 394 | "no nse <0-65535>", |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 395 | "Delete Persistent NS Entity\n" |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 396 | "Delete " NSE_CMD_STR) |
| 397 | { |
| 398 | uint16_t nsei = atoi(argv[0]); |
| 399 | struct gprs_nsvc *nsvc; |
| 400 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 401 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 402 | if (!nsvc) { |
| 403 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 404 | return CMD_WARNING; |
| 405 | } |
| 406 | |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 407 | if (!nsvc->persistent) { |
| 408 | vty_out(vty, "NSEI %u is not a persistent NSE%s", |
| 409 | nsei, VTY_NEWLINE); |
| 410 | return CMD_WARNING; |
| 411 | } |
| 412 | |
| 413 | nsvc->persistent = 0; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 414 | |
| 415 | return CMD_SUCCESS; |
| 416 | } |
| 417 | |
| 418 | DEFUN(cfg_ns_timer, cfg_ns_timer_cmd, |
| 419 | "timer " NS_TIMERS " <0-65535>", |
| 420 | "Network Service Timer\n" |
| 421 | NS_TIMERS_HELP "Timer Value\n") |
| 422 | { |
| 423 | int idx = get_string_value(gprs_ns_timer_strs, argv[0]); |
| 424 | int val = atoi(argv[1]); |
| 425 | |
| 426 | if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout)) |
| 427 | return CMD_WARNING; |
| 428 | |
| 429 | vty_nsi->timeout[idx] = val; |
| 430 | |
| 431 | return CMD_SUCCESS; |
| 432 | } |
| 433 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 434 | #define ENCAPS_STR "NS encapsulation options\n" |
| 435 | |
| 436 | DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd, |
| 437 | "encapsulation udp local-ip A.B.C.D", |
| 438 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 439 | "Set the IP address on which we listen for NS/UDP\n" |
| 440 | "IP Address\n") |
| 441 | { |
| 442 | struct in_addr ia; |
| 443 | |
| 444 | inet_aton(argv[0], &ia); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 445 | vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 446 | |
| 447 | return CMD_SUCCESS; |
| 448 | } |
| 449 | |
| 450 | DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd, |
| 451 | "encapsulation udp local-port <0-65535>", |
| 452 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 453 | "Set the UDP port on which we listen for NS/UDP\n" |
| 454 | "UDP port number\n") |
| 455 | { |
| 456 | unsigned int port = atoi(argv[0]); |
| 457 | |
| 458 | vty_nsi->nsip.local_port = port; |
| 459 | |
| 460 | return CMD_SUCCESS; |
| 461 | } |
| 462 | |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 463 | DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd, |
| 464 | "encapsulation udp dscp <0-255>", |
| 465 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 466 | "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n") |
| 467 | { |
| 468 | int dscp = atoi(argv[0]); |
| 469 | vty_nsi->nsip.dscp = dscp; |
| 470 | return CMD_SUCCESS; |
| 471 | } |
| 472 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 473 | DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd, |
| 474 | "encapsulation framerelay-gre local-ip A.B.C.D", |
| 475 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 476 | "Set the IP address on which we listen for NS/FR/GRE\n" |
| 477 | "IP Address\n") |
| 478 | { |
| 479 | struct in_addr ia; |
| 480 | |
| 481 | if (!vty_nsi->frgre.enabled) { |
| 482 | vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE); |
| 483 | return CMD_WARNING; |
| 484 | } |
| 485 | inet_aton(argv[0], &ia); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 486 | vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 487 | |
| 488 | return CMD_SUCCESS; |
| 489 | } |
| 490 | |
| 491 | DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd, |
| 492 | "encapsulation framerelay-gre enabled (1|0)", |
| 493 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 494 | "Enable or disable Frame Relay over GRE\n" |
| 495 | "Enable\n" "Disable\n") |
| 496 | { |
| 497 | int enabled = atoi(argv[0]); |
| 498 | |
| 499 | vty_nsi->frgre.enabled = enabled; |
| 500 | |
| 501 | return CMD_SUCCESS; |
| 502 | } |
| 503 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 504 | DEFUN(nsvc_nsei, nsvc_nsei_cmd, |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 505 | "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)", |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 506 | "Perform an operation on a NSVC\n" |
Holger Hans Peter Freyther | 887934e | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 507 | "NSEI to identify NS-VC Identifier (NS-VCI)\n" |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 508 | "NS-VC Identifier (NS-VCI)\n" |
Holger Hans Peter Freyther | 887934e | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 509 | "The NSEI\n" |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 510 | "Initiate BLOCK procedure\n" |
| 511 | "Initiate UNBLOCK procedure\n" |
| 512 | "Initiate RESET procedure\n") |
| 513 | { |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 514 | const char *id_type = argv[0]; |
| 515 | uint16_t id = atoi(argv[1]); |
| 516 | const char *operation = argv[2]; |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 517 | struct gprs_nsvc *nsvc; |
| 518 | |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 519 | if (!strcmp(id_type, "nsei")) |
| 520 | nsvc = gprs_nsvc_by_nsei(vty_nsi, id); |
| 521 | else if (!strcmp(id_type, "nsvci")) |
| 522 | nsvc = gprs_nsvc_by_nsvci(vty_nsi, id); |
| 523 | else { |
| 524 | vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE); |
| 525 | return CMD_WARNING; |
| 526 | } |
| 527 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 528 | if (!nsvc) { |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 529 | vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE); |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 530 | return CMD_WARNING; |
| 531 | } |
| 532 | |
| 533 | if (!strcmp(operation, "block")) |
| 534 | gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 535 | else if (!strcmp(operation, "unblock")) |
| 536 | gprs_ns_tx_unblock(nsvc); |
| 537 | else if (!strcmp(operation, "reset")) |
| 538 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 539 | else |
| 540 | return CMD_WARNING; |
| 541 | |
| 542 | return CMD_SUCCESS; |
| 543 | } |
| 544 | |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 545 | DEFUN(logging_fltr_nsvc, |
| 546 | logging_fltr_nsvc_cmd, |
| 547 | "logging filter nsvc (nsei|nsvci) <0-65535>", |
Harald Welte | 6703bf7 | 2010-05-16 00:00:04 +0200 | [diff] [blame] | 548 | LOGGING_STR FILTER_STR |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 549 | "Filter based on NS Virtual Connection\n" |
| 550 | "Identify NS-VC by NSEI\n" |
| 551 | "Identify NS-VC by NSVCI\n" |
| 552 | "Numeric identifier\n") |
| 553 | { |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 554 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 555 | struct gprs_nsvc *nsvc; |
| 556 | uint16_t id = atoi(argv[1]); |
| 557 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 558 | if (!tgt) |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 559 | return CMD_WARNING; |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 560 | |
| 561 | if (!strcmp(argv[0], "nsei")) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 562 | nsvc = gprs_nsvc_by_nsei(vty_nsi, id); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 563 | else |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 564 | nsvc = gprs_nsvc_by_nsvci(vty_nsi, id); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 565 | |
| 566 | if (!nsvc) { |
| 567 | vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE); |
| 568 | return CMD_WARNING; |
| 569 | } |
| 570 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 571 | log_set_nsvc_filter(tgt, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 572 | return CMD_SUCCESS; |
| 573 | } |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 574 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 575 | int gprs_ns_vty_init(struct gprs_ns_inst *nsi) |
| 576 | { |
Neels Hofmeyr | c32bfd5 | 2017-01-12 22:32:19 +0100 | [diff] [blame] | 577 | static bool vty_elements_installed = false; |
| 578 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 579 | vty_nsi = nsi; |
| 580 | |
Neels Hofmeyr | c32bfd5 | 2017-01-12 22:32:19 +0100 | [diff] [blame] | 581 | /* Regression test code may call this function repeatedly, so make sure |
| 582 | * that VTY elements are not duplicated, which would assert. */ |
| 583 | if (vty_elements_installed) |
| 584 | return 0; |
| 585 | vty_elements_installed = true; |
| 586 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 587 | install_element_ve(&show_ns_cmd); |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 588 | install_element_ve(&show_ns_stats_cmd); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 589 | install_element_ve(&show_nse_cmd); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 590 | install_element_ve(&logging_fltr_nsvc_cmd); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 591 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 592 | install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd); |
| 593 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 594 | install_element(CONFIG_NODE, &cfg_ns_cmd); |
| 595 | install_node(&ns_node, config_write_ns); |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 596 | install_default(L_NS_NODE); |
| 597 | install_element(L_NS_NODE, &libgb_exit_cmd); |
| 598 | install_element(L_NS_NODE, &libgb_end_cmd); |
| 599 | install_element(L_NS_NODE, &cfg_nse_nsvci_cmd); |
| 600 | install_element(L_NS_NODE, &cfg_nse_remoteip_cmd); |
| 601 | install_element(L_NS_NODE, &cfg_nse_remoteport_cmd); |
| 602 | install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd); |
| 603 | install_element(L_NS_NODE, &cfg_nse_encaps_cmd); |
| 604 | install_element(L_NS_NODE, &cfg_nse_remoterole_cmd); |
| 605 | install_element(L_NS_NODE, &cfg_no_nse_cmd); |
| 606 | install_element(L_NS_NODE, &cfg_ns_timer_cmd); |
| 607 | install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd); |
| 608 | install_element(L_NS_NODE, &cfg_nsip_local_port_cmd); |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 609 | install_element(L_NS_NODE, &cfg_nsip_dscp_cmd); |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 610 | install_element(L_NS_NODE, &cfg_frgre_enable_cmd); |
| 611 | install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 612 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 613 | install_element(ENABLE_NODE, &nsvc_nsei_cmd); |
| 614 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 615 | return 0; |
| 616 | } |