1 // SPDX-License-Identifier: GPL-2.0-only
6 * Chris Vitale csv@bluetail.com
11 #include <linux/module.h>
12 #include <linux/netfilter/x_tables.h>
13 #include <linux/netfilter_bridge/ebtables.h>
14 #include <linux/skbuff.h>
15 #include <uapi/linux/netfilter_bridge/ebt_802_3.h>
17 static struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
19 return (struct ebt_802_3_hdr *)skb_mac_header(skb);
23 ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
25 const struct ebt_802_3_info *info = par->matchinfo;
26 const struct ebt_802_3_hdr *hdr = ebt_802_3_hdr(skb);
27 __be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
29 if (info->bitmask & EBT_802_3_SAP) {
30 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.ssap))
32 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.dsap))
36 if (info->bitmask & EBT_802_3_TYPE) {
37 if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
39 if (NF_INVF(info, EBT_802_3_TYPE, info->type != type))
46 static int ebt_802_3_mt_check(const struct xt_mtchk_param *par)
48 const struct ebt_802_3_info *info = par->matchinfo;
50 if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
56 static struct xt_match ebt_802_3_mt_reg __read_mostly = {
59 .family = NFPROTO_BRIDGE,
60 .match = ebt_802_3_mt,
61 .checkentry = ebt_802_3_mt_check,
62 .matchsize = sizeof(struct ebt_802_3_info),
66 static int __init ebt_802_3_init(void)
68 return xt_register_match(&ebt_802_3_mt_reg);
71 static void __exit ebt_802_3_fini(void)
73 xt_unregister_match(&ebt_802_3_mt_reg);
76 module_init(ebt_802_3_init);
77 module_exit(ebt_802_3_fini);
78 MODULE_DESCRIPTION("Ebtables: DSAP/SSAP field and SNAP type matching");
79 MODULE_LICENSE("GPL");