Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,383 +0,0 @@
1
-/*
2
- * resolver/dns related functions, dns cache and failover
3
- *
4
- * Copyright (C) 2006 iptelorg GmbH
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- */
22
-
23
-
24
-/**
25
- * @file
26
- * @brief Kamailio core :: resolver/dns related functions, dns cache and failover
27
- * @author andrei
28
- * @ingroup core
29
- * Module: @ref core
30
- */
31
-
32
-
33
-
34
-#ifndef __dns_cache_h
35
-#define __dns_cache_h
36
-
37
-#include "str.h"
38
-#include "config.h" /* MAX_BRANCHES */
39
-#include "timer.h"
40
-#include "ip_addr.h"
41
-#include "atomic_ops.h"
42
-#include "resolve.h"
43
-
44
-
45
-#if defined(USE_DNS_FAILOVER) && !defined(USE_DNS_CACHE)
46
-#error "DNS FAILOVER requires DNS CACHE support (define USE_DNS_CACHE)"
47
-#endif
48
-
49
-#if defined(DNS_WATCHDOG_SUPPORT) && !defined(USE_DNS_CACHE)
50
-#error "DNS WATCHDOG requires DNS CACHE support (define USE_DNS_CACHE)"
51
-#endif
52
-
53
-#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
54
-#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
55
-#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
56
-#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
57
-
58
-/** @brief uncomment the define below for SRV weight based load balancing */
59
-#define DNS_SRV_LB
60
-
61
-#define DNS_LU_LST
62
-
63
-/** @brief dns functions return them as negative values (e.g. return -E_DNS_NO_IP)
64
- *
65
- * listed in the order of importance ( if more errors, only the most important
66
- * is returned)
67
- */
68
-enum dns_errors{
69
-					E_DNS_OK=0,
70
-					E_DNS_EOR, /**< no more records (not an error)
71
-					              -- returned only by the dns_resolve*
72
-								  functions when called iteratively,; it
73
-								  signals the end of the ip/records list */
74
-					E_DNS_UNKNOWN /**< unkown error */,
75
-					E_DNS_INTERNAL_ERR /**< internal error */,
76
-					E_DNS_BAD_SRV_ENTRY,
77
-					E_DNS_NO_SRV /**< unresolvable srv record */,
78
-					E_DNS_BAD_IP_ENTRY,
79
-					E_DNS_NO_IP /**< unresolvable a or aaaa records*/,
80
-					E_DNS_BAD_IP /**< the ip is invalid */,
81
-					E_DNS_BLACKLIST_IP /**< the ip is blacklisted */,
82
-					E_DNS_NAME_TOO_LONG /**< try again with a shorter name */,
83
-					E_DNS_AF_MISMATCH /**< ipv4 or ipv6 only requested, but
84
-										 name contains an ip addr. of the
85
-										 opossite type */ ,
86
-					E_DNS_NO_NAPTR /**< unresolvable naptr record */,
87
-					E_DNS_CRITICAL /**< critical error, marks the end
88
-									  of the error table (always last) */
89
-};
90
-
91
-
92
-
93
-/** @brief return a short string, printable error description (err <=0) */
94
-const char* dns_strerror(int err);
95
-
96
-/** @brief dns entry flags,
97
- * shall be on the power of 2 */
98
-/*@{ */
99
-#define DNS_FLAG_BAD_NAME	1 /**< error flag: unresolvable */
100
-#define DNS_FLAG_PERMANENT	2 /**< permanent record, never times out,
101
-					never deleted, never overwritten
102
-					unless explicitely requested */
103
-/*@} */
104
-
105
-/** @name dns requests flags */
106
-/*@{ */
107
-#define DNS_NO_FLAGS	0
108
-#define DNS_IPV4_ONLY	1
109
-#define DNS_IPV6_ONLY	2
110
-#define DNS_IPV6_FIRST	4
111
-#define DNS_SRV_RR_LB	8  /**< SRV RR weight based load balancing */
112
-#define DNS_TRY_NAPTR	16 /**< enable naptr lookup */
113
-/*@} */
114
-
115
-
116
-/** @name ip blacklist error flags */
117
-/*@{ */
118
-#define IP_ERR_BAD_DST      2 /* destination is marked as bad (e.g. bad ip) */
119
-#define IP_ERR_SND          3 /* send error while using this as destination */
120
-#define IP_ERR_TIMEOUT      4 /* timeout waiting for a response */
121
-#define IP_ERR_TCP_CON      5 /* could not establish tcp connection */
122
-/*@} */
123
-
124
-
125
-/** @brief stripped down dns rr 
126
-	@note name, type and class are not needed, contained in struct dns_query */
127
-struct dns_rr{
128
-	struct dns_rr* next;
129
-	void* rdata; /**< depends on the type */
130
-	ticks_t expire; /**< = ttl + crt_time */
131
-};
132
-
133
-
134
-
135
-#ifdef DNS_LU_LST
136
-struct dns_lu_lst{  /* last used ordered list */
137
-	struct dns_lu_lst* next;
138
-	struct dns_lu_lst* prev;
139
-};
140
-#endif
141
-
142
-struct dns_hash_entry{
143
-	/* hash table links */
144
-	struct dns_hash_entry* next;
145
-	struct dns_hash_entry* prev;
146
-#ifdef DNS_LU_LST
147
-	struct dns_lu_lst last_used_lst;
148
-#endif
149
-	struct dns_rr* rr_lst;
150
-	atomic_t refcnt;
151
-	ticks_t last_used;
152
-	ticks_t expire; /* when the whole entry will expire */
153
-	int total_size;
154
-	unsigned short type;
155
-	unsigned char ent_flags; /* entry flags: unresolvable/permanent */
156
-	unsigned char name_len; /* can be maximum 255 bytes */
157
-	char name[1]; /* variable length, name, null terminated
158
-	                 (actual lenght = name_len +1)*/
159
-};
160
-
161
-
162
-/* to fit in the limit of MAX_BRANCHES */
163
-#if MAX_BRANCHES_LIMIT < 32
164
-typedef unsigned int srv_flags_t;
165
-#else
166
-typedef unsigned long long srv_flags_t;
167
-#endif
168
-
169
-struct dns_srv_handle{
170
-	struct dns_hash_entry* srv; /**< srv entry */
171
-	struct dns_hash_entry* a;   /**< a or aaaa current entry */
172
-#ifdef DNS_SRV_LB
173
-	srv_flags_t srv_tried_rrs;
174
-#endif
175
-	unsigned short port; /**< current port */
176
-	unsigned char srv_no; /**< current record no. in the srv entry */
177
-	unsigned char ip_no;  /**< current record no. in the a/aaaa entry */
178
-	unsigned char proto;  /**< protocol number */
179
-};
180
-
181
-
182
-
183
-const char* dns_strerror(int err);
184
-
185
-void fix_dns_flags(str *gname, str *name);
186
-int use_dns_failover_fixup(void *handle, str *gname, str *name, void **val);
187
-int use_dns_cache_fixup(void *handle, str *gname, str *name, void **val);
188
-int dns_cache_max_mem_fixup(void *handle, str *gname, str *name, void **val);
189
-int init_dns_cache(void);
190
-#ifdef USE_DNS_CACHE_STATS
191
-int init_dns_cache_stats(int iproc_num);
192
-#define DNS_CACHE_ALL_STATS "dc_all_stats"
193
-#endif
194
-void destroy_dns_cache(void);
195
-
196
-
197
-void dns_hash_put(struct dns_hash_entry* e);
198
-void dns_hash_put_shm_unsafe(struct dns_hash_entry* e);
199
-
200
-inline static void dns_srv_handle_put(struct dns_srv_handle* h)
201
-{
202
-	if (h){
203
-		if (h->srv){
204
-			dns_hash_put(h->srv);
205
-			h->srv=0;
206
-		}
207
-		if (h->a){
208
-			dns_hash_put(h->a);
209
-			h->a=0;
210
-		}
211
-	}
212
-}
213
-
214
-
215
-
216
-/** @brief use it when copying, it manually increases the ref cound */
217
-inline static void dns_srv_handle_ref(struct dns_srv_handle *h)
218
-{
219
-	if (h){
220
-		if (h->srv)
221
-			atomic_inc(&h->srv->refcnt);
222
-		if (h->a)
223
-			atomic_inc(&h->a->refcnt);
224
-	}
225
-}
226
-
227
-
228
-
229
-/** @brief safe copy increases the refcnt, src must not change while in this function
230
- * WARNING: the copy must be dns_srv_handle_put ! */
231
-inline static void dns_srv_handle_cpy(struct dns_srv_handle* dst,
232
-										struct dns_srv_handle* src)
233
-{
234
-	dns_srv_handle_ref(src);
235
-	*dst=*src;
236
-}
237
-
238
-
239
-
240
-/** @brief same as above but assume shm_lock held (for internal tm use only) */
241
-inline static void dns_srv_handle_put_shm_unsafe(struct dns_srv_handle* h)
242
-{
243
-	if (h){
244
-		if (h->srv){
245
-			dns_hash_put_shm_unsafe(h->srv);
246
-			h->srv=0;
247
-		}
248
-		if (h->a){
249
-			dns_hash_put_shm_unsafe(h->a);
250
-			h->a=0;
251
-		}
252
-	}
253
-}
254
-
255
-
256
-
257
-/** @brief get "next" ip next time a dns_srv_handle function is called
258
- * params: h   - struct dns_srv_handler
259
- *         err - return code of the last dns_*_resolve* call
260
- * returns: 0 if it doesn't make sense to try another record,
261
- * 1 otherwise
262
- */
263
-inline static int dns_srv_handle_next(struct dns_srv_handle* h, int err)
264
-{
265
-	if (err<0) return 0;
266
-	h->ip_no++;
267
-	return (h->srv || h->a);
268
-}
269
-
270
-
271
-
272
-inline static void dns_srv_handle_init(struct dns_srv_handle* h)
273
-{
274
-	h->srv=h->a=0;
275
-	h->srv_no=h->ip_no=0;
276
-	h->port=0;
277
-	h->proto=0;
278
-#ifdef DNS_SRV_LB
279
-	h->srv_tried_rrs=0;
280
-#endif
281
-}
282
-
283
-
284
-
285
-/** @brief performes a srv query on name
286
- * Params:  name  - srv query target (e.g. _sip._udp.foo.bar)
287
- *          ip    - result: first good ip found
288
- *          port  - result: corresponding port number
289
- *          flags - resolve options (like ipv4 only, ipv6 prefered a.s.o)
290
- * Returns: < 0 on error (can be passed to dns_strerror(), 0 on success
291
- */
292
-int dns_srv_get_ip(str* name, struct ip_addr* ip, unsigned short* port,
293
-					int flags);
294
-
295
-/** @brief performs an A, AAAA (or both) query/queries
296
- * Params:  name  - query target (e.g. foo.bar)
297
- *          ip    - result: first good ip found
298
- *          flags - resolve options (like ipv4 only, ipv6 prefered a.s.o)
299
- * Returns: < 0 on error (can be passed to dns_strerror(), 0 on success
300
- */
301
-int dns_get_ip(str* name, struct ip_addr* ip, int flags);
302
-
303
-struct hostent* dns_srv_get_he(str* name, unsigned short* port, int flags);
304
-struct hostent* dns_get_he(str* name, int flags);
305
-
306
-
307
-/** @brief resolve name to an ip, using srv record. Can be called multiple times
308
- * to iterate on all the possible ips, e.g :
309
- * dns_srv_handle_init(h);
310
- * ret_code=dns_sip_resolve(h,...);
311
- *  while( dns_srv_handle_next(h, ret_code){ ret_code=dns_sip_resolve(h...); }
312
- * dns_srv_handle_put(h);
313
- * WARNING: dns_srv_handle_init() must be called to initialize h and
314
- *  dns_srv_handle_put(h) must be called when h is no longer needed
315
- */
316
-int dns_sip_resolve(struct dns_srv_handle* h,  str* name, struct ip_addr* ip,
317
-					unsigned short* port, char* proto, int flags);
318
-
319
-/** @brief same as above, but fills su intead of changing port and filling an ip */
320
-inline static int dns_sip_resolve2su(struct dns_srv_handle* h,
321
-									 union sockaddr_union* su,
322
-									 str* name, unsigned short port,
323
-									 char* proto, int flags)
324
-{
325
-	struct ip_addr ip;
326
-	int ret;
327
-
328
-	ret=dns_sip_resolve(h, name, &ip, &port, proto, flags);
329
-	if (ret>=0)
330
-		init_su(su, &ip, port);
331
-	return ret;
332
-}
333
-
334
-/** @brief Delete all the entries from the cache.
335
- * If del_permanent is 0, then only the
336
- * non-permanent entries are deleted.
337
- */
338
-void dns_cache_flush(int del_permanent);
339
-
340
-#ifdef DNS_WATCHDOG_SUPPORT
341
-/** @brief sets the state of the DNS servers:
342
- * 1: at least one server is up
343
- * 0: all the servers are down
344
- */
345
-void dns_set_server_state(int state);
346
-
347
-/** @brief returns the state of the DNS servers */
348
-int dns_get_server_state(void);
349
-#endif /* DNS_WATCHDOG_SUPPORT */
350
-
351
-/** @brief Adds a new record to the cache.
352
- * If there is an existing record with the same name and value
353
- * (ip address in case of A/AAAA record, name in case of SRV record)
354
- * only the remaining fields are updated.
355
- *
356
- * Note that permanent records cannot be overwritten unless
357
- * the new record is also permanent. A permanent record
358
- * completely replaces a non-permanent one.
359
- *
360
- * Currently only A, AAAA, and SRV records are supported.
361
- */
362
-int dns_cache_add_record(unsigned short type,
363
-			str *name,
364
-			int ttl,
365
-			str *value,
366
-			int priority,
367
-			int weight,
368
-			int port,
369
-			int flags);
370
-
371
-/** @brief Delete a single record from the cache,
372
- * i.e. the record with the same name and value
373
- * (ip address in case of A/AAAA record, name in case of SRV record).
374
- *
375
- * Currently only A, AAAA, and SRV records are supported.
376
- */
377
-int dns_cache_delete_single_record(unsigned short type,
378
-			str *name,
379
-			str *value,
380
-			int flags);
381
-
382
-
383
-#endif
Browse code

core: Modify doxygen, remove history, remove SVN IDs, change "ser" and "sip-router" to "KAMAILIO"

Olle E. Johansson authored on 16/01/2015 16:38:46
Showing 1 changed files
... ...
@@ -23,7 +23,7 @@
23 23
 
24 24
 /**
25 25
  * @file
26
- * @brief SIP-router core :: resolver/dns related functions, dns cache and failover
26
+ * @brief Kamailio core :: resolver/dns related functions, dns cache and failover
27 27
  * @author andrei
28 28
  * @ingroup core
29 29
  * Module: @ref core
Browse code

core : Update include files - delete IDs, update doxygen, delete history

Olle E. Johansson authored on 03/01/2015 10:55:48
Showing 1 changed files
... ...
@@ -1,18 +1,16 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * resolver/dns related functions, dns cache and failover
5 3
  *
6 4
  * Copyright (C) 2006 iptelorg GmbH
7 5
  *
8
- * This file is part of ser, a free SIP server.
6
+ * This file is part of Kamailio, a free SIP server.
9 7
  *
10
- * ser is free software; you can redistribute it and/or modify
8
+ * Kamailio is free software; you can redistribute it and/or modify
11 9
  * it under the terms of the GNU General Public License as published by
12 10
  * the Free Software Foundation; either version 2 of the License, or
13 11
  * (at your option) any later version
14 12
  *
15
- * ser is distributed in the hope that it will be useful,
13
+ * Kamailio is distributed in the hope that it will be useful,
16 14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 16
  * GNU General Public License for more details.
... ...
@@ -22,16 +20,11 @@
22 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 21
  */
24 22
 
25
-/* History:
26
- * --------
27
- *  2006-07-13  created by andrei
28
- *  2007-06-16  naptr support (andrei)
29
- *  2007-07-30  DNS cache measurements added (Gergo)
30
- */
31 23
 
32 24
 /**
33 25
  * @file
34 26
  * @brief SIP-router core :: resolver/dns related functions, dns cache and failover
27
+ * @author andrei
35 28
  * @ingroup core
36 29
  * Module: @ref core
37 30
  */
Browse code

core: new parameter - max_branches

- the maximum number of uac branches can be set via config
- default value is 12 (old static value for MAX_BRNACHES)
- the upper limit is 31, it has to be at least 1
- example:
max_branches=16

Daniel-Constantin Mierla authored on 17/10/2014 09:04:23
Showing 1 changed files
... ...
@@ -166,10 +166,8 @@ struct dns_hash_entry{
166 166
 };
167 167
 
168 168
 
169
-#if MAX_BRANCHES < 16
170
-/* forking is limited by tm to 12 by default */
171
-typedef unsigned short srv_flags_t;
172
-#elif MAX_BRANCHES < 32
169
+/* to fit in the limit of MAX_BRANCHES */
170
+#if MAX_BRANCHES_LIMIT < 32
173 171
 typedef unsigned int srv_flags_t;
