Reconecto el manager, eventos y comandos de interfaces.

master
Félix Arreola Rodríguez 2025-01-02 17:43:10 -06:00
parent dab460efb6
commit 38ebabf853
33 changed files with 1424 additions and 1883 deletions

View File

@ -1,8 +1,8 @@
Installation Instructions Installation Instructions
************************* *************************
Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software Copyright (C) 1994-1996, 1999-2002, 2004-2017, 2020-2021 Free
Foundation, Inc. Software Foundation, Inc.
Copying and distribution of this file, with or without modification, Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright are permitted in any medium without royalty provided the copyright
@ -225,7 +225,7 @@ order to use an ANSI C compiler:
and if that doesn't work, install pre-built binaries of GCC for HP-UX. and if that doesn't work, install pre-built binaries of GCC for HP-UX.
HP-UX 'make' updates targets which have the same time stamps as their HP-UX 'make' updates targets which have the same timestamps as their
prerequisites, which makes it generally unusable when shipped generated prerequisites, which makes it generally unusable when shipped generated
files such as 'configure' are involved. Use GNU 'make' instead. files such as 'configure' are involved. Use GNU 'make' instead.

View File

@ -36,7 +36,7 @@
#include "ni-marshal.h" #include "ni-marshal.h"
#include "ni-route.h" #include "ni-route.h"
#include "../src/network-inador-manager.h" #include "network-inador-manager.h"
#define COMMAND_SOCKET_PATH "/tmp/network-inador.socket" #define COMMAND_SOCKET_PATH "/tmp/network-inador.socket"

View File

