Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 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 | 9af6ddf | 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 | 799e0c9 | 2010-04-30 21:49:24 +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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 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 | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <netinet/in.h> |
| 24 | #include <arpa/inet.h> |
| 25 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/talloc.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 27 | |
| 28 | #include <openbsc/debug.h> |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 29 | #include <openbsc/gb_proxy.h> |
| 30 | #include <openbsc/gprs_ns.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 31 | #include <openbsc/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 32 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/command.h> |
| 34 | #include <osmocom/vty/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 35 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 36 | static struct gbproxy_config *g_cfg = NULL; |
| 37 | |
| 38 | /* |
| 39 | * vty code for mgcp below |
| 40 | */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 41 | static struct cmd_node gbproxy_node = { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 42 | GBPROXY_NODE, |
| 43 | "%s(gbproxy)#", |
| 44 | 1, |
| 45 | }; |
| 46 | |
| 47 | static int config_write_gbproxy(struct vty *vty) |
| 48 | { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 49 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 50 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 51 | vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 52 | VTY_NEWLINE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 53 | |
| 54 | return CMD_SUCCESS; |
| 55 | } |
| 56 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 57 | DEFUN(cfg_gbproxy, |
| 58 | cfg_gbproxy_cmd, |
| 59 | "gbproxy", |
| 60 | "Configure the Gb proxy") |
| 61 | { |
| 62 | vty->node = GBPROXY_NODE; |
| 63 | return CMD_SUCCESS; |
| 64 | } |
| 65 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 66 | DEFUN(cfg_nsip_sgsn_nsei, |
| 67 | cfg_nsip_sgsn_nsei_cmd, |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 68 | "sgsn nsei <0-65534>", |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 69 | "Set the NSEI to be used in the connection with the SGSN") |
| 70 | { |
| 71 | unsigned int port = atoi(argv[0]); |
| 72 | |
| 73 | g_cfg->nsip_sgsn_nsei = port; |
| 74 | return CMD_SUCCESS; |
| 75 | } |
| 76 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 77 | int gbproxy_vty_init(void) |
| 78 | { |
Harald Welte | 995a2d3 | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 79 | install_element_ve(&show_gbproxy_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 80 | |
| 81 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 82 | install_node(&gbproxy_node, config_write_gbproxy); |
| 83 | install_default(GBPROXY_NODE); |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 84 | install_element(GBPROXY_NODE, &ournode_exit_cmd); |
Harald Welte | 54f7424 | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 85 | install_element(GBPROXY_NODE, &ournode_end_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 86 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 92 | { |
| 93 | int rc; |
| 94 | |
| 95 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 96 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 97 | if (rc < 0) { |
| 98 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 99 | return rc; |
| 100 | } |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |