1 Index: linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_ipp2p.h
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.4.35.4/include/linux/netfilter_ipv4/ipt_ipp2p.h 2007-12-15 05:20:05.756168270 +0100
8 +#define IPP2P_VERSION "0.8.1_rc1"
10 +struct ipt_p2p_info {
15 +#endif //__IPT_IPP2P_H
17 +#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/
18 +//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/
19 +#define SHORT_HAND_NONE 5 /* no short hand*/
21 +#define IPP2P_EDK (1 << 1)
22 +#define IPP2P_DATA_KAZAA (1 << 2)
23 +#define IPP2P_DATA_EDK (1 << 3)
24 +#define IPP2P_DATA_DC (1 << 4)
25 +#define IPP2P_DC (1 << 5)
26 +#define IPP2P_DATA_GNU (1 << 6)
27 +#define IPP2P_GNU (1 << 7)
28 +#define IPP2P_KAZAA (1 << 8)
29 +#define IPP2P_BIT (1 << 9)
30 +#define IPP2P_APPLE (1 << 10)
31 +#define IPP2P_SOUL (1 << 11)
32 +#define IPP2P_WINMX (1 << 12)
33 +#define IPP2P_ARES (1 << 13)
34 +#define IPP2P_MUTE (1 << 14)
35 +#define IPP2P_WASTE (1 << 15)
36 +#define IPP2P_XDCC (1 << 16)
37 Index: linux-2.4.35.4/net/ipv4/netfilter/Config.in
38 ===================================================================
39 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Config.in 2007-12-15 05:19:38.466613124 +0100
40 +++ linux-2.4.35.4/net/ipv4/netfilter/Config.in 2007-12-15 05:20:05.764168722 +0100
42 dep_tristate ' TOS match support' CONFIG_IP_NF_MATCH_TOS $CONFIG_IP_NF_IPTABLES
43 dep_tristate ' recent match support' CONFIG_IP_NF_MATCH_RECENT $CONFIG_IP_NF_IPTABLES
44 dep_tristate ' ECN match support' CONFIG_IP_NF_MATCH_ECN $CONFIG_IP_NF_IPTABLES
45 + dep_tristate ' peer to peer traffic match support' CONFIG_IP_NF_MATCH_IPP2P $CONFIG_IP_NF_IPTABLES
47 dep_tristate ' DSCP match support' CONFIG_IP_NF_MATCH_DSCP $CONFIG_IP_NF_IPTABLES
49 Index: linux-2.4.35.4/net/ipv4/netfilter/Makefile
50 ===================================================================
51 --- linux-2.4.35.4.orig/net/ipv4/netfilter/Makefile 2007-12-15 05:19:38.474613582 +0100
52 +++ linux-2.4.35.4/net/ipv4/netfilter/Makefile 2007-12-15 05:20:05.764168722 +0100
54 obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
55 obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
56 obj-$(CONFIG_IP_NF_MATCH_MAC) += ipt_mac.o
57 +obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
59 obj-$(CONFIG_IP_NF_MATCH_PKTTYPE) += ipt_pkttype.o
60 obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
61 Index: linux-2.4.35.4/net/ipv4/netfilter/ipt_ipp2p.c
62 ===================================================================
63 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
64 +++ linux-2.4.35.4/net/ipv4/netfilter/ipt_ipp2p.c 2007-12-15 05:20:05.764168722 +0100
66 +#if defined(MODVERSIONS)
67 +#include <linux/modversions.h>
69 +#include <linux/module.h>
70 +#include <linux/netfilter_ipv4/ip_tables.h>
71 +#include <linux/version.h>
72 +#include <linux/netfilter_ipv4/ipt_ipp2p.h>
76 +#define get_u8(X,O) (*(__u8 *)(X + O))
77 +#define get_u16(X,O) (*(__u16 *)(X + O))
78 +#define get_u32(X,O) (*(__u32 *)(X + O))
80 +MODULE_AUTHOR("Eicke Friedrich/Klaus Degner <ipp2p@ipp2p.org>");
81 +MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic.");
82 +MODULE_LICENSE("GPL");
85 +/*Search for UDP eDonkey/eMule/Kad commands*/
87 +udp_search_edk (unsigned char *haystack, int packet_len)
89 + unsigned char *t = haystack;
97 + /* client -> server status request */
99 + if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
101 + /* server -> client status request */
102 + case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
104 + /* server description request */
105 + /* e3 2a ff f0 .. | size == 6 */
106 + case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52);
108 + /* server description response */
109 + /* e3 a3 ff f0 .. | size > 40 && size < 200 */
110 + //case 0xa3: return ((IPP2P_EDK * 100) + 53);
112 + case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
115 + case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
124 + /* e4 20 .. | size == 43 */
125 + case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
127 + /* e4 00 .. 00 | size == 35 ? */
128 + case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
130 + /* e4 10 .. 00 | size == 35 ? */
131 + case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
133 + /* e4 18 .. 00 | size == 35 ? */
134 + case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
136 + /* e4 52 .. | size = 44 */
137 + case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
139 + /* e4 58 .. | size == 6 */
140 + case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
142 + /* e4 59 .. | size == 2 */
143 + case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
145 + /* e4 28 .. | packet_len == 52,77,102,127... */
146 + case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
148 + /* e4 50 xx xx | size == 4 */
149 + case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
151 + /* e4 40 xx xx | size == 48 */
152 + case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
157 + } /* end of switch (t[0]) */
162 +/*Search for UDP Gnutella commands*/
164 +udp_search_gnu (unsigned char *haystack, int packet_len)
166 + unsigned char *t = haystack;
169 + if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
170 + if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
175 +/*Search for UDP KaZaA commands*/
177 +udp_search_kazaa (unsigned char *haystack, int packet_len)
179 + unsigned char *t = haystack;
181 + if (t[packet_len-1] == 0x00){
182 + t += (packet_len - 6);
183 + if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
187 +}/*udp_search_kazaa*/
189 +/*Search for UDP DirectConnect commands*/
191 +udp_search_directconnect (unsigned char *haystack, int packet_len)
193 + unsigned char *t = haystack;
194 + if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
196 + if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60);
197 + if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61);
200 +}/*udp_search_directconnect*/
204 +/*Search for UDP BitTorrent commands*/
206 +udp_search_bit (unsigned char *haystack, int packet_len)
211 + /* ^ 00 00 04 17 27 10 19 80 */
212 + if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980))
213 + return (IPP2P_BIT * 100 + 50);
216 + if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
217 + return (IPP2P_BIT * 100 + 51);
218 + if (get_u32(haystack, 16) == __constant_htonl(0x00000400))
219 + return (IPP2P_BIT * 100 + 61);
222 + if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
223 + return (IPP2P_BIT * 100 + 52);
224 + if (get_u32(haystack, 16) == __constant_htonl(0x00000404))
225 + return (IPP2P_BIT * 100 + 62);
228 + if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
229 + return (IPP2P_BIT * 100 + 53);
230 + if (get_u32(haystack, 16) == __constant_htonl(0x00000406))
231 + return (IPP2P_BIT * 100 + 63);
234 + if (get_u32(haystack, 8) == __constant_htonl(0x00000405))
235 + return (IPP2P_BIT * 100 + 54);
238 + if ((get_u32(haystack, 8) == __constant_htonl(0x00000401)))
239 + return (IPP2P_BIT * 100 + 55);
242 + if (get_u32(haystack,8) == __constant_htonl(0x00000827) &&
243 + get_u32(haystack,12) == __constant_htonl(0x37502950))
244 + return (IPP2P_BIT * 100 + 80);
247 + /* this packet does not have a constant size */
248 + if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
249 + return (IPP2P_BIT * 100 + 56);
253 + /* some extra-bitcomet rules:
254 + * "d1:" [a|r] "d2:id20:"
256 + if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
258 + if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
260 + if (memcmp(haystack+12,"d2:id20:",8)==0)
261 + return (IPP2P_BIT * 100 + 57);
266 + /* bitlord rules */
267 + /* packetlen must be bigger than 40 */
268 + /* first 4 bytes are zero */
269 + if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000)
271 + /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/
272 + if (get_u32(haystack, 12) == 0x00000000 &&
273 + get_u32(haystack, 16) == 0x00010000 &&
274 + get_u32(haystack, 24) == 0x00000000 )
275 + return (IPP2P_BIT * 100 + 71);
277 + /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/
278 + if (get_u32(haystack, 12) == 0x00000001 &&
279 + get_u32(haystack, 16) == 0x000d0000 &&
280 + get_u32(haystack, 24) == 0x00000000 )
281 + return (IPP2P_BIT * 100 + 71);
292 +/*Search for Ares commands*/
293 +//#define IPP2P_DEBUG_ARES
295 +search_ares (const unsigned char *payload, const u16 plen)
296 +//int search_ares (unsigned char *haystack, int packet_len, int head_len)
298 +// const unsigned char *t = haystack + head_len;
300 + /* all ares packets start with */
301 + if (payload[1] == 0 && (plen - payload[0]) == 3)
303 + switch (payload[2])
307 + if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
310 + /* ares search, min 3 chars --> 14 bytes
311 + * lets define a search can be up to 30 chars --> max 34 bytes
313 + if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
315 +#ifdef IPP2P_DEBUG_ARES
317 + printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
318 +#endif /* IPP2P_DEBUG_ARES */
323 + /* found connect packet: 03 00 5a 04 03 05 */
324 + /* new version ares 1.8: 03 00 5a xx xx 05 */
325 + if ((plen) == 6){ /* possible connect command*/
326 + if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05))
327 + return ((IPP2P_ARES * 100) + 1);
329 + if ((plen) == 60){ /* possible download command*/
330 + if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){
331 + if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */
332 + return ((IPP2P_ARES * 100) + 2);
340 +/*Search for SoulSeek commands*/
342 +search_soul (const unsigned char *payload, const u16 plen)
344 +//#define IPP2P_DEBUG_SOUL
345 + /* match: xx xx xx xx | xx = sizeof(payload) - 4 */
346 + if (get_u32(payload, 0) == (plen - 4)){
347 + const __u32 m=get_u32(payload, 4);
348 + /* match 00 yy yy 00, yy can be everything */
349 + if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 )
351 +#ifdef IPP2P_DEBUG_SOUL
352 + printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4));
353 +#endif /* IPP2P_DEBUG_SOUL */
354 + return ((IPP2P_SOUL * 100) + 1);
357 + /* next match: 01 yy 00 00 | yy can be everything */
358 + if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
360 +#ifdef IPP2P_DEBUG_SOUL
361 + printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
362 +#endif /* IPP2P_DEBUG_SOUL */
363 + return ((IPP2P_SOUL * 100) + 2);
366 + /* 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 */
367 + /* try to do this in an intelligent way */
368 + /* get all small commandos */
383 +#ifdef IPP2P_DEBUG_SOUL
384 + printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
385 +#endif /* IPP2P_DEBUG_SOUL */
386 + return ((IPP2P_SOUL * 100) + 3);
389 + if (m > 0 && m < 6 )
391 +#ifdef IPP2P_DEBUG_SOUL
392 + printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
393 +#endif /* IPP2P_DEBUG_SOUL */
394 + return ((IPP2P_SOUL * 100) + 4);
396 + if (m > 12 && m < 19 )
398 +#ifdef IPP2P_DEBUG_SOUL
399 + printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
400 +#endif /* IPP2P_DEBUG_SOUL */
401 + return ((IPP2P_SOUL * 100) + 5);
404 + if (m > 34 && m < 38 )
406 +#ifdef IPP2P_DEBUG_SOUL
407 + printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
408 +#endif /* IPP2P_DEBUG_SOUL */
409 + return ((IPP2P_SOUL * 100) + 6);
412 + if (m > 39 && m < 47 )
414 +#ifdef IPP2P_DEBUG_SOUL
415 + printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
416 +#endif /* IPP2P_DEBUG_SOUL */
417 + return ((IPP2P_SOUL * 100) + 7);
420 + if (m > 61 && m < 70 )
422 +#ifdef IPP2P_DEBUG_SOUL
423 + printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
424 +#endif /* IPP2P_DEBUG_SOUL */
425 + return ((IPP2P_SOUL * 100) + 8);
428 +#ifdef IPP2P_DEBUG_SOUL
429 + 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);
430 +#endif /* IPP2P_DEBUG_SOUL */
433 + /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */
434 + /* without size at the beginning !!! */
435 + if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 )
437 + __u32 y=get_u32(payload, 5);
438 + /* we need 19 chars + string */
439 + if ( (y + 19) <= (plen) )
441 + const unsigned char *w=payload+9+y;
442 + if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00);
443 +#ifdef IPP2P_DEBUG_SOUL
444 + printk(KERN_DEBUG "Soulssek special client command recognized\n");
445 +#endif /* IPP2P_DEBUG_SOUL */
446 + return ((IPP2P_SOUL * 100) + 9);
453 +/*Search for WinMX commands*/
455 +search_winmx (const unsigned char *payload, const u16 plen)
457 +//#define IPP2P_DEBUG_WINMX
458 + if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1);
459 + if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2);
460 + //if (packet_len < (head_len + 10)) return 0;
461 + if (plen < 10) return 0;
463 + if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
465 + const u16 end=plen-2;
469 + if (payload[c]== 0x20 && payload[c+1] == 0x22)
473 + if (count>=2) return ((IPP2P_WINMX * 100) + 3);
479 + if ( plen == 149 && payload[0] == '8' )
481 +#ifdef IPP2P_DEBUG_WINMX
482 + printk(KERN_INFO "maybe WinMX\n");
484 + if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
485 +// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
486 +// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
487 + get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))
490 +#ifdef IPP2P_DEBUG_WINMX
491 + printk(KERN_INFO "got WinMX\n");
493 + return ((IPP2P_WINMX * 100) + 4);
500 +/*Search for appleJuice commands*/
502 +search_apple (const unsigned char *payload, const u16 plen)
504 + if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100);
510 +/*Search for BitTorrent commands*/
512 +search_bittorrent (const unsigned char *payload, const u16 plen)
516 + /* test for match 0x13+"BitTorrent protocol" */
517 + if (payload[0] == 0x13)
519 + if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
522 + /* get tracker commandos, all starts with GET /
523 + * then it can follow: scrape| announce
524 + * and then ?hash_info=
526 + if (memcmp(payload,"GET /",5) == 0)
528 + /* message scrape */
529 + if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1);
530 + /* message announce */
531 + if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2);
536 + /* bitcomet encryptes the first packet, so we have to detect another
537 + * one later in the flow */
538 + /* first try failed, too many missdetections */
539 + //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3);
541 + /* second try: block request packets */
542 + 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);
550 +/*check for Kazaa get command*/
552 +search_kazaa (const unsigned char *payload, const u16 plen)
555 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
556 + return (IPP2P_DATA_KAZAA * 100);
562 +/*check for gnutella get command*/
564 +search_gnu (const unsigned char *payload, const u16 plen)
566 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
568 + if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1);
569 + if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2);
575 +/*check for gnutella get commands and other typical data*/
577 +search_all_gnu (const unsigned char *payload, const u16 plen)
580 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
583 + if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1);
584 + if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2);
587 + if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
590 + const u16 end=plen-22;
592 + if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0)))
593 + return ((IPP2P_GNU * 100) + 3);
602 +/*check for KaZaA download commands and other typical data*/
604 +search_all_kazaa (const unsigned char *payload, const u16 plen)
606 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
609 + if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
611 + if (memcmp(payload, "GET /", 5) == 0) {
613 + const u16 end=plen-22;
615 + 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)))
616 + return ((IPP2P_KAZAA * 100) + 2);
624 +/*fast check for edonkey file segment transfer command*/
626 +search_edk (const unsigned char *payload, const u16 plen)
628 + if (payload[0] != 0xe3)
631 + if (payload[5] == 0x47)
632 + return (IPP2P_DATA_EDK * 100);
640 +/*intensive but slower search for some edonkey packets including size-check*/
642 +search_all_edk (const unsigned char *payload, const u16 plen)
644 + if (payload[0] != 0xe3)
648 + const u16 cmd = get_u16(payload, 1);
649 + if (cmd == (plen - 5)) {
650 + switch (payload[5]) {
651 + case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/
652 + case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/
660 +/*fast check for Direct Connect send command*/
662 +search_dc (const unsigned char *payload, const u16 plen)
665 + if (payload[0] != 0x24 )
668 + if (memcmp(&payload[1], "Send|", 5) == 0)
669 + return (IPP2P_DATA_DC * 100);
677 +/*intensive but slower check for all direct connect packets*/
679 +search_all_dc (const unsigned char *payload, const u16 plen)
681 +// unsigned char *t = haystack;
683 + if (payload[0] == 0x24 && payload[plen-1] == 0x7c)
685 + const unsigned char *t=&payload[1];
686 + /* Client-Hub-Protocol */
687 + if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1);
688 + /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */
689 + if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38);
696 +search_mute (const unsigned char *payload, const u16 plen)
698 + if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
700 + //printk(KERN_DEBUG "size hit: %u",size);
701 + if (memcmp(payload,"PublicKey: ",11) == 0 )
703 + return ((IPP2P_MUTE * 100) + 0);
705 +/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
707 + printk(KERN_DEBUG "end pubic key hit: %u",size);
716 +/* check for xdcc */
718 +search_xdcc (const unsigned char *payload, const u16 plen)
720 + /* search in small packets only */
721 + if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0)
725 + const u16 end=plen - 13;
727 + /* is seems to be a irc private massage, chedck for xdcc command */
730 + if (payload[x] == ':')
732 + if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
733 + return ((IPP2P_XDCC * 100) + 0);
741 +/* search for waste */
742 +int search_waste(const unsigned char *payload, const u16 plen)
744 + if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
745 + return ((IPP2P_WASTE * 100) + 0);
753 + __u8 short_hand; /*for fucntions included in short hands*/
755 + int (*function_name) (const unsigned char *, const u16);
757 + {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk},
758 +// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa},
759 +// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk},
760 +// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc},
761 + {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc},
762 +// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu},
763 + {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu},
764 + {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa},
765 + {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent},
766 + {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple},
767 + {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul},
768 + {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx},
769 + {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares},
770 + {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute},
771 + {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste},
772 + {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc},
779 + __u8 short_hand; /*for fucntions included in short hands*/
781 + int (*function_name) (unsigned char *, int);
783 + {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa},
784 + {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit},
785 + {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu},
786 + {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk},
787 + {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect},
793 +match(const struct sk_buff *skb,
794 + const struct net_device *in,
795 + const struct net_device *out,
796 + const void *matchinfo,
799 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
806 + const struct ipt_p2p_info *info = matchinfo;
807 + unsigned char *haystack;
808 + struct iphdr *ip = skb->nh.iph;
809 + int p2p_result = 0, i = 0;
811 + int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
813 + /*must not be a fragment*/
815 + if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
819 + /*make sure that skb is linear*/
820 + if(skb_is_nonlinear(skb)){
821 + if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
826 + haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/
828 + switch (ip->protocol){
829 + case IPPROTO_TCP: /*what to do with a TCP packet*/
831 + struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
833 + if (tcph->fin) return 0; /*if FIN bit is set bail out*/
834 + if (tcph->syn) return 0; /*if SYN bit is set bail out*/
835 + if (tcph->rst) return 0; /*if RST bit is set bail out*/
837 + haystack += tcph->doff * 4; /*get TCP-Header-Size*/
838 + hlen -= tcph->doff * 4;
839 + while (matchlist[i].command) {
840 + if ((((info->cmd & matchlist[i].command) == matchlist[i].command) ||
841 + ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) &&
842 + (hlen > matchlist[i].packet_len)) {
843 + p2p_result = matchlist[i].function_name(haystack, hlen);
846 + if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
847 + p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen);
856 + case IPPROTO_UDP: /*what to do with an UDP packet*/
858 + struct udphdr *udph = (void *) ip + ip->ihl * 4;
860 + while (udp_list[i].command){
861 + if ((((info->cmd & udp_list[i].command) == udp_list[i].command) ||
862 + ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) &&
863 + (hlen > udp_list[i].packet_len)) {
864 + p2p_result = udp_list[i].function_name(haystack, hlen);
866 + if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
867 + p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen);
883 +checkentry(const char *tablename,
884 + const struct ipt_ip *ip,
886 + unsigned int matchsize,
887 + unsigned int hook_mask)
889 + /* Must specify -p tcp */
890 +/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
891 + * printk("ipp2p: Only works on TCP packets, use -p tcp\n");
900 +static struct ipt_match ipp2p_match = {
901 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
909 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
912 + .checkentry = &checkentry,
918 +static int __init init(void)
920 + printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
921 + return ipt_register_match(&ipp2p_match);
924 +static void __exit fini(void)
926 + ipt_unregister_match(&ipp2p_match);
927 + printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);