]>
git.ipfire.org Git - people/ms/network.git/blob - src/libnetwork/interface.c
1 /*#############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2018 IPFire Network Development Team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
25 #include <network/interface.h>
26 #include <network/libnetwork.h>
27 #include <network/logging.h>
28 #include "libnetwork-private.h"
30 struct network_interface
{
31 struct network_ctx
* ctx
;
37 NETWORK_EXPORT
int network_interface_new(struct network_ctx
* ctx
,
38 struct network_interface
** intf
, const char* name
) {
42 struct network_interface
* i
= calloc(1, sizeof(*i
));
47 i
->ctx
= network_ref(ctx
);
49 i
->name
= strdup(name
);
51 DEBUG(i
->ctx
, "Allocated network interface at %p\n", i
);
57 NETWORK_EXPORT
struct network_interface
* network_interface_ref(struct network_interface
* intf
) {
65 static void network_interface_free(struct network_interface
* intf
) {
66 DEBUG(intf
->ctx
, "Released network interface at %p\n", intf
);
71 network_unref(intf
->ctx
);
75 NETWORK_EXPORT
struct network_interface
* network_interface_unref(struct network_interface
* intf
) {
79 if (--intf
->refcount
> 0)
82 network_interface_free(intf
);
86 NETWORK_EXPORT
const char* network_interface_get_name(struct network_interface
* intf
) {