1 diff -urN linux.old/include/linux/netfilter_ipv4/ipt_ipp2p.h linux.dev/include/linux/netfilter_ipv4/ipt_ipp2p.h
2 --- linux.old/include/linux/netfilter_ipv4/ipt_ipp2p.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux.dev/include/linux/netfilter_ipv4/ipt_ipp2p.h 2006-03-23 15:24:47.000000000 +0100
7 +#define IPP2P_VERSION "0.8.1_rc1"
14 +#endif //__IPT_IPP2P_H
16 +#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/
17 +//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/
18 +#define SHORT_HAND_NONE 5 /* no short hand*/
20 +#define IPP2P_EDK (1 << 1)
21 +#define IPP2P_DATA_KAZAA (1 << 2)
22 +#define IPP2P_DATA_EDK (1 << 3)
23 +#define IPP2P_DATA_DC (1 << 4)
24 +#define IPP2P_DC (1 << 5)
25 +#define IPP2P_DATA_GNU (1 << 6)
26 +#define IPP2P_GNU (1 << 7)
27 +#define IPP2P_KAZAA (1 << 8)
28 +#define IPP2P_BIT (1 << 9)
29 +#define IPP2P_APPLE (1 << 10)
30 +#define IPP2P_SOUL (1 << 11)
31 +#define IPP2P_WINMX (1 << 12)
32 +#define IPP2P_ARES (1 << 13)
33 +#define IPP2P_MUTE (1 << 14)
34 +#define IPP2P_WASTE (1 << 15)
35 +#define IPP2P_XDCC (1 << 16)
36 diff -urN linux.old/net/ipv4/netfilter/Kconfig linux.dev/net/ipv4/netfilter/Kconfig
37 --- linux.old/net/ipv4/netfilter/Kconfig 2006-03-23 15:21:19.000000000 +0100
38 +++ linux.dev/net/ipv4/netfilter/Kconfig 2006-03-23 15:26:29.000000000 +0100
41 To compile it as a module, choose M here. If unsure, say N.
43 +config IP_NF_MATCH_IPP2P
45 + depends on IP_NF_IPTABLES
47 + Module for matching traffic of various Peer-to-Peer applications
49 config IP_NF_MATCH_TOS
50 tristate "TOS match support"
51 depends on IP_NF_IPTABLES
52 diff -urN linux.old/net/ipv4/netfilter/Makefile linux.dev/net/ipv4/netfilter/Makefile
53 --- linux.old/net/ipv4/netfilter/Makefile 2006-03-23 15:21:19.000000000 +0100
54 +++ linux.dev/net/ipv4/netfilter/Makefile 2006-03-23 15:27:00.000000000 +0100
56 obj-$(CONFIG_IP_NF_MATCH_HASHLIMIT) += ipt_hashlimit.o
57 obj-$(CONFIG_IP_NF_MATCH_SET) += ipt_set.o
58 obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
59 +obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o
60 obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
61 obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
62 obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
63 diff -urN linux.old/net/ipv4/netfilter/ipt_ipp2p.c linux.dev/net/ipv4/netfilter/ipt_ipp2p.c
64 --- linux.old/net/ipv4/netfilter/ipt_ipp2p.c 1970-01-01 01:00:00.000000000 +0100
65 +++ linux.dev/net/ipv4/netfilter/ipt_ipp2p.c 2006-03-23 15:24:47.000000000 +0100
67 +#if defined(MODVERSIONS)
68 +#include <linux/modversions.h>
70 +#include <linux/module.h>
71 +#include <linux/netfilter_ipv4/ip_tables.h>
72 +#include <linux/version.h>
73 +#include <linux/netfilter_ipv4/ipt_ipp2p.h>
77 +#define get_u8(X,O) (*(__u8 *)(X + O))
78 +#define get_u16(X,O) (*(__u16 *)(X + O))
79 +#define get_u32(X,O) (*(__u32 *)(X + O))
81 +MODULE_AUTHOR("Eicke Friedrich/Klaus Degner <ipp2p@ipp2p.org>");
82 +MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic.");
83 +MODULE_LICENSE("GPL");
86 +/*Search for UDP eDonkey/eMule/Kad commands*/
88 +udp_search_edk (unsigned char *haystack, int packet_len)
90 + unsigned char *t = haystack;
98 + /* client -> server status request */
100 + if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
102 + /* server -> client status request */
103 + case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
105 + /* server description request */
106 + /* e3 2a ff f0 .. | size == 6 */
107 + case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52);
109 + /* server description response */
110 + /* e3 a3 ff f0 .. | size > 40 && size < 200 */
111 + //case 0xa3: return ((IPP2P_EDK * 100) + 53);
113 + case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
116 + case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
125 + /* e4 20 .. | size == 43 */
126 + case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
128 + /* e4 00 .. 00 | size == 35 ? */
129 + case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
131 + /* e4 10 .. 00 | size == 35 ? */
132 + case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
134 + /* e4 18 .. 00 | size == 35 ? */
135 + case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
137 + /* e4 52 .. | size = 44 */
138 + case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
140 + /* e4 58 .. | size == 6 */
141 + case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
143 + /* e4 59 .. | size == 2 */
144 + case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
146 + /* e4 28 .. | packet_len == 52,77,102,127... */
147 + case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
149 + /* e4 50 xx xx | size == 4 */
150 + case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
152 + /* e4 40 xx xx | size == 48 */
153 + case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
158 + } /* end of switch (t[0]) */
163 +/*Search for UDP Gnutella commands*/
165 +udp_search_gnu (unsigned char *haystack, int packet_len)
167 + unsigned char *t = haystack;
170 + if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
171 + if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
176 +/*Search for UDP KaZaA commands*/
178 +udp_search_kazaa (unsigned char *haystack, int packet_len)
180 + unsigned char *t = haystack;
182 + if (t[packet_len-1] == 0x00){
183 + t += (packet_len - 6);
184 + if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
188 +}/*udp_search_kazaa*/
190 +/*Search for UDP DirectConnect commands*/
192 +udp_search_directconnect (unsigned char *haystack, int packet_len)
194 + unsigned char *t = haystack;
195 + if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
197 + if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60);
198 + if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61);
201 +}/*udp_search_directconnect*/
205 +/*Search for UDP BitTorrent commands*/
207 +udp_search_bit (unsigned char *haystack, int packet_len)
212 + /* ^ 00 00 04 17 27 10 19 80 */
213 + if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980))
214 + return (IPP2P_BIT * 100 + 50);
217 + if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
218 + return (IPP2P_BIT * 100 + 51);
219 + if (get_u32(haystack, 16) == __constant_htonl(0x00000400))
220 + return (IPP2P_BIT * 100 + 61);
223 + if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
224 + return (IPP2P_BIT * 100 + 52);
225 + if (get_u32(haystack, 16) == __constant_htonl(0x00000404))
226 + return (IPP2P_BIT * 100 + 62);
229 + if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
230 + return (IPP2P_BIT * 100 + 53);
231 + if (get_u32(haystack, 16) == __constant_htonl(0x00000406))
232 + return (IPP2P_BIT * 100 + 63);
235 + if (get_u32(haystack, 8) == __constant_htonl(0x00000405))
236 + return (IPP2P_BIT * 100 + 54);
239 + if ((get_u32(haystack, 8) == __constant_htonl(0x00000401)))
240 + return (IPP2P_BIT * 100 + 55);
243 + if (get_u32(haystack,8) == __constant_htonl(0x00000827) &&
244 + get_u32(haystack,12) == __constant_htonl(0x37502950))
245 + return (IPP2P_BIT * 100 + 80);
248 + /* this packet does not have a constant size */
249 + if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104))
250 + return (IPP2P_BIT * 100 + 56);
254 + /* some extra-bitcomet rules:
255 + * "d1:" [a|r] "d2:id20:"
257 + if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
259 + if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
261 + if (memcmp(haystack+12,"d2:id20:",8)==0)
262 + return (IPP2P_BIT * 100 + 57);
267 + /* bitlord rules */
268 + /* packetlen must be bigger than 40 */
269 + /* first 4 bytes are zero */
270 + if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000)
272 + /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/
273 + if (get_u32(haystack, 12) == 0x00000000 &&
274 + get_u32(haystack, 16) == 0x00010000 &&
275 + get_u32(haystack, 24) == 0x00000000 )
276 + return (IPP2P_BIT * 100 + 71);
278 + /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/
279 + if (get_u32(haystack, 12) == 0x00000001 &&
280 + get_u32(haystack, 16) == 0x000d0000 &&
281 + get_u32(haystack, 24) == 0x00000000 )
282 + return (IPP2P_BIT * 100 + 71);
293 +/*Search for Ares commands*/
294 +//#define IPP2P_DEBUG_ARES
296 +search_ares (const unsigned char *payload, const u16 plen)
297 +//int search_ares (unsigned char *haystack, int packet_len, int head_len)
299 +// const unsigned char *t = haystack + head_len;
301 + /* all ares packets start with */
302 + if (payload[1] == 0 && (plen - payload[0]) == 3)
304 + switch (payload[2])
308 + if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
311 + /* ares search, min 3 chars --> 14 bytes
312 + * lets define a search can be up to 30 chars --> max 34 bytes
314 + if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
316 +#ifdef IPP2P_DEBUG_ARES
318 + printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
319 +#endif /* IPP2P_DEBUG_ARES */
324 + /* found connect packet: 03 00 5a 04 03 05 */
325 + /* new version ares 1.8: 03 00 5a xx xx 05 */
326 + if ((plen) == 6){ /* possible connect command*/
327 + if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05))
328 + return ((IPP2P_ARES * 100) + 1);
330 + if ((plen) == 60){ /* possible download command*/
331 + if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){
332 + if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */
333 + return ((IPP2P_ARES * 100) + 2);
341 +/*Search for SoulSeek commands*/
343 +search_soul (const unsigned char *payload, const u16 plen)
345 +//#define IPP2P_DEBUG_SOUL
346 + /* match: xx xx xx xx | xx = sizeof(payload) - 4 */
347 + if (get_u32(payload, 0) == (plen - 4)){
348 + const __u32 m=get_u32(payload, 4);
349 + /* match 00 yy yy 00, yy can be everything */
350 + if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 )
352 +#ifdef IPP2P_DEBUG_SOUL
353 + printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4));
354 +#endif /* IPP2P_DEBUG_SOUL */
355 + return ((IPP2P_SOUL * 100) + 1);
358 + /* next match: 01 yy 00 00 | yy can be everything */
359 + if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
361 +#ifdef IPP2P_DEBUG_SOUL
362 + printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
363 +#endif /* IPP2P_DEBUG_SOUL */
364 + return ((IPP2P_SOUL * 100) + 2);
367 + /* 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 */
368 + /* try to do this in an intelligent way */
369 + /* get all small commandos */
384 +#ifdef IPP2P_DEBUG_SOUL
385 + printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
386 +#endif /* IPP2P_DEBUG_SOUL */
387 + return ((IPP2P_SOUL * 100) + 3);
390 + if (m > 0 && m < 6 )
392 +#ifdef IPP2P_DEBUG_SOUL
393 + printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
394 +#endif /* IPP2P_DEBUG_SOUL */
395 + return ((IPP2P_SOUL * 100) + 4);
397 + if (m > 12 && m < 19 )
399 +#ifdef IPP2P_DEBUG_SOUL
400 + printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
401 +#endif /* IPP2P_DEBUG_SOUL */
402 + return ((IPP2P_SOUL * 100) + 5);
405 + if (m > 34 && m < 38 )
407 +#ifdef IPP2P_DEBUG_SOUL
408 + printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
409 +#endif /* IPP2P_DEBUG_SOUL */
410 + return ((IPP2P_SOUL * 100) + 6);
413 + if (m > 39 && m < 47 )
415 +#ifdef IPP2P_DEBUG_SOUL
416 + printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
417 +#endif /* IPP2P_DEBUG_SOUL */
418 + return ((IPP2P_SOUL * 100) + 7);
421 + if (m > 61 && m < 70 )
423 +#ifdef IPP2P_DEBUG_SOUL
424 + printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4));
425 +#endif /* IPP2P_DEBUG_SOUL */
426 + return ((IPP2P_SOUL * 100) + 8);
429 +#ifdef IPP2P_DEBUG_SOUL
430 + 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);
431 +#endif /* IPP2P_DEBUG_SOUL */
434 + /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */
435 + /* without size at the beginning !!! */
436 + if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 )
438 + __u32 y=get_u32(payload, 5);
439 + /* we need 19 chars + string */
440 + if ( (y + 19) <= (plen) )
442 + const unsigned char *w=payload+9+y;
443 + if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00);
444 +#ifdef IPP2P_DEBUG_SOUL
445 + printk(KERN_DEBUG "Soulssek special client command recognized\n");
446 +#endif /* IPP2P_DEBUG_SOUL */
447 + return ((IPP2P_SOUL * 100) + 9);
454 +/*Search for WinMX commands*/
456 +search_winmx (const unsigned char *payload, const u16 plen)
458 +//#define IPP2P_DEBUG_WINMX
459 + if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1);
460 + if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2);
461 + //if (packet_len < (head_len + 10)) return 0;
462 + if (plen < 10) return 0;
464 + if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
466 + const u16 end=plen-2;
470 + if (payload[c]== 0x20 && payload[c+1] == 0x22)
474 + if (count>=2) return ((IPP2P_WINMX * 100) + 3);
480 + if ( plen == 149 && payload[0] == '8' )
482 +#ifdef IPP2P_DEBUG_WINMX
483 + printk(KERN_INFO "maybe WinMX\n");
485 + if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
486 +// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
487 +// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
488 + get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))
491 +#ifdef IPP2P_DEBUG_WINMX
492 + printk(KERN_INFO "got WinMX\n");
494 + return ((IPP2P_WINMX * 100) + 4);
501 +/*Search for appleJuice commands*/
503 +search_apple (const unsigned char *payload, const u16 plen)
505 + if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100);
511 +/*Search for BitTorrent commands*/
513 +search_bittorrent (const unsigned char *payload, const u16 plen)
517 + /* test for match 0x13+"BitTorrent protocol" */
518 + if (payload[0] == 0x13)
520 + if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
523 + /* get tracker commandos, all starts with GET /
524 + * then it can follow: scrape| announce
525 + * and then ?hash_info=
527 + if (memcmp(payload,"GET /",5) == 0)
529 + /* message scrape */
530 + if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1);
531 + /* message announce */
532 + if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2);
537 + /* bitcomet encryptes the first packet, so we have to detect another
538 + * one later in the flow */
539 + /* first try failed, too many missdetections */
540 + //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3);
542 + /* second try: block request packets */
543 + 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);
551 +/*check for Kazaa get command*/
553 +search_kazaa (const unsigned char *payload, const u16 plen)
556 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
557 + return (IPP2P_DATA_KAZAA * 100);
563 +/*check for gnutella get command*/
565 +search_gnu (const unsigned char *payload, const u16 plen)
567 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
569 + if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1);
570 + if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2);
576 +/*check for gnutella get commands and other typical data*/
578 +search_all_gnu (const unsigned char *payload, const u16 plen)
581 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
584 + if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1);
585 + if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2);
588 + if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
591 + const u16 end=plen-22;
593 + if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0)))
594 + return ((IPP2P_GNU * 100) + 3);
603 +/*check for KaZaA download commands and other typical data*/
605 +search_all_kazaa (const unsigned char *payload, const u16 plen)
607 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
610 + if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
612 + if (memcmp(payload, "GET /", 5) == 0) {
614 + const u16 end=plen-22;
616 + 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)))
617 + return ((IPP2P_KAZAA * 100) + 2);
625 +/*fast check for edonkey file segment transfer command*/
627 +search_edk (const unsigned char *payload, const u16 plen)
629 + if (payload[0] != 0xe3)
632 + if (payload[5] == 0x47)
633 + return (IPP2P_DATA_EDK * 100);
641 +/*intensive but slower search for some edonkey packets including size-check*/
643 +search_all_edk (const unsigned char *payload, const u16 plen)
645 + if (payload[0] != 0xe3)
649 + const u16 cmd = get_u16(payload, 1);
650 + if (cmd == (plen - 5)) {
651 + switch (payload[5]) {
652 + case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/
653 + case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/
661 +/*fast check for Direct Connect send command*/
663 +search_dc (const unsigned char *payload, const u16 plen)
666 + if (payload[0] != 0x24 )
669 + if (memcmp(&payload[1], "Send|", 5) == 0)
670 + return (IPP2P_DATA_DC * 100);
678 +/*intensive but slower check for all direct connect packets*/
680 +search_all_dc (const unsigned char *payload, const u16 plen)
682 +// unsigned char *t = haystack;
684 + if (payload[0] == 0x24 && payload[plen-1] == 0x7c)
686 + const unsigned char *t=&payload[1];
687 + /* Client-Hub-Protocol */
688 + if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1);
689 + /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */
690 + if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38);
697 +search_mute (const unsigned char *payload, const u16 plen)
699 + if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
701 + //printk(KERN_DEBUG "size hit: %u",size);
702 + if (memcmp(payload,"PublicKey: ",11) == 0 )
704 + return ((IPP2P_MUTE * 100) + 0);
706 +/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
708 + printk(KERN_DEBUG "end pubic key hit: %u",size);
717 +/* check for xdcc */
719 +search_xdcc (const unsigned char *payload, const u16 plen)
721 + /* search in small packets only */
722 + if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0)
726 + const u16 end=plen - 13;
728 + /* is seems to be a irc private massage, chedck for xdcc command */
731 + if (payload[x] == ':')
733 + if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
734 + return ((IPP2P_XDCC * 100) + 0);
742 +/* search for waste */
743 +int search_waste(const unsigned char *payload, const u16 plen)
745 + if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
746 + return ((IPP2P_WASTE * 100) + 0);
754 + __u8 short_hand; /*for fucntions included in short hands*/
756 + int (*function_name) (const unsigned char *, const u16);
758 + {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk},
759 +// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa},
760 +// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk},
761 +// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc},
762 + {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc},
763 +// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu},
764 + {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu},
765 + {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa},
766 + {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent},
767 + {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple},
768 + {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul},
769 + {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx},
770 + {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares},
771 + {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute},
772 + {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste},
773 + {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc},
780 + __u8 short_hand; /*for fucntions included in short hands*/
782 + int (*function_name) (unsigned char *, int);
784 + {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa},
785 + {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit},
786 + {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu},
787 + {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk},
788 + {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect},
794 +match(const struct sk_buff *skb,
795 + const struct net_device *in,
796 + const struct net_device *out,
797 + const void *matchinfo,
800 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
807 + const struct ipt_p2p_info *info = matchinfo;
808 + unsigned char *haystack;
809 + struct iphdr *ip = skb->nh.iph;
810 + int p2p_result = 0, i = 0;
812 + int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
814 + /*must not be a fragment*/
816 + if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
820 + /*make sure that skb is linear*/
821 + if(skb_is_nonlinear(skb)){
822 + if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
827 + haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/
829 + switch (ip->protocol){
830 + case IPPROTO_TCP: /*what to do with a TCP packet*/
832 + struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
834 + if (tcph->fin) return 0; /*if FIN bit is set bail out*/
835 + if (tcph->syn) return 0; /*if SYN bit is set bail out*/
836 + if (tcph->rst) return 0; /*if RST bit is set bail out*/
838 + haystack += tcph->doff * 4; /*get TCP-Header-Size*/
839 + hlen -= tcph->doff * 4;
840 + while (matchlist[i].command) {
841 + if ((((info->cmd & matchlist[i].command) == matchlist[i].command) ||
842 + ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) &&
843 + (hlen > matchlist[i].packet_len)) {
844 + p2p_result = matchlist[i].function_name(haystack, hlen);
847 + if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
848 + p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen);
857 + case IPPROTO_UDP: /*what to do with an UDP packet*/
859 + struct udphdr *udph = (void *) ip + ip->ihl * 4;
861 + while (udp_list[i].command){
862 + if ((((info->cmd & udp_list[i].command) == udp_list[i].command) ||
863 + ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) &&
864 + (hlen > udp_list[i].packet_len)) {
865 + p2p_result = udp_list[i].function_name(haystack, hlen);
867 + if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n",
868 + p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen);
884 +checkentry(const char *tablename,
885 + const struct ipt_ip *ip,
887 + unsigned int matchsize,
888 + unsigned int hook_mask)
890 + /* Must specify -p tcp */
891 +/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) {
892 + * printk("ipp2p: Only works on TCP packets, use -p tcp\n");
901 +static struct ipt_match ipp2p_match = {
902 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
910 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
913 + .checkentry = &checkentry,
919 +static int __init init(void)
921 + printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
922 + return ipt_register_match(&ipp2p_match);
925 +static void __exit fini(void)
927 + ipt_unregister_match(&ipp2p_match);
928 + printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);