1 /* Shared library add-on to iptables for the TTL target
2 * (C) 2000 by Harald Welte <laforge@gnumonks.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 TTL_help(void)
22 "TTL target options\n"
23 " --ttl-set value Set TTL to <value 0-255>\n"
24 " --ttl-dec value Decrement TTL by <value 1-255>\n"
25 " --ttl-inc value Increment TTL by <value 1-255>\n");
28 static int TTL_parse(int c, char **argv, int invert, unsigned int *flags,
29 const void *entry, struct xt_entry_target **target)
31 struct ipt_TTL_info *info = (struct ipt_TTL_info *) (*target)->data;
34 if (*flags & IPT_TTL_USED) {
35 exit_error(PARAMETER_PROBLEM,
36 "Can't specify TTL option twice");
40 exit_error(PARAMETER_PROBLEM,
41 "TTL: You must specify a value");
43 if (check_inverse(optarg, &invert, NULL, 0))
44 exit_error(PARAMETER_PROBLEM,
45 "TTL: unexpected `!'");
47 if (string_to_number(optarg, 0, 255, &value) == -1)
48 exit_error(PARAMETER_PROBLEM,
49 "TTL: Expected value between 0 and 255");
54 info->mode = IPT_TTL_SET;
59 exit_error(PARAMETER_PROBLEM,
60 "TTL: decreasing by 0?");
63 info->mode = IPT_TTL_DEC;
68 exit_error(PARAMETER_PROBLEM,
69 "TTL: increasing by 0?");
72 info->mode = IPT_TTL_INC;
81 *flags |= IPT_TTL_USED;
86 static void TTL_check(unsigned int flags)
88 if (!(flags & IPT_TTL_USED))
89 exit_error(PARAMETER_PROBLEM,
90 "TTL: You must specify an action");
93 static void TTL_save(const void *ip, const struct xt_entry_target *target)
95 const struct ipt_TTL_info *info =
96 (struct ipt_TTL_info *) target->data;
100 printf("--ttl-set ");
103 printf("--ttl-dec ");
107 printf("--ttl-inc ");
110 printf("%u ", info->ttl);
113 static void TTL_print(const void *ip, const struct xt_entry_target *target,
116 const struct ipt_TTL_info *info =
117 (struct ipt_TTL_info *) target->data;
120 switch (info->mode) {
125 printf("decrement by ");
128 printf("increment by ");
131 printf("%u ", info->ttl);
134 static const struct option TTL_opts[] = {
135 { "ttl-set", 1, NULL, '1' },
136 { "ttl-dec", 1, NULL, '2' },
137 { "ttl-inc", 1, NULL, '3' },
141 static struct xtables_target ttl_tg_reg = {
143 .version = XTABLES_VERSION,
145 .size = XT_ALIGN(sizeof(struct ipt_TTL_info)),
146 .userspacesize = XT_ALIGN(sizeof(struct ipt_TTL_info)),
149 .final_check = TTL_check,
152 .extra_opts = TTL_opts,
157 xtables_register_target(&ttl_tg_reg);