From: Michael Tremer Date: Sun, 4 Jun 2023 14:28:35 +0000 (+0000) Subject: ports: Create scaffolding for operations struct X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e8af30e5ff0ab717f7d878f8e9c62323ec161a1;p=network.git ports: Create scaffolding for operations struct Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 22d90d48..15e9fa0a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -332,6 +332,8 @@ dist_networkd_SOURCES = \ src/networkd/port.h \ src/networkd/port-bus.c \ src/networkd/port-bus.h \ + src/networkd/port-dummy.c \ + src/networkd/port-dummy.h \ src/networkd/stats-collector.c \ src/networkd/stats-collector.h \ src/networkd/string.h \ diff --git a/src/networkd/port-dummy.c b/src/networkd/port-dummy.c new file mode 100644 index 00000000..cc4b649d --- /dev/null +++ b/src/networkd/port-dummy.c @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2023 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include "port.h" +#include "port-dummy.h" + +nw_port_ops_t nw_port_ops_dummy = { + // There is no special configuration + .config_read = NULL, + .config_write = NULL, +}; diff --git a/src/networkd/port-dummy.h b/src/networkd/port-dummy.h new file mode 100644 index 00000000..0a29c84f --- /dev/null +++ b/src/networkd/port-dummy.h @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2023 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef NETWORKD_PORT_DUMMY_H +#define NETWORKD_PORT_DUMMY_H + +#include "port.h" + +extern nw_port_ops_t nw_port_ops_dummy; + +#endif /* NETWORKD_PORT_DUMMY_H */ diff --git a/src/networkd/port.c b/src/networkd/port.c index 23ffd0bd..6ba48757 100644 --- a/src/networkd/port.c +++ b/src/networkd/port.c @@ -30,6 +30,7 @@ #include "link.h" #include "logging.h" #include "port.h" +#include "port-dummy.h" #include "stats-collector.h" #include "string.h" @@ -49,6 +50,9 @@ struct nw_port { // Common attributes nw_address_t address; + // Type Operations + nw_port_ops_t ops; + // VLAN settings struct nw_port_vlan { nw_port* parent; @@ -252,6 +256,13 @@ int nw_port_create(nw_port** port, nw_daemon* daemon, nw_port_type_t type, const // Store the type p->type = type; + // Set operations + switch (p->type) { + case NW_PORT_DUMMY: + p->ops = nw_port_ops_dummy; + break; + } + // Store the name r = nw_string_set(p->name, name); if (r) diff --git a/src/networkd/port.h b/src/networkd/port.h index 032d82c7..76df7a77 100644 --- a/src/networkd/port.h +++ b/src/networkd/port.h @@ -37,8 +37,15 @@ typedef enum nw_port_type { typedef struct nw_port nw_port; #include "address.h" +#include "config.h" #include "daemon.h" +typedef struct nw_port_ops { + // Configuration + int (*config_read)(nw_port* port, nw_config* config); + int (*config_write)(nw_port* port, nw_config* config); +} nw_port_ops_t; + int nw_port_create(nw_port** port, nw_daemon* daemon, nw_port_type_t type, const char* name); int nw_port_create_from_config(nw_port** port, nw_daemon* daemon,