Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / ebtables / extensions / ebt_mark_m.c
blob2a259b04368d0788361df002775b16353aa3e08a
1 /* ebt_mark_m
3 * Authors:
4 * Bart De Schuymer <bdschuym@pandora.be>
6 * July, 2002
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <getopt.h>
13 #include "../include/ebtables_u.h"
14 #include <linux/netfilter_bridge/ebt_mark_m.h>
16 #define MARK '1'
18 static struct option opts[] =
20 { "mark", required_argument, 0, MARK },
21 { 0 }
24 static void print_help()
26 printf(
27 "mark option:\n"
28 "--mark [!] [value][/mask]: Match nfmask value (see man page)\n");
31 static void init(struct ebt_entry_match *match)
33 struct ebt_mark_m_info *markinfo = (struct ebt_mark_m_info *)match->data;
35 markinfo->mark = 0;
36 markinfo->mask = 0;
37 markinfo->invert = 0;
38 markinfo->bitmask = 0;
41 #define OPT_MARK 0x01
42 static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
43 unsigned int *flags, struct ebt_entry_match **match)
45 struct ebt_mark_m_info *markinfo = (struct ebt_mark_m_info *)
46 (*match)->data;
47 char *end;
49 switch (c) {
50 case MARK:
51 ebt_check_option2(flags, MARK);
52 if (ebt_check_inverse2(optarg))
53 markinfo->invert = 1;
54 markinfo->mark = strtoul(optarg, &end, 0);
55 markinfo->bitmask = EBT_MARK_AND;
56 if (*end == '/') {
57 if (end == optarg)
58 markinfo->bitmask = EBT_MARK_OR;
59 markinfo->mask = strtoul(end+1, &end, 0);
60 } else
61 markinfo->mask = 0xffffffff;
62 if ( *end != '\0' || end == optarg)
63 ebt_print_error2("Bad mark value '%s'", optarg);
64 break;
65 default:
66 return 0;
68 return 1;
71 static void final_check(const struct ebt_u_entry *entry,
72 const struct ebt_entry_match *match, const char *name,
73 unsigned int hookmask, unsigned int time)
77 static void print(const struct ebt_u_entry *entry,
78 const struct ebt_entry_match *match)
80 struct ebt_mark_m_info *markinfo =
81 (struct ebt_mark_m_info *)match->data;
83 printf("--mark ");
84 if (markinfo->invert)
85 printf("! ");
86 if (markinfo->bitmask == EBT_MARK_OR)
87 printf("/0x%lx ", markinfo->mask);
88 else if(markinfo->mask != 0xffffffff)
89 printf("0x%lx/0x%lx ", markinfo->mark, markinfo->mask);
90 else
91 printf("0x%lx ", markinfo->mark);
94 static int compare(const struct ebt_entry_match *m1,
95 const struct ebt_entry_match *m2)
97 struct ebt_mark_m_info *markinfo1 = (struct ebt_mark_m_info *)m1->data;
98 struct ebt_mark_m_info *markinfo2 = (struct ebt_mark_m_info *)m2->data;
100 if (markinfo1->invert != markinfo2->invert)
101 return 0;
102 if (markinfo1->mark != markinfo2->mark)
103 return 0;
104 if (markinfo1->mask != markinfo2->mask)
105 return 0;
106 if (markinfo1->bitmask != markinfo2->bitmask)
107 return 0;
108 return 1;
111 static struct ebt_u_match mark_match =
113 .name = "mark_m",
114 .size = sizeof(struct ebt_mark_m_info),
115 .help = print_help,
116 .init = init,
117 .parse = parse,
118 .final_check = final_check,
119 .print = print,
120 .compare = compare,
121 .extra_ops = opts,
124 void _init(void)
126 ebt_register_match(&mark_match);