xt_realm.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* IP tables module for matching the routing realm
  2. *
  3. * (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. #include <linux/module.h>
  10. #include <linux/skbuff.h>
  11. #include <linux/netdevice.h>
  12. #include <net/route.h>
  13. #include <linux/netfilter_ipv4.h>
  14. #include <linux/netfilter/xt_realm.h>
  15. #include <linux/netfilter/x_tables.h>
  16. MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
  17. MODULE_LICENSE("GPL");
  18. MODULE_DESCRIPTION("Xtables: Routing realm match");
  19. MODULE_ALIAS("ipt_realm");
  20. static bool
  21. realm_mt(const struct sk_buff *skb, struct xt_action_param *par)
  22. {
  23. const struct xt_realm_info *info = par->matchinfo;
  24. const struct dst_entry *dst = skb_dst(skb);
  25. return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
  26. }
  27. static struct xt_match realm_mt_reg __read_mostly = {
  28. .name = "realm",
  29. .match = realm_mt,
  30. .matchsize = sizeof(struct xt_realm_info),
  31. .hooks = (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_FORWARD) |
  32. (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN),
  33. .family = NFPROTO_UNSPEC,
  34. .me = THIS_MODULE
  35. };
  36. static int __init realm_mt_init(void)
  37. {
  38. return xt_register_match(&realm_mt_reg);
  39. }
  40. static void __exit realm_mt_exit(void)
  41. {
  42. xt_unregister_match(&realm_mt_reg);
  43. }
  44. module_init(realm_mt_init);
  45. module_exit(realm_mt_exit);