2 * IPv6 Hop Limit Target module
3 * Maciej Soltysiak <solt@dns.toxicfilms.tv>
4 * Based on HW's ttl target
5 * This program is distributed under the terms of GNU GPL
14 #include <linux/netfilter_ipv6/ip6t_HL.h>
16 #define IP6T_HL_USED 1
18 static void HL_help(void)
22 " --hl-set value Set HL to <value 0-255>\n"
23 " --hl-dec value Decrement HL by <value 1-255>\n"
24 " --hl-inc value Increment HL by <value 1-255>\n");
27 static int HL_parse(int c, char **argv, int invert, unsigned int *flags,
28 const void *entry, struct xt_entry_target **target)
30 struct ip6t_HL_info *info = (struct ip6t_HL_info *) (*target)->data;
33 if (*flags & IP6T_HL_USED) {
34 xtables_error(PARAMETER_PROBLEM,
35 "Can't specify HL option twice");
39 xtables_error(PARAMETER_PROBLEM,
40 "HL: You must specify a value");
42 if (xtables_check_inverse(optarg, &invert, NULL, 0))
43 xtables_error(PARAMETER_PROBLEM,
44 "HL: unexpected `!'");
46 if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
47 xtables_error(PARAMETER_PROBLEM,
48 "HL: Expected value between 0 and 255");
53 info->mode = IP6T_HL_SET;
58 xtables_error(PARAMETER_PROBLEM,
59 "HL: decreasing by 0?");
62 info->mode = IP6T_HL_DEC;
67 xtables_error(PARAMETER_PROBLEM,
68 "HL: increasing by 0?");
71 info->mode = IP6T_HL_INC;
79 info->hop_limit = value;
80 *flags |= IP6T_HL_USED;
85 static void HL_check(unsigned int flags)
87 if (!(flags & IP6T_HL_USED))
88 xtables_error(PARAMETER_PROBLEM,
89 "HL: You must specify an action");
92 static void HL_save(const void *ip, const struct xt_entry_target *target)
94 const struct ip6t_HL_info *info =
95 (struct ip6t_HL_info *) target->data;
109 printf("%u ", info->hop_limit);
112 static void HL_print(const void *ip, const struct xt_entry_target *target,
115 const struct ip6t_HL_info *info =
116 (struct ip6t_HL_info *) target->data;
119 switch (info->mode) {
124 printf("decrement by ");
127 printf("increment by ");
130 printf("%u ", info->hop_limit);
133 static const struct option HL_opts[] = {
134 { "hl-set", 1, NULL, '1' },
135 { "hl-dec", 1, NULL, '2' },
136 { "hl-inc", 1, NULL, '3' },
140 static struct xtables_target hl_tg6_reg = {
142 .version = XTABLES_VERSION,
143 .family = NFPROTO_IPV6,
144 .size = XT_ALIGN(sizeof(struct ip6t_HL_info)),
145 .userspacesize = XT_ALIGN(sizeof(struct ip6t_HL_info)),
148 .final_check = HL_check,
151 .extra_opts = HL_opts,
156 xtables_register_target(&hl_tg6_reg);