10 #include <linux/netfilter_ipv4/ipt_ipp2p.h>
16 "IPP2P v%s options:\n"
17 " --ipp2p\tGrab all known p2p packets\n"
18 " --edk\t\t[TCP&UDP]\tAll known eDonkey/eMule/Overnet packets\n"
19 " --dc\t\t[TCP]\t\tAll known Direct Connect packets\n"
20 " --kazaa\t[TCP&UDP]\tAll known KaZaA packets\n"
21 " --gnu\t\t[TCP&UDP]\tAll known Gnutella packets\n"
22 " --bit\t\t[TCP&UDP]\tAll known BitTorrent packets\n"
23 " --apple\t[TCP]\t\tAll known AppleJuice packets\n"
24 " --winmx\t[TCP]\t\tAll known WinMX\n"
25 " --soul\t\t[TCP]\t\tAll known SoulSeek\n"
26 " --ares\t\t[TCP]\t\tAll known Ares\n"
27 " --pp\t\t[TCP&UDP]\tAll known PPLive/PPStream/UUSee/QQLive packets (Please send feedback to: liulei@syiae.edu.cn)\n"
28 " --xunlei\t[TCP]\t\tAll known xunlei/QQCyclone packets\n"
29 " EXPERIMENTAL protocols (please send feedback to: ipp2p@ipp2p.org) :\n"
30 " --mute\t\t[TCP]\t\tAll known Mute packets\n"
31 " --waste\t[TCP]\t\tAll known Waste packets\n"
32 " --xdcc\t\t[TCP]\t\tAll known XDCC packets (only xdcc login)\n\n"
33 " DEBUG SUPPPORT, use only if you know why\n"
34 " --debug\t\tGenerate kernel debug output, THIS WILL SLOW DOWN THE FILTER\n"
35 "\nNote that the follwing options will have the same meaning:\n"
36 " '--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares --pp'\n"
37 "\nIPP2P was intended for TCP only. Due to increasing usage of UDP we needed to change this.\n"
38 "You can now use -p udp to search UDP packets only or without -p switch to search UDP and TCP packets.\n"
39 "\nSee README included with this package for more details or visit http://www.ipp2p.org\n"
41 " iptables -A FORWARD -m ipp2p --ipp2p -j MARK --set-mark 0x01\n"
42 " iptables -A FORWARD -p udp -m ipp2p --kazaa --bit -j DROP\n"
43 " iptables -A FORWARD -p tcp -m ipp2p --edk --soul -j DROP\n\n"
47 static struct option opts
[] = {
48 { "ipp2p", 0, 0, '1' },
51 { "xunlei", 0, 0, '4'},
54 { "kazaa", 0, 0, 'a' },
56 { "apple", 0, 0, 'c' },
57 { "soul", 0, 0, 'd' },
58 { "winmx", 0, 0, 'e' },
59 { "ares", 0, 0, 'f' },
60 { "mute", 0, 0, 'g' },
61 { "waste", 0, 0, 'h' },
62 { "xdcc", 0, 0, 'i' },
63 { "debug", 0, 0, 'j' },
70 init(struct ipt_entry_match
*m
, unsigned int *nfcache
)
72 struct ipt_p2p_info
*info
= (struct ipt_p2p_info
*)m
->data
;
74 *nfcache
|= NFC_UNKNOWN
;
76 /*init the module with default values*/
84 parse(int c
, char **argv
, int invert
, unsigned int *flags
,
85 const struct ipt_entry
*entry
,
86 unsigned int *nfcache
,
87 struct ipt_entry_match
**match
)
89 struct ipt_p2p_info
*info
= (struct ipt_p2p_info
*)(*match
)->data
;
92 case '1': /*cmd: ipp2p*/
93 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
94 exit_error(PARAMETER_PROBLEM
,
95 "ipp2p: `--ipp2p' may only be "
98 exit_error(PARAMETER_PROBLEM
,
99 "ipp2p: `--ipp2p' may only be "
101 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
102 *flags
+= SHORT_HAND_IPP2P
;
106 case '2': /*cmd: edk*/
107 if ((*flags
& IPP2P_EDK
) == IPP2P_EDK
)
108 exit_error(PARAMETER_PROBLEM
,
109 "ipp2p: `--edk' may only be "
111 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
112 exit_error(PARAMETER_PROBLEM
,
113 "ipp2p: `--ipp2p' may only be "
115 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
120 case '3': /*cmd: pp*/
121 if ((*flags
& IPP2P_PP
) == IPP2P_PP
)
122 exit_error(PARAMETER_PROBLEM
,
123 "ipp2p: `--pp' may only be "
125 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
126 exit_error(PARAMETER_PROBLEM
,
127 "ipp2p: `--ipp2p' may only be "
129 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
135 if ((*flags
& IPP2P_XUNLEI
) == IPP2P_XUNLEI
)
136 exit_error(PARAMETER_PROBLEM
,
137 "ipp2p: `--xunlei' may only be "
139 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
140 *flags
+= IPP2P_XUNLEI
;
144 case '7': /*cmd: dc*/
145 if ((*flags
& IPP2P_DC
) == IPP2P_DC
)
146 exit_error(PARAMETER_PROBLEM
,
147 "ipp2p: `--dc' may only be "
149 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
150 exit_error(PARAMETER_PROBLEM
,
151 "ipp2p: `--ipp2p' may only be "
153 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
159 case '9': /*cmd: gnu*/
160 if ((*flags
& IPP2P_GNU
) == IPP2P_GNU
)
161 exit_error(PARAMETER_PROBLEM
,
162 "ipp2p: `--gnu' may only be "
164 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
165 exit_error(PARAMETER_PROBLEM
,
166 "ipp2p: `--ipp2p' may only be "
168 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
173 case 'a': /*cmd: kazaa*/
174 if ((*flags
& IPP2P_KAZAA
) == IPP2P_KAZAA
)
175 exit_error(PARAMETER_PROBLEM
,
176 "ipp2p: `--kazaa' may only be "
178 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
179 exit_error(PARAMETER_PROBLEM
,
180 "ipp2p: `--ipp2p' may only be "
182 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
183 *flags
+= IPP2P_KAZAA
;
187 case 'b': /*cmd: bit*/
188 if ((*flags
& IPP2P_BIT
) == IPP2P_BIT
)
189 exit_error(PARAMETER_PROBLEM
,
190 "ipp2p: `--bit' may only be "
192 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
193 exit_error(PARAMETER_PROBLEM
,
194 "ipp2p: `--ipp2p' may only be "
196 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
201 case 'c': /*cmd: apple*/
202 if ((*flags
& IPP2P_APPLE
) == IPP2P_APPLE
)
203 exit_error(PARAMETER_PROBLEM
,
204 "ipp2p: `--apple' may only be "
206 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
207 exit_error(PARAMETER_PROBLEM
,
208 "ipp2p: `--ipp2p' may only be "
210 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
211 *flags
+= IPP2P_APPLE
;
216 case 'd': /*cmd: soul*/
217 if ((*flags
& IPP2P_SOUL
) == IPP2P_SOUL
)
218 exit_error(PARAMETER_PROBLEM
,
219 "ipp2p: `--soul' may only be "
221 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
222 exit_error(PARAMETER_PROBLEM
,
223 "ipp2p: `--ipp2p' may only be "
225 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
226 *flags
+= IPP2P_SOUL
;
231 case 'e': /*cmd: winmx*/
232 if ((*flags
& IPP2P_WINMX
) == IPP2P_WINMX
)
233 exit_error(PARAMETER_PROBLEM
,
234 "ipp2p: `--winmx' may only be "
236 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
237 exit_error(PARAMETER_PROBLEM
,
238 "ipp2p: `--ipp2p' may only be "
240 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
241 *flags
+= IPP2P_WINMX
;
245 case 'f': /*cmd: ares*/
246 if ((*flags
& IPP2P_ARES
) == IPP2P_ARES
)
247 exit_error(PARAMETER_PROBLEM
,
248 "ipp2p: `--ares' may only be "
250 if ((*flags
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
)
251 exit_error(PARAMETER_PROBLEM
,
252 "ipp2p: `--ipp2p' may only be "
254 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
255 *flags
+= IPP2P_ARES
;
259 case 'g': /*cmd: mute*/
260 if ((*flags
& IPP2P_MUTE
) == IPP2P_MUTE
)
261 exit_error(PARAMETER_PROBLEM
,
262 "ipp2p: `--mute' may only be "
264 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
265 *flags
+= IPP2P_MUTE
;
268 case 'h': /*cmd: waste*/
269 if ((*flags
& IPP2P_WASTE
) == IPP2P_WASTE
)
270 exit_error(PARAMETER_PROBLEM
,
271 "ipp2p: `--waste' may only be "
273 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
274 *flags
+= IPP2P_WASTE
;
277 case 'i': /*cmd: xdcc*/
278 if ((*flags
& IPP2P_XDCC
) == IPP2P_XDCC
)
279 exit_error(PARAMETER_PROBLEM
,
280 "ipp2p: `--xdcc' may only be "
282 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
283 *flags
+= IPP2P_XDCC
;
287 case 'j': /*cmd: debug*/
288 if (invert
) exit_error(PARAMETER_PROBLEM
, "ipp2p: invert [!] is not allowed!");
293 // exit_error(PARAMETER_PROBLEM,
294 // "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n");
302 final_check(unsigned int flags
)
305 exit_error(PARAMETER_PROBLEM
,
306 "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n");
312 print(const struct ipt_ip
*ip
,
313 const struct ipt_entry_match
*match
,
316 struct ipt_p2p_info
*info
= (struct ipt_p2p_info
*)match
->data
;
318 printf("ipp2p v%s", IPP2P_VERSION
);
319 if ((info
->cmd
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
) printf(" --ipp2p");
320 if ((info
->cmd
& IPP2P_KAZAA
) == IPP2P_KAZAA
) printf(" --kazaa");
321 if ((info
->cmd
& IPP2P_GNU
) == IPP2P_GNU
) printf(" --gnu");
322 if ((info
->cmd
& IPP2P_EDK
) == IPP2P_EDK
) printf(" --edk");
323 if ((info
->cmd
& IPP2P_DC
) == IPP2P_DC
) printf(" --dc");
324 if ((info
->cmd
& IPP2P_BIT
) == IPP2P_BIT
) printf(" --bit");
325 if ((info
->cmd
& IPP2P_PP
) == IPP2P_PP
) printf(" --pp");
326 if ((info
->cmd
& IPP2P_XUNLEI
) == IPP2P_XUNLEI
) printf(" --xunlei");
327 if ((info
->cmd
& IPP2P_APPLE
) == IPP2P_APPLE
) printf(" --apple");
328 if ((info
->cmd
& IPP2P_SOUL
) == IPP2P_SOUL
) printf(" --soul");
329 if ((info
->cmd
& IPP2P_WINMX
) == IPP2P_WINMX
) printf(" --winmx");
330 if ((info
->cmd
& IPP2P_ARES
) == IPP2P_ARES
) printf(" --ares");
331 if ((info
->cmd
& IPP2P_MUTE
) == IPP2P_MUTE
) printf(" --mute");
332 if ((info
->cmd
& IPP2P_WASTE
) == IPP2P_WASTE
) printf(" --waste");
333 if ((info
->cmd
& IPP2P_XDCC
) == IPP2P_XDCC
) printf(" --xdcc");
334 if (info
->debug
!= 0) printf(" --debug");
341 save(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
)
343 struct ipt_p2p_info
*info
= (struct ipt_p2p_info
*)match
->data
;
345 if ((info
->cmd
& SHORT_HAND_IPP2P
) == SHORT_HAND_IPP2P
) printf("--ipp2p ");
346 if ((info
->cmd
& IPP2P_KAZAA
) == IPP2P_KAZAA
) printf("--kazaa ");
347 if ((info
->cmd
& IPP2P_GNU
) == IPP2P_GNU
) printf("--gnu ");
348 if ((info
->cmd
& IPP2P_EDK
) == IPP2P_EDK
) printf("--edk ");
349 if ((info
->cmd
& IPP2P_DC
) == IPP2P_DC
) printf("--dc ");
350 if ((info
->cmd
& IPP2P_BIT
) == IPP2P_BIT
) printf("--bit ");
351 if ((info
->cmd
& IPP2P_PP
) == IPP2P_PP
) printf("--pp ");
352 if ((info
->cmd
& IPP2P_XUNLEI
) == IPP2P_XUNLEI
) printf("--xunlei ");
353 if ((info
->cmd
& IPP2P_APPLE
) == IPP2P_APPLE
) printf("--apple ");
354 if ((info
->cmd
& IPP2P_SOUL
) == IPP2P_SOUL
) printf("--soul ");
355 if ((info
->cmd
& IPP2P_WINMX
) == IPP2P_WINMX
) printf("--winmx ");
356 if ((info
->cmd
& IPP2P_ARES
) == IPP2P_ARES
) printf("--ares ");
357 if ((info
->cmd
& IPP2P_MUTE
) == IPP2P_MUTE
) printf("--mute ");
358 if ((info
->cmd
& IPP2P_WASTE
) == IPP2P_WASTE
) printf("--waste ");
359 if ((info
->cmd
& IPP2P_XDCC
) == IPP2P_XDCC
) printf("--xdcc ");
360 if (info
->debug
!= 0) printf("--debug ");
367 struct iptables_match ipp2p
=
371 .version
= IPTABLES_VERSION
,
372 .size
= IPT_ALIGN(sizeof(struct ipt_p2p_info
)),
373 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_p2p_info
)),
377 .final_check
= &final_check
,
387 register_match(&ipp2p
);