ignore_message.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2010 Martin Willi
  3. * Copyright (C) 2010 revosec AG
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include "hook.h"
  16. typedef struct private_ignore_message_t private_ignore_message_t;
  17. /**
  18. * Private data of an ignore_message_t object.
  19. */
  20. struct private_ignore_message_t {
  21. /**
  22. * Implements the hook_t interface.
  23. */
  24. hook_t hook;
  25. /**
  26. * Drop incoming or outgoing?
  27. */
  28. bool in;
  29. /**
  30. * Drop requests or responses?
  31. */
  32. bool req;
  33. /**
  34. * ID of message to drop.
  35. */
  36. int id;
  37. };
  38. METHOD(listener_t, message, bool,
  39. private_ignore_message_t *this, ike_sa_t *ike_sa, message_t *message,
  40. bool incoming, bool plain)
  41. {
  42. if (incoming == this->in && plain &&
  43. message->get_request(message) == this->req &&
  44. message->get_message_id(message) == this->id)
  45. {
  46. DBG1(DBG_CFG, "ignoring message");
  47. message->set_exchange_type(message, EXCHANGE_TYPE_UNDEFINED);
  48. }
  49. return TRUE;
  50. }
  51. METHOD(hook_t, destroy, void,
  52. private_ignore_message_t *this)
  53. {
  54. free(this);
  55. }
  56. /**
  57. * Create the ignore_message hook
  58. */
  59. hook_t *ignore_message_hook_create(char *name)
  60. {
  61. private_ignore_message_t *this;
  62. INIT(this,
  63. .hook = {
  64. .listener = {
  65. .message = _message,
  66. },
  67. .destroy = _destroy,
  68. },
  69. .in = conftest->test->get_bool(conftest->test,
  70. "hooks.%s.inbound", TRUE, name),
  71. .req = conftest->test->get_bool(conftest->test,
  72. "hooks.%s.request", TRUE, name),
  73. .id = conftest->test->get_int(conftest->test,
  74. "hooks.%s.id", 0, name),
  75. );
  76. return &this->hook;
  77. }