@ -29,7 +29,7 @@
#include "ni-ip.h" #include "ni-ip.h"
#include "ni-marshal.h" #include "ni-marshal.h"
#include "../src/network-inador-manager.h" #include "network-inador-manager.h"
struct _NIInterfacePrivate { struct _NIInterfacePrivate {
NIClient *ni_client; NIClient *ni_client;

View File

@ -27,7 +27,7 @@
#include "ni-interface.h" #include "ni-interface.h"
#include "ni-ip.h" #include "ni-ip.h"
#include "../src/network-inador-manager.h" #include "network-inador-manager.h"
struct _NIIPPrivate { struct _NIIPPrivate {
NIInterface *ni_interface; NIInterface *ni_interface;

View File

@ -28,7 +28,7 @@
#include "ni-route.h" #include "ni-route.h"
#include "ni-ip.h" #include "ni-ip.h"
#include "../src/network-inador-manager.h" #include "network-inador-manager.h"
struct _NIRoutePrivate { struct _NIRoutePrivate {
NIClient *ni_client; NIClient *ni_client;

View File

@ -478,7 +478,7 @@ _f_list_remove_link (FList *list,
{ {
if (link->prev->next == link) if (link->prev->next == link)
link->prev->next = link->next; link->prev->next = link->next;
//else else
printf ("corrupted double-linked list detected"); printf ("corrupted double-linked list detected");
} }
if (link->next) if (link->next)

View File

@ -1,8 +1,9 @@
lib_LTLIBRARIES = libnetworkinador.la lib_LTLIBRARIES = libnetworkinador.la
libnetworkinador_la_SOURCES = network-inador.h \ libnetworkinador_la_SOURCES = network-inador-public.h \
network-inador-private.h \ event_notify.c event_notify.h \
network-inador-link-types.h \ getters.c network-inador-private.h \
network-inador-link-types.h network-inador-manager.h network-inador-events.h \
struct_addr_union.h wireless_struct.h \ struct_addr_union.h wireless_struct.h \
handle.c \ handle.c \
netlink-events.c netlink-events.h \ netlink-events.c netlink-events.h \
@ -29,7 +30,7 @@ libnetworkinador_la_CFLAGS = -I$(top_srcdir)/common $(LIBNL3_CFLAGS) $(LIBNLGEN3
LDADD = $(LIBINTL) LDADD = $(LIBINTL)
libnetworkinadordir = $(includedir)/libnetworkinador libnetworkinadordir = $(includedir)/libnetworkinador
libnetworkinador_HEADERS = network-inador.h network-inador-link-types.h libnetworkinador_HEADERS = network-inador-public.h network-inador-link-types.h network-inador-manager.h network-inador-events.h
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
dist_pkgconfig_DATA = network-inador.pc dist_pkgconfig_DATA = network-inador.pc

View File

@ -35,13 +35,13 @@
#include "interfaces.h" #include "interfaces.h"
#include "network-inador-private.h" #include "network-inador-private.h"
//#include "manager.h" #include "network-inador-manager.h"
#include "dhcp_client.h" #include "dhcp_client.h"
#include "resolv_manager.h" #include "resolv_manager.h"
#include "launch_process.h" #include "launch_process.h"
#include "network-inador-manager.h" #include "event_notify.h"
static void interfaces_dhcp_clear_info (InterfaceDHCPClientInfo *dhcpc); static void interfaces_dhcp_clear_info (InterfaceDHCPClientInfo *dhcpc);
@ -111,7 +111,7 @@ void interfaces_dhcp_client_killed_cb (void *data, pid_t pid, int status) {
/* Enviar actualización de estado aquí */ /* Enviar actualización de estado aquí */
iface->dhcpc.dhcp_state = DHCP_CLIENT_KILLED; iface->dhcpc.dhcp_state = DHCP_CLIENT_KILLED;
//manager_send_event_dhcp_change (iface->handle, &iface->dhcpc); network_manager_trigger_dhcp_event (iface->handle, &iface->dhcpc);
if (iface->dhcpc.type == IFACE_ISC_DHCLIENT || iface->dhcpc.type == IFACE_BUSYBOX_UDHCPC) { if (iface->dhcpc.type == IFACE_ISC_DHCLIENT || iface->dhcpc.type == IFACE_BUSYBOX_UDHCPC) {
if (iface->dhcpc.flags & DHCP_CLIENT_FLAG_AUTO_RESTART) { if (iface->dhcpc.flags & DHCP_CLIENT_FLAG_AUTO_RESTART) {
@ -252,7 +252,7 @@ int interfaces_dhcp_client_run (NetworkInadorHandle *handle, int index, int type
iface->dhcpc.process_watch = handle->ops.process_watch (iface->dhcpc.process_pid, interfaces_dhcp_client_killed_cb, iface); iface->dhcpc.process_watch = handle->ops.process_watch (iface->dhcpc.process_pid, interfaces_dhcp_client_killed_cb, iface);
} }
//manager_send_event_dhcp_change (handle, &iface->dhcpc); network_manager_trigger_dhcp_event (handle, &iface->dhcpc);
return 0; return 0;
} }
@ -293,7 +293,7 @@ int interfaces_dhcp_client_stop (NetworkInadorHandle *handle, int index) {
resolv_manager_clear_dhcp_nameservers (handle, iface); resolv_manager_clear_dhcp_nameservers (handle, iface);
/* Enviar actualización de estado aquí */ /* Enviar actualización de estado aquí */
//manager_send_event_dhcp_change (handle, &iface->dhcpc); network_manager_trigger_dhcp_event (handle, &iface->dhcpc);
} }
return 0; return 0;
@ -417,6 +417,6 @@ void interfaces_dhcp_client_internal_feed_from_client (NetworkInadorHandle *hand
resolv_manager_clear_dhcp_nameservers (handle, iface); resolv_manager_clear_dhcp_nameservers (handle, iface);
} }
//manager_send_event_dhcp_change (handle, &iface->dhcpc); network_manager_trigger_dhcp_event (handle, &iface->dhcpc);
} }

View File

@ -24,7 +24,6 @@
#define __DHCPC_DEFS_H__ #define __DHCPC_DEFS_H__
#include <stdint.h> #include <stdint.h>
#include "flist.h"
#include "struct_addr_union.h" #include "struct_addr_union.h"
@ -52,7 +51,7 @@ enum {
#define DHCP_CLIENT_FLAG_DONT_ADD_ROUTE_INFO 0x0004 #define DHCP_CLIENT_FLAG_DONT_ADD_ROUTE_INFO 0x0004
#define DHCP_CLIENT_FLAG_DONT_ADD_IP_INFO 0x0008 #define DHCP_CLIENT_FLAG_DONT_ADD_IP_INFO 0x0008
typedef struct { typedef struct _InterfaceDHCPClientInfo {
int type; int type;
uint32_t flags; uint32_t flags;

108
lib/event_notify.c 100644
View File

@ -0,0 +1,108 @@
/*
* 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;
}
/* 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);
}
}

38
lib/event_notify.h 100644
View File

@ -0,0 +1,38 @@
/*
* event_notify.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 __EVENT_NOTIFY_H__
#define __EVENT_NOTIFY_H__
#include <stdint.h>
#include "network-inador-events.h"
void network_manager_trigger_dhcp_event (NetworkInadorHandle *handle, InterfaceDHCPClientInfo *dhcpc);
void network_manager_trigger_interface_added_event (NetworkInadorHandle *handle, Interface *iface);
void network_manager_trigger_interface_updated_event (NetworkInadorHandle *handle, Interface *iface);
void network_manager_trigger_interface_deleted_event (NetworkInadorHandle *handle, uint32_t index);
void network_manager_trigger_ip_added_event (NetworkInadorHandle *handle, IPAddr *ip_addr);
void network_manager_trigger_ip_deleted_event (NetworkInadorHandle *handle, IPAddr *ip_addr);
#endif /* __EVENT_NOTIFY_H__ */

200
lib/getters.c 100644
View File

@ -0,0 +1,200 @@
/*
* getters.c
* This file is part of Network-inador
*
* Copyright (C) 2025 - 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 <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "network-inador-private.h"
#include "interfaces.h"
#include "ip-address.h"
uint32_t *network_inador_list_ifaces (NetworkInadorHandle *handle) {
uint32_t *memory;
FList *g;
Interface *iface;
int c;
memory = (uint32_t *) malloc ((handle->interfaces_counter + 1) * sizeof (uint32_t));
if (memory == NULL) return NULL;
c = 0;
for (g = handle->interfaces; g != NULL; g = g->next) {
iface = (Interface *) g->data;
memory[c] = iface->index;
c++;
}
memory[c] = 0;
return memory;
}
Interface *network_inador_get_iface (NetworkInadorHandle *handle, uint32_t index) {
_interfaces_locate_by_index (handle->interfaces, index);
}
const unsigned char *network_inador_iface_get_name (Interface *iface) {
return iface->name;
}
uint32_t network_inador_iface_get_index (Interface *iface) {
return iface->index;
}
uint32_t network_inador_iface_get_link_type (Interface *iface) {
return iface->link_type;
}
uint32_t network_inador_iface_get_master_index (Interface *iface) {
return iface->master_index;
}
uint32_t network_inador_iface_get_mtu (Interface *iface) {
return iface->mtu;
}
uint16_t network_inador_iface_get_flags (Interface *iface) {
return iface->flags;
}
uint8_t network_inador_iface_get_is_wireless (Interface *iface) {
return iface->is_wireless;
}
uint8_t network_inador_iface_get_num_ips (Interface *iface) {
return iface->address_counter;
}
IPAddr *network_inador_iface_get_ipaddr_by_index (Interface *iface, int index) {
FList *pos;
pos = f_list_nth (f_list_first (iface->address), index);
if (pos == NULL) return NULL;
return (IPAddr *) (pos->data);
}
Interface *network_inador_ipaddr_get_iface (IPAddr *ip_addr) {
return ip_addr->iface;
}
uint8_t network_inador_ipaddr_get_family (IPAddr *ip_addr) {
return ip_addr->family;
}
uint8_t network_inador_ipaddr_get_prefix (IPAddr *ip_addr) {
return ip_addr->prefix;
}
uint8_t network_inador_ipaddr_has_local (IPAddr *ip_addr) {
return ip_addr->has_local;
}
uint8_t network_inador_ipaddr_has_brd (IPAddr *ip_addr) {
return ip_addr->has_brd;
}
uint8_t network_inador_ipaddr_get_scope (IPAddr *ip_addr) {
return ip_addr->scope;
}
uint32_t network_inador_ipaddr_get_flags (IPAddr *ip_addr) {
return ip_addr->flags;
}
void network_inador_ipaddr_get_cacheinfo (IPAddr *ip_addr, struct ifa_cacheinfo *cacheinfo) {
memcpy (cacheinfo, &ip_addr->cacheinfo, sizeof (struct ifa_cacheinfo));
}
void network_inador_ipaddr_get_addr (IPAddr *ip_addr, void *addr, int *addr_size) {
int family_size = 0;
if (ip_addr->family == AF_INET) {
family_size = sizeof (struct in_addr);
} else if (ip_addr->family == AF_INET6) {
family_size = sizeof (struct in6_addr);
}
if (addr_size != NULL) {
/* Verificar que no supere el máximo de la dirección */
if (*addr_size < family_size) {
family_size = *addr_size;
}
}
memcpy (addr, &ip_addr->addr, family_size);
if (addr_size != NULL) {
*addr_size = family_size;
}
}
void network_inador_ipaddr_get_local_addr (IPAddr *ip_addr, void *addr, int *addr_size) {
int family_size = 0;
if (ip_addr->family == AF_INET) {
family_size = sizeof (struct in_addr);
} else if (ip_addr->family == AF_INET6) {
family_size = sizeof (struct in6_addr);
}
if (addr_size != NULL) {
/* Verificar que no supere el máximo de la dirección */
if (*addr_size < family_size) {
family_size = *addr_size;
}
}
memcpy (addr, &ip_addr->local_addr, family_size);
if (addr_size != NULL) {
*addr_size = family_size;
}
}
void network_inador_ipaddr_get_brd_addr (IPAddr *ip_addr, void *addr, int *addr_size) {
int family_size = 0;
if (ip_addr->family == AF_INET) {
family_size = sizeof (struct in_addr);
} else if (ip_addr->family == AF_INET6) {
family_size = sizeof (struct in6_addr);
}
if (addr_size != NULL) {
/* Verificar que no supere el máximo de la dirección */
if (*addr_size < family_size) {
family_size = *addr_size;
}
}
memcpy (addr, &ip_addr->brd_addr, family_size);
if (addr_size != NULL) {
*addr_size = family_size;
}
}
const unsigned char *network_inador_ipaddr_get_label (IPAddr *ip_addr) {
return ip_addr->label;
}

View File

@ -1,5 +1,5 @@
/* /*
* main.c * handle.c
* This file is part of Network-inador * This file is part of Network-inador
* *
* Copyright (C) 2024 - Félix Arreola Rodríguez * Copyright (C) 2024 - Félix Arreola Rodríguez

View File

@ -34,7 +34,7 @@
#include "routes.h" #include "routes.h"
#include "ip-address.h" #include "ip-address.h"
#include "wireless_if.h" #include "wireless_if.h"
//#include "manager.h" #include "event_notify.h"
#include "network-inador-link-types.h" #include "network-inador-link-types.h"
@ -117,6 +117,7 @@ static int _interfaces_receive_message_interface (struct nl_msg *msg, void *arg,
memset (iface, 0, sizeof (Interface)); memset (iface, 0, sizeof (Interface));
iface->handle = handle; iface->handle = handle;
handle->interfaces_counter++;
handle->interfaces = f_list_append (handle->interfaces, iface); handle->interfaces = f_list_append (handle->interfaces, iface);
was_new = 1; was_new = 1;
@ -137,7 +138,7 @@ static int _interfaces_receive_message_interface (struct nl_msg *msg, void *arg,
//printf ("Interface %d agregada a la interfaz %d (bridge)\n", iface->index, iface->master_index); //printf ("Interface %d agregada a la interfaz %d (bridge)\n", iface->index, iface->master_index);
was_update = 1; was_update = 1;
//manager_send_event_interface_update (handle, iface); network_manager_trigger_interface_updated_event (handle, iface);
return NL_SKIP; return NL_SKIP;
} }
@ -286,9 +287,9 @@ static int _interfaces_receive_message_interface (struct nl_msg *msg, void *arg,
iface->link_type = interfaces_check_link_type (iface); iface->link_type = interfaces_check_link_type (iface);
//manager_send_event_interface_add (handle, iface); network_manager_trigger_interface_added_event (handle, iface);
} else if (was_update) { } else if (was_update) {
//manager_send_event_interface_update (handle, iface); network_manager_trigger_interface_updated_event (handle, iface);
} }
return NL_SKIP; return NL_SKIP;
@ -389,7 +390,7 @@ int interface_receive_message_dellink (struct nl_msg *msg, void *arg) {
//printf ("Interface %d se sacó de su bridge\n", iface->index); //printf ("Interface %d se sacó de su bridge\n", iface->index);
/* Generar EVENTO AQUI */ /* Generar EVENTO AQUI */
//manager_send_event_interface_update (handle, iface); network_manager_trigger_interface_updated_event (handle, iface);
return NL_SKIP; return NL_SKIP;
} }
@ -398,11 +399,12 @@ int interface_receive_message_dellink (struct nl_msg *msg, void *arg) {
//printf ("----- Interfaz eliminada: %s\n", iface->name); //printf ("----- Interfaz eliminada: %s\n", iface->name);
handle->interfaces = f_list_remove (handle->interfaces, iface); handle->interfaces = f_list_remove (handle->interfaces, iface);
handle->interfaces_counter--;
/* Antes de eliminar la interfaz, eliminar la lista ligada de todas las direcciones IP */ /* Antes de eliminar la interfaz, eliminar la lista ligada de todas las direcciones IP */
f_list_free_full (iface->address, free); f_list_free_full (iface->address, free);
//manager_send_event_interface_del (handle, iface->index); network_manager_trigger_interface_deleted_event (handle, iface->index);
free (iface); free (iface);
} }
@ -797,6 +799,7 @@ void interfaces_clean_up (NetworkInadorHandle *handle) {
iface->address = NULL; iface->address = NULL;
} }
handle->interfaces_counter = 0;
f_list_free_full (handle->interfaces, free); f_list_free_full (handle->interfaces, free);
handle->interfaces = NULL; handle->interfaces = NULL;
} }

View File

@ -45,7 +45,7 @@ struct inet6_data {
uint8_t i6_addr_gen_mode; uint8_t i6_addr_gen_mode;
}; };
typedef struct { typedef struct _Interface {
NetworkInadorHandle *handle; NetworkInadorHandle *handle;
uint32_t index; uint32_t index;
char name[IFNAMSIZ]; char name[IFNAMSIZ];
@ -64,7 +64,7 @@ typedef struct {
/* Banderas estilo ioctl */ /* Banderas estilo ioctl */
short flags; short flags;
int is_wireless; uint8_t is_wireless;
char wireless_protocol[IFNAMSIZ]; char wireless_protocol[IFNAMSIZ];
@ -77,6 +77,9 @@ typedef struct {
/* La lista de direcciones IP, ambas */ /* La lista de direcciones IP, ambas */
FList *address; FList *address;
/* Contador auxiliar para la lista de direcciones IP */
int address_counter;
InterfaceDHCPClientInfo dhcpc; InterfaceDHCPClientInfo dhcpc;
/* Información wireless */ /* Información wireless */

View File

@ -32,7 +32,7 @@
#include "network-inador-private.h" #include "network-inador-private.h"
#include "ip-address.h" #include "ip-address.h"
#include "interfaces.h" #include "interfaces.h"
//#include "manager.h" #include "event_notify.h"
#include "routes.h" #include "routes.h"
IPAddr *_ip_address_search_addr (Interface *iface, sa_family_t family, void *addr, uint32_t prefix, void *local_addr) { IPAddr *_ip_address_search_addr (Interface *iface, sa_family_t family, void *addr, uint32_t prefix, void *local_addr) {
@ -162,6 +162,7 @@ int ip_address_receive_message_newaddr (struct nl_msg *msg, void *arg) {
memset (ip_addr, 0, sizeof (*ip_addr)); memset (ip_addr, 0, sizeof (*ip_addr));
iface->address = f_list_append (iface->address, ip_addr); iface->address = f_list_append (iface->address, ip_addr);
iface->address_counter++;
ip_addr->family = addr_msg->ifa_family; ip_addr->family = addr_msg->ifa_family;
memcpy (&ip_addr->addr, &addr, family_size); memcpy (&ip_addr->addr, &addr, family_size);
@ -203,7 +204,7 @@ int ip_address_receive_message_newaddr (struct nl_msg *msg, void *arg) {
} }
if (was_new) { if (was_new) {
//manager_send_event_ip_add (handle, ip_addr); network_manager_trigger_ip_added_event (handle, ip_addr);
} else { } else {
/* En caso contrario, enviar una actualización de IP */ /* En caso contrario, enviar una actualización de IP */
} }
@ -286,10 +287,11 @@ int ip_address_receive_message_deladdr (struct nl_msg *msg, void *arg) {
printf ("Dirección IP - %s/%d sobre interfaz: %d, scope: %d, flags: %u\n", buffer, ip_addr->prefix, iface->index, (unsigned int) ip_addr->scope, ip_addr->flags); printf ("Dirección IP - %s/%d sobre interfaz: %d, scope: %d, flags: %u\n", buffer, ip_addr->prefix, iface->index, (unsigned int) ip_addr->scope, ip_addr->flags);
/* Eliminar de la lista ligada */ /* Eliminar de la lista ligada */
iface->address_counter--;
iface->address = f_list_remove (iface->address, ip_addr); iface->address = f_list_remove (iface->address, ip_addr);
/* Notificar del evento */ /* Notificar del evento */
//manager_send_event_ip_del (handle, ip_addr); network_manager_trigger_ip_deleted_event (handle, ip_addr);
free (ip_addr); free (ip_addr);

View File

@ -35,7 +35,7 @@
#define INFINITY_LIFE_TIME 0xFFFFFFFFU #define INFINITY_LIFE_TIME 0xFFFFFFFFU
#endif #endif
typedef struct { typedef struct _IPAddr {
sa_family_t family; sa_family_t family;
uint8_t prefix; uint8_t prefix;

View File

@ -0,0 +1,49 @@
/*
* network-inador-events.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_EVENTS_H__
#define __NETWORK_INADOR_EVENTS_H__
#include <stdint.h>
typedef struct _NetworkInadorHandle NetworkInadorHandle;
typedef struct _Interface Interface;
typedef struct _InterfaceDHCPClientInfo InterfaceDHCPClientInfo;
typedef struct _IPAddr IPAddr;
typedef void (*NetworkInadorDHCPEventCB) (NetworkInadorHandle *handle, Interface *iface, InterfaceDHCPClientInfo *dhcp_info, void *data);
typedef void (*NetworkInadorInterfaceAddEventCB) (NetworkInadorHandle *handle, Interface *iface, void *data);
typedef void (*NetworkInadorInterfaceUpdateEventCB) (NetworkInadorHandle *handle, Interface *iface, void *data);
typedef void (*NetworkInadorInterfaceDeleteEventCB) (NetworkInadorHandle *handle, uint32_t index, void *data);
typedef void (*NetworkInadorIPAddEventCB) (NetworkInadorHandle *handle, IPAddr *addr, void *data);
typedef void (*NetworkInadorIPDelEventCB) (NetworkInadorHandle *handle, IPAddr *addr, void *data);
/* Pendiente notificar rutas */
void network_manager_add_watch_dhcp (NetworkInadorHandle *handle, NetworkInadorDHCPEventCB cb, void *data);
void network_manager_add_watch_interface_added (NetworkInadorHandle *handle, NetworkInadorInterfaceAddEventCB cb, void *data);
void network_manager_add_watch_interface_updated (NetworkInadorHandle *handle, NetworkInadorInterfaceUpdateEventCB cb, void *data);
void network_manager_add_watch_interface_deleted (NetworkInadorHandle *handle, NetworkInadorInterfaceDeleteEventCB cb, void *data);
void network_manager_add_watch_ip_added (NetworkInadorHandle *handle, NetworkInadorIPAddEventCB cb, void *data);
void network_manager_add_watch_ip_deleted (NetworkInadorHandle *handle, NetworkInadorIPDelEventCB cb, void *data);
#endif /* __NETWORK_INADOR_EVENTS_H__ */

View File

@ -31,8 +31,9 @@
#include <netlink/socket.h> #include <netlink/socket.h>
#include <netlink/msg.h> #include <netlink/msg.h>
#include "network-inador.h" #include "network-inador-public.h"
#include "flist.h" #include "flist.h"
#include "network-inador-events.h"
/* Para vigilar eventos */ /* Para vigilar eventos */
typedef struct { typedef struct {
@ -40,6 +41,23 @@ typedef struct {
unsigned int source; unsigned int source;
} NetlinkEventPair; } 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 */ /* La definición principal que engloba todo */
struct _NetworkInadorHandle { struct _NetworkInadorHandle {
struct NetworkInadorOps ops; struct NetworkInadorOps ops;
@ -50,6 +68,9 @@ struct _NetworkInadorHandle {
FList *route_v6_tables; FList *route_v6_tables;
FList *route_tables_names; FList *route_tables_names;
/* Auxiliar contador de la lista ligada de interfaces */
int interfaces_counter;
/* Entradas para el resolv conf */ /* Entradas para el resolv conf */
FList *resolver_entries; FList *resolver_entries;
int resolver_inotify_fd; int resolver_inotify_fd;
@ -69,6 +90,8 @@ struct _NetworkInadorHandle {
/* El pipe de vigilancia especial de las rutas eliminadas */ /* El pipe de vigilancia especial de las rutas eliminadas */
int pipe_routes[2]; int pipe_routes[2];
unsigned int source_pipe_routes; unsigned int source_pipe_routes;
struct _NetworkInadorEventList notify_list;
}; };
#endif /* __NETWORK_INADOR_PRIVATE_H__ */ #endif /* __NETWORK_INADOR_PRIVATE_H__ */

View File

@ -30,6 +30,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <linux/if_addr.h>
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#endif #endif
@ -38,8 +40,6 @@
#define TRUE !FALSE #define TRUE !FALSE
#endif #endif
typedef struct _NetworkInadorHandle NetworkInadorHandle;
/* Función que define una lectura desde un FD */ /* Función que define una lectura desde un FD */
typedef void (*NetworkInadorInputFunc) (void *, int, int); typedef void (*NetworkInadorInputFunc) (void *, int, int);
typedef void (*NetworkInadorChildWatchFunc) (void *, pid_t, int); typedef void (*NetworkInadorChildWatchFunc) (void *, pid_t, int);
@ -56,6 +56,10 @@ struct NetworkInadorOps {
/* Ver si agregamos timers aquí */ /* Ver si agregamos timers aquí */
}; };
typedef struct _NetworkInadorHandle NetworkInadorHandle;
typedef struct _Interface Interface;
typedef struct _IPAddr IPAddr;
NetworkInadorHandle * network_inador_init_handle (struct NetworkInadorOps *network_inador_ops); NetworkInadorHandle * network_inador_init_handle (struct NetworkInadorOps *network_inador_ops);
void network_inador_destroy_handle (NetworkInadorHandle *handle); void network_inador_destroy_handle (NetworkInadorHandle *handle);
@ -72,5 +76,30 @@ int interfaces_change_name (NetworkInadorHandle *handle, int index, char * new_n
int interfaces_dhcp_client_run (NetworkInadorHandle *handle, int index, int type, uint32_t flags); int interfaces_dhcp_client_run (NetworkInadorHandle *handle, int index, int type, uint32_t flags);
int interfaces_dhcp_client_stop (NetworkInadorHandle *handle, int index); int interfaces_dhcp_client_stop (NetworkInadorHandle *handle, int index);
/* Lista de getters */
uint32_t *network_inador_list_ifaces (NetworkInadorHandle *handle);
Interface * network_inador_get_iface (NetworkInadorHandle *handle, uint32_t index);
const unsigned char *network_inador_iface_get_name (Interface *iface);
uint32_t network_inador_iface_get_index (Interface *iface);
uint32_t network_inador_iface_get_link_type (Interface *iface);
uint32_t network_inador_iface_get_master_index (Interface *iface);
uint32_t network_inador_iface_get_mtu (Interface *iface);
uint16_t network_inador_iface_get_flags (Interface *iface);
uint8_t network_inador_iface_get_is_wireless (Interface *iface);
uint8_t network_inador_iface_get_num_ips (Interface *iface);
IPAddr *network_inador_iface_get_ipaddr_by_index (Interface *iface, int index);
Interface *network_inador_ipaddr_get_iface (IPAddr *ip_addr);
uint8_t network_inador_ipaddr_get_family (IPAddr *ip_addr);
uint8_t network_inador_ipaddr_get_prefix (IPAddr *ip_addr);
uint8_t network_inador_ipaddr_has_local (IPAddr *ip_addr);
uint8_t network_inador_ipaddr_has_brd (IPAddr *ip_addr);
uint8_t network_inador_ipaddr_get_scope (IPAddr *ip_addr);
uint32_t network_inador_ipaddr_get_flags (IPAddr *ip_addr);
void network_inador_ipaddr_get_cacheinfo (IPAddr *ip_addr, struct ifa_cacheinfo *cacheinfo);
void network_inador_ipaddr_get_addr (IPAddr *ip_addr, void *addr, int *addr_size);
void network_inador_ipaddr_get_local_addr (IPAddr *ip_addr, void *addr, int *addr_size);
void network_inador_ipaddr_get_brd_addr (IPAddr *ip_addr, void *addr, int *addr_size);
const unsigned char *network_inador_ipaddr_get_label (IPAddr *ip_addr);
#endif /* __NETWORK_INADOR_H__ */ #endif /* __NETWORK_INADOR_H__ */

View File

@ -1,10 +1,11 @@
# Automake file for NetworkInador # Automake file for NetworkInador
bin_PROGRAMS = network-inador sbin_PROGRAMS = network-inador resolvconf
network_inador_SOURCES = main.c network_inador_SOURCES = main.c \
# manager.c manager.h manager.c manager-private.h \
manager-interfaces.c manager-interfaces.h \
manager-ip.c manager-ip.h
sbin_PROGRAMS = resolvconf
resolvconf_SOURCES = resolv_conf_helper.c \ resolvconf_SOURCES = resolv_conf_helper.c \
../common/flist.c ../common/flist.h \ ../common/flist.c ../common/flist.h \
../common/resolv_conf_parser.c ../common/resolv_conf_parser.h \ ../common/resolv_conf_parser.c ../common/resolv_conf_parser.h \
@ -16,7 +17,7 @@ resolvconf_LDADD =
libexec_PROGRAMS = ni-dhcp-helper libexec_PROGRAMS = ni-dhcp-helper
ni_dhcp_helper_SOURCES = ni-dhcp-iface-helper.c ni_dhcp_helper_SOURCES = ni-dhcp-iface-helper.c
ni_dhcp_helper_CPPFLAGS = $(AM_CPPFLAGS) ni_dhcp_helper_CPPFLAGS = -I$(top_srcdir)/lib $(AM_CPPFLAGS)
ni_dhcp_helper_CFLAGS = $(AM_CFLAGS) ni_dhcp_helper_CFLAGS = $(AM_CFLAGS)
#network_inador_CPPFLAGS = -DGAMEDATA_DIR=\"$(gamedatadir)/\" -DLOCALEDIR=\"$(localedir)\" $(AM_CPPFLAGS) #network_inador_CPPFLAGS = -DGAMEDATA_DIR=\"$(gamedatadir)/\" -DLOCALEDIR=\"$(localedir)\" $(AM_CPPFLAGS)

View File

@ -38,7 +38,8 @@
#include <fcntl.h> #include <fcntl.h>
#include "network-inador.h" #include "network-inador-public.h"
#include "manager-private.h"
/* Usados para salir en caso de una señal */ /* Usados para salir en caso de una señal */
static int sigterm_pipe_fds[2] = { -1, -1 }; static int sigterm_pipe_fds[2] = { -1, -1 };
@ -152,7 +153,8 @@ struct NetworkInadorOps network_ops = {
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
NetworkInadorHandle *handle; NetworkInadorHandle *handle;
GMainLoop *loop = NULL; GMainLoop *loop = NULL;
Manager *unix_socket_manager;
#if !defined(GLIB_VERSION_2_36) #if !defined(GLIB_VERSION_2_36)
g_type_init (); g_type_init ();
#endif #endif
@ -166,6 +168,8 @@ int main (int argc, char *argv[]) {
_main_setup_signal (loop); _main_setup_signal (loop);
unix_socket_manager = manager_new (handle, 0);
interfaces_dhcp_client_run (handle, 3, 1, 1); interfaces_dhcp_client_run (handle, 3, 1, 1);
/*IPAddr addr; /*IPAddr addr;
inet_pton (AF_INET, "192.19.5.6", &addr.sin_addr); inet_pton (AF_INET, "192.19.5.6", &addr.sin_addr);

View File

@ -0,0 +1,306 @@
/*
* manager-interfaces.c
* This file is part of Network-inador
*
* Copyright (C) 2025 - 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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <linux/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "manager-private.h"
#include "network-inador-public.h"
#include "network-inador-manager.h"
/* Empaquetador de datos */
int _manager_pack_interface_info (unsigned char *buffer, Interface *iface) {
const unsigned char *iface_name;
uint32_t u32; uint16_t u16; uint8_t u8;
int string_len;
iface_name = network_inador_iface_get_name (iface);
string_len = strlen (iface_name);
u32 = network_inador_iface_get_index (iface);
memcpy (&buffer[0], &u32, 4);
u32 = network_inador_iface_get_link_type (iface);
memcpy (&buffer[4], &u32, 4);
u32 = network_inador_iface_get_master_index (iface);
memcpy (&buffer[8], &u32, 4);
u32 = network_inador_iface_get_mtu (iface);
memcpy (&buffer[12], &u32, 4);
u16 = network_inador_iface_get_flags (iface);
memcpy (&buffer[16], &u16, 2);
buffer[18] = network_inador_iface_get_is_wireless (iface);
buffer[19] = string_len;
memcpy (&buffer[20], iface_name, string_len);
return 20 + string_len;
}
/* Los comandos que verdaderamente envian */
void _manager_send_interface (ManagerClientInfo *manager_client, Interface *iface, uint8_t is_event) {
unsigned char buffer[32 + IFNAMSIZ + IFNAMSIZ];
int size;
if (is_event) {
buffer[0] = NET_INADOR_TYPE_EVENT;
buffer[1] = NET_INADOR_EVENT_IFACE_ADDED;
} else {
buffer[0] = NET_INADOR_TYPE_RESPONSE;
buffer[1] = NET_INADOR_RESPONSE_IFACE;
}
size = 2 + _manager_pack_interface_info (&buffer[2], iface);
send (manager_client->fd, buffer, size, 0);
}
void _manager_send_interface_deleted (ManagerClientInfo *manager_client, uint32_t index) {
unsigned char buffer[32];
buffer[0] = NET_INADOR_TYPE_EVENT;
buffer[1] = NET_INADOR_EVENT_IFACE_REMOVED;
memcpy (&buffer[2], &index, 4);
send (manager_client->fd, buffer, 6, 0);
}
void _manager_interface_handle_list_interfaces (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
uint32_t *list_index;
int g;
Interface *iface;
list_index = network_inador_list_ifaces (manager_client->manager->handle);
/* TODO Analizar si podemos hacer todo en un solo envio incluyendo el comando de fin de listado */
if (list_index == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_UNKNOWN, NET_INADOR_COMMAND_LIST_IFACES);
return;
}
g = 0;
while (list_index[g] != 0) {
iface = network_inador_get_iface (manager_client->manager->handle, list_index[g]);
if (iface == NULL) continue;
_manager_send_interface (manager_client, iface, FALSE);
g++;
}
_manager_send_end_command (manager_client, NET_INADOR_COMMAND_LIST_IFACES);
free (list_index);
}
void _manager_interface_handle_get_interface (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
Interface *iface;
uint32_t u32;
if (buffer_len < 6) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_GET_IFACE);
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, NET_INADOR_COMMAND_GET_IFACE);
return;
}
_manager_send_interface (manager_client, iface, FALSE);
}
void _manager_interface_handle_up_down_command (ManagerClientInfo *manager_client, uint8_t is_up, unsigned char *buffer, int buffer_len) {
Interface *iface;
uint32_t u32;
int ret;
if (buffer_len < 6) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, (is_up ? NET_INADOR_COMMAND_IFACE_UP : NET_INADOR_COMMAND_IFACE_DOWN));
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, (is_up ? NET_INADOR_COMMAND_IFACE_UP : NET_INADOR_COMMAND_IFACE_DOWN));
return;
}
if (is_up) {
ret = interfaces_change_set_up (manager_client->manager->handle, u32);
} else {
ret = interfaces_change_set_down (manager_client->manager->handle, u32);
}
if (ret == 0) {
/* OK */
_manager_send_executed (manager_client);
} else {
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, (is_up ? NET_INADOR_COMMAND_IFACE_UP : NET_INADOR_COMMAND_IFACE_DOWN));
}
}
void _manager_interface_handle_change_name (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
Interface *iface;
uint32_t u32;
int ret;
int name_len;
unsigned char name[IFNAMSIZ];
if (buffer_len < 7) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
return;
}
name_len = buffer[6];
if (name_len == 0 || name_len >= IFNAMSIZ) {
_manager_send_error (manager_client, NET_INADOR_ERROR_BAD_STRING, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
return;
}
if (name_len + 7 < buffer_len) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
return;
}
memcpy (name, &buffer[7], name_len);
if (name[0] == 0) {
_manager_send_error (manager_client, NET_INADOR_ERROR_BAD_STRING, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
return;
}
name[name_len] = 0;
ret = interfaces_change_name (manager_client->manager->handle, u32, name);
if (ret == 0) {
/* OK */
_manager_send_executed (manager_client);
} else {
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, NET_INADOR_COMMAND_IFACE_CHANGE_NAME);
}
}
void _manager_interface_handle_change_mtu (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
Interface *iface;
uint32_t u32, new_mtu;
int ret;
int name_len;
unsigned char name[IFNAMSIZ];
if (buffer_len < 10) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_IFACE_CHANGE_MTU);
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, NET_INADOR_COMMAND_IFACE_CHANGE_MTU);
return;
}
memcpy (&new_mtu, &buffer[6], 4);
//new_mtu = ntohl (new_mtu);
/* TODO: Revisar el máximo de MTU que se puede poner */
ret = interfaces_change_mtu (manager_client->manager->handle, u32, new_mtu);
if (ret == 0) {
/* OK */
_manager_send_executed (manager_client);
} else {
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, NET_INADOR_COMMAND_IFACE_CHANGE_MTU);
}
}
/* Los eventos que vienen desde la librería */
void _manager_interface_added_event_cb (NetworkInadorHandle *handle, Interface *iface, void *data) {
Manager *manager = (Manager *) data;
GList *g;
ManagerClientInfo *manager_client;
printf ("___ MANAGER ___ Informando interfaz agregada: %s (%i)\n", network_inador_iface_get_name (iface), network_inador_iface_get_index (iface));
for (g = manager->connected_client_list; g != NULL; g = g->next) {
manager_client = (ManagerClientInfo *) g->data;
if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_INTERFACES) {
printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd);
_manager_send_interface (manager_client, iface, TRUE);
}
}
}
void _manager_interface_updated_event_cb (NetworkInadorHandle *handle, Interface *iface, void *data) {
Manager *manager = (Manager *) data;
GList *g;
ManagerClientInfo *manager_client;
printf ("___ MANAGER ___ Informando interfaz actualizada: %s (%i)\n", network_inador_iface_get_name (iface), network_inador_iface_get_index (iface));
for (g = manager->connected_client_list; g != NULL; g = g->next) {
manager_client = (ManagerClientInfo *) g->data;
if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_INTERFACES) {
printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd);
_manager_send_interface (manager_client, iface, TRUE);
}
}
}
void _manager_interface_deleted_event_cb (NetworkInadorHandle *handle, uint32_t index, void *data) {
Manager *manager = (Manager *) data;
GList *g;
ManagerClientInfo *manager_client;
printf ("___ MANAGER ___ Informando interfaz eliminada: %i\n", index);
for (g = manager->connected_client_list; g != NULL; g = g->next) {
manager_client = (ManagerClientInfo *) g->data;
if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_INTERFACES) {
printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd);
_manager_send_interface_deleted (manager_client, index);
}
}
}

View File

@ -0,0 +1,46 @@
/*
* manager-interfaces.h
* This file is part of Network-inador
*
* Copyright (C) 2025 - 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 __MANAGER_INTERFACES_H__
#define __MANAGER_INTERFACES_H__
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "manager-private.h"
#include "network-inador-public.h"
#include "network-inador-manager.h"
void _manager_interface_handle_list_interfaces (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
void _manager_interface_handle_get_interface (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
void _manager_interface_handle_up_down_command (ManagerClientInfo *manager_client, uint8_t is_up, unsigned char *buffer, int buffer_len);
void _manager_interface_handle_change_name (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
void _manager_interface_handle_change_mtu (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
void _manager_interface_added_event_cb (NetworkInadorHandle *handle, Interface *iface, void *data);
void _manager_interface_updated_event_cb (NetworkInadorHandle *handle, Interface *iface, void *data);
void _manager_interface_deleted_event_cb (NetworkInadorHandle *handle, uint32_t index, void *data);
#endif /* __MANAGER_INTERFACES_H__ */

318
src/manager-ip.c 100644
View File

@ -0,0 +1,318 @@
/*
* manager-ip.c
* This file is part of Network-inador
*
* Copyright (C) 2025 - 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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <linux/if.h>
#include <linux/if_addr.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "manager-private.h"
#include "network-inador-public.h"
#include "network-inador-manager.h"
int _manager_pack_ip_info (unsigned char *buffer, IPAddr *ip_addr) {
int family_size = 0;
int label_len;
int pos;
int family;
uint32_t index, flags;
Interface *iface;
int has_brd, has_local;
struct ifa_cacheinfo cacheinfo;
const char *label;
union {
struct in_addr v4;
struct in6_addr v6;
} addr;
/* Familia y máscara */
family = network_inador_ipaddr_get_family (ip_addr);
if (family == AF_INET) {
family_size = sizeof (struct in_addr);
} else if (family == AF_INET6) {
family_size = sizeof (struct in6_addr);
}
iface = network_inador_ipaddr_get_iface (ip_addr);
index = network_inador_iface_get_index (iface);
memcpy (&buffer[0], &index, 4);
buffer[4] = family;
buffer[5] = network_inador_ipaddr_get_prefix (ip_addr);
has_local = network_inador_ipaddr_has_local (ip_addr);
has_brd = network_inador_ipaddr_has_brd (ip_addr);
/* Los campos de bits */
buffer[6] = 0;
if (has_local) {
buffer[6] |= 0x01;
}
if (has_brd) {
buffer[6] |= 0x02;
}
/* Byte scope y las flags */
buffer[7] = network_inador_ipaddr_get_scope (ip_addr);
flags = network_inador_ipaddr_get_flags (ip_addr);
memcpy (&buffer[8], &flags, 4);
network_inador_ipaddr_get_cacheinfo (ip_addr, &cacheinfo);
/* La información de marcas de tiempo de las IPs */
memcpy (&buffer[12], &cacheinfo, 16);
/* La dirección principal */
network_inador_ipaddr_get_addr (ip_addr, &addr, NULL);
memcpy (&buffer[28], &addr, family_size);
pos = 28 + family_size;
if (has_local) {
network_inador_ipaddr_get_local_addr (ip_addr, &addr, NULL);
memcpy (&buffer[pos], &addr, family_size);
pos += family_size;
}
if (has_brd) {
network_inador_ipaddr_get_brd_addr (ip_addr, &addr, NULL);
memcpy (&buffer[pos], &addr, family_size);
pos += family_size;
}
label = network_inador_ipaddr_get_label (ip_addr);
if (label[0] != 0) {
label_len = strlen (label);
buffer[pos] = label_len;
pos++;
memcpy (&buffer[pos], &label, label_len);
pos += label_len;
} else {
buffer[pos] = 0;
pos++;
}
return pos;
}
/* Los comandos que verdaderamente envian */
void _manager_send_ipaddr (ManagerClientInfo *manager_client, IPAddr *ip_addr, uint8_t is_event) {
unsigned char buffer[80];
int size;
if (is_event) {
buffer[0] = NET_INADOR_TYPE_EVENT;
buffer[1] = NET_INADOR_EVENT_IPADDR_ADDED;
} else {
buffer[0] = NET_INADOR_TYPE_RESPONSE;
buffer[1] = NET_INADOR_RESPONSE_IPADDR;
}
size = 2 + _manager_pack_ip_info (&buffer[2], ip_addr);
send (manager_client->fd, buffer, size, 0);
}
void _manager_send_ipaddr_deleted (ManagerClientInfo *manager_client, IPAddr *ip_addr) {
unsigned char buffer[80];
int family_size = 0;
int pos;
int family;
uint32_t index;
Interface *iface;
int has_brd, has_local;
union {
struct in_addr v4;
struct in6_addr v6;
} addr;
buffer[0] = NET_INADOR_TYPE_EVENT;
buffer[1] = NET_INADOR_EVENT_IPADDR_REMOVED;
/* Familia y máscara */
family = network_inador_ipaddr_get_family (ip_addr);
if (family == AF_INET) {
family_size = sizeof (struct in_addr);
} else if (family == AF_INET6) {
family_size = sizeof (struct in6_addr);
}
iface = network_inador_ipaddr_get_iface (ip_addr);
index = network_inador_iface_get_index (iface);
memcpy (&buffer[2], &index, 4);
buffer[6] = family;
buffer[7] = network_inador_ipaddr_get_prefix (ip_addr);
has_local = network_inador_ipaddr_has_local (ip_addr);
buffer[8] = 0;
if (has_local) {
buffer[8] |= 0x01;
}
buffer[9] = 0;
network_inador_ipaddr_get_addr (ip_addr, &addr, NULL);
memcpy (&buffer[10], &addr, family_size);
pos = 10 + family_size;
if (has_local) {
network_inador_ipaddr_get_local_addr (ip_addr, &addr, NULL);
memcpy (&buffer[pos], &addr, family_size);
pos += family_size;
}
send (manager_client->fd, buffer, pos, 0);
}
void _manager_ip_handle_list_ips (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
Interface *iface;
int family, ip_family;
uint32_t u32;
int c, total;
IPAddr *ip_addr;
if (buffer_len < 7) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_LIST_IP);
return;
}
family = buffer[6];
if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_FAMILY, NET_INADOR_COMMAND_LIST_IP);
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, NET_INADOR_COMMAND_LIST_IP);
return;
}
total = network_inador_iface_get_num_ips (iface);
for (c = 0; c < total; c++) {
ip_addr = network_inador_iface_get_ipaddr_by_index (iface, c);
ip_family = network_inador_ipaddr_get_family (ip_addr);
if (family != AF_UNSPEC && family != ip_family) continue;
_manager_send_ipaddr (manager_client, ip_addr, FALSE);
}
_manager_send_end_command (manager_client, NET_INADOR_COMMAND_LIST_IP);
}
void _manager_ip_handle_clear_ips (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
int family, ip_family;
Interface *iface;
IPAddr *ip_addr;
uint32_t u32;
int ret;
int c, total;
if (buffer_len < 7) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_CLEAR_IP);
return;
}
family = buffer[6];
if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_FAMILY, NET_INADOR_COMMAND_CLEAR_IP);
return;
}
memcpy (&u32, &buffer[2], 4);
iface = network_inador_get_iface (manager_client->manager->handle, u32);
if (iface == NULL) {
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_IFACE_INDEX, NET_INADOR_COMMAND_CLEAR_IP);
return;
}
ret = 0;
total = network_inador_iface_get_num_ips (iface);
for (c = 0; c < total; c++) {
ip_addr = network_inador_iface_get_ipaddr_by_index (iface, c);
ip_family = network_inador_ipaddr_get_family (ip_addr);
if (family != AF_UNSPEC && family != ip_family) continue;
// AQUÍ GATUNO
//ret |= ip_address_del_ip (manager_client->manager->handle, iface->index, ip_addr);
}
if (ret == 0) {
/* OK */
_manager_send_executed (manager_client);
} else {
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, NET_INADOR_COMMAND_CLEAR_IP);
}
}
/* Los eventos que vienen desde la librería */
void _manager_ip_added_event_cb (NetworkInadorHandle *handle, IPAddr *ip_addr, void *data) {
Manager *manager = (Manager *) data;
GList *g;
ManagerClientInfo *manager_client;
Interface *iface;
iface = network_inador_ipaddr_get_iface (ip_addr);
printf ("___ MANAGER ___ Informando ip agregada: %s (%i)\n", network_inador_iface_get_name (iface), network_inador_iface_get_index (iface));
for (g = manager->connected_client_list; g != NULL; g = g->next) {
manager_client = (ManagerClientInfo *) g->data;
if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_INTERFACES) {
printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd);
_manager_send_ipaddr (manager_client, ip_addr, TRUE);
}
}
}
void _manager_ip_deleted_event_cb (NetworkInadorHandle *handle, IPAddr *ip_addr, void *data) {
Manager *manager = (Manager *) data;
GList *g;
ManagerClientInfo *manager_client;
Interface *iface;
iface = network_inador_ipaddr_get_iface (ip_addr);
printf ("___ MANAGER ___ Informando ip eliminada: %s (%i)\n", network_inador_iface_get_name (iface), network_inador_iface_get_index (iface));
for (g = manager->connected_client_list; g != NULL; g = g->next) {
manager_client = (ManagerClientInfo *) g->data;
if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_IP) {
printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd);
_manager_send_ipaddr_deleted (manager_client, ip_addr);
}
}
}

