Commit e8683384 authored by Jan Včelák's avatar Jan Včelák 🚀 Committed by Daniel Salzman

sockaddr: move netblock/range matching from ACL code

parent 9457a37f
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
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
......@@ -23,6 +23,7 @@
#include "libknot/errcode.h"
#include "contrib/sockaddr.h"
#include "contrib/openbsd/strlcpy.h"
#include "contrib/macros.h"
int sockaddr_len(const struct sockaddr *ss)
{
......@@ -259,3 +260,49 @@ bool sockaddr_is_any(const struct sockaddr_storage *ss)
return false;
}
bool sockaddr_net_match(const struct sockaddr_storage *ss1,
const struct sockaddr_storage *ss2,
unsigned prefix)
{
if (ss1 == NULL || ss2 == NULL) {
return false;
}
if (ss1->ss_family != ss2->ss_family) {
return false;
}
size_t raw_len = 0;
const uint8_t *raw_1 = sockaddr_raw(ss1, &raw_len);
const uint8_t *raw_2 = sockaddr_raw(ss2, &raw_len);
prefix = MIN(prefix, raw_len * 8);
unsigned bytes = prefix / 8;
unsigned bits = prefix % 8;
/* Compare full bytes. */
if (memcmp(raw_1, raw_2, bytes) != 0) {
return false;
}
/* Compare last partial byte. */
return bits == 0 ||
(raw_1[bytes] >> (8 - bits) == raw_2[bytes] >> (8 - bits));
}
bool sockaddr_range_match(const struct sockaddr_storage *ss,
const struct sockaddr_storage *ss_min,
const struct sockaddr_storage *ss_max)
{
if (ss == NULL || ss_min == NULL || ss_max == NULL) {
return false;
}
if (ss_min->ss_family != ss_max->ss_family ||
ss_min->ss_family != ss->ss_family) {
return false;
}
return sockaddr_cmp(ss, ss_min) >= 0 && sockaddr_cmp(ss, ss_max) <= 0;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
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
......@@ -138,4 +138,30 @@ char *sockaddr_hostname(void);
*/
bool sockaddr_is_any(const struct sockaddr_storage *ss);
/*!
* \brief Check if two addresses match the given network prefix.
*
* \param ss1 First address.
* \param ss2 Second address.
* \param prefix Prefix length.
*
* \retval True if match.
*/
bool sockaddr_net_match(const struct sockaddr_storage *ss1,
const struct sockaddr_storage *ss2,
unsigned prefix);
/*!
* \brief Check if the address is within the given address range (inclusive).
*
* \param ss Address to check.
* \param ss_min Minimum address.
* \param ss_max Maximum address.
*
* \retval True if match.
*/
bool sockaddr_range_match(const struct sockaddr_storage *ss,
const struct sockaddr_storage *ss_min,
const struct sockaddr_storage *ss_max);
/*! @} */
......@@ -339,11 +339,11 @@ static int template_match(int state, synth_template_t *tpl, knot_pkt_t *pkt, str
return state;
}
if (tpl->addr_max.ss_family == AF_UNSPEC) {
if (!netblock_match(&query_addr, &tpl->addr, tpl->mask)) {
if (!sockaddr_net_match(&query_addr, &tpl->addr, tpl->mask)) {
return state; /* Out of our netblock, not applicable. */
}
} else {
if (!netrange_match(&query_addr, &tpl->addr, &tpl->addr_max)) {
if (!sockaddr_range_match(&query_addr, &tpl->addr, &tpl->addr_max)) {
return state; /* Out of our netblock, not applicable. */
}
}
......
......@@ -19,84 +19,6 @@
#include "knot/updates/acl.h"
#include "contrib/sockaddr.h"
static const uint8_t* ipv4_addr(const struct sockaddr_storage *ss) {
struct sockaddr_in *ipv4 = (struct sockaddr_in *)ss;
return (uint8_t *)&ipv4->sin_addr.s_addr;
}
static const uint8_t* ipv6_addr(const struct sockaddr_storage *ss) {
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)ss;
return (uint8_t *)&ipv6->sin6_addr.s6_addr;
}
bool netblock_match(const struct sockaddr_storage *ss1,
const struct sockaddr_storage *ss2,
int prefix)
{
if (ss1 == NULL || ss2 == NULL) {
return false;
}
if (ss1->ss_family != ss2->ss_family) {
return false;
}
const uint8_t *addr1, *addr2;
switch (ss1->ss_family) {
case AF_INET:
addr1 = ipv4_addr(ss1);
addr2 = ipv4_addr(ss2);
if (prefix < 0 || prefix > IPV4_PREFIXLEN) {
prefix = IPV4_PREFIXLEN;
}
break;
case AF_INET6:
addr1 = ipv6_addr(ss1);
addr2 = ipv6_addr(ss2);
if (prefix < 0 || prefix > IPV6_PREFIXLEN) {
prefix = IPV6_PREFIXLEN;
}
break;
default:
return false;
}
/* Compare full bytes address block. */
uint8_t full_bytes = prefix / 8;
if (memcmp(addr1, addr2, full_bytes) != 0) {
return false;
}
/* Compare last partial byte address block. */
uint8_t rest_bits = prefix % 8;
if (rest_bits > 0) {
uint8_t rest1 = addr1[full_bytes] >> (8 - rest_bits);
uint8_t rest2 = addr2[full_bytes] >> (8 - rest_bits);
if (rest1 != rest2) {
return false;
}
}
return true;
}
bool netrange_match(const struct sockaddr_storage *ss,
const struct sockaddr_storage *ss_min,
const struct sockaddr_storage *ss_max)
{
if (ss == NULL || ss_min == NULL || ss_max == NULL) {
return false;
}
assert(ss_min->ss_family == ss_max->ss_family);
if (sockaddr_cmp(ss, ss_min) < 0 || sockaddr_cmp(ss, ss_max) > 0) {
return false;
}
return true;
}
bool acl_allowed(conf_t *conf, conf_val_t *acl, acl_action_t action,
const struct sockaddr_storage *addr,
knot_tsig_key_t *tsig)
......
......@@ -38,33 +38,6 @@ typedef enum {
ACL_ACTION_UPDATE = 3
} acl_action_t;
/*!
* \brief Checks if two netblocks match.
*
* \param ss1 First address.
* \param ss2 Second address.
* \param prefix Netblock length (negative value for maximum prefix length).
*
* \retval bool if match.
*/
bool netblock_match(const struct sockaddr_storage *ss1,
const struct sockaddr_storage *ss2,
int prefix);
/*!
* \brief Checks if the address is within the network range.
*
* \param ss Address to check.
* \param ss_min Minimum address.
* \param ss_max Maximum address.
*
* \retval bool if match.
*/
bool netrange_match(const struct sockaddr_storage *ss,
const struct sockaddr_storage *ss_min,
const struct sockaddr_storage *ss_max
);
/*!
* \brief Checks if the address and/or tsig key matches given ACL list.
*
......
......@@ -229,7 +229,7 @@ int static preferred_master(conf_t *conf, zone_t *zone, conf_remote_t *master)
for (size_t i = 0; i < addr_count; i++) {
conf_remote_t remote = conf_remote(conf, &masters, i);
if (netblock_match(&remote.addr, zone->preferred_master, -1)) {
if (sockaddr_net_match(&remote.addr, zone->preferred_master, -1)) {
*master = remote;
pthread_mutex_unlock(&zone->preferred_lock);
return KNOT_EOK;
......@@ -273,7 +273,7 @@ int zone_master_try(conf_t *conf, zone_t *zone, zone_master_cb callback,
for (size_t i = 0; i < addr_count; i++) {
conf_remote_t master = conf_remote(conf, &masters, i);
if (preferred.addr.ss_family != AF_UNSPEC &&
netblock_match(&master.addr, &preferred.addr, -1)) {
sockaddr_net_match(&master.addr, &preferred.addr, -1)) {
preferred.addr.ss_family = AF_UNSPEC;
continue;
}
......
......@@ -23,178 +23,18 @@
#include "knot/updates/acl.h"
#include "contrib/sockaddr.h"
#define ZONE "example.zone"
#define KEY1 "key1_md5"
#define KEY2 "key2_md5"
#define KEY3 "key3_sha256"
static void check_sockaddr_set(struct sockaddr_storage *ss, int family,
const char *straddr, int port)
{
int ret = sockaddr_set(ss, family, straddr, port);
ok(ret == KNOT_EOK, "set address '%s'", straddr);
}
static void test_netblock_match(void)
{
int ret;
struct sockaddr_storage t = { 0 };
// 127 dec ~ 01111111 bin
// 170 dec ~ 10101010 bin
struct sockaddr_storage ref4 = { 0 };
check_sockaddr_set(&ref4, AF_INET, "127.170.170.127", 0);
// 7F hex ~ 01111111 bin
// AA hex ~ 10101010 bin
struct sockaddr_storage ref6 = { 0 };
check_sockaddr_set(&ref6, AF_INET6, "7FAA::AA7F", 0);
ret = netblock_match(&ref4, &ref6, 32);
ok(ret == false, "match: family mismatch");
ret = netblock_match(NULL, &ref4, 32);
ok(ret == false, "match: NULL first parameter");
ret = netblock_match(&ref4, NULL, 32);
ok(ret == false, "match: NULL second parameter");
ret = netblock_match(&ref4, &ref4, -1);
ok(ret == true, "match: ipv4 - identity, auto full prefix");
ret = netblock_match(&ref4, &ref4, 31);
ok(ret == true, "match: ipv4 - identity, subnet");
ret = netblock_match(&ref4, &ref4, 32);
ok(ret == true, "match: ipv4 - identity, full prefix");
ret = netblock_match(&ref4, &ref4, 33);
ok(ret == true, "match: ipv4 - identity, prefix overflow");
ret = netblock_match(&ref6, &ref6, -1);
ok(ret == true, "match: ipv6 - identity, auto full prefix");
ret = netblock_match(&ref6, &ref6, 127);
ok(ret == true, "match: ipv6 - identity, subnet");
ret = netblock_match(&ref6, &ref6, 128);
ok(ret == true, "match: ipv6 - identity, full prefix");
ret = netblock_match(&ref6, &ref6, 129);
ok(ret == true, "match: ipv6 - identity, prefix overflow");
// 124 dec ~ 01111100 bin
check_sockaddr_set(&t, AF_INET, "124.0.0.0", 0);
ret = netblock_match(&t, &ref4, 5);
ok(ret == true, "match: ipv4 - first byte, shorter prefix");
ret = netblock_match(&t, &ref4, 6);
ok(ret == true, "match: ipv4 - first byte, precise prefix");
ret = netblock_match(&t, &ref4, 7);
ok(ret == false, "match: ipv4 - first byte, not match");
check_sockaddr_set(&t, AF_INET, "127.170.170.124", 0);
ret = netblock_match(&t, &ref4, 29);
ok(ret == true, "match: ipv4 - last byte, shorter prefix");
ret = netblock_match(&t, &ref4, 30);
ok(ret == true, "match: ipv4 - last byte, precise prefix");
ret = netblock_match(&t, &ref4, 31);
ok(ret == false, "match: ipv4 - last byte, not match");
// 7C hex ~ 01111100 bin
check_sockaddr_set(&t, AF_INET6, "7CAA::", 0);
ret = netblock_match(&t, &ref6, 5);
ok(ret == true, "match: ipv6 - first byte, shorter prefix");
ret = netblock_match(&t, &ref6, 6);
ok(ret == true, "match: ipv6 - first byte, precise prefix");
ret = netblock_match(&t, &ref6, 7);
ok(ret == false, "match: ipv6 - first byte, not match");
check_sockaddr_set(&t, AF_INET6, "7FAA::AA7C", 0);
ret = netblock_match(&t, &ref6, 125);
ok(ret == true, "match: ipv6 - last byte, shorter prefix");
ret = netblock_match(&t, &ref6, 126);
ok(ret == true, "match: ipv6 - last byte, precise prefix");
ret = netblock_match(&t, &ref6, 127);
ok(ret == false, "match: ipv6 - last byte, not match");
ok(ret == 0, "set address '%s'", straddr);
}
static void test_netrange_match(void)
{
bool ret;
struct sockaddr_storage t = { 0 };
struct sockaddr_storage min = { 0 };
struct sockaddr_storage max = { 0 };
// IPv4 tests.
check_sockaddr_set(&min, AF_INET, "0.0.0.0", 0);
check_sockaddr_set(&max, AF_INET, "255.255.255.255", 0);
check_sockaddr_set(&t, AF_INET, "0.0.0.0", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv4 max range - minimum");
check_sockaddr_set(&t, AF_INET, "255.255.255.255", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv4 max range - maximum");
check_sockaddr_set(&min, AF_INET, "1.13.113.213", 0);
check_sockaddr_set(&max, AF_INET, "2.24.124.224", 0);
check_sockaddr_set(&t, AF_INET, "1.12.113.213", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative far min");
check_sockaddr_set(&t, AF_INET, "1.13.113.212", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative close min");
check_sockaddr_set(&t, AF_INET, "1.13.113.213", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - minimum");
check_sockaddr_set(&t, AF_INET, "1.13.213.213", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - middle");
check_sockaddr_set(&t, AF_INET, "2.24.124.224", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - max");
check_sockaddr_set(&t, AF_INET, "2.24.124.225", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative close max");
check_sockaddr_set(&t, AF_INET, "2.25.124.225", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative far max");
// IPv6 tests.
check_sockaddr_set(&min, AF_INET6, "::0", 0);
check_sockaddr_set(&max, AF_INET6,
"FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 0);
check_sockaddr_set(&t, AF_INET6, "::0", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv6 max range - minimum");
check_sockaddr_set(&t, AF_INET6,
"FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv6 max range - maximum");
check_sockaddr_set(&min, AF_INET6, "1:13::ABCD:200B", 0);
check_sockaddr_set(&max, AF_INET6, "2:A24::124:224", 0);
check_sockaddr_set(&t, AF_INET6, "1:12::BCD:2000", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative far min");
check_sockaddr_set(&t, AF_INET6, "1:13::ABCD:200A", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative close min");
check_sockaddr_set(&t, AF_INET6, "1:13::ABCD:200B", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - minimum");
check_sockaddr_set(&t, AF_INET6, "1:13:0:12:34:0:ABCD:200B", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - middle");
check_sockaddr_set(&t, AF_INET6, "2:A24::124:224", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - max");
check_sockaddr_set(&t, AF_INET6, "2:A24::124:225", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative close max");
check_sockaddr_set(&t, AF_INET6, "2:FA24::4:24", 0);
ret = netrange_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative far max");
}
#define ZONE "example.zone"
#define KEY1 "key1_md5"
#define KEY2 "key2_md5"
#define KEY3 "key3_sha256"
static void test_acl_allowed(void)
{
int ret;
......@@ -353,12 +193,6 @@ int main(int argc, char *argv[])
{
plan_lazy();
diag("netblock_match");
test_netblock_match();
diag("netrange_match");
test_netrange_match();
diag("acl_allowed");
test_acl_allowed();
......
......@@ -17,6 +17,7 @@
#include <tap/basic.h>
#include "contrib/sockaddr.h"
#include "libknot/errcode.h"
static void test_sockaddr_is_any(void)
{
......@@ -44,11 +45,185 @@ static void test_sockaddr_is_any(void)
ok(sockaddr_is_any(&ipv6_any), "sockaddr_is_any: IPv6 any");
}
static void check_sockaddr_set(struct sockaddr_storage *ss, int family,
const char *straddr, int port)
{
int ret = sockaddr_set(ss, family, straddr, port);
ok(ret == KNOT_EOK, "set address '%s'", straddr);
}
static void test_net_match(void)
{
int ret;
struct sockaddr_storage t = { 0 };
// 127 dec ~ 01111111 bin
// 170 dec ~ 10101010 bin
struct sockaddr_storage ref4 = { 0 };
check_sockaddr_set(&ref4, AF_INET, "127.170.170.127", 0);
// 7F hex ~ 01111111 bin
// AA hex ~ 10101010 bin
struct sockaddr_storage ref6 = { 0 };
check_sockaddr_set(&ref6, AF_INET6, "7FAA::AA7F", 0);
ret = sockaddr_net_match(&ref4, &ref6, 32);
ok(ret == false, "match: family mismatch");
ret = sockaddr_net_match(NULL, &ref4, 32);
ok(ret == false, "match: NULL first parameter");
ret = sockaddr_net_match(&ref4, NULL, 32);
ok(ret == false, "match: NULL second parameter");
ret = sockaddr_net_match(&ref4, &ref4, -1);
ok(ret == true, "match: ipv4 - identity, auto full prefix");
ret = sockaddr_net_match(&ref4, &ref4, 31);
ok(ret == true, "match: ipv4 - identity, subnet");
ret = sockaddr_net_match(&ref4, &ref4, 32);
ok(ret == true, "match: ipv4 - identity, full prefix");
ret = sockaddr_net_match(&ref4, &ref4, 33);
ok(ret == true, "match: ipv4 - identity, prefix overflow");
ret = sockaddr_net_match(&ref6, &ref6, -1);
ok(ret == true, "match: ipv6 - identity, auto full prefix");
ret = sockaddr_net_match(&ref6, &ref6, 127);
ok(ret == true, "match: ipv6 - identity, subnet");
ret = sockaddr_net_match(&ref6, &ref6, 128);
ok(ret == true, "match: ipv6 - identity, full prefix");
ret = sockaddr_net_match(&ref6, &ref6, 129);
ok(ret == true, "match: ipv6 - identity, prefix overflow");
// 124 dec ~ 01111100 bin
check_sockaddr_set(&t, AF_INET, "124.0.0.0", 0);
ret = sockaddr_net_match(&t, &ref4, 5);
ok(ret == true, "match: ipv4 - first byte, shorter prefix");
ret = sockaddr_net_match(&t, &ref4, 6);
ok(ret == true, "match: ipv4 - first byte, precise prefix");
ret = sockaddr_net_match(&t, &ref4, 7);
ok(ret == false, "match: ipv4 - first byte, not match");
check_sockaddr_set(&t, AF_INET, "127.170.170.124", 0);
ret = sockaddr_net_match(&t, &ref4, 29);
ok(ret == true, "match: ipv4 - last byte, shorter prefix");
ret = sockaddr_net_match(&t, &ref4, 30);
ok(ret == true, "match: ipv4 - last byte, precise prefix");
ret = sockaddr_net_match(&t, &ref4, 31);
ok(ret == false, "match: ipv4 - last byte, not match");
// 7C hex ~ 01111100 bin
check_sockaddr_set(&t, AF_INET6, "7CAA::", 0);
ret = sockaddr_net_match(&t, &ref6, 5);
ok(ret == true, "match: ipv6 - first byte, shorter prefix");
ret = sockaddr_net_match(&t, &ref6, 6);
ok(ret == true, "match: ipv6 - first byte, precise prefix");
ret = sockaddr_net_match(&t, &ref6, 7);
ok(ret == false, "match: ipv6 - first byte, not match");
check_sockaddr_set(&t, AF_INET6, "7FAA::AA7C", 0);
ret = sockaddr_net_match(&t, &ref6, 125);
ok(ret == true, "match: ipv6 - last byte, shorter prefix");
ret = sockaddr_net_match(&t, &ref6, 126);
ok(ret == true, "match: ipv6 - last byte, precise prefix");
ret = sockaddr_net_match(&t, &ref6, 127);
ok(ret == false, "match: ipv6 - last byte, not match");
}
static void test_range_match(void)
{
bool ret;
struct sockaddr_storage t = { 0 };
struct sockaddr_storage min = { 0 };
struct sockaddr_storage max = { 0 };
// IPv4 tests.
check_sockaddr_set(&min, AF_INET, "0.0.0.0", 0);
check_sockaddr_set(&max, AF_INET, "255.255.255.255", 0);
check_sockaddr_set(&t, AF_INET, "0.0.0.0", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv4 max range - minimum");
check_sockaddr_set(&t, AF_INET, "255.255.255.255", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv4 max range - maximum");
check_sockaddr_set(&min, AF_INET, "1.13.113.213", 0);
check_sockaddr_set(&max, AF_INET, "2.24.124.224", 0);
check_sockaddr_set(&t, AF_INET, "1.12.113.213", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative far min");
check_sockaddr_set(&t, AF_INET, "1.13.113.212", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative close min");
check_sockaddr_set(&t, AF_INET, "1.13.113.213", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - minimum");
check_sockaddr_set(&t, AF_INET, "1.13.213.213", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - middle");
check_sockaddr_set(&t, AF_INET, "2.24.124.224", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv4 middle range - max");
check_sockaddr_set(&t, AF_INET, "2.24.124.225", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative close max");
check_sockaddr_set(&t, AF_INET, "2.25.124.225", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv4 middle range - negative far max");
// IPv6 tests.
check_sockaddr_set(&min, AF_INET6, "::0", 0);
check_sockaddr_set(&max, AF_INET6,
"FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 0);
check_sockaddr_set(&t, AF_INET6, "::0", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv6 max range - minimum");
check_sockaddr_set(&t, AF_INET6,
"FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv6 max range - maximum");
check_sockaddr_set(&min, AF_INET6, "1:13::ABCD:200B", 0);
check_sockaddr_set(&max, AF_INET6, "2:A24::124:224", 0);
check_sockaddr_set(&t, AF_INET6, "1:12::BCD:2000", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative far min");
check_sockaddr_set(&t, AF_INET6, "1:13::ABCD:200A", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative close min");
check_sockaddr_set(&t, AF_INET6, "1:13::ABCD:200B", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - minimum");
check_sockaddr_set(&t, AF_INET6, "1:13:0:12:34:0:ABCD:200B", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - middle");
check_sockaddr_set(&t, AF_INET6, "2:A24::124:224", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == true, "match: ipv6 middle range - max");
check_sockaddr_set(&t, AF_INET6, "2:A24::124:225", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative close max");
check_sockaddr_set(&t, AF_INET6, "2:FA24::4:24", 0);
ret = sockaddr_range_match(&t, &min, &max);
ok(ret == false, "match: ipv6 middle range - negative far max");
}
int main(int argc, char *argv[])
{
plan_lazy();
diag("sockaddr_is_any");
test_sockaddr_is_any();
diag("sockaddr_net_match");
test_net_match();
diag("sockaddr_range_match");
test_range_match();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment