xt_realm.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* IP tables module for matching the routing realm
  2. *
  3. * $Id: xt_realm.c,v 1.1.1.1 2007/06/12 07:27:14 eyryu 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. #include <linux/module.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/netdevice.h>
  14. #include <net/route.h>
  15. #include <linux/netfilter_ipv4.h>
  16. #include <linux/netfilter/xt_realm.h>
  17. #include <linux/netfilter/x_tables.h>
  18. MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
  19. MODULE_LICENSE("GPL");
  20. MODULE_DESCRIPTION("X_tables realm match");
  21. MODULE_ALIAS("ipt_realm");
  22. static int
  23. match(const struct sk_buff *skb,
  24. const struct net_device *in,
  25. const struct net_device *out,
  26. const struct xt_match *match,
  27. const void *matchinfo,
  28. int offset,
  29. unsigned int protoff,
  30. int *hotdrop)
  31. {
  32. const struct xt_realm_info *info = matchinfo;
  33. struct dst_entry *dst = skb->dst;
  34. return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
  35. }
  36. static struct xt_match realm_match = {
  37. .name = "realm",
  38. .match = match,
  39. .matchsize = sizeof(struct xt_realm_info),
  40. .hooks = (1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
  41. (1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_LOCAL_IN),
  42. .family = AF_INET,
  43. .me = THIS_MODULE
  44. };
  45. static int __init xt_realm_init(void)
  46. {
  47. return xt_register_match(&realm_match);
  48. }
  49. static void __exit xt_realm_fini(void)
  50. {
  51. xt_unregister_match(&realm_match);
  52. }
  53. module_init(xt_realm_init);
  54. module_exit(xt_realm_fini);