Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net wg: Drop invalid message types on the floor faster.



details:   https://anonhg.NetBSD.org/src/rev/f8096ed04abd
branches:  trunk
changeset: 943118:f8096ed04abd
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 27 02:55:04 2020 +0000

description:
wg: Drop invalid message types on the floor faster.

Don't even let them reach the thread -- drop them in softint.

diffstat:

 sys/net/if_wg.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (51 lines):

diff -r 28b4da7ef9e2 -r f8096ed04abd sys/net/if_wg.c
--- a/sys/net/if_wg.c   Thu Aug 27 02:54:31 2020 +0000
+++ b/sys/net/if_wg.c   Thu Aug 27 02:55:04 2020 +0000
@@ -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 <ozaki.ryota%gmail.com@localhost>
@@ -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 @@
        /* 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 @@
         */
        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



Home | Main Index | Thread Index | Old Index