1 --- a/Documentation/Configure.help
2 +++ b/Documentation/Configure.help
3 @@ -3220,6 +3220,15 @@ CONFIG_IP_NF_TARGET_CLASSIFY
4 If you want to compile it as a module, say M here and read
5 Documentation/modules.txt. If unsure, say `N'.
8 +CONFIG_IP_NF_TARGET_TTL
9 + This option adds a `TTL' target, which enables the user to set
10 + the TTL value or increment / decrement the TTL value by a given
13 + If you want to compile it as a module, say M here and read
14 + Documentation/modules.txt. If unsure, say `N'.
16 ipchains (2.2-style) support
17 CONFIG_IP_NF_COMPAT_IPCHAINS
18 This option places ipchains (with masquerading and redirection
20 +++ b/include/linux/netfilter_ipv4/ipt_TTL.h
22 +/* TTL modification module for IP tables
23 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
34 +#define IPT_TTL_MAXMODE IPT_TTL_DEC
36 +struct ipt_TTL_info {
43 --- a/net/ipv4/netfilter/Config.in
44 +++ b/net/ipv4/netfilter/Config.in
45 @@ -110,6 +110,7 @@ if [ "$CONFIG_IP_NF_IPTABLES" != "n" ];
46 dep_tristate ' CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_MANGLE
48 dep_tristate ' LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES
49 + dep_tristate ' TTL target support' CONFIG_IP_NF_TARGET_TTL $CONFIG_IP_NF_IPTABLES
50 dep_tristate ' ULOG target support' CONFIG_IP_NF_TARGET_ULOG $CONFIG_IP_NF_IPTABLES
51 dep_tristate ' TCPMSS target support' CONFIG_IP_NF_TARGET_TCPMSS $CONFIG_IP_NF_IPTABLES
54 +++ b/net/ipv4/netfilter/ipt_TTL.c
56 +/* TTL modification target for IP tables
57 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
59 + * Version: $Revision: 1.1 $
61 + * This software is distributed under the terms of GNU GPL
64 +#include <linux/module.h>
65 +#include <linux/skbuff.h>
66 +#include <linux/ip.h>
67 +#include <net/checksum.h>
69 +#include <linux/netfilter_ipv4/ip_tables.h>
70 +#include <linux/netfilter_ipv4/ipt_TTL.h>
72 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
73 +MODULE_DESCRIPTION("IP tables TTL modification module");
74 +MODULE_LICENSE("GPL");
76 +static unsigned int ipt_ttl_target(struct sk_buff **pskb, unsigned int hooknum,
77 + const struct net_device *in, const struct net_device *out,
78 + const void *targinfo, void *userinfo)
80 + struct iphdr *iph = (*pskb)->nh.iph;
81 + const struct ipt_TTL_info *info = targinfo;
85 + switch (info->mode) {
87 + new_ttl = info->ttl;
90 + new_ttl = iph->ttl + info->ttl;
95 + new_ttl = iph->ttl - info->ttl;
100 + new_ttl = iph->ttl;
104 + if (new_ttl != iph->ttl) {
105 + diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
106 + iph->ttl = new_ttl;
107 + diffs[1] = htons(((unsigned)iph->ttl) << 8);
108 + iph->check = csum_fold(csum_partial((char *)diffs,
110 + iph->check^0xFFFF));
111 + (*pskb)->nfcache |= NFC_ALTERED;
114 + return IPT_CONTINUE;
117 +static int ipt_ttl_checkentry(const char *tablename,
118 + const struct ipt_entry *e,
120 + unsigned int targinfosize,
121 + unsigned int hook_mask)
123 + struct ipt_TTL_info *info = targinfo;
125 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
126 + printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
128 + IPT_ALIGN(sizeof(struct ipt_TTL_info)));
132 + if (strcmp(tablename, "mangle")) {
133 + printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
137 + if (info->mode > IPT_TTL_MAXMODE) {
138 + printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n",
143 + if ((info->mode != IPT_TTL_SET) && (info->ttl == 0)) {
144 + printk(KERN_WARNING "TTL: increment/decrement doesn't make sense with value 0\n");
151 +static struct ipt_target ipt_TTL = { { NULL, NULL }, "TTL",
152 + ipt_ttl_target, ipt_ttl_checkentry, NULL, THIS_MODULE };
154 +static int __init init(void)
156 + return ipt_register_target(&ipt_TTL);
159 +static void __exit fini(void)
161 + ipt_unregister_target(&ipt_TTL);
166 --- a/net/ipv4/netfilter/Makefile
167 +++ b/net/ipv4/netfilter/Makefile
168 @@ -101,6 +101,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
169 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
170 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
171 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
172 +obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
173 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
174 obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o