ipt_ttl.c 1.5 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
 *
 * (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.
 */

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

#include <linux/netfilter_ipv4/ipt_ttl.h>
15
#include <linux/netfilter/x_tables.h>
L
Linus Torvalds 已提交
16 17

MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
18
MODULE_DESCRIPTION("Xtables: IPv4 TTL field match");
L
Linus Torvalds 已提交
19 20
MODULE_LICENSE("GPL");

21
static bool ttl_mt(const struct sk_buff *skb, const struct xt_match_param *par)
L
Linus Torvalds 已提交
22
{
23
	const struct ipt_ttl_info *info = par->matchinfo;
24
	const u8 ttl = ip_hdr(skb)->ttl;
L
Linus Torvalds 已提交
25 26 27

	switch (info->mode) {
		case IPT_TTL_EQ:
28
			return ttl == info->ttl;
L
Linus Torvalds 已提交
29
		case IPT_TTL_NE:
30
			return ttl != info->ttl;
L
Linus Torvalds 已提交
31
		case IPT_TTL_LT:
32
			return ttl < info->ttl;
L
Linus Torvalds 已提交
33
		case IPT_TTL_GT:
34
			return ttl > info->ttl;
L
Linus Torvalds 已提交
35
		default:
36
			printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
L
Linus Torvalds 已提交
37
				info->mode);
38
			return false;
L
Linus Torvalds 已提交
39 40
	}

41
	return false;
L
Linus Torvalds 已提交
42 43
}

44
static struct xt_match ttl_mt_reg __read_mostly = {
L
Linus Torvalds 已提交
45
	.name		= "ttl",
46
	.family		= NFPROTO_IPV4,
47
	.match		= ttl_mt,
48
	.matchsize	= sizeof(struct ipt_ttl_info),
L
Linus Torvalds 已提交
49 50 51
	.me		= THIS_MODULE,
};

52
static int __init ttl_mt_init(void)
L
Linus Torvalds 已提交
53
{
54
	return xt_register_match(&ttl_mt_reg);
L
Linus Torvalds 已提交
55 56
}

57
static void __exit ttl_mt_exit(void)
L
Linus Torvalds 已提交
58
{
59
	xt_unregister_match(&ttl_mt_reg);
L
Linus Torvalds 已提交
60 61
}

62 63
module_init(ttl_mt_init);
module_exit(ttl_mt_exit);