174 172
 #else
175 173
 typedef unsigned long long srv_flags_t;
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -19,7 +19,7 @@
19 19
  *
20 20
  * You should have received a copy of the GNU General Public License
21 21
  * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 23
  */
24 24
 
25 25
 /* History:
Browse code

core: Added void to declarations of functions with empty argument list

In C language, a declaration in the form int f(); is equivalent to int f(...);, thus being able to accept an indefinit number of parameters. With the -Wstrict-prototypes GCC options, these declarations are reported as "function declaration isn’t a prototype".
On some cases, this may trick the compiler into generating unoptimized code (like preparing to handle variadic argument list).
In all cases having a declaration int f() and a definition inf f(int) is missleading, even if standard compliant.
This is still Work in Progress. (maybe adding the -Wstrict-prototypes option to default is desireable)

Marius Zbihlei authored on 02/04/2012 14:19:17
Showing 1 changed files
... ...
@@ -195,12 +195,12 @@ void fix_dns_flags(str *gname, str *name);
195 195
 int use_dns_failover_fixup(void *handle, str *gname, str *name, void **val);
196 196
 int use_dns_cache_fixup(void *handle, str *gname, str *name, void **val);
197 197
 int dns_cache_max_mem_fixup(void *handle, str *gname, str *name, void **val);
198
-int init_dns_cache();
198
+int init_dns_cache(void);
199 199
 #ifdef USE_DNS_CACHE_STATS
200 200
 int init_dns_cache_stats(int iproc_num);
201 201
 #define DNS_CACHE_ALL_STATS "dc_all_stats"
202 202
 #endif
203
-void destroy_dns_cache();
203
+void destroy_dns_cache(void);
204 204
 
205 205
 
206 206
 void dns_hash_put(struct dns_hash_entry* e);
Browse code

dns_cache: remove unused err_flags variable

err_flags is deleted from the dns_rr structure.
This flag was checked sometimes, but its value was never
set. Anyway, this flag contained duplicated information
because the parent structure, dns_hash_entry, has a similar
flag (ent_flags & DNS_FLAG_BAD_NAME). And a single hash
entry cannot contain both positive and negative resource
records at the same time.

Miklos Tirpak authored on 16/06/2010 14:09:31
Showing 1 changed files
... ...
@@ -135,8 +135,6 @@ struct dns_rr{
135 135
 	struct dns_rr* next;
136 136
 	void* rdata; /**< depends on the type */
137 137
 	ticks_t expire; /**< = ttl + crt_time */
138
-	unsigned char err_flags; /**< if 0 everything is ok */
139
-
140 138
 };
141 139
 
142 140
 
Browse code

dns_cache: added support for permanent entries

Permanent entries are intended to be used for management
purposes, i.e. they are useful if there is no DNS server
available for instance. Such entries never expire, and overwrite
any existing entry that was added by the resolver.
They can be added to the cache from modules or over the RPC calls
dns.add_a, dns.add_aaaa and dns.add_srv with the flag value of 2.
(or 3 in case of negative permanent entry)

- err_flags in struct dns_hash_entry is changed to be a general
purpose flag, and renamed to ent_flag.
- DNS_BAD_NAME is renamed to DNS_FLAG_BAD_NAME
- DNS_FLAG_PERMANENT value is added.
- new rpc call to force deleting the permanent entries from the
cache: dns.delete_all_force. (dns.delete_all deletes only
the non-permanent entries.)

