2 * TTL modification target for IP tables
3 * (C) 2000,2005 by Harald Welte <laforge@netfilter.org>
5 * Hop Limit modification target for ip6tables
6 * Maciej Soltysiak <solt@dns.toxicfilms.tv>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
16 #include <linux/ipv6.h>
17 #include <net/checksum.h>
19 #include <linux/netfilter/x_tables.h>
20 #include <linux/netfilter_ipv4/ipt_TTL.h>
21 #include <linux/netfilter_ipv6/ip6t_HL.h>
23 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
24 MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
25 MODULE_DESCRIPTION("Xtables: Hoplimit/TTL Limit field modification target");
26 MODULE_LICENSE("GPL");
29 ttl_tg(struct sk_buff
*skb
,
30 const struct net_device
*in
, const struct net_device
*out
,
31 unsigned int hooknum
, const struct xt_target
*target
,
35 const struct ipt_TTL_info
*info
= targinfo
;
38 if (!skb_make_writable(skb
, skb
->len
))
48 new_ttl
= iph
->ttl
+ info
->ttl
;
53 new_ttl
= iph
->ttl
- info
->ttl
;
62 if (new_ttl
!= iph
->ttl
) {
63 nf_csum_replace2(&iph
->check
, htons(iph
->ttl
<< 8),
72 hl_tg6(struct sk_buff
*skb
,
73 const struct net_device
*in
, const struct net_device
*out
,
74 unsigned int hooknum
, const struct xt_target
*target
,
78 const struct ip6t_HL_info
*info
= targinfo
;
81 if (!skb_make_writable(skb
, skb
->len
))
88 new_hl
= info
->hop_limit
;
91 new_hl
= ip6h
->hop_limit
+ info
->hop_limit
;
96 new_hl
= ip6h
->hop_limit
- info
->hop_limit
;
101 new_hl
= ip6h
->hop_limit
;
105 ip6h
->hop_limit
= new_hl
;
110 static int ttl_tg_check(const char *tablename
,
112 const struct xt_target
*target
,
114 unsigned int hook_mask
)
116 const struct ipt_TTL_info
*info
= targinfo
;
118 if (info
->mode
> IPT_TTL_MAXMODE
) {
119 printk(KERN_WARNING
"ipt_TTL: invalid or unknown Mode %u\n",
123 if (info
->mode
!= IPT_TTL_SET
&& info
->ttl
== 0)
128 static int hl_tg6_check(const char *tablename
,
130 const struct xt_target
*target
,
132 unsigned int hook_mask
)
134 const struct ip6t_HL_info
*info
= targinfo
;
136 if (info
->mode
> IP6T_HL_MAXMODE
) {
137 printk(KERN_WARNING
"ip6t_HL: invalid or unknown Mode %u\n",
141 if (info
->mode
!= IP6T_HL_SET
&& info
->hop_limit
== 0) {
142 printk(KERN_WARNING
"ip6t_HL: increment/decrement doesn't "
143 "make sense with value 0\n");
149 static struct xt_target hl_tg_reg
[] __read_mostly
= {
155 .targetsize
= sizeof(struct ipt_TTL_info
),
157 .checkentry
= ttl_tg_check
,
165 .targetsize
= sizeof(struct ip6t_HL_info
),
167 .checkentry
= hl_tg6_check
,
172 static int __init
hl_tg_init(void)
174 return xt_register_targets(hl_tg_reg
, ARRAY_SIZE(hl_tg_reg
));
177 static void __exit
hl_tg_exit(void)
179 xt_unregister_targets(hl_tg_reg
, ARRAY_SIZE(hl_tg_reg
));
182 module_init(hl_tg_init
);
183 module_exit(hl_tg_exit
);
184 MODULE_ALIAS("ipt_TTL");
185 MODULE_ALIAS("ip6t_HL");