blob: 5ac60df8740514e7c9edb19a6b335a86c83f1539 [file] [log] [blame]
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +08001/*
2 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freytherdf6143a2010-06-15 18:46:56 +08003 * (C) 2010 by On-Waves
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +08004 * 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 Freyther0b8f69d2010-06-15 18:45:38 +080026#include <sccp/sccp_types.h>
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010027
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080028#include <osmocore/select.h>
29#include <osmocore/msgb.h>
30#include <osmocore/timer.h>
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +080031#include <osmocore/write_queue.h>
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080032
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +010033#define DIR_BSC 1
34#define DIR_MSC 2
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080035
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +080036struct bsc_nat;
37
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080038/*
39 * For the NAT we will need to analyze and later patch
40 * the received message. This would require us to parse
41 * the IPA and SCCP header twice. Instead of doing this
42 * we will have one analyze structure and have the patching
43 * and filter operate on the same structure.
44 */
45struct bsc_nat_parsed {
46 /* ip access prototype */
47 int ipa_proto;
48
49 /* source local reference */
50 struct sccp_source_reference *src_local_ref;
51
52 /* destination local reference */
53 struct sccp_source_reference *dest_local_ref;
54
55 /* called ssn number */
56 int called_ssn;
57
58 /* calling ssn number */
59 int calling_ssn;
60
61 /* sccp message type */
62 int sccp_type;
63
64 /* bssap type, e.g. 0 for BSS Management */
65 int bssap;
66
67 /* the gsm0808 message type */
68 int gsm_type;
69};
70
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010071/*
72 * Per BSC data structure
73 */
74struct bsc_connection {
75 struct llist_head list_entry;
76
77 /* do we know anything about this BSC? */
78 int authenticated;
79
80 /* the fd we use to communicate */
Holger Hans Peter Freythered07a3f2010-06-15 18:47:10 +080081 struct write_queue write_queue;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080082
83 /* the LAC assigned to this connection */
84 unsigned int lac;
85
86 /* a timeout node */
87 struct timer_list id_timeout;
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +080088
89 /* a back pointer */
90 struct bsc_nat *nat;
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010091};
92
93/*
94 * Per SCCP source local reference patch table. It needs to
95 * be updated on new SCCP connections, connection confirm and reject,
96 * and on the loss of the BSC connection.
97 */
98struct sccp_connections {
99 struct llist_head list_entry;
100
101 struct bsc_connection *bsc;
102
103 struct sccp_source_reference real_ref;
104 struct sccp_source_reference patched_ref;
105};
106
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800107/**
108 * One BSC entry in the config
109 */
110struct bsc_config {
111 struct llist_head entry;
112
113 char *token;
114 unsigned int lac;
115 int nr;
116
117 struct bsc_nat *nat;
118};
119
120/**
121 * the structure of the "nat" network
122 */
123struct bsc_nat {
124 /* active SCCP connections that need patching */
125 struct llist_head sccp_connections;
126
127 /* active BSC connections that need patching */
128 struct llist_head bsc_connections;
129
130 /* known BSC's */
131 struct llist_head bsc_configs;
132 int num_bsc;
133};
134
135/* create and init the structures */
136struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac);
137struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
138
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +0100139
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800140/**
141 * parse the given message into the above structure
142 */
143struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
144
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800145/**
146 * filter based on IP Access header in both directions
147 */
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100148int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800149int bsc_nat_vty_init(struct bsc_nat *nat);
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800150
151#endif