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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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
, const struct xt_action_param
*par
)
32 const struct ipt_TTL_info
*info
= par
->targinfo
;
35 if (!skb_make_writable(skb
, skb
->len
))
45 new_ttl
= iph
->ttl
+ info
->ttl
;
50 new_ttl
= iph
->ttl
- info
->ttl
;
59 if (new_ttl
!= iph
->ttl
) {
60 csum_replace2(&iph
->check
, htons(iph
->ttl
<< 8),
69 hl_tg6(struct sk_buff
*skb
, const struct xt_action_param
*par
)
72 const struct ip6t_HL_info
*info
= par
->targinfo
;
75 if (!skb_make_writable(skb
, skb
->len
))
82 new_hl
= info
->hop_limit
;
85 new_hl
= ip6h
->hop_limit
+ info
->hop_limit
;
90 new_hl
= ip6h
->hop_limit
- info
->hop_limit
;
95 new_hl
= ip6h
->hop_limit
;
99 ip6h
->hop_limit
= new_hl
;
104 static int ttl_tg_check(const struct xt_tgchk_param
*par
)
106 const struct ipt_TTL_info
*info
= par
->targinfo
;
108 if (info
->mode
> IPT_TTL_MAXMODE
)
110 if (info
->mode
!= IPT_TTL_SET
&& info
->ttl
== 0)
115 static int hl_tg6_check(const struct xt_tgchk_param
*par
)
117 const struct ip6t_HL_info
*info
= par
->targinfo
;
119 if (info
->mode
> IP6T_HL_MAXMODE
)
121 if (info
->mode
!= IP6T_HL_SET
&& info
->hop_limit
== 0)
126 static struct xt_target hl_tg_reg
[] __read_mostly
= {
130 .family
= NFPROTO_IPV4
,
132 .targetsize
= sizeof(struct ipt_TTL_info
),
134 .checkentry
= ttl_tg_check
,
140 .family
= NFPROTO_IPV6
,
142 .targetsize
= sizeof(struct ip6t_HL_info
),
144 .checkentry
= hl_tg6_check
,
149 static int __init
hl_tg_init(void)
151 return xt_register_targets(hl_tg_reg
, ARRAY_SIZE(hl_tg_reg
));
154 static void __exit
hl_tg_exit(void)
156 xt_unregister_targets(hl_tg_reg
, ARRAY_SIZE(hl_tg_reg
));
159 module_init(hl_tg_init
);
160 module_exit(hl_tg_exit
);
161 MODULE_ALIAS("ipt_TTL");
162 MODULE_ALIAS("ip6t_HL");