0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/skbuff.h>
0009 #include <linux/netdevice.h>
0010 #include <net/route.h>
0011
0012 #include <linux/netfilter_ipv4.h>
0013 #include <linux/netfilter/xt_realm.h>
0014 #include <linux/netfilter/x_tables.h>
0015
0016 MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
0017 MODULE_LICENSE("GPL");
0018 MODULE_DESCRIPTION("Xtables: Routing realm match");
0019 MODULE_ALIAS("ipt_realm");
0020
0021 static bool
0022 realm_mt(const struct sk_buff *skb, struct xt_action_param *par)
0023 {
0024 const struct xt_realm_info *info = par->matchinfo;
0025 const struct dst_entry *dst = skb_dst(skb);
0026
0027 return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
0028 }
0029
0030 static struct xt_match realm_mt_reg __read_mostly = {
0031 .name = "realm",
0032 .match = realm_mt,
0033 .matchsize = sizeof(struct xt_realm_info),
0034 .hooks = (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_FORWARD) |
0035 (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN),
0036 .family = NFPROTO_UNSPEC,
0037 .me = THIS_MODULE
0038 };
0039
0040 static int __init realm_mt_init(void)
0041 {
0042 return xt_register_match(&realm_mt_reg);
0043 }
0044
0045 static void __exit realm_mt_exit(void)
0046 {
0047 xt_unregister_match(&realm_mt_reg);
0048 }
0049
0050 module_init(realm_mt_init);
0051 module_exit(realm_mt_exit);