blob: a80b7d132b65fd7cf2460758f7bf007cbf54cad9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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 Welte2e4e6a12006-01-12 13:30:04 -080017#include <linux/netfilter_ipv4.h>
18#include <linux/netfilter/xt_realm.h>
19#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
22MODULE_LICENSE("GPL");
Harald Welte2e4e6a12006-01-12 13:30:04 -080023MODULE_DESCRIPTION("X_tables realm match");
24MODULE_ALIAS("ipt_realm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26static int
27match(const struct sk_buff *skb,
28 const struct net_device *in,
29 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -080030 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 const void *matchinfo,
32 int offset,
Harald Welte2e4e6a12006-01-12 13:30:04 -080033 unsigned int protoff,
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int *hotdrop)
35{
Harald Welte2e4e6a12006-01-12 13:30:04 -080036 const struct xt_realm_info *info = matchinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 struct dst_entry *dst = skb->dst;
38
39 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
40}
41
Harald Welte2e4e6a12006-01-12 13:30:04 -080042static struct xt_match realm_match = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .name = "realm",
Patrick McHardy5d04bff2006-03-20 18:01:58 -080044 .match = match,
45 .matchsize = sizeof(struct xt_realm_info),
46 .hooks = (1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
47 (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN),
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080048 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 .me = THIS_MODULE
50};
51
Andrew Morton65b4b4e2006-03-28 16:37:06 -080052static int __init xt_realm_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080054 return xt_register_match(&realm_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Andrew Morton65b4b4e2006-03-28 16:37:06 -080057static void __exit xt_realm_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080059 xt_unregister_match(&realm_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Andrew Morton65b4b4e2006-03-28 16:37:06 -080062module_init(xt_realm_init);
63module_exit(xt_realm_fini);