2007-02-09 15:24:49 +01:00
|
|
|
/*
|
2005-08-28 07:37:30 +02:00
|
|
|
* Hop Limit modification target for ip6tables
|
|
|
|
* Maciej Soltysiak <solt@dns.toxicfilms.tv>
|
|
|
|
* Based on HW's TTL module
|
|
|
|
*
|
|
|
|
* This software is distributed under the terms of GNU GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/ip.h>
|
2007-02-08 00:11:19 +01:00
|
|
|
#include <linux/ipv6.h>
|
2005-08-28 07:37:30 +02:00
|
|
|
|
2007-02-08 00:11:19 +01:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-08-28 07:37:30 +02:00
|
|
|
#include <linux/netfilter_ipv6/ip6t_HL.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
|
2008-01-15 08:42:28 +01:00
|
|
|
MODULE_DESCRIPTION("Xtables: IPv6 Hop Limit field modification target");
|
2005-08-28 07:37:30 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2007-12-05 08:24:03 +01:00
|
|
|
static unsigned int
|
2008-10-08 11:35:19 +02:00
|
|
|
hl_tg6(struct sk_buff *skb, const struct xt_target_param *par)
|
2005-08-28 07:37:30 +02:00
|
|
|
{
|
|
|
|
struct ipv6hdr *ip6h;
|
2008-10-08 11:35:19 +02:00
|
|
|
const struct ip6t_HL_info *info = par->targinfo;
|
2005-08-28 07:37:30 +02:00
|
|
|
int new_hl;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
if (!skb_make_writable(skb, skb->len))
|
2005-08-28 07:37:30 +02:00
|
|
|
return NF_DROP;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
ip6h = ipv6_hdr(skb);
|
2005-08-28 07:37:30 +02:00
|
|
|
|
|
|
|
switch (info->mode) {
|
|
|
|
case IP6T_HL_SET:
|
|
|
|
new_hl = info->hop_limit;
|
|
|
|
break;
|
|
|
|
case IP6T_HL_INC:
|
|
|
|
new_hl = ip6h->hop_limit + info->hop_limit;
|
|
|
|
if (new_hl > 255)
|
|
|
|
new_hl = 255;
|
|
|
|
break;
|
|
|
|
case IP6T_HL_DEC:
|
|
|
|
new_hl = ip6h->hop_limit - info->hop_limit;
|
|
|
|
if (new_hl < 0)
|
|
|
|
new_hl = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_hl = ip6h->hop_limit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-02-08 00:06:43 +01:00
|
|
|
ip6h->hop_limit = new_hl;
|
2005-08-28 07:37:30 +02:00
|
|
|
|
2007-02-08 00:11:19 +01:00
|
|
|
return XT_CONTINUE;
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 11:35:19 +02:00
|
|
|
static bool hl_tg6_check(const struct xt_tgchk_param *par)
|
2005-08-28 07:37:30 +02:00
|
|
|
{
|
2008-10-08 11:35:19 +02:00
|
|
|
const struct ip6t_HL_info *info = par->targinfo;
|
2005-08-28 07:37:30 +02:00
|
|
|
|
|
|
|
if (info->mode > IP6T_HL_MAXMODE) {
|
2007-02-09 15:24:49 +01:00
|
|
|
printk(KERN_WARNING "ip6t_HL: invalid or unknown Mode %u\n",
|
2005-08-28 07:37:30 +02:00
|
|
|
info->mode);
|
2007-07-08 07:16:26 +02:00
|
|
|
return false;
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
2007-07-08 07:19:08 +02:00
|
|
|
if (info->mode != IP6T_HL_SET && info->hop_limit == 0) {
|
2005-08-28 07:37:30 +02:00
|
|
|
printk(KERN_WARNING "ip6t_HL: increment/decrement doesn't "
|
|
|
|
"make sense with value 0\n");
|
2007-07-08 07:16:26 +02:00
|
|
|
return false;
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
2007-07-08 07:16:26 +02:00
|
|
|
return true;
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 08:24:03 +01:00
|
|
|
static struct xt_target hl_tg6_reg __read_mostly = {
|
2007-02-09 15:24:49 +01:00
|
|
|
.name = "HL",
|
2008-10-08 11:35:01 +02:00
|
|
|
.family = NFPROTO_IPV6,
|
2007-12-05 08:24:03 +01:00
|
|
|
.target = hl_tg6,
|
2006-03-21 03:01:43 +01:00
|
|
|
.targetsize = sizeof(struct ip6t_HL_info),
|
|
|
|
.table = "mangle",
|
2007-12-05 08:24:03 +01:00
|
|
|
.checkentry = hl_tg6_check,
|
2005-08-28 07:37:30 +02:00
|
|
|
.me = THIS_MODULE
|
|
|
|
};
|
|
|
|
|
2007-12-05 08:24:03 +01:00
|
|
|
static int __init hl_tg6_init(void)
|
2005-08-28 07:37:30 +02:00
|
|
|
{
|
2007-12-05 08:24:03 +01:00
|
|
|
return xt_register_target(&hl_tg6_reg);
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 08:24:03 +01:00
|
|
|
static void __exit hl_tg6_exit(void)
|
2005-08-28 07:37:30 +02:00
|
|
|
{
|
2007-12-05 08:24:03 +01:00
|
|
|
xt_unregister_target(&hl_tg6_reg);
|
2005-08-28 07:37:30 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 08:24:03 +01:00
|
|
|
module_init(hl_tg6_init);
|
|
|
|
module_exit(hl_tg6_exit);
|