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