Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/iscsi Replace build option to enable hex encoded big...



details:   https://anonhg.NetBSD.org/src/rev/965b537d5011
branches:  trunk
changeset: 450648:965b537d5011
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Apr 21 11:26:46 2019 +0000

description:
Replace build option to enable hex encoded bignum parameters with a sysctl.

diffstat:

 sys/dev/iscsi/iscsi_globals.h |   3 ++-
 sys/dev/iscsi/iscsi_main.c    |  11 +++++++++--
 sys/dev/iscsi/iscsi_text.c    |  39 ++++++++++++++++++---------------------
 3 files changed, 29 insertions(+), 24 deletions(-)

diffs (141 lines):

diff -r c3c9e5dc52b5 -r 965b537d5011 sys/dev/iscsi/iscsi_globals.h
--- a/sys/dev/iscsi/iscsi_globals.h     Sun Apr 21 11:02:32 2019 +0000
+++ b/sys/dev/iscsi/iscsi_globals.h     Sun Apr 21 11:26:46 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_globals.h,v 1.23 2017/12/03 19:07:10 christos Exp $      */
+/*     $NetBSD: iscsi_globals.h,v 1.24 2019/04/21 11:26:46 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -532,6 +532,7 @@
 #ifdef ISCSI_DEBUG
 
 extern int iscsi_debug_level;  /* How much debug info to display */
+extern bool iscsi_hex_bignums; /* Wether to encode parameters in hex or base64 */
 
 #define DEBOUT(x) printf x
 #define DEB(lev,x) { if (iscsi_debug_level >= lev) printf x ;}
diff -r c3c9e5dc52b5 -r 965b537d5011 sys/dev/iscsi/iscsi_main.c
--- a/sys/dev/iscsi/iscsi_main.c        Sun Apr 21 11:02:32 2019 +0000
+++ b/sys/dev/iscsi/iscsi_main.c        Sun Apr 21 11:26:46 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_main.c,v 1.28 2019/04/11 11:40:58 kamil Exp $    */
+/*     $NetBSD: iscsi_main.c,v 1.29 2019/04/21 11:26:46 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -47,6 +47,7 @@
 #if defined(ISCSI_DEBUG)
 int iscsi_debug_level = ISCSI_DEBUG;
 #endif
+bool iscsi_hex_bignums = false;
 
 bool iscsi_detaching;
 
@@ -383,7 +384,7 @@
        chan->chan_channel = 0;
        chan->chan_flags = SCSIPI_CHAN_NOSETTLE | SCSIPI_CHAN_CANGROW;
        chan->chan_ntargets = 1;
-       chan->chan_nluns = 16;          /* ToDo: ??? */
+       chan->chan_nluns = 16;
        chan->chan_id = sess->s_id;
 
        sess->s_child_dev = config_found(dev, chan, scsiprint);
@@ -618,6 +619,12 @@
                SYSCTL_DESCR("iscsi controls"),
                NULL, 0, NULL, 0,
                CTL_HW, CTL_CREATE, CTL_EOL);
+       sysctl_createv(clog, 0, &node, NULL,
+               CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+               CTLTYPE_BOOL, "hexbignums",
+               SYSCTL_DESCR("encode parameters in hex"),
+               NULL, 0,  &iscsi_hex_bignums, 0,
+               CTL_CREATE, CTL_EOL);
 
 #ifdef ISCSI_DEBUG
        sysctl_createv(clog, 0, &node, NULL,
diff -r c3c9e5dc52b5 -r 965b537d5011 sys/dev/iscsi/iscsi_text.c
--- a/sys/dev/iscsi/iscsi_text.c        Sun Apr 21 11:02:32 2019 +0000
+++ b/sys/dev/iscsi/iscsi_text.c        Sun Apr 21 11:26:46 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsi_text.c,v 1.11 2017/12/03 19:07:10 christos Exp $ */
+/*     $NetBSD: iscsi_text.c,v 1.12 2019/04/21 11:26:46 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -34,9 +34,6 @@
 #include <sys/md5.h>
 #include <sys/cprng.h>
 
-/* define to send T_BIGNUM in hex format instead of base64 */
-/* #define ISCSI_HEXBIGNUMS */
-
 #define isdigit(x) ((x) >= '0' && (x) <= '9')
 #define toupper(x) ((x) & ~0x20)
 
@@ -175,6 +172,7 @@
 {
        text_key_t key;                         /* the key */
        int list_num;                           /* number of elements in list, doubles as */
+       bool hex_bignums;                       /* wether to encode in hex or base64 */
        /* data size for large numeric values */
        union
        {
@@ -633,22 +631,21 @@
 STATIC unsigned
 put_bignumval(negotiation_parameter_t *par, uint8_t *buf)
 {
-#ifdef ISCSI_HEXBIGNUMS
        int k, c;
 
-       my_strcpy(buf, "0x");
-       for (k=0; k<par->list_num; ++k) {
-               c = par->val.sval[k] >> 4;
-               buf[2+2*k] = c < 10 ? '0' + c : 'a' + (c-10);
-               c = par->val.sval[k] & 0xf;
-               buf[2+2*k+1] = c < 10 ? '0' + c : 'a' + (c-10);
+       if (par->hex_bignums) {
+               my_strcpy(buf, "0x");
+               for (k=0; k<par->list_num; ++k) {
+                       c = par->val.sval[k] >> 4;
+                       buf[2+2*k] = c < 10 ? '0' + c : 'a' + (c-10);
+                       c = par->val.sval[k] & 0xf;
+                       buf[2+2*k+1] = c < 10 ? '0' + c : 'a' + (c-10);
+               }
+               buf[2+2*k] = '\0';
+
+               return 2+2*par->list_num;
        }
-       buf[2+2*k] = '\0';
-
-       return 2+2*par->list_num;
-#else
        return base64_encode(par->val.sval, par->list_num, buf);
-#endif
 }
 
 /*
@@ -829,11 +826,10 @@
 
                case T_BIGNUM:
                        /* list_num holds value size */
-#ifdef ISCSI_HEXBIGNUMS
-                       size += 2 + 2*par->list_num;
-#else
-                       size += base64_enclen(par->list_num);
-#endif
+                       if (par->hex_bignums)
+                               size += 2 + 2*par->list_num;
+                       else
+                               size += base64_enclen(par->list_num);
                        i = par->list_num;
                        break;
 
@@ -1002,6 +998,7 @@
        par->key = key;
        par->list_num = 1;
        par->val.sval = val;
+       par->hex_bignums = iscsi_hex_bignums;
        state->num_pars++;
        state->kflags[key] |= NS_SENT;
 



Home | Main Index | Thread Index | Old Index