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 int parse(int c
, char **argv
, int invert
, unsigned int *flags
,
29 const struct ip6t_entry
*entry
, unsigned int *nfcache
,
30 struct ip6t_entry_match
**match
)
32 struct ip6t_hl_info
*info
= (struct ip6t_hl_info
*) (*match
)->data
;
35 check_inverse(optarg
, &invert
, &optind
, 0);
36 value
= atoi(argv
[optind
-1]);
39 exit_error(PARAMETER_PROBLEM
,
40 "Can't specify HL option twice");
43 exit_error(PARAMETER_PROBLEM
,
44 "hl: You must specify a value");
48 info
->mode
= IP6T_HL_NE
;
50 info
->mode
= IP6T_HL_EQ
;
53 info
->hop_limit
= value
;
59 exit_error(PARAMETER_PROBLEM
,
60 "hl: unexpected `!'");
62 info
->mode
= IP6T_HL_LT
;
63 info
->hop_limit
= value
;
69 exit_error(PARAMETER_PROBLEM
,
70 "hl: unexpected `!'");
72 info
->mode
= IP6T_HL_GT
;
73 info
->hop_limit
= value
;
84 static void final_check(unsigned int flags
)
87 exit_error(PARAMETER_PROBLEM
,
88 "HL match: You must specify one of "
89 "`--hl-eq', `--hl-lt', `--hl-gt'");
92 static void print(const struct ip6t_ip6
*ip
,
93 const struct ip6t_entry_match
*match
,
96 static const char *op
[] = {
100 [IP6T_HL_GT
] = ">" };
102 const struct ip6t_hl_info
*info
=
103 (struct ip6t_hl_info
*) match
->data
;
105 printf("HL match HL %s %u ", op
[info
->mode
], info
->hop_limit
);
108 static void save(const struct ip6t_ip6
*ip
,
109 const struct ip6t_entry_match
*match
)
111 static const char *op
[] = {
113 [IP6T_HL_NE
] = "eq !",
115 [IP6T_HL_GT
] = "gt" };
117 const struct ip6t_hl_info
*info
=
118 (struct ip6t_hl_info
*) match
->data
;
120 printf("--hl-%s %u ", op
[info
->mode
], info
->hop_limit
);
123 static struct option opts
[] = {
124 { .name
= "hl", .has_arg
= 1, .flag
= 0, .val
= '2' },
125 { .name
= "hl-eq", .has_arg
= 1, .flag
= 0, .val
= '2' },
126 { .name
= "hl-lt", .has_arg
= 1, .flag
= 0, .val
= '3' },
127 { .name
= "hl-gt", .has_arg
= 1, .flag
= 0, .val
= '4' },
132 struct ip6tables_match hl
= {
134 .version
= IPTABLES_VERSION
,
135 .size
= IP6T_ALIGN(sizeof(struct ip6t_hl_info
)),
136 .userspacesize
= IP6T_ALIGN(sizeof(struct ip6t_hl_info
)),
139 .final_check
= &final_check
,
148 register_match6(&hl
);