Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * BSC NAT Message filtering |
| 3 | * |
| 4 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | df6143a | 2010-06-15 18:46:56 +0800 | [diff] [blame] | 5 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <openbsc/debug.h> |
| 26 | #include <openbsc/gsm_data.h> |
| 27 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 28 | #include <openbsc/bsc_nat_sccp.h> |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 29 | |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 30 | #include <osmocore/talloc.h> |
| 31 | |
Harald Welte | d5db12c | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 32 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 3268540 | 2010-09-15 05:20:40 +0800 | [diff] [blame] | 33 | #include <osmocore/protocol/gsm_08_08.h> |
Holger Hans Peter Freyther | 30e1ae9 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | |
| 37 | /* test messages for ipa */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 38 | static uint8_t ipa_id[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 39 | 0x00, 0x01, 0xfe, 0x06, |
| 40 | }; |
| 41 | |
| 42 | /* SCCP messages are below */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 43 | static uint8_t gsm_reset[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 44 | 0x00, 0x12, 0xfd, |
| 45 | 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe, |
| 46 | 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04, |
| 47 | 0x01, 0x20, |
| 48 | }; |
| 49 | |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 50 | static const uint8_t gsm_reset_ack[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 51 | 0x00, 0x13, 0xfd, |
| 52 | 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01, |
| 53 | 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03, |
| 54 | 0x00, 0x01, 0x31, |
| 55 | }; |
| 56 | |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 57 | static const uint8_t gsm_paging[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 58 | 0x00, 0x20, 0xfd, |
| 59 | 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01, |
| 60 | 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10, |
| 61 | 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10, |
| 62 | 0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06, |
| 63 | }; |
| 64 | |
| 65 | /* BSC -> MSC connection open */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 66 | static const uint8_t bssmap_cr[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 67 | 0x00, 0x2c, 0xfd, |
| 68 | 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02, |
| 69 | 0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05, |
| 70 | 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3, |
| 71 | 0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33, |
| 72 | 0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01, |
| 73 | 0x31, 0x97, 0x61, 0x00 |
| 74 | }; |
| 75 | |
| 76 | /* MSC -> BSC connection confirm */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 77 | static const uint8_t bssmap_cc[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 78 | 0x00, 0x0a, 0xfd, |
| 79 | 0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, |
| 80 | }; |
| 81 | |
| 82 | /* MSC -> BSC released */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 83 | static const uint8_t bssmap_released[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 84 | 0x00, 0x0e, 0xfd, |
| 85 | 0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f, |
| 86 | 0x02, 0x23, 0x42, 0x00, |
| 87 | }; |
| 88 | |
| 89 | /* BSC -> MSC released */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 90 | static const uint8_t bssmap_release_complete[] = { |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 91 | 0x00, 0x07, 0xfd, |
| 92 | 0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03 |
| 93 | }; |
| 94 | |
Holger Hans Peter Freyther | 0a6f62f | 2010-04-06 10:22:01 +0200 | [diff] [blame] | 95 | /* both directions IT timer */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 96 | static const uint8_t connnection_it[] = { |
Holger Hans Peter Freyther | 0a6f62f | 2010-04-06 10:22:01 +0200 | [diff] [blame] | 97 | 0x00, 0x0b, 0xfd, |
| 98 | 0x10, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03, |
| 99 | 0x00, 0x00, 0x00, 0x00, |
| 100 | }; |
| 101 | |
Holger Hans Peter Freyther | 5e63f92 | 2010-04-21 15:45:26 +0800 | [diff] [blame] | 102 | /* error in both directions */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 103 | static const uint8_t proto_error[] = { |
Holger Hans Peter Freyther | 5e63f92 | 2010-04-21 15:45:26 +0800 | [diff] [blame] | 104 | 0x00, 0x05, 0xfd, |
| 105 | 0x0f, 0x22, 0x33, 0x44, 0x00, |
| 106 | }; |
| 107 | |
Holger Hans Peter Freyther | a128d91 | 2010-04-01 08:47:12 +0200 | [diff] [blame] | 108 | /* MGCP wrap... */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 109 | static const uint8_t mgcp_msg[] = { |
Holger Hans Peter Freyther | a128d91 | 2010-04-01 08:47:12 +0200 | [diff] [blame] | 110 | 0x00, 0x03, 0xfc, |
| 111 | 0x20, 0x20, 0x20, |
| 112 | }; |
| 113 | |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 114 | /* location updating request */ |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 115 | static const uint8_t bss_lu[] = { |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 116 | 0x00, 0x2e, 0xfd, |
| 117 | 0x01, 0x91, 0x45, 0x14, 0x02, 0x02, 0x04, 0x02, |
| 118 | 0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05, |
| 119 | 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x14, 0xc3, |
| 120 | 0x50, 0x17, 0x12, 0x05, 0x08, 0x70, 0x72, 0xf4, |
| 121 | 0x80, 0xff, 0xfe, 0x30, 0x08, 0x29, 0x44, 0x50, |
| 122 | 0x12, 0x03, 0x24, 0x01, 0x95, 0x00 |
| 123 | }; |
| 124 | |
Holger Hans Peter Freyther | f192498 | 2010-05-15 23:54:04 +0800 | [diff] [blame] | 125 | /* paging response */ |
| 126 | static const uint8_t pag_resp[] = { |
| 127 | 0x00, 0x2c, 0xfd, 0x01, 0xe5, 0x68, |
| 128 | 0x14, 0x02, 0x02, 0x04, 0x02, 0x42, 0xfe, 0x0f, |
| 129 | 0x1f, 0x00, 0x1d, 0x57, 0x05, 0x08, 0x00, 0x72, |
| 130 | 0xf4, 0x80, 0x20, 0x16, 0xc3, 0x50, 0x17, 0x10, |
| 131 | 0x06, 0x27, 0x01, 0x03, 0x30, 0x18, 0x96, 0x08, |
| 132 | 0x29, 0x26, 0x30, 0x32, 0x11, 0x42, 0x01, 0x19, |
| 133 | 0x00 |
| 134 | }; |
| 135 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 136 | struct filter_result { |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 137 | const uint8_t *data; |
Holger Hans Peter Freyther | e2c1520 | 2010-07-23 19:09:21 +0800 | [diff] [blame] | 138 | const uint16_t length; |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 139 | const int dir; |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 140 | const int result; |
| 141 | }; |
| 142 | |
| 143 | static const struct filter_result results[] = { |
| 144 | { |
| 145 | .data = ipa_id, |
| 146 | .length = ARRAY_SIZE(ipa_id), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 147 | .dir = DIR_MSC, |
| 148 | .result = 1, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 149 | }, |
| 150 | { |
| 151 | .data = gsm_reset, |
| 152 | .length = ARRAY_SIZE(gsm_reset), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 153 | .dir = DIR_MSC, |
| 154 | .result = 1, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 155 | }, |
| 156 | { |
| 157 | .data = gsm_reset_ack, |
| 158 | .length = ARRAY_SIZE(gsm_reset_ack), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 159 | .dir = DIR_BSC, |
| 160 | .result = 1, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 161 | }, |
| 162 | { |
| 163 | .data = gsm_paging, |
| 164 | .length = ARRAY_SIZE(gsm_paging), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 165 | .dir = DIR_BSC, |
| 166 | .result = 0, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 167 | }, |
| 168 | { |
| 169 | .data = bssmap_cr, |
| 170 | .length = ARRAY_SIZE(bssmap_cr), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 171 | .dir = DIR_MSC, |
| 172 | .result = 0, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 173 | }, |
| 174 | { |
| 175 | .data = bssmap_cc, |
| 176 | .length = ARRAY_SIZE(bssmap_cc), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 177 | .dir = DIR_BSC, |
| 178 | .result = 0, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 179 | }, |
| 180 | { |
| 181 | .data = bssmap_released, |
| 182 | .length = ARRAY_SIZE(bssmap_released), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 183 | .dir = DIR_MSC, |
| 184 | .result = 0, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 185 | }, |
| 186 | { |
| 187 | .data = bssmap_release_complete, |
| 188 | .length = ARRAY_SIZE(bssmap_release_complete), |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 189 | .dir = DIR_BSC, |
| 190 | .result = 0, |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 191 | }, |
Holger Hans Peter Freyther | a128d91 | 2010-04-01 08:47:12 +0200 | [diff] [blame] | 192 | { |
| 193 | .data = mgcp_msg, |
| 194 | .length = ARRAY_SIZE(mgcp_msg), |
| 195 | .dir = DIR_MSC, |
| 196 | .result = 0, |
| 197 | }, |
Holger Hans Peter Freyther | 0a6f62f | 2010-04-06 10:22:01 +0200 | [diff] [blame] | 198 | { |
| 199 | .data = connnection_it, |
| 200 | .length = ARRAY_SIZE(connnection_it), |
| 201 | .dir = DIR_BSC, |
| 202 | .result = 0, |
| 203 | }, |
| 204 | { |
| 205 | .data = connnection_it, |
| 206 | .length = ARRAY_SIZE(connnection_it), |
| 207 | .dir = DIR_MSC, |
| 208 | .result = 0, |
| 209 | }, |
Holger Hans Peter Freyther | 5e63f92 | 2010-04-21 15:45:26 +0800 | [diff] [blame] | 210 | { |
| 211 | .data = proto_error, |
| 212 | .length = ARRAY_SIZE(proto_error), |
| 213 | .dir = DIR_BSC, |
| 214 | .result = 0, |
| 215 | }, |
| 216 | { |
| 217 | .data = proto_error, |
| 218 | .length = ARRAY_SIZE(proto_error), |
| 219 | .dir = DIR_MSC, |
| 220 | .result = 0, |
| 221 | }, |
| 222 | |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 223 | }; |
| 224 | |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 225 | static void test_filter(void) |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 226 | { |
| 227 | int i; |
| 228 | |
| 229 | |
| 230 | /* start testinh with proper messages */ |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 231 | fprintf(stderr, "Testing BSS Filtering.\n"); |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 232 | for (i = 0; i < ARRAY_SIZE(results); ++i) { |
| 233 | int result; |
| 234 | struct bsc_nat_parsed *parsed; |
| 235 | struct msgb *msg = msgb_alloc(4096, "test-message"); |
| 236 | |
| 237 | fprintf(stderr, "Going to test item: %d\n", i); |
| 238 | memcpy(msg->data, results[i].data, results[i].length); |
| 239 | msg->l2h = msgb_put(msg, results[i].length); |
| 240 | |
| 241 | parsed = bsc_nat_parse(msg); |
| 242 | if (!parsed) { |
| 243 | fprintf(stderr, "FAIL: Failed to parse the message\n"); |
| 244 | continue; |
| 245 | } |
| 246 | |
Holger Hans Peter Freyther | 1d6fb18 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 247 | result = bsc_nat_filter_ipa(results[i].dir, msg, parsed); |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 248 | if (result != results[i].result) { |
| 249 | fprintf(stderr, "FAIL: Not the expected result got: %d wanted: %d\n", |
| 250 | result, results[i].result); |
| 251 | } |
| 252 | |
| 253 | msgb_free(msg); |
| 254 | } |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 255 | } |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 256 | |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 257 | #include "bsc_data.c" |
| 258 | |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 259 | static void copy_to_msg(struct msgb *msg, const uint8_t *data, unsigned int length) |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 260 | { |
| 261 | msgb_reset(msg); |
| 262 | msg->l2h = msgb_put(msg, length); |
| 263 | memcpy(msg->l2h, data, msgb_l2len(msg)); |
| 264 | } |
| 265 | |
| 266 | #define VERIFY(con_found, con, msg, ver, str) \ |
Holger Hans Peter Freyther | 49c7fb5 | 2010-06-15 18:48:55 +0800 | [diff] [blame] | 267 | if (!con_found || con_found->bsc != con) { \ |
Holger Hans Peter Freyther | 72ba162 | 2010-06-15 18:48:44 +0800 | [diff] [blame] | 268 | fprintf(stderr, "Failed to find the con: %p\n", con_found); \ |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 269 | abort(); \ |
| 270 | } \ |
| 271 | if (memcmp(msg->data, ver, sizeof(ver)) != 0) { \ |
| 272 | fprintf(stderr, "Failed to patch the %s msg.\n", str); \ |
| 273 | abort(); \ |
| 274 | } |
| 275 | |
| 276 | /* test conn tracking once */ |
| 277 | static void test_contrack() |
| 278 | { |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 279 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | 49c7fb5 | 2010-06-15 18:48:55 +0800 | [diff] [blame] | 280 | struct bsc_connection *con; |
| 281 | struct sccp_connections *con_found; |
Holger Hans Peter Freyther | fa20c94 | 2010-05-16 16:51:31 +0800 | [diff] [blame] | 282 | struct sccp_connections *rc_con; |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 283 | struct bsc_nat_parsed *parsed; |
| 284 | struct msgb *msg; |
| 285 | |
| 286 | fprintf(stderr, "Testing connection tracking.\n"); |
| 287 | nat = bsc_nat_alloc(); |
| 288 | con = bsc_connection_alloc(nat); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 289 | con->cfg = bsc_config_alloc(nat, "foo"); |
| 290 | bsc_config_add_lac(con->cfg, 23); |
| 291 | bsc_config_add_lac(con->cfg, 49); |
| 292 | bsc_config_add_lac(con->cfg, 42); |
| 293 | bsc_config_del_lac(con->cfg, 49); |
| 294 | bsc_config_add_lac(con->cfg, 1111); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 295 | msg = msgb_alloc(4096, "test"); |
| 296 | |
| 297 | /* 1.) create a connection */ |
| 298 | copy_to_msg(msg, bsc_cr, sizeof(bsc_cr)); |
| 299 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | b5513ca | 2010-04-21 18:56:12 +0800 | [diff] [blame] | 300 | con_found = patch_sccp_src_ref_to_msc(msg, parsed, con); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 301 | if (con_found != NULL) { |
Holger Hans Peter Freyther | 72ba162 | 2010-06-15 18:48:44 +0800 | [diff] [blame] | 302 | fprintf(stderr, "Con should not exist %p\n", con_found); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 303 | abort(); |
| 304 | } |
Holger Hans Peter Freyther | fa20c94 | 2010-05-16 16:51:31 +0800 | [diff] [blame] | 305 | rc_con = create_sccp_src_ref(con, parsed); |
| 306 | if (!rc_con) { |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 307 | fprintf(stderr, "Failed to create a ref\n"); |
| 308 | abort(); |
| 309 | } |
Holger Hans Peter Freyther | b5513ca | 2010-04-21 18:56:12 +0800 | [diff] [blame] | 310 | con_found = patch_sccp_src_ref_to_msc(msg, parsed, con); |
Holger Hans Peter Freyther | 49c7fb5 | 2010-06-15 18:48:55 +0800 | [diff] [blame] | 311 | if (!con_found || con_found->bsc != con) { |
Holger Hans Peter Freyther | 72ba162 | 2010-06-15 18:48:44 +0800 | [diff] [blame] | 312 | fprintf(stderr, "Failed to find the con: %p\n", con_found); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 313 | abort(); |
| 314 | } |
Holger Hans Peter Freyther | fa20c94 | 2010-05-16 16:51:31 +0800 | [diff] [blame] | 315 | if (con_found != rc_con) { |
| 316 | fprintf(stderr, "Failed to find the right connection.\n"); |
| 317 | abort(); |
| 318 | } |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 319 | if (memcmp(msg->data, bsc_cr_patched, sizeof(bsc_cr_patched)) != 0) { |
| 320 | fprintf(stderr, "Failed to patch the BSC CR msg.\n"); |
| 321 | abort(); |
| 322 | } |
| 323 | talloc_free(parsed); |
| 324 | |
| 325 | /* 2.) get the cc */ |
| 326 | copy_to_msg(msg, msc_cc, sizeof(msc_cc)); |
| 327 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | 49c7fb5 | 2010-06-15 18:48:55 +0800 | [diff] [blame] | 328 | con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat); |
| 329 | VERIFY(con_found, con, msg, msc_cc_patched, "MSC CC"); |
| 330 | if (update_sccp_src_ref(con_found, parsed) != 0) { |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 331 | fprintf(stderr, "Failed to update the SCCP con.\n"); |
| 332 | abort(); |
| 333 | } |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 334 | |
| 335 | /* 3.) send some data */ |
| 336 | copy_to_msg(msg, bsc_dtap, sizeof(bsc_dtap)); |
| 337 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | b5513ca | 2010-04-21 18:56:12 +0800 | [diff] [blame] | 338 | con_found = patch_sccp_src_ref_to_msc(msg, parsed, con); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 339 | VERIFY(con_found, con, msg, bsc_dtap_patched, "BSC DTAP"); |
| 340 | |
| 341 | /* 4.) receive some data */ |
| 342 | copy_to_msg(msg, msc_dtap, sizeof(msc_dtap)); |
| 343 | parsed = bsc_nat_parse(msg); |
| 344 | con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat); |
| 345 | VERIFY(con_found, con, msg, msc_dtap_patched, "MSC DTAP"); |
| 346 | |
| 347 | /* 5.) close the connection */ |
| 348 | copy_to_msg(msg, msc_rlsd, sizeof(msc_rlsd)); |
| 349 | parsed = bsc_nat_parse(msg); |
| 350 | con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat); |
| 351 | VERIFY(con_found, con, msg, msc_rlsd_patched, "MSC RLSD"); |
| 352 | |
| 353 | /* 6.) confirm the connection close */ |
| 354 | copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc)); |
| 355 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | b5513ca | 2010-04-21 18:56:12 +0800 | [diff] [blame] | 356 | con_found = patch_sccp_src_ref_to_msc(msg, parsed, con); |
Holger Hans Peter Freyther | 49c7fb5 | 2010-06-15 18:48:55 +0800 | [diff] [blame] | 357 | if (!con_found || con_found->bsc != con) { |
Holger Hans Peter Freyther | 72ba162 | 2010-06-15 18:48:44 +0800 | [diff] [blame] | 358 | fprintf(stderr, "Failed to find the con: %p\n", con_found); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 359 | abort(); |
| 360 | } |
| 361 | if (memcmp(msg->data, bsc_rlc_patched, sizeof(bsc_rlc_patched)) != 0) { |
| 362 | fprintf(stderr, "Failed to patch the BSC CR msg.\n"); |
| 363 | abort(); |
| 364 | } |
| 365 | remove_sccp_src_ref(con, msg, parsed); |
Holger Hans Peter Freyther | 9d51855 | 2010-04-05 21:44:51 +0200 | [diff] [blame] | 366 | talloc_free(parsed); |
| 367 | |
| 368 | copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc)); |
| 369 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | b5513ca | 2010-04-21 18:56:12 +0800 | [diff] [blame] | 370 | con_found = patch_sccp_src_ref_to_msc(msg, parsed, con); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 371 | |
| 372 | /* verify that it is gone */ |
| 373 | if (con_found != NULL) { |
Holger Hans Peter Freyther | 72ba162 | 2010-06-15 18:48:44 +0800 | [diff] [blame] | 374 | fprintf(stderr, "Con should be gone. %p\n", con_found); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 375 | abort(); |
| 376 | } |
| 377 | talloc_free(parsed); |
| 378 | |
| 379 | |
| 380 | talloc_free(nat); |
| 381 | msgb_free(msg); |
| 382 | } |
| 383 | |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 384 | static void test_paging(void) |
| 385 | { |
Holger Hans Peter Freyther | 979a309 | 2010-04-17 08:07:19 +0200 | [diff] [blame] | 386 | int lac; |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 387 | struct bsc_nat *nat; |
| 388 | struct bsc_connection *con; |
| 389 | struct bsc_nat_parsed *parsed; |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 390 | struct bsc_config *cfg; |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 391 | struct msgb *msg; |
| 392 | |
| 393 | fprintf(stderr, "Testing paging by lac.\n"); |
| 394 | |
| 395 | nat = bsc_nat_alloc(); |
| 396 | con = bsc_connection_alloc(nat); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 397 | cfg = bsc_config_alloc(nat, "unknown"); |
| 398 | con->cfg = cfg; |
| 399 | bsc_config_add_lac(cfg, 23); |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 400 | con->authenticated = 1; |
| 401 | llist_add(&con->list_entry, &nat->bsc_connections); |
| 402 | msg = msgb_alloc(4096, "test"); |
| 403 | |
| 404 | /* Test completely bad input */ |
| 405 | copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); |
Holger Hans Peter Freyther | 979a309 | 2010-04-17 08:07:19 +0200 | [diff] [blame] | 406 | if (bsc_nat_find_bsc(nat, msg, &lac) != 0) { |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 407 | fprintf(stderr, "Should have not found anything.\n"); |
| 408 | abort(); |
| 409 | } |
| 410 | |
| 411 | /* Test it by not finding it */ |
| 412 | copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); |
| 413 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | 979a309 | 2010-04-17 08:07:19 +0200 | [diff] [blame] | 414 | if (bsc_nat_find_bsc(nat, msg, &lac) != 0) { |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 415 | fprintf(stderr, "Should have not found aynthing.\n"); |
| 416 | abort(); |
| 417 | } |
| 418 | talloc_free(parsed); |
| 419 | |
| 420 | /* Test by finding it */ |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 421 | bsc_config_del_lac(cfg, 23); |
| 422 | bsc_config_add_lac(cfg, 8213); |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 423 | copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); |
| 424 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | 979a309 | 2010-04-17 08:07:19 +0200 | [diff] [blame] | 425 | if (bsc_nat_find_bsc(nat, msg, &lac) != con) { |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 426 | fprintf(stderr, "Should have found it.\n"); |
| 427 | abort(); |
| 428 | } |
| 429 | talloc_free(parsed); |
| 430 | } |
| 431 | |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 432 | static void test_mgcp_ass_tracking(void) |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 433 | { |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 434 | struct bsc_connection *bsc; |
| 435 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 436 | struct sccp_connections con; |
| 437 | struct bsc_nat_parsed *parsed; |
| 438 | struct msgb *msg; |
| 439 | |
| 440 | fprintf(stderr, "Testing MGCP.\n"); |
| 441 | memset(&con, 0, sizeof(con)); |
| 442 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 443 | nat = bsc_nat_alloc(); |
| 444 | nat->bsc_endpoints = talloc_zero_array(nat, |
| 445 | struct bsc_endpoint, |
| 446 | 33); |
| 447 | bsc = bsc_connection_alloc(nat); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 448 | bsc->cfg = bsc_config_alloc(nat, "foo"); |
| 449 | bsc_config_add_lac(bsc->cfg, 2323); |
Holger Hans Peter Freyther | d2df4ca | 2010-09-19 20:54:21 +0800 | [diff] [blame] | 450 | bsc->last_endpoint = 0x1a; |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 451 | con.bsc = bsc; |
| 452 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 453 | msg = msgb_alloc(4096, "foo"); |
| 454 | copy_to_msg(msg, ass_cmd, sizeof(ass_cmd)); |
| 455 | parsed = bsc_nat_parse(msg); |
Holger Hans Peter Freyther | cd70237 | 2010-09-20 01:21:51 +0800 | [diff] [blame] | 456 | |
| 457 | if (msg->l2h[16] != 0 || |
| 458 | msg->l2h[17] != 0x1) { |
| 459 | fprintf(stderr, "Input is not as expected.. %s 0x%x\n", |
| 460 | hexdump(msg->l2h, msgb_l2len(msg)), |
| 461 | msg->l2h[17]); |
| 462 | abort(); |
| 463 | } |
| 464 | |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 465 | if (bsc_mgcp_assign_patch(&con, msg) != 0) { |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 466 | fprintf(stderr, "Failed to handle assignment.\n"); |
| 467 | abort(); |
| 468 | } |
| 469 | |
Holger Hans Peter Freyther | cd70237 | 2010-09-20 01:21:51 +0800 | [diff] [blame] | 470 | if (con.msc_endp != 1) { |
| 471 | fprintf(stderr, "Timeslot should be 1.\n"); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 472 | abort(); |
| 473 | } |
| 474 | |
Holger Hans Peter Freyther | d2df4ca | 2010-09-19 20:54:21 +0800 | [diff] [blame] | 475 | if (con.bsc_endp != 0x1b) { |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 476 | fprintf(stderr, "Assigned timeslot should have been 1.\n"); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 477 | abort(); |
| 478 | } |
Holger Hans Peter Freyther | d2df4ca | 2010-09-19 20:54:21 +0800 | [diff] [blame] | 479 | if (con.bsc->endpoint_status[0x1b] != 1) { |
Holger Hans Peter Freyther | 45fd07d | 2010-08-28 18:22:14 +0800 | [diff] [blame] | 480 | fprintf(stderr, "The status on the BSC is wrong.\n"); |
| 481 | abort(); |
| 482 | } |
| 483 | |
Holger Hans Peter Freyther | cd70237 | 2010-09-20 01:21:51 +0800 | [diff] [blame] | 484 | int multiplex, timeslot; |
| 485 | mgcp_endpoint_to_timeslot(0x1b, &multiplex, ×lot); |
| 486 | |
| 487 | uint16_t cic = htons(timeslot & 0x1f); |
| 488 | if (memcmp(&cic, &msg->l2h[16], sizeof(cic)) != 0) { |
| 489 | fprintf(stderr, "Message was not patched properly\n"); |
| 490 | fprintf(stderr, "data cic: 0x%x %s\n", cic, hexdump(msg->l2h, msgb_l2len(msg))); |
| 491 | abort(); |
| 492 | } |
| 493 | |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 494 | talloc_free(parsed); |
| 495 | |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 496 | bsc_mgcp_dlcx(&con); |
Holger Hans Peter Freyther | d2df4ca | 2010-09-19 20:54:21 +0800 | [diff] [blame] | 497 | if (con.bsc_endp != -1 || con.msc_endp != -1 || |
| 498 | con.bsc->endpoint_status[1] != 0 || con.bsc->last_endpoint != 0x1b) { |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 499 | fprintf(stderr, "Clearing should remove the mapping.\n"); |
| 500 | abort(); |
| 501 | } |
Holger Hans Peter Freyther | 7b7eef6 | 2010-04-22 12:08:17 +0800 | [diff] [blame] | 502 | |
| 503 | talloc_free(nat); |
Holger Hans Peter Freyther | 465313e | 2010-06-15 18:49:53 +0800 | [diff] [blame] | 504 | } |
| 505 | |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 506 | /* test the code to find a given connection */ |
| 507 | static void test_mgcp_find(void) |
| 508 | { |
| 509 | struct bsc_nat *nat; |
| 510 | struct bsc_connection *con; |
| 511 | struct sccp_connections *sccp_con; |
| 512 | |
| 513 | fprintf(stderr, "Testing finding of a BSC Connection\n"); |
| 514 | |
| 515 | nat = bsc_nat_alloc(); |
| 516 | con = bsc_connection_alloc(nat); |
| 517 | llist_add(&con->list_entry, &nat->bsc_connections); |
| 518 | |
| 519 | sccp_con = talloc_zero(con, struct sccp_connections); |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 520 | sccp_con->msc_endp = 12; |
| 521 | sccp_con->bsc_endp = 12; |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 522 | sccp_con->bsc = con; |
| 523 | llist_add(&sccp_con->list_entry, &nat->sccp_connections); |
| 524 | |
| 525 | if (bsc_mgcp_find_con(nat, 11) != NULL) { |
| 526 | fprintf(stderr, "Found the wrong connection.\n"); |
| 527 | abort(); |
| 528 | } |
| 529 | |
Holger Hans Peter Freyther | 08a1b16 | 2010-04-18 02:26:16 +0800 | [diff] [blame] | 530 | if (bsc_mgcp_find_con(nat, 12) != sccp_con) { |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 531 | fprintf(stderr, "Didn't find the connection\n"); |
| 532 | abort(); |
| 533 | } |
| 534 | |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 535 | /* free everything */ |
| 536 | talloc_free(nat); |
| 537 | } |
| 538 | |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 539 | static void test_mgcp_rewrite(void) |
| 540 | { |
| 541 | int i; |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 542 | struct msgb *output; |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 543 | fprintf(stderr, "Test rewriting MGCP messages.\n"); |
| 544 | |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 545 | for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) { |
| 546 | const char *orig = mgcp_messages[i].orig; |
| 547 | const char *patc = mgcp_messages[i].patch; |
| 548 | const char *ip = mgcp_messages[i].ip; |
| 549 | const int port = mgcp_messages[i].port; |
| 550 | |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 551 | char *input = strdup(orig); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 552 | |
Holger Hans Peter Freyther | f7c86c5 | 2010-08-30 13:44:32 +0800 | [diff] [blame] | 553 | output = bsc_mgcp_rewrite(input, strlen(input), 0x1e, ip, port); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 554 | if (msgb_l2len(output) != strlen(patc)) { |
| 555 | fprintf(stderr, "Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig)); |
| 556 | fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc); |
| 557 | abort(); |
| 558 | } |
| 559 | |
| 560 | if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) { |
| 561 | fprintf(stderr, "Broken on %d msg: '%s'\n", i, (const char *) output->l2h); |
| 562 | abort(); |
| 563 | } |
| 564 | |
| 565 | msgb_free(output); |
Holger Hans Peter Freyther | 8d20065 | 2010-04-04 18:09:10 +0200 | [diff] [blame] | 566 | free(input); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 567 | } |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 570 | static void test_mgcp_parse(void) |
| 571 | { |
| 572 | int code, ci; |
| 573 | char transaction[60]; |
| 574 | |
| 575 | fprintf(stderr, "Test MGCP response parsing.\n"); |
| 576 | |
| 577 | if (bsc_mgcp_parse_response(crcx_resp, &code, transaction) != 0) { |
| 578 | fprintf(stderr, "Failed to parse CRCX resp.\n"); |
| 579 | abort(); |
| 580 | } |
| 581 | |
| 582 | if (code != 200) { |
| 583 | fprintf(stderr, "Failed to parse the CODE properly. Got: %d\n", code); |
| 584 | abort(); |
| 585 | } |
| 586 | |
| 587 | if (strcmp(transaction, "23265295") != 0) { |
| 588 | fprintf(stderr, "Failed to parse transaction id: '%s'\n", transaction); |
| 589 | abort(); |
| 590 | } |
| 591 | |
| 592 | ci = bsc_mgcp_extract_ci(crcx_resp); |
| 593 | if (ci != 1) { |
| 594 | fprintf(stderr, "Failed to parse the CI. Got: %d\n", ci); |
| 595 | abort(); |
| 596 | } |
| 597 | } |
| 598 | |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 599 | struct cr_filter { |
Holger Hans Peter Freyther | dbd16fe | 2010-07-23 19:08:55 +0800 | [diff] [blame] | 600 | const uint8_t *data; |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 601 | int length; |
| 602 | int result; |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 603 | int contype; |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 604 | |
| 605 | const char *bsc_imsi_allow; |
| 606 | const char *bsc_imsi_deny; |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 607 | const char *nat_imsi_deny; |
| 608 | }; |
| 609 | |
| 610 | static struct cr_filter cr_filter[] = { |
| 611 | { |
| 612 | .data = bssmap_cr, |
| 613 | .length = sizeof(bssmap_cr), |
Holger Hans Peter Freyther | d880f54 | 2010-09-15 01:42:07 +0800 | [diff] [blame] | 614 | .result = 1, |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 615 | .contype = NAT_CON_TYPE_CM_SERV_REQ, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 616 | }, |
| 617 | { |
| 618 | .data = bss_lu, |
| 619 | .length = sizeof(bss_lu), |
Holger Hans Peter Freyther | d880f54 | 2010-09-15 01:42:07 +0800 | [diff] [blame] | 620 | .result = 1, |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 621 | .contype = NAT_CON_TYPE_LU, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 622 | }, |
| 623 | { |
Holger Hans Peter Freyther | f192498 | 2010-05-15 23:54:04 +0800 | [diff] [blame] | 624 | .data = pag_resp, |
| 625 | .length = sizeof(pag_resp), |
Holger Hans Peter Freyther | d880f54 | 2010-09-15 01:42:07 +0800 | [diff] [blame] | 626 | .result = 1, |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 627 | .contype = NAT_CON_TYPE_PAG_RESP, |
Holger Hans Peter Freyther | f192498 | 2010-05-15 23:54:04 +0800 | [diff] [blame] | 628 | }, |
| 629 | { |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 630 | /* nat deny is before blank/null BSC */ |
| 631 | .data = bss_lu, |
| 632 | .length = sizeof(bss_lu), |
| 633 | .result = -3, |
| 634 | .nat_imsi_deny = "[0-9]*", |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 635 | .contype = NAT_CON_TYPE_LU, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 636 | }, |
| 637 | { |
Holger Hans Peter Freyther | a0aeaa7 | 2010-05-14 23:07:58 +0800 | [diff] [blame] | 638 | /* BSC allow is before NAT deny */ |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 639 | .data = bss_lu, |
| 640 | .length = sizeof(bss_lu), |
Holger Hans Peter Freyther | d880f54 | 2010-09-15 01:42:07 +0800 | [diff] [blame] | 641 | .result = 1, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 642 | .nat_imsi_deny = "[0-9]*", |
Holger Hans Peter Freyther | a0aeaa7 | 2010-05-14 23:07:58 +0800 | [diff] [blame] | 643 | .bsc_imsi_allow = "2440[0-9]*", |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 644 | .contype = NAT_CON_TYPE_LU, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 645 | }, |
| 646 | { |
| 647 | /* BSC allow is before NAT deny */ |
| 648 | .data = bss_lu, |
| 649 | .length = sizeof(bss_lu), |
Holger Hans Peter Freyther | d880f54 | 2010-09-15 01:42:07 +0800 | [diff] [blame] | 650 | .result = 1, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 651 | .bsc_imsi_allow = "[0-9]*", |
| 652 | .nat_imsi_deny = "[0-9]*", |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 653 | .contype = NAT_CON_TYPE_LU, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 654 | }, |
| 655 | { |
| 656 | /* filter as deny is first */ |
| 657 | .data = bss_lu, |
| 658 | .length = sizeof(bss_lu), |
Holger Hans Peter Freyther | 1fd6063 | 2010-10-19 20:55:33 +0200 | [diff] [blame] | 659 | .result = 1, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 660 | .bsc_imsi_deny = "[0-9]*", |
| 661 | .bsc_imsi_allow = "[0-9]*", |
| 662 | .nat_imsi_deny = "[0-9]*", |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 663 | .contype = NAT_CON_TYPE_LU, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 664 | }, |
Holger Hans Peter Freyther | 1fd6063 | 2010-10-19 20:55:33 +0200 | [diff] [blame] | 665 | { |
| 666 | /* deny by nat rule */ |
| 667 | .data = bss_lu, |
| 668 | .length = sizeof(bss_lu), |
| 669 | .result = -3, |
| 670 | .bsc_imsi_deny = "000[0-9]*", |
| 671 | .nat_imsi_deny = "[0-9]*", |
| 672 | .contype = NAT_CON_TYPE_LU, |
| 673 | }, |
| 674 | { |
| 675 | /* deny by bsc rule */ |
| 676 | .data = bss_lu, |
| 677 | .length = sizeof(bss_lu), |
| 678 | .result = -2, |
| 679 | .bsc_imsi_deny = "[0-9]*", |
| 680 | .contype = NAT_CON_TYPE_LU, |
| 681 | }, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 682 | |
| 683 | }; |
| 684 | |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 685 | static void test_cr_filter() |
| 686 | { |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 687 | int i, res, contype; |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 688 | struct msgb *msg = msgb_alloc(4096, "test_cr_filter"); |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 689 | struct bsc_nat_parsed *parsed; |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 690 | struct bsc_nat_acc_lst *nat_lst, *bsc_lst; |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 691 | struct bsc_nat_acc_lst_entry *nat_entry, *bsc_entry; |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 692 | |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 693 | struct bsc_nat *nat = bsc_nat_alloc(); |
| 694 | struct bsc_connection *bsc = bsc_connection_alloc(nat); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 695 | bsc->cfg = bsc_config_alloc(nat, "foo"); |
| 696 | bsc_config_add_lac(bsc->cfg, 1234); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 697 | bsc->cfg->acc_lst_name = "bsc"; |
| 698 | nat->acc_lst_name = "nat"; |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 699 | |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 700 | nat_lst = bsc_nat_acc_lst_get(nat, "nat"); |
| 701 | bsc_lst = bsc_nat_acc_lst_get(nat, "bsc"); |
| 702 | |
| 703 | bsc_entry = bsc_nat_acc_lst_entry_create(bsc_lst); |
| 704 | nat_entry = bsc_nat_acc_lst_entry_create(nat_lst); |
| 705 | |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 706 | for (i = 0; i < ARRAY_SIZE(cr_filter); ++i) { |
Holger Hans Peter Freyther | 749497e | 2010-09-29 01:19:42 +0800 | [diff] [blame] | 707 | char *imsi; |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 708 | msgb_reset(msg); |
| 709 | copy_to_msg(msg, cr_filter[i].data, cr_filter[i].length); |
| 710 | |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 711 | nat_lst = bsc_nat_acc_lst_get(nat, "nat"); |
| 712 | bsc_lst = bsc_nat_acc_lst_get(nat, "bsc"); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 713 | |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 714 | bsc_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 715 | cr_filter[i].nat_imsi_deny ? 1 : 0, |
| 716 | &cr_filter[i].nat_imsi_deny); |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 717 | bsc_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 718 | cr_filter[i].bsc_imsi_allow ? 1 : 0, |
| 719 | &cr_filter[i].bsc_imsi_allow); |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 720 | bsc_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny, |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 721 | cr_filter[i].bsc_imsi_deny ? 1 : 0, |
| 722 | &cr_filter[i].bsc_imsi_deny); |
| 723 | |
| 724 | parsed = bsc_nat_parse(msg); |
| 725 | if (!parsed) { |
| 726 | fprintf(stderr, "FAIL: Failed to parse the message\n"); |
| 727 | abort(); |
| 728 | } |
| 729 | |
Holger Hans Peter Freyther | 749497e | 2010-09-29 01:19:42 +0800 | [diff] [blame] | 730 | res = bsc_nat_filter_sccp_cr(bsc, msg, parsed, &contype, &imsi); |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 731 | if (res != cr_filter[i].result) { |
| 732 | fprintf(stderr, "FAIL: Wrong result %d for test %d.\n", res, i); |
| 733 | abort(); |
| 734 | } |
| 735 | |
Holger Hans Peter Freyther | 19c0a84 | 2010-05-16 02:00:40 +0800 | [diff] [blame] | 736 | if (contype != cr_filter[i].contype) { |
| 737 | fprintf(stderr, "FAIL: Wrong contype %d for test %d.\n", res, contype); |
| 738 | abort(); |
| 739 | } |
| 740 | |
Holger Hans Peter Freyther | 749497e | 2010-09-29 01:19:42 +0800 | [diff] [blame] | 741 | talloc_steal(parsed, imsi); |
Holger Hans Peter Freyther | 34a96ae | 2010-05-14 19:49:35 +0800 | [diff] [blame] | 742 | talloc_free(parsed); |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 743 | } |
| 744 | |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 745 | msgb_free(msg); |
| 746 | } |
| 747 | |
Holger Hans Peter Freyther | 3268540 | 2010-09-15 05:20:40 +0800 | [diff] [blame] | 748 | static void test_dt_filter() |
| 749 | { |
| 750 | int i; |
| 751 | struct msgb *msg = msgb_alloc(4096, "test_dt_filter"); |
| 752 | struct bsc_nat_parsed *parsed; |
| 753 | |
| 754 | struct bsc_nat *nat = bsc_nat_alloc(); |
| 755 | struct bsc_connection *bsc = bsc_connection_alloc(nat); |
| 756 | struct sccp_connections *con = talloc_zero(0, struct sccp_connections); |
| 757 | |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 758 | bsc->cfg = bsc_config_alloc(nat, "foo"); |
| 759 | bsc_config_add_lac(bsc->cfg, 23); |
Holger Hans Peter Freyther | 3268540 | 2010-09-15 05:20:40 +0800 | [diff] [blame] | 760 | con->bsc = bsc; |
| 761 | |
| 762 | msgb_reset(msg); |
| 763 | copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp)); |
| 764 | |
| 765 | parsed = bsc_nat_parse(msg); |
| 766 | if (!parsed) { |
| 767 | fprintf(stderr, "FAIL: Could not parse ID resp\n"); |
| 768 | abort(); |
| 769 | } |
| 770 | |
| 771 | if (parsed->bssap != BSSAP_MSG_DTAP) { |
| 772 | fprintf(stderr, "FAIL: It should be dtap\n"); |
| 773 | abort(); |
| 774 | } |
| 775 | |
| 776 | /* gsm_type is actually the size of the dtap */ |
| 777 | if (parsed->gsm_type < msgb_l3len(msg) - 3) { |
| 778 | fprintf(stderr, "FAIL: Not enough space for the content\n"); |
| 779 | abort(); |
| 780 | } |
| 781 | |
| 782 | if (bsc_nat_filter_dt(bsc, msg, con, parsed) != 1) { |
| 783 | fprintf(stderr, "FAIL: Should have passed..\n"); |
| 784 | abort(); |
| 785 | } |
| 786 | |
| 787 | /* just some basic length checking... */ |
| 788 | for (i = ARRAY_SIZE(id_resp); i >= 0; --i) { |
| 789 | msgb_reset(msg); |
| 790 | copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp)); |
| 791 | |
| 792 | parsed = bsc_nat_parse(msg); |
| 793 | if (!parsed) |
| 794 | continue; |
| 795 | |
| 796 | con->imsi_checked = 0; |
| 797 | bsc_nat_filter_dt(bsc, msg, con, parsed); |
| 798 | } |
| 799 | } |
| 800 | |
Holger Hans Peter Freyther | 73bbf89 | 2010-10-21 14:46:57 +0200 | [diff] [blame] | 801 | static void test_setup_rewrite() |
| 802 | { |
| 803 | struct msgb *msg = msgb_alloc(4096, "test_dt_filter"); |
| 804 | struct msgb *out; |
| 805 | struct bsc_nat_parsed *parsed; |
| 806 | const char *imsi = "27408000001234"; |
| 807 | |
| 808 | struct bsc_nat *nat = bsc_nat_alloc(); |
| 809 | |
| 810 | /* a fake list */ |
| 811 | struct msg_entries entries; |
| 812 | struct msg_entry entry; |
| 813 | |
| 814 | INIT_LLIST_HEAD(&entries.entry); |
| 815 | entry.mcc = "274"; |
| 816 | entry.mnc = "08"; |
| 817 | entry.option = "^0([1-9])"; |
| 818 | entry.text = "0049"; |
| 819 | llist_add_tail(&entry.list, &entries.entry); |
| 820 | nat->num_rewr = &entries; |
| 821 | |
| 822 | /* verify that nothing changed */ |
| 823 | msgb_reset(msg); |
| 824 | copy_to_msg(msg, cc_setup_international, ARRAY_SIZE(cc_setup_international)); |
| 825 | parsed = bsc_nat_parse(msg); |
| 826 | if (!parsed) { |
| 827 | fprintf(stderr, "FAIL: Could not parse ID resp\n"); |
| 828 | abort(); |
| 829 | } |
| 830 | |
| 831 | out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); |
| 832 | if (msg != out) { |
| 833 | fprintf(stderr, "FAIL: The message should not have been changed\n"); |
| 834 | abort(); |
| 835 | } |
| 836 | |
| 837 | if (out->len != ARRAY_SIZE(cc_setup_international)) { |
| 838 | fprintf(stderr, "FAIL: Length of message changed\n"); |
| 839 | abort(); |
| 840 | } |
| 841 | |
| 842 | if (memcmp(out->data, cc_setup_international, out->len) != 0) { |
| 843 | fprintf(stderr, "FAIL: Content modified..\n"); |
| 844 | abort(); |
| 845 | } |
| 846 | talloc_free(parsed); |
| 847 | |
| 848 | /* verify that something in the message changes */ |
| 849 | msgb_reset(msg); |
| 850 | copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); |
| 851 | parsed = bsc_nat_parse(msg); |
| 852 | if (!parsed) { |
| 853 | fprintf(stderr, "FAIL: Could not parse ID resp\n"); |
| 854 | abort(); |
| 855 | } |
| 856 | |
| 857 | out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); |
| 858 | if (!out) { |
| 859 | fprintf(stderr, "FAIL: A new message should be created.\n"); |
| 860 | abort(); |
| 861 | } |
| 862 | |
| 863 | if (msg == out) { |
| 864 | fprintf(stderr, "FAIL: The message should have changed\n"); |
| 865 | abort(); |
| 866 | } |
| 867 | |
| 868 | if (out->len != ARRAY_SIZE(cc_setup_national_patched)) { |
| 869 | fprintf(stderr, "FAIL: Length is wrong.\n"); |
| 870 | abort(); |
| 871 | } |
| 872 | |
| 873 | if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) { |
| 874 | fprintf(stderr, "FAIL: Data is wrong.\n"); |
| 875 | fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len)); |
| 876 | abort(); |
| 877 | } |
| 878 | |
| 879 | msgb_free(out); |
Holger Hans Peter Freyther | 74779c6 | 2010-10-28 15:27:00 +0200 | [diff] [blame] | 880 | |
| 881 | /* Make sure that a wildcard is matching */ |
| 882 | entry.mnc = "*"; |
| 883 | msg = msgb_alloc(4096, "test_dt_filter"); |
| 884 | copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); |
| 885 | parsed = bsc_nat_parse(msg); |
| 886 | if (!parsed) { |
| 887 | fprintf(stderr, "FAIL: Could not parse ID resp\n"); |
| 888 | abort(); |
| 889 | } |
| 890 | |
| 891 | out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); |
| 892 | if (!out) { |
| 893 | fprintf(stderr, "FAIL: A new message should be created.\n"); |
| 894 | abort(); |
| 895 | } |
| 896 | |
| 897 | if (msg == out) { |
| 898 | fprintf(stderr, "FAIL: The message should have changed\n"); |
| 899 | abort(); |
| 900 | } |
| 901 | |
| 902 | if (out->len != ARRAY_SIZE(cc_setup_national_patched)) { |
| 903 | fprintf(stderr, "FAIL: Length is wrong.\n"); |
| 904 | abort(); |
| 905 | } |
| 906 | |
| 907 | if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) { |
| 908 | fprintf(stderr, "FAIL: Data is wrong.\n"); |
| 909 | fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len)); |
| 910 | abort(); |
| 911 | } |
| 912 | |
| 913 | msgb_free(out); |
| 914 | |
| 915 | /* Make sure that a wildcard is matching */ |
| 916 | entry.mnc = "09"; |
| 917 | msg = msgb_alloc(4096, "test_dt_filter"); |
| 918 | copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); |
| 919 | parsed = bsc_nat_parse(msg); |
| 920 | if (!parsed) { |
| 921 | fprintf(stderr, "FAIL: Could not parse ID resp\n"); |
| 922 | abort(); |
| 923 | } |
| 924 | |
| 925 | out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); |
| 926 | if (out != msg) { |
| 927 | fprintf(stderr, "FAIL: The message should be unchanged.\n"); |
| 928 | abort(); |
| 929 | } |
| 930 | |
| 931 | if (out->len != ARRAY_SIZE(cc_setup_national)) { |
| 932 | fprintf(stderr, "FAIL: Foo\n"); |
| 933 | abort(); |
| 934 | } |
| 935 | |
| 936 | if (memcmp(out->data, cc_setup_national, ARRAY_SIZE(cc_setup_national)) != 0) { |
| 937 | fprintf(stderr, "FAIL: The message should really be unchanged.\n"); |
| 938 | abort(); |
| 939 | } |
| 940 | |
| 941 | msgb_free(out); |
Holger Hans Peter Freyther | 73bbf89 | 2010-10-21 14:46:57 +0200 | [diff] [blame] | 942 | } |
| 943 | |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 944 | int main(int argc, char **argv) |
| 945 | { |
Holger Hans Peter Freyther | 434a1fd | 2010-06-15 20:18:40 +0800 | [diff] [blame] | 946 | struct log_target *stderr_target; |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 947 | |
Holger Hans Peter Freyther | 30e1ae9 | 2010-07-30 02:53:14 +0800 | [diff] [blame] | 948 | sccp_set_log_area(DSCCP); |
Holger Hans Peter Freyther | f094540 | 2010-07-05 13:29:42 +0800 | [diff] [blame] | 949 | log_init(&log_info); |
Holger Hans Peter Freyther | 434a1fd | 2010-06-15 20:18:40 +0800 | [diff] [blame] | 950 | stderr_target = log_target_create_stderr(); |
| 951 | log_add_target(stderr_target); |
| 952 | log_set_all_filter(stderr_target, 1); |
Holger Hans Peter Freyther | 38f7c75 | 2010-06-15 18:48:36 +0800 | [diff] [blame] | 953 | |
| 954 | test_filter(); |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 955 | test_contrack(); |
Holger Hans Peter Freyther | 04fd992 | 2010-03-30 06:51:53 +0200 | [diff] [blame] | 956 | test_paging(); |
Holger Hans Peter Freyther | fc9bd23 | 2010-04-01 03:55:27 +0200 | [diff] [blame] | 957 | test_mgcp_ass_tracking(); |
| 958 | test_mgcp_find(); |
Holger Hans Peter Freyther | 76c8354 | 2010-04-01 06:48:52 +0200 | [diff] [blame] | 959 | test_mgcp_rewrite(); |
Holger Hans Peter Freyther | 3c3bce1 | 2010-04-01 10:16:28 +0200 | [diff] [blame] | 960 | test_mgcp_parse(); |
Holger Hans Peter Freyther | 0c08db1 | 2010-05-14 08:12:57 +0800 | [diff] [blame] | 961 | test_cr_filter(); |
Holger Hans Peter Freyther | 3268540 | 2010-09-15 05:20:40 +0800 | [diff] [blame] | 962 | test_dt_filter(); |
Holger Hans Peter Freyther | 73bbf89 | 2010-10-21 14:46:57 +0200 | [diff] [blame] | 963 | test_setup_rewrite(); |
Holger Hans Peter Freyther | 0b8f69d | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 964 | return 0; |
| 965 | } |