Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv6 / netfilter / ip6t_hl.c
blob0beaff5471dd320adbc8be0deb2f43954a0b1ce7
1 /* Hop Limit matching module */
3 /* (C) 2001-2002 Maciej Soltysiak <solt@dns.toxicfilms.tv>
4 * Based on HW's ttl module
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
14 #include <linux/netfilter_ipv6/ip6t_hl.h>
15 #include <linux/netfilter_ipv6/ip6_tables.h>
17 MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
18 MODULE_DESCRIPTION("IP tables Hop Limit matching module");
19 MODULE_LICENSE("GPL");
21 static int match(const struct sk_buff *skb, const struct net_device *in,
22 const struct net_device *out, const void *matchinfo,
23 int offset, unsigned int protoff,
24 int *hotdrop)
26 const struct ip6t_hl_info *info = matchinfo;
27 const struct ipv6hdr *ip6h = skb->nh.ipv6h;
29 switch (info->mode) {
30 case IP6T_HL_EQ:
31 return (ip6h->hop_limit == info->hop_limit);
32 break;
33 case IP6T_HL_NE:
34 return (!(ip6h->hop_limit == info->hop_limit));
35 break;
36 case IP6T_HL_LT:
37 return (ip6h->hop_limit < info->hop_limit);
38 break;
39 case IP6T_HL_GT:
40 return (ip6h->hop_limit > info->hop_limit);
41 break;
42 default:
43 printk(KERN_WARNING "ip6t_hl: unknown mode %d\n",
44 info->mode);
45 return 0;
48 return 0;
51 static int checkentry(const char *tablename, const struct ip6t_ip6 *ip,
52 void *matchinfo, unsigned int matchsize,
53 unsigned int hook_mask)
55 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_hl_info)))
56 return 0;
58 return 1;
61 static struct ip6t_match hl_match = {
62 .name = "hl",
63 .match = &match,
64 .checkentry = &checkentry,
65 .me = THIS_MODULE,
68 static int __init init(void)
70 return ip6t_register_match(&hl_match);
73 static void __exit fini(void)
75 ip6t_unregister_match(&hl_match);
79 module_init(init);
80 module_exit(fini);