0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

Windows core : better layer 2 exception handling:

* Handle bad DHCP netmask exception.

* Report TUN_SETUP_FAILED when exceptions thrown
  in tuncli DHCP message capture.
This commit is contained in:
James Yonan 2016-04-10 00:39:10 -06:00
parent 7a435b6dfe
commit 82f82534ee
2 changed files with 46 additions and 20 deletions

View File

@ -66,6 +66,7 @@ namespace openvpn {
/* get host IP address/netmask */
const IPv4::Addr host = IPv4::Addr::from_uint32_net(dhcp->dhcp.yiaddr);
const IPv4::Addr netmask = get_netmask(dhcp, optlen);
const int prefix_len = netmask.prefix_len_nothrow();
/* get the router IP address while padding out all DHCP router options */
const IPv4::Addr router = extract_router(dhcp, optlen);
@ -94,6 +95,11 @@ namespace openvpn {
OPENVPN_LOG("NOTE: failed to obtain netmask via DHCP");
complete = false;
}
if (prefix_len < 0)
{
OPENVPN_LOG("NOTE: bad netmask obtained via DHCP: " << netmask);
complete = false;
}
if (router.unspecified())
{
OPENVPN_LOG("NOTE: failed to obtain router via DHCP");
@ -102,7 +108,7 @@ namespace openvpn {
if (complete)
{
reset();
props->tun_builder_add_address(host.to_string(), netmask.prefix_len(), router.to_string(), false, false);
props->tun_builder_add_address(host.to_string(), prefix_len, router.to_string(), false, false);
if (dns_servers.empty())
OPENVPN_LOG("NOTE: failed to obtain DNS servers via DHCP");
else

View File

@ -293,11 +293,8 @@ namespace openvpn {
{
if (impl)
{
if (dhcp_capture && dhcp_capture->mod_reply(buf))
{
OPENVPN_LOG("DHCP PROPS:" << std::endl << dhcp_capture->get_props().to_string());
layer_2_schedule_timer(1);
}
if (dhcp_capture)
dhcp_inspect(buf);
return impl->write(buf);
}
else
@ -357,6 +354,22 @@ namespace openvpn {
Util::tap_process_logging(h);
}
void dhcp_inspect(Buffer& buf)
{
try {
if (dhcp_capture->mod_reply(buf))
{
OPENVPN_LOG("DHCP PROPS:" << std::endl << dhcp_capture->get_props().to_string());
layer_2_schedule_timer(1);
}
}
catch (const std::exception& e)
{
stop();
parent.tun_error(Error::TUN_SETUP_FAILED, std::string("L2 exception: ") + e.what());
}
}
void layer_2_schedule_timer(const unsigned int seconds)
{
l2_timer.expires_at(Time::now() + Time::Duration::seconds(seconds));
@ -371,21 +384,28 @@ namespace openvpn {
// for layer 2 DHCP handshake to complete.
void layer_2_timer_callback()
{
if (dhcp_capture && tun_setup)
try {
if (dhcp_capture && tun_setup)
{
if (tun_setup->l2_ready(dhcp_capture->get_props()))
{
std::ostringstream os;
tun_setup->l2_finish(dhcp_capture->get_props(), config->stop, os);
OPENVPN_LOG_STRING(os.str());
parent.tun_connected();
dhcp_capture.reset();
}
else
{
OPENVPN_LOG("L2: Waiting for DHCP handshake...");
layer_2_schedule_timer(1);
}
}
}
catch (const std::exception& e)
{
if (tun_setup->l2_ready(dhcp_capture->get_props()))
{
std::ostringstream os;
tun_setup->l2_finish(dhcp_capture->get_props(), config->stop, os);
OPENVPN_LOG_STRING(os.str());
parent.tun_connected();
dhcp_capture.reset();
}
else
{
OPENVPN_LOG("L2: Waiting for DHCP handshake...");
layer_2_schedule_timer(1);
}
stop();
parent.tun_error(Error::TUN_SETUP_FAILED, std::string("L2 exception: ") + e.what());
}
}