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/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_ttl.h>
17 static void ttl_help(void)
20 "ttl match options:\n"
21 " --ttl-eq value Match time to live value\n"
22 " --ttl-lt value Match TTL < value\n"
23 " --ttl-gt value Match TTL > value\n");
26 static int ttl_parse(int c, char **argv, int invert, unsigned int *flags,
27 const void *entry, struct xt_entry_match **match)
29 struct ipt_ttl_info *info = (struct ipt_ttl_info *) (*match)->data;
32 check_inverse(optarg, &invert, &optind, 0);
36 if (string_to_number(optarg, 0, 255, &value) == -1)
37 exit_error(PARAMETER_PROBLEM,
38 "ttl: Expected value between 0 and 255");
41 info->mode = IPT_TTL_NE;
43 info->mode = IPT_TTL_EQ;
49 if (string_to_number(optarg, 0, 255, &value) == -1)
50 exit_error(PARAMETER_PROBLEM,
51 "ttl: Expected value between 0 and 255");
54 exit_error(PARAMETER_PROBLEM,
55 "ttl: unexpected `!'");
57 info->mode = IPT_TTL_LT;
61 if (string_to_number(optarg, 0, 255, &value) == -1)
62 exit_error(PARAMETER_PROBLEM,
63 "ttl: Expected value between 0 and 255");
66 exit_error(PARAMETER_PROBLEM,
67 "ttl: unexpected `!'");
69 info->mode = IPT_TTL_GT;
78 exit_error(PARAMETER_PROBLEM,
79 "Can't specify TTL option twice");
85 static void ttl_check(unsigned int flags)
88 exit_error(PARAMETER_PROBLEM,
89 "TTL match: You must specify one of "
90 "`--ttl-eq', `--ttl-lt', `--ttl-gt");
93 static void ttl_print(const void *ip, const struct xt_entry_match *match,
96 const struct ipt_ttl_info *info =
97 (struct ipt_ttl_info *) match->data;
100 switch (info->mode) {
114 printf("%u ", info->ttl);
117 static void ttl_save(const void *ip, const struct xt_entry_match *match)
119 const struct ipt_ttl_info *info =
120 (struct ipt_ttl_info *) match->data;
122 switch (info->mode) {
127 printf("! --ttl-eq ");
139 printf("%u ", info->ttl);
142 static const struct option ttl_opts[] = {
143 { "ttl", 1, NULL, '2' },
144 { "ttl-eq", 1, NULL, '2'},
145 { "ttl-lt", 1, NULL, '3'},
146 { "ttl-gt", 1, NULL, '4'},
150 static struct xtables_match ttl_mt_reg = {
152 .version = XTABLES_VERSION,
154 .size = XT_ALIGN(sizeof(struct ipt_ttl_info)),
155 .userspacesize = XT_ALIGN(sizeof(struct ipt_ttl_info)),
158 .final_check = ttl_check,
161 .extra_opts = ttl_opts,
167 xtables_register_match(&ttl_mt_reg);