40
src/manager-ip.h 100644
View File

@ -0,0 +1,40 @@
/*
* manager-ip.h
* This file is part of Network-inador
*
* Copyright (C) 2025 - 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 __MANAGER_IP_H__
#define __MANAGER_IP_H__
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "manager-private.h"
#include "network-inador-public.h"
#include "network-inador-manager.h"
void _manager_ip_handle_list_ips (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
void _manager_ip_added_event_cb (NetworkInadorHandle *handle, IPAddr *addr, void *data);
void _manager_ip_deleted_event_cb (NetworkInadorHandle *handle, IPAddr *addr, void *data);
#endif /* __MANAGER_IP_H__ */

View File

@ -0,0 +1,55 @@
/*
* manager-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 __MANAGER_PRIVATE_H__
#define __MANAGER_PRIVATE_H__
#include <glib.h>
#include "network-inador-public.h"
/* Para los clientes y sus respectivos eventos */
typedef struct {
int socket;
guint source;
GList *connected_client_list;
NetworkInadorHandle *handle;
} Manager;
typedef struct {
int fd;
/* Los eventos que quieren ser recibidos en este cliente */
uint32_t wanted_events;
guint source;
Manager *manager;
} ManagerClientInfo;
Manager * manager_new (NetworkInadorHandle *handle, int type);
void _manager_send_error (ManagerClientInfo *manager_client, int error, int orig_cmd);
void _manager_send_executed (ManagerClientInfo *manager_client);
void _manager_send_end_command (ManagerClientInfo *manager_client, int orig_cmd);
#endif /* __MANAGER_PRIVATE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +0,0 @@
/*
* manager.h
* This file is part of Network Inador
*
* Copyright (C) 2021 - Gatuno
*
* 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 __MANAGER_H__
#define __MANAGER_H__
#include <stdint.h>
#include "common.h"
int manager_init (NetworkInadorHandle *handle);
void manager_send_event_interface_add (NetworkInadorHandle *handle, Interface *iface);
void manager_send_event_interface_del (NetworkInadorHandle *handle, uint32_t index);
void manager_send_event_interface_update (NetworkInadorHandle *handle, Interface *iface);
void manager_send_event_ip_add (NetworkInadorHandle *handle, IPAddr *ip_addr);
void manager_send_event_ip_del (NetworkInadorHandle *handle, IPAddr *ip_addr);
void manager_send_event_dhcp_change (NetworkInadorHandle *handle, InterfaceDHCPClientInfo *dhcpc);
void manager_send_event_route_add (NetworkInadorHandle *handle, Route *route);
void manager_send_event_route_del (NetworkInadorHandle *handle, Route *route);
void manager_send_event_route_update (NetworkInadorHandle *handle, Route *route);
void manager_send_event_route_table_del (NetworkInadorHandle *handle, RouteTable *rtable);
void manager_send_event_route_table_add (NetworkInadorHandle *handle, RouteTable *rtable);
#endif /* __MANAGER_H__ */

