blob: 63289b40c8ddfe97b1d8cc0f760990f6e5880bbb [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
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080025realm_mt(const struct sk_buff *skb, const struct net_device *in,
26 const struct net_device *out, const struct xt_match *match,
27 const void *matchinfo, int offset, unsigned int protoff,
28 bool *hotdrop)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Harald Welte2e4e6a12006-01-12 13:30:04 -080030 const struct xt_realm_info *info = matchinfo;
Jan Engelhardta47362a2007-07-07 22:16:55 -070031 const struct dst_entry *dst = skb->dst;
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
34}
35
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080036static struct xt_match realm_mt_reg __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .name = "realm",
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080038 .match = realm_mt,
Patrick McHardy5d04bff2006-03-20 18:01:58 -080039 .matchsize = sizeof(struct xt_realm_info),
Patrick McHardy6e23ae22007-11-19 18:53:30 -080040 .hooks = (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_FORWARD) |
41 (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN),
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080042 .family = AF_INET,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .me = THIS_MODULE
44};
45
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080046static int __init realm_mt_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080048 return xt_register_match(&realm_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080051static void __exit realm_mt_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080053 xt_unregister_match(&realm_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080056module_init(realm_mt_init);
57module_exit(realm_mt_exit);