blob: 404a6a66a5a0c9d7d52ae2de69f658c6a42afe03 [file] [log] [blame]
Eric Dumazet2d592082010-07-23 16:15:14 +02001#include <stdio.h>
Eric Dumazet2d592082010-07-23 16:15:14 +02002#include <xtables.h>
3#include <linux/netfilter/xt_cpu.h>
4
Jan Engelhardt93112922011-02-18 03:41:18 +01005enum {
6 O_CPU = 0,
7};
8
Eric Dumazet2d592082010-07-23 16:15:14 +02009static void cpu_help(void)
10{
11 printf(
12"cpu match options:\n"
13"[!] --cpu number Match CPU number\n");
14}
15
Jan Engelhardt93112922011-02-18 03:41:18 +010016static const struct xt_option_entry cpu_opts[] = {
17 {.name = "cpu", .id = O_CPU, .type = XTTYPE_UINT32,
18 .flags = XTOPT_INVERT | XTOPT_MAND | XTOPT_PUT,
19 XTOPT_POINTER(struct xt_cpu_info, cpu)},
20 XTOPT_TABLEEND,
Eric Dumazet2d592082010-07-23 16:15:14 +020021};
22
Jan Engelhardt93112922011-02-18 03:41:18 +010023static void cpu_parse(struct xt_option_call *cb)
Eric Dumazet2d592082010-07-23 16:15:14 +020024{
Jan Engelhardt93112922011-02-18 03:41:18 +010025 struct xt_cpu_info *cpuinfo = cb->data;
Eric Dumazet2d592082010-07-23 16:15:14 +020026
Jan Engelhardt93112922011-02-18 03:41:18 +010027 xtables_option_parse(cb);
28 if (cb->invert)
29 cpuinfo->invert = true;
Eric Dumazet2d592082010-07-23 16:15:14 +020030}
31
32static void
33cpu_print(const void *ip, const struct xt_entry_match *match, int numeric)
34{
35 const struct xt_cpu_info *info = (void *)match->data;
36
Jan Engelhardt73866352010-12-18 02:04:59 +010037 printf(" cpu %s%u", info->invert ? "! ":"", info->cpu);
Eric Dumazet2d592082010-07-23 16:15:14 +020038}
39
40static void cpu_save(const void *ip, const struct xt_entry_match *match)
41{
42 const struct xt_cpu_info *info = (void *)match->data;
43
Jan Engelhardt73866352010-12-18 02:04:59 +010044 printf("%s --cpu %u", info->invert ? " !" : "", info->cpu);
Eric Dumazet2d592082010-07-23 16:15:14 +020045}
46
47static struct xtables_match cpu_match = {
48 .family = NFPROTO_UNSPEC,
49 .name = "cpu",
50 .version = XTABLES_VERSION,
51 .size = XT_ALIGN(sizeof(struct xt_cpu_info)),
52 .userspacesize = XT_ALIGN(sizeof(struct xt_cpu_info)),
53 .help = cpu_help,
Eric Dumazet2d592082010-07-23 16:15:14 +020054 .print = cpu_print,
55 .save = cpu_save,
Jan Engelhardt93112922011-02-18 03:41:18 +010056 .x6_parse = cpu_parse,
57 .x6_options = cpu_opts,
Eric Dumazet2d592082010-07-23 16:15:14 +020058};
59
60void _init(void)
61{
62 xtables_register_match(&cpu_match);
63}