blob: cc3e76d77a9931f7f697188967465b78d998748b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* IP tables module for matching the routing realm
2 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
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
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/netdevice.h>
13#include <net/route.h>
14
Harald Welte2e4e6a12006-01-12 13:30:04 -080015#include <linux/netfilter_ipv4.h>
16#include <linux/netfilter/xt_realm.h>
17#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
20MODULE_LICENSE("GPL");
Harald Welte2e4e6a12006-01-12 13:30:04 -080021MODULE_DESCRIPTION("X_tables realm match");
22MODULE_ALIAS("ipt_realm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070024static bool
Linus Torvalds1da177e2005-04-16 15:20:36 -070025match(const struct sk_buff *skb,
26 const struct net_device *in,
27 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -080028 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 const void *matchinfo,
30 int offset,
Harald Welte2e4e6a12006-01-12 13:30:04 -080031 unsigned int protoff,
Jan Engelhardtcff533a2007-07-07 22:15:12 -070032 bool *hotdrop)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Harald Welte2e4e6a12006-01-12 13:30:04 -080034 const struct xt_realm_info *info = matchinfo;
Jan Engelhardta47362a2007-07-07 22:16:55 -070035 const struct dst_entry *dst = skb->dst;
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
38}
39
Patrick McHardy9f15c532007-07-07 22:22:02 -070040static struct xt_match realm_match __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .name = "realm",
Patrick McHardy5d04bff2006-03-20 18:01:58 -080042 .match = match,
43 .matchsize = sizeof(struct xt_realm_info),
44 .hooks = (1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
45 (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN),
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080046 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .me = THIS_MODULE
48};
49
Andrew Morton65b4b4e2006-03-28 16:37:06 -080050static int __init xt_realm_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080052 return xt_register_match(&realm_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Andrew Morton65b4b4e2006-03-28 16:37:06 -080055static void __exit xt_realm_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080057 xt_unregister_match(&realm_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Andrew Morton65b4b4e2006-03-28 16:37:06 -080060module_init(xt_realm_init);
61module_exit(xt_realm_fini);