** Copyright (C) 2001-2023 Zabbix SIA
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"zabbix.com/internal/agent"
var testCases = []testCase{
{1, "IPv4 match", "127.0.0.1", "127.0.0.1", false},
{2, "Second IPv4 from list matches", "127.0.0.2", "127.0.0.1,127.0.0.2", false},
{3, "Peer IP is different", "127.0.0.2", "127.0.0.1", true},
{4, "Peer IP is different", "126.0.0.1", "127.0.0.1,127.0.0.2", true},
{5, "IPv6 match", "2001:0db8:0000:0000:0000:ff00:0042:8329", "2001:0db8:0000:0000:0000:ff00:0042:8329", false},
{6, "IPv6 from list matches", "2001:0db8:0000:0000:0000:ff00:0042:8329",
"2001:0db8:0000:0000:0000:ff00:0042:8330,127.0.0.1,2001:0db8:0000:0000:0000:ff00:0042:8329", false},
{7, "Peer IPv6 is different", "2001:0db8:0000:0000:0000:ff00:0042:8330", "2001:0db8:0000:0000:0000:ff00:0042:8329", true},
{8, "Peer IPv6 is different at start", "3001:0db8:0000:0000:0000:ff00:0042:8330", "2001:0db8:0000:0000:0000:ff00:0042:8329", true},
{9, "Peer IP is not in list", "2001:0db8:0000:0000:0000:ff00:0042:8329",
"3001:0db8:0000:0000:0000:ff00:0042:8329,2101:0db8:0000:0000:0000:ff00:0042:8329,2001:0db9:0000:0000:0000:ff00:0042:8329," +
"2001:0db8:0100:0000:0000:ff00:0042:8329,2001:0db8:0000:0001:0000:ff00:0042:8329,2001:0db8:0000:0000:0000:ff10:0042:8329," +
"2001:0db8:0000:0000:0000:ff00:0043:8329", true},
{10, "IPv6 compatible peer is connected", "::127.2.0.1", "127.2.0.1", true},
{11, "IPv6 compatible expanded peer is connected", "0:0:0:0:0:0:7F00:0001", "127.0.0.1", true},
{12, "IPv6 mapped peer is connected", "::ffff:127.0.0.1", "127.0.0.1", false},
{13, "IPv6 mapped peer expanded is connected", "0:0:0:0:0:FFFF:7F00:0001", "127.0.0.1", false},
{14, "IPv6 compatible peer mismatch IP", "::127.2.0.1", "127.1.0.1", true},
{15, "IPv6 compatible expanded mismatch", "0:0:0:0:0:0:7F02:0001", "127.0.0.1", true},
{16, "IPv6 mapped peer mismatch IP", "::ffff:127.0.0.1", "127.1.0.1", true},
{17, "IPv6 mapped peer expanded mismatch IP", "0:0:0:0:0:FFFF:7F00:0001", "127.1.0.1", true},
{18, "IPv6 peer partially compatible", "::fffe:127.0.0.1", "127.0.0.1", true},
{19, "IPv6 peer does not match IPv4", "2001:0db8:0000:0000:0000:ff00:0042:8329", "127.0.0.1", true},
{20, "IPv6 compatible expanded peer is connected, not in list", "F000:0:0:0:0:0:7F00:0001", "127.0.0.1", true},
{21, "IPv6 compatible expanded peer is connected mismatch", "0000:0001:0:0:0:0:7F00:0001", "127.0.0.1", true},
{22, "IPv6 mapped expanded is connected mismatch", "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:7F00:0001", "127.0.0.1", true},
{23, "IPv6 local ip mismatch IPv4 local IP", "::1", "127.0.0.1", true},
{24, "IPv4 local IP expected, but IPv6 local IP expanded connected", "0:0:0:0:0:0:0:0001", "127.0.0.1", true},
{25, "IPv4 compatible peer is connected", "127.2.0.1", "::127.2.0.1", true},
{26, "IPv4 compatible expanded peer is connected", "127.0.0.1", "0:0:0:0:0:0:7F00:0001", true},
{27, "IPv4 mapped peer is connected", "127.0.0.1", "::ffff:127.0.0.1", false},
{28, "IPv4 mapped peer expanded is connected", "127.0.0.1", "0:0:0:0:0:FFFF:7F00:0001", false},
{29, "IPv4 compatible peer mismatch IP", "127.1.0.1", "::127.2.0.1", true},