Module Name:    src
Committed By:   riastradh
Date:           Mon Jul 29 19:46:25 UTC 2024

Modified Files:
        src/sys/net: if_wg.c

Log Message:
wg(4): Queue packet for post-handshake retransmit if limits are hit.

PR kern/58521: experimental wg(4) may drop packet after minutes of quiet


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/net/if_wg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_wg.c
diff -u src/sys/net/if_wg.c:1.126 src/sys/net/if_wg.c:1.127
--- src/sys/net/if_wg.c:1.126	Mon Jul 29 19:45:56 2024
+++ src/sys/net/if_wg.c	Mon Jul 29 19:46:25 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wg.c,v 1.126 2024/07/29 19:45:56 riastradh Exp $	*/
+/*	$NetBSD: if_wg.c,v 1.127 2024/07/29 19:46:25 riastradh Exp $	*/
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ry...@gmail.com>
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.126 2024/07/29 19:45:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.127 2024/07/29 19:46:25 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq_enabled.h"
@@ -3734,8 +3734,20 @@ wgintr(void *cookie)
 		}
 		if (__predict_false(wg_session_hit_limits(wgs))) {
 			WG_TRACE("stable session hit limits");
-			atomic_store_relaxed(&wgs->wgs_force_rekey, true);
-			wg_schedule_peer_task(wgp, WGP_TASK_SEND_INIT_MESSAGE);
+			membar_release();
+			if ((m = atomic_swap_ptr(&wgp->wgp_pending, m)) ==
+			    NULL) {
+				WG_TRACE("queued first packet in a while;"
+				    " reinit handshake");
+				atomic_store_relaxed(&wgs->wgs_force_rekey,
+				    true);
+				wg_schedule_peer_task(wgp,
+				    WGP_TASK_SEND_INIT_MESSAGE);
+			} else {
+				membar_acquire();
+				WG_TRACE("first packet in already queued,"
+				    " dropping");
+			}
 			goto next1;
 		}
 		wg_send_data_msg(wgp, wgs, m);

Reply via email to