Holger Hans Peter Freyther | 57adba5 | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010 by on-waves.com |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #ifndef BSC_NAT_H |
| 23 | #define BSC_NAT_H |
| 24 | |
| 25 | #include <sys/types.h> |
Holger Hans Peter Freyther | f75a680 | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 26 | #include <sccp/sccp_types.h> |
Holger Hans Peter Freyther | 2ef30aa | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 27 | |
Holger Hans Peter Freyther | 3b96089 | 2010-06-15 19:06:18 +0800 | [diff] [blame^] | 28 | #include <osmocore/select.h> |
| 29 | #include <osmocore/msgb.h> |
| 30 | #include <osmocore/timer.h> |
Holger Hans Peter Freyther | 57adba5 | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 31 | |
Holger Hans Peter Freyther | bbf6b65 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 32 | #define DIR_BSC 1 |
| 33 | #define DIR_MSC 2 |
Holger Hans Peter Freyther | f75a680 | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 34 | |
Holger Hans Peter Freyther | de55766 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 35 | struct bsc_nat; |
| 36 | |
Holger Hans Peter Freyther | f75a680 | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 37 | /* |
| 38 | * For the NAT we will need to analyze and later patch |
| 39 | * the received message. This would require us to parse |
| 40 | * the IPA and SCCP header twice. Instead of doing this |
| 41 | * we will have one analyze structure and have the patching |
| 42 | * and filter operate on the same structure. |
| 43 | */ |
| 44 | struct bsc_nat_parsed { |
| 45 | /* ip access prototype */ |
| 46 | int ipa_proto; |
| 47 | |
| 48 | /* source local reference */ |
| 49 | struct sccp_source_reference *src_local_ref; |
| 50 | |
| 51 | /* destination local reference */ |
| 52 | struct sccp_source_reference *dest_local_ref; |
| 53 | |
| 54 | /* called ssn number */ |
| 55 | int called_ssn; |
| 56 | |
| 57 | /* calling ssn number */ |
| 58 | int calling_ssn; |
| 59 | |
| 60 | /* sccp message type */ |
| 61 | int sccp_type; |
| 62 | |
| 63 | /* bssap type, e.g. 0 for BSS Management */ |
| 64 | int bssap; |
| 65 | |
| 66 | /* the gsm0808 message type */ |
| 67 | int gsm_type; |
| 68 | }; |
| 69 | |
Holger Hans Peter Freyther | 2ef30aa | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 70 | /* |
| 71 | * Per BSC data structure |
| 72 | */ |
| 73 | struct bsc_connection { |
| 74 | struct llist_head list_entry; |
| 75 | |
| 76 | /* do we know anything about this BSC? */ |
| 77 | int authenticated; |
| 78 | |
| 79 | /* the fd we use to communicate */ |
| 80 | struct bsc_fd bsc_fd; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 81 | |
| 82 | /* the LAC assigned to this connection */ |
| 83 | unsigned int lac; |
| 84 | |
| 85 | /* a timeout node */ |
| 86 | struct timer_list id_timeout; |
Holger Hans Peter Freyther | de55766 | 2010-06-15 18:46:19 +0800 | [diff] [blame] | 87 | |
| 88 | /* a back pointer */ |
| 89 | struct bsc_nat *nat; |
Holger Hans Peter Freyther | 2ef30aa | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* |
| 93 | * Per SCCP source local reference patch table. It needs to |
| 94 | * be updated on new SCCP connections, connection confirm and reject, |
| 95 | * and on the loss of the BSC connection. |
| 96 | */ |
| 97 | struct sccp_connections { |
| 98 | struct llist_head list_entry; |
| 99 | |
| 100 | struct bsc_connection *bsc; |
| 101 | |
| 102 | struct sccp_source_reference real_ref; |
| 103 | struct sccp_source_reference patched_ref; |
| 104 | }; |
| 105 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 106 | /** |
| 107 | * One BSC entry in the config |
| 108 | */ |
| 109 | struct bsc_config { |
| 110 | struct llist_head entry; |
| 111 | |
| 112 | char *token; |
| 113 | unsigned int lac; |
| 114 | int nr; |
| 115 | |
| 116 | struct bsc_nat *nat; |
| 117 | }; |
| 118 | |
| 119 | /** |
| 120 | * the structure of the "nat" network |
| 121 | */ |
| 122 | struct bsc_nat { |
| 123 | /* active SCCP connections that need patching */ |
| 124 | struct llist_head sccp_connections; |
| 125 | |
| 126 | /* active BSC connections that need patching */ |
| 127 | struct llist_head bsc_connections; |
| 128 | |
| 129 | /* known BSC's */ |
| 130 | struct llist_head bsc_configs; |
| 131 | int num_bsc; |
| 132 | }; |
| 133 | |
| 134 | /* create and init the structures */ |
| 135 | struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac); |
| 136 | struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num); |
| 137 | |
Holger Hans Peter Freyther | 2ef30aa | 2010-02-07 13:08:09 +0100 | [diff] [blame] | 138 | |
Holger Hans Peter Freyther | f75a680 | 2010-06-15 18:45:38 +0800 | [diff] [blame] | 139 | /** |
| 140 | * parse the given message into the above structure |
| 141 | */ |
| 142 | struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg); |
| 143 | |
Holger Hans Peter Freyther | 57adba5 | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 144 | /** |
| 145 | * filter based on IP Access header in both directions |
| 146 | */ |
Holger Hans Peter Freyther | bbf6b65 | 2010-01-30 11:53:30 +0100 | [diff] [blame] | 147 | int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 148 | int bsc_nat_vty_init(struct bsc_nat *nat); |
Holger Hans Peter Freyther | 57adba5 | 2010-06-15 18:45:26 +0800 | [diff] [blame] | 149 | |
| 150 | #endif |