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