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
12 #include <ip6tables.h>
14 #include <linux/netfilter_ipv6/ip6_tables.h>
15 #include <linux/netfilter_ipv6/ip6t_HL.h>
17 #define IP6T_HL_USED 1
19 static void HL_help(void)
23 " --hl-set value Set HL to <value 0-255>\n"
24 " --hl-dec value Decrement HL by <value 1-255>\n"
25 " --hl-inc value Increment HL by <value 1-255>\n");
28 static int HL_parse(int c, char **argv, int invert, unsigned int *flags,
29 const void *entry, struct xt_entry_target **target)
31 struct ip6t_HL_info *info = (struct ip6t_HL_info *) (*target)->data;
34 if (*flags & IP6T_HL_USED) {
35 exit_error(PARAMETER_PROBLEM,
36 "Can't specify HL option twice");
40 exit_error(PARAMETER_PROBLEM,
41 "HL: You must specify a value");
43 if (check_inverse(optarg, &invert, NULL, 0))
44 exit_error(PARAMETER_PROBLEM,
45 "HL: unexpected `!'");
47 if (string_to_number(optarg, 0, 255, &value) == -1)
48 exit_error(PARAMETER_PROBLEM,
49 "HL: Expected value between 0 and 255");
54 info->mode = IP6T_HL_SET;
59 exit_error(PARAMETER_PROBLEM,
60 "HL: decreasing by 0?");
63 info->mode = IP6T_HL_DEC;
68 exit_error(PARAMETER_PROBLEM,
69 "HL: increasing by 0?");
72 info->mode = IP6T_HL_INC;
80 info->hop_limit = value;
81 *flags |= IP6T_HL_USED;
86 static void HL_check(unsigned int flags)
88 if (!(flags & IP6T_HL_USED))
89 exit_error(PARAMETER_PROBLEM,
90 "HL: You must specify an action");
93 static void HL_save(const void *ip, const struct xt_entry_target *target)
95 const struct ip6t_HL_info *info =
96 (struct ip6t_HL_info *) target->data;
110 printf("%u ", info->hop_limit);
113 static void HL_print(const void *ip, const struct xt_entry_target *target,
116 const struct ip6t_HL_info *info =
117 (struct ip6t_HL_info *) target->data;
120 switch (info->mode) {
125 printf("decrement by ");
128 printf("increment by ");
131 printf("%u ", info->hop_limit);
134 static const struct option HL_opts[] = {
135 { "hl-set", 1, NULL, '1' },
136 { "hl-dec", 1, NULL, '2' },
137 { "hl-inc", 1, NULL, '3' },
141 static struct xtables_target hl_tg6_reg = {
143 .version = XTABLES_VERSION,
145 .size = XT_ALIGN(sizeof(struct ip6t_HL_info)),
146 .userspacesize = XT_ALIGN(sizeof(struct ip6t_HL_info)),
149 .final_check = HL_check,
152 .extra_opts = HL_opts,
157 xtables_register_target(&hl_tg6_reg);