aboutsummaryrefslogtreecommitdiffstats
path: root/tools/remus/imqebt/extensions/ebt_imq.c
blob: e1069fdb9a5347ec132d53c6001327711ad0c345 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include "../include/ebtables_u.h"
#include <linux/netfilter_bridge/ebt_imq.h>

#define IMQ_TODEV '1'

static struct option opts[] =
{
       { "todev"           , required_argument, 0, IMQ_TODEV },
       { 0 }
};

static void help(void)
{
  printf(
    "IMQ options:\n"
    "  --todev <N>         enqueue to imq<N>, defaults to 0\n");
}

static void init(struct ebt_entry_target *target)
{
  struct ebt_imq_info *imqinfo = (struct ebt_imq_info *)target->data;

  imqinfo->todev = 0;
}

static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
   unsigned int *flags, struct ebt_entry_target **target)
{
  struct ebt_imq_info *imqinfo = (struct ebt_imq_info *)(*target)->data;

  switch(c) {
  case IMQ_TODEV:
    imqinfo->todev = atoi(optarg);
  }

  return 1;
}

static void final_check(const struct ebt_u_entry *entry,
   const struct ebt_entry_target *target, const char *name,
   unsigned int hookmask, unsigned int time)
{
}

static void print(const struct ebt_u_entry *entry,
   const struct ebt_entry_target *target)
{
  struct ebt_imq_info *imqinfo = (struct ebt_imq_info *)target->data;

  printf("--todev %d", imqinfo->todev);
}

static int compare(const struct ebt_entry_target *t1,
   const struct ebt_entry_target *t2)
{
  struct ebt_imq_info *imqinfo1 = (struct ebt_imq_info *)t1->data;
  struct ebt_imq_info *imqinfo2 = (struct ebt_imq_info *)t2->data;

  if (imqinfo1->todev != imqinfo2->todev)
    return 0;

  return 1;
}

static struct ebt_u_target imq_target =
{
       .name           = "imq",
       .size           = sizeof(struct ebt_imq_info),
       .help           = help,
       .init           = init,
       .parse          = parse,
       .final_check    = final_check,
       .print          = print,
       .compare        = compare,
       .extra_ops      = opts,
};

void _init(void)
{
       ebt_register_target(&imq_target);
}