blob: c342fdca05ad29c798f668269808be9f668538c9 [file] [log] [blame]
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +02001/* (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 Freytherd04d0092015-04-04 22:14:34 +020021#include <openbsc/gsm_data.h>
22#include <openbsc/vty.h>
23
24#include <osmocom/vty/misc.h>
25
Holger Hans Peter Freytherd7e04b92015-04-04 22:28:32 +020026static struct llist_head *_acc_lst;
27static void *_ctx;
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020028
29DEFUN(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 Freythera1e6bd62015-04-04 22:40:12 +020035 struct bsc_msg_acc_lst *acc;
36 acc = bsc_msg_acc_lst_find(_acc_lst, argv[0]);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020037 if (!acc)
38 return CMD_WARNING;
39
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +020040 bsc_msg_acc_lst_delete(acc);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020041 return CMD_SUCCESS;
42}
43
44DEFUN(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 Freythera1e6bd62015-04-04 22:40:12 +020049 struct bsc_msg_acc_lst *acc;
50 acc = bsc_msg_acc_lst_find(_acc_lst, argv[0]);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020051 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
60DEFUN(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 Freythera1e6bd62015-04-04 22:40:12 +020068 struct bsc_msg_acc_lst *acc;
69 struct bsc_msg_acc_lst_entry *entry;
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020070
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +020071 acc = bsc_msg_acc_lst_get(_ctx, _acc_lst, argv[0]);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020072 if (!acc)
73 return CMD_WARNING;
74
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +020075 entry = bsc_msg_acc_lst_entry_create(acc);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020076 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
84DEFUN(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 Freythera1e6bd62015-04-04 22:40:12 +020094 struct bsc_msg_acc_lst *acc;
95 struct bsc_msg_acc_lst_entry *entry;
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020096
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +020097 acc = bsc_msg_acc_lst_get(_ctx, _acc_lst, argv[0]);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +020098 if (!acc)
99 return CMD_WARNING;
100
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +0200101 entry = bsc_msg_acc_lst_entry_create(acc);
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +0200102 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 Freythera1e6bd62015-04-04 22:40:12 +0200114void bsc_msg_acc_lst_write(struct vty *vty, struct bsc_msg_acc_lst *lst)
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +0200115{
Holger Hans Peter Freythera1e6bd62015-04-04 22:40:12 +0200116 struct bsc_msg_acc_lst_entry *entry;
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +0200117
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 Freythera1e6bd62015-04-04 22:40:12 +0200130void bsc_msg_lst_vty_init(void *ctx, struct llist_head *lst, int node)
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +0200131{
Holger Hans Peter Freytherd7e04b92015-04-04 22:28:32 +0200132 _ctx = ctx;
133 _acc_lst = lst;
Holger Hans Peter Freytherd04d0092015-04-04 22:14:34 +0200134 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}