Home | History | Annotate | Download | only in extensions
      1 #include <stdio.h>
      2 #include <xtables.h>
      3 #include <linux/netfilter/xt_cpu.h>
      4 
      5 enum {
      6 	O_CPU = 0,
      7 };
      8 
      9 static void cpu_help(void)
     10 {
     11 	printf(
     12 "cpu match options:\n"
     13 "[!] --cpu number   Match CPU number\n");
     14 }
     15 
     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,
     21 };
     22 
     23 static void cpu_parse(struct xt_option_call *cb)
     24 {
     25 	struct xt_cpu_info *cpuinfo = cb->data;
     26 
     27 	xtables_option_parse(cb);
     28 	if (cb->invert)
     29 		cpuinfo->invert = true;
     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 
     37 	printf(" cpu %s%u", info->invert ? "! ":"", info->cpu);
     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 
     44 	printf("%s --cpu %u", info->invert ? " !" : "", info->cpu);
     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,
     54 	.print		= cpu_print,
     55 	.save		= cpu_save,
     56 	.x6_parse	= cpu_parse,
     57 	.x6_options	= cpu_opts,
     58 };
     59 
     60 void _init(void)
     61 {
     62 	xtables_register_match(&cpu_match);
     63 }
     64