ebt_802_3.c 1.7 KB

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