-
Notifications
You must be signed in to change notification settings - Fork 1
/
libxt_pdp.c
149 lines (128 loc) · 3.7 KB
/
libxt_pdp.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
// Author: [email protected] (Alexey Lapitsky)
#include <arpa/inet.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xtables.h>
#include <linux/netfilter.h>
#include "ipt_pdp.h"
static const struct option pdp_mt_opts[] = {
{.name = "pdp-any", .has_arg = false, .val = '1'},
{.name = "pdp-reserved", .has_arg = false, .val = '2'},
{.name = "pdp-station-id", .has_arg = true, .val = '3'},
{.name = "pdp-imsi", .has_arg = true, .val = '4'},
{NULL},
};
static void pdp_mt_help(void)
{
printf(
"pdp match options for PDP Create Context requests:\n"
" --pdp-any Match any request\n"
" --pdp-reserved Match hardcoded list of station ids\n"
" --pdp-station-id num Match particular Calling-Station-ID\n"
// " --pdp-imsi num Match particular 3GPP-IMSI\n"
);
}
static void pdp_mt_init(struct xt_entry_match *match)
{
struct xt_pdp_mtinfo *info = (void *)match->data;
}
static int pdp_mt_parse(int c, char **argv, int invert,
unsigned int *flags, const void *entry, struct xt_entry_match **match)
{
struct xt_pdp_mtinfo *info = (void *)(*match)->data;
struct in_addr *addrs, mask;
unsigned int naddrs;
if (info->type != 0)
xtables_error(PARAMETER_PROBLEM, "xt_pdp: "
"You can use only one param per rule");
switch (c) {
case '1':
*flags = info->type = PDP_ANY;
return true;
case '2':
*flags = info->type = PDP_RESERVED;
return true;
case '3': /* --station-id num */
if (strlen(optarg) > 12)
xtables_error(PARAMETER_PROBLEM, "xt_pdp: "
"Max parameter length is 12");
info->n = atoll(optarg);
*flags = info->type = PDP_STATION_ID;
return true;
case '4': /* --imsi num */
if (strlen(optarg) > 15)
xtables_error(PARAMETER_PROBLEM, "xt_pdp: "
"Max parameter length is 15");
info->n = atoll(optarg);
*flags = info->type = PDP_IMSI;
return true;
}
return false;
}
static void pdp_mt_check(unsigned int flags)
{
if (flags == 0)
xtables_error(PARAMETER_PROBLEM, "pdp: You need to "
"specify at least one parameter!");
}
static void pdp_mt_print(const void *entry,
const struct xt_entry_match *match, int numeric)
{
const struct xt_pdp_mtinfo *info = (const void *)match->data;
switch (info->type) {
case PDP_ANY:
printf("pdp-any");
return;
case PDP_RESERVED:
printf("pdp-reserved");
return;
case PDP_STATION_ID:
printf("pdp-station-id: %llu", (unsigned long long)info->n);
return;
case PDP_IMSI:
printf("pdp-imsi: %llu", (unsigned long long)info->n);
return;
}
return;
}
static void pdp_mt_save(const void *entry,
const struct xt_entry_match *match)
{
const struct xt_pdp_mtinfo *info = (const void *)match->data;
switch (info->type) {
case PDP_ANY:
printf("--pdp-any ");
return;
case PDP_RESERVED:
printf("--pdp-reserved ");
return;
case PDP_STATION_ID:
printf("--pdp-station-id %llu ", (unsigned long long)info->n);
return;
case PDP_IMSI:
printf("--pdp-imsi %llu ", (unsigned long long)info->n);
return;
}
return;
}
static struct xtables_match pdp_mt_reg = {
.version = XTABLES_VERSION,
.name = "pdp",
.revision = 0,
.size = XT_ALIGN(sizeof(struct xt_pdp_mtinfo)),
.userspacesize = XT_ALIGN(sizeof(struct xt_pdp_mtinfo)),
.help = pdp_mt_help,
.init = pdp_mt_init,
.parse = pdp_mt_parse,
.final_check = pdp_mt_check,
.print = pdp_mt_print,
.save = pdp_mt_save,
.extra_opts = pdp_mt_opts,
};
static void _init(void)
{
xtables_register_match(&pdp_mt_reg);
}