1 /* Shared library add-on to iptables for the TTL target
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 distributed under the terms of GNU GPL
14 #include <linux/netfilter_ipv4/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_TTL.h>
17 #define IPT_TTL_USED 1
19 static void init(struct ipt_entry_target *t, unsigned int *nfcache)
23 static void help(void)
26 "TTL target v%s options\n"
27 " --ttl-set value Set TTL to <value>\n"
28 " --ttl-dec value Decrement TTL by <value>\n"
29 " --ttl-inc value Increment TTL by <value>\n"
33 static int parse(int c, char **argv, int invert, unsigned int *flags,
34 const struct ipt_entry *entry,
35 struct ipt_entry_target **target)
37 struct ipt_TTL_info *info = (struct ipt_TTL_info *) (*target)->data;
40 if (*flags & IPT_TTL_USED) {
41 exit_error(PARAMETER_PROBLEM,
42 "Can't specify TTL option twice");
46 exit_error(PARAMETER_PROBLEM,
47 "TTL: You must specify a value");
49 if (check_inverse(optarg, &invert, NULL, 0))
50 exit_error(PARAMETER_PROBLEM,
51 "TTL: unexpected `!'");
58 info->mode = IPT_TTL_SET;
63 exit_error(PARAMETER_PROBLEM,
64 "TTL: decreasing by 0?");
67 info->mode = IPT_TTL_DEC;
72 exit_error(PARAMETER_PROBLEM,
73 "TTL: increasing by 0?");
76 info->mode = IPT_TTL_INC;
85 *flags |= IPT_TTL_USED;
90 static void final_check(unsigned int flags)
92 if (!(flags & IPT_TTL_USED))
93 exit_error(PARAMETER_PROBLEM,
94 "TTL: You must specify an action");
97 static void save(const struct ipt_ip *ip,
98 const struct ipt_entry_target *target)
100 const struct ipt_TTL_info *info =
101 (struct ipt_TTL_info *) target->data;
103 switch (info->mode) {
105 printf("--ttl-set ");
108 printf("--ttl-dec ");
112 printf("--ttl-inc ");
115 printf("%u ", info->ttl);
118 static void print(const struct ipt_ip *ip,
119 const struct ipt_entry_target *target, int numeric)
121 const struct ipt_TTL_info *info =
122 (struct ipt_TTL_info *) target->data;
125 switch (info->mode) {
130 printf("decrement by ");
133 printf("increment by ");
136 printf("%u ", info->ttl);
139 static struct option opts[] = {
140 { "ttl-set", 1, 0, '1' },
141 { "ttl-dec", 1, 0, '2' },
142 { "ttl-inc", 1, 0, '3' },
147 struct iptables_target TTL = { NULL,
150 IPT_ALIGN(sizeof(struct ipt_TTL_info)),
151 IPT_ALIGN(sizeof(struct ipt_TTL_info)),
163 register_target(&TTL);