Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Hop Limit matching module */ |
| 2 | |
| 3 | /* (C) 2001-2002 Maciej Soltysiak <solt@dns.toxicfilms.tv> |
| 4 | * Based on HW's ttl module |
| 5 | * |
| 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 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/skbuff.h> |
| 13 | |
| 14 | #include <linux/netfilter_ipv6/ip6t_hl.h> |
| 15 | #include <linux/netfilter_ipv6/ip6_tables.h> |
| 16 | |
| 17 | MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>"); |
| 18 | MODULE_DESCRIPTION("IP tables Hop Limit matching module"); |
| 19 | MODULE_LICENSE("GPL"); |
| 20 | |
Patrick McHardy | c498673 | 2006-03-20 18:02:56 -0800 | [diff] [blame] | 21 | static int match(const struct sk_buff *skb, |
| 22 | const struct net_device *in, const struct net_device *out, |
| 23 | const struct xt_match *match, const void *matchinfo, |
| 24 | int offset, unsigned int protoff, int *hotdrop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
| 26 | const struct ip6t_hl_info *info = matchinfo; |
| 27 | const struct ipv6hdr *ip6h = skb->nh.ipv6h; |
| 28 | |
| 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; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static struct ip6t_match hl_match = { |
| 52 | .name = "hl", |
Patrick McHardy | 7f93971 | 2006-03-20 18:01:43 -0800 | [diff] [blame] | 53 | .match = match, |
| 54 | .matchsize = sizeof(struct ip6t_hl_info), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .me = THIS_MODULE, |
| 56 | }; |
| 57 | |
| 58 | static int __init init(void) |
| 59 | { |
| 60 | return ip6t_register_match(&hl_match); |
| 61 | } |
| 62 | |
| 63 | static void __exit fini(void) |
| 64 | { |
| 65 | ip6t_unregister_match(&hl_match); |
| 66 | |
| 67 | } |
| 68 | |
| 69 | module_init(init); |
| 70 | module_exit(fini); |