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