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(+)
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
11 +#ifndef __IPT_IPP2P_H
12 +#define __IPT_IPP2P_H
13 +#define IPP2P_VERSION "0.8.1_rc1"
15 +struct ipt_p2p_info {
20 +#endif //__IPT_IPP2P_H
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*/
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
46 +#if defined(MODVERSIONS)
47 +#include <linux/modversions.h>
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>
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))
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");
65 +/*Search for UDP eDonkey/eMule/Kad commands*/
67 +udp_search_edk (unsigned char *haystack, int packet_len)
69 + unsigned char *t = haystack;
77 + /* client -> server status request */
79 + if (packet_len == 14) return ((IPP2P_EDK * 100) + 50);
81 + /* server -> client status request */
82 + case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51);
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);
88 + /* server description response */
89 + /* e3 a3 ff f0 .. | size > 40 && size < 200 */
90 + //case 0xa3: return ((IPP2P_EDK * 100) + 53);
92 + case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54);
95 + case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55);
104 + /* e4 20 .. | size == 43 */
105 + case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60);
107 + /* e4 00 .. 00 | size == 35 ? */
108 + case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61);
110 + /* e4 10 .. 00 | size == 35 ? */
111 + case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62);
113 + /* e4 18 .. 00 | size == 35 ? */
114 + case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63);
116 + /* e4 52 .. | size = 44 */
117 + case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64);
119 + /* e4 58 .. | size == 6 */
120 + case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65);
122 + /* e4 59 .. | size == 2 */
123 + case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66);
125 + /* e4 28 .. | packet_len == 52,77,102,127... */
126 + case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67);
128 + /* e4 50 xx xx | size == 4 */
129 + case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68);
131 + /* e4 40 xx xx | size == 48 */
132 + case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69);
137 + } /* end of switch (t[0]) */
142 +/*Search for UDP Gnutella commands*/
144 +udp_search_gnu (unsigned char *haystack, int packet_len)
146 + unsigned char *t = haystack;
149 + if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51);
150 + if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52);
155 +/*Search for UDP KaZaA commands*/
157 +udp_search_kazaa (unsigned char *haystack, int packet_len)
159 + unsigned char *t = haystack;
161 + if (t[packet_len-1] == 0x00){
162 + t += (packet_len - 6);
163 + if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50);
167 +}/*udp_search_kazaa*/
169 +/*Search for UDP DirectConnect commands*/
171 +udp_search_directconnect (unsigned char *haystack, int packet_len)
173 + unsigned char *t = haystack;
174 + if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) {
176 + if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60);
177 + if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61);
180 +}/*udp_search_directconnect*/
184 +/*Search for UDP BitTorrent commands*/
186 +udp_search_bit (unsigned char *haystack, int packet_len)
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);
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);
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);
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);
214 + if (get_u32(haystack, 8) == __constant_htonl(0x00000405))
215 + return (IPP2P_BIT * 100 + 54);
218 + if ((get_u32(haystack, 8) == __constant_htonl(0x00000401)))
219 + return (IPP2P_BIT * 100 + 55);
222 + if (get_u32(haystack,8) == __constant_htonl(0x00000827) &&
223 + get_u32(haystack,12) == __constant_htonl(0x37502950))
224 + return (IPP2P_BIT * 100 + 80);
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);
233 + /* some extra-bitcomet rules:
234 + * "d1:" [a|r] "d2:id20:"
236 + if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' )
238 + if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r')
240 + if (memcmp(haystack+12,"d2:id20:",8)==0)
241 + return (IPP2P_BIT * 100 + 57);
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)
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);
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);
272 +/*Search for Ares commands*/
273 +//#define IPP2P_DEBUG_ARES
275 +search_ares (const unsigned char *payload, const u16 plen)
276 +//int search_ares (unsigned char *haystack, int packet_len, int head_len)
278 +// const unsigned char *t = haystack + head_len;
280 + /* all ares packets start with */
281 + if (payload[1] == 0 && (plen - payload[0]) == 3)
283 + switch (payload[2])
287 + if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1);
290 + /* ares search, min 3 chars --> 14 bytes
291 + * lets define a search can be up to 30 chars --> max 34 bytes
293 + if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1);
295 +#ifdef IPP2P_DEBUG_ARES
297 + printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen);
298 +#endif /* IPP2P_DEBUG_ARES */
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);
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);
320 +/*Search for SoulSeek commands*/
322 +search_soul (const unsigned char *payload, const u16 plen)
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 )
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);
337 + /* next match: 01 yy 00 00 | yy can be everything */
338 + if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 )
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);
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 */
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);
369 + if (m > 0 && m < 6 )
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);
376 + if (m > 12 && m < 19 )
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);
384 + if (m > 34 && m < 38 )
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);
392 + if (m > 39 && m < 47 )
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);
400 + if (m > 61 && m < 70 )
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);
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 */
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 )
417 + __u32 y=get_u32(payload, 5);
418 + /* we need 19 chars + string */
419 + if ( (y + 19) <= (plen) )
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);
433 +/*Search for WinMX commands*/
435 +search_winmx (const unsigned char *payload, const u16 plen)
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;
443 + if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){
445 + const u16 end=plen-2;
449 + if (payload[c]== 0x20 && payload[c+1] == 0x22)
453 + if (count>=2) return ((IPP2P_WINMX * 100) + 3);
459 + if ( plen == 149 && payload[0] == '8' )
461 +#ifdef IPP2P_DEBUG_WINMX
462 + printk(KERN_INFO "maybe WinMX\n");
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))
470 +#ifdef IPP2P_DEBUG_WINMX
471 + printk(KERN_INFO "got WinMX\n");
473 + return ((IPP2P_WINMX * 100) + 4);
480 +/*Search for appleJuice commands*/
482 +search_apple (const unsigned char *payload, const u16 plen)
484 + if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100);
490 +/*Search for BitTorrent commands*/
492 +search_bittorrent (const unsigned char *payload, const u16 plen)
496 + /* test for match 0x13+"BitTorrent protocol" */
497 + if (payload[0] == 0x13)
499 + if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100);
502 + /* get tracker commandos, all starts with GET /
503 + * then it can follow: scrape| announce
504 + * and then ?hash_info=
506 + if (memcmp(payload,"GET /",5) == 0)
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);
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);
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);
530 +/*check for Kazaa get command*/
532 +search_kazaa (const unsigned char *payload, const u16 plen)
535 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0)
536 + return (IPP2P_DATA_KAZAA * 100);
542 +/*check for gnutella get command*/
544 +search_gnu (const unsigned char *payload, const u16 plen)
546 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
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);
555 +/*check for gnutella get commands and other typical data*/
557 +search_all_gnu (const unsigned char *payload, const u16 plen)
560 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
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);
567 + if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0))
570 + const u16 end=plen-22;
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);
582 +/*check for KaZaA download commands and other typical data*/
584 +search_all_kazaa (const unsigned char *payload, const u16 plen)
586 + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a))
589 + if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);
591 + if (memcmp(payload, "GET /", 5) == 0) {
593 + const u16 end=plen-22;
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);
604 +/*fast check for edonkey file segment transfer command*/
606 +search_edk (const unsigned char *payload, const u16 plen)
608 + if (payload[0] != 0xe3)
611 + if (payload[5] == 0x47)
612 + return (IPP2P_DATA_EDK * 100);
620 +/*intensive but slower search for some edonkey packets including size-check*/
622 +search_all_edk (const unsigned char *payload, const u16 plen)
624 + if (payload[0] != 0xe3)
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*/
640 +/*fast check for Direct Connect send command*/
642 +search_dc (const unsigned char *payload, const u16 plen)
645 + if (payload[0] != 0x24 )
648 + if (memcmp(&payload[1], "Send|", 5) == 0)
649 + return (IPP2P_DATA_DC * 100);
657 +/*intensive but slower check for all direct connect packets*/
659 +search_all_dc (const unsigned char *payload, const u16 plen)
661 +// unsigned char *t = haystack;
663 + if (payload[0] == 0x24 && payload[plen-1] == 0x7c)
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);
676 +search_mute (const unsigned char *payload, const u16 plen)
678 + if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 )
680 + //printk(KERN_DEBUG "size hit: %u",size);
681 + if (memcmp(payload,"PublicKey: ",11) == 0 )
683 + return ((IPP2P_MUTE * 100) + 0);
685 +/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0)
687 + printk(KERN_DEBUG "end pubic key hit: %u",size);
696 +/* check for xdcc */
698 +search_xdcc (const unsigned char *payload, const u16 plen)
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)
705 + const u16 end=plen - 13;
707 + /* is seems to be a irc private massage, chedck for xdcc command */
710 + if (payload[x] == ':')
712 + if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 )
713 + return ((IPP2P_XDCC * 100) + 0);
721 +/* search for waste */
722 +int search_waste(const unsigned char *payload, const u16 plen)
724 + if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0)
725 + return ((IPP2P_WASTE * 100) + 0);
733 + __u8 short_hand; /*for fucntions included in short hands*/
735 + int (*function_name) (const unsigned char *, const u16);
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},
759 + __u8 short_hand; /*for fucntions included in short hands*/
761 + int (*function_name) (unsigned char *, int);
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},
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,
779 + const void *matchinfo,
782 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
786 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
787 + unsigned int protoff,
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;
797 + int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/
799 + /*must not be a fragment*/
801 + if (info->debug) printk("IPP2P.match: offset found %i \n",offset);
805 + /*make sure that skb is linear*/
806 + if(skb_is_nonlinear(skb)){
807 + if (info->debug) printk("IPP2P.match: nonlinear skb found\n");
812 + haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/
814 + switch (ip->protocol){
815 + case IPPROTO_TCP: /*what to do with a TCP packet*/
817 + struct tcphdr *tcph = (void *) ip + ip->ihl * 4;
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*/
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);
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);
842 + case IPPROTO_UDP: /*what to do with an UDP packet*/
844 + struct udphdr *udph = (void *) ip + ip->ihl * 4;
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);
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);
869 +checkentry(const char *tablename,
870 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
873 + const struct ipt_ip *ip,
875 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
876 + const struct xt_match *match,
879 + unsigned int matchsize,
880 + unsigned int hook_mask)
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");
893 +static struct ipt_match ipp2p_match = {
894 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
902 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
905 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
906 + .matchsize = sizeof(struct ipt_p2p_info),
908 + .checkentry = &checkentry,
914 +static int __init init(void)
916 + printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION);
917 + return ipt_register_match(&ipp2p_match);
920 +static void __exit fini(void)
922 + ipt_unregister_match(&ipp2p_match);
923 + printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION);
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
934 Allows altering the ARP packet payload: source and destination
935 hardware and network addresses.
937 +config IP_NF_MATCH_IPP2P
938 + tristate 'IPP2P match support'
939 + depends on IP_NF_IPTABLES
941 + This option makes possible to match some P2P packets
942 + therefore helps controlling such traffic.
944 + If you want to compile it as a module, say M here and read
945 + <file:Documentation/modules.txt>. If unsure, say `N'.
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
953 +obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_ipp2p.o