Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
6709dbbb | 12 | #include <linux/ip.h> |
1da177e4 LT |
13 | #include <linux/module.h> |
14 | #include <linux/skbuff.h> | |
15 | ||
16 | #include <linux/netfilter_ipv4/ipt_ttl.h> | |
6709dbbb | 17 | #include <linux/netfilter/x_tables.h> |
1da177e4 LT |
18 | |
19 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); | |
20 | MODULE_DESCRIPTION("IP tables TTL matching module"); | |
21 | MODULE_LICENSE("GPL"); | |
22 | ||
c4986734 PM |
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, | |
2e4e6a17 | 26 | int offset, unsigned int protoff, int *hotdrop) |
1da177e4 LT |
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 | ||
6709dbbb | 52 | static struct xt_match ttl_match = { |
1da177e4 | 53 | .name = "ttl", |
6709dbbb | 54 | .family = AF_INET, |
1d5cd909 PM |
55 | .match = match, |
56 | .matchsize = sizeof(struct ipt_ttl_info), | |
1da177e4 LT |
57 | .me = THIS_MODULE, |
58 | }; | |
59 | ||
65b4b4e8 | 60 | static int __init ipt_ttl_init(void) |
1da177e4 | 61 | { |
6709dbbb | 62 | return xt_register_match(&ttl_match); |
1da177e4 LT |
63 | } |
64 | ||
65b4b4e8 | 65 | static void __exit ipt_ttl_fini(void) |
1da177e4 | 66 | { |
6709dbbb | 67 | xt_unregister_match(&ttl_match); |
1da177e4 LT |
68 | } |
69 | ||
65b4b4e8 AM |
70 | module_init(ipt_ttl_init); |
71 | module_exit(ipt_ttl_fini); |