blob: d42e489e750362807f98067d7334d868349765e8 [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 Freyther6a97b8d2010-06-15 18:45:26 +080031
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +010032#define DIR_BSC 1
33#define DIR_MSC 2
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080034
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +080035struct bsc_nat;
36
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080037/*
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 */
44struct 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 Freyther9f8f3d02010-02-07 13:08:09 +010070/*
71 * Per BSC data structure
72 */
73struct 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 Freyther9a85ef32010-06-15 18:46:11 +080081
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 Freytheraa698242010-06-15 18:46:19 +080087
88 /* a back pointer */
89 struct bsc_nat *nat;
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010090};
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 */
97struct 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 Freyther9a85ef32010-06-15 18:46:11 +0800106/**
107 * One BSC entry in the config
108 */
109struct 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 */
122struct 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 */
135struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac);
136struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
137
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +0100138
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800139/**
140 * parse the given message into the above structure
141 */
142struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
143
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800144/**
145 * filter based on IP Access header in both directions
146 */
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100147int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800148int bsc_nat_vty_init(struct bsc_nat *nat);
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800149
150#endif