Merge tag 'armsoc-soc' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[linux-2.6-block.git] / net / bridge / netfilter / ebt_802_3.c
CommitLineData
1da177e4
LT
1/*
2 * 802_3
3 *
4 * Author:
5 * Chris Vitale csv@bluetail.com
6 *
7 * May 2003
9d6f229f 8 *
1da177e4 9 */
18219d3f
JE
10#include <linux/module.h>
11#include <linux/netfilter/x_tables.h>
1da177e4
LT
12#include <linux/netfilter_bridge/ebtables.h>
13#include <linux/netfilter_bridge/ebt_802_3.h>
1da177e4 14
2d06d4a5 15static bool
62fc8051 16ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
1da177e4 17{
f7108a20 18 const struct ebt_802_3_info *info = par->matchinfo;
abfdf1c4 19 const struct ebt_802_3_hdr *hdr = ebt_802_3_hdr(skb);
47c183fa 20 __be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
1da177e4
LT
21
22 if (info->bitmask & EBT_802_3_SAP) {
c37a2dfa 23 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.ssap))
8cc784ee 24 return false;
c37a2dfa 25 if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.dsap))
8cc784ee 26 return false;
1da177e4
LT
27 }
28
29 if (info->bitmask & EBT_802_3_TYPE) {
30 if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
8cc784ee 31 return false;
c37a2dfa 32 if (NF_INVF(info, EBT_802_3_TYPE, info->type != type))
8cc784ee 33 return false;
1da177e4
LT
34 }
35
8cc784ee 36 return true;
1da177e4
LT
37}
38
b0f38452 39static int ebt_802_3_mt_check(const struct xt_mtchk_param *par)
1da177e4 40{
9b4fce7a 41 const struct ebt_802_3_info *info = par->matchinfo;
1da177e4 42
1da177e4 43 if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
bd414ee6 44 return -EINVAL;
1da177e4 45
bd414ee6 46 return 0;
1da177e4
LT
47}
48
043ef46c
JE
49static struct xt_match ebt_802_3_mt_reg __read_mostly = {
50 .name = "802_3",
001a18d3
JE
51 .revision = 0,
52 .family = NFPROTO_BRIDGE,
2d06d4a5
JE
53 .match = ebt_802_3_mt,
54 .checkentry = ebt_802_3_mt_check,
fc0e3df4 55 .matchsize = sizeof(struct ebt_802_3_info),
1da177e4
LT
56 .me = THIS_MODULE,
57};
58
65b4b4e8 59static int __init ebt_802_3_init(void)
1da177e4 60{
043ef46c 61 return xt_register_match(&ebt_802_3_mt_reg);
1da177e4
LT
62}
63
65b4b4e8 64static void __exit ebt_802_3_fini(void)
1da177e4 65{
043ef46c 66 xt_unregister_match(&ebt_802_3_mt_reg);
1da177e4
LT
67}
68
65b4b4e8
AM
69module_init(ebt_802_3_init);
70module_exit(ebt_802_3_fini);
f776c4cd 71MODULE_DESCRIPTION("Ebtables: DSAP/SSAP field and SNAP type matching");
1da177e4 72MODULE_LICENSE("GPL");