From 1333bbcf819c80c18644c8fc88463af7562f8bce Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 31 Jul 2018 11:46:38 +0100 Subject: [PATCH] [Feature] Implement parsing of scoped IPv6 addresses --- src/libutil/addr.c | 7 ++++++- test/lua/unit/addr.lua | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index ce97e486c..a6f1adaf8 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -493,7 +493,7 @@ gboolean rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, gpointer target) { guchar t, *zero = NULL, *s, *d, *addr = target; - const guchar *p, *digit = NULL; + const guchar *p, *digit = NULL, *percent; gsize len4 = 0; guint n = 8, nibbles = 0, word = 0; @@ -513,6 +513,11 @@ rspamd_parse_inet_address_ip6 (const guchar *text, gsize len, gpointer target) p = text; } + /* Check IPv6 scope */ + if ((percent = memchr (p, '%', len)) != NULL && percent > p) { + len = percent - p; /* Ignore scope */ + } + for (/* void */; len; len--) { t = *p++; diff --git a/test/lua/unit/addr.lua b/test/lua/unit/addr.lua index 6ec058c3f..03ceb2dbd 100644 --- a/test/lua/unit/addr.lua +++ b/test/lua/unit/addr.lua @@ -2,7 +2,7 @@ context("Inet addr check functions", function() local ffi = require("ffi") - + ffi.cdef[[ typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; bool rspamd_parse_inet_address (rspamd_inet_addr_t **target, @@ -16,6 +16,8 @@ context("Inet addr check functions", function() {'256.1.1.1', false}, {'/tmp/socket', true}, {'./socket', true}, + {'[fe80::f919:8b26:ff93:3092%5]', true}, + {'[fe80::f919:8b26:ff93:3092]', true}, } for i,c in ipairs(cases) do -- 2.39.5