• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* IP tables module for matching the value of the TTL
2  *
3  * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9 
10 #include <linux/ip.h>
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 
14 #include <linux/netfilter_ipv4/ipt_ttl.h>
15 #include <linux/netfilter/x_tables.h>
16 
17 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
18 MODULE_DESCRIPTION("Xtables: IPv4 TTL field match");
19 MODULE_LICENSE("GPL");
20 
ttl_mt(const struct sk_buff * skb,const struct xt_match_param * par)21 static bool ttl_mt(const struct sk_buff *skb, const struct xt_match_param *par)
22 {
23 	const struct ipt_ttl_info *info = par->matchinfo;
24 	const u8 ttl = ip_hdr(skb)->ttl;
25 
26 	switch (info->mode) {
27 		case IPT_TTL_EQ:
28 			return ttl == info->ttl;
29 		case IPT_TTL_NE:
30 			return ttl != info->ttl;
31 		case IPT_TTL_LT:
32 			return ttl < info->ttl;
33 		case IPT_TTL_GT:
34 			return ttl > info->ttl;
35 		default:
36 			printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
37 				info->mode);
38 			return false;
39 	}
40 
41 	return false;
42 }
43 
44 static struct xt_match ttl_mt_reg __read_mostly = {
45 	.name		= "ttl",
46 	.family		= NFPROTO_IPV4,
47 	.match		= ttl_mt,
48 	.matchsize	= sizeof(struct ipt_ttl_info),
49 	.me		= THIS_MODULE,
50 };
51 
ttl_mt_init(void)52 static int __init ttl_mt_init(void)
53 {
54 	return xt_register_match(&ttl_mt_reg);
55 }
56 
ttl_mt_exit(void)57 static void __exit ttl_mt_exit(void)
58 {
59 	xt_unregister_match(&ttl_mt_reg);
60 }
61 
62 module_init(ttl_mt_init);
63 module_exit(ttl_mt_exit);
64