-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibxt_RAWCOOKIE.c
155 lines (139 loc) · 4.32 KB
/
libxt_RAWCOOKIE.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Based on code cretaed by Patrick McHardy <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define XTABLES_INTERNAL 1
#include <xtables.h>
#include "xt_RAWCOOKIE.h"
#define MACLEN 6
enum
{
O_SACK_PERM = 0,
O_TIMESTAMP,
O_WSCALE,
O_MSS,
O_ECN,
O_SENDDIRECT,
O_TXMAC,
};
static void RAWCOOKIE_help(void)
{
printf(
"RAWCOOKIE target options:\n"
" --sack-perm Set SACK_PERM\n"
" --timestamp Set TIMESTAMP\n"
" --wscale value Set window scaling factor\n"
" --mss value Set MSS value\n"
" --ecn Set ECN\n"
" --senddirect Set send to direct\n"
" --txmac Set tx mac address\n");
}
static const struct xt_option_entry RAWCOOKIE_opts[] = {
{.name = "sack-perm", .id = O_SACK_PERM, .type = XTTYPE_NONE, },
{.name = "timestamp", .id = O_TIMESTAMP, .type = XTTYPE_NONE, },
{.name = "wscale", .id = O_WSCALE, .type = XTTYPE_UINT32, },
{.name = "mss", .id = O_MSS, .type = XTTYPE_UINT32, },
{.name = "ecn", .id = O_ECN, .type = XTTYPE_NONE, },
{.name = "senddirect", .id = O_SENDDIRECT, .type = XTTYPE_NONE, },
{.name = "txmac", .id = O_TXMAC, .type = XTTYPE_ETHERMAC, },
XTOPT_TABLEEND,
};
static void RAWCOOKIE_parse(struct xt_option_call *cb)
{
struct xt_rawcookie_info *info = cb->data;
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_SACK_PERM:
info->options |= XT_RAWCOOKIE_OPT_SACK_PERM;
break;
case O_TIMESTAMP:
info->options |= XT_RAWCOOKIE_OPT_TIMESTAMP;
break;
case O_WSCALE:
info->options |= XT_RAWCOOKIE_OPT_WSCALE;
info->wscale = cb->val.u32;
break;
case O_MSS:
info->options |= XT_RAWCOOKIE_OPT_MSS;
info->mss = cb->val.u32;
break;
case O_ECN:
info->options |= XT_RAWCOOKIE_OPT_ECN;
break;
case O_SENDDIRECT:
info->options |= XT_RAWCOOKIE_OPT_SENDDIRECT;
break;
case O_TXMAC:
info->options |= XT_RAWCOOKIE_OPT_TXMAC;
memcpy(info->txmac, cb->val.ethermac, MACLEN);
break;
}
}
static void RAWCOOKIE_check(struct xt_fcheck_call *cb)
{
}
static void RAWCOOKIE_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
const struct xt_rawcookie_info *info =
(const struct xt_rawcookie_info *)target->data;
printf(" RAWCOOKIE ");
if (info->options & XT_RAWCOOKIE_OPT_SACK_PERM)
printf("sack-perm ");
if (info->options & XT_RAWCOOKIE_OPT_TIMESTAMP)
printf("timestamp ");
if (info->options & XT_RAWCOOKIE_OPT_WSCALE)
printf("wscale %u ", info->wscale);
if (info->options & XT_RAWCOOKIE_OPT_MSS)
printf("mss %u ", info->mss);
if (info->options & XT_RAWCOOKIE_OPT_ECN)
printf("ecn ");
if (info->options & XT_RAWCOOKIE_OPT_SENDDIRECT)
printf("senddirect ");
if (info->options & XT_RAWCOOKIE_OPT_TXMAC)
printf("txmac %s ", info->txmac);
}
static void RAWCOOKIE_save(const void *ip, const struct xt_entry_target *target)
{
const struct xt_rawcookie_info *info =
(const struct xt_rawcookie_info *)target->data;
if (info->options & XT_RAWCOOKIE_OPT_SACK_PERM)
printf(" --sack-perm");
if (info->options & XT_RAWCOOKIE_OPT_TIMESTAMP)
printf(" --timestamp");
if (info->options & XT_RAWCOOKIE_OPT_WSCALE)
printf(" --wscale %u", info->wscale);
if (info->options & XT_RAWCOOKIE_OPT_MSS)
printf(" --mss %u", info->mss);
if (info->options & XT_RAWCOOKIE_OPT_ECN)
printf(" --ecn");
if (info->options & XT_RAWCOOKIE_OPT_SENDDIRECT)
printf(" --senddirect");
if (info->options & XT_RAWCOOKIE_OPT_TXMAC)
printf(" --txmac %s", info->txmac);
}
static struct xtables_target rawcookie_tg_reg = {
.family = NFPROTO_UNSPEC,
.name = "RAWCOOKIE",
.version = XTABLES_VERSION,
.revision = 0,
.size = XT_ALIGN(sizeof(struct xt_rawcookie_info)),
.userspacesize = XT_ALIGN(sizeof(struct xt_rawcookie_info)),
.help = RAWCOOKIE_help,
.print = RAWCOOKIE_print,
.save = RAWCOOKIE_save,
.x6_parse = RAWCOOKIE_parse,
.x6_fcheck = RAWCOOKIE_check,
.x6_options = RAWCOOKIE_opts,
};
void _init(void)
{
xtables_register_target(&rawcookie_tg_reg);
}