Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 1 | /* |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 2 | * (C) 2010-2013 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
| 24 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
| 26 | #include <osmocom/core/utils.h> |
| 27 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 28 | |
| 29 | #include <openbsc/debug.h> |
| 30 | #include <openbsc/sgsn.h> |
Harald Welte | cfb6b28 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 31 | #include <osmocom/gprs/gprs_ns.h> |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 32 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 33 | #include <openbsc/vty.h> |
Harald Welte | 493ba62 | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 34 | #include <openbsc/gsm_04_08_gprs.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 35 | |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 36 | #include <osmocom/vty/command.h> |
| 37 | #include <osmocom/vty/vty.h> |
Pablo Neira Ayuso | 3d31c3a | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 38 | #include <osmocom/vty/misc.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 39 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 40 | #include <pdp.h> |
| 41 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 42 | static struct sgsn_config *g_cfg = NULL; |
| 43 | |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 44 | struct imsi_acl_entry { |
| 45 | struct llist_head list; |
| 46 | char imsi[16+1]; |
| 47 | }; |
Harald Welte | 493ba62 | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 48 | |
| 49 | #define GSM48_MAX_APN_LEN 102 /* 10.5.6.1 */ |
| 50 | static char *gprs_apn2str(uint8_t *apn, unsigned int len) |
| 51 | { |
| 52 | static char apnbuf[GSM48_MAX_APN_LEN+1]; |
Holger Hans Peter Freyther | 41514d9 | 2013-07-04 18:44:16 +0200 | [diff] [blame] | 53 | unsigned int i = 0; |
Harald Welte | 493ba62 | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 54 | |
| 55 | if (!apn) |
| 56 | return ""; |
| 57 | |
| 58 | if (len > sizeof(apnbuf)-1) |
| 59 | len = sizeof(apnbuf)-1; |
| 60 | |
| 61 | memcpy(apnbuf, apn, len); |
| 62 | apnbuf[len] = '\0'; |
| 63 | |
| 64 | /* replace the domain name step sizes with dots */ |
| 65 | while (i < len) { |
| 66 | unsigned int step = apnbuf[i]; |
| 67 | apnbuf[i] = '.'; |
| 68 | i += step+1; |
| 69 | } |
| 70 | |
| 71 | return apnbuf+1; |
| 72 | } |
| 73 | |
Holger Hans Peter Freyther | e8e5ef2 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 74 | char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len) |
Harald Welte | 493ba62 | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 75 | { |
| 76 | static char str[INET6_ADDRSTRLEN + 10]; |
| 77 | |
| 78 | if (!pdpa || len < 2) |
| 79 | return "none"; |
| 80 | |
| 81 | switch (pdpa[0] & 0x0f) { |
| 82 | case PDP_TYPE_ORG_IETF: |
| 83 | switch (pdpa[1]) { |
| 84 | case PDP_TYPE_N_IETF_IPv4: |
| 85 | if (len < 2 + 4) |
| 86 | break; |
| 87 | strcpy(str, "IPv4 "); |
| 88 | inet_ntop(AF_INET, pdpa+2, str+5, sizeof(str)-5); |
| 89 | return str; |
| 90 | case PDP_TYPE_N_IETF_IPv6: |
| 91 | if (len < 2 + 8) |
| 92 | break; |
| 93 | strcpy(str, "IPv6 "); |
| 94 | inet_ntop(AF_INET6, pdpa+2, str+5, sizeof(str)-5); |
| 95 | return str; |
| 96 | default: |
| 97 | break; |
| 98 | } |
| 99 | break; |
| 100 | case PDP_TYPE_ORG_ETSI: |
| 101 | if (pdpa[1] == PDP_TYPE_N_ETSI_PPP) |
| 102 | return "PPP"; |
| 103 | break; |
| 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | return "invalid"; |
| 109 | } |
| 110 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 111 | static struct cmd_node sgsn_node = { |
| 112 | SGSN_NODE, |
Harald Welte | 45362bb | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 113 | "%s(config-sgsn)# ", |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 114 | 1, |
| 115 | }; |
| 116 | |
| 117 | static int config_write_sgsn(struct vty *vty) |
| 118 | { |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 119 | struct sgsn_ggsn_ctx *gctx; |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 120 | struct imsi_acl_entry *acl; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 121 | |
| 122 | vty_out(vty, "sgsn%s", VTY_NEWLINE); |
| 123 | |
Harald Welte | e0aea39 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 124 | vty_out(vty, " gtp local-ip %s%s", |
| 125 | inet_ntoa(g_cfg->gtp_listenaddr.sin_addr), VTY_NEWLINE); |
| 126 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 127 | llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) { |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 128 | vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id, |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 129 | inet_ntoa(gctx->remote_addr), VTY_NEWLINE); |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 130 | vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id, |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 131 | gctx->gtp_version, VTY_NEWLINE); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Harald Welte | 2b9693d | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 134 | vty_out(vty, " auth-policy %s%s", |
| 135 | g_cfg->acl_enabled ? "closed" : "accept-all", VTY_NEWLINE); |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 136 | llist_for_each_entry(acl, &g_cfg->imsi_acl, list) |
| 137 | vty_out(vty, " imsi-acl add %s%s", acl->imsi, VTY_NEWLINE); |
| 138 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 139 | return CMD_SUCCESS; |
| 140 | } |
| 141 | |
Holger Hans Peter Freyther | f403c48 | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 142 | #define SGSN_STR "Configure the SGSN\n" |
| 143 | #define GGSN_STR "Configure the GGSN information\n" |
Harald Welte | e0aea39 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 144 | |
| 145 | DEFUN(cfg_sgsn, cfg_sgsn_cmd, |
| 146 | "sgsn", |
| 147 | SGSN_STR) |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 148 | { |
| 149 | vty->node = SGSN_NODE; |
| 150 | return CMD_SUCCESS; |
| 151 | } |
| 152 | |
Harald Welte | e0aea39 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 153 | DEFUN(cfg_sgsn_bind_addr, cfg_sgsn_bind_addr_cmd, |
| 154 | "gtp local-ip A.B.C.D", |
| 155 | "GTP Parameters\n" |
Holger Hans Peter Freyther | f403c48 | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 156 | "Set the IP address for the local GTP bind\n" |
| 157 | "IPv4 Address\n") |
Harald Welte | e0aea39 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 158 | { |
| 159 | inet_aton(argv[0], &g_cfg->gtp_listenaddr.sin_addr); |
| 160 | |
| 161 | return CMD_SUCCESS; |
| 162 | } |
| 163 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 164 | DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd, |
| 165 | "ggsn <0-255> remote-ip A.B.C.D", |
Holger Hans Peter Freyther | f403c48 | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 166 | GGSN_STR "GGSN Number\n" IP_STR "IPv4 Address\n") |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 167 | { |
| 168 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 169 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 170 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 171 | inet_aton(argv[1], &ggc->remote_addr); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 172 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 173 | return CMD_SUCCESS; |
| 174 | } |
| 175 | |
| 176 | #if 0 |
| 177 | DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd, |
| 178 | "ggsn <0-255> remote-port <0-65535>", |
| 179 | "") |
| 180 | { |
| 181 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 182 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 183 | uint16_t port = atoi(argv[1]); |
| 184 | |
| 185 | } |
| 186 | #endif |
| 187 | |
| 188 | DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd, |
| 189 | "ggsn <0-255> gtp-version (0|1)", |
Holger Hans Peter Freyther | f403c48 | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 190 | GGSN_STR "GGSN Number\n" "GTP Version\n" |
| 191 | "Version 0\n" "Version 1\n") |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 192 | { |
| 193 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 194 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 195 | |
| 196 | if (atoi(argv[1])) |
| 197 | ggc->gtp_version = 1; |
| 198 | else |
| 199 | ggc->gtp_version = 0; |
| 200 | |
| 201 | return CMD_SUCCESS; |
| 202 | } |
| 203 | |
| 204 | #if 0 |
| 205 | DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd, |
| 206 | "apn APNAME ggsn <0-255>", |
| 207 | "") |
| 208 | { |
| 209 | struct apn_ctx ** |
| 210 | } |
| 211 | #endif |
| 212 | |
| 213 | const struct value_string gprs_mm_st_strs[] = { |
| 214 | { GMM_DEREGISTERED, "DEREGISTERED" }, |
| 215 | { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" }, |
| 216 | { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" }, |
Harald Welte | 3ba2ce1 | 2010-06-09 15:50:45 +0200 | [diff] [blame] | 217 | { GMM_REGISTERED_SUSPENDED, "REGISTERED (SUSPENDED)" }, |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 218 | { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" }, |
| 219 | { 0, NULL } |
| 220 | }; |
| 221 | |
| 222 | static void vty_dump_pdp(struct vty *vty, const char *pfx, |
| 223 | struct sgsn_pdp_ctx *pdp) |
| 224 | { |
| 225 | vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s", |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 226 | pfx, pdp->mm->imsi, pdp->sapi, pdp->nsapi, VTY_NEWLINE); |
Harald Welte | 493ba62 | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 227 | vty_out(vty, "%s APN: %s%s", pfx, |
| 228 | gprs_apn2str(pdp->lib->apn_use.v, pdp->lib->apn_use.l), |
| 229 | VTY_NEWLINE); |
| 230 | vty_out(vty, "%s PDP Address: %s%s", pfx, |
| 231 | gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l), |
| 232 | VTY_NEWLINE); |
Harald Welte | 0fe506b | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 233 | vty_out_rate_ctr_group(vty, " ", pdp->ctrg); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static void vty_dump_mmctx(struct vty *vty, const char *pfx, |
| 237 | struct sgsn_mm_ctx *mm, int pdp) |
| 238 | { |
| 239 | vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s", |
| 240 | pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE); |
| 241 | vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn, |
| 242 | mm->tlli, VTY_NEWLINE); |
| 243 | vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, " |
| 244 | "Cell ID: %u%s", pfx, |
| 245 | get_value_string(gprs_mm_st_strs, mm->mm_state), |
| 246 | mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac, |
| 247 | mm->cell_id, VTY_NEWLINE); |
| 248 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 249 | vty_out_rate_ctr_group(vty, " ", mm->ctrg); |
| 250 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 251 | if (pdp) { |
| 252 | struct sgsn_pdp_ctx *pdp; |
| 253 | |
| 254 | llist_for_each_entry(pdp, &mm->pdp_list, list) |
| 255 | vty_dump_pdp(vty, " ", pdp); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn", |
| 260 | SHOW_STR "Display information about the SGSN") |
| 261 | { |
| 262 | /* FIXME: statistics */ |
| 263 | return CMD_SUCCESS; |
| 264 | } |
| 265 | |
| 266 | #define MMCTX_STR "MM Context\n" |
| 267 | #define INCLUDE_PDP_STR "Include PDP Context Information\n" |
| 268 | |
| 269 | #if 0 |
| 270 | DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd, |
| 271 | "show mm-context tlli HEX [pdp]", |
| 272 | SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR) |
| 273 | { |
| 274 | uint32_t tlli; |
| 275 | struct sgsn_mm_ctx *mm; |
| 276 | |
| 277 | tlli = strtoul(argv[0], NULL, 16); |
| 278 | mm = sgsn_mm_ctx_by_tlli(tlli); |
| 279 | if (!mm) { |
| 280 | vty_out(vty, "No MM context for TLLI %08x%s", |
| 281 | tlli, VTY_NEWLINE); |
| 282 | return CMD_WARNING; |
| 283 | } |
| 284 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 285 | return CMD_SUCCESS; |
| 286 | } |
| 287 | #endif |
| 288 | |
| 289 | DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd, |
| 290 | "show mm-context imsi IMSI [pdp]", |
| 291 | SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n" |
| 292 | INCLUDE_PDP_STR) |
| 293 | { |
| 294 | struct sgsn_mm_ctx *mm; |
| 295 | |
| 296 | mm = sgsn_mm_ctx_by_imsi(argv[0]); |
| 297 | if (!mm) { |
| 298 | vty_out(vty, "No MM context for IMSI %s%s", |
| 299 | argv[0], VTY_NEWLINE); |
| 300 | return CMD_WARNING; |
| 301 | } |
| 302 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 303 | return CMD_SUCCESS; |
| 304 | } |
| 305 | |
| 306 | DEFUN(swow_mmctx_all, show_mmctx_all_cmd, |
| 307 | "show mm-context all [pdp]", |
| 308 | SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR) |
| 309 | { |
| 310 | struct sgsn_mm_ctx *mm; |
| 311 | |
| 312 | llist_for_each_entry(mm, &sgsn_mm_ctxts, list) |
| 313 | vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0); |
| 314 | |
| 315 | return CMD_SUCCESS; |
| 316 | } |
| 317 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 318 | DEFUN(show_pdpctx_all, show_pdpctx_all_cmd, |
| 319 | "show pdp-context all", |
Holger Hans Peter Freyther | f403c48 | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 320 | SHOW_STR "Display information on PDP Context\n" "Show everything\n") |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 321 | { |
| 322 | struct sgsn_pdp_ctx *pdp; |
| 323 | |
| 324 | llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list) |
| 325 | vty_dump_pdp(vty, "", pdp); |
| 326 | |
| 327 | return CMD_SUCCESS; |
| 328 | } |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 329 | |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 330 | /* temporary IMSI ACL hack */ |
| 331 | struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi) |
| 332 | { |
| 333 | struct imsi_acl_entry *acl; |
| 334 | llist_for_each_entry(acl, &g_cfg->imsi_acl, list) { |
| 335 | if (!strcmp(imsi, acl->imsi)) |
| 336 | return acl; |
| 337 | } |
| 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | int sgsn_acl_add(const char *imsi) |
| 342 | { |
| 343 | struct imsi_acl_entry *acl; |
| 344 | |
| 345 | if (sgsn_acl_lookup(imsi)) |
| 346 | return -EEXIST; |
| 347 | |
| 348 | acl = talloc_zero(NULL, struct imsi_acl_entry); |
| 349 | if (!acl) |
| 350 | return -ENOMEM; |
| 351 | strncpy(acl->imsi, imsi, sizeof(acl->imsi)); |
| 352 | |
| 353 | llist_add(&acl->list, &g_cfg->imsi_acl); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | int sgsn_acl_del(const char *imsi) |
| 359 | { |
| 360 | struct imsi_acl_entry *acl; |
| 361 | |
| 362 | acl = sgsn_acl_lookup(imsi); |
| 363 | if (!acl) |
| 364 | return -ENODEV; |
| 365 | |
| 366 | llist_del(&acl->list); |
| 367 | talloc_free(acl); |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | DEFUN(imsi_acl, cfg_imsi_acl_cmd, |
| 374 | "imsi-acl (add|del) IMSI", |
| 375 | "Access Control List of foreign IMSIs\n" |
| 376 | "Add IMSI to ACL\n" |
| 377 | "Remove IMSI from ACL\n" |
| 378 | "IMSI of subscriber\n") |
| 379 | { |
| 380 | const char *op = argv[0]; |
| 381 | const char *imsi = argv[1]; |
| 382 | int rc; |
| 383 | |
| 384 | if (!strcmp(op, "add")) |
| 385 | rc = sgsn_acl_add(imsi); |
| 386 | else |
| 387 | rc = sgsn_acl_del(imsi); |
| 388 | |
| 389 | if (rc < 0) { |
| 390 | vty_out(vty, "%% unable to %s ACL\n", op); |
| 391 | return CMD_WARNING; |
| 392 | } |
| 393 | |
| 394 | return CMD_SUCCESS; |
| 395 | } |
| 396 | |
Harald Welte | 2b9693d | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 397 | DEFUN(cfg_auth_policy, cfg_auth_policy_cmd, |
| 398 | "auth-policy (accept-all|closed)", |
| 399 | "Autorization Policy of SGSN\n" |
| 400 | "Accept all IMSIs (DANGEROUS\n" |
| 401 | "Accept only home network subscribers or those in ACL\n") |
| 402 | { |
| 403 | if (!strcmp(argv[0], "accept-all")) |
| 404 | g_cfg->acl_enabled = 0; |
| 405 | else |
| 406 | g_cfg->acl_enabled = 1; |
| 407 | |
| 408 | return CMD_SUCCESS; |
| 409 | } |
| 410 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 411 | int sgsn_vty_init(void) |
| 412 | { |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 413 | install_element_ve(&show_sgsn_cmd); |
| 414 | //install_element_ve(&show_mmctx_tlli_cmd); |
| 415 | install_element_ve(&show_mmctx_imsi_cmd); |
| 416 | install_element_ve(&show_mmctx_all_cmd); |
| 417 | install_element_ve(&show_pdpctx_all_cmd); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 418 | |
| 419 | install_element(CONFIG_NODE, &cfg_sgsn_cmd); |
| 420 | install_node(&sgsn_node, config_write_sgsn); |
Jacob Erlbeck | f414e85 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 421 | vty_install_default(SGSN_NODE); |
Harald Welte | e0aea39 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 422 | install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 423 | install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd); |
| 424 | //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd); |
| 425 | install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd); |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 426 | install_element(SGSN_NODE, &cfg_imsi_acl_cmd); |
Harald Welte | 2b9693d | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 427 | install_element(SGSN_NODE, &cfg_auth_policy_cmd); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg) |
| 433 | { |
| 434 | int rc; |
| 435 | |
| 436 | g_cfg = cfg; |
Harald Welte | a0879c1 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 437 | INIT_LLIST_HEAD(&g_cfg->imsi_acl); |
| 438 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 439 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 440 | if (rc < 0) { |
| 441 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 442 | return rc; |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |