资讯详情

iptables匹配cpu

cpu匹配帮助信息如下,匹配处理报纸CPU核。

# iptables -m cpu -h cpu match options: [!] --cpu number   Match CPU number 

处理器0和1处理如下配置TCP目的端口为80的报纸分别重定向到8080和8081。

# iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 0 -j REDIRECT --to-port 8080  # iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 1 -j REDIRECT --to-port 8081 #  # iptables -t nat -L -v -n Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)  pkts bytes target     prot opt in     out     source               destination              0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 cpu 0 redir ports 8080     0     0 REDIRECT   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 cpu 1 redir ports 8081 

CPU匹配

函数xt_register_matche注册匹配结构cpu_mt_reg。

static struct xt_match cpu_mt_reg __read_mostly = {     .name       = "cpu",     .revision   = 0,     .family     = NFPROTO_UNSPEC,     .checkentry = cpu_mt_check,     .match      = cpu_mt,     .matchsize  = sizeof(struct xt_cpu_info),     .me         = THIS_MODULE, }; static int __init cpu_mt_init(void) {     return xt_register_match(&cpu_mt_reg); 

配置检查函数,判断反向操作invert合法值为0和1。

static int cpu_mt_check(const struct xt_mtchk_param *par) {     const struct xt_cpu_info *info = par->matchinfo;      if (info->invert & ~1)         return -EINVAL;     return 0; 

匹配处理函数cou_mt以下是当前处理器的获取ID,与配置的cpu相比较。

static bool cpu_mt(const struct sk_buff *skb, struct xt_action_param *par) {     const struct xt_cpu_info *info = par->matchinfo;      return (info->cpu == smp_processor_id()) ^ info->invert; 

内核版本 5.10

标签: 压差传感器dpt0100u1

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台