#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;
-struct nw_port;
+// 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"
+#include "port-vlan.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;
+
+ 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 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);
+
+char* nw_port_bus_path(nw_port* port);
+
+int __nw_port_set_link(nw_daemon* daemon, nw_port* port, void* data);
+int __nw_port_drop_link(nw_daemon* daemon, nw_port* port, void* data);
+
+const nw_address_t* nw_port_get_address(nw_port* port);
-int nw_port_create(struct nw_port** port, const char* name);
+int nw_port_reconfigure(nw_port* port);
-struct nw_port* nw_port_ref(struct nw_port* port);
-struct nw_port* nw_port_unref(struct nw_port* port);
+int nw_port_has_carrier(nw_port* port);
-const char* nw_port_name(struct nw_port* port);
+int nw_port_check_type(nw_port* port, const nw_port_type_t type);
-char* nw_port_bus_path(struct nw_port* port);
+// 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 */