2007-02-09 15:24:47 +01:00
|
|
|
/* IP tables module for matching the value of the TTL
|
2005-04-17 00:20:36 +02: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 00:11:19 +01:00
|
|
|
#include <linux/ip.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
|
|
|
#include <linux/netfilter_ipv4/ipt_ttl.h>
|
2007-02-08 00:11:19 +01:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
|
|
|
|
MODULE_DESCRIPTION("IP tables TTL matching module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2007-07-08 07:15:35 +02:00
|
|
|
static bool match(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 00:20:36 +02:00
|
|
|
{
|
|
|
|
const struct ipt_ttl_info *info = matchinfo;
|
2007-04-21 07:47:35 +02:00
|
|
|
const u8 ttl = ip_hdr(skb)->ttl;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
switch (info->mode) {
|
|
|
|
case IPT_TTL_EQ:
|
2007-07-08 07:19:08 +02:00
|
|
|
return ttl == info->ttl;
|
2005-04-17 00:20:36 +02:00
|
|
|
case IPT_TTL_NE:
|
2007-07-08 07:19:08 +02:00
|
|
|
return ttl != info->ttl;
|
2005-04-17 00:20:36 +02:00
|
|
|
case IPT_TTL_LT:
|
2007-07-08 07:19:08 +02:00
|
|
|
return ttl < info->ttl;
|
2005-04-17 00:20:36 +02:00
|
|
|
case IPT_TTL_GT:
|
2007-07-08 07:19:08 +02:00
|
|
|
return ttl > info->ttl;
|
2005-04-17 00:20:36 +02:00
|
|
|
default:
|
2007-02-09 15:24:47 +01:00
|
|
|
printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
|
2005-04-17 00:20:36 +02:00
|
|
|
info->mode);
|
2007-07-08 07:15:35 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2007-07-08 07:15:35 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2007-07-08 07:22:02 +02:00
|
|
|
static struct xt_match ttl_match __read_mostly = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.name = "ttl",
|
2007-02-08 00:11:19 +01:00
|
|
|
.family = AF_INET,
|
2006-03-21 03:01:14 +01:00
|
|
|
.match = match,
|
|
|
|
.matchsize = sizeof(struct ipt_ttl_info),
|
2005-04-17 00:20:36 +02:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init ipt_ttl_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-02-08 00:11:19 +01:00
|
|
|
return xt_register_match(&ttl_match);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit ipt_ttl_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-02-08 00:11:19 +01:00
|
|
|
xt_unregister_match(&ttl_match);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(ipt_ttl_init);
|
|
|
|
module_exit(ipt_ttl_fini);
|