[SK_BUFF]: Introduce ip_hdr(), remove skb->nh.iph
[safe/jmp/linux-2.6] / net / ipv4 / netfilter / ipt_ttl.c
1 /* IP tables module for matching the value of the TTL
2  *
3  * ipt_ttl.c,v 1.5 2000/11/13 11:16:08 laforge Exp
4  *
5  * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/ip.h>
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
15
16 #include <linux/netfilter_ipv4/ipt_ttl.h>
17 #include <linux/netfilter/x_tables.h>
18
19 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
20 MODULE_DESCRIPTION("IP tables TTL matching module");
21 MODULE_LICENSE("GPL");
22
23 static int match(const struct sk_buff *skb,
24                  const struct net_device *in, const struct net_device *out,
25                  const struct xt_match *match, const void *matchinfo,
26                  int offset, unsigned int protoff, int *hotdrop)
27 {
28         const struct ipt_ttl_info *info = matchinfo;
29         const u8 ttl = ip_hdr(skb)->ttl;
30
31         switch (info->mode) {
32                 case IPT_TTL_EQ:
33                         return (ttl == info->ttl);
34                         break;
35                 case IPT_TTL_NE:
36                         return (!(ttl == info->ttl));
37                         break;
38                 case IPT_TTL_LT:
39                         return (ttl < info->ttl);
40                         break;
41                 case IPT_TTL_GT:
42                         return (ttl > info->ttl);
43                         break;
44                 default:
45                         printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
46                                 info->mode);
47                         return 0;
48         }
49
50         return 0;
51 }
52
53 static struct xt_match ttl_match = {
54         .name           = "ttl",
55         .family         = AF_INET,
56         .match          = match,
57         .matchsize      = sizeof(struct ipt_ttl_info),
58         .me             = THIS_MODULE,
59 };
60
61 static int __init ipt_ttl_init(void)
62 {
63         return xt_register_match(&ttl_match);
64 }
65
66 static void __exit ipt_ttl_fini(void)
67 {
68         xt_unregister_match(&ttl_match);
69 }
70
71 module_init(ipt_ttl_init);
72 module_exit(ipt_ttl_fini);