]>
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 #############################################################################*/
26 #include <network/interface.h>
27 #include <network/libnetwork.h>
28 #include <network/logging.h>
29 #include "libnetwork-private.h"
31 struct network_interface
{
32 struct network_ctx
* ctx
;
39 NETWORK_EXPORT
int network_interface_new(struct network_ctx
* ctx
,
40 struct network_interface
** intf
, const char* name
) {
44 unsigned int index
= if_nametoindex(name
);
46 ERROR(ctx
, "Could not find interface %s\n", name
);
50 struct network_interface
* i
= calloc(1, sizeof(*i
));
55 i
->ctx
= network_ref(ctx
);
58 i
->name
= strdup(name
);
60 DEBUG(i
->ctx
, "Allocated network interface at %p\n", i
);
66 NETWORK_EXPORT
struct network_interface
* network_interface_ref(struct network_interface
* intf
) {
74 static void network_interface_free(struct network_interface
* intf
) {
75 DEBUG(intf
->ctx
, "Released network interface at %p\n", intf
);
80 network_unref(intf
->ctx
);
84 NETWORK_EXPORT
struct network_interface
* network_interface_unref(struct network_interface
* intf
) {
88 if (--intf
->refcount
> 0)
91 network_interface_free(intf
);
95 NETWORK_EXPORT
const char* network_interface_get_name(struct network_interface
* intf
) {