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 | ||
12 | #include <linux/module.h> | |
13 | #include <linux/skbuff.h> | |
14 | ||
15 | #include <linux/netfilter_ipv4/ipt_ttl.h> | |
16 | #include <linux/netfilter_ipv4/ip_tables.h> | |
17 | ||
18 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); | |
19 | MODULE_DESCRIPTION("IP tables TTL matching module"); | |
20 | MODULE_LICENSE("GPL"); | |
21 | ||
c4986734 PM |
22 | static int match(const struct sk_buff *skb, |
23 | const struct net_device *in, const struct net_device *out, | |
24 | const struct xt_match *match, const void *matchinfo, | |
2e4e6a17 | 25 | int offset, unsigned int protoff, int *hotdrop) |
1da177e4 LT |
26 | { |
27 | const struct ipt_ttl_info *info = matchinfo; | |
28 | ||
29 | switch (info->mode) { | |
30 | case IPT_TTL_EQ: | |
31 | return (skb->nh.iph->ttl == info->ttl); | |
32 | break; | |
33 | case IPT_TTL_NE: | |
34 | return (!(skb->nh.iph->ttl == info->ttl)); | |
35 | break; | |
36 | case IPT_TTL_LT: | |
37 | return (skb->nh.iph->ttl < info->ttl); | |
38 | break; | |
39 | case IPT_TTL_GT: | |
40 | return (skb->nh.iph->ttl > info->ttl); | |
41 | break; | |
42 | default: | |
43 | printk(KERN_WARNING "ipt_ttl: unknown mode %d\n", | |
44 | info->mode); | |
45 | return 0; | |
46 | } | |
47 | ||
48 | return 0; | |
49 | } | |
50 | ||
1da177e4 LT |
51 | static struct ipt_match ttl_match = { |
52 | .name = "ttl", | |
1d5cd909 PM |
53 | .match = match, |
54 | .matchsize = sizeof(struct ipt_ttl_info), | |
1da177e4 LT |
55 | .me = THIS_MODULE, |
56 | }; | |
57 | ||
65b4b4e8 | 58 | static int __init ipt_ttl_init(void) |
1da177e4 LT |
59 | { |
60 | return ipt_register_match(&ttl_match); | |
61 | } | |
62 | ||
65b4b4e8 | 63 | static void __exit ipt_ttl_fini(void) |
1da177e4 LT |
64 | { |
65 | ipt_unregister_match(&ttl_match); | |
66 | ||
67 | } | |
68 | ||
65b4b4e8 AM |
69 | module_init(ipt_ttl_init); |
70 | module_exit(ipt_ttl_fini); |