2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef included_dns_h
17 #define included_dns_h
19 #include <vppinfra/time.h>
20 #include <vppinfra/cache.h>
21 #include <vppinfra/error.h>
23 #include <vppinfra/hash.h>
24 #include <dns/dns_packet.h>
25 #include <vnet/ip/ip.h>
26 #include <vppinfra/lock.h>
27 #include <vlibapi/api_common.h>
40 } dns_pending_request_t;
49 DNS_API_PENDING_NAME_TO_IP = 1,
50 DNS_API_PENDING_IP_TO_NAME,
51 DNS_PEER_PENDING_NAME_TO_IP,
52 DNS_PEER_PENDING_IP_TO_NAME,
53 } dns_pending_request_type_t;
60 /** The name in "normal human being" notation, e.g. www.foobar.com */
63 /** For CNAME records, the "next name" to resolve */
66 /** Expiration time */
69 /** Cached dns request, for sending retries */
72 /** Retry parameters */
79 /** Cached dns response */
82 /** Clients / peers awaiting responses */
83 dns_pending_request_t *pending_requests;
86 #define DNS_CACHE_ENTRY_FLAG_VALID (1<<0) /**< we have Actual Data */
87 #define DNS_CACHE_ENTRY_FLAG_STATIC (1<<1) /**< static entry */
88 #define DNS_CACHE_ENTRY_FLAG_CNAME (1<<2) /**< CNAME (indirect) entry */
90 #define DNS_RETRIES_PER_SERVER 3
92 #define DNS_RESOLVER_EVENT_RESOLVED 1
93 #define DNS_RESOLVER_EVENT_PENDING 2
98 /** Pool of cache entries */
99 dns_cache_entry_t *entries;
101 /** Pool indices of unresolved entries */
102 u32 *unresolved_entries;
104 /** Find cached record by name */
105 uword *cache_entry_by_name;
106 clib_spinlock_t cache_lock;
109 /** enable / disable flag */
112 /** udp port registration complete */
113 int udp_ports_registered;
115 /** upstream name servers, e.g. 8.8.8.8 */
116 ip4_address_t *ip4_name_servers;
117 ip6_address_t *ip6_name_servers;
119 /** resolver process node index */
120 u32 resolver_process_node_index;
122 /** config parameters */
124 u32 max_ttl_in_seconds;
127 /** message-ID base */
131 vnet_main_t *vnet_main;
132 api_main_t *api_main;
135 extern dns_main_t dns_main;
137 extern vlib_node_registration_t dns46_reply_node;
138 extern vlib_node_registration_t dns4_request_node;
139 extern vlib_node_registration_t dns6_request_node;
141 #define foreach_dns46_request_error \
142 _(NONE, "No error") \
143 _(UNIMPLEMENTED, "Unimplemented") \
144 _(PROCESSED, "DNS request pkts processed") \
145 _(IP_OPTIONS, "DNS pkts with ip options (dropped)") \
146 _(BAD_REQUEST, "DNS pkts with serious discrepancies (dropped)") \
147 _(TOO_MANY_REQUESTS, "DNS pkts asking too many questions") \
148 _(RESOLUTION_REQUIRED, "DNS pkts pending upstream name resolution")
152 #define _(sym,str) DNS46_REQUEST_ERROR_##sym,
153 foreach_dns46_request_error
155 DNS46_REQUEST_N_ERROR,
156 } dns46_request_error_t;
158 #define foreach_dns46_reply_error \
159 _(DISABLED, "DNS pkts punted (feature disabled)") \
160 _(PROCESSED, "DNS reply pkts processed") \
161 _(NO_ELT, "No DNS pool element") \
162 _(FORMAT_ERROR, "DNS format errors") \
163 _(TEST_DROP, "DNS reply pkt dropped for test purposes") \
164 _(MULTIPLE_REPLY, "DNS multiple reply packets") \
165 _(NO_UNRESOLVED_ENTRY, "No unresolved entry for pkt")
169 #define _(sym,str) DNS46_REPLY_ERROR_##sym,
170 foreach_dns46_reply_error
173 } dns46_reply_error_t;
175 void vnet_send_dns_request (vlib_main_t * vm, dns_main_t * dm,
176 dns_cache_entry_t * ep);
177 int vnet_dns_cname_indirection_nolock (vlib_main_t * vm, dns_main_t * dm,
178 u32 ep_index, u8 * reply);
180 int vnet_dns_delete_entry_by_index_nolock (dns_main_t * dm, u32 index);
183 vnet_dns_resolve_name (vlib_main_t * vm, dns_main_t * dm, u8 * name,
184 dns_pending_request_t * t, dns_cache_entry_t ** retp);
187 vnet_dns_send_dns6_request (vlib_main_t * vm, dns_main_t * dm,
188 dns_cache_entry_t * ep, ip6_address_t * server);
190 vnet_dns_send_dns4_request (vlib_main_t * vm, dns_main_t * dm,
191 dns_cache_entry_t * ep, ip4_address_t * server);
193 void vnet_send_dns4_reply (vlib_main_t * vm, dns_main_t * dm,
194 dns_pending_request_t * t, dns_cache_entry_t * ep,
197 void vnet_send_dns6_reply (vlib_main_t * vm, dns_main_t * dm,
198 dns_pending_request_t * t, dns_cache_entry_t * ep,
201 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
202 u8 ** parse_from_here);
204 void vnet_dns_create_resolver_process (vlib_main_t * vm, dns_main_t * dm);
206 format_function_t format_dns_reply;
209 dns_cache_lock (dns_main_t * dm, int tag)
214 ASSERT (dm->cache_lock_tag == 0);
215 clib_spinlock_lock (&dm->cache_lock);
216 dm->cache_lock_tag = tag;
221 dns_cache_unlock (dns_main_t * dm)
225 ASSERT (dm->cache_lock_tag);
226 dm->cache_lock_tag = 0;
227 clib_spinlock_unlock (&dm->cache_lock);
231 extern int dns_resolve_name (u8 *name, dns_cache_entry_t **ep,
232 dns_pending_request_t *t0,
233 dns_resolve_name_t *rn);
234 #endif /* included_dns_h */
237 * fd.io coding-style-patch-verification: ON
240 * eval: (c-set-style "gnu")