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/x_tables.h>
 
  16 #include <linux/netfilter_ipv4/ipt_TTL.h>
 
  18 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
 
  19 MODULE_DESCRIPTION("Xtables: IPv4 TTL field modification target");
 
  20 MODULE_LICENSE("GPL");
 
  23 ttl_tg(struct sk_buff *skb, const struct xt_target_param *par)
 
  26         const struct ipt_TTL_info *info = par->targinfo;
 
  29         if (!skb_make_writable(skb, skb->len))
 
  39                         new_ttl = iph->ttl + info->ttl;
 
  44                         new_ttl = iph->ttl - info->ttl;
 
  53         if (new_ttl != iph->ttl) {
 
  54                 csum_replace2(&iph->check, htons(iph->ttl << 8),
 
  62 static bool ttl_tg_check(const struct xt_tgchk_param *par)
 
  64         const struct ipt_TTL_info *info = par->targinfo;
 
  66         if (info->mode > IPT_TTL_MAXMODE) {
 
  67                 printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
 
  71         if (info->mode != IPT_TTL_SET && info->ttl == 0)
 
  76 static struct xt_target ttl_tg_reg __read_mostly = {
 
  78         .family         = NFPROTO_IPV4,
 
  80         .targetsize     = sizeof(struct ipt_TTL_info),
 
  82         .checkentry     = ttl_tg_check,
 
  86 static int __init ttl_tg_init(void)
 
  88         return xt_register_target(&ttl_tg_reg);
 
  91 static void __exit ttl_tg_exit(void)
 
  93         xt_unregister_target(&ttl_tg_reg);
 
  96 module_init(ttl_tg_init);
 
  97 module_exit(ttl_tg_exit);