]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/networkd/port.h
ports: Add the most basic supports for bonding
[people/ms/network.git] / src / networkd / port.h
index 3981c82addd47b641ea1e42e710ceecb1e8062d0..f8beed3b59e37871ba301913563c9e3f175b277c 100644 (file)
 #ifndef NETWORKD_PORT_H
 #define NETWORKD_PORT_H
 
+#include <systemd/sd-netlink.h>
+
+#ifndef IF_NAMESIZE
+#define IF_NAMESIZE 16
+#endif
+
 #define PORT_CONFIG_DIR                        CONFIG_DIR "/ports"
 
 typedef enum nw_port_type {
        NW_PORT_UNKNOWN = 0,
+       NW_PORT_BONDING,
        NW_PORT_DUMMY,
+       NW_PORT_VLAN,
 } nw_port_type_t;
 
+// VLAN
+#define NW_VLAN_ID_INVALID             0
+#define NW_VLAN_ID_MIN                 1
+#define NW_VLAN_ID_MAX                 4096
+
 typedef struct nw_port nw_port;
+typedef struct nw_port_info nw_port_info_t;
 
 #include "address.h"
+#include "config.h"
 #include "daemon.h"
+#include "port-bonding.h"
+
+struct nw_port_info {
+       // IFLA_INFO_KIND/IFLA_INFO_DATA
+       const char* kind;
+
+       struct nw_port_ops {
+               // Configuration
+               int (*config_read)(nw_port* port);
+               int (*config_write)(nw_port* port);
+
+               // Get Parent Port
+               nw_port* (*get_parent_port)(nw_port* port);
+
+               // Link
+               int (*create_link)(nw_port* port, sd_netlink_message* message);
+               int (*destroy_link)(nw_port* port);
+       } ops;
+};
+
+#define NW_PORT_INFO(port) (port->info)
+#define NW_PORT_OPS(port) (&NW_PORT_INFO(port)->ops)
+
+struct nw_port {
+       nw_daemon* daemon;
+       int nrefs;
+
+       // Link
+       nw_link* link;
 
-int nw_port_create(nw_port** port, nw_daemon* daemon, const char* name);
+       nw_port_type_t type;
+       char name[IF_NAMESIZE];
+
+       // Configuration
+       nw_config *config;
+
+       // Common attributes
+       nw_address_t address;
+
+       // Type Operations
+       const nw_port_info_t* info;
+
+       // Bonding Settings
+       struct nw_port_bonding bonding;
+
+       // VLAN settings
+       struct nw_port_vlan {
+               nw_port* parent;
+               int id;
+
+               // If the parent has not been read from the configuration we will
+               // save the name and try to find it later.
+               char __parent_name[IF_NAMESIZE];
+       } vlan;
+};
+
+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,
+       const char* name, const char* path);
 
 nw_port* nw_port_ref(nw_port* port);
 nw_port* nw_port_unref(nw_port* port);
 
+int nw_port_destroy(nw_port* port);
+int __nw_port_drop_port(nw_daemon* daemon, nw_port* port, void* data);
+
 int nw_port_save(nw_port* port);
 
 const char* nw_port_name(nw_port* port);
@@ -53,4 +129,11 @@ int nw_port_reconfigure(nw_port* port);
 
 int nw_port_has_carrier(nw_port* port);
 
+int nw_port_check_type(nw_port* port, const nw_port_type_t type);
+
+// Stats
+const struct rtnl_link_stats64* nw_port_get_stats64(nw_port* port);
+int __nw_port_update_stats(nw_daemon* daemon, nw_port* port, void* data);
+int nw_port_update_stats(nw_port* port);
+
 #endif /* NETWORKD_PORT_H */