From d1fe8e1bc2f1dc887a9bedca58d5882dff3477c9 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Fri, 17 Nov 2023 19:50:51 +0000
Subject: Prepare for 2.14.0.1. Better ip6_scan().
Signed-off-by: Laurent Bercot
---
NEWS | 6 +++
doc/index.html | 2 +-
doc/license.html | 2 +-
doc/upgrade.html | 5 +++
package/info | 2 +-
src/libstddjb/ip6_scan.c | 96 +++++++++++++++++++++++++++++++++++++-----------
6 files changed, 88 insertions(+), 25 deletions(-)
diff --git a/NEWS b/NEWS
index a4a36e8..b9e080f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,11 @@
Changelog for skalibs.
+In 2.14.0.1
+-----------
+
+ - Bugfixes.
+
+
In 2.14.0.0
-----------
diff --git a/doc/index.html b/doc/index.html
index ae3e433..aa52de9 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -60,7 +60,7 @@ with a standard C development environment
Download
- - The current released version of skalibs is 2.14.0.0.
+ - The current released version of skalibs is 2.14.0.1.
- Alternatively, you can checkout a copy of the
skalibs
git repository:
diff --git a/doc/license.html b/doc/license.html
index c34533f..4d9df3d 100644
--- a/doc/license.html
+++ b/doc/license.html
@@ -74,7 +74,7 @@ color, or different text font.
I am aware that the previous restrictions sound completely
ridiculous while the official skalibs documentation is incomplete.
-As of 2.14.0.0, I'm not going to enforce those restrictions, but if you're
+As of 2.14.0.1, I'm not going to enforce those restrictions, but if you're
going to provide documentation for skalibs, don't keep it to yourself,
please send it to me instead. :-)
diff --git a/doc/upgrade.html b/doc/upgrade.html
index 8add0dc..767feda 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -16,6 +16,11 @@
skarnet.org
+ in 2.14.0.1
+
+
+ - No functional changes.
+
in 2.14.0.0
diff --git a/package/info b/package/info
index 9ed35f7..9a16833 100644
--- a/package/info
+++ b/package/info
@@ -1,4 +1,4 @@
package=skalibs
-version=2.14.0.0
+version=2.14.0.1
category=prog
package_macro_name=SKALIBS
diff --git a/src/libstddjb/ip6_scan.c b/src/libstddjb/ip6_scan.c
index b0e5b56..d2cdad6 100644
--- a/src/libstddjb/ip6_scan.c
+++ b/src/libstddjb/ip6_scan.c
@@ -1,37 +1,89 @@
/* ISC license. */
-#include
+#include
#include
#include
+
+/* IPv6 scanner
+
+class | 0 1 2 3
+st\ev | other hex : .
+
+START | m
+00 | X LIMB COLON1 X
+
+COLON1 | p
+01 | X X NEW X
+
+NEW | m
+02 | END LIMB X X
+
+LIMB | h h
+03 | END LIMB COLON V4
+
+COLON | m p
+04 | X LIMB NEW X
+
+
+END = 05
+V4 = 06
+X = 07
+
+0x10 m mark
+0x20 p set doublecolon pos
+0x40 h scan hex, next limb
+
+*/
+
size_t ip6_scan (char const *s, char *ip6)
{
- static unsigned char const class[256] = "2222222222222222222222222222222222222222222222220000000000122222200000022222222222222222222222222000000222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" ;
- static unsigned char const table[5][3] = { "\024#\005", "\024\"\005", "\024\005\006", "\005\002\005", "\024\t\016" } ;
- uint16_t tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ;
- size_t i = 0 ;
- unsigned int pos = 8, j = 0, state = 0 ;
+ static unsigned char const class[256] = "0000000000000000000000000000000000000000000000301111111111200000011111100000000000000000000000000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ;
+ static uint8_t const table[5][4] =
+ {
+ { 0x07, 0x13, 0x01, 0x07 },
+ { 0x07, 0x07, 0x22, 0x07 },
+ { 0x05, 0x13, 0x07, 0x07 },
+ { 0x45, 0x03, 0x44, 0x06 },
+ { 0x07, 0x13, 0x22, 0x07 }
+ } ;
+ size_t i = 0, mark = 0 ;
+ uint16_t limb[8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ;
+ uint8_t pos = 8, j = 0, state = 0 ;
- while (state < 5)
+ for (; state < 0x05 ; i++)
{
- unsigned char c = table[state][class[(unsigned char)s[i]] - '0'] ;
- state = c & 7 ;
- if (c & 0x20) { if (pos < 8) state = 5 ; else pos = j ; }
- if (c & 0x10)
+ uint8_t c = table[state][class[(unsigned char)s[i]] - '0'] ;
+ state = c & 0x07 ;
+ if (c & 0x10) mark = i ;
+ if (c & 0x20) { if (pos < 8) state = 0x07 ; else pos = j ; }
+ if (c & 0x40)
+ if (j >= 8 || uint16_xscan(s + mark, limb + j++) != i - mark) state = 0x07 ;
+ }
+
+ switch (state)
+ {
+ case 0x05:
+ if (pos == 8 && j < 8 || (pos < 8 && j > 6)) return 0 ;
+ i-- ;
+ break ;
+ case 0x06:
{
- if (tmp[j] & 0xf000) state = 5 ;
- else tmp[j] = (tmp[j] << 4) + fmtscan_num(s[i], 16) ;
+ uint32_t ip4 ;
+ if (pos == 8 && j != 6 || (pos < 8 && j > 4)) return 0 ;
+ i = ip4_scanu32(s + mark, &ip4) ;
+ if (!i) return 0 ;
+ limb[j++] = ip4 >> 16 ;
+ limb[j++] = ip4 & 0xffff ;
+ i += mark ;
+ break ;
}
- if (c & 0x08) if ((++j > 7) && (state < 5)) state = 5 ;
- i++ ;
+ default : return 0 ;
}
- if (((pos < 8) && (j > 6)) || ((pos == 8) && (j < 8))) state = 5 ;
- if (state == 5) return (errno = EINVAL, 0) ;
- for (state = j ; state > pos ; state--) tmp[state - j + 7] = tmp[state - 1] ;
- for (; state < pos + 8 - j ; state++) tmp[state] = 0 ;
-
- for (j = 0 ; j < 8 ; j++) uint16_pack_big(ip6 + (j<<1), tmp[j]) ;
- return i - 1 ;
+ for (state = j ; state > pos ; state--) limb[state - j + 7] = limb[state - 1] ;
+ for (; state < pos + 8 - j ; state++) limb[state] = 0 ;
+ for (j = 0 ; j < 8 ; j++) uint16_pack_big(ip6 + (j<<1), limb[j]) ;
+ return i ;
}
--
cgit v1.2.3