2 * Copyright (C) 2023 Andreas Steffen
4 * Copyright (C) secunet Security Networks AG
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>.
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
17 #include "tun_device_manager.h"
19 #include <utils/debug.h>
21 typedef struct private_tun_device_manager_t private_tun_device_manager_t
;
24 * private data of tun_device_manager
26 struct private_tun_device_manager_t
{
31 tun_device_manager_t
public;
34 * constructor function to create tun_device instances
36 tun_device_constructor_t constructor
;
39 METHOD(tun_device_manager_t
, add_tun_device
, void,
40 private_tun_device_manager_t
*this, tun_device_constructor_t constructor
)
42 if (!this->constructor
)
44 this->constructor
= constructor
;
48 METHOD(tun_device_manager_t
, remove_tun_device
, void,
49 private_tun_device_manager_t
*this, tun_device_constructor_t constructor
)
51 if (this->constructor
== constructor
)
53 this->constructor
= NULL
;
57 METHOD(tun_device_manager_t
, create
, tun_device_t
*,
58 private_tun_device_manager_t
*this, const char *name_tmpl
)
60 if (this->constructor
)
62 return this->constructor(name_tmpl
);
66 return tun_device_create(name_tmpl
);
70 METHOD(tun_device_manager_t
, destroy
, void,
71 private_tun_device_manager_t
*this)
79 tun_device_manager_t
*tun_device_manager_create()
81 private_tun_device_manager_t
*this;
85 .add_tun_device
= _add_tun_device
,
86 .remove_tun_device
= _remove_tun_device
,