Module Name: src
Committed By: riastradh
Date: Thu Aug 27 02:55:05 UTC 2020
Modified Files:
src/sys/net: if_wg.c
Log Message:
wg: Drop invalid message types on the floor faster.
Don't even let them reach the thread -- drop them in softint.
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/sys/net/if_wg.c:1.28
--- src/sys/net/if_wg.c:1.27 Thu Aug 27 02:54:31 2020
+++ src/sys/net/if_wg.c Thu Aug 27 02:55:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $ */
+/* $NetBSD: if_wg.c,v 1.28 2020/08/27 02:55:04 riastradh Exp $ */
/*
* Copyright (C) Ryota Ozaki <[email protected]>
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.27 2020/08/27 02:54:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.28 2020/08/27 02:55:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -2934,6 +2934,7 @@ wg_overudp_cb(struct mbuf **mp, int offs
/* Verify the mbuf chain is long enough to have a wg msg header. */
KASSERT(offset <= m_length(m));
if (__predict_false(m_length(m) - offset < sizeof(struct wg_msg))) {
+ /* drop on the floor */
m_freem(m);
return -1;
}
@@ -2952,15 +2953,21 @@ wg_overudp_cb(struct mbuf **mp, int offs
*/
switch (wgm.wgm_type) {
case WG_MSG_TYPE_DATA:
+ /* handle immediately */
m_adj(m, offset);
wg_handle_msg_data(wg, m, src);
*mp = NULL;
return 1;
+ case WG_MSG_TYPE_INIT:
+ case WG_MSG_TYPE_RESP:
+ case WG_MSG_TYPE_COOKIE:
+ /* pass through to so_receive in wg_receive_packets */
+ return 0;
default:
- break;
+ /* drop on the floor */
+ m_freem(m);
+ return -1;
}
-
- return 0;
}
static int