set_ike_initiator.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <encoding/payloads/unknown_payload.h>
  17. typedef struct private_set_ike_initiator_t private_set_ike_initiator_t;
  18. /**
  19. * Private data of an set_ike_initiator_t object.
  20. */
  21. struct private_set_ike_initiator_t {
  22. /**
  23. * Implements the hook_t interface.
  24. */
  25. hook_t hook;
  26. /**
  27. * Alter requests or responses?
  28. */
  29. bool req;
  30. /**
  31. * ID of message to alter.
  32. */
  33. int id;
  34. };
  35. METHOD(listener_t, message, bool,
  36. private_set_ike_initiator_t *this, ike_sa_t *ike_sa, message_t *message,
  37. bool incoming, bool plain)
  38. {
  39. if (!incoming && plain &&
  40. message->get_request(message) == this->req &&
  41. message->get_message_id(message) == this->id)
  42. {
  43. ike_sa_id_t *id;
  44. DBG1(DBG_CFG, "toggling IKE message initiator flag");
  45. id = message->get_ike_sa_id(message);
  46. id->switch_initiator(id);
  47. }
  48. return TRUE;
  49. }
  50. METHOD(hook_t, destroy, void,
  51. private_set_ike_initiator_t *this)
  52. {
  53. free(this);
  54. }
  55. /**
  56. * Create the IKE_AUTH fill hook
  57. */
  58. hook_t *set_ike_initiator_hook_create(char *name)
  59. {
  60. private_set_ike_initiator_t *this;
  61. INIT(this,
  62. .hook = {
  63. .listener = {
  64. .message = _message,
  65. },
  66. .destroy = _destroy,
  67. },
  68. .req = conftest->test->get_bool(conftest->test,
  69. "hooks.%s.request", TRUE, name),
  70. .id = conftest->test->get_int(conftest->test,
  71. "hooks.%s.id", 0, name),
  72. );
  73. return &this->hook;
  74. }