From owner-svn-src-all@freebsd.org Mon Sep 9 16:32:24 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C8D61D77CD; Mon, 9 Sep 2019 16:32:24 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46Rtx44qJnz4CQK; Mon, 9 Sep 2019 16:32:24 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 87A0E18715; Mon, 9 Sep 2019 16:32:24 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x89GWOXd046171; Mon, 9 Sep 2019 16:32:24 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x89GWOhK045835; Mon, 9 Sep 2019 16:32:24 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201909091632.x89GWOhK045835@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Mon, 9 Sep 2019 16:32:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352075 - head/sys/ddb X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/ddb X-SVN-Commit-Revision: 352075 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Sep 2019 16:32:24 -0000 Author: cem Date: Mon Sep 9 16:32:23 2019 New Revision: 352075 URL: https://svnweb.freebsd.org/changeset/base/352075 Log: ddb(4): Add some support for lexing IPv6 addresses Allow commands to specify that (hex) numbers may start with A-F, by adding the DRT_HEX flag for db_read_token_flags(). As before, numbers containing invalid digits for the current radix are rejected. Also, lex ':' and '::' tokens as tCOLON and tCOLONCOLON respectively. There is a mild conflict here with lexed "identifiers" (tIDENT): ddb identifiers may contain arbitrary colons, and the ddb lexer is greedy. So the identifier lex will swallow any colons it finds inside identifiers, and consumers are still unable to expect the token sequence 'tIDENT tCOLON'. That limitation does not matter for IPv6 addresses, because the lexer always attempts to lex numbers before identifiers. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D21509 Modified: head/sys/ddb/db_lex.c head/sys/ddb/db_lex.h Modified: head/sys/ddb/db_lex.c ============================================================================== --- head/sys/ddb/db_lex.c Mon Sep 9 16:31:14 2019 (r352074) +++ head/sys/ddb/db_lex.c Mon Sep 9 16:32:23 2019 (r352075) @@ -163,7 +163,7 @@ static int db_lex(int flags) { int c, n, radix_mode; - bool lex_wspace; + bool lex_wspace, lex_hex_numbers; switch (flags & DRT_RADIX_MASK) { case DRT_DEFAULT_RADIX: @@ -181,6 +181,7 @@ db_lex(int flags) } lex_wspace = ((flags & DRT_WSPACE) != 0); + lex_hex_numbers = ((flags & DRT_HEX) != 0); c = db_read_char(); for (n = 0; c <= ' ' || c > '~'; n++) { @@ -193,13 +194,16 @@ db_lex(int flags) return (tWSPACE); } - if (c >= '0' && c <= '9') { + if ((c >= '0' && c <= '9') || + (lex_hex_numbers && + ((c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')))) { /* number */ int r, digit = 0; if (radix_mode != -1) r = radix_mode; - else if (c > '0') + else if (c != '0') r = db_radix; else { c = db_read_char(); @@ -328,6 +332,12 @@ db_lex(int flags) } db_unread_char(c); return (tEXCL); + case ':': + c = db_read_char(); + if (c == ':') + return (tCOLONCOLON); + db_unread_char(c); + return (tCOLON); case ';': return (tSEMI); case '&': Modified: head/sys/ddb/db_lex.h ============================================================================== --- head/sys/ddb/db_lex.h Mon Sep 9 16:31:14 2019 (r352074) +++ head/sys/ddb/db_lex.h Mon Sep 9 16:32:23 2019 (r352075) @@ -58,17 +58,26 @@ enum { /* * Flag bit powers of two for db_read_token_flags. * The low 2 bits are reserved for radix selection. + * + * WSPACE: Yield explicit tWSPACE tokens when one or more whitespace characters + * is consumed. + * HEX: Allow tNUMBER tokens to start with 'A'-'F' without explicit "0x" + * prefix. */ enum { _DRT_WSPACE = 2, + _DRT_HEX, }; #ifndef BIT #define BIT(n) (1ull << (n)) #endif enum { DRT_WSPACE = BIT(_DRT_WSPACE), + DRT_HEX = BIT(_DRT_HEX), }; -#define DRT_VALID_FLAGS_MASK ((int)DRT_RADIX_MASK | DRT_WSPACE) +#define DRT_VALID_FLAGS_MASK ((int)DRT_RADIX_MASK | \ + DRT_WSPACE | \ + DRT_HEX) void db_flush_lex(void); char *db_get_line(void); @@ -123,5 +132,7 @@ extern char db_tok_string[TOK_STRING_SIZE]; #define tQUESTION 33 #define tBIT_NOT 34 #define tWSPACE 35 +#define tCOLON 36 +#define tCOLONCOLON 37 #endif /* !_DDB_DB_LEX_H_ */