1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef NS_LISTENLIST_H
13 #define NS_LISTENLIST_H 1
14 
15 /*****
16 ***** Module Info
17 *****/
18 
19 /*! \file
20  * \brief
21  * "Listen lists", as in the "listen-on" configuration statement.
22  */
23 
24 /***
25  *** Imports
26  ***/
27 
28 #include <stdbool.h>
29 
30 #include <isc/net.h>
31 #include <isc/tls.h>
32 
33 #include <dns/types.h>
34 
35 /***
36  *** Types
37  ***/
38 
39 typedef struct ns_listenelt  ns_listenelt_t;
40 typedef struct ns_listenlist ns_listenlist_t;
41 
42 struct ns_listenelt {
43 	isc_mem_t *   mctx;
44 	in_port_t     port;
45 	bool	      is_http;
46 	isc_dscp_t    dscp; /* -1 = not set, 0..63 */
47 	dns_acl_t *   acl;
48 	isc_tlsctx_t *sslctx;
49 	char **	      http_endpoints;
50 	size_t	      http_endpoints_number;
51 	isc_quota_t * http_quota;
52 	uint32_t      max_concurrent_streams;
53 	ISC_LINK(ns_listenelt_t) link;
54 };
55 
56 struct ns_listenlist {
57 	isc_mem_t *mctx;
58 	int	   refcount;
59 	ISC_LIST(ns_listenelt_t) elts;
60 };
61 
62 typedef struct ns_listen_tls_params {
63 	const char *key;
64 	const char *cert;
65 	uint32_t    protocols;
66 	const char *dhparam_file;
67 	const char *ciphers;
68 	bool	    prefer_server_ciphers;
69 	bool	    prefer_server_ciphers_set;
70 	bool	    session_tickets;
71 	bool	    session_tickets_set;
72 } ns_listen_tls_params_t;
73 
74 /***
75  *** Functions
76  ***/
77 
78 isc_result_t
79 ns_listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
80 		    dns_acl_t *acl, bool tls,
81 		    const ns_listen_tls_params_t *tls_params,
82 		    ns_listenelt_t **		  target);
83 /*%<
84  * Create a listen-on list element.
85  *
86  * Requires:
87  * \li	'targetp' is a valid pointer to a pointer containing 'NULL';
88  * \li	'tls_params' is a valid, non-'NULL' pointer if 'tls' equals 'true'.
89  */
90 
91 isc_result_t
92 ns_listenelt_create_http(isc_mem_t *mctx, in_port_t http_port, isc_dscp_t dscp,
93 			 dns_acl_t *acl, bool tls,
94 			 const ns_listen_tls_params_t *tls_params,
95 			 char **endpoints, size_t nendpoints,
96 			 isc_quota_t *quota, const uint32_t max_streams,
97 			 ns_listenelt_t **target);
98 /*%<
99  * Create a listen-on list element for HTTP(S).
100  */
101 
102 void
103 ns_listenelt_destroy(ns_listenelt_t *elt);
104 /*%<
105  * Destroy a listen-on list element.
106  */
107 
108 isc_result_t
109 ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target);
110 /*%<
111  * Create a new, empty listen-on list.
112  */
113 
114 void
115 ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target);
116 /*%<
117  * Attach '*target' to '*source'.
118  */
119 
120 void
121 ns_listenlist_detach(ns_listenlist_t **listp);
122 /*%<
123  * Detach 'listp'.
124  */
125 
126 isc_result_t
127 ns_listenlist_default(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp,
128 		      bool enabled, ns_listenlist_t **target);
129 /*%<
130  * Create a listen-on list with default contents, matching
131  * all addresses with port 'port' (if 'enabled' is true),
132  * or no addresses (if 'enabled' is false).
133  */
134 
135 #endif /* NS_LISTENLIST_H */
136