AVoid sending spurious Version negotiation packets
@@ -143,6 +143,11 @@ int picoquic_parse_long_packet_header(
break;
}
}
+ else {
+ DBG_PRINTF("Version is not recognized: 0x%08x\n", ph->vn);
+ ph->ptype = picoquic_packet_error;
+ ph->pc = 0;
+ }
if (ph->ptype == picoquic_packet_retry) {
/* No segment length or sequence number in retry packets */
@@ -640,8 +645,6 @@ int picoquic_incoming_version_negotiation(
{
int ret = 0;
#ifdef _WINDOWS
- UNREFERENCED_PARAMETER(bytes);
- UNREFERENCED_PARAMETER(length);
UNREFERENCED_PARAMETER(addr_from);
UNREFERENCED_PARAMETER(current_time);
#endif
@@ -709,6 +712,24 @@ int picoquic_prepare_version_negotiation(
picoquic_packet_header* ph)
{
int ret = -1;
+ picoquic_cnx_t* cnx = NULL;
+
+ /* Verify that this is not a spurious error by checking whether a connection context
+ * already exists */
+ if (ph->dest_cnx_id.id_len == quic->local_cnxid_length) {
+ if (quic->local_cnxid_length == 0) {
+ cnx = picoquic_cnx_by_net(quic, addr_from);
+ }
+ else {
+ cnx = picoquic_cnx_by_id(quic, ph->dest_cnx_id);
+ }
+ }
+ if (cnx == NULL) {
+ cnx = picoquic_cnx_by_icid(quic, &ph->dest_cnx_id, addr_from);
+ }
+
+ /* If no connection context exists, send back a version negotiation */
+ if (cnx == NULL) {
picoquic_stateless_packet_t* sp = picoquic_create_stateless_packet(quic);
if (sp != NULL) {
@@ -757,6 +778,7 @@ int picoquic_prepare_version_negotiation(
picoquic_queue_stateless_packet(quic, sp);
}
+ }
return ret;
}
