[PATCH 3/3] nslookup: query class: remove support for class HS and ANY

Henrique de Moraes Holschuh henrique at nic.br
Wed Dec 8 14:20:00 UTC 2021


Remove the support for classes HS (Hesiod) and ANY (wildcard), and with
these gone, also remove the nice, table-driven support for specifying
query classes and use an if(strcasecmp()) hardcoded tree instead.

This reduces some functionality and results in uglier code, but it does
decrease the size of the "query class" support.

NOTE: This change should not be applied if the decrease in size is not
considered worth the functionality and code quality loss.  I personally
feel it is *not* worth the 19 bytes reduction in size.

With this change:

function                                             old     new   delta
nslookup_main                                        945     955     +10
.rodata                                            95465   95468      +3
qclasses                                              32       -     -32
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/0 up/down: 13/-32)            Total: -19 bytes

It brings down the "query class" feature cost to 179 - 19 = 154 bytes.

Signed-off-by: Henrique de Moraes Holschuh <henrique at nic.br>
---
 networking/nslookup.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/networking/nslookup.c b/networking/nslookup.c
index 1cbf8becc..664ed84cc 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -270,16 +270,6 @@ struct query {
 //	unsigned char reply[512];
 };
 
-static const struct {
-	int class;
-	char name[3];
-} qclasses[] ALIGN1 = {
-	{ C_IN,    "IN"  },
-	{ C_CHAOS, "CH"  },
-	{ C_HS,    "HS"  },
-	{ C_ANY,   "ANY" },
-};
-
 static const struct {
 	unsigned char type;
 	char name[7];
@@ -949,14 +939,12 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
 			option_mask32 |= OPT_debug;
 		}
 		if (i == 5) {
-			for (i = 0;; i++) {
-				if (i >= ARRAY_SIZE(qclasses))
-					bb_error_msg_and_die("invalid query class \"%s\"", val);
-				if (strcasecmp(qclasses[i].name, val) == 0) {
-					G.query_class = qclasses[i].class;
-					break;
-				}
-			}
+			if (strcasecmp("IN", val) == 0)
+				G.query_class = C_IN;
+			else if (strcasecmp("CH", val) == 0)
+				G.query_class = C_CHAOS;
+			else
+				bb_error_msg_and_die("invalid query class \"%s\"", val);
 		}
 		if (i > 5) {
 			G.default_timeout = xatou_range(val, 1, INT_MAX / 1000);
-- 
2.20.1



More information about the busybox mailing list