blob: 67419287bc7e143003164d2850378066cac6cd41 [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");
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080021MODULE_DESCRIPTION("Xtables: Routing realm match");
Harald Welte2e4e6a12006-01-12 13:30:04 -080022MODULE_ALIAS("ipt_realm");
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -070024static bool
Jan Engelhardtf7108a22008-10-08 11:35:18 +020025realm_mt(const struct sk_buff *skb, const struct xt_match_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Jan Engelhardtf7108a22008-10-08 11:35:18 +020027 const struct xt_realm_info *info = par->matchinfo;
Jan Engelhardta47362a2007-07-07 22:16:55 -070028 const struct dst_entry *dst = skb->dst;
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
31}
32
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080033static struct xt_match realm_mt_reg __read_mostly = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 .name = "realm",
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080035 .match = realm_mt,
Patrick McHardy5d04bff2006-03-20 18:01:58 -080036 .matchsize = sizeof(struct xt_realm_info),
Patrick McHardy6e23ae22007-11-19 18:53:30 -080037 .hooks = (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_FORWARD) |
38 (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN),
Jan Engelhardtab4f21e2008-10-08 11:35:20 +020039 .family = NFPROTO_UNSPEC,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .me = THIS_MODULE
41};
42
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080043static int __init realm_mt_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080045 return xt_register_match(&realm_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080048static void __exit realm_mt_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080050 xt_unregister_match(&realm_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080053module_init(realm_mt_init);
54module_exit(realm_mt_exit);