netfilter: xtables: move extension arguments into compound structure (1/6)
[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
f7108a20 21static bool ttl_mt(const struct sk_buff *skb, const struct xt_match_param *par)
1da177e4 22{
f7108a20 23 const struct ipt_ttl_info *info = par->matchinfo;
eddc9ec5 24 const u8 ttl = ip_hdr(skb)->ttl;
1da177e4
LT
25
26 switch (info->mode) {
27 case IPT_TTL_EQ:
7c4e36bc 28 return ttl == info->ttl;
1da177e4 29 case IPT_TTL_NE:
7c4e36bc 30 return ttl != info->ttl;
1da177e4 31 case IPT_TTL_LT:
7c4e36bc 32 return ttl < info->ttl;
1da177e4 33 case IPT_TTL_GT:
7c4e36bc 34 return ttl > info->ttl;
1da177e4 35 default:
e905a9ed 36 printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
1da177e4 37 info->mode);
1d93a9cb 38 return false;
1da177e4
LT
39 }
40
1d93a9cb 41 return false;
1da177e4
LT
42}
43
d3c5ee6d 44static struct xt_match ttl_mt_reg __read_mostly = {
1da177e4 45 .name = "ttl",
ee999d8b 46 .family = NFPROTO_IPV4,
d3c5ee6d 47 .match = ttl_mt,
1d5cd909 48 .matchsize = sizeof(struct ipt_ttl_info),
1da177e4
LT
49 .me = THIS_MODULE,
50};
51
d3c5ee6d 52static int __init ttl_mt_init(void)
1da177e4 53{
d3c5ee6d 54 return xt_register_match(&ttl_mt_reg);
1da177e4
LT
55}
56
d3c5ee6d 57static void __exit ttl_mt_exit(void)
1da177e4 58{
d3c5ee6d 59 xt_unregister_match(&ttl_mt_reg);
1da177e4
LT
60}
61
d3c5ee6d
JE
62module_init(ttl_mt_init);
63module_exit(ttl_mt_exit);
This page took 0.394247 seconds and 5 git commands to generate.