Miklos Tirpak authored on 16/06/2010 13:49:24
Showing 1 changed files
... ...
@@ -100,8 +100,14 @@ enum dns_errors{
100 100
 /** @brief return a short string, printable error description (err <=0) */
101 101
 const char* dns_strerror(int err);
102 102
 
103
-/** @brief dns entry error flags */
104
-#define DNS_BAD_NAME     1 /* unresolvable */
103
+/** @brief dns entry flags,
104
+ * shall be on the power of 2 */
105
+/*@{ */
106
+#define DNS_FLAG_BAD_NAME	1 /**< error flag: unresolvable */
107
+#define DNS_FLAG_PERMANENT	2 /**< permanent record, never times out,
108
+					never deleted, never overwritten
109
+					unless explicitely requested */
110
+/*@} */
105 111
 
106 112
 /** @name dns requests flags */
107 113
 /*@{ */
... ...
@@ -155,7 +161,7 @@ struct dns_hash_entry{
155 161
 	ticks_t expire; /* when the whole entry will expire */
156 162
 	int total_size;
157 163
 	unsigned short type;
158
-	unsigned char err_flags;
164
+	unsigned char ent_flags; /* entry flags: unresolvable/permanent */
159 165
 	unsigned char name_len; /* can be maximum 255 bytes */
160 166
 	char name[1]; /* variable length, name, null terminated
161 167
 	                 (actual lenght = name_len +1)*/
... ...
@@ -336,8 +342,11 @@ inline static int dns_sip_resolve2su(struct dns_srv_handle* h,
336 342
 	return ret;
337 343
 }
338 344
 
339
-/** @brief deletes all the entries from the cache */
340
-void dns_cache_flush(void);
345
+/** @brief Delete all the entries from the cache.
346
+ * If del_permanent is 0, then only the
347
+ * non-permanent entries are deleted.
348
+ */
349
+void dns_cache_flush(int del_permanent);
341 350
 
342 351
 #ifdef DNS_WATCHDOG_SUPPORT
343 352
 /** @brief sets the state of the DNS servers:
... ...
@@ -355,6 +364,10 @@ int dns_get_server_state(void);
355 364
  * (ip address in case of A/AAAA record, name in case of SRV record)
356 365
  * only the remaining fields are updated.
357 366
  *
367
+ * Note that permanent records cannot be overwritten unless
368
+ * the new record is also permanent. A permanent record
369
+ * completely replaces a non-permanent one.
370
+ *
358 371
  * Currently only A, AAAA, and SRV records are supported.
359 372
  */
360 373
 int dns_cache_add_record(unsigned short type,
Browse code

dns_cache: dns_cache_delete_single_record() added

The function deletes a single resource record
of an existing DNS entry. If the entry has only one
record then the entire entry is deleted.

The resource record is identified by its name, type,
and value, i.e. ip addres in case of A/AAAA record,
target name in case of SRV record.

Only A, AAAA, and SRV records are supported.

Miklos Tirpak authored on 15/06/2010 08:15:46
Showing 1 changed files
... ...
@@ -350,7 +350,7 @@ void dns_set_server_state(int state);
350 350
 int dns_get_server_state(void);
351 351
 #endif /* DNS_WATCHDOG_SUPPORT */
352 352
 
353
-/* Adds a new record to the cache.
353
+/** @brief Adds a new record to the cache.
354 354
  * If there is an existing record with the same name and value
355 355
  * (ip address in case of A/AAAA record, name in case of SRV record)
356 356
  * only the remaining fields are updated.
... ...
@@ -366,5 +366,16 @@ int dns_cache_add_record(unsigned short type,
366 366
 			int port,
367 367
 			int flags);
368 368
 
369
+/** @brief Delete a single record from the cache,
370
+ * i.e. the record with the same name and value
371
+ * (ip address in case of A/AAAA record, name in case of SRV record).
372
+ *
373
+ * Currently only A, AAAA, and SRV records are supported.
374
+ */
375
+int dns_cache_delete_single_record(unsigned short type,
376
+			str *name,
377
+			str *value,
378
+			int flags);
379
+
369 380
 
370 381
 #endif
Browse code

dns_cahce: add_record function exported

dns_cache_add_record() function has been separated
from the RPC interface so that it can be used also
from other places.

Miklos Tirpak authored on 09/11/2009 15:35:29
Showing 1 changed files
... ...
@@ -350,4 +350,21 @@ void dns_set_server_state(int state);
350 350
 int dns_get_server_state(void);
351 351
 #endif /* DNS_WATCHDOG_SUPPORT */
352 352
 
353
+/* Adds a new record to the cache.
354
+ * If there is an existing record with the same name and value
355
+ * (ip address in case of A/AAAA record, name in case of SRV record)
356
+ * only the remaining fields are updated.
357
+ *
358
+ * Currently only A, AAAA, and SRV records are supported.
359
+ */
360
+int dns_cache_add_record(unsigned short type,
361
+			str *name,
362
+			int ttl,
363
+			str *value,
364
+			int priority,
365
+			int weight,
366
+			int port,
367
+			int flags);
368
+
369
+
353 370
 #endif
Browse code

Doxygen updates

oej authored on 25/10/2009 19:11:28
Showing 1 changed files
... ...
@@ -12,11 +12,6 @@
12 12
  * the Free Software Foundation; either version 2 of the License, or
13 13
  * (at your option) any later version
14 14
  *
15
- * For a license to use the ser software under conditions
16
- * other than those described here, or to purchase support for this
17
- * software, please contact iptel.org by e-mail at the following addresses:
18
- *    info@iptel.org
19
- *
20 15
  * ser is distributed in the hope that it will be useful,
21 16
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 17
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
... ...
@@ -26,6 +21,7 @@
26 21
  * along with this program; if not, write to the Free Software
27 22
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 23
  */
24
+
29 25
 /* History:
30 26
  * --------
31 27
  *  2006-07-13  created by andrei
... ...
@@ -33,6 +29,14 @@
33 29
  *  2007-07-30  DNS cache measurements added (Gergo)
34 30
  */
35 31
 
32
+/**
33
+ * @file
34
+ * @brief SIP-router core :: resolver/dns related functions, dns cache and failover
35
+ * @ingroup core
36
+ * Module: @ref core
37
+ */
38
+
39
+
36 40
 
37 41
 #ifndef __dns_cache_h
38 42
 #define __dns_cache_h
... ...
@@ -58,69 +62,74 @@
58 62
 #define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
59 63
 #define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
60 64
 
61
-/* uncomment the define below for SRV weight based load balancing */
65
+/** @brief uncomment the define below for SRV weight based load balancing */
62 66
 #define DNS_SRV_LB
63 67
 
64 68
 #define DNS_LU_LST
65 69
 
66
-/* dns functions return them as negative values (e.g. return -E_DNS_NO_IP)
70
+/** @brief dns functions return them as negative values (e.g. return -E_DNS_NO_IP)
71
+ *
67 72
  * listed in the order of importance ( if more errors, only the most important
68 73
  * is returned)
69 74
  */
70 75
 enum dns_errors{
71 76
 					E_DNS_OK=0,
72
-					E_DNS_EOR, /* no more records (not an error)
77
+					E_DNS_EOR, /**< no more records (not an error)
73 78
 					              -- returned only by the dns_resolve*
74 79
 								  functions when called iteratively,; it
75 80
 								  signals the end of the ip/records list */
76
-					E_DNS_UNKNOWN /* unkown error */,
77
-					E_DNS_INTERNAL_ERR /* internal error */,
81
+					E_DNS_UNKNOWN /**< unkown error */,
82
+					E_DNS_INTERNAL_ERR /**< internal error */,
78 83
 					E_DNS_BAD_SRV_ENTRY,
79
-					E_DNS_NO_SRV /* unresolvable srv record */,
84
+					E_DNS_NO_SRV /**< unresolvable srv record */,
80 85
 					E_DNS_BAD_IP_ENTRY,
81
-					E_DNS_NO_IP /* unresolvable a or aaaa records*/,
82
-					E_DNS_BAD_IP /* the ip is invalid */,
83
-					E_DNS_BLACKLIST_IP /* the ip is blacklisted */,
84
-					E_DNS_NAME_TOO_LONG /* try again with a shorter name */,
85
-					E_DNS_AF_MISMATCH /* ipv4 or ipv6 only requested, but
86
+					E_DNS_NO_IP /**< unresolvable a or aaaa records*/,
87
+					E_DNS_BAD_IP /**< the ip is invalid */,
88
+					E_DNS_BLACKLIST_IP /**< the ip is blacklisted */,
89
+					E_DNS_NAME_TOO_LONG /**< try again with a shorter name */,
90
+					E_DNS_AF_MISMATCH /**< ipv4 or ipv6 only requested, but
86 91
 										 name contains an ip addr. of the
87 92
 										 opossite type */ ,
88
-					E_DNS_NO_NAPTR /* unresolvable naptr record */,
89
-					E_DNS_CRITICAL /* critical error, marks the end
93
+					E_DNS_NO_NAPTR /**< unresolvable naptr record */,
94
+					E_DNS_CRITICAL /**< critical error, marks the end
90 95
 									  of the error table (always last) */
91 96
 };
92 97
 
93 98
 
94 99
 
95
-/* return a short string, printable error description (err <=0) */
100
+/** @brief return a short string, printable error description (err <=0) */
96 101
 const char* dns_strerror(int err);
97 102
 
98
-/* dns entry error flags */
103
+/** @brief dns entry error flags */
99 104
 #define DNS_BAD_NAME     1 /* unresolvable */
100 105
 
101
-/* dns requests flags */
106
+/** @name dns requests flags */
107
+/*@{ */
102 108
 #define DNS_NO_FLAGS	0
103 109
 #define DNS_IPV4_ONLY	1
104 110
 #define DNS_IPV6_ONLY	2
105 111
 #define DNS_IPV6_FIRST	4
106
-#define DNS_SRV_RR_LB	8  /* SRV RR weight based load balancing */
107
-#define DNS_TRY_NAPTR	16 /* enable naptr lookup */
112
+#define DNS_SRV_RR_LB	8  /**< SRV RR weight based load balancing */
113
+#define DNS_TRY_NAPTR	16 /**< enable naptr lookup */
114
+/*@} */
108 115
 
109 116
 
110
-/* ip blacklist error flags */
117
+/** @name ip blacklist error flags */
118
+/*@{ */
111 119
 #define IP_ERR_BAD_DST      2 /* destination is marked as bad (e.g. bad ip) */
112 120
 #define IP_ERR_SND          3 /* send error while using this as destination */
113 121
 #define IP_ERR_TIMEOUT      4 /* timeout waiting for a response */
114 122
 #define IP_ERR_TCP_CON      5 /* could not establish tcp connection */
123
+/*@} */
115 124
 
116 125
 
117
-/* stripped down dns rr */
126
+/** @brief stripped down dns rr 
127
+	@note name, type and class are not needed, contained in struct dns_query */
118 128
 struct dns_rr{
119 129
 	struct dns_rr* next;
120
-	void* rdata; /* depends on the type */
121
-	/* name, type and class are not needed, contained in struct dns_query */
122
-	ticks_t expire; /* = ttl + crt_time */
123
-	unsigned char err_flags; /* if 0 everything is ok */
130
+	void* rdata; /**< depends on the type */
131
+	ticks_t expire; /**< = ttl + crt_time */
132
+	unsigned char err_flags; /**< if 0 everything is ok */
124 133
 
125 134
 };
126 135
 
... ...
@@ -163,15 +172,15 @@ typedef unsigned long long srv_flags_t;
163 172
 #endif
164 173
 
165 174
 struct dns_srv_handle{
166
-	struct dns_hash_entry* srv; /* srv entry */
167
-	struct dns_hash_entry* a;   /* a or aaaa current entry */
175
+	struct dns_hash_entry* srv; /**< srv entry */
176
+	struct dns_hash_entry* a;   /**< a or aaaa current entry */
168 177
 #ifdef DNS_SRV_LB
169 178
 	srv_flags_t srv_tried_rrs;
170 179
 #endif
171
-	unsigned short port; /* current port */
172
-	unsigned char srv_no; /* current record no. in the srv entry */
173
-	unsigned char ip_no;  /* current record no. in the a/aaaa entry */
174
-	unsigned char proto;  /* protocol number */
180
+	unsigned short port; /**< current port */
181
+	unsigned char srv_no; /**< current record no. in the srv entry */
182
+	unsigned char ip_no;  /**< current record no. in the a/aaaa entry */
183
+	unsigned char proto;  /**< protocol number */
175 184
 };
176 185
 
177 186
 
... ...
@@ -209,7 +218,7 @@ inline static void dns_srv_handle_put(struct dns_srv_handle* h)
209 218
 
210 219
 
211 220
 
212
-/* use it when copying, it manually increases the ref cound */
221
+/** @brief use it when copying, it manually increases the ref cound */
213 222
 inline static void dns_srv_handle_ref(struct dns_srv_handle *h)
214 223
 {
215 224
 	if (h){
... ...
@@ -222,7 +231,7 @@ inline static void dns_srv_handle_ref(struct dns_srv_handle *h)
222 231
 
223 232
 
224 233
 
225
-/* safe copy increases the refcnt, src must not change while in this function
234
+/** @brief safe copy increases the refcnt, src must not change while in this function
226 235
  * WARNING: the copy must be dns_srv_handle_put ! */
227 236
 inline static void dns_srv_handle_cpy(struct dns_srv_handle* dst,
228 237
 										struct dns_srv_handle* src)
... ...
@@ -233,7 +242,7 @@ inline static void dns_srv_handle_cpy(struct dns_srv_handle* dst,
233 242
 
234 243
 
235 244
 
236
-/* same as above but assume shm_lock held (for internal tm use only) */
245
+/** @brief same as above but assume shm_lock held (for internal tm use only) */
237 246
 inline static void dns_srv_handle_put_shm_unsafe(struct dns_srv_handle* h)
238 247
 {
239 248
 	if (h){
... ...
@@ -250,7 +259,7 @@ inline static void dns_srv_handle_put_shm_unsafe(struct dns_srv_handle* h)
250 259
 
251 260
 
252 261
 
253
-/* get "next" ip next time a dns_srv_handle function is called
262
+/** @brief get "next" ip next time a dns_srv_handle function is called
254 263
  * params: h   - struct dns_srv_handler
255 264
  *         err - return code of the last dns_*_resolve* call
256 265
  * returns: 0 if it doesn't make sense to try another record,
... ...
@@ -278,7 +287,7 @@ inline static void dns_srv_handle_init(struct dns_srv_handle* h)
278 287
 
279 288
 
280 289
 
281
-/* performes a srv query on name
290
+/** @brief performes a srv query on name
282 291
  * Params:  name  - srv query target (e.g. _sip._udp.foo.bar)
283 292
  *          ip    - result: first good ip found
284 293
  *          port  - result: corresponding port number
... ...
@@ -288,7 +297,7 @@ inline static void dns_srv_handle_init(struct dns_srv_handle* h)
288 297
 int dns_srv_get_ip(str* name, struct ip_addr* ip, unsigned short* port,
289 298
 					int flags);
290 299
 
291
-/* performs an A, AAAA (or both) query/queries
300
+/** @brief performs an A, AAAA (or both) query/queries
292 301
  * Params:  name  - query target (e.g. foo.bar)
293 302
  *          ip    - result: first good ip found
294 303
  *          flags - resolve options (like ipv4 only, ipv6 prefered a.s.o)
... ...
@@ -300,7 +309,7 @@ struct hostent* dns_srv_get_he(str* name, unsigned short* port, int flags);
300 309
 struct hostent* dns_get_he(str* name, int flags);
301 310
 
302 311
 
303
-/* resolve name to an ip, using srv record. Can be called multiple times
312
+/** @brief resolve name to an ip, using srv record. Can be called multiple times
304 313
  * to iterate on all the possible ips, e.g :
305 314
  * dns_srv_handle_init(h);
306 315
  * ret_code=dns_sip_resolve(h,...);
... ...
@@ -312,7 +321,7 @@ struct hostent* dns_get_he(str* name, int flags);
312 321
 int dns_sip_resolve(struct dns_srv_handle* h,  str* name, struct ip_addr* ip,
313 322
 					unsigned short* port, char* proto, int flags);
314 323
 
315
-/* same as above, but fills su intead of changing port and filling an ip */
324
+/** @brief same as above, but fills su intead of changing port and filling an ip */
316 325
 inline static int dns_sip_resolve2su(struct dns_srv_handle* h,
317 326
 									 union sockaddr_union* su,
318 327
 									 str* name, unsigned short port,
... ...
@@ -327,17 +336,17 @@ inline static int dns_sip_resolve2su(struct dns_srv_handle* h,
327 336
 	return ret;
328 337
 }
329 338
 
330
-/* deletes all the entries from the cache */
339
+/** @brief deletes all the entries from the cache */
331 340
 void dns_cache_flush(void);
332 341
 
333 342
 #ifdef DNS_WATCHDOG_SUPPORT
334
-/* sets the state of the DNS servers:
343
+/** @brief sets the state of the DNS servers:
335 344
  * 1: at least one server is up
336 345
  * 0: all the servers are down
337 346
  */
338 347
 void dns_set_server_state(int state);
339 348
 
340
-/* returns the state of the DNS servers */
349
+/** @brief returns the state of the DNS servers */
341 350
 int dns_get_server_state(void);
342 351
 #endif /* DNS_WATCHDOG_SUPPORT */
343 352
 
Browse code

The fixup function prototypes of the config variables have been extended with the group name. All the fixup functions have been updated.

Miklos Tirpak authored on 13/03/2009 13:59:28
Showing 1 changed files
... ...
@@ -178,10 +178,10 @@ struct dns_srv_handle{
178 178
 
179 179
 const char* dns_strerror(int err);
180 180
 
181
-void fix_dns_flags(str *name);
182
-int use_dns_failover_fixup(void *handle, str *name, void **val);
183
-int use_dns_cache_fixup(void *handle, str *name, void **val);
184
-int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
181
+void fix_dns_flags(str *gname, str *name);
182
+int use_dns_failover_fixup(void *handle, str *gname, str *name, void **val);
183
+int use_dns_cache_fixup(void *handle, str *gname, str *name, void **val);
184
+int dns_cache_max_mem_fixup(void *handle, str *gname, str *name, void **val);
185 185
 int init_dns_cache();
186 186
 #ifdef USE_DNS_CACHE_STATS
187 187
 int init_dns_cache_stats(int iproc_num);
Browse code

- use_dns_cache can be enabled/disabled runtime - dns_cache_init is introduced: if set to 0, the dns cache is not initialized, and cannot be enabled later (default is 1) - dst_blacklist_init is introduced: if set to 0, the dst blacklist is not initialized (similar to dns_cache_init) (default is 1)

Miklos Tirpak authored on 11/02/2008 17:11:59
Showing 1 changed files
... ...
@@ -180,6 +180,7 @@ const char* dns_strerror(int err);
180 180
 
181 181
 void fix_dns_flags(str *name);
182 182
 int use_dns_failover_fixup(void *handle, str *name, void **val);
183
+int use_dns_cache_fixup(void *handle, str *name, void **val);
183 184
 int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
184 185
 int init_dns_cache();
185 186
 #ifdef USE_DNS_CACHE_STATS
Browse code

DNS resolver and cache parameters use the configuration framework that makes the config variables changeable on-the-fly.

- The resolver is reinitialized by each child process separately
when dns_retr_time, dns_retr_no, dns_servers_no, or dns_use_search_list
is changed.

- dns_reinit is introduced: the resolver is reinitialized when the
variable is set to 1, and the variable is reseted to 0 again.
It can be set via RPC for example, when /etc/resolv.conf changes,
but none of the SER config parameters are affected.

- A callback function is called by each child process after the resolver
has been reinitialized, if DNS_WATCHDOG_SUPPORT is enabled.

- socket_types is changed to be a global variable, and set by
fix_all_socket_lists(), because we have to remember for
the socket types, and do not allow dns_try_ipv6 to be enabled if there
is no ipv6 interface.

- minor bug is corrected: the expiration check is removed from
dns_cache_clean() function, when non-expired entries are deleted.

Miklos Tirpak authored on 11/02/2008 09:58:29
Showing 1 changed files
... ...
@@ -53,6 +53,11 @@
53 53
 #error "DNS WATCHDOG requires DNS CACHE support (define USE_DNS_CACHE)"
54 54
 #endif
55 55
 
56
+#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
57
+#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
58
+#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
59
+#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
60
+
56 61
 /* uncomment the define below for SRV weight based load balancing */
57 62
 #define DNS_SRV_LB
58 63
 
... ...
@@ -173,6 +178,9 @@ struct dns_srv_handle{
173 178
 
174 179
 const char* dns_strerror(int err);
175 180
 
181
+void fix_dns_flags(str *name);
182
+int use_dns_failover_fixup(void *handle, str *name, void **val);
183
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
176 184
 int init_dns_cache();
177 185
 #ifdef USE_DNS_CACHE_STATS
178 186
 int init_dns_cache_stats(int iproc_num);
Browse code

dns_get_server_state() implemented which returns the state of the DNS servers

Miklos Tirpak authored on 22/08/2007 15:10:13
Showing 1 changed files
... ...
@@ -327,6 +327,9 @@ void dns_cache_flush(void);
327 327
  * 0: all the servers are down
328 328
  */
329 329
 void dns_set_server_state(int state);
330
+
331
+/* returns the state of the DNS servers */
332
+int dns_get_server_state(void);
330 333
 #endif /* DNS_WATCHDOG_SUPPORT */
331 334
 
332 335
 #endif
Browse code

- DNS cache measurements added

Gergely Kovacs authored on 31/07/2007 13:27:09
Showing 1 changed files
... ...
@@ -22,14 +22,15 @@
22 22
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 23
  * GNU General Public License for more details.
24 24
  *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program; if not, write to the Free Software
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 28
  */
29