Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 1 | /* (C) 2010-2015 by Holger Hans Peter Freyther |
| 2 | * (C) 2010-2013 by On-Waves |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU Affero General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <openbsc/bsc_msg_filter.h> |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 21 | #include <openbsc/gsm_data.h> |
| 22 | #include <openbsc/vty.h> |
| 23 | |
| 24 | #include <osmocom/vty/misc.h> |
| 25 | |
Holger Hans Peter Freyther | ff1f62e | 2015-04-04 22:28:32 +0200 | [diff] [blame] | 26 | static struct llist_head *_acc_lst; |
| 27 | static void *_ctx; |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 28 | |
| 29 | DEFUN(cfg_lst_no, |
| 30 | cfg_lst_no_cmd, |
| 31 | "no access-list NAME", |
| 32 | NO_STR "Remove an access-list by name\n" |
| 33 | "The access-list to remove\n") |
| 34 | { |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 35 | struct bsc_msg_acc_lst *acc; |
| 36 | acc = bsc_msg_acc_lst_find(_acc_lst, argv[0]); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 37 | if (!acc) |
| 38 | return CMD_WARNING; |
| 39 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 40 | bsc_msg_acc_lst_delete(acc); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 41 | return CMD_SUCCESS; |
| 42 | } |
| 43 | |
| 44 | DEFUN(show_acc_lst, |
| 45 | show_acc_lst_cmd, |
| 46 | "show access-list NAME", |
| 47 | SHOW_STR "IMSI access list\n" "Name of the access list\n") |
| 48 | { |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 49 | struct bsc_msg_acc_lst *acc; |
| 50 | acc = bsc_msg_acc_lst_find(_acc_lst, argv[0]); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 51 | if (!acc) |
| 52 | return CMD_WARNING; |
| 53 | |
| 54 | vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE); |
| 55 | vty_out_rate_ctr_group(vty, " ", acc->stats); |
| 56 | |
| 57 | return CMD_SUCCESS; |
| 58 | } |
| 59 | |
| 60 | DEFUN(cfg_lst_imsi_allow, |
| 61 | cfg_lst_imsi_allow_cmd, |
| 62 | "access-list NAME imsi-allow [REGEXP]", |
| 63 | "Access list commands\n" |
| 64 | "Name of the access list\n" |
| 65 | "Add allowed IMSI to the list\n" |
| 66 | "Regexp for IMSIs\n") |
| 67 | { |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 68 | struct bsc_msg_acc_lst *acc; |
| 69 | struct bsc_msg_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 70 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 71 | acc = bsc_msg_acc_lst_get(_ctx, _acc_lst, argv[0]); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 72 | if (!acc) |
| 73 | return CMD_WARNING; |
| 74 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 75 | entry = bsc_msg_acc_lst_entry_create(acc); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 76 | if (!entry) |
| 77 | return CMD_WARNING; |
| 78 | |
| 79 | if (gsm_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]) != 0) |
| 80 | return CMD_WARNING; |
| 81 | return CMD_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | DEFUN(cfg_lst_imsi_deny, |
| 85 | cfg_lst_imsi_deny_cmd, |
| 86 | "access-list NAME imsi-deny [REGEXP] (<0-256>) (<0-256>)", |
| 87 | "Access list commands\n" |
| 88 | "Name of the access list\n" |
| 89 | "Add denied IMSI to the list\n" |
| 90 | "Regexp for IMSIs\n" |
| 91 | "CM Service Reject reason\n" |
| 92 | "LU Reject reason\n") |
| 93 | { |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 94 | struct bsc_msg_acc_lst *acc; |
| 95 | struct bsc_msg_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 96 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 97 | acc = bsc_msg_acc_lst_get(_ctx, _acc_lst, argv[0]); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 98 | if (!acc) |
| 99 | return CMD_WARNING; |
| 100 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 101 | entry = bsc_msg_acc_lst_entry_create(acc); |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 102 | if (!entry) |
| 103 | return CMD_WARNING; |
| 104 | |
| 105 | if (gsm_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]) != 0) |
| 106 | return CMD_WARNING; |
| 107 | if (argc >= 3) |
| 108 | entry->cm_reject_cause = atoi(argv[2]); |
| 109 | if (argc >= 4) |
| 110 | entry->lu_reject_cause = atoi(argv[3]); |
| 111 | return CMD_SUCCESS; |
| 112 | } |
| 113 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 114 | void bsc_msg_acc_lst_write(struct vty *vty, struct bsc_msg_acc_lst *lst) |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 115 | { |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 116 | struct bsc_msg_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 117 | |
| 118 | llist_for_each_entry(entry, &lst->fltr_list, list) { |
| 119 | if (entry->imsi_allow) |
| 120 | vty_out(vty, " access-list %s imsi-allow %s%s", |
| 121 | lst->name, entry->imsi_allow, VTY_NEWLINE); |
| 122 | if (entry->imsi_deny) |
| 123 | vty_out(vty, " access-list %s imsi-deny %s %d %d%s", |
| 124 | lst->name, entry->imsi_deny, |
| 125 | entry->cm_reject_cause, entry->lu_reject_cause, |
| 126 | VTY_NEWLINE); |
| 127 | } |
| 128 | } |
| 129 | |
Holger Hans Peter Freyther | 955f53c | 2015-04-04 22:40:12 +0200 | [diff] [blame] | 130 | void bsc_msg_lst_vty_init(void *ctx, struct llist_head *lst, int node) |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 131 | { |
Holger Hans Peter Freyther | ff1f62e | 2015-04-04 22:28:32 +0200 | [diff] [blame] | 132 | _ctx = ctx; |
| 133 | _acc_lst = lst; |
Holger Hans Peter Freyther | 739a483 | 2015-04-04 22:14:34 +0200 | [diff] [blame] | 134 | install_element_ve(&show_acc_lst_cmd); |
| 135 | |
| 136 | /* access-list */ |
| 137 | install_element(node, &cfg_lst_imsi_allow_cmd); |
| 138 | install_element(node, &cfg_lst_imsi_deny_cmd); |
| 139 | install_element(node, &cfg_lst_no_cmd); |
| 140 | } |