]> git.ipfire.org Git - people/ms/network.git/commitdiff
ports: Add scaffolding for physical Ethernet interfaces
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 14:59:54 +0000 (14:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Jun 2023 14:59:54 +0000 (14:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/networkd/link.c
src/networkd/port-ethernet.c [new file with mode: 0644]
src/networkd/port-ethernet.h [new file with mode: 0644]
src/networkd/port.c
src/networkd/port.h

index 2632ca73daa09c390cff4c2b412b9e10582a68e1..8c0d0c0f4623acd41dd89de6f996fdaa82e45b54 100644 (file)
@@ -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-ethernet.c \
+       src/networkd/port-ethernet.h \
        src/networkd/port-veth.c \
        src/networkd/port-veth.h \
        src/networkd/port-vlan.c \
index 23918cba8dfdccd60476c5831f0bc063db096e89..f172208e8d5c6ab7ddf2c1a9a2245b3ee748b412 100644 (file)
@@ -154,19 +154,6 @@ const char* nw_link_ifname(nw_link* link) {
        return link->ifname;
 }
 
-static int nw_link_get_sd_device(nw_link* link, struct sd_device** device) {
-       int r;
-
-       // Fetch sd-device
-       r = sd_device_new_from_ifindex(device, link->ifindex);
-       if (r < 0) {
-               ERROR("Could not fetch sd-device for link %d: %s\n", link->ifindex, strerror(-r));
-               return r;
-       }
-
-       return 0;
-}
-
 // Stats
 
 const struct rtnl_link_stats64* nw_link_get_stats64(nw_link* link) {
diff --git a/src/networkd/port-ethernet.c b/src/networkd/port-ethernet.c
new file mode 100644 (file)
index 0000000..a48b45e
--- /dev/null
@@ -0,0 +1,63 @@
+/*#############################################################################
+#                                                                             #
+# 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include "config.h"
+#include "json.h"
+#include "port.h"
+#include "port-ethernet.h"
+
+static int nw_port_ethernet_setup(nw_port* port) {
+       int r;
+
+       // Permanent Address
+       r = NW_CONFIG_OPTION_ADDRESS(port->config,
+               "PERMANENT_ADDRESS", &port->ethernet.permanent_address);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
+static int nw_port_ethernet_to_json(nw_port* port, struct json_object* o) {
+       char* address = NULL;
+       int r = 0;
+
+       // Permanent Address
+       address = nw_address_to_string(&port->ethernet.permanent_address);
+       if (address) {
+               r = json_object_add_string(o, "PermanentAddress", address);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+ERROR:
+       if (address)
+               free(address);
+
+       return r;
+}
+
+const nw_port_type_t nw_port_type_ethernet = {
+       // Configuration
+       .setup = nw_port_ethernet_setup,
+
+       // JSON
+       .to_json = nw_port_ethernet_to_json,
+};
diff --git a/src/networkd/port-ethernet.h b/src/networkd/port-ethernet.h
new file mode 100644 (file)
index 0000000..50dade2
--- /dev/null
@@ -0,0 +1,34 @@
+/*#############################################################################
+#                                                                             #
+# 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef NETWORKD_PORT_ETHERNET_H
+#define NETWORKD_PORT_ETHERNET_H
+
+#include "address.h"
+#include "port.h"
+
+struct nw_port_ethernet {
+       // Permanent Address
+       nw_address_t permanent_address;
+};
+
+extern const nw_port_type_t nw_port_type_ethernet;
+
+#endif /* NETWORKD_PORT_ETHERNET_H */
index 84fceee885ad04ff32e942487b910e59c24e8f2c..f54795694640bed6d584afc6fc18cc785b954518 100644 (file)
 #include "port.h"
 #include "port-bonding.h"
 #include "port-dummy.h"
+#include "port-ethernet.h"
 #include "port-veth.h"
 #include "port-vlan.h"
 #include "stats-collector.h"
 #include "string.h"
 
 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" },
+       { NW_PORT_BONDING,  "bonding" },
+       { NW_PORT_DUMMY,    "dummy" },
+       { NW_PORT_ETHERNET, "ethernet" },
+       { NW_PORT_VETH,     "veth", },
+       { NW_PORT_VLAN,     "vlan" },
        { -1, NULL },
 };
 
@@ -167,8 +169,13 @@ int nw_port_create(nw_port** port, nw_daemon* daemon,
                        p->type = &nw_port_type_dummy;
                        break;
 
+               case NW_PORT_ETHERNET:
+                       p->type = &nw_port_type_ethernet;
+                       break;
+
                case NW_PORT_VETH:
                        p->type = &nw_port_type_veth;
+                       break;
 
                case NW_PORT_VLAN:
                        p->type = &nw_port_type_vlan;
@@ -329,6 +336,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_ETHERNET:
                case NW_PORT_VETH:
                        break;
        }
index 5c0a2a12e2dd636cbcb8419d4a16ce6a46c26a7e..f1cb3d289c8e46bdc4d5cf3548b263661cf8da26 100644 (file)
@@ -36,6 +36,7 @@ typedef struct nw_port nw_port;
 typedef enum nw_port_type_id {
        NW_PORT_BONDING,
        NW_PORT_DUMMY,
+       NW_PORT_ETHERNET,
        NW_PORT_VETH,
        NW_PORT_VLAN,
 } nw_port_type_id_t;
@@ -67,6 +68,7 @@ typedef struct nw_port_type {
 #include "daemon.h"
 #include "json.h"
 #include "port-bonding.h"
+#include "port-ethernet.h"
 #include "port-veth.h"
 #include "port-vlan.h"
 
@@ -91,6 +93,9 @@ struct nw_port {
        // Bonding Settings
        struct nw_port_bonding bonding;
 
+       // Ethernet Settings
+       struct nw_port_ethernet ethernet;
+
        // VETH Settings
        struct nw_port_veth veth;