ebt_mark_m.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * ebt_mark_m
  3. *
  4. * Authors:
  5. * Bart De Schuymer <bdschuym@pandora.be>
  6. *
  7. * July, 2002
  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_mark_m.h>
  14. static bool
  15. ebt_mark_mt(const struct sk_buff *skb, struct xt_action_param *par)
  16. {
  17. const struct ebt_mark_m_info *info = par->matchinfo;
  18. if (info->bitmask & EBT_MARK_OR)
  19. return !!(skb->mark & info->mask) ^ info->invert;
  20. return ((skb->mark & info->mask) == info->mark) ^ info->invert;
  21. }
  22. static int ebt_mark_mt_check(const struct xt_mtchk_param *par)
  23. {
  24. const struct ebt_mark_m_info *info = par->matchinfo;
  25. if (info->bitmask & ~EBT_MARK_MASK)
  26. return -EINVAL;
  27. if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
  28. return -EINVAL;
  29. if (!info->bitmask)
  30. return -EINVAL;
  31. return 0;
  32. }
  33. #ifdef CONFIG_COMPAT
  34. struct compat_ebt_mark_m_info {
  35. compat_ulong_t mark, mask;
  36. uint8_t invert, bitmask;
  37. };
  38. static void mark_mt_compat_from_user(void *dst, const void *src)
  39. {
  40. const struct compat_ebt_mark_m_info *user = src;
  41. struct ebt_mark_m_info *kern = dst;
  42. kern->mark = user->mark;
  43. kern->mask = user->mask;
  44. kern->invert = user->invert;
  45. kern->bitmask = user->bitmask;
  46. }
  47. static int mark_mt_compat_to_user(void __user *dst, const void *src)
  48. {
  49. struct compat_ebt_mark_m_info __user *user = dst;
  50. const struct ebt_mark_m_info *kern = src;
  51. if (put_user(kern->mark, &user->mark) ||
  52. put_user(kern->mask, &user->mask) ||
  53. put_user(kern->invert, &user->invert) ||
  54. put_user(kern->bitmask, &user->bitmask))
  55. return -EFAULT;
  56. return 0;
  57. }
  58. #endif
  59. static struct xt_match ebt_mark_mt_reg __read_mostly = {
  60. .name = "mark_m",
  61. .revision = 0,
  62. .family = NFPROTO_BRIDGE,
  63. .match = ebt_mark_mt,
  64. .checkentry = ebt_mark_mt_check,
  65. .matchsize = sizeof(struct ebt_mark_m_info),
  66. #ifdef CONFIG_COMPAT
  67. .compatsize = sizeof(struct compat_ebt_mark_m_info),
  68. .compat_from_user = mark_mt_compat_from_user,
  69. .compat_to_user = mark_mt_compat_to_user,
  70. #endif
  71. .me = THIS_MODULE,
  72. };
  73. static int __init ebt_mark_m_init(void)
  74. {
  75. return xt_register_match(&ebt_mark_mt_reg);
  76. }
  77. static void __exit ebt_mark_m_fini(void)
  78. {
  79. xt_unregister_match(&ebt_mark_mt_reg);
  80. }
  81. module_init(ebt_mark_m_init);
  82. module_exit(ebt_mark_m_fini);
  83. MODULE_DESCRIPTION("Ebtables: Packet mark match");
  84. MODULE_LICENSE("GPL");