blob: 442ef860cfbf5b026ae15e947a13f02fc4eb4a1e [file] [log] [blame]
Dave Barach65457162017-10-10 17:53:14 -04001/*
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 <vnet/dns/dns_packet.h>
25#include <vnet/ip/ip.h>
26
27typedef struct
28{
Dave Barachd2080152017-10-20 09:21:35 -040029 u32 request_type;
30 u32 client_index;
31 u32 client_context;
32} pending_api_request_t;
33
34#define DNS_API_PENDING_NAME_TO_IP 1
35#define DNS_API_PENDING_IP_TO_NAME 2
36
37typedef struct
38{
Dave Barach65457162017-10-10 17:53:14 -040039 /** flags */
40 volatile u8 flags;
41
42 /** The name in "normal human being" notation, e.g. www.foobar.com */
43 u8 *name;
44
Dave Barach0cb01bd2017-10-16 14:39:52 -040045 /** For CNAME records, the "next name" to resolve */
46 u8 *cname;
47
Dave Barach65457162017-10-10 17:53:14 -040048 /** Expiration time */
49 f64 expiration_time;
50
51 /** Cached dns request, for sending retries */
52 u8 *dns_request;
53
54 /** Retry parameters */
55 int retry_count;
56 int server_rotor;
57 int server_af;
58 f64 retry_timer;
59
60 /** Cached dns response */
61 u8 *dns_response;
62
63 /** Clients awaiting responses */
Dave Barachd2080152017-10-20 09:21:35 -040064 pending_api_request_t *pending_api_requests;
Dave Barach65457162017-10-10 17:53:14 -040065 ip4_address_t *ip4_peers_to_notify;
66 ip6_address_t *ip6_peers_to_notify;
67} dns_cache_entry_t;
68
69#define DNS_CACHE_ENTRY_FLAG_VALID (1<<0) /**< we have Actual Data */
70#define DNS_CACHE_ENTRY_FLAG_STATIC (1<<1) /**< static entry */
Dave Barach0cb01bd2017-10-16 14:39:52 -040071#define DNS_CACHE_ENTRY_FLAG_CNAME (1<<2) /**< CNAME (indirect) entry */
Dave Barach65457162017-10-10 17:53:14 -040072
73#define DNS_RETRIES_PER_SERVER 3
74
75#define DNS_RESOLVER_EVENT_RESOLVED 1
76#define DNS_RESOLVER_EVENT_PENDING 2
77
78
79typedef struct
80{
81 /** Pool of cache entries */
82 dns_cache_entry_t *entries;
83
84 /** Pool indices of unresolved entries */
85 u32 *unresolved_entries;
86
87 /** Find cached record by name */
88 uword *cache_entry_by_name;
89 uword *cache_lock;
90
91 /** enable / disable flag */
92 int is_enabled;
93
94 /** upstream name servers, e.g. 8.8.8.8 */
95 ip4_address_t *ip4_name_servers;
96 ip6_address_t *ip6_name_servers;
97
98 /** config parameters */
99 u32 name_cache_size;
100 u32 max_ttl_in_seconds;
101 u32 random_seed;
102
103 /* convenience */
104 vlib_main_t *vlib_main;
105 vnet_main_t *vnet_main;
106} dns_main_t;
107
108extern dns_main_t dns_main;
109
110extern vlib_node_registration_t dns46_reply_node;
111extern vlib_node_registration_t dns_resolver_node;
112
113#define foreach_dns46_reply_error \
114_(PROCESSED, "DNS reply pkts processed") \
115_(NO_ELT, "No DNS pool element") \
116_(FORMAT_ERROR, "DNS format errors") \
117_(TEST_DROP, "DNS reply pkt dropped for test purposes")
118
119typedef enum
120{
121#define _(sym,str) DNS46_REPLY_ERROR_##sym,
122 foreach_dns46_reply_error
123#undef _
124 DNS46_REPLY_N_ERROR,
125} dns46_reply_error_t;
126
127void vnet_send_dns_request (dns_main_t * dm, dns_cache_entry_t * ep);
Dave Barach0cb01bd2017-10-16 14:39:52 -0400128int
129vnet_dns_cname_indirection_nolock (dns_main_t * dm, u32 ep_index, u8 * reply);
130
Dave Barach65457162017-10-10 17:53:14 -0400131int vnet_dns_delete_entry_by_index_nolock (dns_main_t * dm, u32 index);
132
133format_function_t format_dns_reply;
134
135static inline void
136dns_cache_lock (dns_main_t * dm)
137{
138 if (dm->cache_lock)
139 {
140 while (__sync_lock_test_and_set (dm->cache_lock, 1))
141 ;
142 }
143}
144
145static inline void
146dns_cache_unlock (dns_main_t * dm)
147{
148 if (dm->cache_lock)
149 {
150 CLIB_MEMORY_BARRIER ();
151 *dm->cache_lock = 0;
152 }
153}
154
155#endif /* included_dns_h */
156
157/*
158 * fd.io coding-style-patch-verification: ON
159 *
160 * Local Variables:
161 * eval: (c-set-style "gnu")
162 * End:
163 */