Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / net / bridge / netfilter / ebt_802_3.c
blob98534025360f8a4d8c45766921a2791fc80d2218
1 /*
2 * 802_3
4 * Author:
5 * Chris Vitale csv@bluetail.com
7 * May 2003
9 */
11 #include <linux/netfilter_bridge/ebtables.h>
12 #include <linux/netfilter_bridge/ebt_802_3.h>
13 #include <linux/module.h>
15 static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
16 const struct net_device *out, const void *data, unsigned int datalen)
18 const struct ebt_802_3_info *info = data;
19 const struct ebt_802_3_hdr *hdr = ebt_802_3_hdr(skb);
20 __be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
22 if (info->bitmask & EBT_802_3_SAP) {
23 if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
24 return EBT_NOMATCH;
25 if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
26 return EBT_NOMATCH;
29 if (info->bitmask & EBT_802_3_TYPE) {
30 if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
31 return EBT_NOMATCH;
32 if (FWINV(info->type != type, EBT_802_3_TYPE))
33 return EBT_NOMATCH;
36 return EBT_MATCH;
39 static struct ebt_match filter_802_3;
40 static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
41 const struct ebt_entry *e, void *data, unsigned int datalen)
43 const struct ebt_802_3_info *info = data;
45 if (datalen < sizeof(struct ebt_802_3_info))
46 return -EINVAL;
47 if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
48 return -EINVAL;
50 return 0;
53 static struct ebt_match filter_802_3 __read_mostly = {
54 .name = EBT_802_3_MATCH,
55 .match = ebt_filter_802_3,
56 .check = ebt_802_3_check,
57 .me = THIS_MODULE,
60 static int __init ebt_802_3_init(void)
62 return ebt_register_match(&filter_802_3);
65 static void __exit ebt_802_3_fini(void)
67 ebt_unregister_match(&filter_802_3);
70 module_init(ebt_802_3_init);
71 module_exit(ebt_802_3_fini);
72 MODULE_DESCRIPTION("Ebtables: DSAP/SSAP field and SNAP type matching");
73 MODULE_LICENSE("GPL");