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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [ipv4/] [ip_masq_cuseeme.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
2
 *              IP_MASQ_FTP CUSeeMe masquerading module
3
 *
4
 *
5
 * Version:     @(#)$Id: ip_masq_cuseeme.c,v 1.1 2005-12-20 10:41:09 jcastillo Exp $
6
 *
7
 * Author:      Richard Lynch
8
 *
9
 *
10
 * Fixes:
11
 *      Richard Lynch           :       Updated patch to conform to new module
12
 *                                      specifications
13
 *      Nigel Metheringham      :       Multiple port support
14
 *      Michael Owings          :       Fixed broken init code
15
 *                                      Added code to update inbound
16
 *                                      packets with correct local addresses.
17
 *                                      Fixes audio and "chat" problems
18
 *                                      Thanx to the CU-SeeMe Consortium for
19
 *                                      technical docs
20
 *
21
 *
22
 *
23
 *      This program is free software; you can redistribute it and/or
24
 *      modify it under the terms of the GNU General Public License
25
 *      as published by the Free Software Foundation; either version
26
 *      2 of the License, or (at your option) any later version.
27
 *
28
 * Multiple Port Support
29
 *      The helper can be made to handle up to MAX_MASQ_APP_PORTS (normally 12)
30
 *      with the port numbers being defined at module load time.  The module
31
 *      uses the symbol "ports" to define a list of monitored ports, which can
32
 *      be specified on the insmod command line as
33
 *              ports=x1,x2,x3...
34
 *      where x[n] are integer port numbers.  This option can be put into
35
 *      /etc/conf.modules (or /etc/modules.conf depending on your config)
36
 *      where modload will pick it up should you use modload to load your
37
 *      modules.
38
 *
39
 */
40
 
41
#include <linux/module.h>
42
#include <asm/system.h>
43
#include <linux/types.h>
44
#include <linux/kernel.h>
45
#include <linux/skbuff.h>
46
#include <linux/in.h>
47
#include <linux/ip.h>
48
#include <net/protocol.h>
49
#include <net/udp.h>
50
#include <net/ip_masq.h>
51
 
52
#ifndef DEBUG_CONFIG_IP_MASQ_CUSEEME
53
#define DEBUG_CONFIG_IP_MASQ_CUSEEME 0
54
#endif
55
 
56
#pragma pack(1)
57
/* CU-SeeMe Data Header */
58
typedef struct {
59
        u_short         dest_family;
60
        u_short         dest_port;
61
        u_long          dest_addr;
62
        short           family;
63
        u_short         port;
64
        u_long          addr;
65
        u_long          seq;
66
        u_short         msg;
67
        u_short         data_type;
68
        u_short         packet_len;
69
} cu_header;
70
 
71
/* Open Continue Header */
72
typedef struct  {
73
        cu_header       cu_head;
74
        u_short         client_count; /* Number of client info structs */
75
        u_long          seq_no;
76
        char            user_name[20];
77
        char            stuff[4]; /* flags,  version stuff,  etc */
78
}oc_header;
79
 
80
/* client info structures */
81
typedef struct {
82
        u_long          address; /* Client address */
83
        char            stuff[8]; /* Flags, pruning bitfield,  packet counts etc */
84
} client_info;
85
#pragma pack()
86
 
87
#ifdef MODULE
88
#define STATIC
89
#else
90
#define STATIC  static
91
#endif
92
 
93
/*
94
 * List of ports (up to MAX_MASQ_APP_PORTS) to be handled by helper
95
 * First port is set to the default port.
96
 */
97
STATIC int ports[MAX_MASQ_APP_PORTS] = {7648}; /* I rely on the trailing items being set to zero */
98
struct ip_masq_app *masq_incarnations[MAX_MASQ_APP_PORTS];
99
 
100
static int
101
masq_cuseeme_init_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
102
{
103
        MOD_INC_USE_COUNT;
104
        return 0;
105
}
106
 
107
static int
108
masq_cuseeme_done_1 (struct ip_masq_app *mapp, struct ip_masq *ms)
109
{
110
        MOD_DEC_USE_COUNT;
111
        return 0;
112
}
113
 
114
int
115
masq_cuseeme_out (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
116
{
117
        struct sk_buff *skb = *skb_p;
118
        struct iphdr *iph = skb->h.iph;
119
        struct udphdr *uh = (struct udphdr *)&(((char *)iph)[iph->ihl*4]);
120
        cu_header *cu_head;
121
        char *data=(char *)&uh[1];
122
 
123
        if (skb->len - ((unsigned char *) data - skb->h.raw) >= sizeof(cu_header))
124
        {
125
                cu_head         = (cu_header *) data;
126
                /* cu_head->port   = ms->mport; */
127
                if( cu_head->addr )
128
                cu_head->addr = (u_long) dev->pa_addr;
129
#if DEBUG_CONFIG_IP_MASQ_CUSEEME          
130
                if(ntohs(cu_head->data_type) == 257)
131
                   printk(KERN_INFO "Sending talk packet!\n");
132
#endif    
133
        }
134
        return 0;
135
}
136
 
137
int
138
masq_cuseeme_in (struct ip_masq_app *mapp, struct ip_masq *ms, struct sk_buff **skb_p, struct device *dev)
139
{
140
        struct sk_buff *skb = *skb_p;
141
        struct iphdr *iph = skb->h.iph;
142
        struct udphdr *uh = (struct udphdr *)&(((char *)iph)[iph->ihl*4]);
143
        cu_header *cu_head;
144
        oc_header       *oc;
145
        client_info     *ci;
146
        char *data=(char *)&uh[1];
147
        u_short len = skb->len - ((unsigned char *) data - skb->h.raw);
148
        int             i, off;
149
 
150
        if (len >= sizeof(cu_header))
151
        {
152
                cu_head         = (cu_header *) data;
153
                if(cu_head->dest_addr) /* Correct destination address */
154
                        cu_head->dest_addr = (u_long) ms->saddr;
155
                if(ntohs(cu_head->data_type)==101 && len > sizeof(oc_header))
156
                {
157
                        oc = (oc_header * ) data;
158
                        /* Spin (grovel) thru client_info structs till we find our own */
159
                        off=sizeof(oc_header);
160
                        for(i=0;
161
                            (i < oc->client_count && off+sizeof(client_info) <= len);
162
                            i++)
163
                        {
164
                                ci=(client_info *)(data+off);
165
                                if(ci->address==(u_long) dev->pa_addr)
166
                                {
167
                                        /* Update w/ our real ip address and exit */
168
                                        ci->address = (u_long) ms->saddr;
169
                                        break;
170
                                }
171
                                else
172
                                   off+=sizeof(client_info);
173
                        }
174
                }
175
        }
176
        return 0;
177
}
178
 
179
struct ip_masq_app ip_masq_cuseeme = {
180
        NULL,                   /* next */
181
        "cuseeme",
182
        0,                      /* type */
183
        0,                      /* n_attach */
184
        masq_cuseeme_init_1,    /* ip_masq_init_1 */
185
        masq_cuseeme_done_1,    /* ip_masq_done_1 */
186
        masq_cuseeme_out,       /* pkt_out */
187
        masq_cuseeme_in         /* pkt_in */
188
};
189
 
190
 
191
/*
192
 *      ip_masq_cuseeme initialization
193
 */
194
 
195
int ip_masq_cuseeme_init(void)
196
{
197
        int i, j;
198
 
199
        for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
200
                if (ports[i]) {
201
                        if ((masq_incarnations[i] = kmalloc(sizeof(struct ip_masq_app),
202
                                                            GFP_KERNEL)) == NULL)
203
                                return -ENOMEM;
204
                        memcpy(masq_incarnations[i], &ip_masq_cuseeme, sizeof(struct ip_masq_app));
205
                        if ((j = register_ip_masq_app(masq_incarnations[i],
206
                                                      IPPROTO_UDP,
207
                                                      ports[i]))) {
208
                                return j;
209
                        }
210
#if DEBUG_CONFIG_IP_MASQ_CUSEEME
211
                        printk(KERN_INFO "CuSeeMe: loaded support on port[%d] = %d\n",
212
                               i, ports[i]);
213
#endif
214
                } else {
215
                        /* To be safe, force the incarnation table entry to NULL */
216
                        masq_incarnations[i] = NULL;
217
                }
218
        }
219
        return 0;
220
}
221
 
222
/*
223
 *      ip_masq_cuseeme fin.
224
 */
225
 
226
int ip_masq_cuseeme_done(void)
227
{
228
        int i, j, k;
229
 
230
        k=0;
231
        for (i=0; (i<MAX_MASQ_APP_PORTS); i++) {
232
                if (masq_incarnations[i]) {
233
                        if ((j = unregister_ip_masq_app(masq_incarnations[i]))) {
234
                                k = j;
235
                        } else {
236
                                kfree(masq_incarnations[i]);
237
                                masq_incarnations[i] = NULL;
238
#if DEBUG_CONFIG_IP_MASQ_CUSEEME
239
                                printk(KERN_INFO "CuSeeMe: unloaded support on port[%d] = %d\n",
240
                                       i, ports[i]);
241
#endif
242
                        }
243
                }
244
        }
245
        return k;
246
}
247
 
248
#ifdef MODULE
249
 
250
int init_module(void)
251
{
252
        if (ip_masq_cuseeme_init() != 0)
253
                return -EIO;
254
        register_symtab(0);
255
        return 0;
256
}
257
 
258
void cleanup_module(void)
259
{
260
        if (ip_masq_cuseeme_done() != 0)
261
                printk(KERN_INFO "ip_masq_cuseeme: can't remove module");
262
}
263
 
264
#endif /* MODULE */

powered by: WebSVN 2.1.0

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