NetworkInador/lib/event_notify.c

166 lines
6.8 KiB
C
Raw Normal View History

/*
* event_notify.c
* This file is part of Network-inador
*
* Copyright (C) 2024 - Félix Arreola Rodríguez
*
* Network-inador 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 2 of the License, or
* (at your option) any later version.
*
* Network-inador 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 Network-inador; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "network-inador-private.h"
#include "network-inador-events.h"
#include "interfaces.h"
#include "ip-address.h"
//#include "dhcp_defs.h"
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
/* Agregar vigilancias */
void network_manager_add_watch_dhcp (NetworkInadorHandle *handle, NetworkInadorDHCPEventCB cb, void *data) {
handle->notify_list.dhcp_event_cb = cb;
handle->notify_list.dhcp_event_data = data;
}
void network_manager_add_watch_interface_added (NetworkInadorHandle *handle, NetworkInadorInterfaceAddEventCB cb, void *data) {
handle->notify_list.interface_add_event_cb = cb;
handle->notify_list.interface_add_event_data = data;
}
void network_manager_add_watch_interface_updated (NetworkInadorHandle *handle, NetworkInadorInterfaceUpdateEventCB cb, void *data) {
handle->notify_list.interface_update_event_cb = cb;
handle->notify_list.interface_update_event_data = data;
}
void network_manager_add_watch_interface_deleted (NetworkInadorHandle *handle, NetworkInadorInterfaceDeleteEventCB cb, void *data) {
handle->notify_list.interface_del_event_cb = cb;
handle->notify_list.interface_del_event_data = data;
}
void network_manager_add_watch_ip_added (NetworkInadorHandle *handle, NetworkInadorIPAddEventCB cb, void *data) {
handle->notify_list.ip_add_event_cb = cb;
handle->notify_list.ip_add_event_data = data;
}
void network_manager_add_watch_ip_deleted (NetworkInadorHandle *handle, NetworkInadorIPDelEventCB cb, void *data) {
handle->notify_list.ip_del_event_cb = cb;
handle->notify_list.ip_del_event_data = data;
}
void network_manager_add_watch_route_added (NetworkInadorHandle *handle, NetworkInadorRouteAddEventCB cb, void *data) {
handle->notify_list.route_add_event_cb = cb;
handle->notify_list.route_add_event_data = data;
}
void network_manager_add_watch_route_updated (NetworkInadorHandle *handle, NetworkInadorRouteUpdateEventCB cb, void *data) {
handle->notify_list.route_update_event_cb = cb;
handle->notify_list.route_update_event_data = data;
}
void network_manager_add_watch_route_deleted (NetworkInadorHandle *handle, NetworkInadorRouteDelEventCB cb, void *data) {
handle->notify_list.route_del_event_cb = cb;
handle->notify_list.route_del_event_data = data;
}
void network_manager_add_watch_route_table_added (NetworkInadorHandle *handle, NetworkInadorRouteTableAddEventCB cb, void *data) {
handle->notify_list.route_table_add_event_cb = cb;
handle->notify_list.route_table_add_event_data = data;
}
void network_manager_add_watch_route_table_deleted (NetworkInadorHandle *handle, NetworkInadorRouteTableDelEventCB cb, void *data) {
handle->notify_list.route_table_del_event_cb = cb;
handle->notify_list.route_table_del_event_data = data;
}
/* Disparar las vigilancias */
void network_manager_trigger_dhcp_event (NetworkInadorHandle *handle, InterfaceDHCPClientInfo *dhcpc) {
Interface *iface = container_of (dhcpc, Interface, dhcpc);
if (handle->notify_list.dhcp_event_cb != NULL) {
handle->notify_list.dhcp_event_cb (handle, iface, dhcpc, handle->notify_list.dhcp_event_data);
}
}
/* Triggers de interfaces */
void network_manager_trigger_interface_added_event (NetworkInadorHandle *handle, Interface *iface) {
if (handle->notify_list.interface_add_event_cb != NULL) {
handle->notify_list.interface_add_event_cb (handle, iface, handle->notify_list.interface_add_event_data);
}
}
void network_manager_trigger_interface_updated_event (NetworkInadorHandle *handle, Interface *iface) {
if (handle->notify_list.interface_update_event_cb != NULL) {
handle->notify_list.interface_update_event_cb (handle, iface, handle->notify_list.interface_update_event_data);
}
}
void network_manager_trigger_interface_deleted_event (NetworkInadorHandle *handle, uint32_t index) {
if (handle->notify_list.interface_del_event_cb != NULL) {
handle->notify_list.interface_del_event_cb (handle, index, handle->notify_list.interface_del_event_data);
}
}
/* Triggers de ips */
void network_manager_trigger_ip_added_event (NetworkInadorHandle *handle, IPAddr *ip_addr) {
if (handle->notify_list.ip_add_event_cb != NULL) {
handle->notify_list.ip_add_event_cb (handle, ip_addr, handle->notify_list.ip_add_event_data);
}
}
void network_manager_trigger_ip_deleted_event (NetworkInadorHandle *handle, IPAddr *ip_addr) {
if (handle->notify_list.ip_del_event_cb != NULL) {
handle->notify_list.ip_del_event_cb (handle, ip_addr, handle->notify_list.ip_del_event_data);
}
}
/* Triggers de rutas */
void network_manager_trigger_route_added_event (NetworkInadorHandle *handle, Route *route) {
if (handle->notify_list.route_add_event_cb != NULL) {
handle->notify_list.route_add_event_cb (handle, route, handle->notify_list.route_add_event_data);
}
}
void network_manager_trigger_route_updated_event (NetworkInadorHandle *handle, Route *route) {
if (handle->notify_list.route_update_event_cb != NULL) {
handle->notify_list.route_update_event_cb (handle, route, handle->notify_list.route_update_event_data);
}
}
void network_manager_trigger_route_deleted_event (NetworkInadorHandle *handle, Route *route) {
if (handle->notify_list.route_del_event_cb != NULL) {
handle->notify_list.route_del_event_cb (handle, route, handle->notify_list.route_del_event_data);
}
}
/* Trggers de tablasde ruteo */
void network_manager_trigger_route_table_added_event (NetworkInadorHandle *handle, uint32_t table_index, const char *table_name) {
if (handle->notify_list.route_table_add_event_cb != NULL) {
handle->notify_list.route_table_add_event_cb (handle, table_index, table_name, handle->notify_list.route_table_add_event_data);
}
}
void network_manager_trigger_route_table_deleted_event (NetworkInadorHandle *handle, uint32_t table_index) {
if (handle->notify_list.route_table_del_event_cb != NULL) {
handle->notify_list.route_table_del_event_cb (handle, table_index, handle->notify_list.route_table_del_event_data);
}
}