]> git.pld-linux.org Git - packages/kernel.git/blob - pom-ng-ipp2p-20060829.patch
BINFMT_COFF is off
[packages/kernel.git] / pom-ng-ipp2p-20060829.patch
1  include/linux/netfilter_ipv4/ipt_ipp2p.h |   31 +
2  net/ipv4/netfilter/Kconfig               |   10 
3  net/ipv4/netfilter/Makefile              |    1 
4  net/ipv4/netfilter/ipt_ipp2p.c           |  884 +++++++++++++++++++++++++++++++
5  4 files changed, 926 insertions(+)
6
7 diff -Nur --exclude '*.orig' linux.org/include/linux/netfilter_ipv4/ipt_ipp2p.h linux/include/linux/netfilter_ipv4/ipt_ipp2p.h
8 --- linux.org/include/linux/netfilter_ipv4/ipt_ipp2p.h  1970-01-01 00:00:00.000000000 +0000
9 +++ linux/include/linux/netfilter_ipv4/ipt_ipp2p.h      2006-08-29 12:35:07.000000000 +0000
10 @@ -0,0 +1,31 @@
11 +#ifndef __IPT_IPP2P_H
12 +#define __IPT_IPP2P_H
13 +#define IPP2P_VERSION "0.8.1_rc1"
14 +
15 +struct ipt_p2p_info {
16 +    int cmd;
17 +    int debug;
18 +};
19 +
20 +#endif //__IPT_IPP2P_H
21 +
22 +#define SHORT_HAND_IPP2P       1 /* --ipp2p switch*/
23 +//#define SHORT_HAND_DATA              4 /* --ipp2p-data switch*/
24 +#define SHORT_HAND_NONE                5 /* no short hand*/
25 +
26 +#define IPP2P_EDK              (1 << 1)
27 +#define IPP2P_DATA_KAZAA       (1 << 2)
28 +#define IPP2P_DATA_EDK         (1 << 3)
29 +#define IPP2P_DATA_DC          (1 << 4)
30 +#define IPP2P_DC               (1 << 5)
31 +#define IPP2P_DATA_GNU         (1 << 6)
32 +#define IPP2P_GNU              (1 << 7)
33 +#define IPP2P_KAZAA            (1 << 8)
34 +#define IPP2P_BIT              (1 << 9)
35 +#define IPP2P_APPLE            (1 << 10)
36 +#define IPP2P_SOUL             (1 << 11)
37 +#define IPP2P_WINMX            (1 << 12)
38 +#define IPP2P_ARES             (1 << 13)
39 +#define IPP2P_MUTE             (1 << 14)
40 +#define IPP2P_WASTE            (1 << 15)
41 +#define IPP2P_XDCC             (1 << 16)
42 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/ipt_ipp2p.c linux/net/ipv4/netfilter/ipt_ipp2p.c
43 --- linux.org/net/ipv4/netfilter/ipt_ipp2p.c    1970-01-01 00:00:00.000000000 +0000
44 +++ linux/net/ipv4/netfilter/ipt_ipp2p.c        2006-08-29 12:35:07.000000000 +0000
45 @@ -0,0 +1,884 @@
46 +#if defined(MODVERSIONS)
47 +#include <linux/modversions.h>
48 +#endif
49 +#include <linux/module.h>
50 +#include <linux/version.h>
51 +#include <linux/netfilter_ipv4/ip_tables.h>
52 +#include <linux/netfilter_ipv4/ipt_ipp2p.h>
53 +#include <net/tcp.h>
54 +#include <net/udp.h>
55 +
56 +#define get_u8(X,O)  (*(__u8 *)(X + O))
57 +#define get_u16(X,O)  (*(__u16 *)(X + O))
58 +#define get_u32(X,O)  (*(__u32 *)(X + O))
59 +
60 +MODULE_AUTHOR("Eicke Friedrich/Klaus Degner <ipp2p@ipp2p.org>");
61 +MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic.");
62 +MODULE_LICENSE("GPL");
63 +
64 +
65 +/*Search for UDP eDonkey/eMule/Kad commands*/
66 +int
67 +udp_search_edk (unsigned char *haystack, int packet_len)
68 +{
69 +    unsigned char *t = haystack;
70 +    t += 8;
71 +
72 +       switch (t[0]) {
73 +               case 0xe3: 
74 +               {       /*edonkey*/
75 +                       switch (t[1]) 
76 +                       {
77 +                               /* client -> server status request */
78 +                               case 0x96: 
79 +                                       if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
80 +                                       break;
81 +                               /* server -> client status request */
82 +                               case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
83 +                                       break;
84 +                                               /* server description request */
85 +                                               /* e3 2a ff f0 .. | size == 6 */
86 +                               case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52);
87 +                                       break;
88 +                                               /* server description response */
89 +                                               /* e3 a3 ff f0 ..  | size > 40 && size < 200 */
90 +                               //case 0xa3: return ((IPP2P_EDK * 100) + 53);
91 +                               //      break;
92 +                               case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
93 +                                       break;
94 +
95 +                               case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
96 +                                       break;
97 +                       }
98 +                       break;
99 +               }
100 +               case 0xe4: 
101 +               {
102 +                       switch (t[1]) 
103 +                       {
104 +                                               /* e4 20 .. | size == 43 */
105 +                               case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
106 +                                       break;
107 +                                               /* e4 00 .. 00 | size == 35 ? */
108 +                               case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
109 +                                       break;
110 +                                               /* e4 10 .. 00 | size == 35 ? */
111 +                               case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
112 +                                       break;
113 +                                               /* e4 18 .. 00 | size == 35 ? */
114 +                               case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
115 +                                       break;
116 +                                               /* e4 52 .. | size = 44 */
117 +                               case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
118 +                                       break;
119 +                                               /* e4 58 .. | size == 6 */
120 +                               case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
121 +                                       break;
122 +                                               /* e4 59 .. | size == 2 */
123 +                               case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
124 +                                       break;
125 +                                       /* e4 28 .. | packet_len == 52,77,102,127... */
126 +                               case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
127 +                                       break;
128 +                                       /* e4 50 xx xx | size == 4 */
129 +                               case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
130 +                                       break;
131 +                                       /* e4 40 xx xx | size == 48 */
132 +                               case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
133 +                                       break;
134 +                       }
135 +                       break;
136 +               }
137 +       } /* end of switch (t[0]) */
138 +    return 0;
139 +}/*udp_search_edk*/
140 +
141 +
142 +/*Search for UDP Gnutella commands*/
143 +int
144 +udp_search_gnu (unsigned char *haystack, int packet_len)
145 +{
146 +    unsigned char *t = haystack;
147 +    t += 8;
148 +    
149 +    if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
150 +    if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
151 +    return 0;
152 +}/*udp_search_gnu*/
153 +
154 +
155 +/*Search for UDP KaZaA commands*/
156 +int
157 +udp_search_kazaa (unsigned char *haystack, int packet_len)
158 +{
159 +    unsigned char *t = haystack;
160 +    
161 +    if (t[packet_len-1] == 0x00){
162 +       t += (packet_len - 6);
163 +       if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
164 +    }
165 +    
166 +    return 0;
167 +}/*udp_search_kazaa*/
168 +
169 +/*Search for UDP DirectConnect commands*/
170 +int
171 +udp_search_directconnect (unsigned char *haystack, int packet_len)
172 +{
173 +    unsigned char *t = haystack;
174 +    if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
175 +       t+=8;
176 +       if (memcmp(t, "SR ", 3) == 0)                   return ((IPP2P_DC * 100) + 60);
177 +       if (memcmp(t, "Ping ", 5) == 0)                 return ((IPP2P_DC * 100) + 61);
178 +    }
179 +    return 0;
180 +}/*udp_search_directconnect*/
181 +
182 +
183 +
184 +/*Search for UDP BitTorrent commands*/
185 +int
186 +udp_search_bit (unsigned char *haystack, int packet_len)
187 +{
188 +       switch(packet_len)
189 +       {
190 +               case 24:
191 +                       /* ^ 00 00 04 17 27 10 19 80 */
192 +                       if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980)) 
193 +                               return (IPP2P_BIT * 100 + 50);
194 +                       break;
195 +               case 44:
196 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) 
197 +                               return (IPP2P_BIT * 100 + 51);
198 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000400))
199 +                               return (IPP2P_BIT * 100 + 61);
200 +                       break;
201 +               case 65:
202 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) 
203 +                               return (IPP2P_BIT * 100 + 52);
204 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000404))
205 +                               return (IPP2P_BIT * 100 + 62);
206 +                       break;
207 +               case 67:
208 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) 
209 +                               return (IPP2P_BIT * 100 + 53);
210 +                       if (get_u32(haystack, 16) == __constant_htonl(0x00000406))
211 +                               return (IPP2P_BIT * 100 + 63);
212 +                       break;
213 +               case 211:
214 +                       if (get_u32(haystack, 8) == __constant_htonl(0x00000405)) 
215 +                               return (IPP2P_BIT * 100 + 54);
216 +                       break;
217 +               case 29:
218 +                       if ((get_u32(haystack, 8) == __constant_htonl(0x00000401))) 
219 +                               return (IPP2P_BIT * 100 + 55);
220 +                       break;
221 +               case 52:
222 +                       if (get_u32(haystack,8)  == __constant_htonl(0x00000827) &&
223 +                       get_u32(haystack,12) == __constant_htonl(0x37502950))
224 +                               return (IPP2P_BIT * 100 + 80);
225 +                       break;
226 +               default:
227 +                       /* this packet does not have a constant size */
228 +                       if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) 
229 +                               return (IPP2P_BIT * 100 + 56);
230 +                       break;
231 +       }
232 +    
233 +       /* some extra-bitcomet rules:
234 +       * "d1:" [a|r] "d2:id20:"
235 +       */
236 +       if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
237 +       {
238 +               if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
239 +               {
240 +                       if (memcmp(haystack+12,"d2:id20:",8)==0)
241 +                               return (IPP2P_BIT * 100 + 57);
242 +               }
243 +       }
244 +    
245 +#if 0
246 +       /* bitlord rules */
247 +       /* packetlen must be bigger than 40 */
248 +       /* first 4 bytes are zero */
249 +       if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000)
250 +       {
251 +               /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/
252 +               if (get_u32(haystack, 12) == 0x00000000 && 
253 +                   get_u32(haystack, 16) == 0x00010000 &&
254 +                   get_u32(haystack, 24) == 0x00000000 )
255 +                       return (IPP2P_BIT * 100 + 71);
256 +                       
257 +               /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/
258 +               if (get_u32(haystack, 12) == 0x00000001 && 
259 +                   get_u32(haystack, 16) == 0x000d0000 &&
260 +                   get_u32(haystack, 24) == 0x00000000 )
261 +                       return (IPP2P_BIT * 100 + 71);
262 +               
263 +                   
264 +       }
265 +#endif
266 +
267 +    return 0;
268 +}/*udp_search_bit*/
269 +
270 +
271 +
272 +/*Search for Ares commands*/
273 +//#define IPP2P_DEBUG_ARES
274 +int
275 +search_ares (const unsigned char *payload, const u16 plen)
276 +//int search_ares (unsigned char *haystack, int packet_len, int head_len)
277 +{
278 +//     const unsigned char *t = haystack + head_len;
279 +       
280 +       /* all ares packets start with  */
281 +       if (payload[1] == 0 && (plen - payload[0]) == 3)
282 +       {
283 +               switch (payload[2])
284 +               {
285 +                       case 0x5a:
286 +                               /* ares connect */
287 +                               if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
288 +                               break;
289 +                       case 0x09:
290 +                               /* ares search, min 3 chars --> 14 bytes
291 +                                * lets define a search can be up to 30 chars --> max 34 bytes
292 +                                */
293 +                               if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
294 +                               break;
295 +#ifdef IPP2P_DEBUG_ARES
296 +                       default:
297 +                       printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
298 +#endif /* IPP2P_DEBUG_ARES */
299 +               }
300 +       }
301 +
302 +#if 0          
303 +       /* found connect packet: 03 00 5a 04 03 05 */
304 +       /* new version ares 1.8: 03 00 5a xx xx 05 */
305 +    if ((plen) == 6){  /* possible connect command*/
306 +       if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05))
307 +           return ((IPP2P_ARES * 100) + 1);
308 +    }
309 +    if ((plen) == 60){ /* possible download command*/
310 +       if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){
311 +           if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */
312 +               return ((IPP2P_ARES * 100) + 2);
313 +       }
314 +    }
315 +#endif
316 +
317 +    return 0;
318 +} /*search_ares*/
319 +
320 +/*Search for SoulSeek commands*/
321 +int
322 +search_soul (const unsigned char *payload, const u16 plen)
323 +{
324 +//#define IPP2P_DEBUG_SOUL
325 +    /* match: xx xx xx xx | xx = sizeof(payload) - 4 */
326 +    if (get_u32(payload, 0) == (plen - 4)){
327 +       const __u32 m=get_u32(payload, 4);
328 +       /* match 00 yy yy 00, yy can be everything */
329 +        if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 )
330 +       {
331 +#ifdef IPP2P_DEBUG_SOUL
332 +       printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4));
333 +#endif /* IPP2P_DEBUG_SOUL */
334 +               return ((IPP2P_SOUL * 100) + 1);
335 +       }
336 +       
337 +        /* next match: 01 yy 00 00 | yy can be everything */
338 +        if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
339 +       {
340 +#ifdef IPP2P_DEBUG_SOUL
341 +       printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
342 +#endif /* IPP2P_DEBUG_SOUL */
343 +               return ((IPP2P_SOUL * 100) + 2);
344 +       }
345 +       
346 +       /* other soulseek commandos are: 1-5,7,9,13-18,22,23,26,28,35-37,40-46,50,51,60,62-69,91,92,1001 */
347 +       /* try to do this in an intelligent way */
348 +       /* get all small commandos */
349 +       switch(m)
350 +       {
351 +               case 7:
352 +               case 9:
353 +               case 22:
354 +               case 23:
355 +               case 26:
356 +               case 28:
357 +               case 50:
358 +               case 51:
359 +               case 60:
360 +               case 91:
361 +               case 92:
362 +               case 1001:
363 +#ifdef IPP2P_DEBUG_SOUL
364 +               printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
365 +#endif /* IPP2P_DEBUG_SOUL */
366 +               return ((IPP2P_SOUL * 100) + 3);
367 +       }
368 +       
369 +       if (m > 0 && m < 6 ) 
370 +       {
371 +#ifdef IPP2P_DEBUG_SOUL
372 +               printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
373 +#endif /* IPP2P_DEBUG_SOUL */
374 +               return ((IPP2P_SOUL * 100) + 4);
375 +       }
376 +       if (m > 12 && m < 19 )
377 +       {
378 +#ifdef IPP2P_DEBUG_SOUL
379 +               printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
380 +#endif /* IPP2P_DEBUG_SOUL */
381 +               return ((IPP2P_SOUL * 100) + 5);
382 +       }
383 +
384 +       if (m > 34 && m < 38 )
385 +       {
386 +#ifdef IPP2P_DEBUG_SOUL
387 +               printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
388 +#endif /* IPP2P_DEBUG_SOUL */
389 +               return ((IPP2P_SOUL * 100) + 6);
390 +       }
391 +
392 +       if (m > 39 && m < 47 )
393 +       {
394 +#ifdef IPP2P_DEBUG_SOUL
395 +               printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
396 +#endif /* IPP2P_DEBUG_SOUL */
397 +               return ((IPP2P_SOUL * 100) + 7);
398 +       }
399 +
400 +       if (m > 61 && m < 70 ) 
401 +       {
402 +#ifdef IPP2P_DEBUG_SOUL
403 +               printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
404 +#endif /* IPP2P_DEBUG_SOUL */
405 +               return ((IPP2P_SOUL * 100) + 8);
406 +       }
407 +
408 +#ifdef IPP2P_DEBUG_SOUL
409 +       printk(KERN_DEBUG "unknown SOULSEEK command: 0x%x, first 16 bit: 0x%x, first 8 bit: 0x%x ,soulseek ???\n",get_u32(payload, 4),get_u16(payload, 4) >> 16,get_u8(payload, 4) >> 24);
410 +#endif /* IPP2P_DEBUG_SOUL */
411 +    }
412 +       
413 +       /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */
414 +       /* without size at the beginning !!! */
415 +       if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 )
416 +       {
417 +               __u32 y=get_u32(payload, 5);
418 +               /* we need 19 chars + string */
419 +               if ( (y + 19) <= (plen) )
420 +               {
421 +                       const unsigned char *w=payload+9+y;
422 +                       if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00);
423 +#ifdef IPP2P_DEBUG_SOUL
424 +                       printk(KERN_DEBUG "Soulssek special client command recognized\n");
425 +#endif /* IPP2P_DEBUG_SOUL */
426 +                       return ((IPP2P_SOUL * 100) + 9);
427 +               }
428 +       }
429 +    return 0;
430 +}
431 +
432 +
433 +/*Search for WinMX commands*/
434 +int
435 +search_winmx (const unsigned char *payload, const u16 plen)
436 +{
437 +//#define IPP2P_DEBUG_WINMX
438 +    if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0))  return ((IPP2P_WINMX * 100) + 1);
439 +    if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0))  return ((IPP2P_WINMX * 100) + 2);
440 +    //if (packet_len < (head_len + 10)) return 0;
441 +    if (plen < 10) return 0;
442 +    
443 +    if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
444 +        u16 c=4;
445 +        const u16 end=plen-2;
446 +        u8 count=0;
447 +        while (c < end)
448 +        {
449 +               if (payload[c]== 0x20 && payload[c+1] == 0x22)
450 +               {
451 +                       c++;
452 +                       count++;
453 +                       if (count>=2) return ((IPP2P_WINMX * 100) + 3);
454 +               }
455 +               c++;
456 +        }
457 +    }
458 +    
459 +    if ( plen == 149 && payload[0] == '8' )
460 +    {
461 +#ifdef IPP2P_DEBUG_WINMX
462 +       printk(KERN_INFO "maybe WinMX\n");
463 +#endif
464 +       if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
465 +//         get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
466 +//         get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
467 +           get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))
468 +           
469 +       {
470 +#ifdef IPP2P_DEBUG_WINMX
471 +               printk(KERN_INFO "got WinMX\n");
472 +#endif
473 +               return ((IPP2P_WINMX * 100) + 4);
474 +       }
475 +    }
476 +    return 0;
477 +} /*search_winmx*/
478 +
479 +
480 +/*Search for appleJuice commands*/
481 +int
482 +search_apple (const unsigned char *payload, const u16 plen)
483 +{
484 +    if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0))  return (IPP2P_APPLE * 100);
485 +    
486 +    return 0;
487 +}
488 +
489 +
490 +/*Search for BitTorrent commands*/
491 +int
492 +search_bittorrent (const unsigned char *payload, const u16 plen)
493 +{
494 +    if (plen > 20)
495 +    {
496 +       /* test for match 0x13+"BitTorrent protocol" */
497 +       if (payload[0] == 0x13) 
498 +       {
499 +               if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
500 +       }
501 +       
502 +       /* get tracker commandos, all starts with GET /
503 +       * then it can follow: scrape| announce
504 +       * and then ?hash_info=
505 +       */
506 +       if (memcmp(payload,"GET /",5) == 0)
507 +       {
508 +               /* message scrape */
509 +               if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1);
510 +               /* message announce */
511 +               if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2);
512 +       }
513 +    } 
514 +    else 
515 +    {
516 +       /* bitcomet encryptes the first packet, so we have to detect another 
517 +        * one later in the flow */
518 +        /* first try failed, too many missdetections */
519 +       //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3);
520 +       
521 +       /* second try: block request packets */
522 +       if ( plen == 17 && get_u32(payload,0) == __constant_htonl(0x0d) && payload[4] == 0x06 && get_u32(payload,13) == __constant_htonl(0x4000) ) return (IPP2P_BIT * 100 + 3);
523 +    }
524 +
525 +    return 0;
526 +}
527 +
528 +
529 +
530 +/*check for Kazaa get command*/
531 +int
532 +search_kazaa (const unsigned char *payload, const u16 plen)
533 +
534 +{
535 +    if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
536 +       return (IPP2P_DATA_KAZAA * 100);
537 +
538 +    return 0;
539 +}
540 +
541 +
542 +/*check for gnutella get command*/
543 +int
544 +search_gnu (const unsigned char *payload, const u16 plen)
545 +{
546 +    if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
547 +    {
548 +       if (memcmp(payload, "GET /get/", 9) == 0)       return ((IPP2P_DATA_GNU * 100) + 1);
549 +       if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2); 
550 +    }
551 +    return 0;
552 +}
553 +
554 +
555 +/*check for gnutella get commands and other typical data*/
556 +int
557 +search_all_gnu (const unsigned char *payload, const u16 plen)
558 +{
559 +    
560 +    if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
561 +    {
562 +       
563 +       if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1);
564 +       if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2);    
565 +    
566 +    
567 +       if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
568 +       {        
569 +               u16 c=8;
570 +               const u16 end=plen-22;
571 +               while (c < end) {
572 +                       if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0))) 
573 +                               return ((IPP2P_GNU * 100) + 3);
574 +                       c++;
575 +               }
576 +       }
577 +    }
578 +    return 0;
579 +}
580 +
581 +
582 +/*check for KaZaA download commands and other typical data*/
583 +int
584 +search_all_kazaa (const unsigned char *payload, const u16 plen)
585 +{
586 +    if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
587 +    {
588 +
589 +       if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
590 +    
591 +       if (memcmp(payload, "GET /", 5) == 0) {
592 +               u16 c = 8;
593 +               const u16 end=plen-22;
594 +               while (c < end) {
595 +                       if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Kazaa-Username: ", 18) == 0) || (memcmp(&payload[c+2], "User-Agent: PeerEnabler/", 24) == 0)))
596 +                               return ((IPP2P_KAZAA * 100) + 2);
597 +                       c++;
598 +               }
599 +       }
600 +    }
601 +    return 0;
602 +}
603 +
604 +/*fast check for edonkey file segment transfer command*/
605 +int
606 +search_edk (const unsigned char *payload, const u16 plen)
607 +{
608 +    if (payload[0] != 0xe3) 
609 +       return 0;
610 +    else {
611 +       if (payload[5] == 0x47) 
612 +           return (IPP2P_DATA_EDK * 100);
613 +       else    
614 +           return 0;
615 +    }
616 +}
617 +
618 +
619 +
620 +/*intensive but slower search for some edonkey packets including size-check*/
621 +int
622 +search_all_edk (const unsigned char *payload, const u16 plen)
623 +{
624 +    if (payload[0] != 0xe3) 
625 +       return 0;
626 +    else {
627 +       //t += head_len;        
628 +       const u16 cmd = get_u16(payload, 1);
629 +       if (cmd == (plen - 5)) {
630 +           switch (payload[5]) {
631 +               case 0x01: return ((IPP2P_EDK * 100) + 1);      /*Client: hello or Server:hello*/
632 +               case 0x4c: return ((IPP2P_EDK * 100) + 9);      /*Client: Hello-Answer*/
633 +           }
634 +       }
635 +       return 0;
636 +     }
637 +}
638 +
639 +
640 +/*fast check for Direct Connect send command*/
641 +int
642 +search_dc (const unsigned char *payload, const u16 plen)
643 +{
644 +
645 +    if (payload[0] != 0x24 ) 
646 +       return 0;
647 +    else {
648 +       if (memcmp(&payload[1], "Send|", 5) == 0)
649 +           return (IPP2P_DATA_DC * 100);
650 +       else
651 +           return 0;
652 +    }  
653 +
654 +}
655 +
656 +
657 +/*intensive but slower check for all direct connect packets*/
658 +int
659 +search_all_dc (const unsigned char *payload, const u16 plen)
660 +{
661 +//    unsigned char *t = haystack;
662 +
663 +    if (payload[0] == 0x24 && payload[plen-1] == 0x7c) 
664 +    {
665 +       const unsigned char *t=&payload[1];
666 +               /* Client-Hub-Protocol */
667 +       if (memcmp(t, "Lock ", 5) == 0)                 return ((IPP2P_DC * 100) + 1);
668 +       /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */
669 +       if (memcmp(t, "MyNick ", 7) == 0)               return ((IPP2P_DC * 100) + 38); 
670 +    }
671 +    return 0;
672 +}
673 +
674 +/*check for mute*/
675 +int
676 +search_mute (const unsigned char *payload, const u16 plen)
677 +{
678 +       if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
679 +       {
680 +               //printk(KERN_DEBUG "size hit: %u",size);
681 +               if (memcmp(payload,"PublicKey: ",11) == 0 )
682 +               { 
683 +                       return ((IPP2P_MUTE * 100) + 0);
684 +                       
685 +/*                     if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
686 +                       {
687 +                               printk(KERN_DEBUG "end pubic key hit: %u",size);
688 +                               
689 +                       }*/
690 +               }
691 +       }
692 +       return 0;
693 +}
694 +
695 +
696 +/* check for xdcc */
697 +int
698 +search_xdcc (const unsigned char *payload, const u16 plen)
699 +{
700 +       /* search in small packets only */
701 +       if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0)
702 +       {
703 +               
704 +               u16 x=10;
705 +               const u16 end=plen - 13;
706 +               
707 +               /* is seems to be a irc private massage, chedck for xdcc command */
708 +               while (x < end)
709 +               {
710 +                       if (payload[x] == ':')
711 +                       {
712 +                               if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
713 +                                       return ((IPP2P_XDCC * 100) + 0);
714 +                       }
715 +                       x++;
716 +               }
717 +       }
718 +       return 0;
719 +}
720 +
721 +/* search for waste */
722 +int search_waste(const unsigned char *payload, const u16 plen)
723 +{
724 +       if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
725 +               return ((IPP2P_WASTE * 100) + 0);
726 +
727 +       return 0;
728 +}
729 +
730 +
731 +static struct {
732 +    int command;
733 +    __u8 short_hand;                   /*for fucntions included in short hands*/
734 +    int packet_len;
735 +    int (*function_name) (const unsigned char *, const u16);
736 +} matchlist[] = {
737 +    {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk},
738 +//    {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa},
739 +//    {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk},
740 +//    {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc},
741 +    {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc},
742 +//    {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu},
743 +    {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu},
744 +    {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa},
745 +    {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent},
746 +    {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple},
747 +    {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul},
748 +    {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx},
749 +    {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares},
750 +    {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute},
751 +    {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste},
752 +    {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc},
753 +    {0,0,0,NULL}
754 +};
755 +
756 +
757 +static struct {
758 +    int command;
759 +    __u8 short_hand;                   /*for fucntions included in short hands*/
760 +    int packet_len;
761 +    int (*function_name) (unsigned char *, int);
762 +} udp_list[] = {
763 +    {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa},
764 +    {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit},
765 +    {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu},
766 +    {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk},
767 +    {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect},    
768 +    {0,0,0,NULL}
769 +};
770 +
771 +
772 +static int
773 +match(const struct sk_buff *skb,
774 +      const struct net_device *in,
775 +      const struct net_device *out,
776 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
777 +      const struct xt_match *match,
778 +#endif
779 +      const void *matchinfo,
780 +      int offset,
781 +
782 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
783 +      const void *hdr,
784 +      u_int16_t datalen,
785 +#endif
786 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
787 +      unsigned int protoff,
788 +#endif
789 +
790 +      int *hotdrop)
791 +{
792 +    const struct ipt_p2p_info *info = matchinfo;
793 +    unsigned char  *haystack;
794 +    struct iphdr *ip = skb->nh.iph;
795 +    int p2p_result = 0, i = 0;
796 +//    int head_len;
797 +    int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
798 +
799 +    /*must not be a fragment*/
800 +    if (offset) {
801 +       if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
802 +       return 0;
803 +    }
804 +    
805 +    /*make sure that skb is linear*/
806 +    if(skb_is_nonlinear(skb)){
807 +       if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
808 +       return 0;
809 +    }
810 +
811 +
812 +    haystack=(char *)ip+(ip->ihl*4);           /*haystack = packet data*/
813 +
814 +    switch (ip->protocol){
815 +       case IPPROTO_TCP:               /*what to do with a TCP packet*/
816 +       {
817 +           struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
818 +           
819 +           if (tcph->fin) return 0;  /*if FIN bit is set bail out*/
820 +           if (tcph->syn) return 0;  /*if SYN bit is set bail out*/
821 +           if (tcph->rst) return 0;  /*if RST bit is set bail out*/
822 +           
823 +           haystack += tcph->doff * 4; /*get TCP-Header-Size*/
824 +           hlen -= tcph->doff * 4;
825 +           while (matchlist[i].command) {
826 +               if ((((info->cmd & matchlist[i].command) == matchlist[i].command) ||
827 +                   ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) &&
828 +                   (hlen > matchlist[i].packet_len)) {
829 +                           p2p_result = matchlist[i].function_name(haystack, hlen);
830 +                           if (p2p_result) 
831 +                           {
832 +                               if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", 
833 +                                   p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen);
834 +                               return p2p_result;
835 +                           }
836 +               }
837 +           i++;
838 +           }
839 +           return p2p_result;
840 +       }
841 +       
842 +       case IPPROTO_UDP:               /*what to do with an UDP packet*/
843 +       {
844 +           struct udphdr *udph = (void *) ip + ip->ihl * 4;
845 +           
846 +           while (udp_list[i].command){
847 +               if ((((info->cmd & udp_list[i].command) == udp_list[i].command) ||
848 +                   ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) &&
849 +                   (hlen > udp_list[i].packet_len)) {
850 +                           p2p_result = udp_list[i].function_name(haystack, hlen);
851 +                           if (p2p_result){
852 +                               if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", 
853 +                                   p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen);
854 +                               return p2p_result;
855 +                           }
856 +               }
857 +           i++;
858 +           }                   
859 +           return p2p_result;
860 +       }
861 +    
862 +       default: return 0;
863 +    }
864 +}
865 +
866 +
867 +
868 +static int
869 +checkentry(const char *tablename,
870 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
871 +            const void *ip,
872 +#else
873 +            const struct ipt_ip *ip,
874 +#endif
875 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
876 +            const struct xt_match *match,
877 +#endif
878 +           void *matchinfo,
879 +           unsigned int matchsize,
880 +           unsigned int hook_mask)
881 +{
882 +        /* Must specify -p tcp */
883 +/*    if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
884 + *     printk("ipp2p: Only works on TCP packets, use -p tcp\n");
885 + *     return 0;
886 + *    }*/
887 +    return 1;
888 +}
889 +                                                                           
890 +
891 +
892 +
893 +static struct ipt_match ipp2p_match = { 
894 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
895 +       { NULL, NULL }, 
896 +       "ipp2p", 
897 +       &match, 
898 +       &checkentry, 
899 +       NULL, 
900 +       THIS_MODULE
901 +#endif
902 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
903 +       .name           = "ipp2p",
904 +       .match          = &match,
905 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
906 +       .matchsize      = sizeof(struct ipt_p2p_info),
907 +#endif
908 +       .checkentry     = &checkentry,
909 +       .me             = THIS_MODULE,
910 +#endif
911 +};
912 +
913 +
914 +static int __init init(void)
915 +{
916 +    printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
917 +    return ipt_register_match(&ipp2p_match);
918 +}
919 +       
920 +static void __exit fini(void)
921 +{
922 +    ipt_unregister_match(&ipp2p_match);
923 +    printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);    
924 +}
925 +       
926 +module_init(init);
927 +module_exit(fini);
928 +
929 +
930 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Kconfig linux/net/ipv4/netfilter/Kconfig
931 --- linux.org/net/ipv4/netfilter/Kconfig        2006-06-18 01:49:35.000000000 +0000
932 +++ linux/net/ipv4/netfilter/Kconfig    2006-08-29 12:35:07.000000000 +0000
933 @@ -613,5 +613,15 @@
934           Allows altering the ARP packet payload: source and destination
935           hardware and network addresses.
936  
937 +config IP_NF_MATCH_IPP2P
938 +       tristate  'IPP2P match support'
939 +       depends on IP_NF_IPTABLES
940 +       help
941 +         This option makes possible to match some P2P packets
942 +         therefore helps controlling such traffic.
943 +       
944 +         If you want to compile it as a module, say M here and read
945 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
946 +
947  endmenu
948  
949 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Makefile linux/net/ipv4/netfilter/Makefile
950 --- linux.org/net/ipv4/netfilter/Makefile       2006-06-18 01:49:35.000000000 +0000
951 +++ linux/net/ipv4/netfilter/Makefile   2006-08-29 12:35:07.000000000 +0000
952 @@ -0,0 +0,1 @@
953 +obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
This page took 0.111698 seconds and 3 git commands to generate.