View File

@ -1,109 +0,0 @@
#ifndef __NETWOR_INADOR_MANAGER_H__
#define __NETWOR_INADOR_MANAGER_H__
enum {
NET_INADOR_TYPE_COMMAND = 1,
NET_INADOR_TYPE_RESPONSE = 2,
NET_INADOR_TYPE_RESPONSE_ERROR = 3,
NET_INADOR_TYPE_RESPONSE_LISTING_END = 4,
NET_INADOR_TYPE_EVENT = 16
};
/* Lista de eventos */
#define NET_INADOR_EVENT_MASK_INTERFACES 0x01
#define NET_INADOR_EVENT_MASK_IP 0x02
#define NET_INADOR_EVENT_MASK_DHCP_STATUS 0x04
#define NET_INADOR_EVENT_MASK_ROUTES 0x08
#define NET_INADOR_EVENT_MASK_ROUTE_TABLES 0x10
enum {
NET_INADOR_COMMAND_LIST_IFACES = 1,
NET_INADOR_COMMAND_GET_IFACE,
NET_INADOR_COMMAND_IFACE_UP,
NET_INADOR_COMMAND_IFACE_DOWN,
NET_INADOR_COMMAND_IFACE_CHANGE_NAME,
NET_INADOR_COMMAND_IFACE_CHANGE_MTU,
NET_INADOR_COMMAND_CREATE_BRIDGE = 16,
NET_INADOR_COMMAND_CLEAR_MASTER,
NET_INADOR_COMMAND_SET_MASTER,
NET_INADOR_COMMAND_LIST_IP = 32,
NET_INADOR_COMMAND_CLEAR_IP,
NET_INADOR_COMMAND_ADD_IP,
NET_INADOR_COMMAND_REMOVE_IP,
NET_INADOR_COMMAND_RUN_DHCP = 48,
NET_INADOR_COMMAND_STOP_DHCP,
NET_INADOR_COMMAND_GET_DHCP_STATUS,
NET_INADOR_COMMAND_LIST_ROUTES = 64,
NET_INADOR_COMMAND_ADD_ROUTE,
NET_INADOR_COMMAND_REMOVE_ROUTE,
NET_INADOR_COMMAND_LIST_ROUTE_TABLES = 72,
NET_INADOR_COMMAND_SET_EVENT_MASK = 192,
/* Los siguientes comandos son para uso interno */
NET_INADOR_COMMAND_DHCP_CLIENT_FEED = 224,
NET_INADOR_COMMAND_RESOLVCONF_FEED = 225,
NET_INADOR_COMMAND_RESOLVCONF_REMOVE = 226,
};
enum {
NET_INADOR_ERROR_UNKNOWN = 0,
NET_INADOR_ERROR_WRONG_COMMAND,
NET_INADOR_ERROR_INCOMPLETE_REQUEST,
NET_INADOR_ERROR_INVALID_IFACE_INDEX,
NET_INADOR_ERROR_INVALID_FAMILY,
NET_INADOR_ERROR_INVALID_VALUE,
NET_INADOR_ERROR_NOT_EXECUTED,
NET_INADOR_ERROR_BAD_STRING,
};
enum {
NET_INADOR_EVENT_IFACE_ADDED = 2,
NET_INADOR_EVENT_IPADDR_ADDED,
NET_INADOR_EVENT_IFACE_REMOVED,
NET_INADOR_EVENT_IPADDR_REMOVED,
NET_INADOR_EVENT_DHCP_STATUS = 6,
NET_INADOR_EVENT_ROUTE_ADDED = 10,
NET_INADOR_EVENT_ROUTE_REMOVED,
NET_INADOR_EVENT_ROUTE_TABLE_ADDED = 14,
NET_INADOR_EVENT_ROUTE_TABLE_REMOVED,
};
enum {
NET_INADOR_RESPONSE_EXECUTED = 1,
NET_INADOR_RESPONSE_IFACE = 2,
NET_INADOR_RESPONSE_IPADDR,
NET_INADOR_RESPONSE_DHCP_STATUS = 6,
NET_INADOR_RESPONSE_ROUTE = 10,
NET_INADOR_RESPONSE_ROUTE_TABLE = 14
};
enum {
NET_INADOR_DHCP_STATUS_SELECTING = 1,
NET_INADOR_DHCP_STATUS_BOUND,
NET_INADOR_DHCP_STATUS_RENEWED,
NET_INADOR_DHCP_STATUS_EXPIRED,
NET_INADOR_DHCP_STATUS_FAILED,
};
#endif /* __NETWOR_INADOR_MANAGER_H__ */

