Reconecto comandos de agregar y eliminar ips.
parent
38ebabf853
commit
b83407a7f3
|
@ -318,6 +318,8 @@ gboolean ni_add_ip_dialog_get_address (NIAddIPDialog *dialog, struct_addr *addr,
|
|||
*prefix = lprefix;
|
||||
}
|
||||
inet_pton (AF_INET6, ip, addr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -800,6 +800,23 @@ void ni_client_ask_ip_delete (NIClient *ni_client, NIInterface *ni_interface, NI
|
|||
send (ni_client->priv->client_socket, buffer, pos, 0);
|
||||
}
|
||||
|
||||
void ni_client_ask_ip_clear (NIClient *ni_client, NIInterface *ni_interface, int family) {
|
||||
unsigned char buffer[32];
|
||||
uint32_t index;
|
||||
|
||||
if (ni_client->priv->client_socket < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
index = ni_interface_get_index (ni_interface);
|
||||
buffer[0] = NET_INADOR_TYPE_COMMAND;
|
||||
buffer[1] = NET_INADOR_COMMAND_CLEAR_IP;
|
||||
memcpy (&buffer[2], &index, 4);
|
||||
buffer[6] = family;
|
||||
|
||||
send (ni_client->priv->client_socket, buffer, 7, 0);
|
||||
}
|
||||
|
||||
void ni_client_ask_change_iface_name (NIClient *ni_client, NIInterface *ni_interface, const gchar *new_name) {
|
||||
unsigned char buffer[128];
|
||||
uint32_t index;
|
||||
|
|
|
@ -91,6 +91,7 @@ gboolean ni_client_connect (NIClient *ni_client);
|
|||
void ni_client_ask_ip_interface (NIClient *ni_client, NIInterface *ni_interface, int family);
|
||||
void ni_client_ask_ip_new (NIClient *ni_client, NIInterface *ni_interface, int family, int prefix, struct_addr *addr, uint32_t flags, unsigned char scope, int has_local, struct_addr *local_addr, int has_brd, struct_addr *brd_addr, uint32_t *cacheinfo);
|
||||
void ni_client_ask_ip_delete (NIClient *ni_client, NIInterface *ni_interface, NIIP *ni_ip);
|
||||
void ni_client_ask_ip_clear (NIClient *ni_client, NIInterface *ni_interface, int family);
|
||||
void ni_client_ask_change_iface_name (NIClient *ni_client, NIInterface *ni_interface, const gchar *new_name);
|
||||
void ni_client_ask_change_iface_mtu (NIClient *ni_client, NIInterface *ni_interface, guint new_mtu);
|
||||
void ni_client_ask_up_down_interface (NIClient *ni_client, NIInterface *ni_interface, gboolean is_up);
|
||||
|
|
|
@ -538,10 +538,12 @@ static void ni_interface_process_ip_removed (NIInterface *ni_interface, gpointer
|
|||
GList *g;
|
||||
NIIP *ni_ip;
|
||||
|
||||
memset (&search_ip, 0, sizeof (search_ip));
|
||||
search_ip.family = buffer[6];
|
||||
search_ip.prefix = buffer[7];
|
||||
bits = buffer[8];
|
||||
|
||||
search_ip.has_local_addr = FALSE;
|
||||
if (bits & 0x01) search_ip.has_local_addr = TRUE;
|
||||
|
||||
if (search_ip.family == AF_INET) {
|
||||
|
|
|
@ -304,6 +304,20 @@ static void ni_window_interface_addr_v6_button_del_cb (GtkWidget *widget, gpoint
|
|||
ni_window_interface_addr_button_del_cb (widget, AF_INET6, data);
|
||||
}
|
||||
|
||||
static void ni_window_interface_addr_button_clear_cb (GtkWidget *widget, int family, gpointer data) {
|
||||
NIWindowInterface *window_iface = (NIWindowInterface *) data;
|
||||
|
||||
ni_client_ask_ip_clear (ni_interface_get_client (window_iface->priv->ni_interface), window_iface->priv->ni_interface, family);
|
||||
}
|
||||
|
||||
static void ni_window_interface_addr_v4_button_clear_cb (GtkWidget *widget, gpointer data) {
|
||||
ni_window_interface_addr_button_clear_cb (widget, AF_INET, data);
|
||||
}
|
||||
|
||||
static void ni_window_interface_addr_v6_button_clear_cb (GtkWidget *widget, gpointer data) {
|
||||
ni_window_interface_addr_button_clear_cb (widget, AF_INET6, data);
|
||||
}
|
||||
|
||||
/* Función para renderizar el tiempo de la IP en el arbol */
|
||||
void ni_window_interface_cell_renderer_timestamp (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) {
|
||||
NIIP *ni_ip;
|
||||
|
@ -1519,6 +1533,10 @@ static void ni_window_interface_init (NIWindowInterface *window_iface) {
|
|||
g_signal_connect (priv->del_ipv4_button, "clicked", G_CALLBACK (ni_window_interface_addr_v4_button_del_cb), window_iface);
|
||||
gtk_widget_set_sensitive (priv->del_ipv4_button, FALSE);
|
||||
|
||||
button = gtk_button_new_from_icon_name ("edit-clear-all", GTK_ICON_SIZE_LARGE_TOOLBAR);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (ni_window_interface_addr_v4_button_clear_cb), window_iface);
|
||||
|
||||
/* Conectar la señal de cambio de selección del tree view */
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_ipv4));
|
||||
g_signal_connect (selection, "changed", G_CALLBACK (has_ip_selected_v4_cb), window_iface);
|
||||
|
@ -1561,6 +1579,10 @@ static void ni_window_interface_init (NIWindowInterface *window_iface) {
|
|||
g_signal_connect (priv->del_ipv6_button, "clicked", G_CALLBACK (ni_window_interface_addr_v6_button_del_cb), window_iface);
|
||||
gtk_widget_set_sensitive (priv->del_ipv6_button, FALSE);
|
||||
|
||||
button = gtk_button_new_from_icon_name ("edit-clear-all", GTK_ICON_SIZE_LARGE_TOOLBAR);
|
||||
gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (ni_window_interface_addr_v6_button_clear_cb), window_iface);
|
||||
|
||||
/* Conectar la señal de cambio de selección del tree view */
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_ipv6));
|
||||
g_signal_connect (selection, "changed", G_CALLBACK (has_ip_selected_v6_cb), window_iface);
|
||||
|
|
|
@ -322,7 +322,7 @@ static int _ip_address_wait_error (struct sockaddr_nl *nla, struct nlmsgerr *l_e
|
|||
return NL_SKIP;
|
||||
}
|
||||
|
||||
int ip_address_add_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_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) {
|
||||
struct nl_msg * msg;
|
||||
struct ifaddrmsg addr_hdr;
|
||||
int ret, error;
|
||||
|
@ -338,10 +338,10 @@ int ip_address_add_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
addr_hdr.ifa_family = ip_addr->family;
|
||||
addr_hdr.ifa_prefixlen = ip_addr->prefix;
|
||||
addr_hdr.ifa_flags = ip_addr->flags;
|
||||
addr_hdr.ifa_scope = ip_addr->scope;
|
||||
addr_hdr.ifa_family = ip_family;
|
||||
addr_hdr.ifa_prefixlen = ip_prefix;
|
||||
addr_hdr.ifa_flags = ip_flags;
|
||||
addr_hdr.ifa_scope = ip_scope;
|
||||
addr_hdr.ifa_index = index;
|
||||
|
||||
msg = nlmsg_alloc_simple (RTM_NEWADDR, NLM_F_REQUEST);
|
||||
|
@ -353,28 +353,28 @@ int ip_address_add_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ip_addr->family == AF_INET) {
|
||||
if (ip_family == AF_INET) {
|
||||
family_size = sizeof (struct in_addr);
|
||||
} else if (ip_addr->family == AF_INET6) {
|
||||
} else if (ip_family == AF_INET6) {
|
||||
family_size = sizeof (struct in6_addr);
|
||||
}
|
||||
|
||||
ret = nla_put (msg, IFA_ADDRESS, family_size, &ip_addr->addr);
|
||||
if (ip_addr->has_local) {
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, &ip_addr->local_addr);
|
||||
ret = nla_put (msg, IFA_ADDRESS, family_size, ip_addr);
|
||||
if (ip_has_local) {
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, ip_local_addr);
|
||||
} else {
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, &ip_addr->addr);
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, ip_addr);
|
||||
}
|
||||
if (ip_addr->has_brd) {
|
||||
ret |= nla_put (msg, IFA_BROADCAST, family_size, &ip_addr->brd_addr);
|
||||
if (ip_has_brd) {
|
||||
ret |= nla_put (msg, IFA_BROADCAST, family_size, ip_brd_addr);
|
||||
}
|
||||
|
||||
/* El tiempo preferido no puede ser mayor que el tiempo válido */
|
||||
if (ip_addr->cacheinfo.ifa_prefered > ip_addr->cacheinfo.ifa_valid) {
|
||||
ip_addr->cacheinfo.ifa_prefered = ip_addr->cacheinfo.ifa_valid;
|
||||
if (ip_cacheinfo->ifa_prefered > ip_cacheinfo->ifa_valid) {
|
||||
ip_cacheinfo->ifa_prefered = ip_cacheinfo->ifa_valid;
|
||||
}
|
||||
|
||||
ret |= nla_put (msg, IFA_CACHEINFO, 16, &ip_addr->cacheinfo);
|
||||
ret |= nla_put (msg, IFA_CACHEINFO, 16, ip_cacheinfo);
|
||||
|
||||
if (ret != 0) {
|
||||
nlmsg_free (msg);
|
||||
|
@ -406,7 +406,7 @@ int ip_address_add_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ip_address_del_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr) {
|
||||
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) {
|
||||
struct nl_msg * msg;
|
||||
struct ifaddrmsg addr_hdr;
|
||||
int ret, error;
|
||||
|
@ -423,18 +423,9 @@ int ip_address_del_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
addr_pos = f_list_find (iface->address, ip_addr);
|
||||
|
||||
if (addr_pos == NULL) {
|
||||
printf ("Error, la dirección solicitada no pertenece a la interfaz\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr_hdr.ifa_family = ip_addr->family;
|
||||
addr_hdr.ifa_prefixlen = ip_addr->prefix;
|
||||
addr_hdr.ifa_flags = ip_addr->flags;
|
||||
addr_hdr.ifa_scope = ip_addr->scope;
|
||||
memset (&addr_hdr, 0, sizeof (addr_hdr));
|
||||
addr_hdr.ifa_family = ip_family;
|
||||
addr_hdr.ifa_prefixlen = ip_prefix;
|
||||
addr_hdr.ifa_index = index;
|
||||
|
||||
msg = nlmsg_alloc_simple (RTM_DELADDR, NLM_F_REQUEST);
|
||||
|
@ -446,18 +437,15 @@ int ip_address_del_ip (NetworkInadorHandle *handle, int index, IPAddr *ip_addr)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ip_addr->family == AF_INET) {
|
||||
if (ip_family == AF_INET) {
|
||||
family_size = sizeof (struct in_addr);
|
||||
} else if (ip_addr->family == AF_INET6) {
|
||||
} else if (ip_family == AF_INET6) {
|
||||
family_size = sizeof (struct in6_addr);
|
||||
}
|
||||
|
||||
ret = nla_put (msg, IFA_ADDRESS, family_size, &ip_addr->addr);
|
||||
if (ip_addr->has_local) {
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, &ip_addr->local_addr);
|
||||
}
|
||||
if (ip_addr->has_brd) {
|
||||
ret |= nla_put (msg, IFA_BROADCAST, family_size, &ip_addr->brd_addr);
|
||||
ret = nla_put (msg, IFA_ADDRESS, family_size, ip_addr);
|
||||
if (ip_has_local) {
|
||||
ret |= nla_put (msg, IFA_LOCAL, family_size, ip_local_addr);
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
|
|
|
@ -60,8 +60,8 @@ int ip_address_receive_message_newaddr (struct nl_msg *msg, void *arg);
|
|||
int ip_address_receive_message_deladdr (struct nl_msg *msg, void *arg);
|
||||
void ip_address_init (NetworkInadorHandle *handle);
|
||||
|
||||
int ip_address_add_ip (NetworkInadorHandle *handle, int index, IPAddr *addr);
|
||||
int ip_address_del_ip (NetworkInadorHandle *handle, int index, IPAddr *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);
|
||||
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);
|
||||
|
||||
IPAddr *_ip_address_search_addr (Interface *iface, sa_family_t family, void *addr, uint32_t prefix, void *local_addr);
|
||||
|
||||
|
|
|
@ -72,6 +72,10 @@ 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);
|
||||
|
||||
/* 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 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);
|
||||
|
|
|
@ -170,7 +170,7 @@ int main (int argc, char *argv[]) {
|
|||
|
||||
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;
|
||||
inet_pton (AF_INET, "192.19.5.6", &addr.sin_addr);
|
||||
addr.family = AF_INET;
|
||||
|
|
187
src/manager-ip.c
187
src/manager-ip.c
|
@ -235,6 +235,12 @@ void _manager_ip_handle_clear_ips (ManagerClientInfo *manager_client, unsigned c
|
|||
uint32_t u32;
|
||||
int ret;
|
||||
int c, total;
|
||||
uint8_t ip_prefix;
|
||||
uint8_t has_local;
|
||||
union {
|
||||
struct in_addr v4;
|
||||
struct in6_addr v6;
|
||||
} addr, local_addr;
|
||||
|
||||
if (buffer_len < 7) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_CLEAR_IP);
|
||||
|
@ -265,8 +271,19 @@ void _manager_ip_handle_clear_ips (ManagerClientInfo *manager_client, unsigned c
|
|||
|
||||
if (family != AF_UNSPEC && family != ip_family) continue;
|
||||
|
||||
ip_prefix = network_inador_ipaddr_get_prefix (ip_addr);
|
||||
|
||||
network_inador_ipaddr_get_addr (ip_addr, &addr, NULL);
|
||||
|
||||
has_local = network_inador_ipaddr_has_local (ip_addr);
|
||||
if (has_local) {
|
||||
network_inador_ipaddr_get_local_addr (ip_addr, &local_addr, NULL);
|
||||
} else {
|
||||
memcpy (&local_addr, &addr, sizeof (local_addr));
|
||||
}
|
||||
|
||||
// AQUÍ GATUNO
|
||||
//ret |= ip_address_del_ip (manager_client->manager->handle, iface->index, ip_addr);
|
||||
ret |= ip_address_del_ip (manager_client->manager->handle, u32, ip_family, ip_prefix, has_local, &addr, &local_addr);
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
|
@ -277,6 +294,174 @@ void _manager_ip_handle_clear_ips (ManagerClientInfo *manager_client, unsigned c
|
|||
}
|
||||
}
|
||||
|
||||
void _manager_ip_handle_add_ip (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
|
||||
Interface *iface;
|
||||
int ret;
|
||||
int family_size, wanted_size, family;
|
||||
uint32_t u32, ip_flags;
|
||||
uint8_t ip_prefix, ip_scope;
|
||||
uint8_t has_local, has_brd;
|
||||
struct ifa_cacheinfo ip_cacheinfo;
|
||||
union {
|
||||
struct in_addr v4;
|
||||
struct in6_addr v6;
|
||||
} addr, local_addr, brd_addr;
|
||||
|
||||
if (buffer_len < 14) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_ADD_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
family = buffer[6];
|
||||
|
||||
if (family != AF_INET && family != AF_INET6) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_FAMILY, NET_INADOR_COMMAND_ADD_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_ADD_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
ip_prefix = buffer[7];
|
||||
if (family == AF_INET && (ip_prefix > 32 || ip_prefix < 1)) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_VALUE, NET_INADOR_COMMAND_ADD_IP);
|
||||
return;
|
||||
} else if (family == AF_INET6 && (ip_prefix > 128 || ip_prefix < 1)) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_VALUE, NET_INADOR_COMMAND_ADD_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
has_local = buffer[8] & 0x01;
|
||||
has_brd = (buffer[8] & 0x02) >> 1;
|
||||
|
||||
if (family == AF_INET) {
|
||||
family_size = sizeof (struct in_addr);
|
||||
} else if (family == AF_INET6) {
|
||||
family_size = sizeof (struct in6_addr);
|
||||
}
|
||||
/* Ya puedo revisar el resto de la longitud */
|
||||
wanted_size = 22 + family_size + (family_size * has_local) + (family_size * has_brd);
|
||||
if (buffer_len < wanted_size) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_ADD_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
ip_scope = buffer[9];
|
||||
memcpy (&ip_flags, &buffer[10], 4);
|
||||
|
||||
/* Copiar los timestamp de tiempo válido y preferido */
|
||||
memset (&ip_cacheinfo, 0, sizeof (ip_cacheinfo));
|
||||
memcpy (&ip_cacheinfo, &buffer[14], 8);
|
||||
|
||||
/* Copiar las direcciones */
|
||||
memcpy (&addr, &buffer[22], family_size);
|
||||
wanted_size = 22 + family_size;
|
||||
|
||||
if (has_local) {
|
||||
memcpy (&local_addr, &buffer[wanted_size], family_size);
|
||||
wanted_size += family_size;
|
||||
} else {
|
||||
memcpy (&local_addr, &addr, family_size);
|
||||
}
|
||||
|
||||
if (has_brd) {
|
||||
memcpy (&brd_addr, &buffer[wanted_size], family_size);
|
||||
wanted_size += family_size;
|
||||
} else {
|
||||
memset (&brd_addr, 0, sizeof (brd_addr));
|
||||
}
|
||||
|
||||
ret = ip_address_add_ip (manager_client->manager->handle, u32, family, ip_prefix, has_local, has_brd, ip_scope, ip_flags, &ip_cacheinfo, &addr, &local_addr, &brd_addr);
|
||||
|
||||
if (ret == 0) {
|
||||
/* OK */
|
||||
_manager_send_executed (manager_client);
|
||||
} else {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, NET_INADOR_COMMAND_ADD_IP);
|
||||
}
|
||||
}
|
||||
|
||||
void _manager_ip_handle_del_ip (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) {
|
||||
Interface *iface;
|
||||
int ret;
|
||||
int family_size, wanted_size, family;
|
||||
uint32_t u32, ip_flags;
|
||||
uint8_t ip_prefix;
|
||||
uint8_t has_local;
|
||||
union {
|
||||
struct in_addr v4;
|
||||
struct in6_addr v6;
|
||||
} addr, local_addr;
|
||||
|
||||
if (buffer_len < 9) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_REMOVE_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
family = buffer[6];
|
||||
|
||||
if (family != AF_INET && family != AF_INET6) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_FAMILY, NET_INADOR_COMMAND_REMOVE_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_REMOVE_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
ip_prefix = buffer[7];
|
||||
if (family == AF_INET && (ip_prefix > 32 || ip_prefix < 1)) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_VALUE, NET_INADOR_COMMAND_REMOVE_IP);
|
||||
return;
|
||||
} else if (family == AF_INET6 && (ip_prefix > 128 || ip_prefix < 1)) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INVALID_VALUE, NET_INADOR_COMMAND_REMOVE_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
has_local = buffer[8] & 0x01;
|
||||
|
||||
if (family == AF_INET) {
|
||||
family_size = sizeof (struct in_addr);
|
||||
} else if (family == AF_INET6) {
|
||||
family_size = sizeof (struct in6_addr);
|
||||
}
|
||||
/* Ya puedo revisar el resto de la longitud */
|
||||
wanted_size = 9 + family_size + (family_size * has_local);
|
||||
if (buffer_len < wanted_size) {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_INCOMPLETE_REQUEST, NET_INADOR_COMMAND_REMOVE_IP);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Copiar las direcciones */
|
||||
memcpy (&addr, &buffer[9], family_size);
|
||||
wanted_size = 9 + family_size;
|
||||
|
||||
if (has_local) {
|
||||
memcpy (&local_addr, &buffer[wanted_size], family_size);
|
||||
wanted_size += family_size;
|
||||
} else {
|
||||
memcpy (&local_addr, &addr, family_size);
|
||||
}
|
||||
|
||||
ret = ip_address_del_ip (manager_client->manager->handle, u32, family, ip_prefix, has_local, &addr, &local_addr);
|
||||
|
||||
if (ret == 0) {
|
||||
/* OK */
|
||||
_manager_send_executed (manager_client);
|
||||
} else {
|
||||
_manager_send_error (manager_client, NET_INADOR_ERROR_NOT_EXECUTED, NET_INADOR_COMMAND_REMOVE_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;
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include "network-inador-manager.h"
|
||||
|
||||
void _manager_ip_handle_list_ips (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
|
||||
void _manager_ip_handle_clear_ips (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
|
||||
void _manager_ip_handle_add_ip (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len);
|
||||
void _manager_ip_handle_del_ip (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);
|
||||
|
|
|
@ -164,16 +164,15 @@ static gboolean _manager_on_client_data_recv (GIOChannel *source, GIOCondition c
|
|||
case NET_INADOR_COMMAND_LIST_IP:
|
||||
_manager_ip_handle_list_ips (manager_client, buffer, bytes);
|
||||
break;
|
||||
/*case NET_INADOR_COMMAND_CLEAR_IP:
|
||||
_manager_execute_clear_ips (manager_client, buffer, bytes);
|
||||
case NET_INADOR_COMMAND_CLEAR_IP:
|
||||
_manager_ip_handle_clear_ips (manager_client, buffer, bytes);
|
||||
break;
|
||||
case NET_INADOR_COMMAND_ADD_IP:
|
||||
_manager_execute_add_ip (manager_client, buffer, bytes);
|
||||
_manager_ip_handle_add_ip (manager_client, buffer, bytes);
|
||||
break;
|
||||
case NET_INADOR_COMMAND_REMOVE_IP:
|
||||
_manager_execute_delete_ip (manager_client, buffer, bytes);
|
||||
_manager_ip_handle_del_ip (manager_client, buffer, bytes);
|
||||
break;
|
||||
*/
|
||||
case NET_INADOR_COMMAND_SET_EVENT_MASK:
|
||||
_manager_handle_set_event_mask (manager_client, buffer, bytes);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue