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>
15 #include <linux/netfilter_ipv6/ip6t_hl.h>
17 static void hl_help(void)
21 "[!] --hl-eq value Match hop limit value\n"
22 " --hl-lt value Match HL < value\n"
23 " --hl-gt value Match HL > value\n");
26 static int hl_parse(int c
, char **argv
, int invert
, unsigned int *flags
,
27 const void *entry
, struct xt_entry_match
**match
)
29 struct ip6t_hl_info
*info
= (struct ip6t_hl_info
*) (*match
)->data
;
32 xtables_check_inverse(optarg
, &invert
, &optind
, 0);
33 value
= atoi(argv
[optind
-1]);
36 xtables_error(PARAMETER_PROBLEM
,
37 "Can't specify HL option twice");
40 xtables_error(PARAMETER_PROBLEM
,
41 "hl: You must specify a value");
45 info
->mode
= IP6T_HL_NE
;
47 info
->mode
= IP6T_HL_EQ
;
50 info
->hop_limit
= value
;
56 xtables_error(PARAMETER_PROBLEM
,
57 "hl: unexpected `!'");
59 info
->mode
= IP6T_HL_LT
;
60 info
->hop_limit
= value
;
66 xtables_error(PARAMETER_PROBLEM
,
67 "hl: unexpected `!'");
69 info
->mode
= IP6T_HL_GT
;
70 info
->hop_limit
= value
;
81 static void hl_check(unsigned int flags
)
84 xtables_error(PARAMETER_PROBLEM
,
85 "HL match: You must specify one of "
86 "`--hl-eq', `--hl-lt', `--hl-gt'");
89 static void hl_print(const void *ip
, const struct xt_entry_match
*match
,
92 static const char *const op
[] = {
98 const struct ip6t_hl_info
*info
=
99 (struct ip6t_hl_info
*) match
->data
;
101 printf("HL match HL %s %u ", op
[info
->mode
], info
->hop_limit
);
104 static void hl_save(const void *ip
, const struct xt_entry_match
*match
)
106 static const char *const op
[] = {
107 [IP6T_HL_EQ
] = "--hl-eq",
108 [IP6T_HL_NE
] = "! --hl-eq",
109 [IP6T_HL_LT
] = "--hl-lt",
110 [IP6T_HL_GT
] = "--hl-gt" };
112 const struct ip6t_hl_info
*info
=
113 (struct ip6t_hl_info
*) match
->data
;
115 printf("%s %u ", op
[info
->mode
], info
->hop_limit
);
118 static const struct option hl_opts
[] = {
119 { .name
= "hl", .has_arg
= 1, .val
= '2' },
120 { .name
= "hl-eq", .has_arg
= 1, .val
= '2' },
121 { .name
= "hl-lt", .has_arg
= 1, .val
= '3' },
122 { .name
= "hl-gt", .has_arg
= 1, .val
= '4' },
126 static struct xtables_match hl_mt6_reg
= {
128 .version
= XTABLES_VERSION
,
129 .family
= NFPROTO_IPV6
,
130 .size
= XT_ALIGN(sizeof(struct ip6t_hl_info
)),
131 .userspacesize
= XT_ALIGN(sizeof(struct ip6t_hl_info
)),
134 .final_check
= hl_check
,
137 .extra_opts
= hl_opts
,
143 xtables_register_match(&hl_mt6_reg
);