blob: 318e2b62386114b58a4947c91544106d6b7f3abe [file] [log] [blame]
Bart De Schuymera501b782002-07-20 16:15:39 +00001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <sys/socket.h>
5#include <netinet/in.h>
6#include <getopt.h>
7#include "../include/ebtables_u.h"
8#include <linux/netfilter_bridge/ebt_mark_t.h>
9
10extern char *standard_targets[NUM_STANDARD_TARGETS];
11
12#define MARK_TARGET '1'
13#define MARK_SETMARK '2'
14static struct option opts[] =
15{
16 { "mark-target" , required_argument, 0, MARK_TARGET },
17 { "set-mark" , required_argument, 0, MARK_SETMARK },
18 { 0 }
19};
20
21static void print_help()
22{
23 printf(
24 "mark target options:\n"
25 " --set-mark value : Set nfmark value\n"
26 " --mark-target target : ACCEPT, DROP or CONTINUE\n");
27}
28
29static void init(struct ebt_entry_target *target)
30{
31 struct ebt_mark_t_info *markinfo =
32 (struct ebt_mark_t_info *)target->data;
33
34 markinfo->target = EBT_ACCEPT;
35 markinfo->mark = 0;
36 return;
37}
38
39#define OPT_MARK_TARGET 0x01
40#define OPT_MARK_SETMARK 0x02
41static int parse(int c, char **argv, int argc,
42 const struct ebt_u_entry *entry, unsigned int *flags,
43 struct ebt_entry_target **target)
44{
45 int i;
46 struct ebt_mark_t_info *markinfo =
47 (struct ebt_mark_t_info *)(*target)->data;
48 char *end;
49
50 switch (c) {
51 case MARK_TARGET:
52 check_option(flags, OPT_MARK_TARGET);
53 for (i = 0; i < NUM_STANDARD_TARGETS; i++)
54 if (!strcmp(optarg, standard_targets[i])) {
55 markinfo->target = -i - 1;
56 break;
57 }
58 if (i == NUM_STANDARD_TARGETS)
59 print_error("Illegal --mark-target target");
60 break;
61 case MARK_SETMARK:
62 check_option(flags, OPT_MARK_SETMARK);
63 markinfo->mark = strtoul(optarg, &end, 0);
64 if (*end != '\0' || end == optarg)
65 print_error("Bad MARK value `%s'", optarg);
66 break;
67 default:
68 return 0;
69 }
70 return 1;
71}
72
73static void final_check(const struct ebt_u_entry *entry,
74 const struct ebt_entry_target *target, const char *name,
75 unsigned int hook_mask, unsigned int time)
76{
77}
78
79static void print(const struct ebt_u_entry *entry,
80 const struct ebt_entry_target *target)
81{
82 struct ebt_mark_t_info *markinfo =
83 (struct ebt_mark_t_info *)target->data;
84
85 printf("--set-mark 0x%lx", markinfo->mark);
86 if (markinfo->target == EBT_ACCEPT)
87 return;
88 printf(" --mark-target %s",
89 standard_targets[-markinfo->target - 1]);
90}
91
92static int compare(const struct ebt_entry_target *t1,
93 const struct ebt_entry_target *t2)
94{
95 struct ebt_mark_t_info *markinfo1 =
96 (struct ebt_mark_t_info *)t1->data;
97 struct ebt_mark_t_info *markinfo2 =
98 (struct ebt_mark_t_info *)t2->data;
99
100 return (markinfo1->target == markinfo2->target &&
101 markinfo1->mark == markinfo2->mark);
102}
103
104static struct ebt_u_target mark_target =
105{
106 EBT_MARK_TARGET,
107 sizeof(struct ebt_mark_t_info),
108 print_help,
109 init,
110 parse,
111 final_check,
112 print,
113 compare,
114 opts,
115};
116
117static void _init(void) __attribute__ ((constructor));
118static void _init(void)
119{
120 register_target(&mark_target);
121}