xt_cpu.c 1.5 KB

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