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/ipt_TTL.h>
16 #define IPT_TTL_USED 1
18 static void TTL_help(void)
21 "TTL target options\n"
22 " --ttl-set value Set TTL to <value 0-255>\n"
23 " --ttl-dec value Decrement TTL by <value 1-255>\n"
24 " --ttl-inc value Increment TTL by <value 1-255>\n");
27 static int TTL_parse(int c, char **argv, int invert, unsigned int *flags,
28 const void *entry, struct xt_entry_target **target)
30 struct ipt_TTL_info *info = (struct ipt_TTL_info *) (*target)->data;
33 if (*flags & IPT_TTL_USED) {
34 xtables_error(PARAMETER_PROBLEM,
35 "Can't specify TTL option twice");
39 xtables_error(PARAMETER_PROBLEM,
40 "TTL: You must specify a value");
42 if (xtables_check_inverse(optarg, &invert, NULL, 0))
43 xtables_error(PARAMETER_PROBLEM,
44 "TTL: unexpected `!'");
46 if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
47 xtables_error(PARAMETER_PROBLEM,
48 "TTL: Expected value between 0 and 255");
53 info->mode = IPT_TTL_SET;
58 xtables_error(PARAMETER_PROBLEM,
59 "TTL: decreasing by 0?");
62 info->mode = IPT_TTL_DEC;
67 xtables_error(PARAMETER_PROBLEM,
68 "TTL: increasing by 0?");
71 info->mode = IPT_TTL_INC;
80 *flags |= IPT_TTL_USED;
85 static void TTL_check(unsigned int flags)
87 if (!(flags & IPT_TTL_USED))
88 xtables_error(PARAMETER_PROBLEM,
89 "TTL: You must specify an action");
92 static void TTL_save(const void *ip, const struct xt_entry_target *target)
94 const struct ipt_TTL_info *info =
95 (struct ipt_TTL_info *) target->data;
102 printf("--ttl-dec ");
106 printf("--ttl-inc ");
109 printf("%u ", info->ttl);
112 static void TTL_print(const void *ip, const struct xt_entry_target *target,
115 const struct ipt_TTL_info *info =
116 (struct ipt_TTL_info *) target->data;
119 switch (info->mode) {
124 printf("decrement by ");
127 printf("increment by ");
130 printf("%u ", info->ttl);
133 static const struct option TTL_opts[] = {
134 { "ttl-set", 1, NULL, '1' },
135 { "ttl-dec", 1, NULL, '2' },
136 { "ttl-inc", 1, NULL, '3' },
140 static struct xtables_target ttl_tg_reg = {
142 .version = XTABLES_VERSION,
143 .family = NFPROTO_IPV4,
144 .size = XT_ALIGN(sizeof(struct ipt_TTL_info)),
145 .userspacesize = XT_ALIGN(sizeof(struct ipt_TTL_info)),
148 .final_check = TTL_check,
151 .extra_opts = TTL_opts,
156 xtables_register_target(&ttl_tg_reg);