Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* Kernel module to match running CPU */
0003 
0004 /*
0005  * Might be used to distribute connections on several daemons, if
0006  * RPS (Remote Packet Steering) is enabled or NIC is multiqueue capable,
0007  * each RX queue IRQ affined to one CPU (1:1 mapping)
0008  */
0009 
0010 /* (C) 2010 Eric Dumazet
0011  */
0012 
0013 #include <linux/module.h>
0014 #include <linux/skbuff.h>
0015 #include <linux/netfilter/xt_cpu.h>
0016 #include <linux/netfilter/x_tables.h>
0017 
0018 MODULE_LICENSE("GPL");
0019 MODULE_AUTHOR("Eric Dumazet <eric.dumazet@gmail.com>");
0020 MODULE_DESCRIPTION("Xtables: CPU match");
0021 MODULE_ALIAS("ipt_cpu");
0022 MODULE_ALIAS("ip6t_cpu");
0023 
0024 static int cpu_mt_check(const struct xt_mtchk_param *par)
0025 {
0026     const struct xt_cpu_info *info = par->matchinfo;
0027 
0028     if (info->invert & ~1)
0029         return -EINVAL;
0030     return 0;
0031 }
0032 
0033 static bool cpu_mt(const struct sk_buff *skb, struct xt_action_param *par)
0034 {
0035     const struct xt_cpu_info *info = par->matchinfo;
0036 
0037     return (info->cpu == smp_processor_id()) ^ info->invert;
0038 }
0039 
0040 static struct xt_match cpu_mt_reg __read_mostly = {
0041     .name       = "cpu",
0042     .revision   = 0,
0043     .family     = NFPROTO_UNSPEC,
0044     .checkentry = cpu_mt_check,
0045     .match      = cpu_mt,
0046     .matchsize  = sizeof(struct xt_cpu_info),
0047     .me         = THIS_MODULE,
0048 };
0049 
0050 static int __init cpu_mt_init(void)
0051 {
0052     return xt_register_match(&cpu_mt_reg);
0053 }
0054 
0055 static void __exit cpu_mt_exit(void)
0056 {
0057     xt_unregister_match(&cpu_mt_reg);
0058 }
0059 
0060 module_init(cpu_mt_init);
0061 module_exit(cpu_mt_exit);