Agrego comando dhcp al manager.
parent
854405b9d2
commit
969415b70c
|
@ -38,6 +38,7 @@
|
||||||
#include "dhcp.h"
|
#include "dhcp.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "routes.h"
|
||||||
|
|
||||||
#define DHCPC_PIPEOUT_HAS_IP 0x01
|
#define DHCPC_PIPEOUT_HAS_IP 0x01
|
||||||
#define DHCPC_PIPEOUT_HAS_SERVER_IP 0x02
|
#define DHCPC_PIPEOUT_HAS_SERVER_IP 0x02
|
||||||
|
@ -137,6 +138,13 @@ static void _dhcp_parse_client_packet (NetworkInadorHandle *handle, Interface *i
|
||||||
interfaces_manual_add_ipv4 (handle->netlink_sock_request, iface, &address);
|
interfaces_manual_add_ipv4 (handle->netlink_sock_request, iface, &address);
|
||||||
|
|
||||||
/* Y esperar a que se active la IP para luego configurar la ruta */
|
/* Y esperar a que se active la IP para luego configurar la ruta */
|
||||||
|
if (has_gateway) {
|
||||||
|
IPv4 default_dest;
|
||||||
|
|
||||||
|
inet_pton (AF_INET, "0.0.0.0", &default_dest.sin_addr);
|
||||||
|
default_dest.prefix = 0;
|
||||||
|
routes_manual_add_ipv4 (handle->netlink_sock_request, iface, &default_dest, route);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -275,3 +283,4 @@ void dhcp_stop_client (NetworkInadorHandle *handle, Interface *iface) {
|
||||||
kill (iface->dhcp_info.process_pid, SIGTERM);
|
kill (iface->dhcp_info.process_pid, SIGTERM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,5 +24,6 @@
|
||||||
#define __DHCP_H__
|
#define __DHCP_H__
|
||||||
|
|
||||||
void dhcp_run_client (NetworkInadorHandle *handle, Interface *iface);
|
void dhcp_run_client (NetworkInadorHandle *handle, Interface *iface);
|
||||||
|
void dhcp_stop_client (NetworkInadorHandle *handle, Interface *iface);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
#include "network-inador.h"
|
#include "network-inador.h"
|
||||||
|
#include "dhcp.h"
|
||||||
|
|
||||||
#define COMMAND_SOCKET_PATH "/tmp/network-inador.socket"
|
#define COMMAND_SOCKET_PATH "/tmp/network-inador.socket"
|
||||||
|
|
||||||
|
@ -85,7 +86,9 @@ enum {
|
||||||
|
|
||||||
MANAGER_ERROR_PREFIX_INVALID,
|
MANAGER_ERROR_PREFIX_INVALID,
|
||||||
MANAGER_ERROR_IFACE_INVALID,
|
MANAGER_ERROR_IFACE_INVALID,
|
||||||
MANAGER_ERROR_IPV4_INVALID
|
MANAGER_ERROR_IPV4_INVALID,
|
||||||
|
MANAGER_ERROR_DHCP_ALREADY_RUNNING,
|
||||||
|
MANAGER_ERROR_DHCP_NOT_RUNNING
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MANAGER_IFACE_TYPE_WIRELESS 0x02
|
#define MANAGER_IFACE_TYPE_WIRELESS 0x02
|
||||||
|
@ -398,6 +401,46 @@ static void _manager_send_list_ipv4 (NetworkInadorHandle *handle, ManagerCommand
|
||||||
_manager_send_response (request, buffer, pos);
|
_manager_send_response (request, buffer, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _manager_handle_interface_set_dhcp (NetworkInadorHandle *handle, ManagerCommandRequest *request) {
|
||||||
|
/* Primero, validar que haya suficientes bytes:
|
||||||
|
* 1 byte de la interfaz
|
||||||
|
*/
|
||||||
|
|
||||||
|
int index;
|
||||||
|
Interface *iface;
|
||||||
|
unsigned char buffer[8192];
|
||||||
|
IPv4 *ip_g;
|
||||||
|
int pos;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
if (request->command_len < 1) {
|
||||||
|
/* Bytes unsuficientes */
|
||||||
|
_manager_send_invalid_request (request, MANAGER_ERROR_INCOMPLETE_REQUEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
index = request->command_data[0];
|
||||||
|
|
||||||
|
iface = interfaces_locate_by_index (handle->interfaces, index);
|
||||||
|
|
||||||
|
if (iface == NULL) {
|
||||||
|
_manager_send_invalid_request (request, MANAGER_ERROR_IFACE_INVALID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->command == MANAGER_COMMAND_RUN_DHCP_CLIENT && iface->dhcp_info.type != IFACE_NO_DHCP_RUNNING) {
|
||||||
|
_manager_send_invalid_request (request, MANAGER_ERROR_DHCP_ALREADY_RUNNING);
|
||||||
|
} else if (request->command == MANAGER_COMMAND_STOP_DHCP_CLIENT && iface->dhcp_info.type == IFACE_NO_DHCP_RUNNING) {
|
||||||
|
_manager_send_invalid_request (request, MANAGER_ERROR_DHCP_NOT_RUNNING);
|
||||||
|
} else if (request->command == MANAGER_COMMAND_RUN_DHCP_CLIENT) {
|
||||||
|
dhcp_run_client (handle, iface);
|
||||||
|
_manager_send_processing (request);
|
||||||
|
} else if (request->command == MANAGER_COMMAND_STOP_DHCP_CLIENT) {
|
||||||
|
dhcp_stop_client (handle, iface);
|
||||||
|
_manager_send_processing (request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void _manager_send_list_routes (NetworkInadorHandle *handle, ManagerCommandRequest *request) {
|
static void _manager_send_list_routes (NetworkInadorHandle *handle, ManagerCommandRequest *request) {
|
||||||
unsigned char buffer[8192];
|
unsigned char buffer[8192];
|
||||||
Routev4 *route_g;
|
Routev4 *route_g;
|
||||||
|
@ -480,10 +523,8 @@ static gboolean _manager_client_data (GIOChannel *source, GIOCondition condition
|
||||||
_manager_handle_interface_del_ipv4 (handle, &request);
|
_manager_handle_interface_del_ipv4 (handle, &request);
|
||||||
break;
|
break;
|
||||||
case MANAGER_COMMAND_RUN_DHCP_CLIENT:
|
case MANAGER_COMMAND_RUN_DHCP_CLIENT:
|
||||||
|
|
||||||
break;
|
|
||||||
case MANAGER_COMMAND_STOP_DHCP_CLIENT:
|
case MANAGER_COMMAND_STOP_DHCP_CLIENT:
|
||||||
|
_manager_handle_interface_set_dhcp (handle, &request);
|
||||||
break;
|
break;
|
||||||
case MANAGER_COMMAND_LIST_IPV4:
|
case MANAGER_COMMAND_LIST_IPV4:
|
||||||
_manager_send_list_ipv4 (handle, &request);
|
_manager_send_list_ipv4 (handle, &request);
|
||||||
|
|
Loading…
Reference in New Issue