/*
 * network-inador-private.h
 * 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
 */

#ifndef __NETWORK_INADOR_PRIVATE_H__
#define __NETWORK_INADOR_PRIVATE_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include <netlink/socket.h>
#include <netlink/msg.h>

#include "network-inador-public.h"
#include "flist.h"
#include "network-inador-events.h"

/* Para vigilar eventos */
typedef struct {
	struct nl_sock * nl_sock;
	unsigned int source;
} NetlinkEventPair;

typedef struct _NetworkInadorEventList {
	NetworkInadorDHCPEventCB dhcp_event_cb;
	void *dhcp_event_data;
	
	NetworkInadorInterfaceAddEventCB interface_add_event_cb;
	void *interface_add_event_data;
	NetworkInadorInterfaceUpdateEventCB interface_update_event_cb;
	void *interface_update_event_data;
	NetworkInadorInterfaceDeleteEventCB interface_del_event_cb;
	void *interface_del_event_data;
	
	NetworkInadorIPAddEventCB ip_add_event_cb;
	void *ip_add_event_data;
	NetworkInadorIPDelEventCB ip_del_event_cb;
	void *ip_del_event_data;
} NetworkInadorEventList;

/* La definición principal que engloba todo */
struct _NetworkInadorHandle {
	struct NetworkInadorOps ops;
	
	/* La verdadera información */
	FList *interfaces;
	FList *route_v4_tables;
	FList *route_v6_tables;
	FList *route_tables_names;
	
	/* Auxiliar contador de la lista ligada de interfaces */
	int interfaces_counter;
	
	/* Entradas para el resolv conf */
	FList *resolver_entries;
	int resolver_inotify_fd;
	int resolver_inotify_watch;
	
	/* Estos sockets ejecutan comandos */
	struct nl_sock * nl_sock_route;
	//struct nl_sock * nl_sock_nl80211;
	
	/* Estos sockets son de vigilancia de eventos */
	int has_route_events;
	NetlinkEventPair route_events;
	
	/*NetlinkEventPair nl80211_scan;
	NetlinkEventPair nl80211_scan_results;*/
	
	/* El pipe de vigilancia especial de las rutas eliminadas */
	int pipe_routes[2];
	unsigned int source_pipe_routes;
	
	struct _NetworkInadorEventList notify_list;
};

#endif /* __NETWORK_INADOR_PRIVATE_H__ */