[kernel] add patch from #4850 to make hdparm work on usb drivers (#4850)
[openwrt/svn-archive/archive.git] / target / linux / generic-2.4 / patches / 605-netfilter_TTL.patch
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'.
6
7 +TTL target support
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
11 + amount.
12 +
13 + If you want to compile it as a module, say M here and read
14 + Documentation/modules.txt. If unsure, say `N'.
15 +
16 ipchains (2.2-style) support
17 CONFIG_IP_NF_COMPAT_IPCHAINS
18 This option places ipchains (with masquerading and redirection
19 --- /dev/null
20 +++ b/include/linux/netfilter_ipv4/ipt_TTL.h
21 @@ -0,0 +1,21 @@
22 +/* TTL modification module for IP tables
23 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
24 +
25 +#ifndef _IPT_TTL_H
26 +#define _IPT_TTL_H
27 +
28 +enum {
29 + IPT_TTL_SET = 0,
30 + IPT_TTL_INC,
31 + IPT_TTL_DEC
32 +};
33 +
34 +#define IPT_TTL_MAXMODE IPT_TTL_DEC
35 +
36 +struct ipt_TTL_info {
37 + u_int8_t mode;
38 + u_int8_t ttl;
39 +};
40 +
41 +
42 +#endif
43 --- a/net/ipv4/netfilter/Config.in
44 +++ b/net/ipv4/netfilter/Config.in
45 @@ -126,6 +126,7 @@ if [ "$CONFIG_IP_NF_IPTABLES" != "n" ];
46 dep_tristate ' CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_MANGLE
47 fi
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
52 fi
53 --- /dev/null
54 +++ b/net/ipv4/netfilter/ipt_TTL.c
55 @@ -0,0 +1,110 @@
56 +/* TTL modification target for IP tables
57 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
58 + *
59 + * Version: $Revision: 1.1 $
60 + *
61 + * This software is distributed under the terms of GNU GPL
62 + */
63 +
64 +#include <linux/module.h>
65 +#include <linux/skbuff.h>
66 +#include <linux/ip.h>
67 +#include <net/checksum.h>
68 +
69 +#include <linux/netfilter_ipv4/ip_tables.h>
70 +#include <linux/netfilter_ipv4/ipt_TTL.h>
71 +
72 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
73 +MODULE_DESCRIPTION("IP tables TTL modification module");
74 +MODULE_LICENSE("GPL");
75 +
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)
79 +{
80 + struct iphdr *iph = (*pskb)->nh.iph;
81 + const struct ipt_TTL_info *info = targinfo;
82 + u_int16_t diffs[2];
83 + int new_ttl;
84 +
85 + switch (info->mode) {
86 + case IPT_TTL_SET:
87 + new_ttl = info->ttl;
88 + break;
89 + case IPT_TTL_INC:
90 + new_ttl = iph->ttl + info->ttl;
91 + if (new_ttl > 255)
92 + new_ttl = 255;
93 + break;
94 + case IPT_TTL_DEC:
95 + new_ttl = iph->ttl - info->ttl;
96 + if (new_ttl < 0)
97 + new_ttl = 0;
98 + break;
99 + default:
100 + new_ttl = iph->ttl;
101 + break;
102 + }
103 +
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,
109 + sizeof(diffs),
110 + iph->check^0xFFFF));
111 + (*pskb)->nfcache |= NFC_ALTERED;
112 + }
113 +
114 + return IPT_CONTINUE;
115 +}
116 +
117 +static int ipt_ttl_checkentry(const char *tablename,
118 + const struct ipt_entry *e,
119 + void *targinfo,
120 + unsigned int targinfosize,
121 + unsigned int hook_mask)
122 +{
123 + struct ipt_TTL_info *info = targinfo;
124 +
125 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
126 + printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
127 + targinfosize,
128 + IPT_ALIGN(sizeof(struct ipt_TTL_info)));
129 + return 0;
130 + }
131 +
132 + if (strcmp(tablename, "mangle")) {
133 + printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
134 + return 0;
135 + }
136 +
137 + if (info->mode > IPT_TTL_MAXMODE) {
138 + printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n",
139 + info->mode);
140 + return 0;
141 + }
142 +
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");
145 + return 0;
146 + }
147 +
148 + return 1;
149 +}
150 +
151 +static struct ipt_target ipt_TTL = { { NULL, NULL }, "TTL",
152 + ipt_ttl_target, ipt_ttl_checkentry, NULL, THIS_MODULE };
153 +
154 +static int __init init(void)
155 +{
156 + return ipt_register_target(&ipt_TTL);
157 +}
158 +
159 +static void __exit fini(void)
160 +{
161 + ipt_unregister_target(&ipt_TTL);
162 +}
163 +
164 +module_init(init);
165 +module_exit(fini);
166 --- a/net/ipv4/netfilter/Makefile
167 +++ b/net/ipv4/netfilter/Makefile
168 @@ -110,6 +110,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
175