xref: /netbsd-src/external/mpl/bind/dist/lib/ns/include/ns/listenlist.h (revision bcda20f65a8566e103791ec395f7f499ef322704)
1 /*	$NetBSD: listenlist.h,v 1.8 2025/01/26 16:25:46 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 /*****
19 ***** Module Info
20 *****/
21 
22 /*! \file
23  * \brief
24  * "Listen lists", as in the "listen-on" configuration statement.
25  */
26 
27 /***
28  *** Imports
29  ***/
30 
31 #include <stdbool.h>
32 
33 #include <isc/net.h>
34 #include <isc/netmgr.h>
35 #include <isc/tls.h>
36 
37 #include <dns/types.h>
38 
39 /***
40  *** Types
41  ***/
42 
43 typedef struct ns_listenelt  ns_listenelt_t;
44 typedef struct ns_listenlist ns_listenlist_t;
45 
46 struct ns_listenelt {
47 	isc_mem_t	   *mctx;
48 	in_port_t	    port;
49 	bool		    is_http;
50 	dns_acl_t	   *acl;
51 	isc_tlsctx_t	   *sslctx;
52 	isc_tlsctx_cache_t *sslctx_cache;
53 	char		  **http_endpoints;
54 	size_t		    http_endpoints_number;
55 	uint32_t	    http_max_clients;
56 	uint32_t	    max_concurrent_streams;
57 	isc_nm_proxy_type_t proxy;
58 	ISC_LINK(ns_listenelt_t) link;
59 };
60 
61 struct ns_listenlist {
62 	isc_mem_t *mctx;
63 	int	   refcount;
64 	ISC_LIST(ns_listenelt_t) elts;
65 };
66 
67 typedef struct ns_listen_tls_params {
68 	const char *name;
69 	const char *key;
70 	const char *cert;
71 	const char *ca_file;
72 	uint32_t    protocols;
73 	const char *dhparam_file;
74 	const char *ciphers;
75 	const char *cipher_suites;
76 	bool	    prefer_server_ciphers;
77 	bool	    prefer_server_ciphers_set;
78 	bool	    session_tickets;
79 	bool	    session_tickets_set;
80 } ns_listen_tls_params_t;
81 
82 /***
83  *** Functions
84  ***/
85 
86 isc_result_t
87 ns_listenelt_create(isc_mem_t *mctx, in_port_t port, dns_acl_t *acl,
88 		    const uint16_t family, bool tls,
89 		    const ns_listen_tls_params_t *tls_params,
90 		    isc_tlsctx_cache_t *tlsctx_cache, isc_nm_proxy_type_t proxy,
91 		    ns_listenelt_t **target);
92 /*%<
93  * Create a listen-on list element.
94  *
95  * Requires:
96  * \li	'targetp' is a valid pointer to a pointer containing 'NULL';
97  * \li	'tls_params' is a valid, non-'NULL' pointer if 'tls' equals 'true'.
98  * \li	'tlsctx_cache' is a valid, non-'NULL' pointer if 'tls' equals 'true'.
99  */
100 
101 isc_result_t
102 ns_listenelt_create_http(isc_mem_t *mctx, in_port_t http_port, dns_acl_t *acl,
103 			 const uint16_t family, bool tls,
104 			 const ns_listen_tls_params_t *tls_params,
105 			 isc_tlsctx_cache_t	      *tlsctx_cache,
106 			 isc_nm_proxy_type_t proxy, char **endpoints,
107 			 size_t nendpoints, const uint32_t max_clients,
108 			 const uint32_t max_streams, ns_listenelt_t **target);
109 /*%<
110  * Create a listen-on list element for HTTP(S).
111  */
112 
113 void
114 ns_listenelt_destroy(ns_listenelt_t *elt);
115 /*%<
116  * Destroy a listen-on list element.
117  */
118 
119 isc_result_t
120 ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target);
121 /*%<
122  * Create a new, empty listen-on list.
123  */
124 
125 void
126 ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target);
127 /*%<
128  * Attach '*target' to '*source'.
129  */
130 
131 void
132 ns_listenlist_detach(ns_listenlist_t **listp);
133 /*%<
134  * Detach 'listp'.
135  */
136 
137 isc_result_t
138 ns_listenlist_default(isc_mem_t *mctx, in_port_t port, bool enabled,
139 		      const uint16_t family, ns_listenlist_t **target);
140 /*%<
141  * Create a listen-on list with default contents, matching
142  * all addresses with port 'port' (if 'enabled' is true),
143  * or no addresses (if 'enabled' is false).
144  */
145