ebt_802_3.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * 802_3
  4. *
  5. * Author:
  6. * Chris Vitale csv@bluetail.com
  7. *
  8. * May 2003
  9. *
  10. */
  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>
  16. static struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
  17. {
  18. return (struct ebt_802_3_hdr *)skb_mac_header(skb);
  19. }
  20. static bool
  21. ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
  22. {
  23. const struct ebt_802_3_info *info = par->matchinfo;
  24. const struct ebt_802_3_hdr *hdr = ebt_802_3_hdr(skb);
  25. __be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
  26. if (info->bitmask & EBT_802_3_SAP) {
  27. if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.ssap))
  28. return false;
  29. if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.dsap))
  30. return false;
  31. }
  32. if (info->bitmask & EBT_802_3_TYPE) {
  33. if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
  34. return false;
  35. if (NF_INVF(info, EBT_802_3_TYPE, info->type != type))
  36. return false;
  37. }
  38. return true;
  39. }
  40. static int ebt_802_3_mt_check(const struct xt_mtchk_param *par)
  41. {
  42. const struct ebt_802_3_info *info = par->matchinfo;
  43. if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
  44. return -EINVAL;
  45. return 0;
  46. }
  47. static struct xt_match ebt_802_3_mt_reg __read_mostly = {
  48. .name = "802_3",
  49. .revision = 0,
  50. .family = NFPROTO_BRIDGE,
  51. .match = ebt_802_3_mt,
  52. .checkentry = ebt_802_3_mt_check,
  53. .matchsize = sizeof(struct ebt_802_3_info),
  54. .me = THIS_MODULE,
  55. };
  56. static int __init ebt_802_3_init(void)
  57. {
  58. return xt_register_match(&ebt_802_3_mt_reg);
  59. }
  60. static void __exit ebt_802_3_fini(void)
  61. {
  62. xt_unregister_match(&ebt_802_3_mt_reg);
  63. }
  64. module_init(ebt_802_3_init);
  65. module_exit(ebt_802_3_fini);
  66. MODULE_DESCRIPTION("Ebtables: DSAP/SSAP field and SNAP type matching");
  67. MODULE_LICENSE("GPL");