Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[deliverable/linux.git] / net / ipv4 / netfilter / ipt_ttl.c
CommitLineData
e905a9ed 1/* IP tables module for matching the value of the TTL
1da177e4
LT
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
6709dbbb 10#include <linux/ip.h>
1da177e4
LT
11#include <linux/module.h>
12#include <linux/skbuff.h>
13
14#include <linux/netfilter_ipv4/ipt_ttl.h>
6709dbbb 15#include <linux/netfilter/x_tables.h>
1da177e4
LT
16
17MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
2ae15b64 18MODULE_DESCRIPTION("Xtables: IPv4 TTL field match");
1da177e4
LT
19MODULE_LICENSE("GPL");
20
d3c5ee6d
JE
21static bool
22ttl_mt(const struct sk_buff *skb, const struct net_device *in,
23 const struct net_device *out, const struct xt_match *match,
24 const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop)
1da177e4
LT
25{
26 const struct ipt_ttl_info *info = matchinfo;
eddc9ec5 27 const u8 ttl = ip_hdr(skb)->ttl;
1da177e4
LT
28
29 switch (info->mode) {
30 case IPT_TTL_EQ:
7c4e36bc 31 return ttl == info->ttl;
1da177e4 32 case IPT_TTL_NE:
7c4e36bc 33 return ttl != info->ttl;
1da177e4 34 case IPT_TTL_LT:
7c4e36bc 35 return ttl < info->ttl;
1da177e4 36 case IPT_TTL_GT:
7c4e36bc 37 return ttl > info->ttl;
1da177e4 38 default:
e905a9ed 39 printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
1da177e4 40 info->mode);
1d93a9cb 41 return false;
1da177e4
LT
42 }
43
1d93a9cb 44 return false;
1da177e4
LT
45}
46
d3c5ee6d 47static struct xt_match ttl_mt_reg __read_mostly = {
1da177e4 48 .name = "ttl",
6709dbbb 49 .family = AF_INET,
d3c5ee6d 50 .match = ttl_mt,
1d5cd909 51 .matchsize = sizeof(struct ipt_ttl_info),
1da177e4
LT
52 .me = THIS_MODULE,
53};
54
d3c5ee6d 55static int __init ttl_mt_init(void)
1da177e4 56{
d3c5ee6d 57 return xt_register_match(&ttl_mt_reg);
1da177e4
LT
58}
59
d3c5ee6d 60static void __exit ttl_mt_exit(void)
1da177e4 61{
d3c5ee6d 62 xt_unregister_match(&ttl_mt_reg);
1da177e4
LT
63}
64
d3c5ee6d
JE
65module_init(ttl_mt_init);
66module_exit(ttl_mt_exit);
This page took 0.323818 seconds and 5 git commands to generate.