]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/plugins/connmark/connmark_plugin.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libcharon / plugins / connmark / connmark_plugin.c
1 /*
2 * Copyright (C) 2014 Martin Willi
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "connmark_plugin.h"
18 #include "connmark_listener.h"
19
20 #include <daemon.h>
21
22 typedef struct private_connmark_plugin_t private_connmark_plugin_t;
23
24 /**
25 * private data of connmark plugin
26 */
27 struct private_connmark_plugin_t {
28
29 /**
30 * implements plugin interface
31 */
32 connmark_plugin_t public;
33
34 /**
35 * Listener installing netfilter rules
36 */
37 connmark_listener_t *listener;
38 };
39
40 METHOD(plugin_t, get_name, char*,
41 private_connmark_plugin_t *this)
42 {
43 return "connmark";
44 }
45
46 /**
47 * Register listener
48 */
49 static bool plugin_cb(private_connmark_plugin_t *this,
50 plugin_feature_t *feature, bool reg, void *cb_data)
51 {
52 if (reg)
53 {
54 charon->bus->add_listener(charon->bus, &this->listener->listener);
55 }
56 else
57 {
58 charon->bus->remove_listener(charon->bus, &this->listener->listener);
59 }
60 return TRUE;
61 }
62
63 METHOD(plugin_t, get_features, int,
64 private_connmark_plugin_t *this, plugin_feature_t *features[])
65 {
66 static plugin_feature_t f[] = {
67 PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
68 PLUGIN_PROVIDE(CUSTOM, "connmark"),
69 };
70 *features = f;
71 return countof(f);
72 }
73
74 METHOD(plugin_t, destroy, void,
75 private_connmark_plugin_t *this)
76 {
77 this->listener->destroy(this->listener);
78 free(this);
79 }
80
81 /**
82 * Plugin constructor
83 */
84 plugin_t *connmark_plugin_create()
85 {
86 private_connmark_plugin_t *this;
87
88 if (!lib->caps->keep(lib->caps, CAP_NET_ADMIN))
89 {
90 DBG1(DBG_NET, "connmark plugin requires CAP_NET_ADMIN capability");
91 return NULL;
92 }
93
94 if (!lib->caps->keep(lib->caps, CAP_NET_RAW))
95 {
96 DBG1(DBG_NET, "connmark plugin requires CAP_NET_RAW capability");
97 return NULL;
98 }
99
100 INIT(this,
101 .public = {
102 .plugin = {
103 .get_name = _get_name,
104 .get_features = _get_features,
105 .destroy = _destroy,
106 },
107 },
108 .listener = connmark_listener_create(),
109 );
110
111 return &this->public.plugin;
112 }