From: Michael Tremer Date: Fri, 9 Jun 2023 10:37:47 +0000 (+0000) Subject: ports: Add support for VETH X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=67d3fef1d79e933b8af64a39f89fef4b1f8b31cb;p=network.git ports: Add support for VETH Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 2df9185d..caab99e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -338,6 +338,8 @@ dist_networkd_SOURCES = \ src/networkd/port-bus.h \ src/networkd/port-dummy.c \ src/networkd/port-dummy.h \ + src/networkd/port-veth.c \ + src/networkd/port-veth.h \ src/networkd/port-vlan.c \ src/networkd/port-vlan.h \ src/networkd/stats-collector.c \ diff --git a/src/networkd/port-veth.c b/src/networkd/port-veth.c new file mode 100644 index 00000000..44b1a0d4 --- /dev/null +++ b/src/networkd/port-veth.c @@ -0,0 +1,81 @@ +/*############################################################################# +# # +# 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 + +#include "json.h" +#include "port.h" +#include "port-veth.h" + +static int nw_port_veth_setup(nw_port* port) { + int r; + + // Peer + r = NW_CONFIG_OPTION_STRING(port->config, "VETH_PEER", &port->veth.peer); + if (r < 0) + return 1; + + return 0; +} + +static int nw_port_veth_create_link(nw_port* port, sd_netlink_message* m) { + int r; + + // Open the container + r = sd_netlink_message_open_container(m, VETH_INFO_PEER); + if (r < 0) + return r; + + // Set VETH Peer + r = sd_netlink_message_append_string(m, IFLA_VLAN_ID, port->veth.peer); + if (r < 0) + return r; + + // Close the container + r = sd_netlink_message_close_container(m); + if (r < 0) + return r; + + return 0; +} + +static int nw_port_veth_to_json(nw_port* port, struct json_object* o) { + int r; + + // Add the VETH Peer + r = json_object_add_string(o, "VETHPeer", port->veth.peer); + if (r < 0) + return r; + + return 0; +} + +const nw_port_type_t nw_port_type_veth = { + .kind = "veth", + + // Configuration + .setup = nw_port_veth_setup, + + // Link + .create_link = nw_port_veth_create_link, + + // JSON + .to_json = nw_port_veth_to_json, +}; diff --git a/src/networkd/port-veth.h b/src/networkd/port-veth.h new file mode 100644 index 00000000..aa4a03b2 --- /dev/null +++ b/src/networkd/port-veth.h @@ -0,0 +1,35 @@ +/*############################################################################# +# # +# 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_VETH_H +#define NETWORKD_PORT_VETH_H + +#include "port.h" + +// Maximum length of the peer name +#define NW_VETH_PEER_MAX 64 + +struct nw_port_veth { + char peer[NW_VETH_PEER_MAX]; +}; + +extern const nw_port_type_t nw_port_type_veth; + +#endif /* NETWORKD_PORT_VETH_H */ diff --git a/src/networkd/port.c b/src/networkd/port.c index 7d654e3c..fb625207 100644 --- a/src/networkd/port.c +++ b/src/networkd/port.c @@ -33,6 +33,7 @@ #include "port.h" #include "port-bonding.h" #include "port-dummy.h" +#include "port-veth.h" #include "port-vlan.h" #include "stats-collector.h" #include "string.h" @@ -40,6 +41,7 @@ static const nw_string_table_t nw_port_type_id[] = { { NW_PORT_BONDING, "bonding" }, { NW_PORT_DUMMY, "dummy" }, + { NW_PORT_VETH, "veth", }, { NW_PORT_VLAN, "vlan" }, { -1, NULL }, }; @@ -165,6 +167,9 @@ int nw_port_create(nw_port** port, nw_daemon* daemon, p->type = &nw_port_type_dummy; break; + case NW_PORT_VETH: + p->type = &nw_port_type_veth; + case NW_PORT_VLAN: p->type = &nw_port_type_vlan; break; @@ -324,6 +329,7 @@ int __nw_port_drop_port(nw_daemon* daemon, nw_port* port, void* data) { case NW_PORT_BONDING: case NW_PORT_DUMMY: + case NW_PORT_VETH: break; } diff --git a/src/networkd/port.h b/src/networkd/port.h index efa2fdbe..5c0a2a12 100644 --- a/src/networkd/port.h +++ b/src/networkd/port.h @@ -36,6 +36,7 @@ typedef struct nw_port nw_port; typedef enum nw_port_type_id { NW_PORT_BONDING, NW_PORT_DUMMY, + NW_PORT_VETH, NW_PORT_VLAN, } nw_port_type_id_t; @@ -66,6 +67,7 @@ typedef struct nw_port_type { #include "daemon.h" #include "json.h" #include "port-bonding.h" +#include "port-veth.h" #include "port-vlan.h" #define NW_PORT_TYPE(port) (port->type) @@ -89,6 +91,9 @@ struct nw_port { // Bonding Settings struct nw_port_bonding bonding; + // VETH Settings + struct nw_port_veth veth; + // VLAN settings struct nw_port_vlan vlan; };