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, const struct net_device *in,
24 const struct net_device *out, unsigned int hooknum,
25 const void *targinfo, void *userinfo)
28 const struct ipt_TTL_info *info = targinfo;
32 if (!skb_make_writable(pskb, (*pskb)->len))
35 iph = (*pskb)->nh.iph;
42 new_ttl = iph->ttl + info->ttl;
47 new_ttl = iph->ttl - info->ttl;
56 if (new_ttl != iph->ttl) {
57 diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
59 diffs[1] = htons(((unsigned)iph->ttl) << 8);
60 iph->check = csum_fold(csum_partial((char *)diffs,
68 static int ipt_ttl_checkentry(const char *tablename,
69 const struct ipt_entry *e,
71 unsigned int targinfosize,
72 unsigned int hook_mask)
74 struct ipt_TTL_info *info = targinfo;
76 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
77 printk(KERN_WARNING "ipt_TTL: targinfosize %u != %Zu\n",
79 IPT_ALIGN(sizeof(struct ipt_TTL_info)));
83 if (strcmp(tablename, "mangle")) {
84 printk(KERN_WARNING "ipt_TTL: can only be called from "
85 "\"mangle\" table, not \"%s\"\n", tablename);
89 if (info->mode > IPT_TTL_MAXMODE) {
90 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
95 if ((info->mode != IPT_TTL_SET) && (info->ttl == 0))
101 static struct ipt_target ipt_TTL = {
103 .target = ipt_ttl_target,
104 .checkentry = ipt_ttl_checkentry,
108 static int __init init(void)
110 return ipt_register_target(&ipt_TTL);
113 static void __exit fini(void)
115 ipt_unregister_target(&ipt_TTL);