Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* IP tables module for matching the routing realm |
| 2 | * |
| 3 | * $Id: ipt_realm.c,v 1.3 2004/03/05 13:25:40 laforge Exp $ |
| 4 | * |
| 5 | * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/skbuff.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <net/route.h> |
| 16 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 17 | #include <linux/netfilter_ipv4.h> |
| 18 | #include <linux/netfilter/xt_realm.h> |
| 19 | #include <linux/netfilter/x_tables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>"); |
| 22 | MODULE_LICENSE("GPL"); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 23 | MODULE_DESCRIPTION("X_tables realm match"); |
| 24 | MODULE_ALIAS("ipt_realm"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static int |
| 27 | match(const struct sk_buff *skb, |
| 28 | const struct net_device *in, |
| 29 | const struct net_device *out, |
| 30 | const void *matchinfo, |
| 31 | int offset, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 32 | unsigned int protoff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | int *hotdrop) |
| 34 | { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 35 | const struct xt_realm_info *info = matchinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct dst_entry *dst = skb->dst; |
| 37 | |
| 38 | return (info->id == (dst->tclassid & info->mask)) ^ info->invert; |
| 39 | } |
| 40 | |
| 41 | static int check(const char *tablename, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 42 | const void *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | void *matchinfo, |
| 44 | unsigned int matchsize, |
| 45 | unsigned int hook_mask) |
| 46 | { |
| 47 | if (hook_mask |
| 48 | & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) | |
| 49 | (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN))) { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 50 | printk("xt_realm: only valid for POST_ROUTING, LOCAL_OUT, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | "LOCAL_IN or FORWARD.\n"); |
| 52 | return 0; |
| 53 | } |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 54 | if (matchsize != XT_ALIGN(sizeof(struct xt_realm_info))) { |
| 55 | printk("xt_realm: invalid matchsize.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | return 1; |
| 59 | } |
| 60 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 61 | static struct xt_match realm_match = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .name = "realm", |
| 63 | .match = match, |
| 64 | .checkentry = check, |
| 65 | .me = THIS_MODULE |
| 66 | }; |
| 67 | |
| 68 | static int __init init(void) |
| 69 | { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 70 | return xt_register_match(AF_INET, &realm_match); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void __exit fini(void) |
| 74 | { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame^] | 75 | xt_unregister_match(AF_INET, &realm_match); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | module_init(init); |
| 79 | module_exit(fini); |