Source-Changes-HG archive

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

[src/trunk]: src/sys/opencrypto implement crypto_ret_q limitation. original c...



details:   https://anonhg.NetBSD.org/src/rev/e46ac7311783
branches:  trunk
changeset: 824118:e46ac7311783
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Wed May 24 09:57:36 2017 +0000

description:
implement crypto_ret_q limitation. original code is implemented by hsuenaga@IIJ.

diffstat:

 sys/opencrypto/crypto.c |  22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diffs (50 lines):

diff -r cf1eb0bfc969 -r e46ac7311783 sys/opencrypto/crypto.c
--- a/sys/opencrypto/crypto.c   Wed May 24 09:55:18 2017 +0000
+++ b/sys/opencrypto/crypto.c   Wed May 24 09:57:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crypto.c,v 1.73 2017/05/24 09:54:35 knakahara Exp $ */
+/*     $NetBSD: crypto.c,v 1.74 2017/05/24 09:57:36 knakahara Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $   */
 /*     $OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $ */
 
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.73 2017/05/24 09:54:35 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.74 2017/05/24 09:57:36 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -145,6 +145,15 @@
                crypto_##name##_len--;          \
        } while(0);
 
+#define CRYPTO_Q_INC_DROPS(name)               \
+       do {                                    \
+               crypto_##name##_drops++;        \
+       } while(0);
+
+#define CRYPTO_Q_IS_FULL(name)                                 \
+       (crypto_##name##_maxlen > 0                             \
+           && (crypto_##name##_len > crypto_##name##_maxlen))
+
 /*
  * current queue length.
  */
@@ -1217,6 +1226,15 @@
        struct cryptodesc *crd;
        struct cryptop *crp;
 
+       /*
+        * When crp_ret_q is full, we restrict here to avoid crp_ret_q overflow
+        * by error callback.
+        */
+       if (CRYPTO_Q_IS_FULL(crp_ret_q)) {
+               CRYPTO_Q_INC_DROPS(crp_ret_q);
+               return NULL;
+       }
+
        crp = pool_get(&cryptop_pool, 0);
        if (crp == NULL) {
                return NULL;



Home | Main Index | Thread Index | Old Index