Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 1 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 2 | * Summary: ebt_vlan - IEEE 802.1Q extension module for userspace |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 3 | * |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 4 | * Description: 802.1Q Virtual LAN match support module for ebtables project. |
| 5 | * Enables to match 802.1Q: |
| 6 | * 1) VLAN-tagged frames by VLAN numeric identifier (12 - bits field) |
| 7 | * 2) Priority-tagged frames by user_priority (3 bits field) |
| 8 | * 3) Encapsulated Frame by ethernet protocol type/length |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 9 | * |
| 10 | * Authors: |
| 11 | * Bart De Schuymer <bart.de.schuymer@pandora.be> |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 12 | * Nick Fedchik <nick@fedchik.org.ua> |
| 13 | * June, 2002 |
| 14 | * |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 15 | * License: GNU GPL |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License as published by |
| 19 | * the Free Software Foundation; either version 2 of the License, or |
| 20 | * (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 30 | * |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 31 | */ |
Bart De Schuymer | e4b1fdf | 2002-06-16 09:20:22 +0000 | [diff] [blame] | 32 | |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
Bart De Schuymer | e4b1fdf | 2002-06-16 09:20:22 +0000 | [diff] [blame] | 35 | #include <string.h> |
Bart De Schuymer | e4b1fdf | 2002-06-16 09:20:22 +0000 | [diff] [blame] | 36 | #include <getopt.h> |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 37 | #include <ctype.h> |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 38 | #include "../include/ebtables_u.h" |
Bart De Schuymer | c1939b1 | 2002-11-20 19:41:54 +0000 | [diff] [blame] | 39 | #include "../include/ethernetdb.h" |
Bart De Schuymer | e4b1fdf | 2002-06-16 09:20:22 +0000 | [diff] [blame] | 40 | #include <linux/netfilter_bridge/ebt_vlan.h> |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 41 | #include <linux/if_ether.h> |
| 42 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 43 | |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 44 | #define GET_BITMASK(_MASK_) vlaninfo->bitmask & _MASK_ |
| 45 | #define SET_BITMASK(_MASK_) vlaninfo->bitmask |= _MASK_ |
Bart De Schuymer | 2ab59ea | 2002-07-24 10:14:02 +0000 | [diff] [blame] | 46 | #define INV_FLAG(_inv_flag_) (vlaninfo->invflags & _inv_flag_) ? "! " : "" |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 47 | #define CHECK_IF_MISSING_VALUE if (optind > argc) print_error ("Missing %s value", opts[c].name); |
| 48 | #define CHECK_INV_FLAG(_INDEX_) if (check_inverse (optarg)) vlaninfo->invflags |= _INDEX_; |
| 49 | #define CHECK_RANGE(_RANGE_) if (_RANGE_) print_error ("Invalid %s range", opts[c].name); |
| 50 | |
| 51 | #define NAME_VLAN_ID "id" |
| 52 | #define NAME_VLAN_PRIO "prio" |
| 53 | #define NAME_VLAN_ENCAP "encap" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 54 | |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 55 | #define VLAN_ID 0 |
| 56 | #define VLAN_PRIO 1 |
| 57 | #define VLAN_ENCAP 2 |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 58 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 59 | static struct option opts[] = { |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 60 | {EBT_VLAN_MATCH "-" NAME_VLAN_ID, required_argument, NULL, |
| 61 | VLAN_ID}, |
| 62 | {EBT_VLAN_MATCH "-" NAME_VLAN_PRIO, required_argument, NULL, |
| 63 | VLAN_PRIO}, |
| 64 | {EBT_VLAN_MATCH "-" NAME_VLAN_ENCAP, required_argument, NULL, |
| 65 | VLAN_ENCAP}, |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 66 | {NULL} |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 69 | /* |
| 70 | * option inverse flags definition |
| 71 | */ |
| 72 | #define OPT_VLAN_ID 0x01 |
| 73 | #define OPT_VLAN_PRIO 0x02 |
| 74 | #define OPT_VLAN_ENCAP 0x04 |
| 75 | #define OPT_VLAN_FLAGS (OPT_VLAN_ID | OPT_VLAN_PRIO | OPT_VLAN_ENCAP) |
| 76 | |
| 77 | struct ethertypeent *ethent; |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 78 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 79 | /* |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 80 | * Print out local help by "ebtables -h <match name>" |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 81 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 82 | |
| 83 | static void print_help() |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 84 | { |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 85 | #define HELP_TITLE "802.1Q VLAN extension" |
| 86 | |
| 87 | printf(HELP_TITLE " options:\n"); |
| 88 | printf("--" EBT_VLAN_MATCH "-" NAME_VLAN_ID " %s" NAME_VLAN_ID |
| 89 | " : VLAN-tagged frame identifier, 0,1-4096 (integer), default 1\n", |
| 90 | OPT_VLAN_FLAGS & OPT_VLAN_ID ? "[!] " : ""); |
| 91 | printf("--" EBT_VLAN_MATCH "-" NAME_VLAN_PRIO " %s" NAME_VLAN_PRIO |
| 92 | " : Priority-tagged frame user_priority, 0-7 (integer), default 0\n", |
| 93 | OPT_VLAN_FLAGS & OPT_VLAN_PRIO ? "[!] " : ""); |
| 94 | printf("--" EBT_VLAN_MATCH "-" NAME_VLAN_ENCAP " %s" |
| 95 | NAME_VLAN_ENCAP |
| 96 | " : Encapsulated frame type (hexadecimal), default IP (0800)\n", |
| 97 | OPT_VLAN_FLAGS & OPT_VLAN_ENCAP ? "[!] " : ""); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Initialization function |
| 102 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 103 | static void init(struct ebt_entry_match *match) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 104 | { |
| 105 | struct ebt_vlan_info *vlaninfo = |
| 106 | (struct ebt_vlan_info *) match->data; |
| 107 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 108 | * Set initial values |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 109 | */ |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 110 | vlaninfo->id = 1; /* Default VID for VLAN-tagged 802.1Q frames */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 111 | vlaninfo->prio = 0; |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 112 | vlaninfo->encap = 0; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 113 | vlaninfo->invflags = 0; |
| 114 | vlaninfo->bitmask = 0; |
| 115 | } |
| 116 | |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 117 | |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 118 | /* |
| 119 | * Parse passed arguments values (ranges, flags, etc...) |
| 120 | * int c - parameter number from static struct option opts[] |
| 121 | * int argc - total amout of arguments (std argc value) |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 122 | * int argv - arguments (std argv value) |
| 123 | * const struct ebt_u_entry *entry - default ebtables entry set |
| 124 | * unsigned int *flags - |
| 125 | * struct ebt_entry_match **match - |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 126 | */ |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 127 | static int |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 128 | parse(int c, |
| 129 | char **argv, |
| 130 | int argc, |
| 131 | const struct ebt_u_entry *entry, |
| 132 | unsigned int *flags, struct ebt_entry_match **match) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 133 | { |
| 134 | struct ebt_vlan_info *vlaninfo = |
| 135 | (struct ebt_vlan_info *) (*match)->data; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 136 | char *end; |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 137 | struct ebt_vlan_info local; |
| 138 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 139 | switch (c) { |
| 140 | case VLAN_ID: |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 141 | check_option(flags, OPT_VLAN_ID); |
| 142 | CHECK_INV_FLAG(EBT_VLAN_ID); |
| 143 | CHECK_IF_MISSING_VALUE; |
| 144 | (unsigned short) local.id = |
| 145 | strtoul(argv[optind - 1], &end, 10); |
| 146 | CHECK_RANGE(local.id > 4094 || *end != '\0'); |
| 147 | vlaninfo->id = local.id; |
| 148 | SET_BITMASK(EBT_VLAN_ID); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 149 | break; |
| 150 | |
| 151 | case VLAN_PRIO: |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 152 | check_option(flags, OPT_VLAN_PRIO); |
| 153 | CHECK_INV_FLAG(EBT_VLAN_PRIO); |
| 154 | CHECK_IF_MISSING_VALUE; |
| 155 | (unsigned char) local.prio = |
| 156 | strtoul(argv[optind - 1], &end, 10); |
| 157 | CHECK_RANGE(local.prio >= 8 || *end != '\0'); |
| 158 | vlaninfo->prio = local.prio; |
| 159 | SET_BITMASK(EBT_VLAN_PRIO); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 160 | break; |
| 161 | |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 162 | case VLAN_ENCAP: |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 163 | check_option(flags, OPT_VLAN_ENCAP); |
| 164 | CHECK_INV_FLAG(EBT_VLAN_ENCAP); |
| 165 | CHECK_IF_MISSING_VALUE; |
| 166 | (unsigned short) local.encap = |
| 167 | strtoul(argv[optind - 1], &end, 16); |
Bart De Schuymer | c1939b1 | 2002-11-20 19:41:54 +0000 | [diff] [blame] | 168 | if (*end != '\0') { |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 169 | ethent = getethertypebyname(argv[optind - 1]); |
| 170 | if (ethent == NULL) |
| 171 | print_error("Unknown %s encap", |
| 172 | opts[c].name); |
| 173 | local.encap = ethent->e_ethertype; |
Bart De Schuymer | c1939b1 | 2002-11-20 19:41:54 +0000 | [diff] [blame] | 174 | } |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 175 | CHECK_RANGE(local.encap < ETH_ZLEN); |
| 176 | vlaninfo->encap = htons(local.encap); |
| 177 | SET_BITMASK(EBT_VLAN_ENCAP); |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 178 | break; |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 179 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 180 | default: |
| 181 | return 0; |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 182 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 183 | } |
| 184 | return 1; |
| 185 | } |
| 186 | |
| 187 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 188 | * Final check - logical conditions |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 189 | */ |
| 190 | static void |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 191 | final_check(const struct ebt_u_entry *entry, |
| 192 | const struct ebt_entry_match *match, |
| 193 | const char *name, unsigned int hookmask, unsigned int time) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 194 | { |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 195 | |
| 196 | struct ebt_vlan_info *vlaninfo = |
| 197 | (struct ebt_vlan_info *) match->data; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 198 | /* |
Bart De Schuymer | 4057319 | 2002-08-29 16:48:36 +0000 | [diff] [blame] | 199 | * Specified proto isn't 802.1Q? |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 200 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 201 | if (entry->ethproto != ETH_P_8021Q || entry->invflags & EBT_IPROTO) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 202 | print_error |
Bart De Schuymer | 2ab59ea | 2002-07-24 10:14:02 +0000 | [diff] [blame] | 203 | ("For use 802.1Q extension the protocol must be specified as 802_1Q"); |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 204 | /* |
fnm3 | cd33827 | 2002-11-09 13:27:31 +0000 | [diff] [blame] | 205 | * Check if specified vlan-encap=0x8100 (802.1Q Frame) |
| 206 | * when vlan-encap specified. |
| 207 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 208 | if (GET_BITMASK(EBT_VLAN_ENCAP)) { |
| 209 | if (vlaninfo->encap == htons(0x8100)) |
fnm3 | cd33827 | 2002-11-09 13:27:31 +0000 | [diff] [blame] | 210 | print_error |
| 211 | ("Encapsulated frame type can not be 802.1Q (0x8100)"); |
| 212 | } |
| 213 | |
| 214 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 215 | * Check if specified vlan-id=0 (priority-tagged frame condition) |
| 216 | * when vlan-prio was specified. |
| 217 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 218 | if (GET_BITMASK(EBT_VLAN_PRIO)) { |
| 219 | if (vlaninfo->id && GET_BITMASK(EBT_VLAN_ID)) |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 220 | print_error |
Bart De Schuymer | 2ab59ea | 2002-07-24 10:14:02 +0000 | [diff] [blame] | 221 | ("For use user_priority the specified vlan-id must be 0"); |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 222 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Print line when listing rules by ebtables -L |
| 227 | */ |
| 228 | static void |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 229 | print(const struct ebt_u_entry *entry, const struct ebt_entry_match *match) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 230 | { |
| 231 | struct ebt_vlan_info *vlaninfo = |
| 232 | (struct ebt_vlan_info *) match->data; |
| 233 | |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 234 | char ethertype_name[21]; |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 235 | /* |
| 236 | * Print VLAN ID if they are specified |
| 237 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 238 | if (GET_BITMASK(EBT_VLAN_ID)) { |
| 239 | printf("--%s %s%d ", |
| 240 | opts[VLAN_ID].name, |
| 241 | INV_FLAG(EBT_VLAN_ID), vlaninfo->id); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 242 | } |
| 243 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 244 | * Print user priority if they are specified |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 245 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 246 | if (GET_BITMASK(EBT_VLAN_PRIO)) { |
| 247 | printf("--%s %s%d ", |
| 248 | opts[VLAN_PRIO].name, |
| 249 | INV_FLAG(EBT_VLAN_PRIO), vlaninfo->prio); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 250 | } |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 251 | /* |
fnm3 | 91fc2be | 2002-06-25 16:37:52 +0000 | [diff] [blame] | 252 | * Print encapsulated frame type if they are specified |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 253 | */ |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 254 | if (GET_BITMASK(EBT_VLAN_ENCAP)) { |
| 255 | printf("--%s %s", |
| 256 | opts[VLAN_ENCAP].name, INV_FLAG(EBT_VLAN_ENCAP)); |
| 257 | bzero(ethertype_name, 21); |
| 258 | ethent = getethertypebynumber(ntohs(vlaninfo->encap)); |
| 259 | if (ethent != NULL) { |
| 260 | printf("%s ", ethent->e_name); |
| 261 | } else { |
| 262 | printf("%4.4X ", ntohs(vlaninfo->encap)); |
| 263 | } |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 264 | } |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | |
| 268 | static int |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 269 | compare(const struct ebt_entry_match *vlan1, |
| 270 | const struct ebt_entry_match *vlan2) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 271 | { |
| 272 | struct ebt_vlan_info *vlaninfo1 = |
| 273 | (struct ebt_vlan_info *) vlan1->data; |
| 274 | struct ebt_vlan_info *vlaninfo2 = |
| 275 | (struct ebt_vlan_info *) vlan2->data; |
| 276 | /* |
| 277 | * Compare argc |
| 278 | */ |
| 279 | if (vlaninfo1->bitmask != vlaninfo2->bitmask) |
| 280 | return 0; |
| 281 | /* |
| 282 | * Compare inv flags |
| 283 | */ |
| 284 | if (vlaninfo1->invflags != vlaninfo2->invflags) |
| 285 | return 0; |
| 286 | /* |
| 287 | * Compare VLAN ID if they are present |
| 288 | */ |
| 289 | if (vlaninfo1->bitmask & EBT_VLAN_ID) { |
| 290 | if (vlaninfo1->id != vlaninfo2->id) |
| 291 | return 0; |
| 292 | }; |
| 293 | /* |
| 294 | * Compare VLAN Prio if they are present |
| 295 | */ |
| 296 | if (vlaninfo1->bitmask & EBT_VLAN_PRIO) { |
| 297 | if (vlaninfo1->prio != vlaninfo2->prio) |
| 298 | return 0; |
| 299 | }; |
fnm3 | f794d5a | 2002-06-14 17:28:13 +0000 | [diff] [blame] | 300 | /* |
| 301 | * Compare VLAN Encap if they are present |
| 302 | */ |
| 303 | if (vlaninfo1->bitmask & EBT_VLAN_ENCAP) { |
| 304 | if (vlaninfo1->encap != vlaninfo2->encap) |
| 305 | return 0; |
| 306 | }; |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 307 | |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | static struct ebt_u_match vlan_match = { |
| 312 | EBT_VLAN_MATCH, |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 313 | sizeof(struct ebt_vlan_info), |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 314 | print_help, |
| 315 | init, |
| 316 | parse, |
| 317 | final_check, |
| 318 | print, |
| 319 | compare, |
Bart De Schuymer | 9cfd654 | 2002-08-13 16:08:08 +0000 | [diff] [blame] | 320 | opts |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 323 | static void _init(void) __attribute__ ((constructor)); |
| 324 | static void _init(void) |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 325 | { |
fnm3 | 8e011e6 | 2002-11-21 10:32:04 +0000 | [diff] [blame^] | 326 | register_match(&vlan_match); |
Bart De Schuymer | 1abc55d | 2002-06-01 19:23:47 +0000 | [diff] [blame] | 327 | } |