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 <vnet/dns/dns_packet.h>
25 #include <vnet/ip/ip.h>
38 } dns_pending_request_t;
42 DNS_API_PENDING_NAME_TO_IP = 1,
43 DNS_API_PENDING_IP_TO_NAME,
44 DNS_PEER_PENDING_NAME_TO_IP,
45 DNS_PEER_PENDING_IP_TO_NAME,
46 } dns_pending_request_type_t;
53 /** The name in "normal human being" notation, e.g. www.foobar.com */
56 /** For CNAME records, the "next name" to resolve */
59 /** Expiration time */
62 /** Cached dns request, for sending retries */
65 /** Retry parameters */
72 /** Cached dns response */
75 /** Clients / peers awaiting responses */
76 dns_pending_request_t *pending_requests;
79 #define DNS_CACHE_ENTRY_FLAG_VALID (1<<0) /**< we have Actual Data */
80 #define DNS_CACHE_ENTRY_FLAG_STATIC (1<<1) /**< static entry */
81 #define DNS_CACHE_ENTRY_FLAG_CNAME (1<<2) /**< CNAME (indirect) entry */
83 #define DNS_RETRIES_PER_SERVER 3
85 #define DNS_RESOLVER_EVENT_RESOLVED 1
86 #define DNS_RESOLVER_EVENT_PENDING 2
91 /** Pool of cache entries */
92 dns_cache_entry_t *entries;
94 /** Pool indices of unresolved entries */
95 u32 *unresolved_entries;
97 /** Find cached record by name */
98 uword *cache_entry_by_name;
101 /** enable / disable flag */
104 /** udp port registration complete */
105 int udp_ports_registered;
107 /** upstream name servers, e.g. 8.8.8.8 */
108 ip4_address_t *ip4_name_servers;
109 ip6_address_t *ip6_name_servers;
111 /** config parameters */
113 u32 max_ttl_in_seconds;
117 vlib_main_t *vlib_main;
118 vnet_main_t *vnet_main;
121 extern dns_main_t dns_main;
123 extern vlib_node_registration_t dns46_reply_node;
124 extern vlib_node_registration_t dns4_request_node;
125 extern vlib_node_registration_t dns6_request_node;
126 extern vlib_node_registration_t dns_resolver_node;
128 #define foreach_dns46_request_error \
129 _(NONE, "No error") \
130 _(UNIMPLEMENTED, "Unimplemented") \
131 _(PROCESSED, "DNS request pkts processed") \
132 _(IP_OPTIONS, "DNS pkts with ip options (dropped)") \
133 _(BAD_REQUEST, "DNS pkts with serious discrepanices (dropped)") \
134 _(TOO_MANY_REQUESTS, "DNS pkts asking too many questions") \
135 _(RESOLUTION_REQUIRED, "DNS pkts pending upstream name resolution")
139 #define _(sym,str) DNS46_REQUEST_ERROR_##sym,
140 foreach_dns46_request_error
142 DNS46_REQUEST_N_ERROR,
143 } dns46_request_error_t;
145 #define foreach_dns46_reply_error \
146 _(DISABLED, "DNS pkts punted (feature disabled)") \
147 _(PROCESSED, "DNS reply pkts processed") \
148 _(NO_ELT, "No DNS pool element") \
149 _(FORMAT_ERROR, "DNS format errors") \
150 _(TEST_DROP, "DNS reply pkt dropped for test purposes")
154 #define _(sym,str) DNS46_REPLY_ERROR_##sym,
155 foreach_dns46_reply_error
158 } dns46_reply_error_t;
160 void vnet_send_dns_request (dns_main_t * dm, dns_cache_entry_t * ep);
162 vnet_dns_cname_indirection_nolock (dns_main_t * dm, u32 ep_index, u8 * reply);
164 int vnet_dns_delete_entry_by_index_nolock (dns_main_t * dm, u32 index);
167 vnet_dns_resolve_name (dns_main_t * dm, u8 * name, dns_pending_request_t * t,
168 dns_cache_entry_t ** retp);
171 vnet_dns_send_dns6_request (dns_main_t * dm,
172 dns_cache_entry_t * ep, ip6_address_t * server);
174 vnet_dns_send_dns4_request (dns_main_t * dm,
175 dns_cache_entry_t * ep, ip4_address_t * server);
177 void vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * t,
178 dns_cache_entry_t * ep, vlib_buffer_t * b0);
180 void vnet_send_dns6_reply (dns_main_t * dm, dns_pending_request_t * t,
181 dns_cache_entry_t * ep, vlib_buffer_t * b0);
183 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
184 u8 ** parse_from_here);
186 format_function_t format_dns_reply;
189 dns_cache_lock (dns_main_t * dm)
193 while (clib_atomic_test_and_set (dm->cache_lock))
199 dns_cache_unlock (dns_main_t * dm)
203 CLIB_MEMORY_BARRIER ();
208 #endif /* included_dns_h */
211 * fd.io coding-style-patch-verification: ON
214 * eval: (c-set-style "gnu")