xt_cpu.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Kernel module to match running CPU */
  3. /*
  4. * Might be used to distribute connections on several daemons, if
  5. * RPS (Remote Packet Steering) is enabled or NIC is multiqueue capable,
  6. * each RX queue IRQ affined to one CPU (1:1 mapping)
  7. */
  8. /* (C) 2010 Eric Dumazet
  9. */
  10. #include <linux/module.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/netfilter/xt_cpu.h>
  13. #include <linux/netfilter/x_tables.h>
  14. MODULE_LICENSE("GPL");
  15. MODULE_AUTHOR("Eric Dumazet <eric.dumazet@gmail.com>");
  16. MODULE_DESCRIPTION("Xtables: CPU match");
  17. MODULE_ALIAS("ipt_cpu");
  18. MODULE_ALIAS("ip6t_cpu");
  19. static int cpu_mt_check(const struct xt_mtchk_param *par)
  20. {
  21. const struct xt_cpu_info *info = par->matchinfo;
  22. if (info->invert & ~1)
  23. return -EINVAL;
  24. return 0;
  25. }
  26. static bool cpu_mt(const struct sk_buff *skb, struct xt_action_param *par)
  27. {
  28. const struct xt_cpu_info *info = par->matchinfo;
  29. return (info->cpu == smp_processor_id()) ^ info->invert;
  30. }
  31. static struct xt_match cpu_mt_reg __read_mostly = {
  32. .name = "cpu",
  33. .revision = 0,
  34. .family = NFPROTO_UNSPEC,
  35. .checkentry = cpu_mt_check,
  36. .match = cpu_mt,
  37. .matchsize = sizeof(struct xt_cpu_info),
  38. .me = THIS_MODULE,
  39. };
  40. static int __init cpu_mt_init(void)
  41. {
  42. return xt_register_match(&cpu_mt_reg);
  43. }
  44. static void __exit cpu_mt_exit(void)
  45. {
  46. xt_unregister_match(&cpu_mt_reg);
  47. }
  48. module_init(cpu_mt_init);
  49. module_exit(cpu_mt_exit);