From 44d6f47ad6196db45c8a2a135f26eb248d77c2ee Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 05:44:50 +0100 Subject: [PATCH 01/13] ipp2p: import 20080304 code base --- extensions/Kbuild | 1 + extensions/Mbuild | 1 + extensions/libxt_ipp2p.c | 397 ++++++++++++++++ extensions/libxt_ipp2p.man | 43 ++ extensions/xt_ipp2p.Kconfig | 6 + extensions/xt_ipp2p.c | 905 ++++++++++++++++++++++++++++++++++++ extensions/xt_ipp2p.h | 31 ++ mconfig | 1 + 8 files changed, 1385 insertions(+) create mode 100644 extensions/libxt_ipp2p.c create mode 100644 extensions/libxt_ipp2p.man create mode 100644 extensions/xt_ipp2p.Kconfig create mode 100644 extensions/xt_ipp2p.c create mode 100644 extensions/xt_ipp2p.h diff --git a/extensions/Kbuild b/extensions/Kbuild index 9a06eb4..82dd141 100644 --- a/extensions/Kbuild +++ b/extensions/Kbuild @@ -13,6 +13,7 @@ obj-${build_TARPIT} += xt_TARPIT.o obj-${build_TEE} += xt_TEE.o obj-${build_condition} += xt_condition.o obj-${build_geoip} += xt_geoip.o +obj-${build_ipp2p} += xt_ipp2p.o obj-${build_portscan} += xt_portscan.o -include ${M}/*.Kbuild diff --git a/extensions/Mbuild b/extensions/Mbuild index c0060a4..7f8a019 100644 --- a/extensions/Mbuild +++ b/extensions/Mbuild @@ -6,4 +6,5 @@ obj-${build_TARPIT} += libxt_TARPIT.so obj-${build_TEE} += libxt_TEE.so obj-${build_condition} += libxt_condition.so obj-${build_geoip} += libxt_geoip.so +obj-${build_ipp2p} += libxt_ipp2p.so obj-${build_portscan} += libxt_portscan.so diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c new file mode 100644 index 0000000..6fed3bc --- /dev/null +++ b/extensions/libxt_ipp2p.c @@ -0,0 +1,397 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include "xt_ipp2p.h" + +static void +help(void) +{ + printf( + "IPP2P v%s options:\n" + " --ipp2p Grab all known p2p packets\n" + " --edk [TCP&UDP] All known eDonkey/eMule/Overnet packets\n" + " --dc [TCP] All known Direct Connect packets\n" + " --kazaa [TCP&UDP] All known KaZaA packets\n" + " --gnu [TCP&UDP] All known Gnutella packets\n" + " --bit [TCP&UDP] All known BitTorrent packets\n" + " --apple [TCP] All known AppleJuice packets\n" + " --winmx [TCP] All known WinMX\n" + " --soul [TCP] All known SoulSeek\n" + " --ares [TCP] All known Ares\n\n" + " EXPERIMENTAL protocols (please send feedback to: ipp2p@ipp2p.org) :\n" + " --mute [TCP] All known Mute packets\n" + " --waste [TCP] All known Waste packets\n" + " --xdcc [TCP] All known XDCC packets (only xdcc login)\n\n" + " DEBUG SUPPPORT, use only if you know why\n" + " --debug Generate kernel debug output, THIS WILL SLOW DOWN THE FILTER\n" + "\nNote that the follwing options will have the same meaning:\n" + " '--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares'\n" + "\nIPP2P was intended for TCP only. Due to increasing usage of UDP we needed to change this.\n" + "You can now use -p udp to search UDP packets only or without -p switch to search UDP and TCP packets.\n" + "\nSee README included with this package for more details or visit http://www.ipp2p.org\n" + "\nExamples:\n" + " iptables -A FORWARD -m ipp2p --ipp2p -j MARK --set-mark 0x01\n" + " iptables -A FORWARD -p udp -m ipp2p --kazaa --bit -j DROP\n" + " iptables -A FORWARD -p tcp -m ipp2p --edk --soul -j DROP\n\n" + , IPP2P_VERSION); +} + +static struct option opts[] = { + { "ipp2p", 0, 0, '1' }, + { "edk", 0, 0, '2' }, + { "dc", 0, 0, '7' }, + { "gnu", 0, 0, '9' }, + { "kazaa", 0, 0, 'a' }, + { "bit", 0, 0, 'b' }, + { "apple", 0, 0, 'c' }, + { "soul", 0, 0, 'd' }, + { "winmx", 0, 0, 'e' }, + { "ares", 0, 0, 'f' }, + { "mute", 0, 0, 'g' }, + { "waste", 0, 0, 'h' }, + { "xdcc", 0, 0, 'i' }, + { "debug", 0, 0, 'j' }, + {0} +}; + + + +static void +init(struct xt_entry_match *m) +{ + struct ipt_p2p_info *info = (struct ipt_p2p_info *)m->data; + + /*init the module with default values*/ + info->cmd = 0; + info->debug = 0; + +} + + +static int +parse(int c, char **argv, int invert, unsigned int *flags, + const void *entry, + struct xt_entry_match **match) +{ + struct ipt_p2p_info *info = (struct ipt_p2p_info *)(*match)->data; + + switch (c) { + case '1': /*cmd: ipp2p*/ + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified once!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p-data' may only be " + "specified alone!");*/ + if ((*flags) != 0) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += SHORT_HAND_IPP2P; + info->cmd = *flags; + break; + + case '2': /*cmd: edk*/ + if ((*flags & IPP2P_EDK) == IPP2P_EDK) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--edk' may only be " + "specified once"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p-data' may only be " + "specified alone!");*/ + if ((*flags & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_EDK; + info->cmd = *flags; + break; + + + case '7': /*cmd: dc*/ + if ((*flags & IPP2P_DC) == IPP2P_DC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--dc' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p-data' may only be " + "specified alone!");*/ + if ((*flags & IPP2P_DATA_DC) == IPP2P_DATA_DC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_DC; + info->cmd = *flags; + break; + + + case '9': /*cmd: gnu*/ + if ((*flags & IPP2P_GNU) == IPP2P_GNU) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--gnu' may only be " + "specified once!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p-data' may only be " + "specified alone!");*/ + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if ((*flags & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_GNU; + info->cmd = *flags; + break; + + case 'a': /*cmd: kazaa*/ + if ((*flags & IPP2P_KAZAA) == IPP2P_KAZAA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--kazaa' may only be " + "specified once!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p-data' may only be " + "specified alone!");*/ + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if ((*flags & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_KAZAA; + info->cmd = *flags; + break; + + case 'b': /*cmd: bit*/ + if ((*flags & IPP2P_BIT) == IPP2P_BIT) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--bit' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_BIT; + info->cmd = *flags; + break; + + case 'c': /*cmd: apple*/ + if ((*flags & IPP2P_APPLE) == IPP2P_APPLE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--apple' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_APPLE; + info->cmd = *flags; + break; + + + case 'd': /*cmd: soul*/ + if ((*flags & IPP2P_SOUL) == IPP2P_SOUL) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--soul' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_SOUL; + info->cmd = *flags; + break; + + + case 'e': /*cmd: winmx*/ + if ((*flags & IPP2P_WINMX) == IPP2P_WINMX) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--winmx' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_WINMX; + info->cmd = *flags; + break; + + case 'f': /*cmd: ares*/ + if ((*flags & IPP2P_ARES) == IPP2P_ARES) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ares' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ipp2p' may only be " + "specified alone!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_ARES; + info->cmd = *flags; + break; + + case 'g': /*cmd: mute*/ + if ((*flags & IPP2P_MUTE) == IPP2P_MUTE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--mute' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_MUTE; + info->cmd = *flags; + break; + case 'h': /*cmd: waste*/ + if ((*flags & IPP2P_WASTE) == IPP2P_WASTE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--waste' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_WASTE; + info->cmd = *flags; + break; + case 'i': /*cmd: xdcc*/ + if ((*flags & IPP2P_XDCC) == IPP2P_XDCC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ares' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_XDCC; + info->cmd = *flags; + break; + + case 'j': /*cmd: debug*/ + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + info->debug = 1; + break; + + default: +// exit_error(PARAMETER_PROBLEM, +// "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); + return 0; + } + return 1; +} + + +static void +final_check(unsigned int flags) +{ + if (!flags) + exit_error(PARAMETER_PROBLEM, + "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); +} + + + +static void +print(const void *ip, + const struct xt_entry_match *match, + int numeric) +{ + struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + + printf("ipp2p v%s", IPP2P_VERSION); + if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) printf(" --ipp2p"); +// if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) printf(" --ipp2p-data"); + if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) printf(" --kazaa"); +// if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) printf(" --kazaa-data"); +// if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) printf(" --gnu-data"); + if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf(" --gnu"); + if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf(" --edk"); +// if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) printf(" --edk-data"); +// if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) printf(" --dc-data"); + if ((info->cmd & IPP2P_DC) == IPP2P_DC) printf(" --dc"); + if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) printf(" --bit"); + if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) printf(" --apple"); + if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) printf(" --soul"); + if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) printf(" --winmx"); + if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) printf(" --ares"); + if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) printf(" --mute"); + if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) printf(" --waste"); + if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) printf(" --xdcc"); + if (info->debug != 0) printf(" --debug"); + printf(" "); +} + + + +static void +save(const void *ip, const struct xt_entry_match *match) +{ + struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + + if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) printf("--ipp2p "); +// if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) printf("--ipp2p-data "); + if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) printf("--kazaa "); +// if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) printf("--kazaa-data "); +// if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) printf("--gnu-data "); + if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf("--gnu "); + if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf("--edk "); +// if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) printf("--edk-data "); +// if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) printf("--dc-data "); + if ((info->cmd & IPP2P_DC) == IPP2P_DC) printf("--dc "); + if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) printf("--bit "); + if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) printf("--apple "); + if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) printf("--soul "); + if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) printf("--winmx "); + if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) printf("--ares "); + if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) printf(" --mute"); + if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) printf(" --waste"); + if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) printf(" --xdcc"); + if (info->debug != 0) printf("--debug "); +} + + + + +static +struct xtables_match ipp2p= +{ + .next = NULL, + .name = "ipp2p", + .version = XTABLES_VERSION, + .size = XT_ALIGN(sizeof(struct ipt_p2p_info)), + .userspacesize = XT_ALIGN(sizeof(struct ipt_p2p_info)), + .help = &help, + .init = &init, + .parse = &parse, + .final_check = &final_check, + .print = &print, + .save = &save, + .extra_opts = opts +}; + + + +void _init(void) +{ + xtables_register_match(&ipp2p); +} + diff --git a/extensions/libxt_ipp2p.man b/extensions/libxt_ipp2p.man new file mode 100644 index 0000000..da34514 --- /dev/null +++ b/extensions/libxt_ipp2p.man @@ -0,0 +1,43 @@ +This module matches certain packets in P2P flows. It is not +designed to match all packets belonging to a P2P connection - +use IPP2P together with CONNMARK for this purpose. Also visit +http://www.ipp2p.org for detailed information. + +Use it together with -p tcp or -p udp to search these protocols +only or without -p switch to search packets of both protocols. + +IPP2P provides the following options: +.TP +.B "--edk " +Matches as many eDonkey/eMule packets as possible. +.TP +.B "--kazaa " +Matches as many KaZaA packets as possible. +.TP +.B "--gnu " +Matches as many Gnutella packets as possible. +.TP +.B "--dc " +Matches as many Direct Connect packets as possible. +.TP +.B "--bit " +Matches BitTorrent packets. +.TP +.B "--apple " +Matches AppleJuice packets. +.TP +.B "--soul " +Matches some SoulSeek packets. Considered as beta, use careful! +.TP +.B "--winmx " +Matches some WinMX packets. Considered as beta, use careful! +.TP +.B "--ares " +Matches Ares and AresLite packets. Use together with -j DROP only. +.TP +.B "--ipp2p " +Short hand for: --edk --kazaa --gnu --dc +.TP +.B "--debug " +Prints some information about each hit into kernel logfile. May +produce huge logfiles so beware! diff --git a/extensions/xt_ipp2p.Kconfig b/extensions/xt_ipp2p.Kconfig new file mode 100644 index 0000000..ef29447 --- /dev/null +++ b/extensions/xt_ipp2p.Kconfig @@ -0,0 +1,6 @@ +config NETFILTER_XT_MATCH_IPP2P + tristate '"ipp2p" match support' + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED + ---help--- + This option makes possible to match some P2P packets + therefore helps controlling such traffic. diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c new file mode 100644 index 0000000..5dc0a10 --- /dev/null +++ b/extensions/xt_ipp2p.c @@ -0,0 +1,905 @@ +#if defined(MODVERSIONS) +#include +#endif +#include +#include +#include +#include +#include +#include "xt_ipp2p.h" +#include "compat_xtables.h" + +#define get_u8(X,O) (*(__u8 *)(X + O)) +#define get_u16(X,O) (*(__u16 *)(X + O)) +#define get_u32(X,O) (*(__u32 *)(X + O)) + +MODULE_AUTHOR("Eicke Friedrich/Klaus Degner "); +MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic."); +MODULE_LICENSE("GPL"); + + +/*Search for UDP eDonkey/eMule/Kad commands*/ +int +udp_search_edk (unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + t += 8; + + switch (t[0]) { + case 0xe3: + { /*edonkey*/ + switch (t[1]) + { + /* client -> server status request */ + case 0x96: + if (packet_len == 14) return ((IPP2P_EDK * 100) + 50); + break; + /* server -> client status request */ + case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51); + break; + /* server description request */ + /* e3 2a ff f0 .. | size == 6 */ + case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52); + break; + /* server description response */ + /* e3 a3 ff f0 .. | size > 40 && size < 200 */ + //case 0xa3: return ((IPP2P_EDK * 100) + 53); + // break; + case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54); + break; + + case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55); + break; + } + break; + } + case 0xe4: + { + switch (t[1]) + { + /* e4 20 .. | size == 43 */ + case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60); + break; + /* e4 00 .. 00 | size == 35 ? */ + case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61); + break; + /* e4 10 .. 00 | size == 35 ? */ + case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62); + break; + /* e4 18 .. 00 | size == 35 ? */ + case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63); + break; + /* e4 52 .. | size = 44 */ + case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64); + break; + /* e4 58 .. | size == 6 */ + case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65); + break; + /* e4 59 .. | size == 2 */ + case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66); + break; + /* e4 28 .. | packet_len == 52,77,102,127... */ + case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67); + break; + /* e4 50 xx xx | size == 4 */ + case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68); + break; + /* e4 40 xx xx | size == 48 */ + case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69); + break; + } + break; + } + } /* end of switch (t[0]) */ + return 0; +}/*udp_search_edk*/ + + +/*Search for UDP Gnutella commands*/ +int +udp_search_gnu (unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + t += 8; + + if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51); + if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52); + return 0; +}/*udp_search_gnu*/ + + +/*Search for UDP KaZaA commands*/ +int +udp_search_kazaa (unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + + if (t[packet_len-1] == 0x00){ + t += (packet_len - 6); + if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50); + } + + return 0; +}/*udp_search_kazaa*/ + +/*Search for UDP DirectConnect commands*/ +int +udp_search_directconnect (unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) { + t+=8; + if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60); + if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61); + } + return 0; +}/*udp_search_directconnect*/ + + + +/*Search for UDP BitTorrent commands*/ +int +udp_search_bit (unsigned char *haystack, int packet_len) +{ + switch(packet_len) + { + case 24: + /* ^ 00 00 04 17 27 10 19 80 */ + if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980)) + return (IPP2P_BIT * 100 + 50); + break; + case 44: + if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return (IPP2P_BIT * 100 + 51); + if (get_u32(haystack, 16) == __constant_htonl(0x00000400)) + return (IPP2P_BIT * 100 + 61); + break; + case 65: + if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return (IPP2P_BIT * 100 + 52); + if (get_u32(haystack, 16) == __constant_htonl(0x00000404)) + return (IPP2P_BIT * 100 + 62); + break; + case 67: + if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return (IPP2P_BIT * 100 + 53); + if (get_u32(haystack, 16) == __constant_htonl(0x00000406)) + return (IPP2P_BIT * 100 + 63); + break; + case 211: + if (get_u32(haystack, 8) == __constant_htonl(0x00000405)) + return (IPP2P_BIT * 100 + 54); + break; + case 29: + if ((get_u32(haystack, 8) == __constant_htonl(0x00000401))) + return (IPP2P_BIT * 100 + 55); + break; + case 52: + if (get_u32(haystack,8) == __constant_htonl(0x00000827) && + get_u32(haystack,12) == __constant_htonl(0x37502950)) + return (IPP2P_BIT * 100 + 80); + break; + default: + /* this packet does not have a constant size */ + if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return (IPP2P_BIT * 100 + 56); + break; + } + + /* some extra-bitcomet rules: + * "d1:" [a|r] "d2:id20:" + */ + if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' ) + { + if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r') + { + if (memcmp(haystack+12,"d2:id20:",8)==0) + return (IPP2P_BIT * 100 + 57); + } + } + +#if 0 + /* bitlord rules */ + /* packetlen must be bigger than 40 */ + /* first 4 bytes are zero */ + if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000) + { + /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/ + if (get_u32(haystack, 12) == 0x00000000 && + get_u32(haystack, 16) == 0x00010000 && + get_u32(haystack, 24) == 0x00000000 ) + return (IPP2P_BIT * 100 + 71); + + /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/ + if (get_u32(haystack, 12) == 0x00000001 && + get_u32(haystack, 16) == 0x000d0000 && + get_u32(haystack, 24) == 0x00000000 ) + return (IPP2P_BIT * 100 + 71); + + + } +#endif + + return 0; +}/*udp_search_bit*/ + + + +/*Search for Ares commands*/ +//#define IPP2P_DEBUG_ARES +int +search_ares (const unsigned char *payload, const u16 plen) +//int search_ares (unsigned char *haystack, int packet_len, int head_len) +{ +// const unsigned char *t = haystack + head_len; + + /* all ares packets start with */ + if (payload[1] == 0 && (plen - payload[0]) == 3) + { + switch (payload[2]) + { + case 0x5a: + /* ares connect */ + if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1); + break; + case 0x09: + /* ares search, min 3 chars --> 14 bytes + * lets define a search can be up to 30 chars --> max 34 bytes + */ + if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1); + break; +#ifdef IPP2P_DEBUG_ARES + default: + printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen); +#endif /* IPP2P_DEBUG_ARES */ + } + } + +#if 0 + /* found connect packet: 03 00 5a 04 03 05 */ + /* new version ares 1.8: 03 00 5a xx xx 05 */ + if ((plen) == 6){ /* possible connect command*/ + if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05)) + return ((IPP2P_ARES * 100) + 1); + } + if ((plen) == 60){ /* possible download command*/ + if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){ + if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */ + return ((IPP2P_ARES * 100) + 2); + } + } +#endif + + return 0; +} /*search_ares*/ + +/*Search for SoulSeek commands*/ +int +search_soul (const unsigned char *payload, const u16 plen) +{ +//#define IPP2P_DEBUG_SOUL + /* match: xx xx xx xx | xx = sizeof(payload) - 4 */ + if (get_u32(payload, 0) == (plen - 4)){ + const __u32 m=get_u32(payload, 4); + /* match 00 yy yy 00, yy can be everything */ + if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 1); + } + + /* next match: 01 yy 00 00 | yy can be everything */ + if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 2); + } + + /* 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 */ + /* try to do this in an intelligent way */ + /* get all small commandos */ + switch(m) + { + case 7: + case 9: + case 22: + case 23: + case 26: + case 28: + case 50: + case 51: + case 60: + case 91: + case 92: + case 1001: +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 3); + } + + if (m > 0 && m < 6 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 4); + } + if (m > 12 && m < 19 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 5); + } + + if (m > 34 && m < 38 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 6); + } + + if (m > 39 && m < 47 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 7); + } + + if (m > 61 && m < 70 ) + { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 8); + } + +#ifdef IPP2P_DEBUG_SOUL + 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); +#endif /* IPP2P_DEBUG_SOUL */ + } + + /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */ + /* without size at the beginning !!! */ + if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 ) + { + __u32 y=get_u32(payload, 5); + /* we need 19 chars + string */ + if ( (y + 19) <= (plen) ) + { + const unsigned char *w=payload+9+y; + if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00); +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "Soulssek special client command recognized\n"); +#endif /* IPP2P_DEBUG_SOUL */ + return ((IPP2P_SOUL * 100) + 9); + } + } + return 0; +} + + +/*Search for WinMX commands*/ +int +search_winmx (const unsigned char *payload, const u16 plen) +{ +//#define IPP2P_DEBUG_WINMX + if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1); + if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2); + //if (packet_len < (head_len + 10)) return 0; + if (plen < 10) return 0; + + if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){ + u16 c=4; + const u16 end=plen-2; + u8 count=0; + while (c < end) + { + if (payload[c]== 0x20 && payload[c+1] == 0x22) + { + c++; + count++; + if (count>=2) return ((IPP2P_WINMX * 100) + 3); + } + c++; + } + } + + if ( plen == 149 && payload[0] == '8' ) + { +#ifdef IPP2P_DEBUG_WINMX + printk(KERN_INFO "maybe WinMX\n"); +#endif + if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 && +// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) && +// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792)) + get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792)) + + { +#ifdef IPP2P_DEBUG_WINMX + printk(KERN_INFO "got WinMX\n"); +#endif + return ((IPP2P_WINMX * 100) + 4); + } + } + return 0; +} /*search_winmx*/ + + +/*Search for appleJuice commands*/ +int +search_apple (const unsigned char *payload, const u16 plen) +{ + if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100); + + return 0; +} + + +/*Search for BitTorrent commands*/ +int +search_bittorrent (const unsigned char *payload, const u16 plen) +{ + if (plen > 20) + { + /* test for match 0x13+"BitTorrent protocol" */ + if (payload[0] == 0x13) + { + if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100); + } + + /* get tracker commandos, all starts with GET / + * then it can follow: scrape| announce + * and then ?hash_info= + */ + if (memcmp(payload,"GET /",5) == 0) + { + /* message scrape */ + if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1); + /* message announce */ + if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2); + } + } + else + { + /* bitcomet encryptes the first packet, so we have to detect another + * one later in the flow */ + /* first try failed, too many missdetections */ + //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3); + + /* second try: block request packets */ + 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); + } + + return 0; +} + + + +/*check for Kazaa get command*/ +int +search_kazaa (const unsigned char *payload, const u16 plen) + +{ + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0) + return (IPP2P_DATA_KAZAA * 100); + + return 0; +} + + +/*check for gnutella get command*/ +int +search_gnu (const unsigned char *payload, const u16 plen) +{ + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) + { + if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1); + if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2); + } + return 0; +} + + +/*check for gnutella get commands and other typical data*/ +int +search_all_gnu (const unsigned char *payload, const u16 plen) +{ + + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) + { + + if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1); + if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2); + + + if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0)) + { + u16 c=8; + const u16 end=plen-22; + while (c < end) { + if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0))) + return ((IPP2P_GNU * 100) + 3); + c++; + } + } + } + return 0; +} + + +/*check for KaZaA download commands and other typical data*/ +int +search_all_kazaa (const unsigned char *payload, const u16 plen) +{ + if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) + { + + if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1); + + if (memcmp(payload, "GET /", 5) == 0) { + u16 c = 8; + const u16 end=plen-22; + while (c < end) { + 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))) + return ((IPP2P_KAZAA * 100) + 2); + c++; + } + } + } + return 0; +} + +/*fast check for edonkey file segment transfer command*/ +int +search_edk (const unsigned char *payload, const u16 plen) +{ + if (payload[0] != 0xe3) + return 0; + else { + if (payload[5] == 0x47) + return (IPP2P_DATA_EDK * 100); + else + return 0; + } +} + + + +/*intensive but slower search for some edonkey packets including size-check*/ +int +search_all_edk (const unsigned char *payload, const u16 plen) +{ + if (payload[0] != 0xe3) + return 0; + else { + //t += head_len; + const u16 cmd = get_u16(payload, 1); + if (cmd == (plen - 5)) { + switch (payload[5]) { + case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/ + case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/ + } + } + return 0; + } +} + + +/*fast check for Direct Connect send command*/ +int +search_dc (const unsigned char *payload, const u16 plen) +{ + + if (payload[0] != 0x24 ) + return 0; + else { + if (memcmp(&payload[1], "Send|", 5) == 0) + return (IPP2P_DATA_DC * 100); + else + return 0; + } + +} + + +/*intensive but slower check for all direct connect packets*/ +int +search_all_dc (const unsigned char *payload, const u16 plen) +{ +// unsigned char *t = haystack; + + if (payload[0] == 0x24 && payload[plen-1] == 0x7c) + { + const unsigned char *t=&payload[1]; + /* Client-Hub-Protocol */ + if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1); + /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */ + if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38); + } + return 0; +} + +/*check for mute*/ +int +search_mute (const unsigned char *payload, const u16 plen) +{ + if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 ) + { + //printk(KERN_DEBUG "size hit: %u",size); + if (memcmp(payload,"PublicKey: ",11) == 0 ) + { + return ((IPP2P_MUTE * 100) + 0); + +/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0) + { + printk(KERN_DEBUG "end pubic key hit: %u",size); + + }*/ + } + } + return 0; +} + + +/* check for xdcc */ +int +search_xdcc (const unsigned char *payload, const u16 plen) +{ + /* search in small packets only */ + if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0) + { + + u16 x=10; + const u16 end=plen - 13; + + /* is seems to be a irc private massage, chedck for xdcc command */ + while (x < end) + { + if (payload[x] == ':') + { + if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 ) + return ((IPP2P_XDCC * 100) + 0); + } + x++; + } + } + return 0; +} + +/* search for waste */ +int search_waste(const unsigned char *payload, const u16 plen) +{ + if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0) + return ((IPP2P_WASTE * 100) + 0); + + return 0; +} + + +static struct { + int command; + __u8 short_hand; /*for fucntions included in short hands*/ + int packet_len; + int (*function_name) (const unsigned char *, const u16); +} matchlist[] = { + {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk}, +// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa}, +// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk}, +// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc}, + {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc}, +// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu}, + {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu}, + {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa}, + {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent}, + {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple}, + {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul}, + {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx}, + {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares}, + {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute}, + {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste}, + {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc}, + {0,0,0,NULL} +}; + + +static struct { + int command; + __u8 short_hand; /*for fucntions included in short hands*/ + int packet_len; + int (*function_name) (unsigned char *, int); +} udp_list[] = { + {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa}, + {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit}, + {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu}, + {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk}, + {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect}, + {0,0,0,NULL} +}; + + +static int +match(const struct sk_buff *skb, + const struct net_device *in, + const struct net_device *out, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) + const struct xt_match *match, +#endif + const void *matchinfo, + int offset, + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + const void *hdr, + u_int16_t datalen, +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + unsigned int protoff, +#endif + + int *hotdrop) +{ + const struct ipt_p2p_info *info = matchinfo; + unsigned char *haystack; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) + struct iphdr *ip = ip_hdr(skb); +#else + struct iphdr *ip = skb->nh.iph; +#endif + int p2p_result = 0, i = 0; +// int head_len; + int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/ + + /*must not be a fragment*/ + if (offset) { + if (info->debug) printk("IPP2P.match: offset found %i \n",offset); + return 0; + } + + /*make sure that skb is linear*/ + if(skb_is_nonlinear(skb)){ + if (info->debug) printk("IPP2P.match: nonlinear skb found\n"); + return 0; + } + + + haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/ + + switch (ip->protocol){ + case IPPROTO_TCP: /*what to do with a TCP packet*/ + { + struct tcphdr *tcph = (void *) ip + ip->ihl * 4; + + if (tcph->fin) return 0; /*if FIN bit is set bail out*/ + if (tcph->syn) return 0; /*if SYN bit is set bail out*/ + if (tcph->rst) return 0; /*if RST bit is set bail out*/ + + haystack += tcph->doff * 4; /*get TCP-Header-Size*/ + hlen -= tcph->doff * 4; + while (matchlist[i].command) { + if ((((info->cmd & matchlist[i].command) == matchlist[i].command) || + ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) && + (hlen > matchlist[i].packet_len)) { + p2p_result = matchlist[i].function_name(haystack, hlen); + if (p2p_result) + { + if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", + p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen); + return p2p_result; + } + } + i++; + } + return p2p_result; + } + + case IPPROTO_UDP: /*what to do with an UDP packet*/ + { + struct udphdr *udph = (void *) ip + ip->ihl * 4; + + while (udp_list[i].command){ + if ((((info->cmd & udp_list[i].command) == udp_list[i].command) || + ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) && + (hlen > udp_list[i].packet_len)) { + p2p_result = udp_list[i].function_name(haystack, hlen); + if (p2p_result){ + if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", + p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen); + return p2p_result; + } + } + i++; + } + return p2p_result; + } + + default: return 0; + } +} + + + +static int +checkentry(const char *tablename, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + const void *ip, +#else + const struct ipt_ip *ip, +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) + const struct xt_match *match, +#endif + void *matchinfo, +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) + unsigned int matchsize, +#endif + unsigned int hook_mask) +{ + /* Must specify -p tcp */ +/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) { + * printk("ipp2p: Only works on TCP packets, use -p tcp\n"); + * return 0; + * }*/ + return 1; +} + + + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) +static struct xt_match ipp2p_match = { +#else +static struct ipt_match ipp2p_match = { +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + { NULL, NULL }, + "ipp2p", + &match, + &checkentry, + NULL, + THIS_MODULE +#endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + .name = "ipp2p", +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + .family = AF_INET, +#endif + .match = &match, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) + .matchsize = sizeof(struct ipt_p2p_info), +#endif + .checkentry = &checkentry, + .me = THIS_MODULE, +#endif +}; + + +static int __init init(void) +{ + printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + return xt_register_match(&ipp2p_match); +#else + return ipt_register_match(&ipp2p_match); +#endif +} + +static void __exit fini(void) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + xt_unregister_match(&ipp2p_match); +#else + ipt_unregister_match(&ipp2p_match); +#endif + printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION); +} + +module_init(init); +module_exit(fini); + + diff --git a/extensions/xt_ipp2p.h b/extensions/xt_ipp2p.h new file mode 100644 index 0000000..1bd3f64 --- /dev/null +++ b/extensions/xt_ipp2p.h @@ -0,0 +1,31 @@ +#ifndef __IPT_IPP2P_H +#define __IPT_IPP2P_H +#define IPP2P_VERSION "0.8.1_rc1" + +struct ipt_p2p_info { + int cmd; + int debug; +}; + +#endif //__IPT_IPP2P_H + +#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/ +//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/ +#define SHORT_HAND_NONE 5 /* no short hand*/ + +#define IPP2P_EDK (1 << 1) +#define IPP2P_DATA_KAZAA (1 << 2) +#define IPP2P_DATA_EDK (1 << 3) +#define IPP2P_DATA_DC (1 << 4) +#define IPP2P_DC (1 << 5) +#define IPP2P_DATA_GNU (1 << 6) +#define IPP2P_GNU (1 << 7) +#define IPP2P_KAZAA (1 << 8) +#define IPP2P_BIT (1 << 9) +#define IPP2P_APPLE (1 << 10) +#define IPP2P_SOUL (1 << 11) +#define IPP2P_WINMX (1 << 12) +#define IPP2P_ARES (1 << 13) +#define IPP2P_MUTE (1 << 14) +#define IPP2P_WASTE (1 << 15) +#define IPP2P_XDCC (1 << 16) diff --git a/mconfig b/mconfig index b78570e..38eedba 100644 --- a/mconfig +++ b/mconfig @@ -8,4 +8,5 @@ build_TARPIT=m build_TEE=m build_condition=m build_geoip=m +build_ipp2p=m build_portscan=m From edcbcee84e4d9b5f605a913ade19e4db16aec9f6 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 05:56:43 +0100 Subject: [PATCH 02/13] ipp2p: remove compat and obsolete code --- extensions/libxt_ipp2p.c | 33 ------------ extensions/xt_ipp2p.c | 112 --------------------------------------- 2 files changed, 145 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index 6fed3bc..98263a0 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -1,11 +1,9 @@ - #include #include #include #include #include #include - #include #include "xt_ipp2p.h" @@ -60,20 +58,6 @@ static struct option opts[] = { {0} }; - - -static void -init(struct xt_entry_match *m) -{ - struct ipt_p2p_info *info = (struct ipt_p2p_info *)m->data; - - /*init the module with default values*/ - info->cmd = 0; - info->debug = 0; - -} - - static int parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, @@ -121,7 +105,6 @@ parse(int c, char **argv, int invert, unsigned int *flags, info->cmd = *flags; break; - case '7': /*cmd: dc*/ if ((*flags & IPP2P_DC) == IPP2P_DC) exit_error(PARAMETER_PROBLEM, @@ -143,7 +126,6 @@ parse(int c, char **argv, int invert, unsigned int *flags, info->cmd = *flags; break; - case '9': /*cmd: gnu*/ if ((*flags & IPP2P_GNU) == IPP2P_GNU) exit_error(PARAMETER_PROBLEM, @@ -214,7 +196,6 @@ parse(int c, char **argv, int invert, unsigned int *flags, info->cmd = *flags; break; - case 'd': /*cmd: soul*/ if ((*flags & IPP2P_SOUL) == IPP2P_SOUL) exit_error(PARAMETER_PROBLEM, @@ -229,7 +210,6 @@ parse(int c, char **argv, int invert, unsigned int *flags, info->cmd = *flags; break; - case 'e': /*cmd: winmx*/ if ((*flags & IPP2P_WINMX) == IPP2P_WINMX) exit_error(PARAMETER_PROBLEM, @@ -299,7 +279,6 @@ parse(int c, char **argv, int invert, unsigned int *flags, return 1; } - static void final_check(unsigned int flags) { @@ -308,8 +287,6 @@ final_check(unsigned int flags) "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); } - - static void print(const void *ip, const struct xt_entry_match *match, @@ -340,8 +317,6 @@ print(const void *ip, printf(" "); } - - static void save(const void *ip, const struct xt_entry_match *match) { @@ -368,19 +343,14 @@ save(const void *ip, const struct xt_entry_match *match) if (info->debug != 0) printf("--debug "); } - - - static struct xtables_match ipp2p= { - .next = NULL, .name = "ipp2p", .version = XTABLES_VERSION, .size = XT_ALIGN(sizeof(struct ipt_p2p_info)), .userspacesize = XT_ALIGN(sizeof(struct ipt_p2p_info)), .help = &help, - .init = &init, .parse = &parse, .final_check = &final_check, .print = &print, @@ -388,10 +358,7 @@ struct xtables_match ipp2p= .extra_opts = opts }; - - void _init(void) { xtables_register_match(&ipp2p); } - diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index 5dc0a10..7584241 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -1,6 +1,3 @@ -#if defined(MODVERSIONS) -#include -#endif #include #include #include @@ -17,7 +14,6 @@ MODULE_AUTHOR("Eicke Friedrich/Klaus Degner "); MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic."); MODULE_LICENSE("GPL"); - /*Search for UDP eDonkey/eMule/Kad commands*/ int udp_search_edk (unsigned char *haystack, int packet_len) @@ -94,7 +90,6 @@ udp_search_edk (unsigned char *haystack, int packet_len) return 0; }/*udp_search_edk*/ - /*Search for UDP Gnutella commands*/ int udp_search_gnu (unsigned char *haystack, int packet_len) @@ -107,7 +102,6 @@ udp_search_gnu (unsigned char *haystack, int packet_len) return 0; }/*udp_search_gnu*/ - /*Search for UDP KaZaA commands*/ int udp_search_kazaa (unsigned char *haystack, int packet_len) @@ -135,8 +129,6 @@ udp_search_directconnect (unsigned char *haystack, int packet_len) return 0; }/*udp_search_directconnect*/ - - /*Search for UDP BitTorrent commands*/ int udp_search_bit (unsigned char *haystack, int packet_len) @@ -215,24 +207,17 @@ udp_search_bit (unsigned char *haystack, int packet_len) get_u32(haystack, 16) == 0x000d0000 && get_u32(haystack, 24) == 0x00000000 ) return (IPP2P_BIT * 100 + 71); - - } #endif return 0; }/*udp_search_bit*/ - - /*Search for Ares commands*/ //#define IPP2P_DEBUG_ARES int search_ares (const unsigned char *payload, const u16 plen) -//int search_ares (unsigned char *haystack, int packet_len, int head_len) { -// const unsigned char *t = haystack + head_len; - /* all ares packets start with */ if (payload[1] == 0 && (plen - payload[0]) == 3) { @@ -432,7 +417,6 @@ search_winmx (const unsigned char *payload, const u16 plen) return 0; } /*search_winmx*/ - /*Search for appleJuice commands*/ int search_apple (const unsigned char *payload, const u16 plen) @@ -442,7 +426,6 @@ search_apple (const unsigned char *payload, const u16 plen) return 0; } - /*Search for BitTorrent commands*/ int search_bittorrent (const unsigned char *payload, const u16 plen) @@ -481,12 +464,9 @@ search_bittorrent (const unsigned char *payload, const u16 plen) return 0; } - - /*check for Kazaa get command*/ int search_kazaa (const unsigned char *payload, const u16 plen) - { if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0) return (IPP2P_DATA_KAZAA * 100); @@ -494,7 +474,6 @@ search_kazaa (const unsigned char *payload, const u16 plen) return 0; } - /*check for gnutella get command*/ int search_gnu (const unsigned char *payload, const u16 plen) @@ -507,19 +486,15 @@ search_gnu (const unsigned char *payload, const u16 plen) return 0; } - /*check for gnutella get commands and other typical data*/ int search_all_gnu (const unsigned char *payload, const u16 plen) { - if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) { - if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1); if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2); - if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0)) { u16 c=8; @@ -534,7 +509,6 @@ search_all_gnu (const unsigned char *payload, const u16 plen) return 0; } - /*check for KaZaA download commands and other typical data*/ int search_all_kazaa (const unsigned char *payload, const u16 plen) @@ -571,8 +545,6 @@ search_edk (const unsigned char *payload, const u16 plen) } } - - /*intensive but slower search for some edonkey packets including size-check*/ int search_all_edk (const unsigned char *payload, const u16 plen) @@ -592,7 +564,6 @@ search_all_edk (const unsigned char *payload, const u16 plen) } } - /*fast check for Direct Connect send command*/ int search_dc (const unsigned char *payload, const u16 plen) @@ -609,13 +580,10 @@ search_dc (const unsigned char *payload, const u16 plen) } - /*intensive but slower check for all direct connect packets*/ int search_all_dc (const unsigned char *payload, const u16 plen) { -// unsigned char *t = haystack; - if (payload[0] == 0x24 && payload[plen-1] == 0x7c) { const unsigned char *t=&payload[1]; @@ -656,7 +624,6 @@ search_xdcc (const unsigned char *payload, const u16 plen) /* search in small packets only */ if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0) { - u16 x=10; const u16 end=plen - 13; @@ -683,7 +650,6 @@ int search_waste(const unsigned char *payload, const u16 plen) return 0; } - static struct { int command; __u8 short_hand; /*for fucntions included in short hands*/ @@ -709,7 +675,6 @@ static struct { {0,0,0,NULL} }; - static struct { int command; __u8 short_hand; /*for fucntions included in short hands*/ @@ -724,36 +689,20 @@ static struct { {0,0,0,NULL} }; - static int match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) const struct xt_match *match, -#endif const void *matchinfo, int offset, - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) - const void *hdr, - u_int16_t datalen, -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) unsigned int protoff, -#endif - int *hotdrop) { const struct ipt_p2p_info *info = matchinfo; unsigned char *haystack; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) struct iphdr *ip = ip_hdr(skb); -#else - struct iphdr *ip = skb->nh.iph; -#endif int p2p_result = 0, i = 0; -// int head_len; int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/ /*must not be a fragment*/ @@ -768,7 +717,6 @@ match(const struct sk_buff *skb, return 0; } - haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/ switch (ip->protocol){ @@ -823,83 +771,23 @@ match(const struct sk_buff *skb, } } - - -static int -checkentry(const char *tablename, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) - const void *ip, -#else - const struct ipt_ip *ip, -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) - const struct xt_match *match, -#endif - void *matchinfo, -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) - unsigned int matchsize, -#endif - unsigned int hook_mask) -{ - /* Must specify -p tcp */ -/* if (ip->proto != IPPROTO_TCP || (ip->invflags & IPT_INV_PROTO)) { - * printk("ipp2p: Only works on TCP packets, use -p tcp\n"); - * return 0; - * }*/ - return 1; -} - - - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) static struct xt_match ipp2p_match = { -#else -static struct ipt_match ipp2p_match = { -#endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) - { NULL, NULL }, - "ipp2p", - &match, - &checkentry, - NULL, - THIS_MODULE -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) .name = "ipp2p", -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) .family = AF_INET, -#endif .match = &match, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) .matchsize = sizeof(struct ipt_p2p_info), -#endif - .checkentry = &checkentry, .me = THIS_MODULE, -#endif }; - static int __init init(void) { - printk(KERN_INFO "IPP2P v%s loading\n", IPP2P_VERSION); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) return xt_register_match(&ipp2p_match); -#else - return ipt_register_match(&ipp2p_match); -#endif } static void __exit fini(void) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) xt_unregister_match(&ipp2p_match); -#else - ipt_unregister_match(&ipp2p_match); -#endif - printk(KERN_INFO "IPP2P v%s unloaded\n", IPP2P_VERSION); } module_init(init); module_exit(fini); - - From c237fe24863dacaf2aecb33322e1098ab8387730 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 06:53:08 +0100 Subject: [PATCH 03/13] ipp2p: adhere to codingstyle --- extensions/libxt_ipp2p.c | 576 ++++++++-------- extensions/xt_ipp2p.c | 1379 ++++++++++++++++++++------------------ 2 files changed, 1034 insertions(+), 921 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index 98263a0..42023a0 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -7,358 +7,398 @@ #include #include "xt_ipp2p.h" -static void -help(void) +static void ipp2p_mt_help(void) { - printf( - "IPP2P v%s options:\n" - " --ipp2p Grab all known p2p packets\n" - " --edk [TCP&UDP] All known eDonkey/eMule/Overnet packets\n" - " --dc [TCP] All known Direct Connect packets\n" - " --kazaa [TCP&UDP] All known KaZaA packets\n" - " --gnu [TCP&UDP] All known Gnutella packets\n" - " --bit [TCP&UDP] All known BitTorrent packets\n" - " --apple [TCP] All known AppleJuice packets\n" - " --winmx [TCP] All known WinMX\n" - " --soul [TCP] All known SoulSeek\n" - " --ares [TCP] All known Ares\n\n" - " EXPERIMENTAL protocols (please send feedback to: ipp2p@ipp2p.org) :\n" - " --mute [TCP] All known Mute packets\n" - " --waste [TCP] All known Waste packets\n" - " --xdcc [TCP] All known XDCC packets (only xdcc login)\n\n" - " DEBUG SUPPPORT, use only if you know why\n" - " --debug Generate kernel debug output, THIS WILL SLOW DOWN THE FILTER\n" - "\nNote that the follwing options will have the same meaning:\n" - " '--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares'\n" - "\nIPP2P was intended for TCP only. Due to increasing usage of UDP we needed to change this.\n" - "You can now use -p udp to search UDP packets only or without -p switch to search UDP and TCP packets.\n" - "\nSee README included with this package for more details or visit http://www.ipp2p.org\n" - "\nExamples:\n" - " iptables -A FORWARD -m ipp2p --ipp2p -j MARK --set-mark 0x01\n" - " iptables -A FORWARD -p udp -m ipp2p --kazaa --bit -j DROP\n" - " iptables -A FORWARD -p tcp -m ipp2p --edk --soul -j DROP\n\n" - , IPP2P_VERSION); + printf( + "IPP2P v%s options:\n" + " --ipp2p Grab all known p2p packets\n" + " --edk [tcp,udp] All known eDonkey/eMule/Overnet packets\n" + " --dc [tcp] All known Direct Connect packets\n" + " --kazaa [tcp,udp] All known KaZaA packets\n" + " --gnu [tcp,udp] All known Gnutella packets\n" + " --bit [tcp,udp] All known BitTorrent packets\n" + " --apple [tcp] All known AppleJuice packets\n" + " --winmx [tcp] All known WinMX\n" + " --soul [tcp] All known SoulSeek\n" + " --ares [tcp] All known Ares\n\n" + "EXPERIMENTAL protocols (please send feedback to: ipp2p@ipp2p.org) :\n" + " --mute [tcp] All known Mute packets\n" + " --waste [tcp] All known Waste packets\n" + " --xdcc [tcp] All known XDCC packets (only xdcc login)\n\n" + "DEBUG SUPPPORT, use only if you know why\n" + " --debug Generate kernel debug output, THIS WILL SLOW DOWN THE FILTER\n" + "\nNote that the follwing options will have the same meaning:\n" + " '--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares'\n" + "\nIPP2P was intended for TCP only. Due to increasing usage of UDP we needed to change this.\n" + "You can now use -p udp to search UDP packets only or without -p switch to search UDP and TCP packets.\n" + "\nSee README included with this package for more details or visit http://www.ipp2p.org\n" + "\nExamples:\n" + " iptables -A FORWARD -m ipp2p --ipp2p -j MARK --set-mark 0x01\n" + " iptables -A FORWARD -p udp -m ipp2p --kazaa --bit -j DROP\n" + " iptables -A FORWARD -p tcp -m ipp2p --edk --soul -j DROP\n\n" + , IPP2P_VERSION); } -static struct option opts[] = { - { "ipp2p", 0, 0, '1' }, - { "edk", 0, 0, '2' }, +static struct option ipp2p_mt_opts[] = { + { "ipp2p", 0, 0, '1' }, + { "edk", 0, 0, '2' }, { "dc", 0, 0, '7' }, { "gnu", 0, 0, '9' }, { "kazaa", 0, 0, 'a' }, { "bit", 0, 0, 'b' }, - { "apple", 0, 0, 'c' }, - { "soul", 0, 0, 'd' }, - { "winmx", 0, 0, 'e' }, + { "apple", 0, 0, 'c' }, + { "soul", 0, 0, 'd' }, + { "winmx", 0, 0, 'e' }, { "ares", 0, 0, 'f' }, { "mute", 0, 0, 'g' }, { "waste", 0, 0, 'h' }, { "xdcc", 0, 0, 'i' }, { "debug", 0, 0, 'j' }, - {0} + {0}, }; -static int -parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, - struct xt_entry_match **match) +static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, + const void *entry, struct xt_entry_match **match) { - struct ipt_p2p_info *info = (struct ipt_p2p_info *)(*match)->data; - - switch (c) { + struct ipt_p2p_info *info = (struct ipt_p2p_info *)(*match)->data; + + switch (c) { case '1': /*cmd: ipp2p*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p-data' may only be " "specified alone!");*/ - if ((*flags) != 0) - exit_error(PARAMETER_PROBLEM, + if ((*flags) != 0) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += SHORT_HAND_IPP2P; - info->cmd = *flags; - break; - + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += SHORT_HAND_IPP2P; + info->cmd = *flags; + break; + case '2': /*cmd: edk*/ - if ((*flags & IPP2P_EDK) == IPP2P_EDK) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_EDK) == IPP2P_EDK) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--edk' may only be " "specified once"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p-data' may only be " "specified alone!");*/ - if ((*flags & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) - exit_error(PARAMETER_PROBLEM, - "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_EDK; - info->cmd = *flags; - break; + if ((*flags & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_EDK; + info->cmd = *flags; + break; case '7': /*cmd: dc*/ - if ((*flags & IPP2P_DC) == IPP2P_DC) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--dc' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_DC) == IPP2P_DC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--dc' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p-data' may only be " "specified alone!");*/ - if ((*flags & IPP2P_DATA_DC) == IPP2P_DATA_DC) - exit_error(PARAMETER_PROBLEM, - "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_DC; - info->cmd = *flags; - break; + if ((*flags & IPP2P_DATA_DC) == IPP2P_DATA_DC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_DC; + info->cmd = *flags; + break; case '9': /*cmd: gnu*/ - if ((*flags & IPP2P_GNU) == IPP2P_GNU) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--gnu' may only be " - "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_GNU) == IPP2P_GNU) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--gnu' may only be " + "specified once!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p-data' may only be " "specified alone!");*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if ((*flags & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) - exit_error(PARAMETER_PROBLEM, - "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_GNU; - info->cmd = *flags; - break; + if ((*flags & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_GNU; + info->cmd = *flags; + break; case 'a': /*cmd: kazaa*/ - if ((*flags & IPP2P_KAZAA) == IPP2P_KAZAA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--kazaa' may only be " - "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_KAZAA) == IPP2P_KAZAA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--kazaa' may only be " + "specified once!"); +/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p-data' may only be " "specified alone!");*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if ((*flags & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_KAZAA; - info->cmd = *flags; - break; + if ((*flags & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) + exit_error(PARAMETER_PROBLEM, + "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_KAZAA; + info->cmd = *flags; + break; case 'b': /*cmd: bit*/ - if ((*flags & IPP2P_BIT) == IPP2P_BIT) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--bit' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_BIT) == IPP2P_BIT) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--bit' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_BIT; - info->cmd = *flags; - break; + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_BIT; + info->cmd = *flags; + break; case 'c': /*cmd: apple*/ - if ((*flags & IPP2P_APPLE) == IPP2P_APPLE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--apple' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_APPLE) == IPP2P_APPLE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--apple' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_APPLE; - info->cmd = *flags; - break; + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_APPLE; + info->cmd = *flags; + break; case 'd': /*cmd: soul*/ - if ((*flags & IPP2P_SOUL) == IPP2P_SOUL) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--soul' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_SOUL) == IPP2P_SOUL) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--soul' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_SOUL; - info->cmd = *flags; - break; + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_SOUL; + info->cmd = *flags; + break; case 'e': /*cmd: winmx*/ - if ((*flags & IPP2P_WINMX) == IPP2P_WINMX) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--winmx' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_WINMX) == IPP2P_WINMX) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--winmx' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_WINMX; - info->cmd = *flags; - break; + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_WINMX; + info->cmd = *flags; + break; case 'f': /*cmd: ares*/ - if ((*flags & IPP2P_ARES) == IPP2P_ARES) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ares' may only be " - "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, + if ((*flags & IPP2P_ARES) == IPP2P_ARES) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ares' may only be " + "specified once!"); + if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + exit_error(PARAMETER_PROBLEM, "ipp2p: `--ipp2p' may only be " "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_ARES; - info->cmd = *flags; - break; - + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_ARES; + info->cmd = *flags; + break; + case 'g': /*cmd: mute*/ - if ((*flags & IPP2P_MUTE) == IPP2P_MUTE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--mute' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_MUTE; - info->cmd = *flags; - break; + if ((*flags & IPP2P_MUTE) == IPP2P_MUTE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--mute' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_MUTE; + info->cmd = *flags; + break; case 'h': /*cmd: waste*/ - if ((*flags & IPP2P_WASTE) == IPP2P_WASTE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--waste' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_WASTE; - info->cmd = *flags; - break; + if ((*flags & IPP2P_WASTE) == IPP2P_WASTE) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--waste' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_WASTE; + info->cmd = *flags; + break; case 'i': /*cmd: xdcc*/ - if ((*flags & IPP2P_XDCC) == IPP2P_XDCC) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ares' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_XDCC; - info->cmd = *flags; - break; + if ((*flags & IPP2P_XDCC) == IPP2P_XDCC) + exit_error(PARAMETER_PROBLEM, + "ipp2p: `--ares' may only be " + "specified once!"); + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + *flags += IPP2P_XDCC; + info->cmd = *flags; + break; case 'j': /*cmd: debug*/ - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - info->debug = 1; - break; + if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + info->debug = 1; + break; default: -// exit_error(PARAMETER_PROBLEM, -// "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); - return 0; - } - return 1; +// exit_error(PARAMETER_PROBLEM, +// "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); + return 0; + } + return 1; +} + +static void ipp2p_mt_check(unsigned int flags) +{ + if (!flags) + exit_error(PARAMETER_PROBLEM, + "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); } static void -final_check(unsigned int flags) +ipp2p_mt_print(const void *entry, const struct xt_entry_match *match, + int numeric) { - if (!flags) - exit_error(PARAMETER_PROBLEM, - "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); + struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + + printf("ipp2p v%s", IPP2P_VERSION); + if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + printf(" --ipp2p"); +/* + if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) + printf(" --ipp2p-data"); +*/ + if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) + printf(" --kazaa"); +/* + if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) + printf(" --kazaa-data"); + if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) + printf(" --gnu-data"); +*/ + if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf(" --gnu"); + if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf(" --edk"); +/* + if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) + printf(" --edk-data"); + if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) + printf(" --dc-data"); +*/ + if ((info->cmd & IPP2P_DC) == IPP2P_DC) + printf(" --dc"); + if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) + printf(" --bit"); + if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) + printf(" --apple"); + if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) + printf(" --soul"); + if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) + printf(" --winmx"); + if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) + printf(" --ares"); + if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) + printf(" --mute"); + if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) + printf(" --waste"); + if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) + printf(" --xdcc"); + if (info->debug != 0) + printf(" --debug"); + printf(" "); } -static void -print(const void *ip, - const struct xt_entry_match *match, - int numeric) +static void ipp2p_mt_save(const void *entry, const struct xt_entry_match *match) { - struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; - - printf("ipp2p v%s", IPP2P_VERSION); - if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) printf(" --ipp2p"); -// if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) printf(" --ipp2p-data"); - if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) printf(" --kazaa"); -// if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) printf(" --kazaa-data"); -// if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) printf(" --gnu-data"); - if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf(" --gnu"); - if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf(" --edk"); -// if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) printf(" --edk-data"); -// if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) printf(" --dc-data"); - if ((info->cmd & IPP2P_DC) == IPP2P_DC) printf(" --dc"); - if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) printf(" --bit"); - if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) printf(" --apple"); - if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) printf(" --soul"); - if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) printf(" --winmx"); - if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) printf(" --ares"); - if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) printf(" --mute"); - if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) printf(" --waste"); - if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) printf(" --xdcc"); - if (info->debug != 0) printf(" --debug"); - printf(" "); -} - -static void -save(const void *ip, const struct xt_entry_match *match) -{ - struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; - - if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) printf("--ipp2p "); -// if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) printf("--ipp2p-data "); - if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) printf("--kazaa "); -// if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) printf("--kazaa-data "); -// if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) printf("--gnu-data "); - if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf("--gnu "); - if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf("--edk "); -// if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) printf("--edk-data "); -// if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) printf("--dc-data "); - if ((info->cmd & IPP2P_DC) == IPP2P_DC) printf("--dc "); - if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) printf("--bit "); - if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) printf("--apple "); - if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) printf("--soul "); - if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) printf("--winmx "); - if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) printf("--ares "); - if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) printf(" --mute"); - if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) printf(" --waste"); - if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) printf(" --xdcc"); - if (info->debug != 0) printf("--debug "); + struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + + if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) + printf("--ipp2p "); +/* + if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) + printf("--ipp2p-data "); +*/ + if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) + printf("--kazaa "); +/* if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) + printf("--kazaa-data "); + if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) + printf("--gnu-data "); +*/ + if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) + printf("--gnu "); + if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) + printf("--edk "); +/* if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) + printf("--edk-data "); + if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) + printf("--dc-data "); +*/ + if ((info->cmd & IPP2P_DC) == IPP2P_DC) + printf("--dc "); + if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) + printf("--bit "); + if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) + printf("--apple "); + if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) + printf("--soul "); + if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) + printf("--winmx "); + if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) + printf("--ares "); + if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) + printf(" --mute"); + if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) + printf(" --waste"); + if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) + printf(" --xdcc"); + if (info->debug != 0) + printf("--debug "); } -static -struct xtables_match ipp2p= -{ - .name = "ipp2p", - .version = XTABLES_VERSION, - .size = XT_ALIGN(sizeof(struct ipt_p2p_info)), - .userspacesize = XT_ALIGN(sizeof(struct ipt_p2p_info)), - .help = &help, - .parse = &parse, - .final_check = &final_check, - .print = &print, - .save = &save, - .extra_opts = opts +static struct xtables_match ipp2p_mt_reg = { + .version = XTABLES_VERSION, + .name = "ipp2p", + .revision = 0, + .family = AF_INET, + .size = XT_ALIGN(sizeof(struct ipt_p2p_info)), + .userspacesize = XT_ALIGN(sizeof(struct ipt_p2p_info)), + .help = ipp2p_mt_help, + .parse = ipp2p_mt_parse, + .final_check = ipp2p_mt_check, + .print = ipp2p_mt_print, + .save = ipp2p_mt_save, + .extra_opts = ipp2p_mt_opts, }; - + void _init(void) { - xtables_register_match(&ipp2p); + xtables_register_match(&ipp2p_mt_reg); } diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index 7584241..575792d 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -6,289 +6,336 @@ #include "xt_ipp2p.h" #include "compat_xtables.h" -#define get_u8(X,O) (*(__u8 *)(X + O)) -#define get_u16(X,O) (*(__u16 *)(X + O)) -#define get_u32(X,O) (*(__u32 *)(X + O)) +//#define IPP2P_DEBUG_ARES +//#define IPP2P_DEBUG_SOUL +//#define IPP2P_DEBUG_WINMX + +#define get_u8(X, O) (*(__u8 *)(X + O)) +#define get_u16(X, O) (*(__u16 *)(X + O)) +#define get_u32(X, O) (*(__u32 *)(X + O)) MODULE_AUTHOR("Eicke Friedrich/Klaus Degner "); MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic."); MODULE_LICENSE("GPL"); -/*Search for UDP eDonkey/eMule/Kad commands*/ -int -udp_search_edk (unsigned char *haystack, int packet_len) +/* Search for UDP eDonkey/eMule/Kad commands */ +int udp_search_edk(unsigned char *haystack, int packet_len) { - unsigned char *t = haystack; - t += 8; + unsigned char *t = haystack; + t += 8; switch (t[0]) { - case 0xe3: - { /*edonkey*/ - switch (t[1]) - { - /* client -> server status request */ - case 0x96: - if (packet_len == 14) return ((IPP2P_EDK * 100) + 50); - break; - /* server -> client status request */ - case 0x97: if (packet_len == 42) return ((IPP2P_EDK * 100) + 51); - break; - /* server description request */ - /* e3 2a ff f0 .. | size == 6 */ - case 0xa2: if ( (packet_len == 14) && ( get_u16(t,2) == __constant_htons(0xfff0) ) ) return ((IPP2P_EDK * 100) + 52); - break; - /* server description response */ - /* e3 a3 ff f0 .. | size > 40 && size < 200 */ - //case 0xa3: return ((IPP2P_EDK * 100) + 53); - // break; - case 0x9a: if (packet_len==26) return ((IPP2P_EDK * 100) + 54); - break; + case 0xe3: + /* edonkey */ + switch (t[1]) { + /* client -> server status request */ + case 0x96: + if (packet_len == 14) + return IPP2P_EDK * 100 + 50; + break; - case 0x92: if (packet_len==18) return ((IPP2P_EDK * 100) + 55); - break; - } + /* server -> client status request */ + case 0x97: + if (packet_len == 42) + return IPP2P_EDK * 100 + 51; + break; + + /* server description request */ + /* e3 2a ff f0 .. | size == 6 */ + case 0xa2: + if (packet_len == 14 && + get_u16(t, 2) == __constant_htons(0xfff0)) + return IPP2P_EDK * 100 + 52; + break; + + /* server description response */ + /* e3 a3 ff f0 .. | size > 40 && size < 200 */ + /* + case 0xa3: + return IPP2P_EDK * 100 + 53; + break; + */ + + case 0x9a: + if (packet_len == 26) + return IPP2P_EDK * 100 + 54; + break; + + case 0x92: + if (packet_len == 18) + return IPP2P_EDK * 100 + 55; break; } - case 0xe4: - { - switch (t[1]) - { - /* e4 20 .. | size == 43 */ - case 0x20: if ((packet_len == 43) && (t[2] != 0x00) && (t[34] != 0x00)) return ((IPP2P_EDK * 100) + 60); - break; - /* e4 00 .. 00 | size == 35 ? */ - case 0x00: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 61); - break; - /* e4 10 .. 00 | size == 35 ? */ - case 0x10: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 62); - break; - /* e4 18 .. 00 | size == 35 ? */ - case 0x18: if ((packet_len == 35) && (t[26] == 0x00)) return ((IPP2P_EDK * 100) + 63); - break; - /* e4 52 .. | size = 44 */ - case 0x52: if (packet_len == 44 ) return ((IPP2P_EDK * 100) + 64); - break; - /* e4 58 .. | size == 6 */ - case 0x58: if (packet_len == 14 ) return ((IPP2P_EDK * 100) + 65); - break; - /* e4 59 .. | size == 2 */ - case 0x59: if (packet_len == 10 )return ((IPP2P_EDK * 100) + 66); - break; - /* e4 28 .. | packet_len == 52,77,102,127... */ - case 0x28: if (((packet_len-52) % 25) == 0) return ((IPP2P_EDK * 100) + 67); - break; - /* e4 50 xx xx | size == 4 */ - case 0x50: if (packet_len == 12) return ((IPP2P_EDK * 100) + 68); - break; - /* e4 40 xx xx | size == 48 */ - case 0x40: if (packet_len == 56) return ((IPP2P_EDK * 100) + 69); - break; - } + break; + + case 0xe4: + switch (t[1]) { + /* e4 20 .. | size == 43 */ + case 0x20: + if (packet_len == 43 && t[2] != 0x00 && t[34] != 0x00) + return IPP2P_EDK * 100 + 60; + break; + + /* e4 00 .. 00 | size == 35 ? */ + case 0x00: + if (packet_len == 35 && t[26] == 0x00) + return IPP2P_EDK * 100 + 61; + break; + + /* e4 10 .. 00 | size == 35 ? */ + case 0x10: + if (packet_len == 35 && t[26] == 0x00) + return IPP2P_EDK * 100 + 62; + break; + + /* e4 18 .. 00 | size == 35 ? */ + case 0x18: + if (packet_len == 35 && t[26] == 0x00) + return IPP2P_EDK * 100 + 63; + break; + + /* e4 52 .. | size = 44 */ + case 0x52: + if (packet_len == 44) + return IPP2P_EDK * 100 + 64; + break; + + /* e4 58 .. | size == 6 */ + case 0x58: + if (packet_len == 14) + return IPP2P_EDK * 100 + 65; + break; + + /* e4 59 .. | size == 2 */ + case 0x59: + if (packet_len == 10) + return IPP2P_EDK * 100 + 66; + break; + + /* e4 28 .. | packet_len == 52,77,102,127... */ + case 0x28: + if ((packet_len - 52) % 25 == 0) + return IPP2P_EDK * 100 + 67; + break; + + /* e4 50 xx xx | size == 4 */ + case 0x50: + if (packet_len == 12) + return IPP2P_EDK * 100 + 68; + break; + + /* e4 40 xx xx | size == 48 */ + case 0x40: + if (packet_len == 56) + return IPP2P_EDK * 100 + 69; break; } - } /* end of switch (t[0]) */ - return 0; -}/*udp_search_edk*/ - -/*Search for UDP Gnutella commands*/ -int -udp_search_gnu (unsigned char *haystack, int packet_len) -{ - unsigned char *t = haystack; - t += 8; - - if (memcmp(t, "GND", 3) == 0) return ((IPP2P_GNU * 100) + 51); - if (memcmp(t, "GNUTELLA ", 9) == 0) return ((IPP2P_GNU * 100) + 52); - return 0; -}/*udp_search_gnu*/ - -/*Search for UDP KaZaA commands*/ -int -udp_search_kazaa (unsigned char *haystack, int packet_len) -{ - unsigned char *t = haystack; - - if (t[packet_len-1] == 0x00){ - t += (packet_len - 6); - if (memcmp(t, "KaZaA", 5) == 0) return (IPP2P_KAZAA * 100 +50); - } - - return 0; -}/*udp_search_kazaa*/ - -/*Search for UDP DirectConnect commands*/ -int -udp_search_directconnect (unsigned char *haystack, int packet_len) -{ - unsigned char *t = haystack; - if ((*(t + 8) == 0x24) && (*(t + packet_len - 1) == 0x7c)) { - t+=8; - if (memcmp(t, "SR ", 3) == 0) return ((IPP2P_DC * 100) + 60); - if (memcmp(t, "Ping ", 5) == 0) return ((IPP2P_DC * 100) + 61); - } - return 0; -}/*udp_search_directconnect*/ - -/*Search for UDP BitTorrent commands*/ -int -udp_search_bit (unsigned char *haystack, int packet_len) -{ - switch(packet_len) - { - case 24: - /* ^ 00 00 04 17 27 10 19 80 */ - if ((ntohl(get_u32(haystack, 8)) == 0x00000417) && (ntohl(get_u32(haystack, 12)) == 0x27101980)) - return (IPP2P_BIT * 100 + 50); - break; - case 44: - if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) - return (IPP2P_BIT * 100 + 51); - if (get_u32(haystack, 16) == __constant_htonl(0x00000400)) - return (IPP2P_BIT * 100 + 61); - break; - case 65: - if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) - return (IPP2P_BIT * 100 + 52); - if (get_u32(haystack, 16) == __constant_htonl(0x00000404)) - return (IPP2P_BIT * 100 + 62); - break; - case 67: - if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) - return (IPP2P_BIT * 100 + 53); - if (get_u32(haystack, 16) == __constant_htonl(0x00000406)) - return (IPP2P_BIT * 100 + 63); - break; - case 211: - if (get_u32(haystack, 8) == __constant_htonl(0x00000405)) - return (IPP2P_BIT * 100 + 54); - break; - case 29: - if ((get_u32(haystack, 8) == __constant_htonl(0x00000401))) - return (IPP2P_BIT * 100 + 55); - break; - case 52: - if (get_u32(haystack,8) == __constant_htonl(0x00000827) && - get_u32(haystack,12) == __constant_htonl(0x37502950)) - return (IPP2P_BIT * 100 + 80); - break; - default: - /* this packet does not have a constant size */ - if (packet_len >= 40 && get_u32(haystack, 16) == __constant_htonl(0x00000402) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) - return (IPP2P_BIT * 100 + 56); - break; + break; } - - /* some extra-bitcomet rules: - * "d1:" [a|r] "d2:id20:" - */ - if (packet_len > 30 && get_u8(haystack, 8) == 'd' && get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':' ) - { - if (get_u8(haystack, 11) == 'a' || get_u8(haystack, 11) == 'r') - { - if (memcmp(haystack+12,"d2:id20:",8)==0) - return (IPP2P_BIT * 100 + 57); - } + return 0; +} + +/* Search for UDP Gnutella commands */ +int udp_search_gnu(unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + t += 8; + + if (memcmp(t, "GND", 3) == 0) + return IPP2P_GNU * 100 + 51; + if (memcmp(t, "GNUTELLA ", 9) == 0) + return IPP2P_GNU * 100 + 52; + return 0; +} + +/* Search for UDP KaZaA commands */ +int udp_search_kazaa(unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + + if (t[packet_len-1] == 0x00) { + t += packet_len - 6; + if (memcmp(t, "KaZaA", 5) == 0) + return IPP2P_KAZAA * 100 + 50; } - + + return 0; +} + +/* Search for UDP DirectConnect commands */ +int udp_search_directconnect(unsigned char *haystack, int packet_len) +{ + unsigned char *t = haystack; + + if (*(t + 8) == 0x24 && *(t + packet_len - 1) == 0x7c) { + t += 8; + if (memcmp(t, "SR ", 3) == 0) + return IPP2P_DC * 100 + 60; + if (memcmp(t, "Ping ", 5) == 0) + return IPP2P_DC * 100 + 61; + } + return 0; +} + +/* Search for UDP BitTorrent commands */ +int udp_search_bit(unsigned char *haystack, int packet_len) +{ + switch (packet_len) { + case 24: + /* ^ 00 00 04 17 27 10 19 80 */ + if (ntohl(get_u32(haystack, 8)) == 0x00000417 && + ntohl(get_u32(haystack, 12)) == 0x27101980) + return IPP2P_BIT * 100 + 50; + break; + case 44: + if (get_u32(haystack, 16) == __constant_htonl(0x00000400) && + get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return IPP2P_BIT * 100 + 51; + if (get_u32(haystack, 16) == __constant_htonl(0x00000400)) + return IPP2P_BIT * 100 + 61; + break; + case 65: + if (get_u32(haystack, 16) == __constant_htonl(0x00000404) && + get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return IPP2P_BIT * 100 + 52; + if (get_u32(haystack, 16) == __constant_htonl(0x00000404)) + return IPP2P_BIT * 100 + 62; + break; + case 67: + if (get_u32(haystack, 16) == __constant_htonl(0x00000406) && get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return (IPP2P_BIT * 100 + 53); + if (get_u32(haystack, 16) == __constant_htonl(0x00000406)) + return (IPP2P_BIT * 100 + 63); + break; + case 211: + if (get_u32(haystack, 8) == __constant_htonl(0x00000405)) + return IPP2P_BIT * 100 + 54; + break; + case 29: + if (get_u32(haystack, 8) == __constant_htonl(0x00000401)) + return IPP2P_BIT * 100 + 55; + break; + case 52: + if (get_u32(haystack, 8) == __constant_htonl(0x00000827) && + get_u32(haystack, 12) == __constant_htonl(0x37502950)) + return IPP2P_BIT * 100 + 80; + break; + default: + /* this packet does not have a constant size */ + if (packet_len >= 40 && + get_u32(haystack, 16) == __constant_htonl(0x00000402) && + get_u32(haystack, 36) == __constant_htonl(0x00000104)) + return IPP2P_BIT * 100 + 56; + break; + } + + /* some extra-bitcomet rules: "d1:" [a|r] "d2:id20:" */ + if (packet_len > 30 && get_u8(haystack, 8) == 'd' && + get_u8(haystack, 9) == '1' && get_u8(haystack, 10) == ':') + if (get_u8(haystack, 11) == 'a' || + get_u8(haystack, 11) == 'r') + if (memcmp(haystack + 12, "d2:id20:", 8) == 0) + return IPP2P_BIT * 100 + 57; + #if 0 /* bitlord rules */ /* packetlen must be bigger than 40 */ /* first 4 bytes are zero */ - if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000) - { + if (packet_len > 40 && get_u32(haystack, 8) == 0x00000000) { /* first rule: 00 00 00 00 01 00 00 xx xx xx xx 00 00 00 00*/ - if (get_u32(haystack, 12) == 0x00000000 && + if (get_u32(haystack, 12) == 0x00000000 && get_u32(haystack, 16) == 0x00010000 && - get_u32(haystack, 24) == 0x00000000 ) - return (IPP2P_BIT * 100 + 71); - + get_u32(haystack, 24) == 0x00000000) + return IPP2P_BIT * 100 + 71; + /* 00 01 00 00 0d 00 00 xx xx xx xx 00 00 00 00*/ - if (get_u32(haystack, 12) == 0x00000001 && + if (get_u32(haystack, 12) == 0x00000001 && get_u32(haystack, 16) == 0x000d0000 && - get_u32(haystack, 24) == 0x00000000 ) - return (IPP2P_BIT * 100 + 71); + get_u32(haystack, 24) == 0x00000000) + return IPP2P_BIT * 100 + 71; } #endif - return 0; -}/*udp_search_bit*/ + return 0; +} -/*Search for Ares commands*/ -//#define IPP2P_DEBUG_ARES -int -search_ares (const unsigned char *payload, const u16 plen) +/* Search for Ares commands */ +int search_ares(const unsigned char *payload, const u16 plen) { /* all ares packets start with */ - if (payload[1] == 0 && (plen - payload[0]) == 3) - { - switch (payload[2]) - { - case 0x5a: - /* ares connect */ - if ( plen == 6 && payload[5] == 0x05 ) return ((IPP2P_ARES * 100) + 1); - break; - case 0x09: - /* ares search, min 3 chars --> 14 bytes - * lets define a search can be up to 30 chars --> max 34 bytes - */ - if ( plen >= 14 && plen <= 34 ) return ((IPP2P_ARES * 100) + 1); - break; + if (payload[1] == 0 && plen - payload[0] == 3) { + switch (payload[2]) { + case 0x5a: + /* ares connect */ + if (plen == 6 && payload[5] == 0x05) + return IPP2P_ARES * 100 + 1; + break; + case 0x09: + /* + * ares search, min 3 chars --> 14 bytes + * lets define a search can be up to 30 chars + * --> max 34 bytes + */ + if (plen >= 14 && plen <= 34) + return IPP2P_ARES * 100 + 1; + break; #ifdef IPP2P_DEBUG_ARES - default: - printk(KERN_DEBUG "Unknown Ares command %x recognized, len: %u \n", (unsigned int) payload[2],plen); -#endif /* IPP2P_DEBUG_ARES */ + default: + printk(KERN_DEBUG "Unknown Ares command %x " + "recognized, len: %u\n", + (unsigned int)payload[2], plen); +#endif } } -#if 0 +#if 0 /* found connect packet: 03 00 5a 04 03 05 */ /* new version ares 1.8: 03 00 5a xx xx 05 */ - if ((plen) == 6){ /* possible connect command*/ - if ((payload[0] == 0x03) && (payload[1] == 0x00) && (payload[2] == 0x5a) && (payload[5] == 0x05)) - return ((IPP2P_ARES * 100) + 1); - } - if ((plen) == 60){ /* possible download command*/ - if ((payload[59] == 0x0a) && (payload[58] == 0x0a)){ - if (memcmp(t, "PUSH SHA1:", 10) == 0) /* found download command */ - return ((IPP2P_ARES * 100) + 2); - } - } + if (plen == 6) + /* possible connect command */ + if (payload[0] == 0x03 && payload[1] == 0x00 && + payload[2] == 0x5a && payload[5] == 0x05) + return IPP2P_ARES * 100 + 1; + + if (plen == 60) + /* possible download command*/ + if (payload[59] == 0x0a && payload[58] == 0x0a) + if (memcmp(t, "PUSH SHA1:", 10) == 0) + /* found download command */ + return IPP2P_ARES * 100 + 2; #endif - return 0; -} /*search_ares*/ + return 0; +} -/*Search for SoulSeek commands*/ -int -search_soul (const unsigned char *payload, const u16 plen) +/* Search for SoulSeek commands */ +int search_soul(const unsigned char *payload, const u16 plen) { -//#define IPP2P_DEBUG_SOUL - /* match: xx xx xx xx | xx = sizeof(payload) - 4 */ - if (get_u32(payload, 0) == (plen - 4)){ - const __u32 m=get_u32(payload, 4); - /* match 00 yy yy 00, yy can be everything */ - if ( get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00 ) - { + /* match: xx xx xx xx | xx = sizeof(payload) - 4 */ + if (get_u32(payload, 0) == plen - 4) { + const __u32 m = get_u32(payload, 4); + /* match 00 yy yy 00, yy can be everything */ + if (get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00) { #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "0: Soulseek command 0x%x recognized\n",get_u32(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 1); - } - - /* next match: 01 yy 00 00 | yy can be everything */ - if ( get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000 ) - { + printk(KERN_DEBUG "0: Soulseek command 0x%x " + "recognized\n", get_u32(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 1; + } + + /* next match: 01 yy 00 00 | yy can be everything */ + if (get_u8(payload, 4) == 0x01 && get_u16(payload, 6) == 0x0000) { #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "1: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 2); - } - - /* 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 */ - /* try to do this in an intelligent way */ - /* get all small commandos */ - switch(m) - { + printk(KERN_DEBUG "1: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 2; + } + + /* 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 */ + /* try to do this in an intelligent way */ + /* get all small commandos */ + switch (m) { case 7: case 9: case 22: @@ -302,339 +349,364 @@ search_soul (const unsigned char *payload, const u16 plen) case 92: case 1001: #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "2: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 3); - } - - if (m > 0 && m < 6 ) - { -#ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "3: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 4); - } - if (m > 12 && m < 19 ) - { -#ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "4: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 5); - } + printk(KERN_DEBUG "2: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 3; + } - if (m > 34 && m < 38 ) - { + if (m > 0 && m < 6) { #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "5: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 6); - } + printk(KERN_DEBUG "3: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 4; + } - if (m > 39 && m < 47 ) - { + if (m > 12 && m < 19) { #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "6: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 7); - } + printk(KERN_DEBUG "4: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 5; + } - if (m > 61 && m < 70 ) - { + if (m > 34 && m < 38) { #ifdef IPP2P_DEBUG_SOUL - printk(KERN_DEBUG "7: Soulseek command 0x%x recognized\n",get_u16(payload, 4)); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 8); - } + printk(KERN_DEBUG "5: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 6; + } + + if (m > 39 && m < 47) { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "6: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 7; + } + + if (m > 61 && m < 70) { +#ifdef IPP2P_DEBUG_SOUL + printk(KERN_DEBUG "7: Soulseek command 0x%x " + "recognized\n", get_u16(payload, 4)); +#endif + return IPP2P_SOUL * 100 + 8; + } #ifdef IPP2P_DEBUG_SOUL - 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); -#endif /* IPP2P_DEBUG_SOUL */ - } - + 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); +#endif + } + /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */ /* without size at the beginning !!! */ - if ( get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01 ) - { - __u32 y=get_u32(payload, 5); + if (get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01) { + __u32 y = get_u32(payload, 5); /* we need 19 chars + string */ - if ( (y + 19) <= (plen) ) - { - const unsigned char *w=payload+9+y; - if (get_u32(w, 0) == 0x01 && ( get_u16(w, 4) == 0x4600 || get_u16(w, 4) == 0x5000) && get_u32(w, 6) == 0x00); + if (y + 19 <= plen) { + const unsigned char *w = payload + 9 + y; + if (get_u32(w, 0) == 0x01 && + (get_u16(w, 4) == 0x4600 || + get_u16(w, 4) == 0x5000) && + get_u32(w, 6) == 0x00) + ; #ifdef IPP2P_DEBUG_SOUL printk(KERN_DEBUG "Soulssek special client command recognized\n"); -#endif /* IPP2P_DEBUG_SOUL */ - return ((IPP2P_SOUL * 100) + 9); +#endif + return IPP2P_SOUL * 100 + 9; } } - return 0; + return 0; } - -/*Search for WinMX commands*/ -int -search_winmx (const unsigned char *payload, const u16 plen) +/* Search for WinMX commands */ +int search_winmx(const unsigned char *payload, const u16 plen) { -//#define IPP2P_DEBUG_WINMX - if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0)) return ((IPP2P_WINMX * 100) + 1); - if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0)) return ((IPP2P_WINMX * 100) + 2); - //if (packet_len < (head_len + 10)) return 0; - if (plen < 10) return 0; - - if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)){ - u16 c=4; - const u16 end=plen-2; - u8 count=0; - while (c < end) - { - if (payload[c]== 0x20 && payload[c+1] == 0x22) - { - c++; - count++; - if (count>=2) return ((IPP2P_WINMX * 100) + 3); - } - c++; - } - } - - if ( plen == 149 && payload[0] == '8' ) - { -#ifdef IPP2P_DEBUG_WINMX - printk(KERN_INFO "maybe WinMX\n"); -#endif - if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 && -// get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) && -// get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792)) - get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792)) - - { -#ifdef IPP2P_DEBUG_WINMX - printk(KERN_INFO "got WinMX\n"); -#endif - return ((IPP2P_WINMX * 100) + 4); - } - } - return 0; -} /*search_winmx*/ - -/*Search for appleJuice commands*/ -int -search_apple (const unsigned char *payload, const u16 plen) -{ - if ( (plen > 7) && (payload[6] == 0x0d) && (payload[7] == 0x0a) && (memcmp(payload, "ajprot", 6) == 0)) return (IPP2P_APPLE * 100); - - return 0; -} - -/*Search for BitTorrent commands*/ -int -search_bittorrent (const unsigned char *payload, const u16 plen) -{ - if (plen > 20) - { - /* test for match 0x13+"BitTorrent protocol" */ - if (payload[0] == 0x13) - { - if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100); - } - - /* get tracker commandos, all starts with GET / - * then it can follow: scrape| announce - * and then ?hash_info= + if (plen == 4 && memcmp(payload, "SEND", 4) == 0) + return IPP2P_WINMX * 100 + 1; + if (plen == 3 && memcmp(payload, "GET", 3) == 0) + return IPP2P_WINMX * 100 + 2; + /* + if (packet_len < head_len + 10) + return 0; */ - if (memcmp(payload,"GET /",5) == 0) - { - /* message scrape */ - if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1); - /* message announce */ - if ( memcmp(payload+5,"announce?info_hash=",19)==0 ) return (IPP2P_BIT * 100 + 2); - } - } - else - { - /* bitcomet encryptes the first packet, so we have to detect another - * one later in the flow */ - /* first try failed, too many missdetections */ - //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3); - - /* second try: block request packets */ - 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); - } + if (plen < 10) + return 0; - return 0; -} + if (memcmp(payload, "SEND", 4) == 0 || memcmp(payload, "GET", 3) == 0) { + u16 c = 4; + const u16 end = plen - 2; + u8 count = 0; -/*check for Kazaa get command*/ -int -search_kazaa (const unsigned char *payload, const u16 plen) -{ - if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a) && memcmp(payload, "GET /.hash=", 11) == 0) - return (IPP2P_DATA_KAZAA * 100); - - return 0; -} - -/*check for gnutella get command*/ -int -search_gnu (const unsigned char *payload, const u16 plen) -{ - if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) - { - if (memcmp(payload, "GET /get/", 9) == 0) return ((IPP2P_DATA_GNU * 100) + 1); - if (memcmp(payload, "GET /uri-res/", 13) == 0) return ((IPP2P_DATA_GNU * 100) + 2); - } - return 0; -} - -/*check for gnutella get commands and other typical data*/ -int -search_all_gnu (const unsigned char *payload, const u16 plen) -{ - if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) - { - if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) return ((IPP2P_GNU * 100) + 1); - if (memcmp(payload, "GNUTELLA/", 9) == 0) return ((IPP2P_GNU * 100) + 2); - - if ((memcmp(payload, "GET /get/", 9) == 0) || (memcmp(payload, "GET /uri-res/", 13) == 0)) - { - u16 c=8; - const u16 end=plen-22; while (c < end) { - if ( payload[c] == 0x0a && payload[c+1] == 0x0d && ((memcmp(&payload[c+2], "X-Gnutella-", 11) == 0) || (memcmp(&payload[c+2], "X-Queue:", 8) == 0))) - return ((IPP2P_GNU * 100) + 3); + if (payload[c] == 0x20 && payload[c+1] == 0x22) { + c++; + count++; + if (count >= 2) + return IPP2P_WINMX * 100 + 3; + } c++; } } - } - return 0; -} -/*check for KaZaA download commands and other typical data*/ -int -search_all_kazaa (const unsigned char *payload, const u16 plen) -{ - if ((payload[plen-2] == 0x0d) && (payload[plen-1] == 0x0a)) - { - - if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1); - - if (memcmp(payload, "GET /", 5) == 0) { - u16 c = 8; - const u16 end=plen-22; - while (c < end) { - 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))) - return ((IPP2P_KAZAA * 100) + 2); - c++; - } - } - } - return 0; -} - -/*fast check for edonkey file segment transfer command*/ -int -search_edk (const unsigned char *payload, const u16 plen) -{ - if (payload[0] != 0xe3) - return 0; - else { - if (payload[5] == 0x47) - return (IPP2P_DATA_EDK * 100); - else - return 0; - } -} - -/*intensive but slower search for some edonkey packets including size-check*/ -int -search_all_edk (const unsigned char *payload, const u16 plen) -{ - if (payload[0] != 0xe3) - return 0; - else { - //t += head_len; - const u16 cmd = get_u16(payload, 1); - if (cmd == (plen - 5)) { - switch (payload[5]) { - case 0x01: return ((IPP2P_EDK * 100) + 1); /*Client: hello or Server:hello*/ - case 0x4c: return ((IPP2P_EDK * 100) + 9); /*Client: Hello-Answer*/ - } - } - return 0; - } -} - -/*fast check for Direct Connect send command*/ -int -search_dc (const unsigned char *payload, const u16 plen) -{ - - if (payload[0] != 0x24 ) - return 0; - else { - if (memcmp(&payload[1], "Send|", 5) == 0) - return (IPP2P_DATA_DC * 100); - else - return 0; - } - -} - -/*intensive but slower check for all direct connect packets*/ -int -search_all_dc (const unsigned char *payload, const u16 plen) -{ - if (payload[0] == 0x24 && payload[plen-1] == 0x7c) - { - const unsigned char *t=&payload[1]; - /* Client-Hub-Protocol */ - if (memcmp(t, "Lock ", 5) == 0) return ((IPP2P_DC * 100) + 1); - /* Client-Client-Protocol, some are already recognized by client-hub (like lock) */ - if (memcmp(t, "MyNick ", 7) == 0) return ((IPP2P_DC * 100) + 38); - } - return 0; -} - -/*check for mute*/ -int -search_mute (const unsigned char *payload, const u16 plen) -{ - if ( plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121 ) - { - //printk(KERN_DEBUG "size hit: %u",size); - if (memcmp(payload,"PublicKey: ",11) == 0 ) - { - return ((IPP2P_MUTE * 100) + 0); - -/* if (memcmp(t+size-14,"\x0aEndPublicKey\x0a",14) == 0) - { - printk(KERN_DEBUG "end pubic key hit: %u",size); - - }*/ + if (plen == 149 && payload[0] == '8') { +#ifdef IPP2P_DEBUG_WINMX + printk(KERN_INFO "maybe WinMX\n"); +#endif + if (get_u32(payload, 17) == 0 && get_u32(payload, 21) == 0 && + get_u32(payload, 25) == 0 && +// get_u32(payload, 33) == __constant_htonl(0x71182b1a) && +// get_u32(payload, 37) == __constant_htonl(0x05050000) && +// get_u32(payload, 133) == __constant_htonl(0x31097edf) && +// get_u32(payload, 145) == __constant_htonl(0xdcb8f792)) + get_u16(payload, 39) == 0 && + get_u16(payload, 135) == __constant_htons(0x7edf) && + get_u16(payload,147) == __constant_htons(0xf792)) + { +#ifdef IPP2P_DEBUG_WINMX + printk(KERN_INFO "got WinMX\n"); +#endif + return IPP2P_WINMX * 100 + 4; } } return 0; } +/* Search for appleJuice commands */ +int search_apple(const unsigned char *payload, const u16 plen) +{ + if (plen > 7 && payload[6] == 0x0d && payload[7] == 0x0a && + memcmp(payload, "ajprot", 6) == 0) + return IPP2P_APPLE * 100; + + return 0; +} + +/* Search for BitTorrent commands */ +int search_bittorrent(const unsigned char *payload, const u16 plen) +{ + if (plen > 20) { + /* test for match 0x13+"BitTorrent protocol" */ + if (payload[0] == 0x13) + if (memcmp(payload + 1, "BitTorrent protocol", 19) == 0) + return IPP2P_BIT * 100; + + /* + * get tracker commandos, all starts with GET / + * then it can follow: scrape| announce + * and then ?hash_info= + */ + if (memcmp(payload, "GET /", 5) == 0) { + /* message scrape */ + if (memcmp(payload + 5, "scrape?info_hash=", 17) == 0) + return IPP2P_BIT * 100 + 1; + /* message announce */ + if (memcmp(payload + 5, "announce?info_hash=", 19) == 0) + return IPP2P_BIT * 100 + 2; + } + } else { + /* bitcomet encryptes the first packet, so we have to detect another + * one later in the flow */ + /* first try failed, too many missdetections */ + /* + if (size == 5 && get_u32(t, 0) == __constant_htonl(1) && + t[4] < 3) + return IPP2P_BIT * 100 + 3; + */ + + /* second try: block request packets */ + 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; + } + + return 0; +} + +/* check for Kazaa get command */ +int search_kazaa(const unsigned char *payload, const u16 plen) +{ + if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a && + memcmp(payload, "GET /.hash=", 11) == 0) + return IPP2P_DATA_KAZAA * 100; + + return 0; +} + +/* check for gnutella get command */ +int search_gnu(const unsigned char *payload, const u16 plen) +{ + if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { + if (memcmp(payload, "GET /get/", 9) == 0) + return IPP2P_DATA_GNU * 100 + 1; + if (memcmp(payload, "GET /uri-res/", 13) == 0) + return IPP2P_DATA_GNU * 100 + 2; + } + return 0; +} + +/* check for gnutella get commands and other typical data */ +int search_all_gnu(const unsigned char *payload, const u16 plen) +{ + if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { + if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) + return IPP2P_GNU * 100 + 1; + if (memcmp(payload, "GNUTELLA/", 9) == 0) + return IPP2P_GNU * 100 + 2; + + if (memcmp(payload, "GET /get/", 9) == 0 || + memcmp(payload, "GET /uri-res/", 13) == 0) + { + u16 c = 8; + const u16 end = plen - 22; + while (c < end) { + if (payload[c] == 0x0a && + payload[c+1] == 0x0d && + (memcmp(&payload[c+2], "X-Gnutella-", 11) == 0 || + memcmp(&payload[c+2], "X-Queue:", 8) == 0)) + return IPP2P_GNU * 100 + 3; + c++; + } + } + } + return 0; +} + +/* check for KaZaA download commands and other typical data */ +int search_all_kazaa(const unsigned char *payload, const u16 plen) +{ + if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { + if (memcmp(payload, "GIVE ", 5) == 0) + return IPP2P_KAZAA * 100 + 1; + + if (memcmp(payload, "GET /", 5) == 0) { + u16 c = 8; + const u16 end = plen - 22; + + while (c < end) { + 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)) + return IPP2P_KAZAA * 100 + 2; + c++; + } + } + } + return 0; +} + +/* fast check for edonkey file segment transfer command */ +int search_edk(const unsigned char *payload, const u16 plen) +{ + if (payload[0] != 0xe3) { + return 0; + } else { + if (payload[5] == 0x47) + return IPP2P_DATA_EDK * 100; + else + return 0; + } +} + +/* intensive but slower search for some edonkey packets including size-check */ +int search_all_edk(const unsigned char *payload, const u16 plen) +{ + if (payload[0] != 0xe3) { + return 0; + } else { + //t += head_len; + const u16 cmd = get_u16(payload, 1); + + if (cmd == plen - 5) { + switch (payload[5]) { + case 0x01: + /* Client: hello or Server:hello */ + return IPP2P_EDK * 100 + 1; + case 0x4c: + /* Client: Hello-Answer */ + return IPP2P_EDK * 100 + 9; + } + } + return 0; + } +} + +/* fast check for Direct Connect send command */ +int search_dc(const unsigned char *payload, const u16 plen) +{ + if (payload[0] != 0x24) { + return 0; + } else { + if (memcmp(&payload[1], "Send|", 5) == 0) + return IPP2P_DATA_DC * 100; + else + return 0; + } +} + +/* intensive but slower check for all direct connect packets */ +int search_all_dc(const unsigned char *payload, const u16 plen) +{ + if (payload[0] == 0x24 && payload[plen-1] == 0x7c) { + const unsigned char *t = &payload[1]; + + /* Client-Hub-Protocol */ + if (memcmp(t, "Lock ", 5) == 0) + return IPP2P_DC * 100 + 1; + + /* + * Client-Client-Protocol, some are already recognized by + * client-hub (like lock) + */ + if (memcmp(t, "MyNick ", 7) == 0) + return IPP2P_DC * 100 + 38; + } + return 0; +} + +/* check for mute */ +int search_mute(const unsigned char *payload, const u16 plen) +{ + if (plen == 209 || plen == 345 || plen == 473 || plen == 609 || + plen == 1121) { + //printk(KERN_DEBUG "size hit: %u", size); + if (memcmp(payload,"PublicKey: ", 11) == 0) { + return IPP2P_MUTE * 100 + 0; + /* + if (memcmp(t + size - 14, "\x0aEndPublicKey\x0a", 14) == 0) + printk(KERN_DEBUG "end pubic key hit: %u", size); + */ + } + } + return 0; +} /* check for xdcc */ -int -search_xdcc (const unsigned char *payload, const u16 plen) +int search_xdcc(const unsigned char *payload, const u16 plen) { /* search in small packets only */ - if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload,"PRIVMSG ",8) == 0) + if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && + payload[plen-2] == 0x0d && memcmp(payload, "PRIVMSG ", 8) == 0) { - u16 x=10; - const u16 end=plen - 13; - - /* is seems to be a irc private massage, chedck for xdcc command */ - while (x < end) - { + u16 x = 10; + const u16 end = plen - 13; + + /* + * is seems to be a irc private massage, chedck for + * xdcc command + */ + while (x < end) { if (payload[x] == ':') - { - if ( memcmp(&payload[x+1],"xdcc send #",11) == 0 ) - return ((IPP2P_XDCC * 100) + 0); - } + if (memcmp(&payload[x+1], "xdcc send #", 11) == 0) + return IPP2P_XDCC * 100 + 0; x++; } } @@ -644,150 +716,151 @@ search_xdcc (const unsigned char *payload, const u16 plen) /* search for waste */ int search_waste(const unsigned char *payload, const u16 plen) { - if ( plen >= 8 && memcmp(payload,"GET.sha1:",9) == 0) - return ((IPP2P_WASTE * 100) + 0); + if (plen >= 8 && memcmp(payload, "GET.sha1:", 9) == 0) + return IPP2P_WASTE * 100 + 0; return 0; } static struct { - int command; - __u8 short_hand; /*for fucntions included in short hands*/ - int packet_len; - int (*function_name) (const unsigned char *, const u16); + int command; + __u8 short_hand; /* for fucntions included in short hands */ + int packet_len; + int (*function_name)(const unsigned char *, const u16); } matchlist[] = { - {IPP2P_EDK,SHORT_HAND_IPP2P,20, &search_all_edk}, -// {IPP2P_DATA_KAZAA,SHORT_HAND_DATA,200, &search_kazaa}, -// {IPP2P_DATA_EDK,SHORT_HAND_DATA,60, &search_edk}, -// {IPP2P_DATA_DC,SHORT_HAND_DATA,26, &search_dc}, - {IPP2P_DC,SHORT_HAND_IPP2P,5, search_all_dc}, -// {IPP2P_DATA_GNU,SHORT_HAND_DATA,40, &search_gnu}, - {IPP2P_GNU,SHORT_HAND_IPP2P,5, &search_all_gnu}, - {IPP2P_KAZAA,SHORT_HAND_IPP2P,5, &search_all_kazaa}, - {IPP2P_BIT,SHORT_HAND_IPP2P,20, &search_bittorrent}, - {IPP2P_APPLE,SHORT_HAND_IPP2P,5, &search_apple}, - {IPP2P_SOUL,SHORT_HAND_IPP2P,5, &search_soul}, - {IPP2P_WINMX,SHORT_HAND_IPP2P,2, &search_winmx}, - {IPP2P_ARES,SHORT_HAND_IPP2P,5, &search_ares}, - {IPP2P_MUTE,SHORT_HAND_NONE,200, &search_mute}, - {IPP2P_WASTE,SHORT_HAND_NONE,5, &search_waste}, - {IPP2P_XDCC,SHORT_HAND_NONE,5, &search_xdcc}, - {0,0,0,NULL} + {IPP2P_EDK, SHORT_HAND_IPP2P, 20, search_all_edk}, +// {IPP2P_DATA_KAZAA, SHORT_HAND_DATA, 200, search_kazaa}, +// {IPP2P_DATA_EDK, SHORT_HAND_DATA, 60, search_edk}, +// {IPP2P_DATA_DC, SHORT_HAND_DATA, 26, search_dc}, + {IPP2P_DC, SHORT_HAND_IPP2P, 5, search_all_dc}, +// {IPP2P_DATA_GNU, SHORT_HAND_DATA, 40, search_gnu}, + {IPP2P_GNU, SHORT_HAND_IPP2P, 5, search_all_gnu}, + {IPP2P_KAZAA, SHORT_HAND_IPP2P, 5, search_all_kazaa}, + {IPP2P_BIT, SHORT_HAND_IPP2P, 20, search_bittorrent}, + {IPP2P_APPLE, SHORT_HAND_IPP2P, 5, search_apple}, + {IPP2P_SOUL, SHORT_HAND_IPP2P, 5, search_soul}, + {IPP2P_WINMX, SHORT_HAND_IPP2P, 2, search_winmx}, + {IPP2P_ARES, SHORT_HAND_IPP2P, 5, search_ares}, + {IPP2P_MUTE, SHORT_HAND_NONE, 200, search_mute}, + {IPP2P_WASTE, SHORT_HAND_NONE, 5, search_waste}, + {IPP2P_XDCC, SHORT_HAND_NONE, 5, search_xdcc}, + {0}, }; static struct { - int command; - __u8 short_hand; /*for fucntions included in short hands*/ - int packet_len; - int (*function_name) (unsigned char *, int); + int command; + __u8 short_hand; /* for fucntions included in short hands */ + int packet_len; + int (*function_name)(unsigned char *, int); } udp_list[] = { - {IPP2P_KAZAA,SHORT_HAND_IPP2P,14, &udp_search_kazaa}, - {IPP2P_BIT,SHORT_HAND_IPP2P,23, &udp_search_bit}, - {IPP2P_GNU,SHORT_HAND_IPP2P,11, &udp_search_gnu}, - {IPP2P_EDK,SHORT_HAND_IPP2P,9, &udp_search_edk}, - {IPP2P_DC,SHORT_HAND_IPP2P,12, &udp_search_directconnect}, - {0,0,0,NULL} + {IPP2P_KAZAA, SHORT_HAND_IPP2P, 14, udp_search_kazaa}, + {IPP2P_BIT, SHORT_HAND_IPP2P, 23, udp_search_bit}, + {IPP2P_GNU, SHORT_HAND_IPP2P, 11, udp_search_gnu}, + {IPP2P_EDK, SHORT_HAND_IPP2P, 9, udp_search_edk}, + {IPP2P_DC, SHORT_HAND_IPP2P, 12, udp_search_directconnect}, + {0}, }; static int -match(const struct sk_buff *skb, - const struct net_device *in, - const struct net_device *out, - const struct xt_match *match, - const void *matchinfo, - int offset, - unsigned int protoff, - int *hotdrop) +match(const struct sk_buff *skb, const struct net_device *in, + const struct net_device *out, const struct xt_match *match, + const void *matchinfo, int offset, unsigned int protoff, int *hotdrop) { - const struct ipt_p2p_info *info = matchinfo; - unsigned char *haystack; - struct iphdr *ip = ip_hdr(skb); - int p2p_result = 0, i = 0; - int hlen = ntohs(ip->tot_len)-(ip->ihl*4); /*hlen = packet-data length*/ + const struct ipt_p2p_info *info = matchinfo; + unsigned char *haystack; + struct iphdr *ip = ip_hdr(skb); + int p2p_result = 0, i = 0; + int hlen = ntohs(ip->tot_len) - ip->ihl * 4; /* hlen = packet-data length */ - /*must not be a fragment*/ - if (offset) { - if (info->debug) printk("IPP2P.match: offset found %i \n",offset); - return 0; - } - - /*make sure that skb is linear*/ - if(skb_is_nonlinear(skb)){ - if (info->debug) printk("IPP2P.match: nonlinear skb found\n"); - return 0; - } - - haystack=(char *)ip+(ip->ihl*4); /*haystack = packet data*/ - - switch (ip->protocol){ - case IPPROTO_TCP: /*what to do with a TCP packet*/ - { - struct tcphdr *tcph = (void *) ip + ip->ihl * 4; - - if (tcph->fin) return 0; /*if FIN bit is set bail out*/ - if (tcph->syn) return 0; /*if SYN bit is set bail out*/ - if (tcph->rst) return 0; /*if RST bit is set bail out*/ - - haystack += tcph->doff * 4; /*get TCP-Header-Size*/ - hlen -= tcph->doff * 4; - while (matchlist[i].command) { - if ((((info->cmd & matchlist[i].command) == matchlist[i].command) || - ((info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand)) && - (hlen > matchlist[i].packet_len)) { - p2p_result = matchlist[i].function_name(haystack, hlen); - if (p2p_result) - { - if (info->debug) printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", - p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen); - return p2p_result; - } - } - i++; - } - return p2p_result; + /* must not be a fragment */ + if (offset != 0) { + if (info->debug) + printk("IPP2P.match: offset found %i \n", offset); + return 0; } - - case IPPROTO_UDP: /*what to do with an UDP packet*/ + + /* make sure that skb is linear */ + if (skb_is_nonlinear(skb)) { + if (info->debug) + printk("IPP2P.match: nonlinear skb found\n"); + return 0; + } + + haystack = (char *)ip + ip->ihl * 4; /* haystack = packet data */ + + switch (ip->protocol) { + case IPPROTO_TCP: /* what to do with a TCP packet */ { - struct udphdr *udph = (void *) ip + ip->ihl * 4; - - while (udp_list[i].command){ - if ((((info->cmd & udp_list[i].command) == udp_list[i].command) || - ((info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand)) && - (hlen > udp_list[i].packet_len)) { - p2p_result = udp_list[i].function_name(haystack, hlen); - if (p2p_result){ - if (info->debug) printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", - p2p_result, NIPQUAD(ip->saddr),ntohs(udph->source), NIPQUAD(ip->daddr),ntohs(udph->dest),hlen); - return p2p_result; - } + struct tcphdr *tcph = (void *)ip + ip->ihl * 4; + + if (tcph->fin) return 0; /* if FIN bit is set bail out */ + if (tcph->syn) return 0; /* if SYN bit is set bail out */ + if (tcph->rst) return 0; /* if RST bit is set bail out */ + + haystack += tcph->doff * 4; /* get TCP-Header-Size */ + hlen -= tcph->doff * 4; + while (matchlist[i].command) { + if (((info->cmd & matchlist[i].command) == matchlist[i].command || + (info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand) && + hlen > matchlist[i].packet_len) + { + p2p_result = matchlist[i].function_name(haystack, hlen); + if (p2p_result) { + if (info->debug) + printk("IPP2P.debug:TCP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", + p2p_result, NIPQUAD(ip->saddr),ntohs(tcph->source), NIPQUAD(ip->daddr),ntohs(tcph->dest),hlen); + return p2p_result; + } + } + i++; } - i++; - } - return p2p_result; + return p2p_result; + } + + case IPPROTO_UDP: /* what to do with an UDP packet */ + { + struct udphdr *udph = (void *)ip + ip->ihl * 4; + + while (udp_list[i].command) { + if (((info->cmd & udp_list[i].command) == udp_list[i].command || + (info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand) && + hlen > udp_list[i].packet_len) + { + p2p_result = udp_list[i].function_name(haystack, hlen); + if (p2p_result) { + if (info->debug) + printk("IPP2P.debug:UDP-match: %i from: %u.%u.%u.%u:%i to: %u.%u.%u.%u:%i Length: %i\n", + p2p_result, NIPQUAD(ip->saddr), ntohs(udph->source), NIPQUAD(ip->daddr), ntohs(udph->dest), hlen); + return p2p_result; + } + } + i++; + } + return p2p_result; + } + + default: + return 0; } - - default: return 0; - } } static struct xt_match ipp2p_match = { - .name = "ipp2p", - .family = AF_INET, - .match = &match, - .matchsize = sizeof(struct ipt_p2p_info), - .me = THIS_MODULE, + .name = "ipp2p", + .family = AF_INET, + .match = &match, + .matchsize = sizeof(struct ipt_p2p_info), + .me = THIS_MODULE, }; static int __init init(void) { - return xt_register_match(&ipp2p_match); + return xt_register_match(&ipp2p_match); } - + static void __exit fini(void) { - xt_unregister_match(&ipp2p_match); + xt_unregister_match(&ipp2p_match); } - + module_init(init); module_exit(fini); From cc23d0a2e79c83ed86b6facafc2cd9358c641c1f Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 07:21:55 +0100 Subject: [PATCH 04/13] ipp2p: fix match function signature --- extensions/xt_ipp2p.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index 575792d..79513ca 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -761,10 +761,10 @@ static struct { {0}, }; -static int -match(const struct sk_buff *skb, const struct net_device *in, - const struct net_device *out, const struct xt_match *match, - const void *matchinfo, int offset, unsigned int protoff, int *hotdrop) +static bool +ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, + const struct net_device *out, const struct xt_match *match, + const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop) { const struct ipt_p2p_info *info = matchinfo; unsigned char *haystack; @@ -844,23 +844,24 @@ match(const struct sk_buff *skb, const struct net_device *in, } } -static struct xt_match ipp2p_match = { +static struct xt_match ipp2p_mt_reg __read_mostly = { .name = "ipp2p", + .revision = 0, .family = AF_INET, - .match = &match, + .match = ipp2p_mt, .matchsize = sizeof(struct ipt_p2p_info), .me = THIS_MODULE, }; -static int __init init(void) +static int __init ipp2p_mt_init(void) { - return xt_register_match(&ipp2p_match); + return xt_register_match(&ipp2p_mt_reg); } -static void __exit fini(void) +static void __exit ipp2p_mt_exit(void) { - xt_unregister_match(&ipp2p_match); + xt_unregister_match(&ipp2p_mt_reg); } -module_init(init); -module_exit(fini); +module_init(ipp2p_mt_init); +module_exit(ipp2p_mt_exit); From 569643ac8c258089f2f85df95a7415db0da77549 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 06:55:15 +0100 Subject: [PATCH 05/13] ipp2p: static and const annotations, type usage --- extensions/libxt_ipp2p.c | 8 +-- extensions/xt_ipp2p.c | 129 +++++++++++++++++++++++---------------- 2 files changed, 81 insertions(+), 56 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index 42023a0..4994dc0 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -39,7 +39,7 @@ static void ipp2p_mt_help(void) , IPP2P_VERSION); } -static struct option ipp2p_mt_opts[] = { +static const struct option ipp2p_mt_opts[] = { { "ipp2p", 0, 0, '1' }, { "edk", 0, 0, '2' }, { "dc", 0, 0, '7' }, @@ -287,7 +287,7 @@ static void ipp2p_mt_print(const void *entry, const struct xt_entry_match *match, int numeric) { - struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + const struct ipt_p2p_info *info = (const void *)match->data; printf("ipp2p v%s", IPP2P_VERSION); if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) @@ -337,7 +337,7 @@ ipp2p_mt_print(const void *entry, const struct xt_entry_match *match, static void ipp2p_mt_save(const void *entry, const struct xt_entry_match *match) { - struct ipt_p2p_info *info = (struct ipt_p2p_info *)match->data; + const struct ipt_p2p_info *info = (const void *)match->data; if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) printf("--ipp2p "); @@ -398,7 +398,7 @@ static struct xtables_match ipp2p_mt_reg = { .extra_opts = ipp2p_mt_opts, }; -void _init(void) +static void _init(void) { xtables_register_match(&ipp2p_mt_reg); } diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index 79513ca..e52dfda 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -19,9 +19,10 @@ MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic."); MODULE_LICENSE("GPL"); /* Search for UDP eDonkey/eMule/Kad commands */ -int udp_search_edk(unsigned char *haystack, int packet_len) +static unsigned int +udp_search_edk(const unsigned char *haystack, const unsigned int packet_len) { - unsigned char *t = haystack; + const unsigned char *t = haystack; t += 8; switch (t[0]) { @@ -136,9 +137,10 @@ int udp_search_edk(unsigned char *haystack, int packet_len) } /* Search for UDP Gnutella commands */ -int udp_search_gnu(unsigned char *haystack, int packet_len) +static unsigned int +udp_search_gnu(const unsigned char *haystack, const unsigned int packet_len) { - unsigned char *t = haystack; + const unsigned char *t = haystack; t += 8; if (memcmp(t, "GND", 3) == 0) @@ -149,9 +151,10 @@ int udp_search_gnu(unsigned char *haystack, int packet_len) } /* Search for UDP KaZaA commands */ -int udp_search_kazaa(unsigned char *haystack, int packet_len) +static unsigned int +udp_search_kazaa(const unsigned char *haystack, const unsigned int packet_len) { - unsigned char *t = haystack; + const unsigned char *t = haystack; if (t[packet_len-1] == 0x00) { t += packet_len - 6; @@ -163,9 +166,10 @@ int udp_search_kazaa(unsigned char *haystack, int packet_len) } /* Search for UDP DirectConnect commands */ -int udp_search_directconnect(unsigned char *haystack, int packet_len) +static unsigned int udp_search_directconnect(const unsigned char *haystack, + const unsigned int packet_len) { - unsigned char *t = haystack; + const unsigned char *t = haystack; if (*(t + 8) == 0x24 && *(t + packet_len - 1) == 0x7c) { t += 8; @@ -178,7 +182,8 @@ int udp_search_directconnect(unsigned char *haystack, int packet_len) } /* Search for UDP BitTorrent commands */ -int udp_search_bit(unsigned char *haystack, int packet_len) +static unsigned int +udp_search_bit(const unsigned char *haystack, const unsigned int packet_len) { switch (packet_len) { case 24: @@ -260,7 +265,8 @@ int udp_search_bit(unsigned char *haystack, int packet_len) } /* Search for Ares commands */ -int search_ares(const unsigned char *payload, const u16 plen) +static unsigned int +search_ares(const unsigned char *payload, const unsigned int plen) { /* all ares packets start with */ if (payload[1] == 0 && plen - payload[0] == 3) { @@ -309,11 +315,13 @@ int search_ares(const unsigned char *payload, const u16 plen) } /* Search for SoulSeek commands */ -int search_soul(const unsigned char *payload, const u16 plen) +static unsigned int +search_soul(const unsigned char *payload, const unsigned int plen) { /* match: xx xx xx xx | xx = sizeof(payload) - 4 */ if (get_u32(payload, 0) == plen - 4) { - const __u32 m = get_u32(payload, 4); + const uint32_t m = get_u32(payload, 4); + /* match 00 yy yy 00, yy can be everything */ if (get_u8(payload, 4) == 0x00 && get_u8(payload, 7) == 0x00) { #ifdef IPP2P_DEBUG_SOUL @@ -406,7 +414,8 @@ int search_soul(const unsigned char *payload, const u16 plen) /* match 14 00 00 00 01 yy 00 00 00 STRING(YY) 01 00 00 00 00 46|50 00 00 00 00 */ /* without size at the beginning !!! */ if (get_u32(payload, 0) == 0x14 && get_u8(payload, 4) == 0x01) { - __u32 y = get_u32(payload, 5); + uint32_t y = get_u32(payload, 5); + /* we need 19 chars + string */ if (y + 19 <= plen) { const unsigned char *w = payload + 9 + y; @@ -425,7 +434,8 @@ int search_soul(const unsigned char *payload, const u16 plen) } /* Search for WinMX commands */ -int search_winmx(const unsigned char *payload, const u16 plen) +static unsigned int +search_winmx(const unsigned char *payload, const unsigned int plen) { if (plen == 4 && memcmp(payload, "SEND", 4) == 0) return IPP2P_WINMX * 100 + 1; @@ -439,9 +449,9 @@ int search_winmx(const unsigned char *payload, const u16 plen) return 0; if (memcmp(payload, "SEND", 4) == 0 || memcmp(payload, "GET", 3) == 0) { - u16 c = 4; - const u16 end = plen - 2; - u8 count = 0; + uint16_t c = 4; + const uint16_t end = plen - 2; + uint8_t count = 0; while (c < end) { if (payload[c] == 0x20 && payload[c+1] == 0x22) { @@ -478,7 +488,8 @@ int search_winmx(const unsigned char *payload, const u16 plen) } /* Search for appleJuice commands */ -int search_apple(const unsigned char *payload, const u16 plen) +static unsigned int +search_apple(const unsigned char *payload, const unsigned int plen) { if (plen > 7 && payload[6] == 0x0d && payload[7] == 0x0a && memcmp(payload, "ajprot", 6) == 0) @@ -488,7 +499,8 @@ int search_apple(const unsigned char *payload, const u16 plen) } /* Search for BitTorrent commands */ -int search_bittorrent(const unsigned char *payload, const u16 plen) +static unsigned int +search_bittorrent(const unsigned char *payload, const unsigned int plen) { if (plen > 20) { /* test for match 0x13+"BitTorrent protocol" */ @@ -531,7 +543,8 @@ int search_bittorrent(const unsigned char *payload, const u16 plen) } /* check for Kazaa get command */ -int search_kazaa(const unsigned char *payload, const u16 plen) +static unsigned int +search_kazaa(const unsigned char *payload, const unsigned int plen) { if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a && memcmp(payload, "GET /.hash=", 11) == 0) @@ -541,7 +554,8 @@ int search_kazaa(const unsigned char *payload, const u16 plen) } /* check for gnutella get command */ -int search_gnu(const unsigned char *payload, const u16 plen) +static unsigned int +search_gnu(const unsigned char *payload, const unsigned int plen) { if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { if (memcmp(payload, "GET /get/", 9) == 0) @@ -553,7 +567,8 @@ int search_gnu(const unsigned char *payload, const u16 plen) } /* check for gnutella get commands and other typical data */ -int search_all_gnu(const unsigned char *payload, const u16 plen) +static unsigned int +search_all_gnu(const unsigned char *payload, const unsigned int plen) { if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { if (memcmp(payload, "GNUTELLA CONNECT/", 17) == 0) @@ -564,8 +579,9 @@ int search_all_gnu(const unsigned char *payload, const u16 plen) if (memcmp(payload, "GET /get/", 9) == 0 || memcmp(payload, "GET /uri-res/", 13) == 0) { - u16 c = 8; - const u16 end = plen - 22; + uint16_t c = 8; + const uint16_t end = plen - 22; + while (c < end) { if (payload[c] == 0x0a && payload[c+1] == 0x0d && @@ -580,15 +596,16 @@ int search_all_gnu(const unsigned char *payload, const u16 plen) } /* check for KaZaA download commands and other typical data */ -int search_all_kazaa(const unsigned char *payload, const u16 plen) +static unsigned int +search_all_kazaa(const unsigned char *payload, const unsigned int plen) { if (payload[plen-2] == 0x0d && payload[plen-1] == 0x0a) { if (memcmp(payload, "GIVE ", 5) == 0) return IPP2P_KAZAA * 100 + 1; if (memcmp(payload, "GET /", 5) == 0) { - u16 c = 8; - const u16 end = plen - 22; + uint16_t c = 8; + const uint16_t end = plen - 22; while (c < end) { if (payload[c] == 0x0a && @@ -604,7 +621,8 @@ int search_all_kazaa(const unsigned char *payload, const u16 plen) } /* fast check for edonkey file segment transfer command */ -int search_edk(const unsigned char *payload, const u16 plen) +static unsigned int +search_edk(const unsigned char *payload, const unsigned int plen) { if (payload[0] != 0xe3) { return 0; @@ -617,13 +635,14 @@ int search_edk(const unsigned char *payload, const u16 plen) } /* intensive but slower search for some edonkey packets including size-check */ -int search_all_edk(const unsigned char *payload, const u16 plen) +static unsigned int +search_all_edk(const unsigned char *payload, const unsigned int plen) { if (payload[0] != 0xe3) { return 0; } else { //t += head_len; - const u16 cmd = get_u16(payload, 1); + const uint16_t cmd = get_u16(payload, 1); if (cmd == plen - 5) { switch (payload[5]) { @@ -640,7 +659,8 @@ int search_all_edk(const unsigned char *payload, const u16 plen) } /* fast check for Direct Connect send command */ -int search_dc(const unsigned char *payload, const u16 plen) +static unsigned int +search_dc(const unsigned char *payload, const unsigned int plen) { if (payload[0] != 0x24) { return 0; @@ -653,7 +673,8 @@ int search_dc(const unsigned char *payload, const u16 plen) } /* intensive but slower check for all direct connect packets */ -int search_all_dc(const unsigned char *payload, const u16 plen) +static unsigned int +search_all_dc(const unsigned char *payload, const unsigned int plen) { if (payload[0] == 0x24 && payload[plen-1] == 0x7c) { const unsigned char *t = &payload[1]; @@ -673,7 +694,8 @@ int search_all_dc(const unsigned char *payload, const u16 plen) } /* check for mute */ -int search_mute(const unsigned char *payload, const u16 plen) +static unsigned int +search_mute(const unsigned char *payload, const unsigned int plen) { if (plen == 209 || plen == 345 || plen == 473 || plen == 609 || plen == 1121) { @@ -690,14 +712,15 @@ int search_mute(const unsigned char *payload, const u16 plen) } /* check for xdcc */ -int search_xdcc(const unsigned char *payload, const u16 plen) +static unsigned int +search_xdcc(const unsigned char *payload, const unsigned int plen) { /* search in small packets only */ if (plen > 20 && plen < 200 && payload[plen-1] == 0x0a && payload[plen-2] == 0x0d && memcmp(payload, "PRIVMSG ", 8) == 0) { - u16 x = 10; - const u16 end = plen - 13; + uint16_t x = 10; + const uint16_t end = plen - 13; /* * is seems to be a irc private massage, chedck for @@ -714,7 +737,8 @@ int search_xdcc(const unsigned char *payload, const u16 plen) } /* search for waste */ -int search_waste(const unsigned char *payload, const u16 plen) +static unsigned int +search_waste(const unsigned char *payload, const unsigned int plen) { if (plen >= 8 && memcmp(payload, "GET.sha1:", 9) == 0) return IPP2P_WASTE * 100 + 0; @@ -722,11 +746,11 @@ int search_waste(const unsigned char *payload, const u16 plen) return 0; } -static struct { - int command; +static const struct { + unsigned int command; __u8 short_hand; /* for fucntions included in short hands */ - int packet_len; - int (*function_name)(const unsigned char *, const u16); + unsigned int packet_len; + unsigned int (*function_name)(const unsigned char *, const unsigned int); } matchlist[] = { {IPP2P_EDK, SHORT_HAND_IPP2P, 20, search_all_edk}, // {IPP2P_DATA_KAZAA, SHORT_HAND_DATA, 200, search_kazaa}, @@ -747,11 +771,11 @@ static struct { {0}, }; -static struct { - int command; +static const struct { + unsigned int command; __u8 short_hand; /* for fucntions included in short hands */ - int packet_len; - int (*function_name)(unsigned char *, int); + unsigned int packet_len; + unsigned int (*function_name)(const unsigned char *, const unsigned int); } udp_list[] = { {IPP2P_KAZAA, SHORT_HAND_IPP2P, 14, udp_search_kazaa}, {IPP2P_BIT, SHORT_HAND_IPP2P, 23, udp_search_bit}, @@ -767,10 +791,11 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop) { const struct ipt_p2p_info *info = matchinfo; - unsigned char *haystack; - struct iphdr *ip = ip_hdr(skb); - int p2p_result = 0, i = 0; - int hlen = ntohs(ip->tot_len) - ip->ihl * 4; /* hlen = packet-data length */ + const unsigned char *haystack; + const struct iphdr *ip = ip_hdr(skb); + bool p2p_result = false; + int i = 0; + unsigned int hlen = ntohs(ip->tot_len) - ip->ihl * 4; /* hlen = packet-data length */ /* must not be a fragment */ if (offset != 0) { @@ -786,12 +811,12 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, return 0; } - haystack = (char *)ip + ip->ihl * 4; /* haystack = packet data */ + haystack = (const char *)ip + ip->ihl * 4; /* haystack = packet data */ switch (ip->protocol) { case IPPROTO_TCP: /* what to do with a TCP packet */ { - struct tcphdr *tcph = (void *)ip + ip->ihl * 4; + const struct tcphdr *tcph = (const void *)ip + ip->ihl * 4; if (tcph->fin) return 0; /* if FIN bit is set bail out */ if (tcph->syn) return 0; /* if SYN bit is set bail out */ @@ -819,7 +844,7 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, case IPPROTO_UDP: /* what to do with an UDP packet */ { - struct udphdr *udph = (void *)ip + ip->ihl * 4; + const struct udphdr *udph = (const void *)ip + ip->ihl * 4; while (udp_list[i].command) { if (((info->cmd & udp_list[i].command) == udp_list[i].command || From 3c8131b976d2fb61c8e54437658bc632b46fd77f Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 07:13:16 +0100 Subject: [PATCH 06/13] ipp2p: use auxiliary skb functions --- extensions/xt_ipp2p.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index e52dfda..ae8a239 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -795,7 +795,7 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, const struct iphdr *ip = ip_hdr(skb); bool p2p_result = false; int i = 0; - unsigned int hlen = ntohs(ip->tot_len) - ip->ihl * 4; /* hlen = packet-data length */ + unsigned int hlen = ntohs(ip->tot_len) - ip_hdrlen(skb); /* hlen = packet-data length */ /* must not be a fragment */ if (offset != 0) { @@ -811,12 +811,12 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, return 0; } - haystack = (const char *)ip + ip->ihl * 4; /* haystack = packet data */ + haystack = skb_network_header(skb) + ip_hdrlen(skb); switch (ip->protocol) { case IPPROTO_TCP: /* what to do with a TCP packet */ { - const struct tcphdr *tcph = (const void *)ip + ip->ihl * 4; + const struct tcphdr *tcph = tcp_hdr(skb); if (tcph->fin) return 0; /* if FIN bit is set bail out */ if (tcph->syn) return 0; /* if SYN bit is set bail out */ @@ -844,7 +844,7 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, case IPPROTO_UDP: /* what to do with an UDP packet */ { - const struct udphdr *udph = (const void *)ip + ip->ihl * 4; + const struct udphdr *udph = udp_hdr(skb); while (udp_list[i].command) { if (((info->cmd & udp_list[i].command) == udp_list[i].command || From 0712d0fdcab2077065f2b57f4cdbaa8f04d07df4 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 07:15:03 +0100 Subject: [PATCH 07/13] ipp2p: guard against potential unaligned access get_u16() and get_u32() may get passed unaligned pointers; let's play it safe. --- extensions/xt_ipp2p.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index ae8a239..c4c2eea 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "xt_ipp2p.h" #include "compat_xtables.h" @@ -10,9 +11,9 @@ //#define IPP2P_DEBUG_SOUL //#define IPP2P_DEBUG_WINMX -#define get_u8(X, O) (*(__u8 *)(X + O)) -#define get_u16(X, O) (*(__u16 *)(X + O)) -#define get_u32(X, O) (*(__u32 *)(X + O)) +#define get_u8(X, O) (*(__u8 *)(X + O)) +#define get_u16(X, O) get_unaligned((__u16 *)(X + O)) +#define get_u32(X, O) get_unaligned((__u32 *)(X + O)) MODULE_AUTHOR("Eicke Friedrich/Klaus Degner "); MODULE_DESCRIPTION("An extension to iptables to identify P2P traffic."); From a1d307e33684a9562defad429e64fcb4f78b7ee7 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 26 Mar 2008 07:53:10 +0100 Subject: [PATCH 08/13] ipp2p: internally simplify selecting protocol searches --- extensions/libxt_ipp2p.c | 188 ++++++--------------------------------- extensions/xt_ipp2p.c | 50 +++++------ extensions/xt_ipp2p.h | 57 +++++++----- 3 files changed, 85 insertions(+), 210 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index 4994dc0..b34ffc2 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -11,7 +11,6 @@ static void ipp2p_mt_help(void) { printf( "IPP2P v%s options:\n" - " --ipp2p Grab all known p2p packets\n" " --edk [tcp,udp] All known eDonkey/eMule/Overnet packets\n" " --dc [tcp] All known Direct Connect packets\n" " --kazaa [tcp,udp] All known KaZaA packets\n" @@ -27,8 +26,6 @@ static void ipp2p_mt_help(void) " --xdcc [tcp] All known XDCC packets (only xdcc login)\n\n" "DEBUG SUPPPORT, use only if you know why\n" " --debug Generate kernel debug output, THIS WILL SLOW DOWN THE FILTER\n" - "\nNote that the follwing options will have the same meaning:\n" - " '--ipp2p' is equal to '--edk --dc --kazaa --gnu --bit --apple --winmx --soul --ares'\n" "\nIPP2P was intended for TCP only. Due to increasing usage of UDP we needed to change this.\n" "You can now use -p udp to search UDP packets only or without -p switch to search UDP and TCP packets.\n" "\nSee README included with this package for more details or visit http://www.ipp2p.org\n" @@ -40,7 +37,6 @@ static void ipp2p_mt_help(void) } static const struct option ipp2p_mt_opts[] = { - { "ipp2p", 0, 0, '1' }, { "edk", 0, 0, '2' }, { "dc", 0, 0, '7' }, { "gnu", 0, 0, '9' }, @@ -63,37 +59,11 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, struct ipt_p2p_info *info = (struct ipt_p2p_info *)(*match)->data; switch (c) { - case '1': /*cmd: ipp2p*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p-data' may only be " - "specified alone!");*/ - if ((*flags) != 0) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += SHORT_HAND_IPP2P; - info->cmd = *flags; - break; - case '2': /*cmd: edk*/ if ((*flags & IPP2P_EDK) == IPP2P_EDK) exit_error(PARAMETER_PROBLEM, "ipp2p: `--edk' may only be " "specified once"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p-data' may only be " - "specified alone!");*/ if ((*flags & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) exit_error(PARAMETER_PROBLEM, "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); @@ -107,14 +77,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--dc' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p-data' may only be " - "specified alone!");*/ if ((*flags & IPP2P_DATA_DC) == IPP2P_DATA_DC) exit_error(PARAMETER_PROBLEM, "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); @@ -128,14 +90,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--gnu' may only be " "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p-data' may only be " - "specified alone!");*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if ((*flags & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) exit_error(PARAMETER_PROBLEM, "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); @@ -149,14 +103,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--kazaa' may only be " "specified once!"); -/* if ((*flags & SHORT_HAND_DATA) == SHORT_HAND_DATA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p-data' may only be " - "specified alone!");*/ - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if ((*flags & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) exit_error(PARAMETER_PROBLEM, "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); @@ -170,11 +116,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--bit' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags += IPP2P_BIT; info->cmd = *flags; break; @@ -184,10 +125,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--apple' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags += IPP2P_APPLE; info->cmd = *flags; @@ -198,10 +135,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--soul' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags += IPP2P_SOUL; info->cmd = *flags; @@ -212,10 +145,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--winmx' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags += IPP2P_WINMX; info->cmd = *flags; @@ -226,10 +155,6 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--ares' may only be " "specified once!"); - if ((*flags & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ipp2p' may only be " - "specified alone!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags += IPP2P_ARES; info->cmd = *flags; @@ -283,104 +208,43 @@ static void ipp2p_mt_check(unsigned int flags) "\nipp2p-parameter problem: for ipp2p usage type: iptables -m ipp2p --help\n"); } +static const char *const ipp2p_cmds[] = { + [IPP2N_EDK] = "--edk", + [IPP2N_DATA_KAZAA] = "--kazaa-data", + [IPP2N_DATA_EDK] = "--edk-data", + [IPP2N_DATA_DC] = "--dc-data", + [IPP2N_DC] = "--dc", + [IPP2N_DATA_GNU] = "--gnu-data", + [IPP2N_GNU] = "--gnu", + [IPP2N_KAZAA] = "--kazaa", + [IPP2N_BIT] = "--bit", + [IPP2N_APPLE] = "--apple", + [IPP2N_SOUL] = "--soul", + [IPP2N_WINMX] = "--winmx", + [IPP2N_ARES] = "--ares", + [IPP2N_MUTE] = "--mute", + [IPP2N_WASTE] = "--waste", + [IPP2N_XDCC] = "--xdcc", +}; + static void ipp2p_mt_print(const void *entry, const struct xt_entry_match *match, int numeric) { const struct ipt_p2p_info *info = (const void *)match->data; + unsigned int i; + + for (i = IPP2N_EDK; i <= IPP2N_XDCC; ++i) + if (info->cmd & (1 << i)) + printf("%s ", ipp2p_cmds[i]); - printf("ipp2p v%s", IPP2P_VERSION); - if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - printf(" --ipp2p"); -/* - if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) - printf(" --ipp2p-data"); -*/ - if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) - printf(" --kazaa"); -/* - if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) - printf(" --kazaa-data"); - if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) - printf(" --gnu-data"); -*/ - if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) printf(" --gnu"); - if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) printf(" --edk"); -/* - if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) - printf(" --edk-data"); - if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) - printf(" --dc-data"); -*/ - if ((info->cmd & IPP2P_DC) == IPP2P_DC) - printf(" --dc"); - if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) - printf(" --bit"); - if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) - printf(" --apple"); - if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) - printf(" --soul"); - if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) - printf(" --winmx"); - if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) - printf(" --ares"); - if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) - printf(" --mute"); - if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) - printf(" --waste"); - if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) - printf(" --xdcc"); if (info->debug != 0) - printf(" --debug"); - printf(" "); + printf("--debug "); } static void ipp2p_mt_save(const void *entry, const struct xt_entry_match *match) { - const struct ipt_p2p_info *info = (const void *)match->data; - - if ((info->cmd & SHORT_HAND_IPP2P) == SHORT_HAND_IPP2P) - printf("--ipp2p "); -/* - if ((info->cmd & SHORT_HAND_DATA) == SHORT_HAND_DATA) - printf("--ipp2p-data "); -*/ - if ((info->cmd & IPP2P_KAZAA) == IPP2P_KAZAA) - printf("--kazaa "); -/* if ((info->cmd & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) - printf("--kazaa-data "); - if ((info->cmd & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) - printf("--gnu-data "); -*/ - if ((info->cmd & IPP2P_GNU) == IPP2P_GNU) - printf("--gnu "); - if ((info->cmd & IPP2P_EDK) == IPP2P_EDK) - printf("--edk "); -/* if ((info->cmd & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) - printf("--edk-data "); - if ((info->cmd & IPP2P_DATA_DC) == IPP2P_DATA_DC) - printf("--dc-data "); -*/ - if ((info->cmd & IPP2P_DC) == IPP2P_DC) - printf("--dc "); - if ((info->cmd & IPP2P_BIT) == IPP2P_BIT) - printf("--bit "); - if ((info->cmd & IPP2P_APPLE) == IPP2P_APPLE) - printf("--apple "); - if ((info->cmd & IPP2P_SOUL) == IPP2P_SOUL) - printf("--soul "); - if ((info->cmd & IPP2P_WINMX) == IPP2P_WINMX) - printf("--winmx "); - if ((info->cmd & IPP2P_ARES) == IPP2P_ARES) - printf("--ares "); - if ((info->cmd & IPP2P_MUTE) == IPP2P_MUTE) - printf(" --mute"); - if ((info->cmd & IPP2P_WASTE) == IPP2P_WASTE) - printf(" --waste"); - if ((info->cmd & IPP2P_XDCC) == IPP2P_XDCC) - printf(" --xdcc"); - if (info->debug != 0) - printf("--debug "); + ipp2p_mt_print(entry, match, true); } static struct xtables_match ipp2p_mt_reg = { diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index c4c2eea..63bd656 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -749,40 +749,38 @@ search_waste(const unsigned char *payload, const unsigned int plen) static const struct { unsigned int command; - __u8 short_hand; /* for fucntions included in short hands */ unsigned int packet_len; unsigned int (*function_name)(const unsigned char *, const unsigned int); } matchlist[] = { - {IPP2P_EDK, SHORT_HAND_IPP2P, 20, search_all_edk}, -// {IPP2P_DATA_KAZAA, SHORT_HAND_DATA, 200, search_kazaa}, -// {IPP2P_DATA_EDK, SHORT_HAND_DATA, 60, search_edk}, -// {IPP2P_DATA_DC, SHORT_HAND_DATA, 26, search_dc}, - {IPP2P_DC, SHORT_HAND_IPP2P, 5, search_all_dc}, -// {IPP2P_DATA_GNU, SHORT_HAND_DATA, 40, search_gnu}, - {IPP2P_GNU, SHORT_HAND_IPP2P, 5, search_all_gnu}, - {IPP2P_KAZAA, SHORT_HAND_IPP2P, 5, search_all_kazaa}, - {IPP2P_BIT, SHORT_HAND_IPP2P, 20, search_bittorrent}, - {IPP2P_APPLE, SHORT_HAND_IPP2P, 5, search_apple}, - {IPP2P_SOUL, SHORT_HAND_IPP2P, 5, search_soul}, - {IPP2P_WINMX, SHORT_HAND_IPP2P, 2, search_winmx}, - {IPP2P_ARES, SHORT_HAND_IPP2P, 5, search_ares}, - {IPP2P_MUTE, SHORT_HAND_NONE, 200, search_mute}, - {IPP2P_WASTE, SHORT_HAND_NONE, 5, search_waste}, - {IPP2P_XDCC, SHORT_HAND_NONE, 5, search_xdcc}, + {IPP2P_EDK, 20, search_all_edk}, +// {IPP2P_DATA_KAZAA, 200, search_kazaa}, +// {IPP2P_DATA_EDK, 60, search_edk}, +// {IPP2P_DATA_DC, 26, search_dc}, + {IPP2P_DC, 5, search_all_dc}, +// {IPP2P_DATA_GNU, 40, search_gnu}, + {IPP2P_GNU, 5, search_all_gnu}, + {IPP2P_KAZAA, 5, search_all_kazaa}, + {IPP2P_BIT, 20, search_bittorrent}, + {IPP2P_APPLE, 5, search_apple}, + {IPP2P_SOUL, 5, search_soul}, + {IPP2P_WINMX, 2, search_winmx}, + {IPP2P_ARES, 5, search_ares}, + {IPP2P_MUTE, 200, search_mute}, + {IPP2P_WASTE, 5, search_waste}, + {IPP2P_XDCC, 5, search_xdcc}, {0}, }; static const struct { unsigned int command; - __u8 short_hand; /* for fucntions included in short hands */ unsigned int packet_len; unsigned int (*function_name)(const unsigned char *, const unsigned int); } udp_list[] = { - {IPP2P_KAZAA, SHORT_HAND_IPP2P, 14, udp_search_kazaa}, - {IPP2P_BIT, SHORT_HAND_IPP2P, 23, udp_search_bit}, - {IPP2P_GNU, SHORT_HAND_IPP2P, 11, udp_search_gnu}, - {IPP2P_EDK, SHORT_HAND_IPP2P, 9, udp_search_edk}, - {IPP2P_DC, SHORT_HAND_IPP2P, 12, udp_search_directconnect}, + {IPP2P_KAZAA, 14, udp_search_kazaa}, + {IPP2P_BIT, 23, udp_search_bit}, + {IPP2P_GNU, 11, udp_search_gnu}, + {IPP2P_EDK, 9, udp_search_edk}, + {IPP2P_DC, 12, udp_search_directconnect}, {0}, }; @@ -826,8 +824,7 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, haystack += tcph->doff * 4; /* get TCP-Header-Size */ hlen -= tcph->doff * 4; while (matchlist[i].command) { - if (((info->cmd & matchlist[i].command) == matchlist[i].command || - (info->cmd & matchlist[i].short_hand) == matchlist[i].short_hand) && + if ((info->cmd & matchlist[i].command) == matchlist[i].command && hlen > matchlist[i].packet_len) { p2p_result = matchlist[i].function_name(haystack, hlen); @@ -848,8 +845,7 @@ ipp2p_mt(const struct sk_buff *skb, const struct net_device *in, const struct udphdr *udph = udp_hdr(skb); while (udp_list[i].command) { - if (((info->cmd & udp_list[i].command) == udp_list[i].command || - (info->cmd & udp_list[i].short_hand) == udp_list[i].short_hand) && + if ((info->cmd & udp_list[i].command) == udp_list[i].command && hlen > udp_list[i].packet_len) { p2p_result = udp_list[i].function_name(haystack, hlen); diff --git a/extensions/xt_ipp2p.h b/extensions/xt_ipp2p.h index 1bd3f64..c051d85 100644 --- a/extensions/xt_ipp2p.h +++ b/extensions/xt_ipp2p.h @@ -2,30 +2,45 @@ #define __IPT_IPP2P_H #define IPP2P_VERSION "0.8.1_rc1" +enum { + IPP2N_EDK, + IPP2N_DATA_KAZAA, + IPP2N_DATA_EDK, + IPP2N_DATA_DC, + IPP2N_DC, + IPP2N_DATA_GNU, + IPP2N_GNU, + IPP2N_KAZAA, + IPP2N_BIT, + IPP2N_APPLE, + IPP2N_SOUL, + IPP2N_WINMX, + IPP2N_ARES, + IPP2N_MUTE, + IPP2N_WASTE, + IPP2N_XDCC, + + IPP2P_EDK = 1 << IPP2N_EDK, + IPP2P_DATA_KAZAA = 1 << IPP2N_DATA_KAZAA, + IPP2P_DATA_EDK = 1 << IPP2N_DATA_EDK, + IPP2P_DATA_DC = 1 << IPP2N_DATA_DC, + IPP2P_DC = 1 << IPP2N_DC, + IPP2P_DATA_GNU = 1 << IPP2N_DATA_GNU, + IPP2P_GNU = 1 << IPP2N_GNU, + IPP2P_KAZAA = 1 << IPP2N_KAZAA, + IPP2P_BIT = 1 << IPP2N_BIT, + IPP2P_APPLE = 1 << IPP2N_APPLE, + IPP2P_SOUL = 1 << IPP2N_SOUL, + IPP2P_WINMX = 1 << IPP2N_WINMX, + IPP2P_ARES = 1 << IPP2N_ARES, + IPP2P_MUTE = 1 << IPP2N_MUTE, + IPP2P_WASTE = 1 << IPP2N_WASTE, + IPP2P_XDCC = 1 << IPP2N_XDCC, +}; + struct ipt_p2p_info { int cmd; int debug; }; #endif //__IPT_IPP2P_H - -#define SHORT_HAND_IPP2P 1 /* --ipp2p switch*/ -//#define SHORT_HAND_DATA 4 /* --ipp2p-data switch*/ -#define SHORT_HAND_NONE 5 /* no short hand*/ - -#define IPP2P_EDK (1 << 1) -#define IPP2P_DATA_KAZAA (1 << 2) -#define IPP2P_DATA_EDK (1 << 3) -#define IPP2P_DATA_DC (1 << 4) -#define IPP2P_DC (1 << 5) -#define IPP2P_DATA_GNU (1 << 6) -#define IPP2P_GNU (1 << 7) -#define IPP2P_KAZAA (1 << 8) -#define IPP2P_BIT (1 << 9) -#define IPP2P_APPLE (1 << 10) -#define IPP2P_SOUL (1 << 11) -#define IPP2P_WINMX (1 << 12) -#define IPP2P_ARES (1 << 13) -#define IPP2P_MUTE (1 << 14) -#define IPP2P_WASTE (1 << 15) -#define IPP2P_XDCC (1 << 16) From 01df89eb8b96f3a1a5f93ce02a829b4745ec1fc6 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 27 Mar 2008 08:15:59 +0100 Subject: [PATCH 09/13] ipp2p: enable experimental data stream analyzers (get rid of "function unused" warnings) --- extensions/xt_ipp2p.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index 63bd656..cde94e5 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -753,11 +753,11 @@ static const struct { unsigned int (*function_name)(const unsigned char *, const unsigned int); } matchlist[] = { {IPP2P_EDK, 20, search_all_edk}, -// {IPP2P_DATA_KAZAA, 200, search_kazaa}, -// {IPP2P_DATA_EDK, 60, search_edk}, -// {IPP2P_DATA_DC, 26, search_dc}, + {IPP2P_DATA_KAZAA, 200, search_kazaa}, /* exp */ + {IPP2P_DATA_EDK, 60, search_edk}, /* exp */ + {IPP2P_DATA_DC, 26, search_dc}, /* exp */ {IPP2P_DC, 5, search_all_dc}, -// {IPP2P_DATA_GNU, 40, search_gnu}, + {IPP2P_DATA_GNU, 40, search_gnu}, /* exp */ {IPP2P_GNU, 5, search_all_gnu}, {IPP2P_KAZAA, 5, search_all_kazaa}, {IPP2P_BIT, 20, search_bittorrent}, From 376d41618c83c7fec00986f6716dd9ff29712abc Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 27 Mar 2008 08:21:49 +0100 Subject: [PATCH 10/13] ipp2p: use OR in flag settings in libxt_ipp2p --- extensions/libxt_ipp2p.c | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index b34ffc2..f2c7c45 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -68,8 +68,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_EDK; - info->cmd = *flags; + *flags |= IPP2P_EDK; + info->cmd |= IPP2P_EDK; break; case '7': /*cmd: dc*/ @@ -81,8 +81,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_DC; - info->cmd = *flags; + *flags |= IPP2P_DC; + info->cmd |= IPP2P_DC; break; case '9': /*cmd: gnu*/ @@ -94,8 +94,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_GNU; - info->cmd = *flags; + *flags |= IPP2P_GNU; + info->cmd |= IPP2P_GNU; break; case 'a': /*cmd: kazaa*/ @@ -107,8 +107,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_KAZAA; - info->cmd = *flags; + *flags |= IPP2P_KAZAA; + info->cmd |= IPP2P_KAZAA; break; case 'b': /*cmd: bit*/ @@ -116,8 +116,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, exit_error(PARAMETER_PROBLEM, "ipp2p: `--bit' may only be " "specified once!"); - *flags += IPP2P_BIT; - info->cmd = *flags; + *flags |= IPP2P_BIT; + info->cmd |= IPP2P_BIT; break; case 'c': /*cmd: apple*/ @@ -126,8 +126,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, "ipp2p: `--apple' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_APPLE; - info->cmd = *flags; + *flags |= IPP2P_APPLE; + info->cmd |= IPP2P_APPLE; break; case 'd': /*cmd: soul*/ @@ -136,8 +136,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, "ipp2p: `--soul' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_SOUL; - info->cmd = *flags; + *flags |= IPP2P_SOUL; + info->cmd |= IPP2P_SOUL; break; case 'e': /*cmd: winmx*/ @@ -146,8 +146,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, "ipp2p: `--winmx' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_WINMX; - info->cmd = *flags; + *flags |= IPP2P_WINMX; + info->cmd |= IPP2P_WINMX; break; case 'f': /*cmd: ares*/ @@ -156,8 +156,8 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, "ipp2p: `--ares' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_ARES; - info->cmd = *flags; + *flags |= IPP2P_ARES; + info->cmd |= IPP2P_ARES; break; case 'g': /*cmd: mute*/ @@ -166,26 +166,28 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, "ipp2p: `--mute' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_MUTE; - info->cmd = *flags; + *flags |= IPP2P_MUTE; + info->cmd |= IPP2P_MUTE; break; + case 'h': /*cmd: waste*/ if ((*flags & IPP2P_WASTE) == IPP2P_WASTE) exit_error(PARAMETER_PROBLEM, "ipp2p: `--waste' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_WASTE; - info->cmd = *flags; + *flags |= IPP2P_WASTE; + info->cmd |= IPP2P_WASTE; break; + case 'i': /*cmd: xdcc*/ if ((*flags & IPP2P_XDCC) == IPP2P_XDCC) exit_error(PARAMETER_PROBLEM, "ipp2p: `--ares' may only be " "specified once!"); if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); - *flags += IPP2P_XDCC; - info->cmd = *flags; + *flags |= IPP2P_XDCC; + info->cmd |= IPP2P_XDCC; break; case 'j': /*cmd: debug*/ From 54f78ac3ef39c3946f4f54e9462d59b1c5cd0a2b Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 27 Mar 2008 09:20:40 +0100 Subject: [PATCH 11/13] ipp2p: use param_act() for parameter validation --- extensions/libxt_ipp2p.c | 101 +++++++++++++-------------------------- 1 file changed, 34 insertions(+), 67 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index f2c7c45..fb6d2fa 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -6,6 +6,7 @@ #include #include #include "xt_ipp2p.h" +#define param_act(t, s, f) param_act((t), "ipp2p", (s), (f)) static void ipp2p_mt_help(void) { @@ -60,138 +61,104 @@ static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, switch (c) { case '2': /*cmd: edk*/ - if ((*flags & IPP2P_EDK) == IPP2P_EDK) + param_act(P_ONLY_ONCE, "--edk", *flags & IPP2P_EDK); + param_act(P_NO_INVERT, "--edk", invert); + if (*flags & IPP2P_DATA_EDK) exit_error(PARAMETER_PROBLEM, - "ipp2p: `--edk' may only be " - "specified once"); - if ((*flags & IPP2P_DATA_EDK) == IPP2P_DATA_EDK) - exit_error(PARAMETER_PROBLEM, "ipp2p: use `--edk' OR `--edk-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags |= IPP2P_EDK; info->cmd |= IPP2P_EDK; break; case '7': /*cmd: dc*/ - if ((*flags & IPP2P_DC) == IPP2P_DC) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--dc' may only be " - "specified once!"); - if ((*flags & IPP2P_DATA_DC) == IPP2P_DATA_DC) - exit_error(PARAMETER_PROBLEM, + param_act(P_ONLY_ONCE, "--dc", *flags & IPP2P_DC); + param_act(P_NO_INVERT, "--dc", invert); + if (*flags & IPP2P_DATA_DC) + exit_error(PARAMETER_PROBLEM, "ipp2p: use `--dc' OR `--dc-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags |= IPP2P_DC; info->cmd |= IPP2P_DC; break; case '9': /*cmd: gnu*/ - if ((*flags & IPP2P_GNU) == IPP2P_GNU) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--gnu' may only be " - "specified once!"); - if ((*flags & IPP2P_DATA_GNU) == IPP2P_DATA_GNU) - exit_error(PARAMETER_PROBLEM, + param_act(P_ONLY_ONCE, "--gnu", *flags & IPP2P_GNU); + param_act(P_NO_INVERT, "--gnu", invert); + if (*flags & IPP2P_DATA_GNU) + exit_error(PARAMETER_PROBLEM, "ipp2p: use `--gnu' OR `--gnu-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags |= IPP2P_GNU; info->cmd |= IPP2P_GNU; break; case 'a': /*cmd: kazaa*/ - if ((*flags & IPP2P_KAZAA) == IPP2P_KAZAA) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--kazaa' may only be " - "specified once!"); - if ((*flags & IPP2P_DATA_KAZAA) == IPP2P_DATA_KAZAA) - exit_error(PARAMETER_PROBLEM, + param_act(P_ONLY_ONCE, "--kazaa", *flags & IPP2P_KAZAA); + param_act(P_NO_INVERT, "--kazaa", invert); + if (*flags & IPP2P_DATA_KAZAA) + exit_error(PARAMETER_PROBLEM, "ipp2p: use `--kazaa' OR `--kazaa-data' but not both of them!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); *flags |= IPP2P_KAZAA; info->cmd |= IPP2P_KAZAA; break; case 'b': /*cmd: bit*/ - if ((*flags & IPP2P_BIT) == IPP2P_BIT) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--bit' may only be " - "specified once!"); + param_act(P_ONLY_ONCE, "--kazaa", *flags & IPP2P_BIT); + param_act(P_NO_INVERT, "--kazaa", invert); *flags |= IPP2P_BIT; info->cmd |= IPP2P_BIT; break; case 'c': /*cmd: apple*/ - if ((*flags & IPP2P_APPLE) == IPP2P_APPLE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--apple' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--apple", *flags & IPP2P_APPLE); + param_act(P_NO_INVERT, "--apple", invert); *flags |= IPP2P_APPLE; info->cmd |= IPP2P_APPLE; break; case 'd': /*cmd: soul*/ - if ((*flags & IPP2P_SOUL) == IPP2P_SOUL) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--soul' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--soul", *flags & IPP2P_SOUL); + param_act(P_NO_INVERT, "--soul", invert); *flags |= IPP2P_SOUL; info->cmd |= IPP2P_SOUL; break; case 'e': /*cmd: winmx*/ - if ((*flags & IPP2P_WINMX) == IPP2P_WINMX) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--winmx' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--winmx", *flags & IPP2P_WINMX); + param_act(P_NO_INVERT, "--winmx", invert); *flags |= IPP2P_WINMX; info->cmd |= IPP2P_WINMX; break; case 'f': /*cmd: ares*/ - if ((*flags & IPP2P_ARES) == IPP2P_ARES) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ares' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--ares", *flags & IPP2P_ARES); + param_act(P_NO_INVERT, "--ares", invert); *flags |= IPP2P_ARES; info->cmd |= IPP2P_ARES; break; case 'g': /*cmd: mute*/ - if ((*flags & IPP2P_MUTE) == IPP2P_MUTE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--mute' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--mute", *flags & IPP2P_MUTE); + param_act(P_NO_INVERT, "--mute", invert); *flags |= IPP2P_MUTE; info->cmd |= IPP2P_MUTE; break; case 'h': /*cmd: waste*/ - if ((*flags & IPP2P_WASTE) == IPP2P_WASTE) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--waste' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--waste", *flags & IPP2P_WASTE); + param_act(P_NO_INVERT, "--waste", invert); *flags |= IPP2P_WASTE; info->cmd |= IPP2P_WASTE; break; case 'i': /*cmd: xdcc*/ - if ((*flags & IPP2P_XDCC) == IPP2P_XDCC) - exit_error(PARAMETER_PROBLEM, - "ipp2p: `--ares' may only be " - "specified once!"); - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--xdcc", *flags & IPP2P_XDCC); + param_act(P_NO_INVERT, "--xdcc", invert); *flags |= IPP2P_XDCC; info->cmd |= IPP2P_XDCC; break; case 'j': /*cmd: debug*/ - if (invert) exit_error(PARAMETER_PROBLEM, "ipp2p: invert [!] is not allowed!"); + param_act(P_ONLY_ONCE, "--debug", info->debug); + param_act(P_NO_INVERT, "--debug", invert); info->debug = 1; break; From 585cfd49abafa2bc92dc0aeed09dd46b01ce29e7 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 27 Mar 2008 09:53:41 +0100 Subject: [PATCH 12/13] ipp2p: use c99 initializers in getopt structure --- extensions/libxt_ipp2p.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/extensions/libxt_ipp2p.c b/extensions/libxt_ipp2p.c index fb6d2fa..d9caa2d 100644 --- a/extensions/libxt_ipp2p.c +++ b/extensions/libxt_ipp2p.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -38,20 +39,20 @@ static void ipp2p_mt_help(void) } static const struct option ipp2p_mt_opts[] = { - { "edk", 0, 0, '2' }, - { "dc", 0, 0, '7' }, - { "gnu", 0, 0, '9' }, - { "kazaa", 0, 0, 'a' }, - { "bit", 0, 0, 'b' }, - { "apple", 0, 0, 'c' }, - { "soul", 0, 0, 'd' }, - { "winmx", 0, 0, 'e' }, - { "ares", 0, 0, 'f' }, - { "mute", 0, 0, 'g' }, - { "waste", 0, 0, 'h' }, - { "xdcc", 0, 0, 'i' }, - { "debug", 0, 0, 'j' }, - {0}, + {.name = "edk", .has_arg = false, .val = '2'}, + {.name = "dc", .has_arg = false, .val = '7'}, + {.name = "gnu", .has_arg = false, .val = '9'}, + {.name = "kazaa", .has_arg = false, .val = 'a'}, + {.name = "bit", .has_arg = false, .val = 'b'}, + {.name = "apple", .has_arg = false, .val = 'c'}, + {.name = "soul", .has_arg = false, .val = 'd'}, + {.name = "winmx", .has_arg = false, .val = 'e'}, + {.name = "ares", .has_arg = false, .val = 'f'}, + {.name = "mute", .has_arg = false, .val = 'g'}, + {.name = "waste", .has_arg = false, .val = 'h'}, + {.name = "xdcc", .has_arg = false, .val = 'i'}, + {.name = "debug", .has_arg = false, .val = 'j'}, + {NULL}, }; static int ipp2p_mt_parse(int c, char **argv, int invert, unsigned int *flags, From 29139c141462668ac9003a19172bb4e03ba055d0 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 1 Apr 2008 00:27:58 +0200 Subject: [PATCH 13/13] ipp2p: add missing MODULE_ALIAS(ipt_ipp2p) --- extensions/xt_ipp2p.c | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/xt_ipp2p.c b/extensions/xt_ipp2p.c index cde94e5..2ac0967 100644 --- a/extensions/xt_ipp2p.c +++ b/extensions/xt_ipp2p.c @@ -887,3 +887,4 @@ static void __exit ipp2p_mt_exit(void) module_init(ipp2p_mt_init); module_exit(ipp2p_mt_exit); +MODULE_ALIAS("ipt_ipp2p");