Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 1 | /* |
Holger Hans Peter Freyther | d2361d9 | 2012-12-03 15:32:54 +0100 | [diff] [blame] | 2 | * (C) 2010-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010-2012 by On-Waves |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [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. |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [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/>. |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef BSC_NAT_H |
| 22 | #define BSC_NAT_H |
| 23 | |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 24 | #include "mgcp.h" |
| 25 | |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/select.h> |
| 28 | #include <osmocom/core/msgb.h> |
| 29 | #include <osmocom/core/msgfile.h> |
| 30 | #include <osmocom/core/timer.h> |
| 31 | #include <osmocom/core/write_queue.h> |
| 32 | #include <osmocom/core/rate_ctr.h> |
| 33 | #include <osmocom/core/statistics.h> |
| 34 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 35 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 36 | #include <regex.h> |
| 37 | |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 38 | #define DIR_BSC 1 |
| 39 | #define DIR_MSC 2 |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 40 | |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 41 | #define PAGIN_GROUP_UNASSIGNED -1 |
| 42 | |
Holger Hans Peter Freyther | 3d38742 | 2010-10-16 16:35:00 +0200 | [diff] [blame] | 43 | struct sccp_source_reference; |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 44 | struct nat_sccp_connection; |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 45 | struct bsc_nat_parsed; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 46 | struct bsc_nat; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 47 | struct bsc_nat_ussd_con; |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 48 | struct nat_rewrite_rule; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 49 | |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 50 | enum { |
| 51 | NAT_CON_TYPE_NONE, |
| 52 | NAT_CON_TYPE_LU, |
| 53 | NAT_CON_TYPE_CM_SERV_REQ, |
| 54 | NAT_CON_TYPE_PAG_RESP, |
Holger Hans Peter Freyther | 74dc303 | 2010-09-29 02:47:29 +0800 | [diff] [blame] | 55 | NAT_CON_TYPE_SSA, |
Holger Hans Peter Freyther | b71c23b | 2010-05-16 20:43:52 +0800 | [diff] [blame] | 56 | NAT_CON_TYPE_LOCAL_REJECT, |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 57 | NAT_CON_TYPE_OTHER, |
| 58 | }; |
| 59 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 60 | /* |
Holger Hans Peter Freyther | e5d3249 | 2011-04-16 16:02:59 +0200 | [diff] [blame] | 61 | * Is this terminated to the MSC, to the local machine (release |
| 62 | * handling for IMSI filtering) or to a USSD provider? |
| 63 | */ |
| 64 | enum { |
| 65 | NAT_CON_END_MSC, |
| 66 | NAT_CON_END_LOCAL, |
| 67 | NAT_CON_END_USSD, |
| 68 | }; |
| 69 | |
| 70 | /* |
Daniel Willmann | a86bc39 | 2011-02-18 14:32:56 +0100 | [diff] [blame] | 71 | * Pending command entry |
| 72 | */ |
| 73 | struct bsc_cmd_list { |
| 74 | struct llist_head list_entry; |
| 75 | |
| 76 | struct osmo_timer_list timeout; |
| 77 | |
| 78 | /* The NATed ID used on the bsc_con*/ |
| 79 | int nat_id; |
| 80 | |
| 81 | /* The control connection from which the command originated */ |
| 82 | struct ctrl_connection *ccon; |
| 83 | |
| 84 | /* The command from the control connection */ |
| 85 | struct ctrl_cmd *cmd; |
| 86 | }; |
| 87 | |
| 88 | /* |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 89 | * Per BSC data structure |
| 90 | */ |
| 91 | struct bsc_connection { |
| 92 | struct llist_head list_entry; |
| 93 | |
| 94 | /* do we know anything about this BSC? */ |
| 95 | int authenticated; |
| 96 | |
| 97 | /* the fd we use to communicate */ |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 98 | struct osmo_wqueue write_queue; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 99 | |
Holger Hans Peter Freyther | 47dd494 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 100 | /* the BSS associated */ |
| 101 | struct bsc_config *cfg; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 102 | |
| 103 | /* a timeout node */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 104 | struct osmo_timer_list id_timeout; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 105 | |
Holger Hans Peter Freyther | 906c15e | 2010-05-02 19:28:59 +0800 | [diff] [blame] | 106 | /* pong timeout */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 107 | struct osmo_timer_list ping_timeout; |
| 108 | struct osmo_timer_list pong_timeout; |
Holger Hans Peter Freyther | 906c15e | 2010-05-02 19:28:59 +0800 | [diff] [blame] | 109 | |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 110 | /* mgcp related code */ |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 111 | char *_endpoint_status; |
Holger Hans Peter Freyther | a9e9331 | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 112 | int number_multiplexes; |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 113 | int max_endpoints; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 114 | int last_endpoint; |
Holger Hans Peter Freyther | 462b7d7 | 2012-10-24 21:53:40 +0200 | [diff] [blame] | 115 | int next_transaction; |
| 116 | uint32_t pending_dlcx_count; |
| 117 | struct llist_head pending_dlcx; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 118 | |
Daniel Willmann | a86bc39 | 2011-02-18 14:32:56 +0100 | [diff] [blame] | 119 | /* track the pending commands for this BSC */ |
| 120 | struct llist_head cmd_pending; |
| 121 | int last_id; |
| 122 | |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 123 | /* a back pointer */ |
| 124 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 125 | }; |
| 126 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 127 | /** |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 128 | * Stats per BSC |
| 129 | */ |
| 130 | struct bsc_config_stats { |
Holger Hans Peter Freyther | b2c38eb | 2010-06-17 18:16:00 +0800 | [diff] [blame] | 131 | struct rate_ctr_group *ctrg; |
| 132 | }; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 133 | |
Holger Hans Peter Freyther | b2c38eb | 2010-06-17 18:16:00 +0800 | [diff] [blame] | 134 | enum bsc_cfg_ctr { |
| 135 | BCFG_CTR_SCCP_CONN, |
| 136 | BCFG_CTR_SCCP_CALLS, |
| 137 | BCFG_CTR_NET_RECONN, |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 138 | BCFG_CTR_DROPPED_SCCP, |
| 139 | BCFG_CTR_DROPPED_CALLS, |
Holger Hans Peter Freyther | ee88496 | 2010-09-25 17:58:22 +0800 | [diff] [blame] | 140 | BCFG_CTR_REJECTED_CR, |
| 141 | BCFG_CTR_REJECTED_MSG, |
| 142 | BCFG_CTR_ILL_PACKET, |
Holger Hans Peter Freyther | 463dc62 | 2010-10-03 19:41:42 +0800 | [diff] [blame] | 143 | BCFG_CTR_CON_TYPE_LU, |
| 144 | BCFG_CTR_CON_CMSERV_RQ, |
| 145 | BCFG_CTR_CON_PAG_RESP, |
Holger Hans Peter Freyther | 74dc303 | 2010-09-29 02:47:29 +0800 | [diff] [blame] | 146 | BCFG_CTR_CON_SSA, |
Holger Hans Peter Freyther | 463dc62 | 2010-10-03 19:41:42 +0800 | [diff] [blame] | 147 | BCFG_CTR_CON_OTHER, |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /** |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 151 | * One BSC entry in the config |
| 152 | */ |
| 153 | struct bsc_config { |
| 154 | struct llist_head entry; |
| 155 | |
| 156 | char *token; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 157 | int nr; |
| 158 | |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 159 | char *description; |
| 160 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 161 | /* imsi white and blacklist */ |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 162 | char *acc_lst_name; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 163 | |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 164 | int forbid_paging; |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 165 | int paging_group; |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 166 | |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 167 | /* audio handling */ |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 168 | int max_endpoints; |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 169 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 170 | /* backpointer */ |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 171 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 172 | |
| 173 | struct bsc_config_stats stats; |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 174 | |
| 175 | struct llist_head lac_list; |
| 176 | }; |
| 177 | |
| 178 | struct bsc_lac_entry { |
| 179 | struct llist_head entry; |
| 180 | uint16_t lac; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 181 | }; |
| 182 | |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 183 | struct bsc_nat_paging_group { |
| 184 | struct llist_head entry; |
| 185 | |
| 186 | /* list of lac entries */ |
| 187 | struct llist_head lists; |
| 188 | int nr; |
| 189 | }; |
| 190 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 191 | /** |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 192 | * BSCs point of view of endpoints |
| 193 | */ |
| 194 | struct bsc_endpoint { |
Holger Hans Peter Freyther | 5b2726e | 2010-08-06 09:05:05 +0800 | [diff] [blame] | 195 | /* the operation that is carried out */ |
| 196 | int transaction_state; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 197 | /* the pending transaction id */ |
| 198 | char *transaction_id; |
| 199 | /* the bsc we are talking to */ |
| 200 | struct bsc_connection *bsc; |
| 201 | }; |
| 202 | |
| 203 | /** |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 204 | * Statistic for the nat. |
| 205 | */ |
| 206 | struct bsc_nat_statistics { |
| 207 | struct { |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 208 | struct osmo_counter *conn; |
| 209 | struct osmo_counter *calls; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 210 | } sccp; |
| 211 | |
| 212 | struct { |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 213 | struct osmo_counter *reconn; |
| 214 | struct osmo_counter *auth_fail; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 215 | } bsc; |
| 216 | |
| 217 | struct { |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 218 | struct osmo_counter *reconn; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 219 | } msc; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 220 | |
| 221 | struct { |
Pablo Neira Ayuso | dfb342c | 2011-05-06 12:13:10 +0200 | [diff] [blame] | 222 | struct osmo_counter *reconn; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 223 | } ussd; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
Holger Hans Peter Freyther | 2f1a984 | 2010-09-25 06:14:52 +0800 | [diff] [blame] | 226 | enum bsc_nat_acc_ctr { |
| 227 | ACC_LIST_BSC_FILTER, |
| 228 | ACC_LIST_NAT_FILTER, |
| 229 | }; |
| 230 | |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 231 | struct bsc_nat_acc_lst { |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 232 | struct llist_head list; |
| 233 | |
Holger Hans Peter Freyther | 2f1a984 | 2010-09-25 06:14:52 +0800 | [diff] [blame] | 234 | /* counter */ |
| 235 | struct rate_ctr_group *stats; |
| 236 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 237 | /* the name of the list */ |
| 238 | const char *name; |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 239 | struct llist_head fltr_list; |
| 240 | }; |
| 241 | |
| 242 | struct bsc_nat_acc_lst_entry { |
| 243 | struct llist_head list; |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 244 | |
| 245 | /* the filter */ |
| 246 | char *imsi_allow; |
| 247 | regex_t imsi_allow_re; |
| 248 | char *imsi_deny; |
| 249 | regex_t imsi_deny_re; |
Holger Hans Peter Freyther | 415cd2e | 2014-01-20 09:55:46 +0100 | [diff] [blame^] | 250 | |
| 251 | /* reject reasons for the access lists */ |
| 252 | int cm_reject_cause; |
| 253 | int lu_reject_cause; |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 254 | }; |
| 255 | |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 256 | /** |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 257 | * the structure of the "nat" network |
| 258 | */ |
| 259 | struct bsc_nat { |
| 260 | /* active SCCP connections that need patching */ |
| 261 | struct llist_head sccp_connections; |
| 262 | |
| 263 | /* active BSC connections that need patching */ |
| 264 | struct llist_head bsc_connections; |
| 265 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 266 | /* access lists */ |
| 267 | struct llist_head access_lists; |
| 268 | |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 269 | /* paging groups */ |
| 270 | struct llist_head paging_groups; |
| 271 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 272 | /* known BSC's */ |
| 273 | struct llist_head bsc_configs; |
| 274 | int num_bsc; |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 275 | int bsc_ip_dscp; |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 276 | |
| 277 | /* MGCP config */ |
| 278 | struct mgcp_config *mgcp_cfg; |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 279 | uint8_t mgcp_msg[4096]; |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 280 | int mgcp_length; |
Holger Hans Peter Freyther | c327187 | 2012-11-05 14:54:56 +0100 | [diff] [blame] | 281 | int mgcp_ipa; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 282 | |
Holger Hans Peter Freyther | b752761 | 2010-04-07 11:20:36 +0200 | [diff] [blame] | 283 | /* msc things */ |
Holger Hans Peter Freyther | e188010 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 284 | struct llist_head dests; |
| 285 | struct bsc_msc_dest *main_dest; |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 286 | struct bsc_msc_connection *msc_con; |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 287 | char *token; |
Holger Hans Peter Freyther | b752761 | 2010-04-07 11:20:36 +0200 | [diff] [blame] | 288 | |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 289 | /* timeouts */ |
| 290 | int auth_timeout; |
| 291 | int ping_timeout; |
| 292 | int pong_timeout; |
| 293 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 294 | struct bsc_endpoint *bsc_endpoints; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 295 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 296 | /* filter */ |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 297 | char *acc_lst_name; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 298 | |
Holger Hans Peter Freyther | 1f8276e | 2013-01-01 11:25:09 +0100 | [diff] [blame] | 299 | /* Barring of subscribers with a rb tree */ |
| 300 | struct rb_root imsi_black_list; |
| 301 | char *imsi_black_list_fn; |
| 302 | |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 303 | /* number rewriting */ |
| 304 | char *num_rewr_name; |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 305 | struct llist_head num_rewr; |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 306 | char *num_rewr_post_name; |
| 307 | struct llist_head num_rewr_post; |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 308 | |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 309 | char *smsc_rewr_name; |
| 310 | struct llist_head smsc_rewr; |
Holger Hans Peter Freyther | acc4031 | 2011-05-27 19:21:24 +0200 | [diff] [blame] | 311 | char *tpdest_match_name; |
| 312 | struct llist_head tpdest_match; |
Holger Hans Peter Freyther | 68368dd | 2012-01-10 22:39:07 +0100 | [diff] [blame] | 313 | char *sms_clear_tp_srr_name; |
| 314 | struct llist_head sms_clear_tp_srr; |
Holger Hans Peter Freyther | 8e60f62 | 2012-01-18 20:00:28 +0100 | [diff] [blame] | 315 | char *sms_num_rewr_name; |
| 316 | struct llist_head sms_num_rewr; |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 317 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 318 | /* more rewriting */ |
| 319 | char *num_rewr_trie_name; |
| 320 | struct nat_rewrite *num_rewr_trie; |
| 321 | |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 322 | /* USSD messages we want to match */ |
| 323 | char *ussd_lst_name; |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 324 | char *ussd_query; |
Holger Hans Peter Freyther | a18b116 | 2011-04-01 17:32:21 +0200 | [diff] [blame] | 325 | regex_t ussd_query_re; |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 326 | char *ussd_token; |
| 327 | char *ussd_local; |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 328 | struct osmo_fd ussd_listen; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 329 | struct bsc_nat_ussd_con *ussd_con; |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 330 | |
Holger Hans Peter Freyther | de2b860 | 2011-04-23 23:55:14 +0200 | [diff] [blame] | 331 | /* for maintainenance */ |
| 332 | int blocked; |
| 333 | |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 334 | /* statistics */ |
| 335 | struct bsc_nat_statistics stats; |
Daniel Willmann | 6fc4a98 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 336 | |
| 337 | /* control interface */ |
| 338 | struct ctrl_handle *ctrl; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 339 | }; |
| 340 | |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 341 | struct bsc_nat_ussd_con { |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 342 | struct osmo_wqueue queue; |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 343 | struct bsc_nat *nat; |
| 344 | int authorized; |
| 345 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 346 | struct osmo_timer_list auth_timeout; |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
Holger Hans Peter Freyther | bdf764a | 2012-12-17 14:35:03 +0100 | [diff] [blame] | 349 | struct bsc_nat_reject_cause { |
| 350 | int lu_reject_cause; |
| 351 | int cm_reject_cause; |
| 352 | }; |
| 353 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 354 | /* create and init the structures */ |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 355 | struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 356 | struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num); |
Holger Hans Peter Freyther | 9212d9d | 2011-02-27 11:18:41 +0100 | [diff] [blame] | 357 | void bsc_config_free(struct bsc_config *); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 358 | void bsc_config_add_lac(struct bsc_config *cfg, int lac); |
| 359 | void bsc_config_del_lac(struct bsc_config *cfg, int lac); |
| 360 | int bsc_config_handles_lac(struct bsc_config *cfg, int lac); |
| 361 | |
Holger Hans Peter Freyther | dcf8a7d | 2010-06-15 18:48:01 +0800 | [diff] [blame] | 362 | struct bsc_nat *bsc_nat_alloc(void); |
| 363 | struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 364 | void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 365 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 366 | void sccp_connection_destroy(struct nat_sccp_connection *); |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 367 | void bsc_close_connection(struct bsc_connection *); |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 368 | |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 369 | const char *bsc_con_type_to_string(int type); |
| 370 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 371 | /** |
| 372 | * parse the given message into the above structure |
| 373 | */ |
| 374 | struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg); |
| 375 | |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 376 | /** |
| 377 | * filter based on IP Access header in both directions |
| 378 | */ |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 379 | int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 380 | int bsc_nat_vty_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 1ffe98c | 2011-05-02 16:20:32 +0200 | [diff] [blame] | 381 | int bsc_nat_find_paging(struct msgb *msg, const uint8_t **,int *len); |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 382 | |
Holger Hans Peter Freyther | 0ab6bab | 2010-06-15 18:47:49 +0800 | [diff] [blame] | 383 | /** |
Holger Hans Peter Freyther | b4af5c9 | 2010-05-14 03:39:56 +0800 | [diff] [blame] | 384 | * Content filtering. |
| 385 | */ |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 386 | int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg, |
Holger Hans Peter Freyther | bdf764a | 2012-12-17 14:35:03 +0100 | [diff] [blame] | 387 | struct bsc_nat_parsed *, int *con_type, char **imsi, |
| 388 | struct bsc_nat_reject_cause *cause); |
Holger Hans Peter Freyther | 74e0a1b | 2010-09-15 01:11:08 +0800 | [diff] [blame] | 389 | int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg, |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 390 | struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, |
Holger Hans Peter Freyther | bdf764a | 2012-12-17 14:35:03 +0100 | [diff] [blame] | 391 | struct bsc_nat_reject_cause *cause); |
Holger Hans Peter Freyther | b4af5c9 | 2010-05-14 03:39:56 +0800 | [diff] [blame] | 392 | |
| 393 | /** |
Holger Hans Peter Freyther | 0ab6bab | 2010-06-15 18:47:49 +0800 | [diff] [blame] | 394 | * SCCP patching and handling |
| 395 | */ |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 396 | struct nat_sccp_connection *create_sccp_src_ref(struct bsc_connection *bsc, struct bsc_nat_parsed *parsed); |
| 397 | int update_sccp_src_ref(struct nat_sccp_connection *sccp, struct bsc_nat_parsed *parsed); |
Holger Hans Peter Freyther | 0ab6bab | 2010-06-15 18:47:49 +0800 | [diff] [blame] | 398 | void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed); |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 399 | struct nat_sccp_connection *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *); |
| 400 | struct nat_sccp_connection *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_connection *); |
| 401 | struct nat_sccp_connection *bsc_nat_find_con_by_bsc(struct bsc_nat *, struct sccp_source_reference *); |
Holger Hans Peter Freyther | 0ab6bab | 2010-06-15 18:47:49 +0800 | [diff] [blame] | 402 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 403 | /** |
| 404 | * MGCP/Audio handling |
| 405 | */ |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 406 | int bsc_mgcp_nr_multiplexes(int max_endpoints); |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 407 | int bsc_write_mgcp(struct bsc_connection *bsc, const uint8_t *data, unsigned int length); |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 408 | int bsc_mgcp_assign_patch(struct nat_sccp_connection *, struct msgb *msg); |
| 409 | void bsc_mgcp_init(struct nat_sccp_connection *); |
| 410 | void bsc_mgcp_dlcx(struct nat_sccp_connection *); |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 411 | void bsc_mgcp_free_endpoints(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 412 | int bsc_mgcp_nat_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 413 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 414 | struct nat_sccp_connection *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number); |
Jacob Erlbeck | 3dff27d | 2013-11-29 13:43:48 +0100 | [diff] [blame] | 415 | struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, |
| 416 | int port, int *payload_type); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 417 | void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg); |
| 418 | |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 419 | void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 420 | int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]); |
Holger Hans Peter Freyther | 4634013 | 2010-08-06 08:26:54 +0800 | [diff] [blame] | 421 | uint32_t bsc_mgcp_extract_ci(const char *resp); |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 422 | |
Holger Hans Peter Freyther | 2896df7 | 2010-04-08 10:24:57 +0200 | [diff] [blame] | 423 | |
| 424 | int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int id); |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 425 | int bsc_do_write(struct osmo_wqueue *queue, struct msgb *msg, int id); |
| 426 | int bsc_write_msg(struct osmo_wqueue *queue, struct msgb *msg); |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 427 | int bsc_write_cb(struct osmo_fd *bfd, struct msgb *msg); |
Holger Hans Peter Freyther | 2896df7 | 2010-04-08 10:24:57 +0200 | [diff] [blame] | 428 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 429 | /* IMSI allow/deny handling */ |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 430 | struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name); |
| 431 | struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name); |
| 432 | void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst); |
Holger Hans Peter Freyther | 12dc89a | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 433 | |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 434 | struct bsc_nat_acc_lst_entry *bsc_nat_acc_lst_entry_create(struct bsc_nat_acc_lst *); |
Holger Hans Peter Freyther | c1cac1e | 2010-10-11 09:50:31 +0200 | [diff] [blame] | 435 | int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *imsi); |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 436 | |
Holger Hans Peter Freyther | 20ee312 | 2010-07-05 14:39:44 +0800 | [diff] [blame] | 437 | int bsc_nat_msc_is_connected(struct bsc_nat *nat); |
| 438 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 439 | int bsc_conn_type_to_ctr(struct nat_sccp_connection *conn); |
Holger Hans Peter Freyther | 463dc62 | 2010-10-03 19:41:42 +0800 | [diff] [blame] | 440 | |
Holger Hans Peter Freyther | a396757 | 2010-09-29 02:30:50 +0800 | [diff] [blame] | 441 | struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *msg, uint32_t *len); |
| 442 | |
Holger Hans Peter Freyther | 17870cf | 2010-09-29 19:32:55 +0800 | [diff] [blame] | 443 | /** USSD filtering */ |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 444 | int bsc_ussd_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 6fcc3a9 | 2013-08-26 14:04:43 +0200 | [diff] [blame] | 445 | int bsc_ussd_check(struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, struct msgb *msg); |
| 446 | int bsc_ussd_close_connections(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 17870cf | 2010-09-29 19:32:55 +0800 | [diff] [blame] | 447 | |
Holger Hans Peter Freyther | df8e6e9 | 2011-05-27 14:09:55 +0200 | [diff] [blame] | 448 | struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi); |
Holger Hans Peter Freyther | a914daf | 2010-10-21 12:12:57 +0200 | [diff] [blame] | 449 | |
Holger Hans Peter Freyther | 6860c44 | 2011-05-02 19:16:13 +0200 | [diff] [blame] | 450 | /** paging group handling */ |
| 451 | struct bsc_nat_paging_group *bsc_nat_paging_group_num(struct bsc_nat *nat, int group); |
| 452 | struct bsc_nat_paging_group *bsc_nat_paging_group_create(struct bsc_nat *nat, int group); |
| 453 | void bsc_nat_paging_group_delete(struct bsc_nat_paging_group *); |
| 454 | void bsc_nat_paging_group_add_lac(struct bsc_nat_paging_group *grp, int lac); |
| 455 | void bsc_nat_paging_group_del_lac(struct bsc_nat_paging_group *grp, int lac); |
| 456 | |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 457 | /** |
| 458 | * Number rewriting support below |
| 459 | */ |
| 460 | struct bsc_nat_num_rewr_entry { |
| 461 | struct llist_head list; |
| 462 | |
| 463 | regex_t msisdn_reg; |
| 464 | regex_t num_reg; |
| 465 | |
| 466 | char *replace; |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 467 | uint8_t is_prefix_lookup; |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 468 | }; |
| 469 | |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 470 | void bsc_nat_num_rewr_entry_adapt(void *ctx, struct llist_head *head, const struct osmo_config_list *); |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 471 | |
Holger Hans Peter Freyther | 1f8276e | 2013-01-01 11:25:09 +0100 | [diff] [blame] | 472 | struct bsc_nat_barr_entry { |
| 473 | struct rb_node node; |
| 474 | |
| 475 | char *imsi; |
| 476 | int cm_reject_cause; |
| 477 | int lu_reject_cause; |
| 478 | }; |
| 479 | |
| 480 | int bsc_nat_barr_adapt(void *ctx, struct rb_root *rbtree, const struct osmo_config_list *); |
| 481 | int bsc_nat_barr_find(struct rb_root *root, const char *imsi, int *cm, int *lu); |
| 482 | |
Holger Hans Peter Freyther | c327187 | 2012-11-05 14:54:56 +0100 | [diff] [blame] | 483 | void bsc_nat_send_mgcp_to_msc(struct bsc_nat *bsc_nat, struct msgb *msg); |
| 484 | void bsc_nat_handle_mgcp(struct bsc_nat *bsc, struct msgb *msg); |
| 485 | |
Holger Hans Peter Freyther | 98da544 | 2012-11-05 16:04:10 +0100 | [diff] [blame] | 486 | struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port); |
| 487 | void bsc_nat_ctrl_del_pending(struct bsc_cmd_list *pending); |
| 488 | int bsc_nat_handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg); |
| 489 | |
Holger Hans Peter Freyther | b2b291d | 2013-04-16 13:23:43 +0200 | [diff] [blame] | 490 | int bsc_nat_extract_lac(struct bsc_connection *bsc, struct nat_sccp_connection *con, |
| 491 | struct bsc_nat_parsed *parsed, struct msgb *msg); |
| 492 | |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 493 | #endif |