FD.io VPP  v21.10.1-2-g0a485f517
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 struct
43 {
46 
47 typedef enum
48 {
54 
55 typedef struct
56 {
57  /** flags */
58  volatile u8 flags;
59 
60  /** The name in "normal human being" notation, e.g. www.foobar.com */
61  u8 *name;
62 
63  /** For CNAME records, the "next name" to resolve */
65 
66  /** Expiration time */
68 
69  /** Cached dns request, for sending retries */
71 
72  /** Retry parameters */
75  int server_af;
78 
79  /** Cached dns response */
81 
82  /** Clients / peers awaiting responses */
85 
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 */
89 
90 #define DNS_RETRIES_PER_SERVER 3
91 
92 #define DNS_RESOLVER_EVENT_RESOLVED 1
93 #define DNS_RESOLVER_EVENT_PENDING 2
94 
95 
96 typedef struct
97 {
98  /** Pool of cache entries */
100 
101  /** Pool indices of unresolved entries */
103 
104  /** Find cached record by name */
108 
109  /** enable / disable flag */
111 
112  /** udp port registration complete */
114 
115  /** upstream name servers, e.g. 8.8.8.8 */
117  ip6_address_t *ip6_name_servers;
118 
119  /** resolver process node index */
121 
122  /** config parameters */
126 
127  /** message-ID base */
129 
130  /* convenience */
133 } dns_main_t;
134 
135 extern dns_main_t dns_main;
136 
140 
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")
149 
150 typedef enum
151 {
152 #define _(sym,str) DNS46_REQUEST_ERROR_##sym,
154 #undef _
157 
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")
166 
167 typedef enum
168 {
169 #define _(sym,str) DNS46_REPLY_ERROR_##sym,
171 #undef _
174 
176  dns_cache_entry_t * ep);
178  u32 ep_index, u8 * reply);
179 
181 
182 int
185 
186 void
188  dns_cache_entry_t * ep, ip6_address_t * server);
189 void
191  dns_cache_entry_t * ep, ip4_address_t * server);
192 
195  vlib_buffer_t * b0);
196 
199  vlib_buffer_t * b0);
200 
201 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
202  u8 ** parse_from_here);
203 
205 
207 
208 static inline void
209 dns_cache_lock (dns_main_t * dm, int tag)
210 {
211  if (dm->cache_lock)
212  {
213  ASSERT (tag);
214  ASSERT (dm->cache_lock_tag == 0);
216  dm->cache_lock_tag = tag;
217  }
218 }
219 
220 static inline void
222 {
223  if (dm->cache_lock)
224  {
225  ASSERT (dm->cache_lock_tag);
226  dm->cache_lock_tag = 0;
228  }
229 }
230 
231 extern int dns_resolve_name (u8 *name, dns_cache_entry_t **ep,
233  dns_resolve_name_t *rn);
234 #endif /* included_dns_h */
235 
236 /*
237  * fd.io coding-style-patch-verification: ON
238  *
239  * Local Variables:
240  * eval: (c-set-style "gnu")
241  * End:
242  */
ip_address
Definition: ip_types.h:79
label
u32 label
Definition: fib_types.api:25
vnet_send_dns6_reply
void vnet_send_dns6_reply(vlib_main_t *vm, dns_main_t *dm, dns_pending_request_t *t, dns_cache_entry_t *ep, vlib_buffer_t *b0)
Definition: dns.c:2648
dns_main_t::entries
dns_cache_entry_t * entries
Pool of cache entries.
Definition: dns.h:99
dns_cache_entry_t
Definition: dns.h:55
dns_pending_request_t::id
u16 id
Definition: dns.h:36
dns_main_t::is_enabled
int is_enabled
enable / disable flag
Definition: dns.h:110
dns_main_t::msg_id_base
u16 msg_id_base
message-ID base
Definition: dns.h:128
DNS_API_PENDING_IP_TO_NAME
@ DNS_API_PENDING_IP_TO_NAME
Definition: dns.h:50
dns_cache_lock
static void dns_cache_lock(dns_main_t *dm, int tag)
Definition: dns.h:209
dns_cache_entry_t::retry_timer
f64 retry_timer
Definition: dns.h:77
DNS46_REQUEST_N_ERROR
@ DNS46_REQUEST_N_ERROR
Definition: dns.h:155
name
string name[64]
Definition: fib.api:25
vnet_send_dns4_reply
void vnet_send_dns4_reply(vlib_main_t *vm, dns_main_t *dm, dns_pending_request_t *t, dns_cache_entry_t *ep, vlib_buffer_t *b0)
Definition: dns.c:2657
dns_main
dns_main_t dns_main
Definition: dns.c:41
vnet_dns_resolve_name
int vnet_dns_resolve_name(vlib_main_t *vm, dns_main_t *dm, u8 *name, dns_pending_request_t *t, dns_cache_entry_t **retp)
Definition: dns.c:720
DNS_API_PENDING_NAME_TO_IP
@ DNS_API_PENDING_NAME_TO_IP
Definition: dns.h:49
u16
unsigned short u16
Definition: types.h:57
dns_cache_entry_t::flags
volatile u8 flags
flags
Definition: dns.h:58
dns4_request_node
vlib_node_registration_t dns4_request_node
(constructor) VLIB_REGISTER_NODE (dns4_request_node)
Definition: request_node.c:293
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
dns_main_t::udp_ports_registered
int udp_ports_registered
udp port registration complete
Definition: dns.h:113
dns_cache_unlock
static void dns_cache_unlock(dns_main_t *dm)
Definition: dns.h:221
dns_main_t::ip4_name_servers
ip4_address_t * ip4_name_servers
upstream name servers, e.g.
Definition: dns.h:116
dns_cache_entry_t::server_rotor
int server_rotor
Definition: dns.h:74
vnet_dns_delete_entry_by_index_nolock
int vnet_dns_delete_entry_by_index_nolock(dns_main_t *dm, u32 index)
Definition: dns.c:572
dns_resolve_name_t
Definition: dns.h:42
dns46_reply_error_t
dns46_reply_error_t
Definition: dns.h:167
dns_pending_request_t::name
u8 * name
Definition: dns.h:39
foreach_dns46_request_error
#define foreach_dns46_request_error
Definition: dns.h:141
vnet_dns_labels_to_name
u8 * vnet_dns_labels_to_name(u8 *label, u8 *full_text, u8 **parse_from_here)
arc-function for the above.
Definition: dns.c:405
dns_cache_entry_t::pending_requests
dns_pending_request_t * pending_requests
Clients / peers awaiting responses.
Definition: dns.h:83
dns_main_t::ip6_name_servers
ip6_address_t * ip6_name_servers
Definition: dns.h:117
dns_main_t::cache_lock_tag
int cache_lock_tag
Definition: dns.h:107
hash.h
dns_cache_entry_t::name
u8 * name
The name in "normal human being" notation, e.g.
Definition: dns.h:61
dns_main_t::cache_lock
clib_spinlock_t cache_lock
Definition: dns.h:106
error.h
dns_pending_request_t::client_index
u32 client_index
Definition: dns.h:32
dns_resolve_name_t::address
ip_address_t address
Definition: dns.h:44
dns6_request_node
vlib_node_registration_t dns6_request_node
(constructor) VLIB_REGISTER_NODE (dns6_request_node)
Definition: request_node.c:320
dns_main_t::cache_entry_by_name
uword * cache_entry_by_name
Find cached record by name.
Definition: dns.h:105
lock.h
dns_pending_request_t::dst_port
u16 dst_port
Definition: dns.h:35
clib_spinlock_lock
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
DNS46_REPLY_N_ERROR
@ DNS46_REPLY_N_ERROR
Definition: dns.h:172
clib_spinlock_s
Definition: lock.h:51
vnet_dns_cname_indirection_nolock
int vnet_dns_cname_indirection_nolock(vlib_main_t *vm, dns_main_t *dm, u32 ep_index, u8 *reply)
Handle cname indirection.
Definition: dns.c:876
dns_pending_request_t::client_context
u32 client_context
Definition: dns.h:33
uword
u64 uword
Definition: types.h:112
dns_main_t::api_main
api_main_t * api_main
Definition: dns.h:132
time.h
dns_packet.h
f64
double f64
Definition: types.h:142
dns_pending_request_type_t
dns_pending_request_type_t
Definition: dns.h:47
dns_main_t::max_ttl_in_seconds
u32 max_ttl_in_seconds
Definition: dns.h:124
dns_cache_entry_t::expiration_time
f64 expiration_time
Expiration time.
Definition: dns.h:67
ip4_address_t
Definition: ip4_packet.h:50
dns_pending_request_t::request_type
u32 request_type
Definition: dns.h:31
DNS_PEER_PENDING_IP_TO_NAME
@ DNS_PEER_PENDING_IP_TO_NAME
Definition: dns.h:52
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
dns46_reply_node
vlib_node_registration_t dns46_reply_node
(constructor) VLIB_REGISTER_NODE (dns46_reply_node)
Definition: reply_node.c:42
dns_main_t::random_seed
u32 random_seed
Definition: dns.h:125
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
dns_cache_entry_t::dns_request
u8 * dns_request
Cached dns request, for sending retries.
Definition: dns.h:70
vnet_main_t
Definition: vnet.h:76
dns_cache_entry_t::dns_response
u8 * dns_response
Cached dns response.
Definition: dns.h:80
dns_cache_entry_t::cname
u8 * cname
For CNAME records, the "next name" to resolve.
Definition: dns.h:64
index
u32 index
Definition: flow_types.api:221
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
cache.h
dns_resolve_name
int dns_resolve_name(u8 *name, dns_cache_entry_t **ep, dns_pending_request_t *t0, dns_resolve_name_t *rn)
Definition: dns.c:1348
dns_pending_request_t::pad
u16 pad
Definition: dns.h:37
vnet_send_dns_request
void vnet_send_dns_request(vlib_main_t *vm, dns_main_t *dm, dns_cache_entry_t *ep)
Definition: dns.c:447
ip.h
u32
unsigned int u32
Definition: types.h:88
dns_main_t::name_cache_size
u32 name_cache_size
config parameters
Definition: dns.h:123
format_dns_reply
format_function_t format_dns_reply
Definition: dns.h:206
vnet_dns_send_dns6_request
void vnet_dns_send_dns6_request(vlib_main_t *vm, dns_main_t *dm, dns_cache_entry_t *ep, ip6_address_t *server)
Definition: dns.c:288
clib_spinlock_unlock
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
dns_pending_request_t::is_ip6
u8 is_ip6
Definition: dns.h:34
vlib_main_t
Definition: main.h:102
DNS_PEER_PENDING_NAME_TO_IP
@ DNS_PEER_PENDING_NAME_TO_IP
Definition: dns.h:51
u8
unsigned char u8
Definition: types.h:56
dns_main_t::vnet_main
vnet_main_t * vnet_main
Definition: dns.h:131
api_common.h
dns_main_t::resolver_process_node_index
u32 resolver_process_node_index
resolver process node index
Definition: dns.h:120
dns_main_t::unresolved_entries
u32 * unresolved_entries
Pool indices of unresolved entries.
Definition: dns.h:102
dns_pending_request_t
Definition: dns.h:29
vnet_dns_send_dns4_request
void vnet_dns_send_dns4_request(vlib_main_t *vm, dns_main_t *dm, dns_cache_entry_t *ep, ip4_address_t *server)
Definition: dns.c:220
dns_main_t
Definition: dns.h:96
vnet_dns_create_resolver_process
void vnet_dns_create_resolver_process(vlib_main_t *vm, dns_main_t *dm)
Definition: resolver_process.c:349
dns_cache_entry_t::server_af
int server_af
Definition: dns.h:75
dns_cache_entry_t::retry_count
int retry_count
Retry parameters.
Definition: dns.h:73
dns_cache_entry_t::server_fails
int server_fails
Definition: dns.h:76
foreach_dns46_reply_error
#define foreach_dns46_reply_error
Definition: dns.h:158
dns46_request_error_t
dns46_request_error_t
Definition: dns.h:150
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111