- 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)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,823 +0,0 @@ |
1 |
-/* |
|
2 |
- * |
|
3 |
- * ip address family related structures |
|
4 |
- * |
|
5 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
6 |
- * |
|
7 |
- * This file is part of Kamailio, a free SIP server. |
|
8 |
- * |
|
9 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
10 |
- * it under the terms of the GNU General Public License as published by |
|
11 |
- * the Free Software Foundation; either version 2 of the License, or |
|
12 |
- * (at your option) any later version |
|
13 |
- * |
|
14 |
- * Kamailio is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU General Public License for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
21 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
- */ |
|
23 |
-/*! |
|
24 |
-* \file |
|
25 |
-* \brief Kamailio core :: ip address family related structures |
|
26 |
-* \ingroup core |
|
27 |
-* Module: \ref core |
|
28 |
-*/ |
|
29 |
- |
|
30 |
-#ifndef ip_addr_h |
|
31 |
-#define ip_addr_h |
|
32 |
- |
|
33 |
-#include <string.h> |
|
34 |
-#include <sys/types.h> |
|
35 |
-#include <sys/socket.h> |
|
36 |
-#include <netinet/in.h> |
|
37 |
-#include <netdb.h> |
|
38 |
-#include "str.h" |
|
39 |
-#include "compiler_opt.h" |
|
40 |
-#include "ut.h" |
|
41 |
- |
|
42 |
- |
|
43 |
-#include "dprint.h" |
|
44 |
- |
|
45 |
-enum sip_protos { PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_SCTP, PROTO_WS, PROTO_WSS, PROTO_OTHER }; |
|
46 |
-#define PROTO_LAST PROTO_OTHER |
|
47 |
- |
|
48 |
-#ifdef USE_COMP |
|
49 |
-enum comp_methods { COMP_NONE, COMP_SIGCOMP, COMP_SERGZ }; |
|
50 |
-#endif |
|
51 |
- |
|
52 |
-struct ip_addr{ |
|
53 |
- unsigned int af; /* address family: AF_INET6 or AF_INET */ |
|
54 |
- unsigned int len; /* address len, 16 or 4 */ |
|
55 |
- |
|
56 |
- /* 64 bits aligned address */ |
|
57 |
- union { |
|
58 |
- unsigned long addrl[16/sizeof(long)]; /* long format*/ |
|
59 |
- unsigned int addr32[4]; |
|
60 |
- unsigned short addr16[8]; |
|
61 |
- unsigned char addr[16]; |
|
62 |
- }u; |
|
63 |
-}; |
|
64 |
- |
|
65 |
-typedef struct ip_addr ip_addr_t; |
|
66 |
- |
|
67 |
-struct net{ |
|
68 |
- struct ip_addr ip; |
|
69 |
- struct ip_addr mask; |
|
70 |
-}; |
|
71 |
- |
|
72 |
-union sockaddr_union{ |
|
73 |
- struct sockaddr s; |
|
74 |
- struct sockaddr_in sin; |
|
75 |
- struct sockaddr_in6 sin6; |
|
76 |
-}; |
|
77 |
- |
|
78 |
- |
|
79 |
- |
|
80 |
-enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, |
|
81 |
- SI_IS_ANY=8, SI_IS_MHOMED=16 }; |
|
82 |
- |
|
83 |
-struct addr_info{ |
|
84 |
- str name; /* name - eg.: foo.bar or 10.0.0.1 */ |
|
85 |
- struct ip_addr address; /*ip address */ |
|
86 |
- str address_str; /*ip address converted to string -- optimization*/ |
|
87 |
- enum si_flags flags; /* SI_IS_IP | SI_IS_LO | SI_IS_MCAST */ |
|
88 |
- union sockaddr_union su; |
|
89 |
- struct addr_info* next; |
|
90 |
- struct addr_info* prev; |
|
91 |
-}; |
|
92 |
- |
|
93 |
-struct advertise_info { |
|
94 |
- str name; /* name - eg.: foo.bar or 10.0.0.1 */ |
|
95 |
- unsigned short port_no; /* port number */ |
|
96 |
- str port_no_str; /* port number converted to string -- optimization*/ |
|
97 |
- str address_str; /*ip address converted to string -- optimization*/ |
|
98 |
- struct ip_addr address; /* ip address */ |
|
99 |
- str sock_str; /* Socket proto, ip, and port as string */ |
|
100 |
-}; |
|
101 |
- |
|
102 |
-struct socket_info{ |
|
103 |
- int socket; |
|
104 |
- str name; /* name - eg.: foo.bar or 10.0.0.1 */ |
|
105 |
- struct ip_addr address; /* ip address */ |
|
106 |
- str address_str; /*ip address converted to string -- optimization*/ |
|
107 |
- str port_no_str; /* port number converted to string -- optimization*/ |
|
108 |
- enum si_flags flags; /* SI_IS_IP | SI_IS_LO | SI_IS_MCAST */ |
|
109 |
- union sockaddr_union su; |
|
110 |
- struct socket_info* next; |
|
111 |
- struct socket_info* prev; |
|
112 |
- unsigned short port_no; /* port number */ |
|
113 |
- char proto; /* tcp or udp*/ |
|
114 |
- str sock_str; /* Socket proto, ip, and port as string */ |
|
115 |
- struct addr_info* addr_info_lst; /* extra addresses (e.g. SCTP mh) */ |
|
116 |
- int workers; /* number of worker processes for this socket */ |
|
117 |
- int workers_tcpidx; /* index of workers in tcp children array */ |
|
118 |
- struct advertise_info useinfo; /* details to be used in SIP msg */ |
|
119 |
-#ifdef USE_MCAST |
|
120 |
- str mcast; /* name of interface that should join multicast group*/ |
|
121 |
-#endif /* USE_MCAST */ |
|
122 |
-}; |
|
123 |
- |
|
124 |
- |
|
125 |
-struct receive_info{ |
|
126 |
- struct ip_addr src_ip; |
|
127 |
- struct ip_addr dst_ip; |
|
128 |
- unsigned short src_port; /* host byte order */ |
|
129 |
- unsigned short dst_port; /* host byte order */ |
|
130 |
- int proto_reserved1; /* tcp stores the connection id here */ |
|
131 |
- int proto_reserved2; |
|
132 |
- union sockaddr_union src_su; /* useful for replies*/ |
|
133 |
- struct socket_info* bind_address; /* sock_info structure on which |
|
134 |
- the msg was received*/ |
|
135 |
- char proto; |
|
136 |
-#ifdef USE_COMP |
|
137 |
- short comp; /* compression */ |
|
138 |
-#endif |
|
139 |
- /* no need for dst_su yet */ |
|
140 |
-}; |
|
141 |
- |
|
142 |
-typedef struct sr_net_info { |
|
143 |
- str data; |
|
144 |
- struct dest_info* dst; |
|
145 |
- struct receive_info* rcv; |
|
146 |
-} sr_net_info_t; |
|
147 |
- |
|
148 |
-/* send flags */ |
|
149 |
-#define SND_F_FORCE_CON_REUSE 1 /* reuse an existing connection or fail */ |
|
150 |
-#define SND_F_CON_CLOSE 2 /* close the connection after sending */ |
|
151 |
-#define SND_F_FORCE_SOCKET 4 /* send socket in dst is forced */ |
|
152 |
- |
|
153 |
-struct snd_flags { |
|
154 |
- unsigned char f; /* snd flags */ |
|
155 |
- unsigned char blst_imask; /* blacklist ignore mask */ |
|
156 |
-}; |
|
157 |
- |
|
158 |
- |
|
159 |
-typedef struct snd_flags snd_flags_t; |
|
160 |
- |
|
161 |
-#define SND_FLAGS_INIT(sflags) \ |
|
162 |
- do{ \ |
|
163 |
- (sflags)->f=0; \ |
|
164 |
- (sflags)->blst_imask=0; \ |
|
165 |
- }while(0) |
|
166 |
- |
|
167 |
-#define SND_FLAGS_OR(dst, src1, src2) \ |
|
168 |
- do{ \ |
|
169 |
- (dst)->f = (src1)->f | (src2)->f; \ |
|
170 |
- (dst)->blst_imask = (src1)->blst_imask | (src2)->blst_imask; \ |
|
171 |
- }while(0) |
|
172 |
- |
|
173 |
-#define SND_FLAGS_AND(dst, src1, src2) \ |
|
174 |
- do{ \ |
|
175 |
- (dst)->f = (src1)->f & (src2)->f; \ |
|
176 |
- (dst)->blst_imask = (src1)->blst_imask & (src2)->blst_imask; \ |
|
177 |
- }while(0) |
|
178 |
- |
|
179 |
-struct dest_info{ |
|
180 |
- struct socket_info* send_sock; |
|
181 |
- union sockaddr_union to; |
|
182 |
- int id; /* tcp stores the connection id here */ |
|
183 |
- char proto; |
|
184 |
- snd_flags_t send_flags; |
|
185 |
-#ifdef USE_COMP |
|
186 |
- short comp; |
|
187 |
-#endif |
|
188 |
-}; |
|
189 |
- |
|
190 |
- |
|
191 |
-/* list of names for multi-homed sockets that need to bind on |
|
192 |
- * multiple addresses in the same time (sctp ) */ |
|
193 |
-struct name_lst{ |
|
194 |
- char* name; |
|
195 |
- struct name_lst* next; |
|
196 |
- int flags; |
|
197 |
-}; |
|
198 |
- |
|
199 |
- |
|
200 |
-struct socket_id{ |
|
201 |
- struct name_lst* addr_lst; /* address list, the first one must |
|
202 |
- be present and is the main one |
|
203 |
- (in case of multihoming sctp)*/ |
|
204 |
- int flags; |
|
205 |
- int proto; |
|
206 |
- int port; |
|
207 |
- struct socket_id* next; |
|
208 |
-}; |
|
209 |
- |
|
210 |
- |
|
211 |
- |
|
212 |
-/* len of the sockaddr */ |
|
213 |
-#ifdef HAVE_SOCKADDR_SA_LEN |
|
214 |
-#define sockaddru_len(su) ((su).s.sa_len) |
|
215 |
-#else |
|
216 |
-#define sockaddru_len(su) \ |
|
217 |
- (((su).s.sa_family==AF_INET6)?sizeof(struct sockaddr_in6):\ |
|
218 |
- sizeof(struct sockaddr_in)) |
|
219 |
-#endif /* HAVE_SOCKADDR_SA_LEN*/ |
|
220 |
- |
|
221 |
-/* inits an ip_addr with the addr. info from a hostent structure |
|
222 |
- * ip = struct ip_addr* |
|
223 |
- * he= struct hostent* |
|
224 |
- */ |
|
225 |
-#define hostent2ip_addr(ip, he, addr_no) \ |
|
226 |
- do{ \ |
|
227 |
- (ip)->af=(he)->h_addrtype; \ |
|
228 |
- (ip)->len=(he)->h_length; \ |
|
229 |
- memcpy((ip)->u.addr, (he)->h_addr_list[(addr_no)], (ip)->len); \ |
|
230 |
- }while(0) |
|
231 |
- |
|
232 |
- |
|
233 |
- |
|
234 |
- |
|
235 |
-/* gets the protocol family corresponding to a specific address family |
|
236 |
- * ( PF_INET - AF_INET, PF_INET6 - AF_INET6, af for others) |
|
237 |
- */ |
|
238 |
-#define AF2PF(af) (((af)==AF_INET)?PF_INET:((af)==AF_INET6)?PF_INET6:(af)) |
|
239 |
- |
|
240 |
- |
|
241 |
- |
|
242 |
- |
|
243 |
-struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask); |
|
244 |
-struct net* mk_new_net_bitlen(struct ip_addr* ip, unsigned int bitlen); |
|
245 |
-int mk_net(struct net* n, struct ip_addr* ip, struct ip_addr* mask); |
|
246 |
-int mk_net_bitlen(struct net* n, struct ip_addr* ip, unsigned int bitlen); |
|
247 |
-int mk_net_str(struct net* dst, str* s); |
|
248 |
- |
|
249 |
-void print_ip(char* prefix, struct ip_addr* ip, char* suffix); |
|
250 |
-void stdout_print_ip(struct ip_addr* ip); |
|
251 |
-void print_net(struct net* net); |
|
252 |
- |
|
253 |
-char* get_proto_name(unsigned int proto); |
|
254 |
-#define proto2a get_proto_name |
|
255 |
- |
|
256 |
-int get_valid_proto_string(unsigned int iproto, int utype, int vtype, |
|
257 |
- str *sproto); |
|
258 |
- |
|
259 |
-#ifdef USE_MCAST |
|
260 |
-/* Returns 1 if the given address is a multicast address */ |
|
261 |
-int is_mcast(struct ip_addr* ip); |
|
262 |
-#endif /* USE_MCAST */ |
|
263 |
- |
|
264 |
-/* returns 1 if the given ip address is INADDR_ANY or IN6ADDR_ANY, |
|
265 |
- * 0 otherwise */ |
|
266 |
-inline static int ip_addr_any(struct ip_addr* ip) |
|
267 |
-{ |
|
268 |
- int r; |
|
269 |
- int l; |
|
270 |
- |
|
271 |
- l=ip->len/4; |
|
272 |
- for (r=0; r<l; r++) |
|
273 |
- if (ip->u.addr32[r]!=0) |
|
274 |
- return 0; |
|
275 |
- return 1; |
|
276 |
-} |
|
277 |
- |
|
278 |
- |
|
279 |
- |
|
280 |
-/* returns 1 if the given ip address is a loopback address |
|
281 |
- * 0 otherwise */ |
|
282 |
-inline static int ip_addr_loopback(struct ip_addr* ip) |
|
283 |
-{ |
|
284 |
- if (ip->af==AF_INET) |
|
285 |
- return ip->u.addr32[0]==htonl(INADDR_LOOPBACK); |
|
286 |
- else if (ip->af==AF_INET6) |
|
287 |
- return IN6_IS_ADDR_LOOPBACK((struct in6_addr*)ip->u.addr32); |
|
288 |
- return 0; |
|
289 |
-} |
|
290 |
- |
|
291 |
- |
|
292 |
- |
|
293 |
-/* creates an ANY ip_addr (filled with 0, af and len properly set) */ |
|
294 |
-inline static void ip_addr_mk_any(int af, struct ip_addr* ip) |
|
295 |
-{ |
|
296 |
- ip->af=af; |
|
297 |
- if (likely(af==AF_INET)){ |
|
298 |
- ip->len=4; |
|
299 |
- ip->u.addr32[0]=0; |
|
300 |
- } |
|
301 |
- else{ |
|
302 |
- ip->len=16; |
|
303 |
-#if (defined (ULONG_MAX) && ULONG_MAX > 4294967295) || defined LP64 |
|
304 |
- /* long is 64 bits */ |
|
305 |
- ip->u.addrl[0]=0; |
|
306 |
- ip->u.addrl[1]=0; |
|
307 |
-#else |
|
308 |
- ip->u.addr32[0]=0; |
|
309 |
- ip->u.addr32[1]=0; |
|
310 |
- ip->u.addr32[2]=0; |
|
311 |
- ip->u.addr32[3]=0; |
|
312 |
-#endif /* ULONG_MAX */ |
|
313 |
- } |
|
314 |
-} |
|
315 |
- |
|
316 |
-/* returns 1 if ip & net.mask == net.ip ; 0 otherwise & -1 on error |
|
317 |
- [ diff. address families ]) */ |
|
318 |
-inline static int matchnet(struct ip_addr* ip, struct net* net) |
|
319 |
-{ |
|
320 |
- unsigned int r; |
|
321 |
- |
|
322 |
- if (ip->af == net->ip.af){ |
|
323 |
- for(r=0; r<ip->len/4; r++){ /* ipv4 & ipv6 addresses are |
|
324 |
- all multiple of 4*/ |
|
325 |
- if ((ip->u.addr32[r]&net->mask.u.addr32[r])!= |
|
326 |
- net->ip.u.addr32[r]){ |
|
327 |
- return 0; |
|
328 |
- } |
|
329 |
- } |
|
330 |
- return 1; |
|
331 |
- }; |
|
332 |
- return -1; |
|
333 |
-} |
|
334 |
- |
|
335 |
- |
|
336 |
- |
|
337 |
- |
|
338 |
-/* inits an ip_addr pointer from a sockaddr structure*/ |
|
339 |
-static inline void sockaddr2ip_addr(struct ip_addr* ip, struct sockaddr* sa) |
|
340 |
-{ |
|
341 |
- switch(sa->sa_family){ |
|
342 |
- case AF_INET: |
|
343 |
- ip->af=AF_INET; |
|
344 |
- ip->len=4; |
|
345 |
- memcpy(ip->u.addr, &((struct sockaddr_in*)sa)->sin_addr, 4); |
|
346 |
- break; |
|
347 |
- case AF_INET6: |
|
348 |
- ip->af=AF_INET6; |
|
349 |
- ip->len=16; |
|
350 |
- memcpy(ip->u.addr, &((struct sockaddr_in6*)sa)->sin6_addr, 16); |
|
351 |
- break; |
|
352 |
- default: |
|
353 |
- LM_CRIT("unknown address family %d\n", sa->sa_family); |
|
354 |
- } |
|
355 |
-} |
|
356 |
- |
|
357 |
- |
|
358 |
- |
|
359 |
-/* compare 2 ip_addrs (both args are pointers)*/ |
|
360 |
-#define ip_addr_cmp(ip1, ip2) \ |
|
361 |
- (((ip1)->af==(ip2)->af)&& \ |
|
362 |
- (memcmp((ip1)->u.addr, (ip2)->u.addr, (ip1)->len)==0)) |
|
363 |
- |
|
364 |
- |
|
365 |
- |
|
366 |
-/* compare 2 sockaddr_unions */ |
|
367 |
-static inline int su_cmp(const union sockaddr_union* s1, |
|
368 |
- const union sockaddr_union* s2) |
|
369 |
-{ |
|
370 |
- if (s1->s.sa_family!=s2->s.sa_family) return 0; |
|
371 |
- switch(s1->s.sa_family){ |
|
372 |
- case AF_INET: |
|
373 |
- return (s1->sin.sin_port==s2->sin.sin_port)&& |
|
374 |
- (memcmp(&s1->sin.sin_addr, &s2->sin.sin_addr, 4)==0); |
|
375 |
- case AF_INET6: |
|
376 |
- return (s1->sin6.sin6_port==s2->sin6.sin6_port)&& |
|
377 |
- (memcmp(&s1->sin6.sin6_addr, &s2->sin6.sin6_addr, 16)==0); |
|
378 |
- default: |
|
379 |
- LM_CRIT("unknown address family %d\n", s1->s.sa_family); |
|
380 |
- return 0; |
|
381 |
- } |
|
382 |
-} |
|
383 |
- |
|
384 |
- |
|
385 |
- |
|
386 |
-/* gets the port number (host byte order) */ |
|
387 |
-static inline unsigned short su_getport(const union sockaddr_union* su) |
|
388 |
-{ |
|
389 |
- switch(su->s.sa_family){ |
|
390 |
- case AF_INET: |
|
391 |
- return ntohs(su->sin.sin_port); |
|
392 |
- case AF_INET6: |
|
393 |
- return ntohs(su->sin6.sin6_port); |
|
394 |
- default: |
|
395 |
- LM_CRIT("unknown address family %d\n", su->s.sa_family); |
|
396 |
- return 0; |
|
397 |
- } |
|
398 |
-} |
|
399 |
- |
|
400 |
- |
|
401 |
- |
|
402 |
-/* sets the port number (host byte order) */ |
|
403 |
-static inline void su_setport(union sockaddr_union* su, unsigned short port) |
|
404 |
-{ |
|
405 |
- switch(su->s.sa_family){ |
|
406 |
- case AF_INET: |
|
407 |
- su->sin.sin_port=htons(port); |
|
408 |
- break; |
|
409 |
- case AF_INET6: |
|
410 |
- su->sin6.sin6_port=htons(port); |
|
411 |
- break; |
|
412 |
- default: |
|
413 |
- LM_CRIT("unknown address family %d\n", su->s.sa_family); |
|
414 |
- } |
|
415 |
-} |
|
416 |
- |
|
417 |
- |
|
418 |
- |
|
419 |
-/* inits an ip_addr pointer from a sockaddr_union ip address */ |
|
420 |
-static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su) |
|
421 |
-{ |
|
422 |
- switch(su->s.sa_family){ |
|
423 |
- case AF_INET: |
|
424 |
- ip->af=AF_INET; |
|
425 |
- ip->len=4; |
|
426 |
- memcpy(ip->u.addr, &su->sin.sin_addr, 4); |
|
427 |
- break; |
|
428 |
- case AF_INET6: |
|
429 |
- ip->af=AF_INET6; |
|
430 |
- ip->len=16; |
|
431 |
- memcpy(ip->u.addr, &su->sin6.sin6_addr, 16); |
|
432 |
- break; |
|
433 |
- default: |
|
434 |
- LM_CRIT("unknown address family %d\n", su->s.sa_family); |
|
435 |
- } |
|
436 |
-} |
|
437 |
- |
|
438 |
- |
|
439 |
-/* ip_addr2su -> the same as init_su*/ |
|
440 |
-#define ip_addr2su init_su |
|
441 |
- |
|
442 |
-/* inits a struct sockaddr_union from a struct ip_addr and a port no |
|
443 |
- * returns 0 if ok, -1 on error (unknown address family) |
|
444 |
- * the port number is in host byte order */ |
|
445 |
-static inline int init_su( union sockaddr_union* su, |
|
446 |
- struct ip_addr* ip, |
|
447 |
- unsigned short port ) |
|
448 |
-{ |
|
449 |
- memset(su, 0, sizeof(union sockaddr_union));/*needed on freebsd*/ |
|
450 |
- su->s.sa_family=ip->af; |
|
451 |
- switch(ip->af){ |
|
452 |
- case AF_INET6: |
|
453 |
- memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len); |
|
454 |
- #ifdef HAVE_SOCKADDR_SA_LEN |
|
455 |
- su->sin6.sin6_len=sizeof(struct sockaddr_in6); |
|
456 |
- #endif |
|
457 |
- su->sin6.sin6_port=htons(port); |
|
458 |
- break; |
|
459 |
- case AF_INET: |
|
460 |
- memcpy(&su->sin.sin_addr, ip->u.addr, ip->len); |
|
461 |
- #ifdef HAVE_SOCKADDR_SA_LEN |
|
462 |
- su->sin.sin_len=sizeof(struct sockaddr_in); |
|
463 |
- #endif |
|
464 |
- su->sin.sin_port=htons(port); |
|
465 |
- break; |
|
466 |
- default: |
|
467 |
- LM_CRIT("unknown address family %d\n", ip->af); |
|
468 |
- return -1; |
|
469 |
- } |
|
470 |
- return 0; |
|
471 |
-} |
|
472 |
- |
|
473 |
- |
|
474 |
- |
|
475 |
-/* inits a struct sockaddr_union from a struct hostent, an address index in |
|
476 |
- * the hostent structure and a port no. (host byte order) |
|
477 |
- * WARNING: no index overflow checks! |
|
478 |
- * returns 0 if ok, -1 on error (unknown address family) */ |
|
479 |
-static inline int hostent2su( union sockaddr_union* su, |
|
480 |
- struct hostent* he, |
|
481 |
- unsigned int idx, |
|
482 |
- unsigned short port ) |
|
483 |
-{ |
|
484 |
- memset(su, 0, sizeof(union sockaddr_union)); /*needed on freebsd*/ |
|
485 |
- su->s.sa_family=he->h_addrtype; |
|
486 |
- switch(he->h_addrtype){ |
|
487 |
- case AF_INET6: |
|
488 |
- memcpy(&su->sin6.sin6_addr, he->h_addr_list[idx], he->h_length); |
|
489 |
- #ifdef HAVE_SOCKADDR_SA_LEN |
|
490 |
- su->sin6.sin6_len=sizeof(struct sockaddr_in6); |
|
491 |
- #endif |
|
492 |
- su->sin6.sin6_port=htons(port); |
|
493 |
- break; |
|
494 |
- case AF_INET: |
|
495 |
- memcpy(&su->sin.sin_addr, he->h_addr_list[idx], he->h_length); |
|
496 |
- #ifdef HAVE_SOCKADDR_SA_LEN |
|
497 |
- su->sin.sin_len=sizeof(struct sockaddr_in); |
|
498 |
- #endif |
|
499 |
- su->sin.sin_port=htons(port); |
|
500 |
- break; |
|
501 |
- default: |
|
502 |
- LM_CRIT("unknown address family %d\n", he->h_addrtype); |
|
503 |
- return -1; |
|
504 |
- } |
|
505 |
- return 0; |
|
506 |
-} |
|
507 |
- |
|
508 |
- |
|
509 |
- |
|
510 |
-/* maximum size of a str returned by ip_addr2str */ |
|
511 |
-#define IP6_MAX_STR_SIZE 39 /*1234:5678:9012:3456:7890:1234:5678:9012*/ |
|
512 |
-#define IP4_MAX_STR_SIZE 15 /*123.456.789.012*/ |
|
513 |
- |
|
514 |
-/* converts a raw ipv6 addr (16 bytes) to ascii */ |
|
515 |
-static inline int ip6tosbuf(unsigned char* ip6, char* buff, int len) |
|
516 |
-{ |
|
517 |
- int offset; |
|
518 |
- register unsigned char a,b,c; |
|
519 |
- register unsigned char d; |
|
520 |
- register unsigned short hex4; |
|
521 |
- int r; |
|
522 |
- #define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0') |
|
523 |
- |
|
524 |
- |
|
525 |
- offset=0; |
|
526 |
- if (unlikely(len<IP6_MAX_STR_SIZE)) |
|
527 |
- return 0; |
|
528 |
- for(r=0;r<7;r++){ |
|
529 |
- hex4=((unsigned char)ip6[r*2]<<8)+(unsigned char)ip6[r*2+1]; |
|
530 |
- a=hex4>>12; |
|
531 |
- b=(hex4>>8)&0xf; |
|
532 |
- c=(hex4>>4)&0xf; |
|
533 |
- d=hex4&0xf; |
|
534 |
- if (a){ |
|
535 |
- buff[offset]=HEXDIG(a); |
|
536 |
- buff[offset+1]=HEXDIG(b); |
|
537 |
- buff[offset+2]=HEXDIG(c); |
|
538 |
- buff[offset+3]=HEXDIG(d); |
|
539 |
- buff[offset+4]=':'; |
|
540 |
- offset+=5; |
|
541 |
- }else if(b){ |
|
542 |
- buff[offset]=HEXDIG(b); |
|
543 |
- buff[offset+1]=HEXDIG(c); |
|
544 |
- buff[offset+2]=HEXDIG(d); |
|
545 |
- buff[offset+3]=':'; |
|
546 |
- offset+=4; |
|
547 |
- }else if(c){ |
|
548 |
- buff[offset]=HEXDIG(c); |
|
549 |
- buff[offset+1]=HEXDIG(d); |
|
550 |
- buff[offset+2]=':'; |
|
551 |
- offset+=3; |
|
552 |
- }else{ |
|
553 |
- buff[offset]=HEXDIG(d); |
|
554 |
- buff[offset+1]=':'; |
|
555 |
- offset+=2; |
|
556 |
- } |
|
557 |
- } |
|
558 |
- /* last int16*/ |
|
559 |
- hex4=((unsigned char)ip6[r*2]<<8)+(unsigned char)ip6[r*2+1]; |
|
560 |
- a=hex4>>12; |
|
561 |
- b=(hex4>>8)&0xf; |
|
562 |
- c=(hex4>>4)&0xf; |
|
563 |
- d=hex4&0xf; |
|
564 |
- if (a){ |
|
565 |
- buff[offset]=HEXDIG(a); |
|
566 |
- buff[offset+1]=HEXDIG(b); |
|
567 |
- buff[offset+2]=HEXDIG(c); |
|
568 |
- buff[offset+3]=HEXDIG(d); |
|
569 |
- offset+=4; |
|
570 |
- }else if(b){ |
|
571 |
- buff[offset]=HEXDIG(b); |
|
572 |
- buff[offset+1]=HEXDIG(c); |
|
573 |
- buff[offset+2]=HEXDIG(d); |
|
574 |
- offset+=3; |
|
575 |
- }else if(c){ |
|
576 |
- buff[offset]=HEXDIG(c); |
|
577 |
- buff[offset+1]=HEXDIG(d); |
|
578 |
- offset+=2; |
|
579 |
- }else{ |
|
580 |
- buff[offset]=HEXDIG(d); |
|
581 |
- offset+=1; |
|
582 |
- } |
|
583 |
- |
|
584 |
- return offset; |
|
585 |
-} |
|
586 |
- |
|
587 |
- |
|
588 |
- |
|
589 |
-/* converts a raw ipv4 addr (4 bytes) to ascii */ |
|
590 |
-static inline int ip4tosbuf(unsigned char* ip4, char* buff, int len) |
|
591 |
-{ |
|
592 |
- int offset; |
|
593 |
- register unsigned char a,b,c; |
|
594 |
- int r; |
|
595 |
- |
|
596 |
- |
|
597 |
- offset=0; |
|
598 |
- if (unlikely(len<IP4_MAX_STR_SIZE)) |
|
599 |
- return 0; |
|
600 |
- for(r=0;r<3;r++){ |
|
601 |
- a=(unsigned char)ip4[r]/100; |
|
602 |
- c=(unsigned char)ip4[r]%10; |
|
603 |
- b=(unsigned char)ip4[r]%100/10; |
|
604 |
- if (a){ |
|
605 |
- buff[offset]=a+'0'; |
|
606 |
- buff[offset+1]=b+'0'; |
|
607 |
- buff[offset+2]=c+'0'; |
|
608 |
- buff[offset+3]='.'; |
|
609 |
- offset+=4; |
|
610 |
- }else if (b){ |
|
611 |
- buff[offset]=b+'0'; |
|
612 |
- buff[offset+1]=c+'0'; |
|
613 |
- buff[offset+2]='.'; |
|
614 |
- offset+=3; |
|
615 |
- }else{ |
|
616 |
- buff[offset]=c+'0'; |
|
617 |
- buff[offset+1]='.'; |
|
618 |
- offset+=2; |
|
619 |
- } |
|
620 |
- } |
|
621 |
- /* last number */ |
|
622 |
- a=(unsigned char)ip4[r]/100; |
|
623 |
- c=(unsigned char)ip4[r]%10; |
|
624 |
- b=(unsigned char)ip4[r]%100/10; |
|
625 |
- if (a){ |
|
626 |
- buff[offset]=a+'0'; |
|
627 |
- buff[offset+1]=b+'0'; |
|
628 |
- buff[offset+2]=c+'0'; |
|
629 |
- offset+=3; |
|
630 |
- }else if (b){ |
|
631 |
- buff[offset]=b+'0'; |
|
632 |
- buff[offset+1]=c+'0'; |
|
633 |
- offset+=2; |
|
634 |
- }else{ |
|
635 |
- buff[offset]=c+'0'; |
|
636 |
- offset+=1; |
|
637 |
- } |
|
638 |
- |
|
639 |
- return offset; |
|
640 |
-} |
|
641 |
- |
|
642 |
- |
|
643 |
- |
|
644 |
-/* fast ip_addr -> string converter; |
|
645 |
- * returns number of bytes written in buf on success, <=0 on error |
|
646 |
- * The buffer must have enough space to hold the maximum size ip address |
|
647 |
- * of the corresponding address (see IP[46] above) or else the function |
|
648 |
- * will return error (no detailed might fit checks are made, for example |
|
649 |
- * if len==7 the function will fail even for 1.2.3.4). |
|
650 |
- */ |
|
651 |
-static inline int ip_addr2sbuf(struct ip_addr* ip, char* buff, int len) |
|
652 |
-{ |
|
653 |
- switch(ip->af){ |
|
654 |
- case AF_INET6: |
|
655 |
- return ip6tosbuf(ip->u.addr, buff, len); |
|
656 |
- break; |
|
657 |
- case AF_INET: |
|
658 |
- return ip4tosbuf(ip->u.addr, buff, len); |
|
659 |
- break; |
|
660 |
- default: |
|
661 |
- LM_CRIT("unknown address family %d\n", ip->af); |
|
662 |
- return 0; |
|
663 |
- } |
|
664 |
-} |
|
665 |
- |
|
666 |
- |
|
667 |
- |
|
668 |
-/* maximum size of a str returned by ip_addr2a (including \0) */ |
|
669 |
-#define IP_ADDR_MAX_STR_SIZE (IP6_MAX_STR_SIZE+1) /* ip62ascii + \0*/ |
|
670 |
-/* fast ip_addr -> string converter; |
|
671 |
- * it uses an internal buffer |
|
672 |
- */ |
|
673 |
-static inline char* ip_addr2a(struct ip_addr* ip) |
|
674 |
-{ |
|
675 |
- |
|
676 |
- static char buff[IP_ADDR_MAX_STR_SIZE]; |
|
677 |
- int len; |
|
678 |
- |
|
679 |
- |
|
680 |
- len=ip_addr2sbuf(ip, buff, sizeof(buff)-1); |
|
681 |
- buff[len]=0; |
|
682 |
- |
|
683 |
- return buff; |
|
684 |
-} |
|
685 |
- |
|
686 |
-/* full address in text representation, including [] for ipv6 */ |
|
687 |
-static inline char* ip_addr2strz(struct ip_addr* ip) |
|
688 |
-{ |
|
689 |
- |
|
690 |
- static char buff[IP_ADDR_MAX_STR_SIZE+2]; |
|
691 |
- char *p; |
|
692 |
- int len; |
|
693 |
- |
|
694 |
- p = buff; |
|
695 |
- if(ip->af==AF_INET6) { |
|
696 |
- *p++ = '['; |
|
697 |
- } |
|
698 |
- len=ip_addr2sbuf(ip, p, sizeof(buff)-3); |
|
699 |
- p += len; |
|
700 |
- if(ip->af==AF_INET6) { |
|
701 |
- *p++ = ']'; |
|
702 |
- } |
|
703 |
- *p=0; |
|
704 |
- |
|
705 |
- return buff; |
|
706 |
-} |
|
707 |
- |
|
708 |
-#define SU2A_MAX_STR_SIZE (IP6_MAX_STR_SIZE + 2 /* [] */+\ |
|
709 |
- 1 /* : */ + USHORT2SBUF_MAX_LEN + 1 /* \0 */) |
|
710 |
-/* returns an asciiz string containing the ip and the port |
|
711 |
- * (<ip_addr>:port or [<ipv6_addr>]:port) |
|
712 |
- */ |
|
713 |
-static inline char* su2a(union sockaddr_union* su, int su_len) |
|
714 |
-{ |
|
715 |
- static char buf[SU2A_MAX_STR_SIZE]; |
|
716 |
- int offs; |
|
717 |
- |
|
718 |
- if (unlikely(su->s.sa_family==AF_INET6)){ |
|
719 |
- if (unlikely(su_len<sizeof(su->sin6))) |
|
720 |
- return "<addr. error>"; |
|
721 |
- buf[0]='['; |
|
722 |
- offs=1+ip6tosbuf((unsigned char*)su->sin6.sin6_addr.s6_addr, &buf[1], |
|
723 |
- sizeof(buf)-4); |
|
724 |
- buf[offs]=']'; |
|
725 |
- offs++; |
|
726 |
- }else |
|
727 |
- if (unlikely(su_len<sizeof(su->sin))) |
|
728 |
- return "<addr. error>"; |
|
729 |
- else |
|
730 |
- offs=ip4tosbuf((unsigned char*)&su->sin.sin_addr, buf, sizeof(buf)-2); |
|
731 |
- buf[offs]=':'; |
|
732 |
- offs+=1+ushort2sbuf(su_getport(su), &buf[offs+1], sizeof(buf)-(offs+1)-1); |
|
733 |
- buf[offs]=0; |
|
734 |
- return buf; |
|
735 |
-} |
|
736 |
- |
|
737 |
-#define SUIP2A_MAX_STR_SIZE (IP6_MAX_STR_SIZE + 2 /* [] */ + 1 /* \0 */) |
|
738 |
-/* returns an asciiz string containing the ip |
|
739 |
- * (<ipv4_addr> or [<ipv6_addr>]) |
|
740 |
- */ |
|
741 |
-static inline char* suip2a(union sockaddr_union* su, int su_len) |
|
742 |
-{ |
|
743 |
- static char buf[SUIP2A_MAX_STR_SIZE]; |
|
744 |
- int offs; |
|
745 |
- |
|
746 |
- if (unlikely(su->s.sa_family==AF_INET6)){ |
|
747 |
- if (unlikely(su_len<sizeof(su->sin6))) |
|
748 |
- return "<addr. error>"; |
|
749 |
- buf[0]='['; |
|
750 |
- offs=1+ip6tosbuf((unsigned char*)su->sin6.sin6_addr.s6_addr, &buf[1], |
|
751 |
- IP6_MAX_STR_SIZE); |
|
752 |
- buf[offs]=']'; |
|
753 |
- offs++; |
|
754 |
- }else |
|
755 |
- if (unlikely(su_len<sizeof(su->sin))) |
|
756 |
- return "<addr. error>"; |
|
757 |
- else |
|
758 |
- offs=ip4tosbuf((unsigned char*)&su->sin.sin_addr, buf, IP4_MAX_STR_SIZE); |
|
759 |
- buf[offs]=0; |
|
760 |
- return buf; |
|
761 |
-} |
|
762 |
- |
|
763 |
- |
|
764 |
- |
|
765 |
-/* converts an ip_addr structure to a hostent, returns pointer to internal |
|
766 |
- * statical structure */ |
|
767 |
-static inline struct hostent* ip_addr2he(str* name, struct ip_addr* ip) |
|
768 |
-{ |
|
769 |
- static struct hostent he; |
|
770 |
- static char hostname[256]; |
|
771 |
- static char* p_aliases[1]; |
|
772 |
- static char* p_addr[2]; |
|
773 |
- static char address[16]; |
|
774 |
- |
|
775 |
- p_aliases[0]=0; /* no aliases*/ |
|
776 |
- p_addr[1]=0; /* only one address*/ |
|
777 |
- p_addr[0]=address; |
|
778 |
- strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256); |
|
779 |
- if (ip->len>16) return 0; |
|
780 |
- memcpy(address, ip->u.addr, ip->len); |
|
781 |
- |
|
782 |
- he.h_addrtype=ip->af; |
|
783 |
- he.h_length=ip->len; |
|
784 |
- he.h_addr_list=p_addr; |
|
785 |
- he.h_aliases=p_aliases; |
|
786 |
- he.h_name=hostname; |
|
787 |
- return &he; |
|
788 |
-} |
|
789 |
- |
|
790 |
- |
|
791 |
- |
|
792 |
-/* init a dest_info structure */ |
|
793 |
-#define init_dest_info(dst) \ |
|
794 |
- do{ \ |
|
795 |
- memset((dst), 0, sizeof(struct dest_info)); \ |
|
796 |
- } while(0) |
|
797 |
- |
|
798 |
- |
|
799 |
- |
|
800 |
-/* init a dest_info structure from a recv_info structure */ |
|
801 |
-inline static void init_dst_from_rcv(struct dest_info* dst, |
|
802 |
- struct receive_info* rcv) |
|
803 |
-{ |
|
804 |
- dst->send_sock=rcv->bind_address; |
|
805 |
- dst->to=rcv->src_su; |
|
806 |
- dst->id=rcv->proto_reserved1; |
|
807 |
- dst->proto=rcv->proto; |
|
808 |
- dst->send_flags.f=0; |
|
809 |
- dst->send_flags.blst_imask=0; |
|
810 |
-#ifdef USE_COMP |
|
811 |
- dst->comp=rcv->comp; |
|
812 |
-#endif |
|
813 |
-} |
|
814 |
- |
|
815 |
-/** |
|
816 |
- * match ip address with net address and bitmask |
|
817 |
- * - return 0 on match, -1 otherwise |
|
818 |
- */ |
|
819 |
-int ip_addr_match_net(ip_addr_t *iaddr, ip_addr_t *naddr, int mask); |
|
820 |
- |
|
821 |
-int si_get_signaling_data(struct socket_info *si, str **addr, str **port); |
|
822 |
- |
|
823 |
-#endif |
- You can now define a mcast parameter before a listen parameter that
contains a multicast address. After each listen parameter mcast gets
reset. mcast must contain the name of an interface, eg `eth1`.
Issue GH#813
... | ... |
@@ -116,6 +116,9 @@ struct socket_info{ |
116 | 116 |
int workers; /* number of worker processes for this socket */ |
117 | 117 |
int workers_tcpidx; /* index of workers in tcp children array */ |
118 | 118 |
struct advertise_info useinfo; /* details to be used in SIP msg */ |
119 |
+#ifdef USE_MCAST |
|
120 |
+ str mcast; /* name of interface that should join multicast group*/ |
|
121 |
+#endif /* USE_MCAST */ |
|
119 | 122 |
}; |
120 | 123 |
|
121 | 124 |
|
- update Makefile.defs for recent versions of Solaris Studio
... | ... |
@@ -136,6 +136,11 @@ struct receive_info{ |
136 | 136 |
/* no need for dst_su yet */ |
137 | 137 |
}; |
138 | 138 |
|
139 |
+typedef struct sr_net_info { |
|
140 |
+ str data; |
|
141 |
+ struct dest_info* dst; |
|
142 |
+ struct receive_info* rcv; |
|
143 |
+} sr_net_info_t; |
|
139 | 144 |
|
140 | 145 |
/* send flags */ |
141 | 146 |
#define SND_F_FORCE_CON_REUSE 1 /* reuse an existing connection or fail */ |
- buffer size set to IP6_MAX_STR_SIZE, it was too short and returned
value was empty addres "[]"
- the function is used only by siptrace
- patch from github pull request #381
... | ... |
@@ -741,14 +741,14 @@ static inline char* suip2a(union sockaddr_union* su, int su_len) |
741 | 741 |
return "<addr. error>"; |
742 | 742 |
buf[0]='['; |
743 | 743 |
offs=1+ip6tosbuf((unsigned char*)su->sin6.sin6_addr.s6_addr, &buf[1], |
744 |
- sizeof(buf)-4); |
|
744 |
+ IP6_MAX_STR_SIZE); |
|
745 | 745 |
buf[offs]=']'; |
746 | 746 |
offs++; |
747 | 747 |
}else |
748 | 748 |
if (unlikely(su_len<sizeof(su->sin))) |
749 | 749 |
return "<addr. error>"; |
750 | 750 |
else |
751 |
- offs=ip4tosbuf((unsigned char*)&su->sin.sin_addr, buf, sizeof(buf)-2); |
|
751 |
+ offs=ip4tosbuf((unsigned char*)&su->sin.sin_addr, buf, IP4_MAX_STR_SIZE); |
|
752 | 752 |
buf[offs]=0; |
753 | 753 |
return buf; |
754 | 754 |
} |
- returns variants for uppercase and lowecase, representation for uri or
bare proto: udp, tcp, tls, sctp, ws and wss
- in uri, PROTO_WS and PROTO_WSS are represented as transport=ws
... | ... |
@@ -245,7 +245,8 @@ void print_net(struct net* net); |
245 | 245 |
char* get_proto_name(unsigned int proto); |
246 | 246 |
#define proto2a get_proto_name |
247 | 247 |
|
248 |
- |
|
248 |
+int get_valid_proto_string(unsigned int iproto, int utype, int vtype, |
|
249 |
+ str *sproto); |
|
249 | 250 |
|
250 | 251 |
#ifdef USE_MCAST |
251 | 252 |
/* Returns 1 if the given address is a multicast address */ |
... | ... |
@@ -4,19 +4,14 @@ |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2001-2003 FhG Fokus |
6 | 6 |
* |
7 |
- * This file is part of ser, a free SIP server. |
|
7 |
+ * This file is part of Kamailio, a free SIP server. |
|
8 | 8 |
* |
9 |
- * ser is free software; you can redistribute it and/or modify |
|
9 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
10 | 10 |
* it under the terms of the GNU General Public License as published by |
11 | 11 |
* the Free Software Foundation; either version 2 of the License, or |
12 | 12 |
* (at your option) any later version |
13 | 13 |
* |
14 |
- * For a license to use the ser software under conditions |
|
15 |
- * other than those described here, or to purchase support for this |
|
16 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
17 |
- * info@iptel.org |
|
18 |
- * |
|
19 |
- * ser is distributed in the hope that it will be useful, |
|