1/* $NetBSD: ecs.h,v 1.1 2024/02/18 20:57:36 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16#ifndef DNS_ECS_H 17#define DNS_ECS_H 1 18 19#include <inttypes.h> 20 21#include <isc/lang.h> 22#include <isc/netaddr.h> 23#include <isc/types.h> 24 25#include <dns/rdatatype.h> 26#include <dns/types.h> 27 28/*% 29 * Maximum scope values for IPv4 and IPv6. 30 */ 31#ifndef ECS_MAX_V4_SCOPE 32#define ECS_MAX_V4_SCOPE 24 33#endif 34 35#ifndef ECS_MAX_V6_SCOPE 36#define ECS_MAX_V6_SCOPE 56 37#endif 38 39/* 40 * Any updates to this structure should also be applied in 41 * contrib/modules/dlz/dlz_minmal.h. 42 */ 43struct dns_ecs { 44 isc_netaddr_t addr; 45 uint8_t source; 46 uint8_t scope; 47}; 48 49/* <address>/NNN/NNN */ 50#define DNS_ECS_FORMATSIZE (ISC_NETADDR_FORMATSIZE + 9) 51 52ISC_LANG_BEGINDECLS 53 54void 55dns_ecs_init(dns_ecs_t *ecs); 56/*%< 57 * Initialize a DNS ECS structure. 58 * 59 * Requires: 60 * \li 'ecs' is not NULL and points to a valid dns_ecs structure. 61 */ 62 63bool 64dns_ecs_equals(const dns_ecs_t *ecs1, const dns_ecs_t *ecs2); 65/*%< 66 * Determine whether two ECS address prefixes are equal (except the 67 * scope prefix-length field). 68 * 69 * 'ecs1->source' must exactly match 'ecs2->source'; the address families 70 * must match; and the first 'ecs1->source' bits of the addresses must 71 * match. Subsequent address bits and the 'scope' values are ignored. 72 */ 73 74void 75dns_ecs_format(const dns_ecs_t *ecs, char *buf, size_t size); 76/*%< 77 * Format an ECS record as text. Result is guaranteed to be null-terminated. 78 * 79 * Requires: 80 * \li 'ecs' is not NULL. 81 * \li 'buf' is not NULL. 82 * \li 'size' is at least DNS_ECS_FORMATSIZE 83 */ 84ISC_LANG_ENDDECLS 85 86#endif /* DNS_ECS_H */ 87