1/*	$NetBSD: ecs.h,v 1.9 2024/02/21 22:52:09 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#pragma once
17
18#include <inttypes.h>
19
20#include <isc/lang.h>
21#include <isc/netaddr.h>
22#include <isc/types.h>
23
24#include <dns/rdatatype.h>
25#include <dns/types.h>
26
27/*%
28 * Maximum scope values for IPv4 and IPv6.
29 */
30#ifndef ECS_MAX_V4_SCOPE
31#define ECS_MAX_V4_SCOPE 24
32#endif
33
34#ifndef ECS_MAX_V6_SCOPE
35#define ECS_MAX_V6_SCOPE 56
36#endif
37
38/*
39 * Any updates to this structure should also be applied in
40 * contrib/modules/dlz/dlz_minmal.h.
41 */
42struct dns_ecs {
43	isc_netaddr_t addr;
44	uint8_t	      source;
45	uint8_t	      scope;
46};
47
48/* <address>/NNN/NNN */
49#define DNS_ECS_FORMATSIZE (ISC_NETADDR_FORMATSIZE + 9)
50
51ISC_LANG_BEGINDECLS
52
53void
54dns_ecs_init(dns_ecs_t *ecs);
55/*%<
56 * Initialize a DNS ECS structure.
57 *
58 * Requires:
59 * \li 'ecs' is not NULL and points to a valid dns_ecs structure.
60 */
61
62bool
63dns_ecs_equals(const dns_ecs_t *ecs1, const dns_ecs_t *ecs2);
64/*%<
65 * Determine whether two ECS address prefixes are equal (except the
66 * scope prefix-length field).
67 *
68 * 'ecs1->source' must exactly match 'ecs2->source'; the address families
69 * must match; and the first 'ecs1->source' bits of the addresses must
70 * match. Subsequent address bits and the 'scope' values are ignored.
71 */
72
73void
74dns_ecs_format(const dns_ecs_t *ecs, char *buf, size_t size);
75/*%<
76 * Format an ECS record as text. Result is guaranteed to be null-terminated.
77 *
78 * Requires:
79 * \li  'ecs' is not NULL.
80 * \li  'buf' is not NULL.
81 * \li  'size' is at least DNS_ECS_FORMATSIZE
82 */
83ISC_LANG_ENDDECLS
84