www.usr.com/support/gpl/USR9107_release.1.4.tar.gz
[bcm963xx.git] / userapps / opensource / ebtables / extensions / ebt_standard.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <getopt.h>
4 #include "../include/ebtables_u.h"
5
6 static struct option opts[] =
7 {
8         {0}
9 };
10
11 static void print_help()
12 {
13         printf("Standard targets: DROP, ACCEPT, RETURN or CONTINUE;\n"
14                "The target can also be a user defined chain.\n");
15 }
16
17 static void init(struct ebt_entry_target *t)
18 {
19         ((struct ebt_standard_target *)t)->verdict = EBT_CONTINUE;
20 }
21
22 static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
23    unsigned int *flags, struct ebt_entry_target **target)
24 {
25         return 0;
26 }
27
28 static void final_check(const struct ebt_u_entry *entry,
29    const struct ebt_entry_target *target, const char *name,
30    unsigned int hookmask, unsigned int time)
31 {
32 }
33
34 struct ebt_u_entries *nr_to_chain(int nr);
35
36 static void print(const struct ebt_u_entry *entry,
37    const struct ebt_entry_target *target)
38 {
39         int verdict = ((struct ebt_standard_target *)target)->verdict;
40
41         if (verdict >= 0) {
42                 struct ebt_u_entries *entries;
43
44                 entries = nr_to_chain(verdict + NF_BR_NUMHOOKS);
45                 printf("%s", entries->name);
46                 return;
47         }
48         if (verdict == EBT_CONTINUE)
49                 printf("CONTINUE ");
50         else if (verdict == EBT_ACCEPT)
51                 printf("ACCEPT ");
52         else if (verdict == EBT_DROP)
53                 printf("DROP ");
54         else if (verdict == EBT_RETURN)
55                 printf("RETURN ");
56         else
57                 print_bug("Bad standard target");
58 }
59
60 static int compare(const struct ebt_entry_target *t1,
61    const struct ebt_entry_target *t2)
62 {
63         return ((struct ebt_standard_target *)t1)->verdict ==
64            ((struct ebt_standard_target *)t2)->verdict;
65 }
66
67 static struct ebt_u_target standard =
68 {
69         .name           = EBT_STANDARD_TARGET,
70         .size           = sizeof(struct ebt_standard_target) -
71                           sizeof(struct ebt_entry_target),
72         .help           = print_help,
73         .init           = init,
74         .parse          = parse,
75         .final_check    = final_check,
76         .print          = print,
77         .compare        = compare,
78         .extra_ops      = opts,
79 };
80
81 static void _init(void) __attribute__ ((constructor));
82 static void _init(void)
83 {
84         register_target(&standard);
85 }