NetworkInador/src/common.h

232 lines
4.7 KiB
C
Raw Normal View History

2018-08-07 15:28:22 -05:00
/*
2019-12-31 11:05:50 -06:00
* common.h
2018-08-07 15:28:22 -05:00
* This file is part of Network-inador
*
2019-12-31 11:05:50 -06:00
* Copyright (C) 2019, 2020 - Félix Arreola Rodríguez
2018-08-07 15:28:22 -05:00
*
* 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
*/
2019-12-31 11:05:50 -06:00
#ifndef __COMMON_H__
#define __COMMON_H__
2018-08-17 01:16:01 -05:00
2020-01-02 12:53:53 -06:00
#include <stdint.h>
#include <time.h>
2020-01-02 12:53:53 -06:00
#include <netinet/in.h>
#include <net/ethernet.h>
2019-12-31 11:05:50 -06:00
#include <linux/if.h>
2018-08-23 13:31:27 -05:00
#include <glib.h>
2019-12-31 11:05:50 -06:00
#include <gmodule.h>
2018-08-23 13:31:27 -05:00
2019-12-31 11:05:50 -06:00
#ifndef FALSE
#define FALSE 0
#endif
2019-12-31 11:05:50 -06:00
#ifndef TRUE
#define TRUE !FALSE
#endif
#ifndef INFINITY_LIFE_TIME
#define INFINITY_LIFE_TIME 0xFFFFFFFFU
#endif
typedef struct _NetworkInadorHandle NetworkInadorHandle;
typedef struct _NetworkInadorManager NetworkInadorManager;
2021-09-04 23:26:39 -05:00
typedef struct _Interface Interface;
typedef union {
struct in_addr v4;
struct in6_addr v6;
} struct_addr;
2020-01-02 12:53:53 -06:00
typedef struct _IPAddr {
sa_family_t family;
int prefix;
struct_addr local_addr;
struct_addr addr;
struct_addr brd_addr;
char label[256];
struct ifa_cacheinfo cacheinfo;
int is_p2p;
int has_brd;
int has_local;
uint32_t flags;
2020-01-02 12:53:53 -06:00
unsigned char scope;
2021-09-04 23:26:39 -05:00
Interface *iface;
2020-01-02 12:53:53 -06:00
} IPAddr;
#define SSID_MAX_LEN 32
typedef struct _WirelessBSS {
/** Number of counts without seeing this BSS */
unsigned int scan_miss_count;
/** Index of the last scan update */
unsigned int last_update_idx;
/** BSSID */
uint8_t bssid[ETHER_ADDR_LEN * 2 + 1];
/** HESSID */
//u8 hessid[ETHER_ADDR_LEN * 2 + 1];
/** SSID */
uint8_t ssid[SSID_MAX_LEN];
/** Length of SSID */
size_t ssid_len;
/** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
int freq;
/** Capability information field in host byte order */
uint16_t caps;
/** Timestamp of last Beacon/Probe Response frame */
uint64_t tsf;
/** Time of the last update (i.e., Beacon or Probe Response RX) */
struct timespec last_update;
} WirelessBSS;
typedef struct _WirelessInfo {
int phy;
uint32_t *freqs;
int num_freqs;
uint32_t caps;
gboolean can_scan;
gboolean can_scan_ssid;
gboolean supported;
unsigned int bss_update_idx;
GList *aps;
} WirelessInfo;
2021-12-28 23:21:31 -06:00
/* Información del proceso de DHCP */
enum {
IFACE_NO_DHCP = 0,
IFACE_ISC_DHCLIENT
};
/* FIXME: Revisar estos estados */
2021-12-28 23:21:31 -06:00
enum {
DHCP_CLIENT_SELECTING,
DHCP_CLIENT_BOUND,
DHCP_CLIENT_RENEWED,
DHCP_CLIENT_EXPIRED,
DHCP_CLIENT_FAILED,
2021-12-28 23:21:31 -06:00
DHCP_CLIENT_KILLED,
DHCP_CLIENT_EXTERNAL_RUNNING
};
#define DHCP_CLIENT_FLAG_AUTO_RESTART 0x0001
typedef struct _InterfaceDHCPClientInfo {
int type;
uint32_t flags;
int dhcp_state;
/* Para vigilar el proceso */
GPid process_pid;
guint process_watch;
/* La información obtenida desde el cliente */
struct_addr ip, gateway, broadcast;
int prefix;
struct_addr dhcp_server_ip;
/* TODO: Falta almacenar la información de DNS */
2021-12-28 23:21:31 -06:00
} InterfaceDHCPClientInfo;
2021-09-04 23:26:39 -05:00
struct _Interface {
2021-12-28 23:21:31 -06:00
NetworkInadorHandle *handle;
uint32_t index;
2018-08-07 15:28:22 -05:00
char name[IFNAMSIZ];
2021-09-04 23:26:39 -05:00
uint32_t link_type;
uint16_t arp_type;
unsigned char real_hw[ETHER_ADDR_LEN * 2 + 1];
/* Para las interfaces dentro de un bridge */
uint32_t master_index;
uint32_t mtu;
2018-08-07 15:28:22 -05:00
2019-12-31 11:05:50 -06:00
/* Para las interfaces vlan */
unsigned int vlan_parent;
/* Banderas estilo ioctl */
2018-08-07 15:28:22 -05:00
short flags;
2021-08-07 19:42:55 -05:00
int is_wireless;
2018-08-07 15:28:22 -05:00
char wireless_protocol[IFNAMSIZ];
/* Tipo */
2021-09-04 23:26:39 -05:00
char rtnl_type[IFNAMSIZ];
2018-08-07 15:28:22 -05:00
2020-01-02 12:53:53 -06:00
GList *address;
2018-08-07 15:28:22 -05:00
2021-12-28 23:21:31 -06:00
InterfaceDHCPClientInfo dhcpc;
2018-08-23 13:31:27 -05:00
/* Información wireless */
WirelessInfo *wireless;
2021-09-04 23:26:39 -05:00
};
/* Para los clientes y sus respectivos eventos */
typedef struct {
int fd;
/* Los eventos que quieren ser recibidos en este cliente */
uint32_t wanted_events;
guint source;
NetworkInadorManager *manager;
} ManagerClientInfo;
struct _NetworkInadorManager {
int socket;
guint source;
GList *connected_client_list;
NetworkInadorHandle *handle;
};
2018-08-07 15:28:22 -05:00
/* Para vigilar eventos */
typedef struct _netlink_event_pair {
struct nl_sock * nl_sock;
guint source;
} NetlinkEventPair;
2021-09-04 23:26:39 -05:00
struct _NetworkInadorHandle {
2019-12-31 11:05:50 -06:00
GList *interfaces;
//Routev4 *rtable_v4;
2018-08-17 01:16:01 -05:00
2021-09-04 23:26:39 -05:00
NetworkInadorManager *manager;
2019-12-31 11:05:50 -06:00
struct nl_sock * nl_sock_route;
struct nl_sock * nl_sock_nl80211;
NetlinkEventPair route_events;
NetlinkEventPair nl80211_scan;
NetlinkEventPair nl80211_scan_results;
2021-09-04 23:26:39 -05:00
};
2018-08-07 15:28:22 -05:00
2019-12-31 11:05:50 -06:00
#endif /* __COMMON_H__ */
2018-08-07 15:28:22 -05:00