xt_realm.c 1.3 KB

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