forecast_plugin.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2010-2014 Martin Willi
  3. * Copyright (C) 2010-2014 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 "forecast_plugin.h"
  16. #include "forecast_listener.h"
  17. #include "forecast_forwarder.h"
  18. #include <daemon.h>
  19. typedef struct private_forecast_plugin_t private_forecast_plugin_t;
  20. /**
  21. * Private data of forecast plugin
  22. */
  23. struct private_forecast_plugin_t {
  24. /**
  25. * implements plugin interface
  26. */
  27. forecast_plugin_t public;
  28. /**
  29. * Listener registering active tunnels
  30. */
  31. forecast_listener_t *listener;
  32. /**
  33. * Broadcast/Multicast sniffer and forwarder
  34. */
  35. forecast_forwarder_t *forwarder;
  36. };
  37. METHOD(plugin_t, get_name, char*,
  38. private_forecast_plugin_t *this)
  39. {
  40. return "forecast";
  41. }
  42. /**
  43. * Register plugin features
  44. */
  45. static bool register_forecast(private_forecast_plugin_t *this,
  46. plugin_feature_t *feature, bool reg, void *data)
  47. {
  48. if (reg)
  49. {
  50. this->forwarder = forecast_forwarder_create(this->listener);
  51. if (!this->forwarder)
  52. {
  53. return FALSE;
  54. }
  55. charon->bus->add_listener(charon->bus, &this->listener->listener);
  56. }
  57. else
  58. {
  59. charon->bus->remove_listener(charon->bus, &this->listener->listener);
  60. this->forwarder->destroy(this->forwarder);
  61. }
  62. return TRUE;
  63. }
  64. METHOD(plugin_t, get_features, int,
  65. private_forecast_plugin_t *this, plugin_feature_t *features[])
  66. {
  67. static plugin_feature_t f[] = {
  68. PLUGIN_CALLBACK((plugin_feature_callback_t)register_forecast, NULL),
  69. PLUGIN_PROVIDE(CUSTOM, "forecast"),
  70. };
  71. *features = f;
  72. return countof(f);
  73. }
  74. METHOD(plugin_t, destroy, void,
  75. private_forecast_plugin_t *this)
  76. {
  77. this->listener->destroy(this->listener);
  78. free(this);
  79. }
  80. /**
  81. * Plugin constructor
  82. */
  83. plugin_t *forecast_plugin_create()
  84. {
  85. private_forecast_plugin_t *this;
  86. if (!lib->caps->keep(lib->caps, CAP_NET_RAW))
  87. {
  88. DBG1(DBG_NET, "forecast plugin requires CAP_NET_RAW capability");
  89. return NULL;
  90. }
  91. INIT(this,
  92. .public = {
  93. .plugin = {
  94. .get_name = _get_name,
  95. .get_features = _get_features,
  96. .reload = (void*)return_false,
  97. .destroy = _destroy,
  98. },
  99. },
  100. .listener = forecast_listener_create(),
  101. );
  102. return &this->public.plugin;
  103. }