FD.io VPP  v19.08-23-g4b943d6
Vector Packet Processing
dns.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef included_dns_h
17 #define included_dns_h
18 
19 #include <vppinfra/time.h>
20 #include <vppinfra/cache.h>
21 #include <vppinfra/error.h>
22 
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>
28 
29 typedef struct
30 {
38  u8 dst_address[16];
39  u8 *name;
41 
42 typedef enum
43 {
49 
50 typedef struct
51 {
52  /** flags */
53  volatile u8 flags;
54 
55  /** The name in "normal human being" notation, e.g. www.foobar.com */
56  u8 *name;
57 
58  /** For CNAME records, the "next name" to resolve */
60 
61  /** Expiration time */
63 
64  /** Cached dns request, for sending retries */
66 
67  /** Retry parameters */
70  int server_af;
73 
74  /** Cached dns response */
76 
77  /** Clients / peers awaiting responses */
80 
81 #define DNS_CACHE_ENTRY_FLAG_VALID (1<<0) /**< we have Actual Data */
82 #define DNS_CACHE_ENTRY_FLAG_STATIC (1<<1) /**< static entry */
83 #define DNS_CACHE_ENTRY_FLAG_CNAME (1<<2) /**< CNAME (indirect) entry */
84 
85 #define DNS_RETRIES_PER_SERVER 3
86 
87 #define DNS_RESOLVER_EVENT_RESOLVED 1
88 #define DNS_RESOLVER_EVENT_PENDING 2
89 
90 
91 typedef struct
92 {
93  /** Pool of cache entries */
95 
96  /** Pool indices of unresolved entries */
98 
99  /** Find cached record by name */
103 
104  /** enable / disable flag */
106 
107  /** udp port registration complete */
109 
110  /** upstream name servers, e.g. 8.8.8.8 */
113 
114  /** resolver process node index */
116 
117  /** config parameters */
121 
122  /** message-ID base */
124 
125  /* convenience */
129 } dns_main_t;
130 
131 extern dns_main_t dns_main;
132 
136 
137 #define foreach_dns46_request_error \
138 _(NONE, "No error") \
139 _(UNIMPLEMENTED, "Unimplemented") \
140 _(PROCESSED, "DNS request pkts processed") \
141 _(IP_OPTIONS, "DNS pkts with ip options (dropped)") \
142 _(BAD_REQUEST, "DNS pkts with serious discrepanices (dropped)") \
143 _(TOO_MANY_REQUESTS, "DNS pkts asking too many questions") \
144 _(RESOLUTION_REQUIRED, "DNS pkts pending upstream name resolution")
145 
146 typedef enum
147 {
148 #define _(sym,str) DNS46_REQUEST_ERROR_##sym,
150 #undef _
153 
154 #define foreach_dns46_reply_error \
155 _(DISABLED, "DNS pkts punted (feature disabled)") \
156 _(PROCESSED, "DNS reply pkts processed") \
157 _(NO_ELT, "No DNS pool element") \
158 _(FORMAT_ERROR, "DNS format errors") \
159 _(TEST_DROP, "DNS reply pkt dropped for test purposes") \
160 _(MULTIPLE_REPLY, "DNS multiple reply packets") \
161 _(NO_UNRESOLVED_ENTRY, "No unresolved entry for pkt")
162 
163 typedef enum
164 {
165 #define _(sym,str) DNS46_REPLY_ERROR_##sym,
167 #undef _
170 
172 int
173 vnet_dns_cname_indirection_nolock (dns_main_t * dm, u32 ep_index, u8 * reply);
174 
176 
177 int
179  dns_cache_entry_t ** retp);
180 
181 void
183  dns_cache_entry_t * ep, ip6_address_t * server);
184 void
186  dns_cache_entry_t * ep, ip4_address_t * server);
187 
189  dns_cache_entry_t * ep, vlib_buffer_t * b0);
190 
192  dns_cache_entry_t * ep, vlib_buffer_t * b0);
193 
194 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
195  u8 ** parse_from_here);
196 
198 
200 
201 static inline void
202 dns_cache_lock (dns_main_t * dm, int tag)
203 {
204  if (dm->cache_lock)
205  {
206  ASSERT (tag);
207  ASSERT (dm->cache_lock_tag == 0);
209  dm->cache_lock_tag = tag;
210  }
211 }
212 
213 static inline void
215 {
216  if (dm->cache_lock)
217  {
218  ASSERT (dm->cache_lock_tag);
219  dm->cache_lock_tag = 0;
221  }
222 }
223 
224 #endif /* included_dns_h */
225 
226 /*
227  * fd.io coding-style-patch-verification: ON
228  *
229  * Local Variables:
230  * eval: (c-set-style "gnu")
231  * End:
232  */
Definition: dns.h:50
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:100
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:78
void vnet_send_dns4_reply(dns_main_t *dm, dns_pending_request_t *t, dns_cache_entry_t *ep, vlib_buffer_t *b0)
Definition: dns.c:2775
ip6_address_t * ip6_name_servers
Definition: dns.h:112
dns_main_t dns_main
Definition: dns.c:61
u8 * vnet_dns_labels_to_name(u8 *label, u8 *full_text, u8 **parse_from_here)
arc-function for the above.
Definition: dns.c:516
vlib_node_registration_t dns46_reply_node
(constructor) VLIB_REGISTER_NODE (dns46_reply_node)
Definition: reply_node.c:42
void vnet_dns_send_dns4_request(dns_main_t *dm, dns_cache_entry_t *ep, ip4_address_t *server)
Definition: dns.c:240
vlib_node_registration_t dns4_request_node
(constructor) VLIB_REGISTER_NODE (dns4_request_node)
Definition: request_node.c:293
u8 * dns_response
Cached dns response.
Definition: dns.h:75
int retry_count
Retry parameters.
Definition: dns.h:68
int vnet_dns_resolve_name(dns_main_t *dm, u8 *name, dns_pending_request_t *t, dns_cache_entry_t **retp)
Definition: dns.c:828
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u32 client_context
Definition: dns.h:33
void vnet_dns_send_dns6_request(dns_main_t *dm, dns_cache_entry_t *ep, ip6_address_t *server)
Definition: dns.c:359
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
vlib_main_t * vlib_main
Definition: dns.h:126
clib_spinlock_t cache_lock
Definition: dns.h:101
u8 * dns_request
Cached dns request, for sending retries.
Definition: dns.h:65
f64 retry_timer
Definition: dns.h:72
u32 * unresolved_entries
Pool indices of unresolved entries.
Definition: dns.h:97
unsigned int u32
Definition: types.h:88
u32 resolver_process_node_index
resolver process node index
Definition: dns.h:115
dns_pending_request_t * pending_requests
Clients / peers awaiting responses.
Definition: dns.h:78
ip4_address_t * ip4_name_servers
upstream name servers, e.g.
Definition: dns.h:111
u8 * cname
For CNAME records, the "next name" to resolve.
Definition: dns.h:59
u8 * name
The name in "normal human being" notation, e.g.
Definition: dns.h:56
int cache_lock_tag
Definition: dns.h:102
unsigned short u16
Definition: types.h:57
#define foreach_dns46_reply_error
Definition: dns.h:154
u32 label
Definition: fib_types.api:25
u8 name[64]
Definition: memclnt.api:152
dns46_reply_error_t
Definition: dns.h:163
int server_rotor
Definition: dns.h:69
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
int vnet_dns_cname_indirection_nolock(dns_main_t *dm, u32 ep_index, u8 *reply)
Handle cname indirection.
Definition: dns.c:984
dns_pending_request_type_t
Definition: dns.h:42
api_main_t * api_main
Definition: dns.h:128
static void dns_cache_unlock(dns_main_t *dm)
Definition: dns.h:214
int vnet_dns_delete_entry_by_index_nolock(dns_main_t *dm, u32 index)
Definition: dns.c:682
u16 msg_id_base
message-ID base
Definition: dns.h:123
#define ASSERT(truth)
void vnet_send_dns6_reply(dns_main_t *dm, dns_pending_request_t *t, dns_cache_entry_t *ep, vlib_buffer_t *b0)
Definition: dns.c:2767
volatile u8 flags
flags
Definition: dns.h:53
vnet_main_t * vnet_main
Definition: dns.h:127
int udp_ports_registered
udp port registration complete
Definition: dns.h:108
uword * cache_entry_by_name
Find cached record by name.
Definition: dns.h:100
vlib_node_registration_t dns6_request_node
(constructor) VLIB_REGISTER_NODE (dns6_request_node)
Definition: request_node.c:320
struct _vlib_node_registration vlib_node_registration_t
static void dns_cache_lock(dns_main_t *dm, int tag)
Definition: dns.h:202
void vnet_dns_create_resolver_process(dns_main_t *dm)
u32 max_ttl_in_seconds
Definition: dns.h:119
u32 name_cache_size
config parameters
Definition: dns.h:118
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
format_function_t format_dns_reply
Definition: dns.h:199
Definition: dns.h:91
int server_fails
Definition: dns.h:71
void vnet_send_dns_request(dns_main_t *dm, dns_cache_entry_t *ep)
Definition: dns.c:558
u32 random_seed
Definition: dns.h:120
int server_af
Definition: dns.h:70
f64 expiration_time
Expiration time.
Definition: dns.h:62
#define foreach_dns46_request_error
Definition: dns.h:137
dns46_request_error_t
Definition: dns.h:146
int is_enabled
enable / disable flag
Definition: dns.h:105
dns_cache_entry_t * entries
Pool of cache entries.
Definition: dns.h:94