/* * main.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 */ #ifndef __NETWORK_INADOR_H__ #define __NETWORK_INADOR_H__ #include #include #include #include #include #include #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE !FALSE #endif /* Función que define una lectura desde un FD */ typedef void (*NetworkInadorInputFunc) (void *, int, int); typedef void (*NetworkInadorChildWatchFunc) (void *, pid_t, int); struct NetworkInadorOps { /* Vigilar FDs */ unsigned int (*input_add) (int fd, int cond, NetworkInadorInputFunc func, void *user_data); void (*input_remove) (unsigned int); /* Vigilar procesos */ unsigned int (*process_watch) (pid_t pid, NetworkInadorChildWatchFunc, void *user_data); void (*process_unwatch) (unsigned int); /* Ver si agregamos timers aquí */ }; typedef struct _NetworkInadorHandle NetworkInadorHandle; typedef struct _Interface Interface; typedef struct _IPAddr IPAddr; typedef struct _Route Route; typedef struct _RouteNH RouteNH; NetworkInadorHandle * network_inador_init_handle (struct NetworkInadorOps *network_inador_ops); void network_inador_destroy_handle (NetworkInadorHandle *handle); void network_inador_setup_child_handler (NetworkInadorHandle *handle); /* Funciones básicas de interfaces */ int interfaces_change_mac_address (NetworkInadorHandle *handle, int index, void *new_mac); int interfaces_change_mtu (NetworkInadorHandle *handle, int index, uint32_t new_mtu); int interfaces_change_set_up (NetworkInadorHandle *handle, int index); int interfaces_change_set_down (NetworkInadorHandle *handle, int index); int interfaces_change_name (NetworkInadorHandle *handle, int index, char * new_name); int interfaces_delete (NetworkInadorHandle *handle, int index); /* Funciones básicas de IP */ int ip_address_del_ip (NetworkInadorHandle *handle, int index, uint8_t ip_family, uint8_t ip_prefix, uint8_t ip_has_local, void *ip_addr, void *ip_local_addr); int ip_address_add_ip (NetworkInadorHandle *handle, int index, uint8_t ip_family, uint8_t ip_prefix, uint8_t ip_has_local, uint8_t ip_has_brd, uint8_t ip_scope, uint32_t ip_flags, struct ifa_cacheinfo *ip_cacheinfo, void *ip_addr, void *ip_local_addr, void *ip_brd_addr); /* Funciones de bridge */ int interfaces_bridge_create (NetworkInadorHandle *handle, const char *name); int interfaces_bridge_set_master_interface (NetworkInadorHandle *handle, int master_index, int index); int interfaces_bridge_remove_master_interface (NetworkInadorHandle *handle, int index); /* Funciones básicas de dhcp */ int interfaces_dhcp_client_run (NetworkInadorHandle *handle, int index, int type, uint32_t flags); int interfaces_dhcp_client_stop (NetworkInadorHandle *handle, int index); /* Funciones de Rutas */ int routes_add (NetworkInadorHandle *handle, uint8_t route_family, uint8_t route_prefix, uint8_t route_tos, uint32_t route_table, uint8_t route_protocol, uint8_t route_scope, uint8_t route_type, void *dest, void *prefsrc, uint32_t route_priority, void *route_nexthops); int routes_del (NetworkInadorHandle *handle, uint8_t route_family, uint8_t route_prefix, uint8_t route_tos, uint32_t route_table, uint32_t route_priority, void *dest); /* Funciones de tablas de ruteo */ /* Funciones de resolvconf */ void resolv_manager_process_resolvconf_entries (NetworkInadorHandle *handle, void *entries); void resolv_manager_clear_entries_by_prog (NetworkInadorHandle *handle, const uint32_t iface_index, const char *prog); /* Lista de getters */ uint32_t *network_inador_list_ifaces (NetworkInadorHandle *handle); Interface * network_inador_get_iface (NetworkInadorHandle *handle, uint32_t index); Interface *network_inador_get_iface_by_name (NetworkInadorHandle *handle, const char *name); 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); int network_inador_get_routes_count (NetworkInadorHandle *handle, int family); Route *network_inador_get_route_by_index (NetworkInadorHandle *handle, int family, int index); uint8_t network_inador_route_get_family (Route *route); uint8_t network_inador_route_get_type (Route *route); uint32_t network_inador_route_get_table (Route *route); uint8_t network_inador_route_get_prefix (Route *route); uint8_t network_inador_route_get_protocol (Route *route); uint8_t network_inador_route_get_tos (Route *route); uint8_t network_inador_route_get_scope (Route *route); uint8_t network_inador_route_has_prefsrc (Route *route); uint32_t network_inador_route_get_priority (Route *route); void network_inador_route_get_dest (Route *route, void *dest, int *addr_size); void network_inador_route_get_prefsrc (Route *route, void *prefsrc, int *addr_size); int network_inador_route_get_num_nexthops (Route *route); RouteNH *network_inador_route_get_nexthop_by_index (Route *route, int index); uint8_t network_inador_nexthop_has_gw (RouteNH *nexthop); void network_inador_nexthop_get_gw (RouteNH *nexthop, void *gw, int *addr_size); uint8_t network_inador_nexthop_get_flags (RouteNH *nexthop); uint8_t network_inador_nexthop_get_weight (RouteNH *nexthop); uint32_t network_inador_nexthop_get_out_index (RouteNH *nexthop); int network_inador_rtables_get_count_tables (NetworkInadorHandle *handle); void network_inador_rtables_get_table_by_index (NetworkInadorHandle *handle, uint32_t nth, uint32_t *table_index, unsigned char *table_name, size_t table_name_size); void *network_inador_route_append_nexthop (void *list, uint8_t family, void *gw, uint32_t out_iface, uint8_t weight, uint8_t flags); void network_inador_route_free_all_nexthops (void *list); void *network_inador_resolvconf_append_ns_entry (void *list, int family, void *addr, int iface_index, const char *owner_prog); void network_inador_resolvconf_free_all_entries (void *list); #endif /* __NETWORK_INADOR_H__ */