Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / ebtables / extensions / ebt_802_3.c
blobdd22eb2605334824f5d7b2d7120fd30211182c59
1 /* 802_3
3 * Author:
4 * Chris Vitale <csv@bluetail.com>
6 * May 2003
7 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <getopt.h>
13 #include "../include/ebtables_u.h"
14 #include "../include/ethernetdb.h"
15 #include <linux/netfilter_bridge/ebt_802_3.h>
17 #define _802_3_SAP '1'
18 #define _802_3_TYPE '2'
20 static struct option opts[] =
22 { "802_3-sap" , required_argument, 0, _802_3_SAP },
23 { "802_3-type" , required_argument, 0, _802_3_TYPE },
24 { 0 }
27 static void print_help()
29 printf(
30 "802_3 options:\n"
31 "--802_3-sap [!] protocol : 802.3 DSAP/SSAP- 1 byte value (hex)\n"
32 " DSAP and SSAP are always the same. One SAP applies to both fields\n"
33 "--802_3-type [!] protocol : 802.3 SNAP Type- 2 byte value (hex)\n"
34 " Type implies SAP value 0xaa\n");
37 static void init(struct ebt_entry_match *match)
39 struct ebt_802_3_info *info = (struct ebt_802_3_info *)match->data;
41 info->invflags = 0;
42 info->bitmask = 0;
45 static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
46 unsigned int *flags, struct ebt_entry_match **match)
48 struct ebt_802_3_info *info = (struct ebt_802_3_info *) (*match)->data;
49 unsigned int i;
50 char *end;
52 switch (c) {
53 case _802_3_SAP:
54 ebt_check_option2(flags, _802_3_SAP);
55 if (ebt_check_inverse2(optarg))
56 info->invflags |= EBT_802_3_SAP;
57 i = strtoul(optarg, &end, 16);
58 if (i > 255 || *end != '\0')
59 ebt_print_error2("Problem with specified "
60 "sap hex value, %x",i);
61 info->sap = i; /* one byte, so no byte order worries */
62 info->bitmask |= EBT_802_3_SAP;
63 break;
64 case _802_3_TYPE:
65 ebt_check_option2(flags, _802_3_TYPE);
66 if (ebt_check_inverse2(optarg))
67 info->invflags |= EBT_802_3_TYPE;
68 i = strtoul(optarg, &end, 16);
69 if (i > 65535 || *end != '\0') {
70 ebt_print_error2("Problem with the specified "
71 "type hex value, %x",i);
73 info->type = htons(i);
74 info->bitmask |= EBT_802_3_TYPE;
75 break;
76 default:
77 return 0;
79 return 1;
82 static void final_check(const struct ebt_u_entry *entry,
83 const struct ebt_entry_match *match, const char *name,
84 unsigned int hookmask, unsigned int time)
86 if (!(entry->bitmask & EBT_802_3))
87 ebt_print_error("For 802.3 DSAP/SSAP filtering the protocol "
88 "must be LENGTH");
91 static void print(const struct ebt_u_entry *entry,
92 const struct ebt_entry_match *match)
94 struct ebt_802_3_info *info = (struct ebt_802_3_info *)match->data;
96 if (info->bitmask & EBT_802_3_SAP) {
97 printf("--802_3-sap ");
98 if (info->invflags & EBT_802_3_SAP)
99 printf("! ");
100 printf("0x%.2x ", info->sap);
102 if (info->bitmask & EBT_802_3_TYPE) {
103 printf("--802_3-type ");
104 if (info->invflags & EBT_802_3_TYPE)
105 printf("! ");
106 printf("0x%.4x ", ntohs(info->type));
110 static int compare(const struct ebt_entry_match *m1,
111 const struct ebt_entry_match *m2)
113 struct ebt_802_3_info *info1 = (struct ebt_802_3_info *)m1->data;
114 struct ebt_802_3_info *info2 = (struct ebt_802_3_info *)m2->data;
116 if (info1->bitmask != info2->bitmask)
117 return 0;
118 if (info1->invflags != info2->invflags)
119 return 0;
120 if (info1->bitmask & EBT_802_3_SAP) {
121 if (info1->sap != info2->sap)
122 return 0;
124 if (info1->bitmask & EBT_802_3_TYPE) {
125 if (info1->type != info2->type)
126 return 0;
128 return 1;
131 static struct ebt_u_match _802_3_match =
133 .name = "802_3",
134 .size = sizeof(struct ebt_802_3_info),
135 .help = print_help,
136 .init = init,
137 .parse = parse,
138 .final_check = final_check,
139 .print = print,
140 .compare = compare,
141 .extra_ops = opts,
144 void _init(void)
146 ebt_register_match(&_802_3_match);