4 * Chris Vitale <csv@bluetail.com>
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
},
27 static void print_help()
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
;
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
;
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
;
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
;
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 "
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
)
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
)
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
)
118 if (info1
->invflags
!= info2
->invflags
)
120 if (info1
->bitmask
& EBT_802_3_SAP
) {
121 if (info1
->sap
!= info2
->sap
)
124 if (info1
->bitmask
& EBT_802_3_TYPE
) {
125 if (info1
->type
!= info2
->type
)
131 static struct ebt_u_match _802_3_match
=
134 .size
= sizeof(struct ebt_802_3_info
),
138 .final_check
= final_check
,
146 ebt_register_match(&_802_3_match
);