ipt_ttl.c 1.7 KB
Newer Older
1
/* IP tables module for matching the value of the TTL
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11
 *
 * ipt_ttl.c,v 1.5 2000/11/13 11:16:08 laforge Exp
 *
 * (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.
 */

12
#include <linux/ip.h>
L
Linus Torvalds 已提交
13 14 15 16
#include <linux/module.h>
#include <linux/skbuff.h>

#include <linux/netfilter_ipv4/ipt_ttl.h>
17
#include <linux/netfilter/x_tables.h>
L
Linus Torvalds 已提交
18 19 20 21 22

MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
MODULE_DESCRIPTION("IP tables TTL matching module");
MODULE_LICENSE("GPL");

23 24 25
static int match(const struct sk_buff *skb,
		 const struct net_device *in, const struct net_device *out,
		 const struct xt_match *match, const void *matchinfo,
26
		 int offset, unsigned int protoff, int *hotdrop)
L
Linus Torvalds 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
{
	const struct ipt_ttl_info *info = matchinfo;

	switch (info->mode) {
		case IPT_TTL_EQ:
			return (skb->nh.iph->ttl == info->ttl);
			break;
		case IPT_TTL_NE:
			return (!(skb->nh.iph->ttl == info->ttl));
			break;
		case IPT_TTL_LT:
			return (skb->nh.iph->ttl < info->ttl);
			break;
		case IPT_TTL_GT:
			return (skb->nh.iph->ttl > info->ttl);
			break;
		default:
44
			printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
L
Linus Torvalds 已提交
45 46 47 48 49 50 51
				info->mode);
			return 0;
	}

	return 0;
}

52
static struct xt_match ttl_match = {
L
Linus Torvalds 已提交
53
	.name		= "ttl",
54
	.family		= AF_INET,
55 56
	.match		= match,
	.matchsize	= sizeof(struct ipt_ttl_info),
L
Linus Torvalds 已提交
57 58 59
	.me		= THIS_MODULE,
};

60
static int __init ipt_ttl_init(void)
L
Linus Torvalds 已提交
61
{
62
	return xt_register_match(&ttl_match);
L
Linus Torvalds 已提交
63 64
}

65
static void __exit ipt_ttl_fini(void)
L
Linus Torvalds 已提交
66
{
67
	xt_unregister_match(&ttl_match);
L
Linus Torvalds 已提交
68 69
}

70 71
module_init(ipt_ttl_init);
module_exit(ipt_ttl_fini);