Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / net / ipv4 / netfilter / ipt_ttl.c
blobe0b8caeb710c9d188ded36dd0acb790719cf6c9b
1 /* IP tables module for matching the value of the TTL
3 * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>
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 */
10 #include <linux/ip.h>
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
14 #include <linux/netfilter_ipv4/ipt_ttl.h>
15 #include <linux/netfilter/x_tables.h>
17 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
18 MODULE_DESCRIPTION("Xtables: IPv4 TTL field match");
19 MODULE_LICENSE("GPL");
21 static bool
22 ttl_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)
26 const struct ipt_ttl_info *info = matchinfo;
27 const u8 ttl = ip_hdr(skb)->ttl;
29 switch (info->mode) {
30 case IPT_TTL_EQ:
31 return ttl == info->ttl;
32 case IPT_TTL_NE:
33 return ttl != info->ttl;
34 case IPT_TTL_LT:
35 return ttl < info->ttl;
36 case IPT_TTL_GT:
37 return ttl > info->ttl;
38 default:
39 printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
40 info->mode);
41 return false;
44 return false;
47 static struct xt_match ttl_mt_reg __read_mostly = {
48 .name = "ttl",
49 .family = AF_INET,
50 .match = ttl_mt,
51 .matchsize = sizeof(struct ipt_ttl_info),
52 .me = THIS_MODULE,
55 static int __init ttl_mt_init(void)
57 return xt_register_match(&ttl_mt_reg);
60 static void __exit ttl_mt_exit(void)
62 xt_unregister_match(&ttl_mt_reg);
65 module_init(ttl_mt_init);
66 module_exit(ttl_mt_exit);