Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 2 | #include <xtables.h> |
| 3 | #include <linux/netfilter/xt_cpu.h> |
| 4 | |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 5 | enum { |
| 6 | O_CPU = 0, |
| 7 | }; |
| 8 | |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 9 | static void cpu_help(void) |
| 10 | { |
| 11 | printf( |
| 12 | "cpu match options:\n" |
| 13 | "[!] --cpu number Match CPU number\n"); |
| 14 | } |
| 15 | |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 16 | static 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 Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 21 | }; |
| 22 | |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 23 | static void cpu_parse(struct xt_option_call *cb) |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 24 | { |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 25 | struct xt_cpu_info *cpuinfo = cb->data; |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 26 | |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 27 | xtables_option_parse(cb); |
| 28 | if (cb->invert) |
| 29 | cpuinfo->invert = true; |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static void |
| 33 | cpu_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 Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 37 | printf(" cpu %s%u", info->invert ? "! ":"", info->cpu); |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static 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 Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 44 | printf("%s --cpu %u", info->invert ? " !" : "", info->cpu); |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static 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 Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 54 | .print = cpu_print, |
| 55 | .save = cpu_save, |
Jan Engelhardt | 9311292 | 2011-02-18 03:41:18 +0100 | [diff] [blame] | 56 | .x6_parse = cpu_parse, |
| 57 | .x6_options = cpu_opts, |
Eric Dumazet | 2d59208 | 2010-07-23 16:15:14 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | void _init(void) |
| 61 | { |
| 62 | xtables_register_match(&cpu_match); |
| 63 | } |