avf: properly set irq queue masks
[vpp.git] / src / vnet / dns / dns.h
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 <vnet/dns/dns_packet.h>
25 #include <vnet/ip/ip.h>
26 #include <vppinfra/lock.h>
27
28 typedef struct
29 {
30   u32 request_type;
31   u32 client_index;
32   u32 client_context;
33   u8 is_ip6;
34   u16 dst_port;
35   u16 id;
36   u16 pad;
37   u8 dst_address[16];
38   u8 *name;
39 } dns_pending_request_t;
40
41 typedef enum
42 {
43   DNS_API_PENDING_NAME_TO_IP = 1,
44   DNS_API_PENDING_IP_TO_NAME,
45   DNS_PEER_PENDING_NAME_TO_IP,
46   DNS_PEER_PENDING_IP_TO_NAME,
47 } dns_pending_request_type_t;
48
49 typedef struct
50 {
51   /** flags */
52   volatile u8 flags;
53
54   /** The name in "normal human being" notation, e.g. www.foobar.com */
55   u8 *name;
56
57   /** For CNAME records, the "next name" to resolve */
58   u8 *cname;
59
60   /** Expiration time */
61   f64 expiration_time;
62
63   /** Cached dns request, for sending retries */
64   u8 *dns_request;
65
66   /** Retry parameters */
67   int retry_count;
68   int server_rotor;
69   int server_af;
70   int server_fails;
71   f64 retry_timer;
72
73   /** Cached dns response */
74   u8 *dns_response;
75
76   /** Clients / peers awaiting responses */
77   dns_pending_request_t *pending_requests;
78 } dns_cache_entry_t;
79
80 #define DNS_CACHE_ENTRY_FLAG_VALID      (1<<0) /**< we have Actual Data */
81 #define DNS_CACHE_ENTRY_FLAG_STATIC     (1<<1) /**< static entry */
82 #define DNS_CACHE_ENTRY_FLAG_CNAME      (1<<2) /**< CNAME (indirect) entry */
83
84 #define DNS_RETRIES_PER_SERVER 3
85
86 #define DNS_RESOLVER_EVENT_RESOLVED     1
87 #define DNS_RESOLVER_EVENT_PENDING      2
88
89
90 typedef struct
91 {
92   /** Pool of cache entries */
93   dns_cache_entry_t *entries;
94
95   /** Pool indices of unresolved entries */
96   u32 *unresolved_entries;
97
98   /** Find cached record by name */
99   uword *cache_entry_by_name;
100   clib_spinlock_t cache_lock;
101
102   /** enable / disable flag */
103   int is_enabled;
104
105   /** udp port registration complete */
106   int udp_ports_registered;
107
108   /** upstream name servers, e.g. 8.8.8.8 */
109   ip4_address_t *ip4_name_servers;
110   ip6_address_t *ip6_name_servers;
111
112   /** resolver process node index */
113   u32 resolver_process_node_index;
114
115   /** config parameters */
116   u32 name_cache_size;
117   u32 max_ttl_in_seconds;
118   u32 random_seed;
119
120   /* convenience */
121   vlib_main_t *vlib_main;
122   vnet_main_t *vnet_main;
123 } dns_main_t;
124
125 extern dns_main_t dns_main;
126
127 extern vlib_node_registration_t dns46_reply_node;
128 extern vlib_node_registration_t dns4_request_node;
129 extern vlib_node_registration_t dns6_request_node;
130
131 #define foreach_dns46_request_error                                     \
132 _(NONE, "No error")                                                     \
133 _(UNIMPLEMENTED, "Unimplemented")                                       \
134 _(PROCESSED, "DNS request pkts processed")                              \
135 _(IP_OPTIONS, "DNS pkts with ip options (dropped)")                     \
136 _(BAD_REQUEST, "DNS pkts with serious discrepanices (dropped)")         \
137 _(TOO_MANY_REQUESTS, "DNS pkts asking too many questions")              \
138 _(RESOLUTION_REQUIRED, "DNS pkts pending upstream name resolution")
139
140 typedef enum
141 {
142 #define _(sym,str) DNS46_REQUEST_ERROR_##sym,
143   foreach_dns46_request_error
144 #undef _
145     DNS46_REQUEST_N_ERROR,
146 } dns46_request_error_t;
147
148 #define foreach_dns46_reply_error                       \
149 _(DISABLED, "DNS pkts punted (feature disabled)")       \
150 _(PROCESSED, "DNS reply pkts processed")                \
151 _(NO_ELT, "No DNS pool element")                        \
152 _(FORMAT_ERROR, "DNS format errors")                    \
153 _(TEST_DROP, "DNS reply pkt dropped for test purposes") \
154 _(MULTIPLE_REPLY, "DNS multiple reply packets")         \
155 _(NO_UNRESOLVED_ENTRY, "No unresolved entry for pkt")
156
157 typedef enum
158 {
159 #define _(sym,str) DNS46_REPLY_ERROR_##sym,
160   foreach_dns46_reply_error
161 #undef _
162     DNS46_REPLY_N_ERROR,
163 } dns46_reply_error_t;
164
165 void vnet_send_dns_request (dns_main_t * dm, dns_cache_entry_t * ep);
166 int
167 vnet_dns_cname_indirection_nolock (dns_main_t * dm, u32 ep_index, u8 * reply);
168
169 int vnet_dns_delete_entry_by_index_nolock (dns_main_t * dm, u32 index);
170
171 int
172 vnet_dns_resolve_name (dns_main_t * dm, u8 * name, dns_pending_request_t * t,
173                        dns_cache_entry_t ** retp);
174
175 void
176 vnet_dns_send_dns6_request (dns_main_t * dm,
177                             dns_cache_entry_t * ep, ip6_address_t * server);
178 void
179 vnet_dns_send_dns4_request (dns_main_t * dm,
180                             dns_cache_entry_t * ep, ip4_address_t * server);
181
182 void vnet_send_dns4_reply (dns_main_t * dm, dns_pending_request_t * t,
183                            dns_cache_entry_t * ep, vlib_buffer_t * b0);
184
185 void vnet_send_dns6_reply (dns_main_t * dm, dns_pending_request_t * t,
186                            dns_cache_entry_t * ep, vlib_buffer_t * b0);
187
188 u8 *vnet_dns_labels_to_name (u8 * label, u8 * full_text,
189                              u8 ** parse_from_here);
190
191 void vnet_dns_create_resolver_process (dns_main_t * dm);
192
193 format_function_t format_dns_reply;
194
195 static inline void
196 dns_cache_lock (dns_main_t * dm)
197 {
198   if (dm->cache_lock)
199     {
200       clib_spinlock_lock (&dm->cache_lock);
201     }
202 }
203
204 static inline void
205 dns_cache_unlock (dns_main_t * dm)
206 {
207   if (dm->cache_lock)
208     {
209       clib_spinlock_unlock (&dm->cache_lock);
210     }
211 }
212
213 #endif /* included_dns_h */
214
215 /*
216  * fd.io coding-style-patch-verification: ON
217  *
218  * Local Variables:
219  * eval: (c-set-style "gnu")
220  * End:
221  */