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" |
Holger Hans Peter Freyther | 4ba947b | 2015-04-05 18:07:45 +0200 | [diff] [blame] | 25 | #include "bsc_msg_filter.h" |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 26 | |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 27 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 28 | #include <osmocom/core/select.h> |
| 29 | #include <osmocom/core/msgb.h> |
| 30 | #include <osmocom/core/msgfile.h> |
| 31 | #include <osmocom/core/timer.h> |
| 32 | #include <osmocom/core/write_queue.h> |
| 33 | #include <osmocom/core/rate_ctr.h> |
| 34 | #include <osmocom/core/statistics.h> |
| 35 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 37 | #include <regex.h> |
| 38 | |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 39 | #define DIR_BSC 1 |
| 40 | #define DIR_MSC 2 |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 41 | |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 42 | #define PAGIN_GROUP_UNASSIGNED -1 |
| 43 | |
Holger Hans Peter Freyther | 3d38742 | 2010-10-16 16:35:00 +0200 | [diff] [blame] | 44 | struct sccp_source_reference; |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 45 | struct nat_sccp_connection; |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 46 | struct bsc_nat_parsed; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 47 | struct bsc_nat; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 48 | struct bsc_nat_ussd_con; |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 49 | struct nat_rewrite_rule; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 51 | /* |
Holger Hans Peter Freyther | e5d3249 | 2011-04-16 16:02:59 +0200 | [diff] [blame] | 52 | * Is this terminated to the MSC, to the local machine (release |
| 53 | * handling for IMSI filtering) or to a USSD provider? |
| 54 | */ |
| 55 | enum { |
| 56 | NAT_CON_END_MSC, |
| 57 | NAT_CON_END_LOCAL, |
| 58 | NAT_CON_END_USSD, |
| 59 | }; |
| 60 | |
| 61 | /* |
Daniel Willmann | a86bc39 | 2011-02-18 14:32:56 +0100 | [diff] [blame] | 62 | * Pending command entry |
| 63 | */ |
| 64 | struct bsc_cmd_list { |
| 65 | struct llist_head list_entry; |
| 66 | |
| 67 | struct osmo_timer_list timeout; |
| 68 | |
| 69 | /* The NATed ID used on the bsc_con*/ |
| 70 | int nat_id; |
| 71 | |
| 72 | /* The control connection from which the command originated */ |
| 73 | struct ctrl_connection *ccon; |
| 74 | |
| 75 | /* The command from the control connection */ |
| 76 | struct ctrl_cmd *cmd; |
| 77 | }; |
| 78 | |
| 79 | /* |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 80 | * Per BSC data structure |
| 81 | */ |
| 82 | struct bsc_connection { |
| 83 | struct llist_head list_entry; |
| 84 | |
| 85 | /* do we know anything about this BSC? */ |
| 86 | int authenticated; |
Holger Hans Peter Freyther | 9705671 | 2015-06-08 16:28:15 +0200 | [diff] [blame] | 87 | uint8_t last_rand[16]; |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 88 | |
| 89 | /* the fd we use to communicate */ |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 90 | struct osmo_wqueue write_queue; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 91 | |
Jacob Erlbeck | e827812 | 2014-03-31 13:42:11 +0200 | [diff] [blame] | 92 | /* incoming message buffer */ |
| 93 | struct msgb *pending_msg; |
| 94 | |
Holger Hans Peter Freyther | 47dd494 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 95 | /* the BSS associated */ |
| 96 | struct bsc_config *cfg; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 97 | |
| 98 | /* a timeout node */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 99 | struct osmo_timer_list id_timeout; |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 100 | |
Holger Hans Peter Freyther | 906c15e | 2010-05-02 19:28:59 +0800 | [diff] [blame] | 101 | /* pong timeout */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 102 | struct osmo_timer_list ping_timeout; |
| 103 | struct osmo_timer_list pong_timeout; |
Holger Hans Peter Freyther | 906c15e | 2010-05-02 19:28:59 +0800 | [diff] [blame] | 104 | |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 105 | /* mgcp related code */ |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 106 | char *_endpoint_status; |
Holger Hans Peter Freyther | a9e9331 | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 107 | int number_multiplexes; |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 108 | int max_endpoints; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 109 | int last_endpoint; |
Holger Hans Peter Freyther | 462b7d7 | 2012-10-24 21:53:40 +0200 | [diff] [blame] | 110 | int next_transaction; |
| 111 | uint32_t pending_dlcx_count; |
| 112 | struct llist_head pending_dlcx; |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 113 | |
Daniel Willmann | a86bc39 | 2011-02-18 14:32:56 +0100 | [diff] [blame] | 114 | /* track the pending commands for this BSC */ |
| 115 | struct llist_head cmd_pending; |
| 116 | int last_id; |
| 117 | |
Holger Hans Peter Freyther | aa69824 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 118 | /* a back pointer */ |
| 119 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 122 | /** |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 123 | * Stats per BSC |
| 124 | */ |
| 125 | struct bsc_config_stats { |
Holger Hans Peter Freyther | b2c38eb | 2010-06-17 18:16:00 +0800 | [diff] [blame] | 126 | struct rate_ctr_group *ctrg; |
| 127 | }; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 128 | |
Holger Hans Peter Freyther | b2c38eb | 2010-06-17 18:16:00 +0800 | [diff] [blame] | 129 | enum bsc_cfg_ctr { |
| 130 | BCFG_CTR_SCCP_CONN, |
| 131 | BCFG_CTR_SCCP_CALLS, |
| 132 | BCFG_CTR_NET_RECONN, |
Holger Hans Peter Freyther | 8330c1c | 2010-06-17 18:29:42 +0800 | [diff] [blame] | 133 | BCFG_CTR_DROPPED_SCCP, |
| 134 | BCFG_CTR_DROPPED_CALLS, |
Holger Hans Peter Freyther | ee88496 | 2010-09-25 17:58:22 +0800 | [diff] [blame] | 135 | BCFG_CTR_REJECTED_CR, |
| 136 | BCFG_CTR_REJECTED_MSG, |
| 137 | BCFG_CTR_ILL_PACKET, |
Holger Hans Peter Freyther | 463dc62 | 2010-10-03 19:41:42 +0800 | [diff] [blame] | 138 | BCFG_CTR_CON_TYPE_LU, |
| 139 | BCFG_CTR_CON_CMSERV_RQ, |
| 140 | BCFG_CTR_CON_PAG_RESP, |
Holger Hans Peter Freyther | 74dc303 | 2010-09-29 02:47:29 +0800 | [diff] [blame] | 141 | BCFG_CTR_CON_SSA, |
Holger Hans Peter Freyther | 463dc62 | 2010-10-03 19:41:42 +0800 | [diff] [blame] | 142 | BCFG_CTR_CON_OTHER, |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /** |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 146 | * One BSC entry in the config |
| 147 | */ |
| 148 | struct bsc_config { |
| 149 | struct llist_head entry; |
| 150 | |
Holger Hans Peter Freyther | 694d980 | 2015-06-08 18:33:28 +0200 | [diff] [blame] | 151 | uint8_t key[16]; |
| 152 | uint8_t key_present; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 153 | char *token; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 154 | int nr; |
| 155 | |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 156 | char *description; |
| 157 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 158 | /* imsi white and blacklist */ |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 159 | char *acc_lst_name; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 160 | |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 161 | int forbid_paging; |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 162 | int paging_group; |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 163 | |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 164 | /* audio handling */ |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 165 | int max_endpoints; |
Holger Hans Peter Freyther | ed500e3 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 166 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 167 | /* backpointer */ |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 168 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 169 | |
| 170 | struct bsc_config_stats stats; |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 171 | |
| 172 | struct llist_head lac_list; |
Pablo Neira Ayuso | cab6e75 | 2014-02-05 18:56:17 +0100 | [diff] [blame] | 173 | |
| 174 | /* Osmux is enabled/disabled per BSC */ |
| 175 | int osmux; |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 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 | |
| 226 | /** |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 227 | * the structure of the "nat" network |
| 228 | */ |
| 229 | struct bsc_nat { |
| 230 | /* active SCCP connections that need patching */ |
| 231 | struct llist_head sccp_connections; |
| 232 | |
| 233 | /* active BSC connections that need patching */ |
| 234 | struct llist_head bsc_connections; |
| 235 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 236 | /* access lists */ |
| 237 | struct llist_head access_lists; |
| 238 | |
Holger Hans Peter Freyther | 474698a | 2011-05-02 16:50:36 +0200 | [diff] [blame] | 239 | /* paging groups */ |
| 240 | struct llist_head paging_groups; |
| 241 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 242 | /* known BSC's */ |
| 243 | struct llist_head bsc_configs; |
| 244 | int num_bsc; |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 245 | int bsc_ip_dscp; |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 246 | |
| 247 | /* MGCP config */ |
| 248 | struct mgcp_config *mgcp_cfg; |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 249 | uint8_t mgcp_msg[4096]; |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 250 | int mgcp_length; |
Holger Hans Peter Freyther | c327187 | 2012-11-05 14:54:56 +0100 | [diff] [blame] | 251 | int mgcp_ipa; |
Holger Hans Peter Freyther | 7f100c9 | 2015-04-23 20:25:17 -0400 | [diff] [blame] | 252 | int sdp_ensure_amr_mode_set; |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 253 | |
Holger Hans Peter Freyther | b752761 | 2010-04-07 11:20:36 +0200 | [diff] [blame] | 254 | /* msc things */ |
Holger Hans Peter Freyther | e188010 | 2011-04-23 23:31:31 +0200 | [diff] [blame] | 255 | struct llist_head dests; |
| 256 | struct bsc_msc_dest *main_dest; |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 257 | struct bsc_msc_connection *msc_con; |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 258 | char *token; |
Holger Hans Peter Freyther | b752761 | 2010-04-07 11:20:36 +0200 | [diff] [blame] | 259 | |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 260 | /* timeouts */ |
| 261 | int auth_timeout; |
| 262 | int ping_timeout; |
| 263 | int pong_timeout; |
| 264 | |
Holger Hans Peter Freyther | a0df82d | 2010-04-01 08:21:33 +0200 | [diff] [blame] | 265 | struct bsc_endpoint *bsc_endpoints; |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 266 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 267 | /* filter */ |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 268 | char *acc_lst_name; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 269 | |
Holger Hans Peter Freyther | 1f8276e | 2013-01-01 11:25:09 +0100 | [diff] [blame] | 270 | /* Barring of subscribers with a rb tree */ |
| 271 | struct rb_root imsi_black_list; |
| 272 | char *imsi_black_list_fn; |
| 273 | |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 274 | /* number rewriting */ |
| 275 | char *num_rewr_name; |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 276 | struct llist_head num_rewr; |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 277 | char *num_rewr_post_name; |
| 278 | struct llist_head num_rewr_post; |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 279 | |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 280 | char *smsc_rewr_name; |
| 281 | struct llist_head smsc_rewr; |
Holger Hans Peter Freyther | acc4031 | 2011-05-27 19:21:24 +0200 | [diff] [blame] | 282 | char *tpdest_match_name; |
| 283 | struct llist_head tpdest_match; |
Holger Hans Peter Freyther | 68368dd | 2012-01-10 22:39:07 +0100 | [diff] [blame] | 284 | char *sms_clear_tp_srr_name; |
| 285 | struct llist_head sms_clear_tp_srr; |
Holger Hans Peter Freyther | 8e60f62 | 2012-01-18 20:00:28 +0100 | [diff] [blame] | 286 | char *sms_num_rewr_name; |
| 287 | struct llist_head sms_num_rewr; |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 288 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 289 | /* more rewriting */ |
| 290 | char *num_rewr_trie_name; |
| 291 | struct nat_rewrite *num_rewr_trie; |
| 292 | |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 293 | /* USSD messages we want to match */ |
| 294 | char *ussd_lst_name; |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 295 | char *ussd_query; |
Holger Hans Peter Freyther | a18b116 | 2011-04-01 17:32:21 +0200 | [diff] [blame] | 296 | regex_t ussd_query_re; |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 297 | char *ussd_token; |
| 298 | char *ussd_local; |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 299 | struct osmo_fd ussd_listen; |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 300 | struct bsc_nat_ussd_con *ussd_con; |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 301 | |
Holger Hans Peter Freyther | de2b860 | 2011-04-23 23:55:14 +0200 | [diff] [blame] | 302 | /* for maintainenance */ |
| 303 | int blocked; |
| 304 | |
Holger Hans Peter Freyther | d470286 | 2010-04-12 12:17:09 +0200 | [diff] [blame] | 305 | /* statistics */ |
| 306 | struct bsc_nat_statistics stats; |
Daniel Willmann | 6fc4a98 | 2011-07-22 17:55:42 +0200 | [diff] [blame] | 307 | |
| 308 | /* control interface */ |
| 309 | struct ctrl_handle *ctrl; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 310 | }; |
| 311 | |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 312 | struct bsc_nat_ussd_con { |
Pablo Neira Ayuso | e1273b1 | 2011-05-06 12:09:47 +0200 | [diff] [blame] | 313 | struct osmo_wqueue queue; |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 314 | struct bsc_nat *nat; |
| 315 | int authorized; |
| 316 | |
Jacob Erlbeck | e827812 | 2014-03-31 13:42:11 +0200 | [diff] [blame] | 317 | struct msgb *pending_msg; |
| 318 | |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 319 | struct osmo_timer_list auth_timeout; |
Holger Hans Peter Freyther | 91b9a45 | 2011-04-16 17:01:47 +0200 | [diff] [blame] | 320 | }; |
| 321 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 322 | /* create and init the structures */ |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 323 | 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] | 324 | struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num); |
Holger Hans Peter Freyther | aa0cecd | 2015-06-08 09:54:45 +0200 | [diff] [blame] | 325 | struct bsc_config *bsc_config_by_token(struct bsc_nat *nat, const char *token, int len); |
Holger Hans Peter Freyther | 9212d9d | 2011-02-27 11:18:41 +0100 | [diff] [blame] | 326 | void bsc_config_free(struct bsc_config *); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 327 | void bsc_config_add_lac(struct bsc_config *cfg, int lac); |
| 328 | void bsc_config_del_lac(struct bsc_config *cfg, int lac); |
| 329 | int bsc_config_handles_lac(struct bsc_config *cfg, int lac); |
| 330 | |
Holger Hans Peter Freyther | dcf8a7d | 2010-06-15 18:48:01 +0800 | [diff] [blame] | 331 | struct bsc_nat *bsc_nat_alloc(void); |
| 332 | struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 333 | 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] | 334 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 335 | void sccp_connection_destroy(struct nat_sccp_connection *); |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 336 | void bsc_close_connection(struct bsc_connection *); |
Holger Hans Peter Freyther | 9f8f3d0 | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 337 | |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 338 | const char *bsc_con_type_to_string(int type); |
| 339 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 340 | /** |
| 341 | * parse the given message into the above structure |
| 342 | */ |
| 343 | struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg); |
| 344 | |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 345 | /** |
| 346 | * filter based on IP Access header in both directions |
| 347 | */ |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 348 | 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] | 349 | int bsc_nat_vty_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 1ffe98c | 2011-05-02 16:20:32 +0200 | [diff] [blame] | 350 | 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] | 351 | |
Holger Hans Peter Freyther | 0ab6bab | 2010-06-15 18:47:49 +0800 | [diff] [blame] | 352 | /** |
| 353 | * SCCP patching and handling |
| 354 | */ |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 355 | struct nat_sccp_connection *create_sccp_src_ref(struct bsc_connection *bsc, struct bsc_nat_parsed *parsed); |
| 356 | 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] | 357 | 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] | 358 | struct nat_sccp_connection *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *); |
| 359 | struct nat_sccp_connection *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_connection *); |
| 360 | 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] | 361 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 362 | /** |
| 363 | * MGCP/Audio handling |
| 364 | */ |
Holger Hans Peter Freyther | 9ec030d | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 365 | int bsc_mgcp_nr_multiplexes(int max_endpoints); |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 366 | 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] | 367 | int bsc_mgcp_assign_patch(struct nat_sccp_connection *, struct msgb *msg); |
| 368 | void bsc_mgcp_init(struct nat_sccp_connection *); |
| 369 | void bsc_mgcp_dlcx(struct nat_sccp_connection *); |
Holger Hans Peter Freyther | 241e130 | 2010-03-31 09:16:56 +0200 | [diff] [blame] | 370 | void bsc_mgcp_free_endpoints(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 371 | int bsc_mgcp_nat_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 372 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 373 | 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] | 374 | struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, |
Holger Hans Peter Freyther | e9f7c99 | 2015-08-13 18:31:09 +0200 | [diff] [blame^] | 375 | int port, int osmux, int *first_payload_type, int mode_set); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 376 | void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg); |
| 377 | |
Holger Hans Peter Freyther | 26a4389 | 2010-04-05 23:09:27 +0200 | [diff] [blame] | 378 | void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 379 | 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] | 380 | uint32_t bsc_mgcp_extract_ci(const char *resp); |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 381 | |
Holger Hans Peter Freyther | 2896df7 | 2010-04-08 10:24:57 +0200 | [diff] [blame] | 382 | |
| 383 | 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] | 384 | int bsc_do_write(struct osmo_wqueue *queue, struct msgb *msg, int id); |
| 385 | int bsc_write_msg(struct osmo_wqueue *queue, struct msgb *msg); |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 386 | 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] | 387 | |
Holger Hans Peter Freyther | 20ee312 | 2010-07-05 14:39:44 +0800 | [diff] [blame] | 388 | int bsc_nat_msc_is_connected(struct bsc_nat *nat); |
| 389 | |
Holger Hans Peter Freyther | c279e39 | 2013-04-16 09:53:13 +0200 | [diff] [blame] | 390 | 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] | 391 | |
Holger Hans Peter Freyther | a396757 | 2010-09-29 02:30:50 +0800 | [diff] [blame] | 392 | struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *msg, uint32_t *len); |
| 393 | |
Holger Hans Peter Freyther | 17870cf | 2010-09-29 19:32:55 +0800 | [diff] [blame] | 394 | /** USSD filtering */ |
Holger Hans Peter Freyther | c16c2dc | 2010-10-13 20:22:36 +0200 | [diff] [blame] | 395 | int bsc_ussd_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 6fcc3a9 | 2013-08-26 14:04:43 +0200 | [diff] [blame] | 396 | int bsc_ussd_check(struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, struct msgb *msg); |
| 397 | int bsc_ussd_close_connections(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 17870cf | 2010-09-29 19:32:55 +0800 | [diff] [blame] | 398 | |
Holger Hans Peter Freyther | df8e6e9 | 2011-05-27 14:09:55 +0200 | [diff] [blame] | 399 | 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] | 400 | |
Holger Hans Peter Freyther | 6860c44 | 2011-05-02 19:16:13 +0200 | [diff] [blame] | 401 | /** paging group handling */ |
| 402 | struct bsc_nat_paging_group *bsc_nat_paging_group_num(struct bsc_nat *nat, int group); |
| 403 | struct bsc_nat_paging_group *bsc_nat_paging_group_create(struct bsc_nat *nat, int group); |
| 404 | void bsc_nat_paging_group_delete(struct bsc_nat_paging_group *); |
| 405 | void bsc_nat_paging_group_add_lac(struct bsc_nat_paging_group *grp, int lac); |
| 406 | void bsc_nat_paging_group_del_lac(struct bsc_nat_paging_group *grp, int lac); |
| 407 | |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 408 | /** |
| 409 | * Number rewriting support below |
| 410 | */ |
| 411 | struct bsc_nat_num_rewr_entry { |
| 412 | struct llist_head list; |
| 413 | |
| 414 | regex_t msisdn_reg; |
| 415 | regex_t num_reg; |
| 416 | |
| 417 | char *replace; |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 418 | uint8_t is_prefix_lookup; |
Holger Hans Peter Freyther | ad75eab | 2011-05-27 12:38:58 +0200 | [diff] [blame] | 419 | }; |
| 420 | |
Holger Hans Peter Freyther | 9c20571 | 2011-05-27 17:14:15 +0200 | [diff] [blame] | 421 | 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] | 422 | |
Holger Hans Peter Freyther | c327187 | 2012-11-05 14:54:56 +0100 | [diff] [blame] | 423 | void bsc_nat_send_mgcp_to_msc(struct bsc_nat *bsc_nat, struct msgb *msg); |
| 424 | void bsc_nat_handle_mgcp(struct bsc_nat *bsc, struct msgb *msg); |
| 425 | |
Holger Hans Peter Freyther | 98da544 | 2012-11-05 16:04:10 +0100 | [diff] [blame] | 426 | struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port); |
| 427 | void bsc_nat_ctrl_del_pending(struct bsc_cmd_list *pending); |
| 428 | int bsc_nat_handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg); |
| 429 | |
Holger Hans Peter Freyther | b2b291d | 2013-04-16 13:23:43 +0200 | [diff] [blame] | 430 | int bsc_nat_extract_lac(struct bsc_connection *bsc, struct nat_sccp_connection *con, |
| 431 | struct bsc_nat_parsed *parsed, struct msgb *msg); |
| 432 | |
Holger Hans Peter Freyther | 4ba947b | 2015-04-05 18:07:45 +0200 | [diff] [blame] | 433 | int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg, |
| 434 | struct bsc_nat_parsed *, int *con_type, char **imsi, |
| 435 | struct bsc_filter_reject_cause *cause); |
| 436 | int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg, |
| 437 | struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, |
| 438 | struct bsc_filter_reject_cause *cause); |
| 439 | |
Holger Hans Peter Freyther | 7c00983 | 2015-04-05 13:45:53 +0200 | [diff] [blame] | 440 | /** |
| 441 | * CTRL interface helper |
| 442 | */ |
| 443 | void bsc_nat_inform_reject(struct bsc_connection *bsc, const char *imsi); |
Holger Hans Peter Freyther | 73ec698 | 2014-08-29 09:56:58 +0200 | [diff] [blame] | 444 | |
| 445 | /* |
| 446 | * Use for testing |
| 447 | */ |
| 448 | void bsc_nat_free(struct bsc_nat *nat); |
| 449 | |
Holger Hans Peter Freyther | 6a97b8d | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 450 | #endif |