blob: 070a03da625e312e2f838ee3b0c9faff80883f54 [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>
21#include <openbsc/bsc_nat.h>
22#include <openbsc/gsm_data.h>
23#include <openbsc/vty.h>
24
25#include <osmocom/vty/misc.h>
26
27static struct bsc_nat *_nat;
28
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{
35 struct bsc_nat_acc_lst *acc;
36 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
37 if (!acc)
38 return CMD_WARNING;
39
40 bsc_nat_acc_lst_delete(acc);
41 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{
49 struct bsc_nat_acc_lst *acc;
50 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
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
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{
68 struct bsc_nat_acc_lst *acc;
69 struct bsc_nat_acc_lst_entry *entry;
70
71 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
72 if (!acc)
73 return CMD_WARNING;
74
75 entry = bsc_nat_acc_lst_entry_create(acc);
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
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{
94 struct bsc_nat_acc_lst *acc;
95 struct bsc_nat_acc_lst_entry *entry;
96
97 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
98 if (!acc)
99 return CMD_WARNING;
100
101 entry = bsc_nat_acc_lst_entry_create(acc);
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
114void bsc_nat_acc_lst_write(struct vty *vty, struct bsc_nat_acc_lst *lst)
115{
116 struct bsc_nat_acc_lst_entry *entry;
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
130
131void bsc_nat_lst_vty_init(struct bsc_nat *nat, int node)
132{
133 _nat = nat;
134
135 install_element_ve(&show_acc_lst_cmd);
136
137 /* access-list */
138 install_element(node, &cfg_lst_imsi_allow_cmd);
139 install_element(node, &cfg_lst_imsi_deny_cmd);
140 install_element(node, &cfg_lst_no_cmd);
141}