1 /* 802_3
2 *
3 * Author:
4 * Chris Vitale <csv@bluetail.com>
5 *
6 * May 2003
7 *
8 * Adapted by Arturo Borrero Gonzalez <arturo@debian.org>
9 * to use libxtables for ebtables-compat
10 */
11
12 #include <stdbool.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <xtables.h>
17 #include <linux/netfilter_bridge/ebt_802_3.h>
18
19 static const struct xt_option_entry br802_3_opts[] =
20 {
21 { .name = "802_3-sap", .id = EBT_802_3_SAP,
22 .type = XTTYPE_UINT8, .base = 16,
23 .flags = XTOPT_INVERT | XTOPT_PUT,
24 XTOPT_POINTER(struct ebt_802_3_info, sap) },
25 { .name = "802_3-type", .id = EBT_802_3_TYPE,
26 .type = XTTYPE_UINT16, .base = 16,
27 .flags = XTOPT_INVERT | XTOPT_PUT | XTOPT_NBO,
28 XTOPT_POINTER(struct ebt_802_3_info, type) },
29 XTOPT_TABLEEND,
30 };
31
br802_3_print_help(void)32 static void br802_3_print_help(void)
33 {
34 printf(
35 "802_3 options:\n"
36 "[!] --802_3-sap protocol : 802.3 DSAP/SSAP- 1 byte value (hex)\n"
37 " DSAP and SSAP are always the same. One SAP applies to both fields\n"
38 "[!] --802_3-type protocol : 802.3 SNAP Type- 2 byte value (hex)\n"
39 " Type implies SAP value 0xaa\n");
40 }
41
br802_3_parse(struct xt_option_call * cb)42 static void br802_3_parse(struct xt_option_call *cb)
43 {
44 struct ebt_802_3_info *info = cb->data;
45
46 xtables_option_parse(cb);
47 info->bitmask |= cb->entry->id;
48 if (cb->invert)
49 info->invflags |= cb->entry->id;
50 }
51
br802_3_print(const void * ip,const struct xt_entry_match * match,int numeric)52 static void br802_3_print(const void *ip, const struct xt_entry_match *match,
53 int numeric)
54 {
55 struct ebt_802_3_info *info = (struct ebt_802_3_info *)match->data;
56
57 if (info->bitmask & EBT_802_3_SAP) {
58 if (info->invflags & EBT_802_3_SAP)
59 printf("! ");
60 printf("--802_3-sap 0x%.2x ", info->sap);
61 }
62 if (info->bitmask & EBT_802_3_TYPE) {
63 if (info->invflags & EBT_802_3_TYPE)
64 printf("! ");
65 printf("--802_3-type 0x%.4x ", ntohs(info->type));
66 }
67 }
68
69 static struct xtables_match br802_3_match =
70 {
71 .name = "802_3",
72 .revision = 0,
73 .version = XTABLES_VERSION,
74 .family = NFPROTO_BRIDGE,
75 .size = XT_ALIGN(sizeof(struct ebt_802_3_info)),
76 .userspacesize = XT_ALIGN(sizeof(struct ebt_802_3_info)),
77 .help = br802_3_print_help,
78 .x6_parse = br802_3_parse,
79 .print = br802_3_print,
80 .x6_options = br802_3_opts,
81 };
82
_init(void)83 void _init(void)
84 {
85 xtables_register_match(&br802_3_match);
86 }
87