]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - net/ipv4/netfilter/ipt_ttl.c
[IP]: Introduce ip_hdrlen()
[linux-3.10.git] / 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
30         switch (info->mode) {
31                 case IPT_TTL_EQ:
32                         return (skb->nh.iph->ttl == info->ttl);
33                         break;
34                 case IPT_TTL_NE:
35                         return (!(skb->nh.iph->ttl == info->ttl));
36                         break;
37                 case IPT_TTL_LT:
38                         return (skb->nh.iph->ttl < info->ttl);
39                         break;
40                 case IPT_TTL_GT:
41                         return (skb->nh.iph->ttl > info->ttl);
42                         break;
43                 default:
44                         printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
45                                 info->mode);
46                         return 0;
47         }
48
49         return 0;
50 }
51
52 static struct xt_match ttl_match = {
53         .name           = "ttl",
54         .family         = AF_INET,
55         .match          = match,
56         .matchsize      = sizeof(struct ipt_ttl_info),
57         .me             = THIS_MODULE,
58 };
59
60 static int __init ipt_ttl_init(void)
61 {
62         return xt_register_match(&ttl_match);
63 }
64
65 static void __exit ipt_ttl_fini(void)
66 {
67         xt_unregister_match(&ttl_match);
68 }
69
70 module_init(ipt_ttl_init);
71 module_exit(ipt_ttl_fini);