View File

@ -0,0 +1,76 @@
/*
* resolv_manager.c
* This file is part of Network-inador
*
* Copyright (C) 2022 - 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 <ctype.h>
#include "common.h"
#include "utils.h"
#include "resolv_conf_parser.h"
GList * resolv_manager_clear_entries (GList *entries, char *prog) {
GList *g, *next;
ResolvConfEntry *entry;
g = entries;
while (g != NULL) {
next = g->next;
entry = (ResolvConfEntry *) g->data;
if (strcmp (entry->owner_prog, prog) == 0) {
/* Hay que eliminar esta entrada, coincide por nombre de programa */
}
g = next;
}
return entries;
}
GList *resolv_manager_generate_entries (NetworkInadorHandle *handle) {
}
void resolv_manager_init (NetworkInadorHandle *handle) {
FILE *fd;
GList *entries;
/* Debemos primero instalar el manejador de eventos de escritura sobre el resolv.conf */
handle->resolver_entries = NULL;
/* Luego, leer el resolv.conf */
fd = fopen ("/etc/resolv.conf", "r");
if (fd != NULL) {
entries = resolv_manager_parse_file (fd, RESOLV_ORIGIN_RESOLVCONF);
handle->resolver_entries_from_file = entries;
}
}

View File

@ -0,0 +1,32 @@
/*
* struct_addr_union.h
* This file is part of NetworkInador
*
* Copyright (C) 2023 - Félix Arreola Rodríguez
*
* NetworkInador 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.
*
* NetworkInador 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 NetworkInador; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef __STRUCT_ADDR_UNION_H__
#define __STRUCT_ADDR_UNION_H__
typedef union {
struct in_addr v4;
struct in6_addr v6;
} struct_addr;
#endif /* __STRUCT_ADDR_UNION_H__ */