-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibipt_DUPLICATE.c
94 lines (80 loc) · 2.73 KB
/
libipt_DUPLICATE.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Shared library add-on to iptables to add customized DUPLICATE
* target module support.
*
* Written by Samuel Tan <samueltan@gmail.com>
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <xtables.h>
#include <linux/netfilter_ipv4/ipt_DUPLICATE.h>
#include <linux/version.h>
static void DUPLICATE_help(void)
{
printf(
"DUPLICATE target options:\n"
"--times NUM Duplicate each packet NUM times (1 by default)\n");
printf("(*) See man page or read the INCOMPATIBILITES file for compatibility issues.\n");
}
static const struct option DUPLICATE_opts[] = {
{ "times", 1, NULL, '1' },
{ .name = NULL }
};
static void DUPLICATE_init(struct xt_entry_target *t)
{
struct ipt_duplicate_info *duplicate = (struct ipt_duplicate_info *)t->data;
duplicate->times = 1; /* duplicate packet once by default */
}
static int DUPLICATE_parse(int c, char **argv, int invert, unsigned int *flags,
const void *entry, struct xt_entry_target **target)
{
struct ipt_duplicate_info *duplicate = (struct ipt_duplicate_info *)(*target)->data;
unsigned int val;
switch(c) {
case '1':
if (!xtables_strtoui(optarg, NULL, &val, 0, UINT32_MAX))
xtables_error(PARAMETER_PROBLEM,
"cannot parse --times `%s'", optarg);
if (val < 1)
xtables_error(PARAMETER_PROBLEM,
"Argument passed to --times cannot be less than 1");
duplicate->times = val;
return 1;
default:
/* Fall through */
break;
}
return 0;
}
static void DUPLICATE_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
const struct ipt_duplicate_info *duplicate
= (const struct ipt_duplicate_info *)target->data;
printf("times %d ", duplicate->times);
}
static void DUPLICATE_save(const void *ip, const struct xt_entry_target *target)
{
const struct ipt_duplicate_info *duplicate
= (const struct ipt_duplicate_info *)target->data;
printf("--times %d ", duplicate->times);
}
static struct xtables_target duplicate_tg_reg = {
.name = "DUPLICATE",
.version = XTABLES_VERSION,
.family = NFPROTO_IPV4,
.size = XT_ALIGN(sizeof(struct ipt_duplicate_info)),
.userspacesize = XT_ALIGN(sizeof(struct ipt_duplicate_info)),
.help = DUPLICATE_help,
.init = DUPLICATE_init,
.parse = DUPLICATE_parse,
.print = DUPLICATE_print,
.save = DUPLICATE_save,
.extra_opts = DUPLICATE_opts,
};
void _init(void)
{
xtables_register_target(&duplicate_tg_reg);
}