1 /* Shared library add-on to iptables to add TTL matching support
2 * (C) 2000 by Harald Welte <laforge@gnumonks.org>
4 * $Id: libipt_ttl.c,v 1.6 2002/05/29 13:08:16 laforge Exp $
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 help(void)
20 "TTL match v%s 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"
27 static void init(struct ipt_entry_match *m, unsigned int *nfcache)
29 /* caching not yet implemented */
30 *nfcache |= NFC_UNKNOWN;
33 static int parse(int c, char **argv, int invert, unsigned int *flags,
34 const struct ipt_entry *entry, unsigned int *nfcache,
35 struct ipt_entry_match **match)
37 struct ipt_ttl_info *info = (struct ipt_ttl_info *) (*match)->data;
40 check_inverse(optarg, &invert, &optind, 0);
41 value = atoi(argv[optind-1]);
44 exit_error(PARAMETER_PROBLEM,
45 "Can't specify TTL option twice");
48 exit_error(PARAMETER_PROBLEM,
49 "ttl: You must specify a value");
53 info->mode = IPT_TTL_NE;
55 info->mode = IPT_TTL_EQ;
64 exit_error(PARAMETER_PROBLEM,
65 "ttl: unexpected `!'");
67 info->mode = IPT_TTL_LT;
74 exit_error(PARAMETER_PROBLEM,
75 "ttl: unexpected `!'");
77 info->mode = IPT_TTL_GT;
90 static void final_check(unsigned int flags)
93 exit_error(PARAMETER_PROBLEM,
94 "TTL match: You must specify one of "
95 "`--ttl-eq', `--ttl-lt', `--ttl-gt");
98 static void print(const struct ipt_ip *ip,
99 const struct ipt_entry_match *match,
102 const struct ipt_ttl_info *info =
103 (struct ipt_ttl_info *) match->data;
105 printf("TTL match ");
106 switch (info->mode) {
120 printf("%u ", info->ttl);
123 static void save(const struct ipt_ip *ip,
124 const struct ipt_entry_match *match)
126 const struct ipt_ttl_info *info =
127 (struct ipt_ttl_info *) match->data;
129 switch (info->mode) {
134 printf("! --ttl-eq ");
146 printf("%u ", info->ttl);
149 static struct option opts[] = {
150 { "ttl", 1, 0, '2' },
151 { "ttl-eq", 1, 0, '2'},
152 { "ttl-lt", 1, 0, '3'},
153 { "ttl-gt", 1, 0, '4'},
158 struct iptables_match ttl = {
162 IPT_ALIGN(sizeof(struct ipt_ttl_info)),
163 IPT_ALIGN(sizeof(struct ipt_ttl_info)),
176 register_match(&ttl);