2007-02-09 17:24:47 +03:00
|
|
|
/* IP tables module for matching the value of the TTL
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* (C) 2000,2001 by Harald Welte <laforge@netfilter.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2007-02-08 02:11:19 +03:00
|
|
|
#include <linux/ip.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
|
|
|
#include <linux/netfilter_ipv4/ipt_ttl.h>
|
2007-02-08 02:11:19 +03:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
|
|
|
|
MODULE_DESCRIPTION("IP tables TTL matching module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2007-12-05 10:24:03 +03:00
|
|
|
static bool
|
|
|
|
ttl_mt(const struct sk_buff *skb, const struct net_device *in,
|
|
|
|
const struct net_device *out, const struct xt_match *match,
|
|
|
|
const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
const struct ipt_ttl_info *info = matchinfo;
|
2007-04-21 09:47:35 +04:00
|
|
|
const u8 ttl = ip_hdr(skb)->ttl;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
switch (info->mode) {
|
|
|
|
case IPT_TTL_EQ:
|
2007-07-08 09:19:08 +04:00
|
|
|
return ttl == info->ttl;
|
2005-04-17 02:20:36 +04:00
|
|
|
case IPT_TTL_NE:
|
2007-07-08 09:19:08 +04:00
|
|
|
return ttl != info->ttl;
|
2005-04-17 02:20:36 +04:00
|
|
|
case IPT_TTL_LT:
|
2007-07-08 09:19:08 +04:00
|
|
|
return ttl < info->ttl;
|
2005-04-17 02:20:36 +04:00
|
|
|
case IPT_TTL_GT:
|
2007-07-08 09:19:08 +04:00
|
|
|
return ttl > info->ttl;
|
2005-04-17 02:20:36 +04:00
|
|
|
default:
|
2007-02-09 17:24:47 +03:00
|
|
|
printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
info->mode);
|
2007-07-08 09:15:35 +04:00
|
|
|
return false;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-07-08 09:15:35 +04:00
|
|
|
return false;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 10:24:03 +03:00
|
|
|
static struct xt_match ttl_mt_reg __read_mostly = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.name = "ttl",
|
2007-02-08 02:11:19 +03:00
|
|
|
.family = AF_INET,
|
2007-12-05 10:24:03 +03:00
|
|
|
.match = ttl_mt,
|
2006-03-21 05:01:14 +03:00
|
|
|
.matchsize = sizeof(struct ipt_ttl_info),
|
2005-04-17 02:20:36 +04:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2007-12-05 10:24:03 +03:00
|
|
|
static int __init ttl_mt_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-12-05 10:24:03 +03:00
|
|
|
return xt_register_match(&ttl_mt_reg);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 10:24:03 +03:00
|
|
|
static void __exit ttl_mt_exit(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-12-05 10:24:03 +03:00
|
|
|
xt_unregister_match(&ttl_mt_reg);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 10:24:03 +03:00
|
|
|
module_init(ttl_mt_init);
|
|
|
|
module_exit(ttl_mt_exit);
|