xt_mark.c 2.0 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. static unsigned int
  24. mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
  25. {
  26. const struct xt_mark_tginfo2 *info = par->targinfo;
  27. skb->mark = (skb->mark & ~info->mask) ^ info->mark;
  28. return XT_CONTINUE;
  29. }
  30. static bool
  31. mark_mt(const struct sk_buff *skb, struct xt_action_param *par)
  32. {
  33. const struct xt_mark_mtinfo1 *info = par->matchinfo;
  34. return ((skb->mark & info->mask) == info->mark) ^ info->invert;
  35. }
  36. static struct xt_target mark_tg_reg __read_mostly = {
  37. .name = "MARK",
  38. .revision = 2,
  39. .family = NFPROTO_UNSPEC,
  40. .target = mark_tg,
  41. .targetsize = sizeof(struct xt_mark_tginfo2),
  42. .me = THIS_MODULE,
  43. };
  44. static struct xt_match mark_mt_reg __read_mostly = {
  45. .name = "mark",
  46. .revision = 1,
  47. .family = NFPROTO_UNSPEC,
  48. .match = mark_mt,
  49. .matchsize = sizeof(struct xt_mark_mtinfo1),
  50. .me = THIS_MODULE,
  51. };
  52. static int __init mark_mt_init(void)
  53. {
  54. int ret;
  55. ret = xt_register_target(&mark_tg_reg);
  56. if (ret < 0)
  57. return ret;
  58. ret = xt_register_match(&mark_mt_reg);
  59. if (ret < 0) {
  60. xt_unregister_target(&mark_tg_reg);
  61. return ret;
  62. }
  63. return 0;
  64. }
  65. static void __exit mark_mt_exit(void)
  66. {
  67. xt_unregister_match(&mark_mt_reg);
  68. xt_unregister_target(&mark_tg_reg);
  69. }
  70. module_init(mark_mt_init);
  71. module_exit(mark_mt_exit);