1 /* TTL modification target for IP tables
2 * (C) 2000,2005 by Harald Welte <laforge@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
13 #include <net/checksum.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
16 #include <linux/netfilter_ipv4/ipt_TTL.h>
18 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19 MODULE_DESCRIPTION("IP tables TTL modification module");
20 MODULE_LICENSE("GPL");
23 ipt_ttl_target(struct sk_buff **pskb,
24 const struct net_device *in, const struct net_device *out,
25 unsigned int hooknum, const struct xt_target *target,
26 const void *targinfo, void *userinfo)
29 const struct ipt_TTL_info *info = targinfo;
33 if (!skb_make_writable(pskb, (*pskb)->len))
36 iph = (*pskb)->nh.iph;
43 new_ttl = iph->ttl + info->ttl;
48 new_ttl = iph->ttl - info->ttl;
57 if (new_ttl != iph->ttl) {
58 diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
60 diffs[1] = htons(((unsigned)iph->ttl) << 8);
61 iph->check = csum_fold(csum_partial((char *)diffs,
69 static int ipt_ttl_checkentry(const char *tablename,
71 const struct xt_target *target,
73 unsigned int targinfosize,
74 unsigned int hook_mask)
76 struct ipt_TTL_info *info = targinfo;
78 if (info->mode > IPT_TTL_MAXMODE) {
79 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
83 if ((info->mode != IPT_TTL_SET) && (info->ttl == 0))
88 static struct ipt_target ipt_TTL = {
90 .target = ipt_ttl_target,
91 .targetsize = sizeof(struct ipt_TTL_info),
93 .checkentry = ipt_ttl_checkentry,
97 static int __init ipt_ttl_init(void)
99 return ipt_register_target(&ipt_TTL);
102 static void __exit ipt_ttl_fini(void)
104 ipt_unregister_target(&ipt_TTL);
107 module_init(ipt_ttl_init);
108 module_exit(ipt_ttl_fini);