2
Shared library add-on to iptables to add PSD support
4
Copyright (C) 2000,2001 astaro AG
6
This file is distributed under the terms of the GNU General Public
7
License (GPL). Copies of the GPL can be obtained from:
8
ftp://prep.ai.mit.edu/pub/gnu/GPL
10
2000-05-04 Markus Hennig <hennig@astaro.de> : initial
11
2000-08-18 Dennis Koslowski <koslowski@astaro.de> : first release
12
2000-12-01 Dennis Koslowski <koslowski@astaro.de> : UDP scans detection added
13
2001-02-04 Jan Rekorajski <baggins@pld.org.pl> : converted from target to match
14
2003-03-02 Harald Welte <laforge@netfilter.org>: fix 'storage' bug
15
2008-04-03 Mohd Nawawi <nawawi@tracenetworkcorporation.com>: update to 2.6.24 / 1.4 code
16
2008-06-24 Mohd Nawawi <nawawi@tracenetworkcorporation.com>: update to 2.6.24 / 1.4.1 code
17
2009-08-07 Mohd Nawawi Mohamad Jamili <nawawi@tracenetworkcorporation.com> : ported to xtables-addons
29
#include <linux/netfilter/x_tables.h>
32
/* Function which prints out usage message. */
33
static void psd_mt_help(void) {
35
"psd match options:\n"
36
" --psd-weight-threshold threshhold Portscan detection weight threshold\n"
37
" --psd-delay-threshold delay Portscan detection delay threshold\n"
38
" --psd-lo-ports-weight lo Privileged ports weight\n"
39
" --psd-hi-ports-weight hi High ports weight\n\n");
42
static const struct option psd_mt_opts[] = {
43
{.name = "psd-weight-threshold", .has_arg = true, .val = '1'},
44
{.name = "psd-delay-threshold", .has_arg = true, .val = '2'},
45
{.name = "psd-lo-ports-weight", .has_arg = true, .val = '3'},
46
{.name = "psd-hi-ports-weight", .has_arg = true, .val = '4'},
50
/* Initialize the target. */
51
static void psd_mt_init(struct xt_entry_match *match) {
52
struct xt_psd_info *psdinfo = (struct xt_psd_info *)match->data;
53
psdinfo->weight_threshold = SCAN_WEIGHT_THRESHOLD;
54
psdinfo->delay_threshold = SCAN_DELAY_THRESHOLD;
55
psdinfo->lo_ports_weight = PORT_WEIGHT_PRIV;
56
psdinfo->hi_ports_weight = PORT_WEIGHT_HIGH;
59
#define XT_PSD_OPT_CTRESH 0x01
60
#define XT_PSD_OPT_DTRESH 0x02
61
#define XT_PSD_OPT_LPWEIGHT 0x04
62
#define XT_PSD_OPT_HPWEIGHT 0x08
64
static int psd_mt_parse(int c, char **argv, int invert, unsigned int *flags,
65
const void *entry, struct xt_entry_match **match)
67
struct xt_psd_info *psdinfo = (struct xt_psd_info *)(*match)->data;
71
/* PSD-weight-threshold */
73
if (*flags & XT_PSD_OPT_CTRESH)
74
xtables_error(PARAMETER_PROBLEM,"Can't specify --psd-weight-threshold twice");
75
if (!xtables_strtoui(optarg, NULL, &num, 0, PSD_MAX_RATE))
76
xtables_error(PARAMETER_PROBLEM, "bad --psd-weight-threshold '%s'", optarg);
77
psdinfo->weight_threshold = num;
78
*flags |= XT_PSD_OPT_CTRESH;
81
/* PSD-delay-threshold */
83
if (*flags & XT_PSD_OPT_DTRESH)
84
xtables_error(PARAMETER_PROBLEM, "Can't specify --psd-delay-threshold twice");
85
if (!xtables_strtoui(optarg, NULL, &num, 0, PSD_MAX_RATE))
86
xtables_error(PARAMETER_PROBLEM, "bad --psd-delay-threshold '%s'", optarg);
87
psdinfo->delay_threshold = num;
88
*flags |= XT_PSD_OPT_DTRESH;
91
/* PSD-lo-ports-weight */
93
if (*flags & XT_PSD_OPT_LPWEIGHT)
94
xtables_error(PARAMETER_PROBLEM, "Can't specify --psd-lo-ports-weight twice");
95
if (!xtables_strtoui(optarg, NULL, &num, 0, PSD_MAX_RATE))
96
xtables_error(PARAMETER_PROBLEM, "bad --psd-lo-ports-weight '%s'", optarg);
97
psdinfo->lo_ports_weight = num;
98
*flags |= XT_PSD_OPT_LPWEIGHT;
101
/* PSD-hi-ports-weight */
103
if (*flags & XT_PSD_OPT_HPWEIGHT)
104
xtables_error(PARAMETER_PROBLEM, "Can't specify --psd-hi-ports-weight twice");
105
if (!xtables_strtoui(optarg, NULL, &num, 0, PSD_MAX_RATE))
106
xtables_error(PARAMETER_PROBLEM, "bad --psd-hi-ports-weight '%s'", optarg);
107
psdinfo->hi_ports_weight = num;
108
*flags |= XT_PSD_OPT_HPWEIGHT;
114
/* Final check; nothing. */
115
static void psd_mt_final_check(unsigned int flags) {}
117
/* Prints out the targinfo. */
118
static void psd_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
120
const struct xt_psd_info *psdinfo = (const struct xt_psd_info *)match->data;
122
printf("weight-threshold: %u ", psdinfo->weight_threshold);
123
printf("delay-threshold: %u ", psdinfo->delay_threshold);
124
printf("lo-ports-weight: %u ", psdinfo->lo_ports_weight);
125
printf("hi-ports-weight: %u ", psdinfo->hi_ports_weight);
128
/* Saves the union ipt_targinfo in parsable form to stdout. */
129
static void psd_mt_save(const void *ip, const struct xt_entry_match *match)
131
const struct xt_psd_info *psdinfo = (const struct xt_psd_info *)match->data;
132
printf("--psd-weight-threshold %u ", psdinfo->weight_threshold);
133
printf("--psd-delay-threshold %u ", psdinfo->delay_threshold);
134
printf("--psd-lo-ports-weight %u ", psdinfo->lo_ports_weight);
135
printf("--psd-hi-ports-weight %u ", psdinfo->hi_ports_weight);
138
static struct xtables_match psd_mt_reg = {
140
.version = XTABLES_VERSION,
143
.size = XT_ALIGN(sizeof(struct xt_psd_info)),
144
.userspacesize = XT_ALIGN(sizeof(struct xt_psd_info)),
147
.parse = psd_mt_parse,
148
.final_check = psd_mt_final_check,
149
.print = psd_mt_print,
151
.extra_opts = psd_mt_opts,
154
static __attribute__((constructor)) void psd_mt_ldr(void)
156
xtables_register_match(&psd_mt_reg);