blob: 5fc4affd9fdb4dd28d868c9ba83d7dc18ac32678 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * 802_3
3 *
4 * Author:
5 * Chris Vitale csv@bluetail.com
6 *
7 * May 2003
YOSHIFUJI Hideaki9d6f2292007-02-09 23:24:35 +09008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Jan Engelhardt18219d32008-10-08 11:35:13 +020010#include <linux/module.h>
11#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/netfilter_bridge/ebtables.h>
13#include <linux/netfilter_bridge/ebt_802_3.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020015static bool
Jan Engelhardt62fc8052009-07-07 20:42:08 +020016ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017{
Jan Engelhardtf7108a22008-10-08 11:35:18 +020018 const struct ebt_802_3_info *info = par->matchinfo;
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080019 const struct ebt_802_3_hdr *hdr = ebt_802_3_hdr(skb);
Al Viro47c183fa2006-11-14 21:11:51 -080020 __be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22 if (info->bitmask & EBT_802_3_SAP) {
Joe Perchesc37a2df2016-06-24 13:25:22 -070023 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.ssap))
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020024 return false;
Joe Perchesc37a2df2016-06-24 13:25:22 -070025 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.dsap))
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020026 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 }
28
29 if (info->bitmask & EBT_802_3_TYPE) {
30 if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020031 return false;
Joe Perchesc37a2df2016-06-24 13:25:22 -070032 if (NF_INVF(info, EBT_802_3_TYPE, info->type != type))
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020033 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 }
35
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020036 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Jan Engelhardtb0f38452010-03-19 17:16:42 +010039static int ebt_802_3_mt_check(const struct xt_mtchk_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020041 const struct ebt_802_3_info *info = par->matchinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
Jan Engelhardtbd414ee2010-03-23 16:35:56 +010044 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Jan Engelhardtbd414ee2010-03-23 16:35:56 +010046 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Jan Engelhardt043ef462008-10-08 11:35:15 +020049static struct xt_match ebt_802_3_mt_reg __read_mostly = {
50 .name = "802_3",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020051 .revision = 0,
52 .family = NFPROTO_BRIDGE,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020053 .match = ebt_802_3_mt,
54 .checkentry = ebt_802_3_mt_check,
Florian Westphalfc0e3df2010-02-15 18:16:26 +010055 .matchsize = sizeof(struct ebt_802_3_info),
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .me = THIS_MODULE,
57};
58
Andrew Morton65b4b4e2006-03-28 16:37:06 -080059static int __init ebt_802_3_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Jan Engelhardt043ef462008-10-08 11:35:15 +020061 return xt_register_match(&ebt_802_3_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Andrew Morton65b4b4e2006-03-28 16:37:06 -080064static void __exit ebt_802_3_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Jan Engelhardt043ef462008-10-08 11:35:15 +020066 xt_unregister_match(&ebt_802_3_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
Andrew Morton65b4b4e2006-03-28 16:37:06 -080069module_init(ebt_802_3_init);
70module_exit(ebt_802_3_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080071MODULE_DESCRIPTION("Ebtables: DSAP/SSAP field and SNAP type matching");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_LICENSE("GPL");