xt_mark.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * xt_mark - Netfilter module to match NFMARK value
  3. *
  4. * (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
  5. * Copyright © CC Computer Consultants GmbH, 2007 - 2008
  6. * Jan Engelhardt <jengelh@medozas.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/netfilter/xt_mark.h>
  15. #include <linux/netfilter/x_tables.h>
  16. MODULE_LICENSE("GPL");
  17. MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
  18. MODULE_DESCRIPTION("Xtables: packet mark operations");
  19. MODULE_ALIAS("ipt_mark");
  20. MODULE_ALIAS("ip6t_mark");
  21. MODULE_ALIAS("ipt_MARK");
  22. MODULE_ALIAS("ip6t_MARK");
  23. MODULE_ALIAS("arpt_MARK");
  24. static unsigned int
  25. mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
  26. {
  27. const struct xt_mark_tginfo2 *info = par->targinfo;
  28. skb->mark = (skb->mark & ~info->mask) ^ info->mark;
  29. return XT_CONTINUE;
  30. }
  31. static bool
  32. mark_mt(const struct sk_buff *skb, struct xt_action_param *par)
  33. {
  34. const struct xt_mark_mtinfo1 *info = par->matchinfo;
  35. return ((skb->mark & info->mask) == info->mark) ^ info->invert;
  36. }
  37. static struct xt_target mark_tg_reg __read_mostly = {
  38. .name = "MARK",
  39. .revision = 2,
  40. .family = NFPROTO_UNSPEC,
  41. .target = mark_tg,
  42. .targetsize = sizeof(struct xt_mark_tginfo2),
  43. .me = THIS_MODULE,
  44. };
  45. static struct xt_match mark_mt_reg __read_mostly = {
  46. .name = "mark",
  47. .revision = 1,
  48. .family = NFPROTO_UNSPEC,
  49. .match = mark_mt,
  50. .matchsize = sizeof(struct xt_mark_mtinfo1),
  51. .me = THIS_MODULE,
  52. };
  53. static int __init mark_mt_init(void)
  54. {
  55. int ret;
  56. ret = xt_register_target(&mark_tg_reg);
  57. if (ret < 0)
  58. return ret;
  59. ret = xt_register_match(&mark_mt_reg);
  60. if (ret < 0) {
  61. xt_unregister_target(&mark_tg_reg);
  62. return ret;
  63. }
  64. return 0;
  65. }
  66. static void __exit mark_mt_exit(void)
  67. {
  68. xt_unregister_match(&mark_mt_reg);
  69. xt_unregister_target(&mark_tg_reg);
  70. }
  71. module_init(mark_mt_init);
  72. module_exit(mark_mt_exit);