2 * IPv6 Hop Limit matching module
3 * Maciej Soltysiak <solt@dns.toxicfilms.tv>
4 * Based on HW's ttl match
5 * This program is released under the terms of GNU GPL
6 * Cleanups by Stephane Ouellette <ouellettes@videotron.ca>
13 #include <ip6tables.h>
15 #include <linux/netfilter_ipv6/ip6_tables.h>
16 #include <linux/netfilter_ipv6/ip6t_hl.h>
18 static void help(void)
21 "HL match v%s options:\n"
22 " --hl-eq [!] value Match hop limit value\n"
23 " --hl-lt value Match HL < value\n"
24 " --hl-gt value Match HL > value\n"
28 static void init(struct ip6t_entry_match *m, unsigned int *nfcache)
30 /* caching not yet implemented */
31 *nfcache |= NFC_UNKNOWN;
34 static int parse(int c, char **argv, int invert, unsigned int *flags,
35 const struct ip6t_entry *entry, unsigned int *nfcache,
36 struct ip6t_entry_match **match)
38 struct ip6t_hl_info *info = (struct ip6t_hl_info *) (*match)->data;
41 check_inverse(optarg, &invert, &optind, 0);
42 value = atoi(argv[optind-1]);
45 exit_error(PARAMETER_PROBLEM,
46 "Can't specify HL option twice");
49 exit_error(PARAMETER_PROBLEM,
50 "hl: You must specify a value");
54 info->mode = IP6T_HL_NE;
56 info->mode = IP6T_HL_EQ;
59 info->hop_limit = value;
65 exit_error(PARAMETER_PROBLEM,
66 "hl: unexpected `!'");
68 info->mode = IP6T_HL_LT;
69 info->hop_limit = value;
75 exit_error(PARAMETER_PROBLEM,
76 "hl: unexpected `!'");
78 info->mode = IP6T_HL_GT;
79 info->hop_limit = value;
90 static void final_check(unsigned int flags)
93 exit_error(PARAMETER_PROBLEM,
94 "HL match: You must specify one of "
95 "`--hl-eq', `--hl-lt', `--hl-gt'");
98 static void print(const struct ip6t_ip6 *ip,
99 const struct ip6t_entry_match *match,
102 static const char *op[] = {
106 [IP6T_HL_GT] = ">" };
108 const struct ip6t_hl_info *info =
109 (struct ip6t_hl_info *) match->data;
111 printf("HL match HL %s %u ", op[info->mode], info->hop_limit);
114 static void save(const struct ip6t_ip6 *ip,
115 const struct ip6t_entry_match *match)
117 static const char *op[] = {
119 [IP6T_HL_NE] = "eq !",
121 [IP6T_HL_GT] = "gt" };
123 const struct ip6t_hl_info *info =
124 (struct ip6t_hl_info *) match->data;
126 printf("--hl-%s %u ", op[info->mode], info->hop_limit);
129 static struct option opts[] = {
130 { .name = "hl", .has_arg = 1, .flag = 0, .val = '2' },
131 { .name = "hl-eq", .has_arg = 1, .flag = 0, .val = '2' },
132 { .name = "hl-lt", .has_arg = 1, .flag = 0, .val = '3' },
133 { .name = "hl-gt", .has_arg = 1, .flag = 0, .val = '4' },
138 struct ip6tables_match hl = {
140 .version = IPTABLES_VERSION,
141 .size = IP6T_ALIGN(sizeof(struct ip6t_hl_info)),
142 .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_hl_info)),
146 .final_check = &final_check,
155 register_match6(&hl);