OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [ipv4/] [ip_masq_raudio.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
2
 *              IP_MASQ_RAUDIO  - Real Audio masquerading module
3
 *
4
 *
5
 * Version:     @(#)$Id: ip_masq_raudio.c,v 1.1 2005-12-20 10:41:09 jcastillo Exp $
6
 *
7
 * Author:      Nigel Metheringham
8
 *              [strongly based on ftp module by Juan Jose Ciarlante & Wouter Gadeyne]
9
 *              [Real Audio information taken from Progressive Networks firewall docs]
10
 *              [Kudos to Progressive Networks for making the protocol specs available]
11
 *
12
 *
13
 *
14
 *      This program is free software; you can redistribute it and/or
15
 *      modify it under the terms of the GNU General Public License
16
 *      as published by the Free Software Foundation; either version
17
 *      2 of the License, or (at your option) any later version.
18
 *
19
 *
20
 * Limitations
21
 *      The IP Masquerading proxies at present do not have access to a processed
22
 *      data stream.  Hence for a protocol like the Real Audio control protocol,
23
 *      which depends on knowing where you are in the data stream, you either
24
 *      to keep a *lot* of state in your proxy, or you cheat and simplify the
25
 *      problem [needless to say I did the latter].
26
 *
27
 *      This proxy only handles data in the first packet.  Everything else is
28
 *      passed transparently.  This means it should work under all normal
29
 *      circumstances, but it could be fooled by new data formats or a
30
 *      malicious application!
31
 *
32
 *      At present the "first packet" is defined as a packet starting with
33
 *      the protocol ID string - "PNA".
34
 *      When the link is up there appears to be enough control data
35
 *      crossing the control link to keep it open even if a long audio
36
 *      piece is playing.
37
 *
38
 *      The Robust UDP support added in RealAudio 3.0 is supported, but due
39
 *      to servers/clients not making great use of this has not been greatly
40
 *      tested.  RealVideo (as used in the Real client version 4.0beta1) is
41
 *      supported but again is not greatly tested (bandwidth requirements
42
 *      appear to exceed that available at the sites supporting the protocol).
43
 *
44
 * Multiple Port Support
45
 *      The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
46
 *      with the port numbers being defined at module load time.  The module
47
 *      uses the symbol "ports" to define a list of monitored ports, which can
48
 *      be specified on the insmod command line as
49
 *              ports=x1,x2,x3...
50
 *      where x[n] are integer port numbers.  This option can be put into
51
 *      /etc/conf.modules (or /etc/modules.conf depending on your config)
52
 *      where modload will pick it up should you use modload to load your
53
 *      modules.
54
 *
55
 */
56
 
57
#include <linux/module.h>
58
#include <asm/system.h>
59
#include <linux/types.h>
60
#include <linux/kernel.h>
61
#include <linux/skbuff.h>
62
#include <linux/in.h>
63
#include <linux/ip.h>
64
#include <net/protocol.h>
65
#include <net/tcp.h>
66
#include <net/ip_masq.h>
67
 
68
#ifndef DEBUG_CONFIG_IP_MASQ_RAUDIO
69
#define DEBUG_CONFIG_IP_MASQ_RAUDIO 0
70
#endif
71
 
72
struct raudio_priv_data {
73
        /* Associated data connection - setup but not used at present */
74
        struct  ip_masq *data_conn;
75
        /* UDP Error correction connection - setup but not used at present */
76
        struct  ip_masq *error_conn;
77
        /* Have we seen and performed setup */
78
        short   seen_start;
79
};
80
 
81
#ifdef MODULE
82
#define STATIC
83
#else
84
#define STATIC  static
85
#endif
86
 
87
/*
88
 * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
89
 * First port is set to the default port.
90
 */
91
STATIC int ports[MAX_MASQ_APP_PORTS] = {7070}; /* I rely on the trailing items being set to zero */
92
struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
93
 
94
static int
95
masq_raudio_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
96
{
97
        MOD_INC_USE_COUNT;
98
        if ((ms->app_data = kmalloc(sizeof(struct raudio_priv_data),
99
                                    GFP_ATOMIC)) == NULL)
100
                printk(KERN_INFO "RealAudio: No memory for application data\n");
101
        else
102
        {
103
                struct raudio_priv_data *priv =
104
                        (struct raudio_priv_data *)ms->app_data;
105
                priv->seen_start = 0;
106
                priv->data_conn = NULL;
107
                priv->error_conn = NULL;
108
        }
109
        return 0;
110
}
111
 
112
static int
113
masq_raudio_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
114
{
115
        MOD_DEC_USE_COUNT;
116
        if (ms->app_data)
117
                kfree_s(ms->app_data, sizeof(struct raudio_priv_data));
118
        return 0;
119
}
120
 
121
int
122
masq_raudio_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
123
{
124
        struct sk_buff *skb;
125
        struct iphdr *iph;
126
        struct tcphdr *th;
127
        char *p, *data, *data_limit;
128
        struct ip_masq *n_ms;
129
        unsigned short version, msg_id, msg_len, udp_port;
130
        struct raudio_priv_data *priv =
131
                (struct raudio_priv_data *)ms->app_data;
132
 
133
        /* Everything running correctly already */
134
        if (priv && priv->seen_start)
135
                return 0;
136
 
137
        skb = *skb_p;
138
        iph = skb->h.iph;
139
        th = (struct tcphdr *)&(((char *)iph)[iph->ihl*4]);
140
        data = (char *)&th[1];
141
 
142
        data_limit = skb->h.raw + skb->len;
143
 
144
        /* Check to see if this is the first packet with protocol ID */
145
        if (memcmp(data, "PNA", 3)) {
146
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
147
                printk("RealAudio: not initial protocol packet - ignored\n");
148
#endif
149
                return(0);
150
        }
151
        data += 3;
152
        memcpy(&version, data, 2);
153
 
154
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
155
        printk("RealAudio: initial seen - protocol version %d\n",
156
               ntohs(version));
157
#endif
158
        if (priv)
159
                priv->seen_start = 1;
160
 
161
        if (ntohs(version) >= 256)
162
        {
163
                printk(KERN_INFO "RealAudio: version (%d) not supported\n",
164
                       ntohs(version));
165
                return 0;
166
        }
167
 
168
        data += 2;
169
        while (data+4 < data_limit) {
170
                memcpy(&msg_id, data, 2);
171
                data += 2;
172
                memcpy(&msg_len, data, 2);
173
                data += 2;
174
                if (ntohs(msg_id) == 0) {
175
                        /* The zero tag indicates the end of options */
176
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
177
                        printk("RealAudio: packet end tag seen\n");
178
#endif
179
                        return 0;
180
                }
181
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
182
                printk("RealAudio: msg %d - %d byte\n",
183
                       ntohs(msg_id), ntohs(msg_len));
184
#endif
185
                if (ntohs(msg_id) == 0) {
186
                        /* The zero tag indicates the end of options */
187
                        return 0;
188
                }
189
                p = data;
190
                data += ntohs(msg_len);
191
                if (data > data_limit)
192
                {
193
                        printk(KERN_INFO "RealAudio: Packet too short for data\n");
194
                        return 0;
195
                }
196
                if ((ntohs(msg_id) == 1) || (ntohs(msg_id) == 7)) {
197
                        /*
198
                         * MsgId == 1
199
                         * Audio UDP data port on client
200
                         *
201
                         * MsgId == 7
202
                         * Robust UDP error correction port number on client
203
                         *
204
                         * Since these messages are treated just the same, they
205
                         * are bundled together here....
206
                         */
207
                        memcpy(&udp_port, p, 2);
208
 
209
                        /*
210
                         * Sometimes a server sends a message 7 with a zero UDP port
211
                         * Rather than do anything with this, just ignore it!
212
                         */
213
                        if (udp_port == 0)
214
                                continue;
215
 
216
                        n_ms = ip_masq_new(dev, IPPROTO_UDP,
217
                                           ms->saddr, udp_port,
218
                                           ms->daddr, 0,
219
                                           IP_MASQ_F_NO_DPORT);
220
 
221
                        if (n_ms==NULL)
222
                                return 0;
223
 
224
                        memcpy(p, &(n_ms->mport), 2);
225
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
226
                        printk("RealAudio: rewrote UDP port %d -> %d in msg %d\n",
227
                               ntohs(udp_port), ntohs(n_ms->mport), ntohs(msg_id));
228
#endif
229
                        ip_masq_set_expire(n_ms, ip_masq_expire->udp_timeout);
230
 
231
                        /* Make ref in application data to data connection */
232
                        if (priv) {
233
                                if (ntohs(msg_id) == 1)
234
                                        priv->data_conn = n_ms;
235
                                else
236
                                        priv->error_conn = n_ms;
237
                        }
238
                }
239
        }
240
        return 0;
241
}
242
 
243
struct ip_masq_app ip_masq_raudio = {
244
        NULL,                   /* next */
245
        "RealAudio",            /* name */
246
        0,                      /* type */
247
        0,                      /* n_attach */
248
        masq_raudio_init_1,     /* ip_masq_init_1 */
249
        masq_raudio_done_1,     /* ip_masq_done_1 */
250
        masq_raudio_out,        /* pkt_out */
251
        NULL                    /* pkt_in */
252
};
253
 
254
/*
255
 *      ip_masq_raudio initialization
256
 */
257
 
258
int ip_masq_raudio_init(void)
259
{
260
        int i, j;
261
 
262
        for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
263
                if (ports[i]) {
264
                        if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
265
                                                            GFP_KERNEL)) == NULL)
266
                                return -ENOMEM;
267
                        memcpy(masq_incarnations[i], &ip_masq_raudio, sizeof(struct ip_masq_app));
268
                        if ((j = register_ip_masq_app(masq_incarnations[i],
269
                                                      IPPROTO_TCP,
270
                                                      ports[i]))) {
271
                                return j;
272
                        }
273
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
274
                        printk("RealAudio: loaded support on port[%d] = %d\n",
275
                               i, ports[i]);
276
#endif
277
                } else {
278
                        /* To be safe, force the incarnation table entry to NULL */
279
                        masq_incarnations[i] = NULL;
280
                }
281
        }
282
        return 0;
283
}
284
 
285
/*
286
 *      ip_masq_raudio fin.
287
 */
288
 
289
int ip_masq_raudio_done(void)
290
{
291
        int i, j, k;
292
 
293
        k=0;
294
        for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
295
                if (masq_incarnations[i]) {
296
                        if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
297
                                k = j;
298
                        } else {
299
                                kfree(masq_incarnations[i]);
300
                                masq_incarnations[i] = NULL;
301
#if DEBUG_CONFIG_IP_MASQ_RAUDIO
302
                                printk("RealAudio: unloaded support on port[%d] = %d\n",
303
                                       i, ports[i]);
304
#endif
305
                        }
306
                }
307
        }
308
        return k;
309
}
310
 
311
#ifdef MODULE
312
 
313
int init_module(void)
314
{
315
        if (ip_masq_raudio_init() != 0)
316
                return -EIO;
317
        register_symtab(0);
318
        return 0;
319
}
320
 
321
void cleanup_module(void)
322
{
323
        if (ip_masq_raudio_done() != 0)
324
                printk("ip_masq_raudio: can't remove module");
325
}
326
 
327
#endif /* MODULE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.