ebt_pkttype.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ebt_pkttype
  4. *
  5. * Authors:
  6. * Bart De Schuymer <bdschuym@pandora.be>
  7. *
  8. * April, 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/netfilter_bridge/ebt_pkttype.h>
  15. static bool
  16. ebt_pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par)
  17. {
  18. const struct ebt_pkttype_info *info = par->matchinfo;
  19. return (skb->pkt_type == info->pkt_type) ^ info->invert;
  20. }
  21. static int ebt_pkttype_mt_check(const struct xt_mtchk_param *par)
  22. {
  23. const struct ebt_pkttype_info *info = par->matchinfo;
  24. if (info->invert != 0 && info->invert != 1)
  25. return -EINVAL;
  26. /* Allow any pkt_type value */
  27. return 0;
  28. }
  29. static struct xt_match ebt_pkttype_mt_reg __read_mostly = {
  30. .name = "pkttype",
  31. .revision = 0,
  32. .family = NFPROTO_BRIDGE,
  33. .match = ebt_pkttype_mt,
  34. .checkentry = ebt_pkttype_mt_check,
  35. .matchsize = sizeof(struct ebt_pkttype_info),
  36. .me = THIS_MODULE,
  37. };
  38. static int __init ebt_pkttype_init(void)
  39. {
  40. return xt_register_match(&ebt_pkttype_mt_reg);
  41. }
  42. static void __exit ebt_pkttype_fini(void)
  43. {
  44. xt_unregister_match(&ebt_pkttype_mt_reg);
  45. }
  46. module_init(ebt_pkttype_init);
  47. module_exit(ebt_pkttype_fini);
  48. MODULE_DESCRIPTION("Ebtables: Link layer packet type match");
  49. MODULE_LICENSE("GPL");