|
1 | | -/* $OpenBSD: d1_pkt.c,v 1.102 2021/07/21 07:51:12 jsing Exp $ */ |
| 1 | +/* $OpenBSD: d1_pkt.c,v 1.103 2021/07/21 08:42:14 jsing Exp $ */ |
2 | 2 | /* |
3 | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -274,34 +274,23 @@ dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue) |
274 | 274 | } |
275 | 275 |
|
276 | 276 | static int |
277 | | -dtls1_process_buffered_records(SSL *s) |
| 277 | +dtls1_process_buffered_record(SSL *s) |
278 | 278 | { |
279 | | -pitem *item; |
| 279 | +/* Check if epoch is current. */ |
| 280 | +if (D1I(s)->unprocessed_rcds.epoch != D1I(s)->r_epoch) |
| 281 | +return (0); |
280 | 282 |
|
281 | | -item = pqueue_peek(D1I(s)->unprocessed_rcds.q); |
282 | | -if (item) { |
283 | | -/* Check if epoch is current. */ |
284 | | -if (D1I(s)->unprocessed_rcds.epoch != D1I(s)->r_epoch) |
285 | | -return (1); |
286 | | -/* Nothing to do. */ |
287 | | - |
288 | | -/* Process all the records. */ |
289 | | -while (pqueue_peek(D1I(s)->unprocessed_rcds.q)) { |
290 | | -if (!dtls1_retrieve_buffered_record((s), |
291 | | - &((D1I(s))->unprocessed_rcds))) |
292 | | -return (0); |
293 | | -if (!dtls1_process_record(s)) |
294 | | -return (0); |
295 | | -if (dtls1_buffer_record(s, &(D1I(s)->processed_rcds), |
296 | | - S3I(s)->rrec.seq_num) < 0) |
297 | | -return (-1); |
298 | | -} |
| 283 | +/* Update epoch once all unprocessed records have been processed. */ |
| 284 | +if (pqueue_peek(D1I(s)->unprocessed_rcds.q) == NULL) { |
| 285 | +D1I(s)->unprocessed_rcds.epoch = D1I(s)->r_epoch + 1; |
| 286 | +return (0); |
299 | 287 | } |
300 | 288 |
|
301 | | - /* sync epoch numbers once all the unprocessed records |
302 | | - * have been processed */ |
303 | | -D1I(s)->processed_rcds.epoch = D1I(s)->r_epoch; |
304 | | -D1I(s)->unprocessed_rcds.epoch = D1I(s)->r_epoch + 1; |
| 289 | +/* Process one of the records. */ |
| 290 | +if (!dtls1_retrieve_buffered_record(s, &D1I(s)->unprocessed_rcds)) |
| 291 | +return (-1); |
| 292 | +if (!dtls1_process_record(s)) |
| 293 | +return (-1); |
305 | 294 |
|
306 | 295 | return (1); |
307 | 296 | } |
@@ -365,22 +354,15 @@ dtls1_process_record(SSL *s) |
365 | 354 | int |
366 | 355 | dtls1_get_record(SSL *s) |
367 | 356 | { |
368 | | -SSL3_RECORD_INTERNAL *rr; |
| 357 | +SSL3_RECORD_INTERNAL *rr = &(S3I(s)->rrec); |
369 | 358 | unsigned char *p = NULL; |
370 | 359 | DTLS1_BITMAP *bitmap; |
371 | 360 | unsigned int is_next_epoch; |
372 | | -int n; |
| 361 | +int ret, n; |
373 | 362 |
|
374 | | -rr = &(S3I(s)->rrec); |
375 | | - |
376 | | -/* The epoch may have changed. If so, process all the |
377 | | - * pending records. This is a non-blocking operation. */ |
378 | | -if (dtls1_process_buffered_records(s) < 0) |
379 | | -return (-1); |
380 | | - |
381 | | -/* if we're renegotiating, then there may be buffered records */ |
382 | | -if (dtls1_retrieve_buffered_record((s), &((D1I(s))->processed_rcds))) |
383 | | -return 1; |
| 363 | +/* See if there are pending records that can now be processed. */ |
| 364 | +if ((ret = dtls1_process_buffered_record(s)) != 0) |
| 365 | +return (ret); |
384 | 366 |
|
385 | 367 | /* get something from the wire */ |
386 | 368 | if (0) { |
@@ -1189,7 +1171,6 @@ dtls1_dispatch_alert(SSL *s) |
1189 | 1171 | return (i); |
1190 | 1172 | } |
1191 | 1173 |
|
1192 | | - |
1193 | 1174 | static DTLS1_BITMAP * |
1194 | 1175 | dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch) |
1195 | 1176 | { |
|
0 commit comments