Agrego tipo bridge y vlan a interfaces.
parent
56e9f4b67d
commit
5e57e34de4
|
@ -44,7 +44,7 @@
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
|
|
||||||
Interface * interfaces_locate_by_index (Interface *list, int index);
|
Interface * interfaces_locate_by_index (Interface *list, int index);
|
||||||
static void _interfaces_append_ipv4_to_struct (Interface *interface, struct in_addr address, uint32_t prefix);
|
static IPv4 * _interfaces_append_ipv4_to_struct (Interface *interface, struct in_addr address, uint32_t prefix);
|
||||||
|
|
||||||
int global_nl_seq = 1;
|
int global_nl_seq = 1;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ Interface * interfaces_locate_by_index (Interface *list, int index) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _interfaces_append_ipv4_to_struct (Interface *interface, struct in_addr address, uint32_t prefix) {
|
static IPv4 * _interfaces_append_ipv4_to_struct (Interface *interface, struct in_addr address, uint32_t prefix) {
|
||||||
IPv4 *new_addr, *last;
|
IPv4 *new_addr, *last;
|
||||||
|
|
||||||
new_addr = (IPv4 *) malloc (sizeof (IPv4));
|
new_addr = (IPv4 *) malloc (sizeof (IPv4));
|
||||||
|
@ -95,6 +95,8 @@ static void _interfaces_append_ipv4_to_struct (Interface *interface, struct in_a
|
||||||
|
|
||||||
last->next = new_addr;
|
last->next = new_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IPv4 * _interfaces_serach_ipv4 (Interface *interface, struct in_addr address, uint32_t prefix) {
|
static IPv4 * _interfaces_serach_ipv4 (Interface *interface, struct in_addr address, uint32_t prefix) {
|
||||||
|
@ -191,12 +193,12 @@ void interfaces_add_or_update_rtnl_link (NetworkInadorHandle *handle, struct nlm
|
||||||
iface = NLMSG_DATA(h);
|
iface = NLMSG_DATA(h);
|
||||||
len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
|
len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
|
||||||
|
|
||||||
printf ("Mensaje de nueva interfaz: %i\n", iface->ifi_index);
|
//printf ("Mensaje de nueva interfaz: %i\n", iface->ifi_index);
|
||||||
new = interfaces_locate_by_index (handle->interfaces, iface->ifi_index);
|
new = interfaces_locate_by_index (handle->interfaces, iface->ifi_index);
|
||||||
|
|
||||||
/* Si el objeto interface no existe, crearlo y ligarlo en la lista de interfaces */
|
/* Si el objeto interface no existe, crearlo y ligarlo en la lista de interfaces */
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
printf ("Creando...\n");
|
//printf ("Creando...\n");
|
||||||
new = malloc (sizeof (Interface));
|
new = malloc (sizeof (Interface));
|
||||||
memset (new, 0, sizeof (Interface));
|
memset (new, 0, sizeof (Interface));
|
||||||
new->next = NULL;
|
new->next = NULL;
|
||||||
|
@ -260,13 +262,13 @@ void interfaces_add_or_update_rtnl_link (NetworkInadorHandle *handle, struct nlm
|
||||||
case IFLA_MASTER:
|
case IFLA_MASTER:
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
memcpy (&new->master_index, RTA_DATA (attribute), 4);
|
memcpy (&new->master_index, RTA_DATA (attribute), 4);
|
||||||
printf ("Interface %d has master: %i\n", iface->ifi_index, new->master_index);
|
//printf ("Interface %d has master: %i\n", iface->ifi_index, new->master_index);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IFLA_MTU:
|
case IFLA_MTU:
|
||||||
memcpy (&new->mtu, RTA_DATA (attribute), attribute->rta_len);
|
memcpy (&new->mtu, RTA_DATA (attribute), attribute->rta_len);
|
||||||
|
|
||||||
printf ("Interface %d has mtu: %u\n", iface->ifi_index, new->mtu);
|
//printf ("Interface %d has mtu: %u\n", iface->ifi_index, new->mtu);
|
||||||
break;
|
break;
|
||||||
case IFLA_OPERSTATE:
|
case IFLA_OPERSTATE:
|
||||||
{
|
{
|
||||||
|
@ -274,7 +276,7 @@ void interfaces_add_or_update_rtnl_link (NetworkInadorHandle *handle, struct nlm
|
||||||
memcpy (&operstate, RTA_DATA (attribute), sizeof (operstate));
|
memcpy (&operstate, RTA_DATA (attribute), sizeof (operstate));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IFLA_AF_SPEC:
|
/*case IFLA_AF_SPEC:
|
||||||
{
|
{
|
||||||
struct rtattr * sub_attr;
|
struct rtattr * sub_attr;
|
||||||
int sub_len;
|
int sub_len;
|
||||||
|
@ -297,7 +299,7 @@ void interfaces_add_or_update_rtnl_link (NetworkInadorHandle *handle, struct nlm
|
||||||
sub_attr = (struct rtattr *) (((char *) sub_attr) + RTA_ALIGN (nla_len));
|
sub_attr = (struct rtattr *) (((char *) sub_attr) + RTA_ALIGN (nla_len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;*/
|
||||||
case IFLA_LINKINFO:
|
case IFLA_LINKINFO:
|
||||||
{
|
{
|
||||||
struct rtattr * nest_attr;
|
struct rtattr * nest_attr;
|
||||||
|
@ -311,38 +313,22 @@ void interfaces_add_or_update_rtnl_link (NetworkInadorHandle *handle, struct nlm
|
||||||
sub_len = nest_attr->rta_len;
|
sub_len = nest_attr->rta_len;
|
||||||
|
|
||||||
if (sub_len > nest_size) {
|
if (sub_len > nest_size) {
|
||||||
printf ("Los sub atributos se acabaron prematuramente\n");
|
//printf ("Los sub atributos se acabaron prematuramente\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf ("Interface %d, IFLA_LINKINFO, sub attributo type: %i\n", iface->ifi_index, nest_attr->rta_type);
|
//printf ("Interface %d, IFLA_LINKINFO, sub attributo type: %i\n", iface->ifi_index, nest_attr->rta_type);
|
||||||
|
|
||||||
if (nest_attr->rta_type == IFLA_INFO_KIND) {
|
if (nest_attr->rta_type == IFLA_INFO_KIND) {
|
||||||
printf ("IFLA_INFO_KIND: %s\n", RTA_DATA (nest_attr));
|
printf ("IFLA_INFO_KIND: %s\n", RTA_DATA (nest_attr));
|
||||||
} else if (nest_attr->rta_type == IFLA_INFO_DATA) {
|
if (strcmp (RTA_DATA (nest_attr), "vlan") == 0) {
|
||||||
printf ("Segunda anidación: IFLA_INFO_DATA: size: %d\n", nest_attr->rta_len);
|
new->is_vlan = 1;
|
||||||
struct rtattr *nest2_attr;
|
} else if (strcmp (RTA_DATA (nest_attr), "nlmon") == 0) {
|
||||||
int nest2_size;
|
new->is_nlmon = 1;
|
||||||
int sub2_len;
|
} else if (strcmp (RTA_DATA (nest_attr), "bridge") == 0) {
|
||||||
|
new->is_bridge = 1;
|
||||||
nest2_size = nest_attr->rta_len;
|
|
||||||
nest2_attr = RTA_DATA (nest_attr);
|
|
||||||
|
|
||||||
while (nest2_size > sizeof (nest2_attr)) {
|
|
||||||
sub2_len = nest2_attr->rta_len;
|
|
||||||
printf ("------ Nest2_attr->rta_len = %d. El tamaño es: %d\n", sub2_len, nest2_size);
|
|
||||||
if (sub2_len > nest2_size) {
|
|
||||||
printf ("Los sub atributos se acabaron prematuramente\n");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
printf ("Interface %d, IFLA_INFO_DATA, sub attributo type: %i, size: %d\n", iface->ifi_index, nest2_attr->rta_type, nest2_attr->rta_len);
|
|
||||||
|
|
||||||
//if (
|
|
||||||
|
|
||||||
nest2_size -= RTA_ALIGN (sub2_len);
|
|
||||||
nest2_attr = (struct rtattr *) (((char *) nest2_attr) + RTA_ALIGN (sub2_len));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
nest_size -= RTA_ALIGN (sub_len);
|
nest_size -= RTA_ALIGN (sub_len);
|
||||||
nest_attr = (struct rtattr *) (((char *) nest_attr) + RTA_ALIGN (sub_len));
|
nest_attr = (struct rtattr *) (((char *) nest_attr) + RTA_ALIGN (sub_len));
|
||||||
}
|
}
|
||||||
|
@ -462,8 +448,11 @@ void interfaces_add_or_update_ipv4 (NetworkInadorHandle *handle, struct nlmsghdr
|
||||||
|
|
||||||
if (new == NULL) {
|
if (new == NULL) {
|
||||||
printf ("Agregando IP a la lista de IP's\n");
|
printf ("Agregando IP a la lista de IP's\n");
|
||||||
_interfaces_append_ipv4_to_struct (iface, ip, prefix);
|
new = _interfaces_append_ipv4_to_struct (iface, ip, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new->flags = addr->ifa_flags;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void interfaces_del_ipv4 (NetworkInadorHandle *handle, struct nlmsghdr *h) {
|
void interfaces_del_ipv4 (NetworkInadorHandle *handle, struct nlmsghdr *h) {
|
||||||
|
|
|
@ -56,9 +56,11 @@ enum {
|
||||||
MANAGER_RESPONSE_LIST_ROUTES,
|
MANAGER_RESPONSE_LIST_ROUTES,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MANAGER_IFACE_TYPE_WIRELESS 2
|
#define MANAGER_IFACE_TYPE_WIRELESS 0x02
|
||||||
#define MANAGER_IFACE_TYPE_BRIDGE 4
|
#define MANAGER_IFACE_TYPE_BRIDGE 0x04
|
||||||
#define MANAGER_IFACE_TYPE_LOOPBACK 8
|
#define MANAGER_IFACE_TYPE_LOOPBACK 0x8
|
||||||
|
#define MANAGER_IFACE_TYPE_VLAN 0x10
|
||||||
|
#define MANAGER_IFACE_TYPE_NLMON 0x20
|
||||||
|
|
||||||
static void _manager_send_invalid_request (int sock, struct sockaddr_un *client, socklen_t socklen, int seq) {
|
static void _manager_send_invalid_request (int sock, struct sockaddr_un *client, socklen_t socklen, int seq) {
|
||||||
unsigned char buffer[128];
|
unsigned char buffer[128];
|
||||||
|
@ -106,6 +108,14 @@ static void _manager_send_list_interfaces (NetworkInadorHandle *handle, int sock
|
||||||
flags |= MANAGER_IFACE_TYPE_BRIDGE;
|
flags |= MANAGER_IFACE_TYPE_BRIDGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iface_g->is_vlan) {
|
||||||
|
flags |= MANAGER_IFACE_TYPE_VLAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iface_g->is_nlmon) {
|
||||||
|
flags |= MANAGER_IFACE_TYPE_NLMON;
|
||||||
|
}
|
||||||
|
|
||||||
buffer[pos + 1] = flags;
|
buffer[pos + 1] = flags;
|
||||||
|
|
||||||
/* Copiar la mac address */
|
/* Copiar la mac address */
|
||||||
|
|
|
@ -33,26 +33,33 @@ typedef struct _IPv4 {
|
||||||
struct in_addr sin_addr;
|
struct in_addr sin_addr;
|
||||||
uint32_t prefix;
|
uint32_t prefix;
|
||||||
|
|
||||||
|
unsigned char flags;
|
||||||
|
|
||||||
struct _IPv4 *next;
|
struct _IPv4 *next;
|
||||||
} IPv4;
|
} IPv4;
|
||||||
|
|
||||||
typedef struct _Interface {
|
typedef struct _Interface {
|
||||||
char name[IFNAMSIZ];
|
char name[IFNAMSIZ];
|
||||||
int ifi_type;
|
int ifi_type;
|
||||||
char real_hw[ETHER_ADDR_LEN * 2 + 1];
|
unsigned char real_hw[ETHER_ADDR_LEN * 2 + 1];
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
|
|
||||||
|
/* Para las interfaces dentro de un bridge */
|
||||||
unsigned int master_index;
|
unsigned int master_index;
|
||||||
|
|
||||||
unsigned int mtu;
|
unsigned int mtu;
|
||||||
|
|
||||||
|
/* Banderas estilo ioctl */
|
||||||
short flags;
|
short flags;
|
||||||
|
|
||||||
char wireless_protocol[IFNAMSIZ];
|
char wireless_protocol[IFNAMSIZ];
|
||||||
|
|
||||||
|
/* Tipo */
|
||||||
int is_loopback;
|
int is_loopback;
|
||||||
int is_wireless;
|
int is_wireless;
|
||||||
int is_bridge;
|
int is_bridge;
|
||||||
int is_vlan;
|
int is_vlan;
|
||||||
|
int is_nlmon;
|
||||||
|
|
||||||
IPv4 *v4_address;
|
IPv4 *v4_address;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue