NPN tests.
[openssl.git] / ssl / d1_lib.c
index 8039740555f2b388168a3250a277da20e237a62d..c2867c92a2f5f72fc584c105ca83ad0236c54f94 100644 (file)
@@ -68,6 +68,7 @@
 
 static void get_current_time(struct timeval *t);
 const char dtls1_version_str[]="DTLSv1" OPENSSL_VERSION_PTEXT;
+int dtls1_listen(SSL *s, struct sockaddr *client);
 
 SSL3_ENC_METHOD DTLSv1_enc_data={
     dtls1_enc,
@@ -203,6 +204,9 @@ long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
        case DTLS_CTRL_HANDLE_TIMEOUT:
                ret = dtls1_handle_timeout(s);
                break;
+       case DTLS_CTRL_LISTEN:
+               ret = dtls1_listen(s, parg);
+               break;
 
        default:
                ret = ssl3_ctrl(s, cmd, larg, parg);
@@ -279,6 +283,16 @@ struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft)
                timeleft->tv_usec += 1000000;
                }
 
+       /* If remaining time is less than 15 ms, set it to 0
+        * to prevent issues because of small devergences with
+        * socket timeouts.
+        */
+       if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000)
+               {
+               memset(timeleft, 0, sizeof(struct timeval));
+               }
+       
+
        return timeleft;
        }
 
@@ -334,7 +348,7 @@ int dtls1_handle_timeout(SSL *s)
        if ( state->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT)
                {
                /* fail the connection, enough alerts have been sent */
-               SSLerr(SSL_F_DTLS1_READ_FAILED,SSL_R_READ_TIMEOUT_EXPIRED);
+               SSLerr(SSL_F_DTLS1_HANDLE_TIMEOUT,SSL_R_READ_TIMEOUT_EXPIRED);
                return 0;
                }
 
@@ -364,3 +378,17 @@ static void get_current_time(struct timeval *t)
        gettimeofday(t, NULL);
 #endif
 }
+
+int dtls1_listen(SSL *s, struct sockaddr *client)
+       {
+       int ret;
+
+       SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
+       s->d1->listen = 1;
+
+       ret = SSL_accept(s);
+       if (ret <= 0) return ret;
+       
+       (void) BIO_dgram_get_peer(SSL_get_rbio(s), client);
+       return 1;
+       }