1 /* Shared library add-on to iptables for the TTL target
2 * (C) 2000 by Harald Welte <laforge@gnumonks.org>
4 * $Id: libipt_TTL.c 3507 2004-12-28 13:11:59Z /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=rusty/emailAddress=rusty@netfilter.org $
6 * This program is distributed under the terms of GNU GPL
14 #include <linux/netfilter_ipv4/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_TTL.h>
17 #define IPT_TTL_USED 1
19 static void init(struct ipt_entry_target
*t
, unsigned int *nfcache
)
23 static void help(void)
26 "TTL target v%s options\n"
27 " --ttl-set value Set TTL to <value 0-255>\n"
28 " --ttl-dec value Decrement TTL by <value 1-255>\n"
29 " --ttl-inc value Increment TTL by <value 1-255>\n"
33 static int parse(int c
, char **argv
, int invert
, unsigned int *flags
,
34 const struct ipt_entry
*entry
,
35 struct ipt_entry_target
**target
)
37 struct ipt_TTL_info
*info
= (struct ipt_TTL_info
*) (*target
)->data
;
40 if (*flags
& IPT_TTL_USED
) {
41 exit_error(PARAMETER_PROBLEM
,
42 "Can't specify TTL option twice");
46 exit_error(PARAMETER_PROBLEM
,
47 "TTL: You must specify a value");
49 if (check_inverse(optarg
, &invert
, NULL
, 0))
50 exit_error(PARAMETER_PROBLEM
,
51 "TTL: unexpected `!'");
53 if (string_to_number(optarg
, 0, 255, &value
) == -1)
54 exit_error(PARAMETER_PROBLEM
,
55 "TTL: Expected value between 0 and 255");
60 info
->mode
= IPT_TTL_SET
;
65 exit_error(PARAMETER_PROBLEM
,
66 "TTL: decreasing by 0?");
69 info
->mode
= IPT_TTL_DEC
;
74 exit_error(PARAMETER_PROBLEM
,
75 "TTL: increasing by 0?");
78 info
->mode
= IPT_TTL_INC
;
87 *flags
|= IPT_TTL_USED
;
92 static void final_check(unsigned int flags
)
94 if (!(flags
& IPT_TTL_USED
))
95 exit_error(PARAMETER_PROBLEM
,
96 "TTL: You must specify an action");
99 static void save(const struct ipt_ip
*ip
,
100 const struct ipt_entry_target
*target
)
102 const struct ipt_TTL_info
*info
=
103 (struct ipt_TTL_info
*) target
->data
;
105 switch (info
->mode
) {
107 printf("--ttl-set ");
110 printf("--ttl-dec ");
114 printf("--ttl-inc ");
117 printf("%u ", info
->ttl
);
120 static void print(const struct ipt_ip
*ip
,
121 const struct ipt_entry_target
*target
, int numeric
)
123 const struct ipt_TTL_info
*info
=
124 (struct ipt_TTL_info
*) target
->data
;
127 switch (info
->mode
) {
132 printf("decrement by ");
135 printf("increment by ");
138 printf("%u ", info
->ttl
);
141 static struct option opts
[] = {
142 { "ttl-set", 1, 0, '1' },
143 { "ttl-dec", 1, 0, '2' },
144 { "ttl-inc", 1, 0, '3' },
148 static struct iptables_target TTL
= {
151 .version
= IPTABLES_VERSION
,
152 .size
= IPT_ALIGN(sizeof(struct ipt_TTL_info
)),
153 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_TTL_info
)),
157 .final_check
= &final_check
,
165 register_target(&TTL
);