blob: e70edc6734e3b32e8565b09c9642766577f24791 [file] [log] [blame]
Jan Engelhardt32b8e612010-07-23 21:16:14 +02001#include <stdbool.h>
Patrick McHardy6afc5b72008-01-15 17:27:04 +00002#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#include <stddef.h>
6#include <getopt.h>
7
8#include <xtables.h>
9#include <linux/netfilter/xt_rateest.h>
10
11/* Ugly hack to pass info to final_check function. We should fix the API */
12static struct xt_rateest_match_info *rateest_info;
13
14static void rateest_help(void)
15{
16 printf(
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020017"rateest match options:\n"
Patrick McHardy6afc5b72008-01-15 17:27:04 +000018" --rateest1 name Rate estimator name\n"
19" --rateest2 name Rate estimator name\n"
20" --rateest-delta Compare difference(s) to given rate(s)\n"
21" --rateest-bps1 [bps] Compare bps\n"
22" --rateest-pps1 [pps] Compare pps\n"
23" --rateest-bps2 [bps] Compare bps\n"
24" --rateest-pps2 [pps] Compare pps\n"
25" [!] --rateest-lt Match if rate is less than given rate/estimator\n"
26" [!] --rateest-gt Match if rate is greater than given rate/estimator\n"
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020027" [!] --rateest-eq Match if rate is equal to given rate/estimator\n");
Patrick McHardy6afc5b72008-01-15 17:27:04 +000028}
29
30enum rateest_options {
31 OPT_RATEEST1,
32 OPT_RATEEST2,
33 OPT_RATEEST_BPS1,
34 OPT_RATEEST_PPS1,
35 OPT_RATEEST_BPS2,
36 OPT_RATEEST_PPS2,
37 OPT_RATEEST_DELTA,
38 OPT_RATEEST_LT,
39 OPT_RATEEST_GT,
40 OPT_RATEEST_EQ,
41};
42
43static const struct option rateest_opts[] = {
Jan Engelhardt32b8e612010-07-23 21:16:14 +020044 {.name = "rateest1", .has_arg = true, .val = OPT_RATEEST1},
45 {.name = "rateest", .has_arg = true, .val = OPT_RATEEST1}, /* alias for absolute mode */
46 {.name = "rateest2", .has_arg = true, .val = OPT_RATEEST2},
47 {.name = "rateest-bps1", .has_arg = false, .val = OPT_RATEEST_BPS1},
48 {.name = "rateest-pps1", .has_arg = false, .val = OPT_RATEEST_PPS1},
49 {.name = "rateest-bps2", .has_arg = false, .val = OPT_RATEEST_BPS2},
50 {.name = "rateest-pps2", .has_arg = false, .val = OPT_RATEEST_PPS2},
51 {.name = "rateest-bps", .has_arg = false, .val = OPT_RATEEST_BPS2}, /* alias for absolute mode */
52 {.name = "rateest-pps", .has_arg = false, .val = OPT_RATEEST_PPS2}, /* alias for absolute mode */
53 {.name = "rateest-delta", .has_arg = false, .val = OPT_RATEEST_DELTA},
54 {.name = "rateest-lt", .has_arg = false, .val = OPT_RATEEST_LT},
55 {.name = "rateest-gt", .has_arg = false, .val = OPT_RATEEST_GT},
56 {.name = "rateest-eq", .has_arg = false, .val = OPT_RATEEST_EQ},
57 XT_GETOPT_TABLEEND,
Patrick McHardy6afc5b72008-01-15 17:27:04 +000058};
59
60/* Copied from iproute. See http://physics.nist.gov/cuu/Units/binary.html */
61static const struct rate_suffix {
62 const char *name;
63 double scale;
64} suffixes[] = {
65 { "bit", 1. },
66 { "Kibit", 1024. },
67 { "kbit", 1000. },
68 { "mibit", 1024.*1024. },
69 { "mbit", 1000000. },
70 { "gibit", 1024.*1024.*1024. },
71 { "gbit", 1000000000. },
72 { "tibit", 1024.*1024.*1024.*1024. },
73 { "tbit", 1000000000000. },
74 { "Bps", 8. },
75 { "KiBps", 8.*1024. },
76 { "KBps", 8000. },
77 { "MiBps", 8.*1024*1024. },
78 { "MBps", 8000000. },
79 { "GiBps", 8.*1024.*1024.*1024. },
80 { "GBps", 8000000000. },
81 { "TiBps", 8.*1024.*1024.*1024.*1024. },
82 { "TBps", 8000000000000. },
Jan Engelhardt104fb312011-05-07 04:01:25 +020083 {NULL},
Patrick McHardy6afc5b72008-01-15 17:27:04 +000084};
85
86static int
Jan Engelhardt7ac40522011-01-07 12:34:04 +010087rateest_get_rate(uint32_t *rate, const char *str)
Patrick McHardy6afc5b72008-01-15 17:27:04 +000088{
89 char *p;
90 double bps = strtod(str, &p);
91 const struct rate_suffix *s;
92
93 if (p == str)
94 return -1;
95
96 if (*p == '\0') {
97 *rate = bps / 8.; /* assume bytes/sec */
98 return 0;
99 }
100
101 for (s = suffixes; s->name; ++s) {
102 if (strcasecmp(s->name, p) == 0) {
103 *rate = (bps * s->scale) / 8.;
104 return 0;
105 }
106 }
107
108 return -1;
109}
110
111static int
112rateest_parse(int c, char **argv, int invert, unsigned int *flags,
113 const void *entry, struct xt_entry_match **match)
114{
115 struct xt_rateest_match_info *info = (void *)(*match)->data;
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100116 unsigned int val;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000117
118 rateest_info = info;
119
120 switch (c) {
121 case OPT_RATEEST1:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100122 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000123 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100124 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000125 "rateest: rateest can't be inverted");
126
127 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100128 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000129 "rateest: can't specify --rateest1 twice");
130 *flags |= 1 << c;
131
132 strncpy(info->name1, optarg, sizeof(info->name1) - 1);
133 break;
134
135 case OPT_RATEEST2:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100136 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000137 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100138 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000139 "rateest: rateest can't be inverted");
140
141 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100142 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000143 "rateest: can't specify --rateest2 twice");
144 *flags |= 1 << c;
145
146 strncpy(info->name2, optarg, sizeof(info->name2) - 1);
147 info->flags |= XT_RATEEST_MATCH_REL;
148 break;
149
150 case OPT_RATEEST_BPS1:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100151 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000152 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100153 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000154 "rateest: rateest-bps can't be inverted");
155
156 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100157 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000158 "rateest: can't specify --rateest-bps1 twice");
159 *flags |= 1 << c;
160
161 info->flags |= XT_RATEEST_MATCH_BPS;
162
163 /* The rate is optional and only required in absolute mode */
164 if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
165 break;
166
167 if (rateest_get_rate(&info->bps1, argv[optind]) < 0)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100168 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000169 "rateest: could not parse rate `%s'",
170 argv[optind]);
171 optind++;
172 break;
173
174 case OPT_RATEEST_PPS1:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100175 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000176 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100177 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000178 "rateest: rateest-pps can't be inverted");
179
180 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100181 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000182 "rateest: can't specify --rateest-pps1 twice");
183 *flags |= 1 << c;
184
185 info->flags |= XT_RATEEST_MATCH_PPS;
186
187 /* The rate is optional and only required in absolute mode */
188 if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
189 break;
190
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100191 if (!xtables_strtoui(argv[optind], NULL, &val, 0, UINT32_MAX))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100192 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000193 "rateest: could not parse pps `%s'",
194 argv[optind]);
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100195 info->pps1 = val;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000196 optind++;
197 break;
198
199 case OPT_RATEEST_BPS2:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100200 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000201 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100202 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000203 "rateest: rateest-bps can't be inverted");
204
205 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100206 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000207 "rateest: can't specify --rateest-bps2 twice");
208 *flags |= 1 << c;
209
210 info->flags |= XT_RATEEST_MATCH_BPS;
211
212 /* The rate is optional and only required in absolute mode */
213 if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
214 break;
215
216 if (rateest_get_rate(&info->bps2, argv[optind]) < 0)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100217 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000218 "rateest: could not parse rate `%s'",
219 argv[optind]);
220 optind++;
221 break;
222
223 case OPT_RATEEST_PPS2:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100224 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000225 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100226 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000227 "rateest: rateest-pps can't be inverted");
228
229 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100230 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000231 "rateest: can't specify --rateest-pps2 twice");
232 *flags |= 1 << c;
233
234 info->flags |= XT_RATEEST_MATCH_PPS;
235
236 /* The rate is optional and only required in absolute mode */
237 if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
238 break;
239
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100240 if (!xtables_strtoui(argv[optind], NULL, &val, 0, UINT32_MAX))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100241 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000242 "rateest: could not parse pps `%s'",
243 argv[optind]);
Jan Engelhardt5f2922c2009-01-27 18:43:01 +0100244 info->pps2 = val;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000245 optind++;
246 break;
247
248 case OPT_RATEEST_DELTA:
Jan Engelhardtbf971282009-11-03 19:55:11 +0100249 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000250 if (invert)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100251 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000252 "rateest: rateest-delta can't be inverted");
253
254 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100255 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000256 "rateest: can't specify --rateest-delta twice");
257 *flags |= 1 << c;
258
259 info->flags |= XT_RATEEST_MATCH_DELTA;
260 break;
261
262 case OPT_RATEEST_EQ:
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200263 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000264
265 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100266 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000267 "rateest: can't specify lt/gt/eq twice");
268 *flags |= 1 << c;
269
270 info->mode = XT_RATEEST_MATCH_EQ;
271 if (invert)
272 info->flags |= XT_RATEEST_MATCH_INVERT;
273 break;
274
275 case OPT_RATEEST_LT:
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200276 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000277
278 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100279 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000280 "rateest: can't specify lt/gt/eq twice");
281 *flags |= 1 << c;
282
283 info->mode = XT_RATEEST_MATCH_LT;
284 if (invert)
285 info->flags |= XT_RATEEST_MATCH_INVERT;
286 break;
287
288 case OPT_RATEEST_GT:
Jan Engelhardtbbe83862009-10-24 00:45:33 +0200289 xtables_check_inverse(optarg, &invert, &optind, 0, argv);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000290
291 if (*flags & (1 << c))
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100292 xtables_error(PARAMETER_PROBLEM,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000293 "rateest: can't specify lt/gt/eq twice");
294 *flags |= 1 << c;
295
296 info->mode = XT_RATEEST_MATCH_GT;
297 if (invert)
298 info->flags |= XT_RATEEST_MATCH_INVERT;
299 break;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000300 }
301
302 return 1;
303}
304
305static void
306rateest_final_check(unsigned int flags)
307{
308 struct xt_rateest_match_info *info = rateest_info;
309
Jan Engelhardtc3d0a7b2008-12-30 12:03:39 +0100310 if (info == NULL)
Jan Engelhardt1829ed42009-02-21 03:29:44 +0100311 xtables_error(PARAMETER_PROBLEM, "rateest match: "
Jan Engelhardtc3d0a7b2008-12-30 12:03:39 +0100312 "you need to specify some flags");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000313 if (!(info->flags & XT_RATEEST_MATCH_REL))
314 info->flags |= XT_RATEEST_MATCH_ABS;
315}
316
317static void
Jan Engelhardt7ac40522011-01-07 12:34:04 +0100318rateest_print_rate(uint32_t rate, int numeric)
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000319{
320 double tmp = (double)rate*8;
321
322 if (numeric)
Jan Engelhardt73866352010-12-18 02:04:59 +0100323 printf(" %u", rate);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000324 else if (tmp >= 1000.0*1000000.0)
Jan Engelhardt73866352010-12-18 02:04:59 +0100325 printf(" %.0fMbit", tmp/1000000.0);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000326 else if (tmp >= 1000.0 * 1000.0)
Jan Engelhardt73866352010-12-18 02:04:59 +0100327 printf(" %.0fKbit", tmp/1000.0);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000328 else
Jan Engelhardt73866352010-12-18 02:04:59 +0100329 printf(" %.0fbit", tmp);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000330}
331
332static void
Jan Engelhardt69f564e2009-05-26 13:14:06 +0200333rateest_print_mode(const struct xt_rateest_match_info *info,
334 const char *prefix)
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000335{
336 if (info->flags & XT_RATEEST_MATCH_INVERT)
Jan Engelhardt73866352010-12-18 02:04:59 +0100337 printf(" !");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000338
339 switch (info->mode) {
340 case XT_RATEEST_MATCH_EQ:
Jan Engelhardt73866352010-12-18 02:04:59 +0100341 printf(" %seq", prefix);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000342 break;
343 case XT_RATEEST_MATCH_LT:
Jan Engelhardt73866352010-12-18 02:04:59 +0100344 printf(" %slt", prefix);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000345 break;
346 case XT_RATEEST_MATCH_GT:
Jan Engelhardt73866352010-12-18 02:04:59 +0100347 printf(" %sgt", prefix);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000348 break;
349 default:
350 exit(1);
351 }
352}
353
354static void
355rateest_print(const void *ip, const struct xt_entry_match *match, int numeric)
356{
Jan Engelhardt69f564e2009-05-26 13:14:06 +0200357 const struct xt_rateest_match_info *info = (const void *)match->data;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000358
Jan Engelhardt73866352010-12-18 02:04:59 +0100359 printf(" rateest match ");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000360
Jan Engelhardt73866352010-12-18 02:04:59 +0100361 printf("%s", info->name1);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000362 if (info->flags & XT_RATEEST_MATCH_DELTA)
Jan Engelhardt73866352010-12-18 02:04:59 +0100363 printf(" delta");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000364
365 if (info->flags & XT_RATEEST_MATCH_BPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100366 printf(" bps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000367 if (info->flags & XT_RATEEST_MATCH_DELTA)
368 rateest_print_rate(info->bps1, numeric);
369 if (info->flags & XT_RATEEST_MATCH_ABS) {
370 rateest_print_mode(info, "");
371 rateest_print_rate(info->bps2, numeric);
372 }
373 }
374 if (info->flags & XT_RATEEST_MATCH_PPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100375 printf(" pps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000376 if (info->flags & XT_RATEEST_MATCH_DELTA)
Jan Engelhardt73866352010-12-18 02:04:59 +0100377 printf(" %u", info->pps1);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000378 if (info->flags & XT_RATEEST_MATCH_ABS) {
379 rateest_print_mode(info, "");
Jan Engelhardt73866352010-12-18 02:04:59 +0100380 printf(" %u", info->pps2);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000381 }
382 }
383
384 if (info->flags & XT_RATEEST_MATCH_REL) {
385 rateest_print_mode(info, "");
386
Jan Engelhardt73866352010-12-18 02:04:59 +0100387 printf(" %s", info->name2);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000388 if (info->flags & XT_RATEEST_MATCH_DELTA)
Jan Engelhardt73866352010-12-18 02:04:59 +0100389 printf(" delta");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000390
391 if (info->flags & XT_RATEEST_MATCH_BPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100392 printf(" bps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000393 if (info->flags & XT_RATEEST_MATCH_DELTA)
394 rateest_print_rate(info->bps2, numeric);
395 }
396 if (info->flags & XT_RATEEST_MATCH_PPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100397 printf(" pps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000398 if (info->flags & XT_RATEEST_MATCH_DELTA)
Jan Engelhardt73866352010-12-18 02:04:59 +0100399 printf(" %u", info->pps2);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000400 }
401 }
402}
403
404static void
405rateest_save(const void *ip, const struct xt_entry_match *match)
406{
Jan Engelhardt69f564e2009-05-26 13:14:06 +0200407 const struct xt_rateest_match_info *info = (const void *)match->data;
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000408
409 if (info->flags & XT_RATEEST_MATCH_REL) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100410 printf(" --rateest1 %s", info->name1);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000411 if (info->flags & XT_RATEEST_MATCH_BPS)
Jan Engelhardt73866352010-12-18 02:04:59 +0100412 printf(" --rateest-bps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000413 if (info->flags & XT_RATEEST_MATCH_PPS)
Jan Engelhardt73866352010-12-18 02:04:59 +0100414 printf(" --rateest-pps");
415 rateest_print_mode(info, " --rateest-");
416 printf(" --rateest2 %s", info->name2);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000417 } else {
Jan Engelhardt73866352010-12-18 02:04:59 +0100418 printf(" --rateest %s", info->name1);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000419 if (info->flags & XT_RATEEST_MATCH_BPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100420 printf(" --rateest-bps1");
Luciano Coelhob4fa7222010-07-15 18:09:54 +0200421 rateest_print_rate(info->bps1, 0);
Jan Engelhardt73866352010-12-18 02:04:59 +0100422 printf(" --rateest-bps2");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000423 rateest_print_rate(info->bps2, 0);
Luciano Coelhob4fa7222010-07-15 18:09:54 +0200424 rateest_print_mode(info, "--rateest-");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000425 }
426 if (info->flags & XT_RATEEST_MATCH_PPS) {
Jan Engelhardt73866352010-12-18 02:04:59 +0100427 printf(" --rateest-pps");
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000428 rateest_print_mode(info, "--rateest-");
Jan Engelhardt73866352010-12-18 02:04:59 +0100429 printf(" %u", info->pps2);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000430 }
431 }
432}
433
Jan Engelhardt23545c22008-02-14 04:23:04 +0100434static struct xtables_match rateest_mt_reg = {
Jan Engelhardt42979362009-06-01 11:56:23 +0200435 .family = NFPROTO_UNSPEC,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000436 .name = "rateest",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +0200437 .version = XTABLES_VERSION,
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000438 .size = XT_ALIGN(sizeof(struct xt_rateest_match_info)),
439 .userspacesize = XT_ALIGN(offsetof(struct xt_rateest_match_info, est1)),
440 .help = rateest_help,
441 .parse = rateest_parse,
442 .final_check = rateest_final_check,
443 .print = rateest_print,
444 .save = rateest_save,
445 .extra_opts = rateest_opts,
446};
447
448void _init(void)
449{
Jan Engelhardt23545c22008-02-14 04:23:04 +0100450 xtables_register_match(&rateest_mt_reg);
Patrick McHardy6afc5b72008-01-15 17:27:04 +0000451}