timeout = 1000;
if (!tun_is_up(vpninfo)) {
- if (vpninfo->delay_tunnel)
+ if (vpninfo->delay_tunnel > 0) {
vpn_progress(vpninfo, PRG_DEBUG, _("Delaying tunnel by protocol request.\n"));
- else if (vpninfo->dtls_state == DTLS_CONNECTING) {
+ /* XX: don't let this spin forever */
+ if (--vpninfo->delay_tunnel > 0)
+ did_work++;
+ } else if (vpninfo->dtls_state == DTLS_CONNECTING) {
/* Postpone tun device creation after DTLS is connected so
* we have a better knowledge of the link MTU. We also
* force the creation if DTLS enters sleeping mode - i.e.,
#endif
int ssl_fd;
int dtls_fd;
- int delay_tunnel; /* Delay tunnel setup */
- int delay_close; /* Delay close of mainloop */
+ int delay_tunnel; /* Delay tunnel setup (2 for immediate callback, 1 for wait) */
+ int delay_close; /* Delay close of mainloop (2 for immediate callback, 1 for wait) */
int dtls_tos_current;
int dtls_pass_tos;
switch (ppp->ppp_state) {
case PPPS_DEAD:
- /* Delay tunnel setup until after PPP negotiation */
- vpninfo->delay_tunnel = 1;
-
/* Prevent race conditions after recovering dead peer connection */
vpninfo->ssl_times.last_rx = vpninfo->ssl_times.last_tx = now;
break;
ppp->ppp_state = PPPS_NETWORK;
- vpninfo->delay_tunnel = 0; /* tunnel can start now */
- vpninfo->delay_close = 2; /* need two mainloop iterations on close (send TERMREQ; receive TERMACK) */
+ vpninfo->delay_close = 2; /* we will need immediate callback (to send TERMREQ) when local side wants to close */
/* fall through */
case PPPS_NETWORK:
ppp->lcp.state |= NCP_TERM_REQ_SENT;
ppp->lcp.last_req = now;
(void) queue_config_packet(vpninfo, PPP_LCP, ++ppp->lcp.id, TERMREQ, 0, NULL);
+ vpninfo->delay_close = 1; /* need to wait until we receive TERMACK */
}
if (!ka_check_deadline(timeout, now, ppp->lcp.last_req + 3))
- vpninfo->delay_close = 1;
+ vpninfo->delay_close = 1; /* still waiting to receive TERMACK */
else
(void) queue_config_packet(vpninfo, PPP_LCP, ++ppp->lcp.id, TERMREQ, 0, NULL);
}
return -EINVAL;
}
+ /* Delay tunnel setup until after PPP negotiation */
+ vpninfo->delay_tunnel = (ppp->ppp_state == PPPS_NETWORK ? 0 : 1);
+
if (last_state != ppp->ppp_state) {
vpn_progress(vpninfo, PRG_DEBUG,
_("PPP state transition from %s to %s\n"),
#define NCP_CONF_ACK_SENT 8
#define NCP_TERM_REQ_SENT 16
#define NCP_TERM_REQ_RECEIVED 32
-#define NCP_TERM_ACK_SENT 16
-#define NCP_TERM_ACK_RECEIVED 32
+#define NCP_TERM_ACK_SENT 64
+#define NCP_TERM_ACK_RECEIVED 128
/* RFC1661 (or RFC1662 for ASYNCMAP) */
#define LCP_MRU 1