1 /* Shared library add-on to iptables to add TTL matching support
2 * (C) 2000 by Harald Welte <laforge@gnumonks.org>
6 * This program is released under the terms of GNU GPL */
14 #include <linux/netfilter_ipv4/ipt_ttl.h>
16 static void ttl_help(void)
19 "ttl match options:\n"
20 " --ttl-eq value Match time to live value\n"
21 " --ttl-lt value Match TTL < value\n"
22 " --ttl-gt value Match TTL > value\n");
25 static int ttl_parse(int c
, char **argv
, int invert
, unsigned int *flags
,
26 const void *entry
, struct xt_entry_match
**match
)
28 struct ipt_ttl_info
*info
= (struct ipt_ttl_info
*) (*match
)->data
;
31 xtables_check_inverse(optarg
, &invert
, &optind
, 0);
35 if (!xtables_strtoui(optarg
, NULL
, &value
, 0, UINT8_MAX
))
36 xtables_error(PARAMETER_PROBLEM
,
37 "ttl: Expected value between 0 and 255");
40 info
->mode
= IPT_TTL_NE
;
42 info
->mode
= IPT_TTL_EQ
;
48 if (!xtables_strtoui(optarg
, NULL
, &value
, 0, UINT8_MAX
))
49 xtables_error(PARAMETER_PROBLEM
,
50 "ttl: Expected value between 0 and 255");
53 xtables_error(PARAMETER_PROBLEM
,
54 "ttl: unexpected `!'");
56 info
->mode
= IPT_TTL_LT
;
60 if (!xtables_strtoui(optarg
, NULL
, &value
, 0, UINT8_MAX
))
61 xtables_error(PARAMETER_PROBLEM
,
62 "ttl: Expected value between 0 and 255");
65 xtables_error(PARAMETER_PROBLEM
,
66 "ttl: unexpected `!'");
68 info
->mode
= IPT_TTL_GT
;
77 xtables_error(PARAMETER_PROBLEM
,
78 "Can't specify TTL option twice");
84 static void ttl_check(unsigned int flags
)
87 xtables_error(PARAMETER_PROBLEM
,
88 "TTL match: You must specify one of "
89 "`--ttl-eq', `--ttl-lt', `--ttl-gt");
92 static void ttl_print(const void *ip
, const struct xt_entry_match
*match
,
95 const struct ipt_ttl_info
*info
=
96 (struct ipt_ttl_info
*) match
->data
;
113 printf("%u ", info
->ttl
);
116 static void ttl_save(const void *ip
, const struct xt_entry_match
*match
)
118 const struct ipt_ttl_info
*info
=
119 (struct ipt_ttl_info
*) match
->data
;
121 switch (info
->mode
) {
126 printf("! --ttl-eq ");
138 printf("%u ", info
->ttl
);
141 static const struct option ttl_opts
[] = {
142 { "ttl", 1, NULL
, '2' },
143 { "ttl-eq", 1, NULL
, '2'},
144 { "ttl-lt", 1, NULL
, '3'},
145 { "ttl-gt", 1, NULL
, '4'},
149 static struct xtables_match ttl_mt_reg
= {
151 .version
= XTABLES_VERSION
,
152 .family
= NFPROTO_IPV4
,
153 .size
= XT_ALIGN(sizeof(struct ipt_ttl_info
)),
154 .userspacesize
= XT_ALIGN(sizeof(struct ipt_ttl_info
)),
157 .final_check
= ttl_check
,
160 .extra_opts
= ttl_opts
,
166 xtables_register_match(&ttl_mt_reg
);