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 init(struct ip6t_entry_target *t, unsigned int *nfcache)
23 static void help(void)
26 "HL target v%s options\n"
27 " --hl-set value Set HL to <value>\n"
28 " --hl-dec value Decrement HL by <value>\n"
29 " --hl-inc value Increment HL by <value>\n"
33 static int parse(int c, char **argv, int invert, unsigned int *flags,
34 const struct ip6t_entry *entry,
35 struct ip6t_entry_target **target)
37 struct ip6t_HL_info *info = (struct ip6t_HL_info *) (*target)->data;
40 if (*flags & IP6T_HL_USED) {
41 exit_error(PARAMETER_PROBLEM,
42 "Can't specify HL option twice");
46 exit_error(PARAMETER_PROBLEM,
47 "HL: You must specify a value");
49 if (check_inverse(optarg, &invert, NULL, 0))
50 exit_error(PARAMETER_PROBLEM,
51 "HL: unexpected `!'");
58 info->mode = IP6T_HL_SET;
63 exit_error(PARAMETER_PROBLEM,
64 "HL: decreasing by 0?");
67 info->mode = IP6T_HL_DEC;
72 exit_error(PARAMETER_PROBLEM,
73 "HL: increasing by 0?");
76 info->mode = IP6T_HL_INC;
84 info->hop_limit = value;
85 *flags |= IP6T_HL_USED;
90 static void final_check(unsigned int flags)
92 if (!(flags & IP6T_HL_USED))
93 exit_error(PARAMETER_PROBLEM,
94 "HL: You must specify an action");
97 static void save(const struct ip6t_ip6 *ip,
98 const struct ip6t_entry_target *target)
100 const struct ip6t_HL_info *info =
101 (struct ip6t_HL_info *) target->data;
103 switch (info->mode) {
115 printf("%u ", info->hop_limit);
118 static void print(const struct ip6t_ip6 *ip,
119 const struct ip6t_entry_target *target, int numeric)
121 const struct ip6t_HL_info *info =
122 (struct ip6t_HL_info *) target->data;
125 switch (info->mode) {
130 printf("decrement by ");
133 printf("increment by ");
136 printf("%u ", info->hop_limit);
139 static struct option opts[] = {
140 { "hl-set", 1, 0, '1' },
141 { "hl-dec", 1, 0, '2' },
142 { "hl-inc", 1, 0, '3' },
147 struct ip6tables_target HL = { NULL,
150 IP6T_ALIGN(sizeof(struct ip6t_HL_info)),
151 IP6T_ALIGN(sizeof(struct ip6t_HL_info)),
163 register_target6(&HL);