... | ... |
@@ -7,8 +7,8 @@ |
7 | 7 |
#version number |
8 | 8 |
VERSION = 0 |
9 | 9 |
PATCHLEVEL = 8 |
10 |
-SUBLEVEL = 7 |
|
11 |
-EXTRAVERSION = -7-ipaq-viadbg |
|
10 |
+SUBLEVEL = 8 |
|
11 |
+EXTRAVERSION = -1-ipv6 |
|
12 | 12 |
|
13 | 13 |
RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) |
14 | 14 |
OS = $(shell uname -s) |
... | ... |
@@ -74,9 +74,11 @@ ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ ) |
74 | 74 |
# -DNEW_HNAME |
75 | 75 |
# 32-bit header name parsing; turn off for lower speed ;-) or debugging; |
76 | 76 |
# to become non-optional if fast and stable |
77 |
-# -SILENT_FR |
|
77 |
+# -DSILENT_FR |
|
78 | 78 |
# if defined, when FR timer hits (in tm) cancel is sent only if forking |
79 | 79 |
# if used; otherwise, just delete the transaction without doing anything |
80 |
+# -DUSE_IPV6 |
|
81 |
+# compiles ipv6 support |
|
80 | 82 |
|
81 | 83 |
DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \ |
82 | 84 |
-DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\ |
... | ... |
@@ -85,10 +87,9 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \ |
85 | 87 |
-DSHM_MEM -DSHM_MMAP \ |
86 | 88 |
-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \ |
87 | 89 |
-DWAIT -DNEW_HNAME \ |
88 |
- -DNOISY_REPLIES \ |
|
89 |
- -DVERY_NOISY_REPLIES\ |
|
90 |
- -DSILENT_FR \ |
|
91 |
- #-DUSE_SYNONIM\ |
|
90 |
+ -DUSE_IPV6 \ |
|
91 |
+ #-DVERY_NOISY_REPLIES\ |
|
92 |
+ #-DSILENT_FR \ |
|
92 | 93 |
#-DNO_DEBUG \ |
93 | 94 |
#-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=0 \ |
94 | 95 |
#-DNOSMP \ |
... | ... |
@@ -102,8 +103,8 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \ |
102 | 103 |
|
103 | 104 |
|
104 | 105 |
#PROFILE= -pg #set this if you want profiling |
105 |
-mode = debug |
|
106 |
-#mode = release |
|
106 |
+#mode = debug |
|
107 |
+mode = release |
|
107 | 108 |
|
108 | 109 |
# platform dependent settings |
109 | 110 |
|
... | ... |
@@ -37,7 +37,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
37 | 37 |
{ |
38 | 38 |
int ret; |
39 | 39 |
int v; |
40 |
- struct sockaddr_in* to; |
|
40 |
+ union sockaddr_union* to; |
|
41 | 41 |
struct proxy_l* p; |
42 | 42 |
char* tmp; |
43 | 43 |
char *new_uri, *end, *crt; |
... | ... |
@@ -77,8 +77,8 @@ int do_action(struct action* a, struct sip_msg* msg) |
77 | 77 |
/*if ((end)&&(*end)){*/ |
78 | 78 |
if (err){ |
79 | 79 |
LOG(L_ERR, "ERROR: do_action: " |
80 |
- "forward: bad port in " |
|
81 |
- "uri: <%s>\n", uri.port.s); |
|
80 |
+ "forward: bad port in " |
|
81 |
+ "uri: <%s>\n", uri.port.s); |
|
82 | 82 |
ret=E_UNSPEC; |
83 | 83 |
goto error_fwd_uri; |
84 | 84 |
} |
... | ... |
@@ -116,24 +116,22 @@ int do_action(struct action* a, struct sip_msg* msg) |
116 | 116 |
} |
117 | 117 |
break; |
118 | 118 |
case SEND_T: |
119 |
- to=(struct sockaddr_in*) malloc(sizeof(struct sockaddr_in)); |
|
120 |
- if (to==0){ |
|
121 |
- LOG(L_ERR, "ERROR: do_action: " |
|
122 |
- "memory allocation failure\n"); |
|
123 |
- ret=E_OUT_OF_MEM; |
|
124 |
- break; |
|
125 |
- } |
|
126 | 119 |
if ((a->p1_type!= PROXY_ST)|(a->p2_type!=NUMBER_ST)){ |
127 | 120 |
LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n", |
128 | 121 |
a->p1_type, a->p2_type); |
129 | 122 |
ret=E_BUG; |
130 | 123 |
break; |
131 | 124 |
} |
125 |
+ to=(union sockaddr_union*) malloc(sizeof(union sockaddr_union)); |
|
126 |
+ if (to==0){ |
|
127 |
+ LOG(L_ERR, "ERROR: do_action: " |
|
128 |
+ "memory allocation failure\n"); |
|
129 |
+ ret=E_OUT_OF_MEM; |
|
130 |
+ break; |
|
131 |
+ } |
|
132 | 132 |
|
133 | 133 |
p=(struct proxy_l*)a->p1.data; |
134 | 134 |
|
135 |
- to->sin_family = AF_INET; |
|
136 |
- to->sin_port=(p->port)?htons(p->port):htons(SIP_PORT); |
|
137 | 135 |
if (p->ok==0){ |
138 | 136 |
if (p->host.h_addr_list[p->addr_idx+1]) |
139 | 137 |
p->addr_idx++; |
... | ... |
@@ -141,15 +139,14 @@ int do_action(struct action* a, struct sip_msg* msg) |
141 | 139 |
p->addr_idx=0; |
142 | 140 |
p->ok=1; |
143 | 141 |
} |
144 |
- memcpy(&(to->sin_addr.s_addr), p->host.h_addr_list[p->addr_idx], |
|
145 |
- sizeof(to->sin_addr.s_addr)); |
|
146 |
- /* |
|
147 |
- to->sin_addr.s_addr=*((long*)p->host.h_addr_list[p->addr_idx]); |
|
148 |
- */ |
|
149 |
- p->tx++; |
|
150 |
- p->tx_bytes+=msg->len; |
|
151 |
- ret=udp_send(msg->orig, msg->len, (struct sockaddr*)to, |
|
152 |
- sizeof(struct sockaddr_in)); |
|
142 |
+ ret=hostent2su( to, &p->host, p->addr_idx, |
|
143 |
+ (p->port)?htons(p->port):htons(SIP_PORT) ); |
|
144 |
+ if (ret==0){ |
|
145 |
+ p->tx++; |
|
146 |
+ p->tx_bytes+=msg->len; |
|
147 |
+ ret=udp_send(msg->orig, msg->len, to, |
|
148 |
+ sizeof(union sockaddr_union)); |
|
149 |
+ } |
|
153 | 150 |
free(to); |
154 | 151 |
if (ret<0){ |
155 | 152 |
p->errors++; |
... | ... |
@@ -8,6 +8,7 @@ |
8 | 8 |
%{ |
9 | 9 |
#include "cfg.tab.h" |
10 | 10 |
#include "dprint.h" |
11 |
+ #include "globals.h" |
|
11 | 12 |
#include <string.h> |
12 | 13 |
#include <stdlib.h> |
13 | 14 |
|
... | ... |
@@ -107,6 +108,9 @@ DIGIT [0-9] |
107 | 108 |
ALPHANUM {LETTER}|{DIGIT}|[_] |
108 | 109 |
NUMBER {DIGIT}+ |
109 | 110 |
ID {LETTER}{ALPHANUM}* |
111 |
+HEX [0-9a-fA-F] |
|
112 |
+HEX4 {HEX}{1,4} |
|
113 |
+IPV6ADDR ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::" |
|
110 | 114 |
QUOTES \" |
111 | 115 |
TICK \' |
112 | 116 |
SLASH "/" |
... | ... |
@@ -188,8 +192,10 @@ EAT_ABLE [\ \t\b\r] |
188 | 192 |
<INITIAL>{AND} { count(); return AND; } |
189 | 193 |
<INITIAL>{OR} { count(); return OR; } |
190 | 194 |
|
191 |
-<INITIAL>{NUMBER} { count(); yylval.intval=atoi(yytext); |
|
192 |
- return NUMBER; } |
|
195 |
+ |
|
196 |
+ |
|
197 |
+<INITIAL>{IPV6ADDR} { count(); yylval.strval=yytext; return IPV6ADDR; } |
|
198 |
+<INITIAL>{NUMBER} { count(); yylval.intval=atoi(yytext);return NUMBER; } |
|
193 | 199 |
<INITIAL>{YES} { count(); yylval.intval=1; return NUMBER; } |
194 | 200 |
<INITIAL>{NO} { count(); yylval.intval=0; return NUMBER; } |
195 | 201 |
|
... | ... |
@@ -13,12 +13,14 @@ |
13 | 13 |
#include <netinet/in.h> |
14 | 14 |
#include <arpa/inet.h> |
15 | 15 |
#include <string.h> |
16 |
+#include <errno.h> |
|
16 | 17 |
#include "route_struct.h" |
17 | 18 |
#include "globals.h" |
18 | 19 |
#include "route.h" |
19 | 20 |
#include "dprint.h" |
20 | 21 |
#include "sr_module.h" |
21 | 22 |
#include "modparam.h" |
23 |
+#include "ip_addr.h" |
|
22 | 24 |
|
23 | 25 |
#include "config.h" |
24 | 26 |
|
... | ... |
@@ -40,7 +42,8 @@ void* f_tmp; |
40 | 42 |
char* strval; |
41 | 43 |
struct expr* expr; |
42 | 44 |
struct action* action; |
43 |
- struct net* net; |
|
45 |
+ struct net* ipnet; |
|
46 |
+ struct ip_addr* ipaddr; |
|
44 | 47 |
} |
45 | 48 |
|
46 | 49 |
/* terminals */ |
... | ... |
@@ -106,6 +109,7 @@ void* f_tmp; |
106 | 109 |
%token <intval> NUMBER |
107 | 110 |
%token <strval> ID |
108 | 111 |
%token <strval> STRING |
112 |
+%token <strval> IPV6ADDR |
|
109 | 113 |
|
110 | 114 |
/* other */ |
111 | 115 |
%token COMMA |
... | ... |
@@ -124,8 +128,8 @@ void* f_tmp; |
124 | 128 |
/*non-terminals */ |
125 | 129 |
%type <expr> exp, exp_elem /*, condition*/ |
126 | 130 |
%type <action> action, actions, cmd, if_cmd, stm |
127 |
-%type <uval> ipv4 |
|
128 |
-%type <net> net4 |
|
131 |
+%type <ipaddr> ipv4, ipv6, ip |
|
132 |
+%type <ipnet> ipnet |
|
129 | 133 |
%type <strval> host |
130 | 134 |
/*%type <route_el> rules; |
131 | 135 |
%type <route_el> rule; |
... | ... |
@@ -175,18 +179,25 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; } |
175 | 179 |
| CHECK_VIA EQUAL error { yyerror("boolean value expected"); } |
176 | 180 |
| LOOP_CHECKS EQUAL NUMBER { loop_checks=$3; } |
177 | 181 |
| LOOP_CHECKS EQUAL error { yyerror("boolean value expected"); } |
178 |
- | LISTEN EQUAL ipv4 { |
|
182 |
+ | LISTEN EQUAL ip { |
|
179 | 183 |
if (addresses_no < MAX_LISTEN){ |
180 |
- tmp=inet_ntoa(*(struct in_addr*)&$3); |
|
181 |
- names[addresses_no]= |
|
182 |
- (char*)malloc(strlen(tmp)+1); |
|
183 |
- if (names[addresses_no]==0){ |
|
184 |
+ tmp=ip_addr2a($3); |
|
185 |
+ /* tmp=inet_ntoa(*(struct in_addr*)&$3);*/ |
|
186 |
+ if (tmp==0){ |
|
184 | 187 |
LOG(L_CRIT, "ERROR: cfg. parser: " |
185 |
- "out of memory.\n"); |
|
188 |
+ " bad ip address: %s\n", |
|
189 |
+ strerror(errno)); |
|
186 | 190 |
}else{ |
187 |
- strncpy(names[addresses_no], tmp, |
|
188 |
- strlen(tmp)+1); |
|
189 |
- addresses_no++; |
|
191 |
+ names[addresses_no]= |
|
192 |
+ (char*)malloc(strlen(tmp)+1); |
|
193 |
+ if (names[addresses_no]==0){ |
|
194 |
+ LOG(L_CRIT, "ERROR: cfg. parser: " |
|
195 |
+ "out of memory.\n"); |
|
196 |
+ }else{ |
|
197 |
+ strncpy(names[addresses_no], tmp, |
|
198 |
+ strlen(tmp)+1); |
|
199 |
+ addresses_no++; |
|
200 |
+ } |
|
190 | 201 |
} |
191 | 202 |
}else{ |
192 | 203 |
LOG(L_CRIT, "ERROR: cfg. parser:" |
... | ... |
@@ -255,21 +266,63 @@ module_stm: LOADMODULE STRING { DBG("loading module %s\n", $2); |
255 | 266 |
; |
256 | 267 |
|
257 | 268 |
|
269 |
+ip: ipv4 { $$=$1; } |
|
270 |
+ |ipv6 { $$=$1; } |
|
271 |
+ ; |
|
272 |
+ |
|
258 | 273 |
ipv4: NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { |
259 |
- if (($1>255) || ($1<0) || |
|
260 |
- ($3>255) || ($3<0) || |
|
261 |
- ($5>255) || ($5<0) || |
|
262 |
- ($7>255) || ($7<0)){ |
|
263 |
- yyerror("invalid ipv4" |
|
264 |
- "address"); |
|
265 |
- $$=0; |
|
274 |
+ $$=malloc(sizeof(struct ip_addr)); |
|
275 |
+ if ($$==0){ |
|
276 |
+ LOG(L_CRIT, "ERROR: cfg. " |
|
277 |
+ "parser: out of memory.\n" |
|
278 |
+ ); |
|
266 | 279 |
}else{ |
267 |
- $$=htonl( ($1<<24)| |
|
280 |
+ memset($$, 0, |
|
281 |
+ sizeof(struct ip_addr)); |
|
282 |
+ $$->af=AF_INET; |
|
283 |
+ $$->len=4; |
|
284 |
+ if (($1>255) || ($1<0) || |
|
285 |
+ ($3>255) || ($3<0) || |
|
286 |
+ ($5>255) || ($5<0) || |
|
287 |
+ ($7>255) || ($7<0)){ |
|
288 |
+ yyerror("invalid ipv4" |
|
289 |
+ "address"); |
|
290 |
+ $$->u.addr32[0]=0; |
|
291 |
+ /* $$=0; */ |
|
292 |
+ }else{ |
|
293 |
+ $$->u.addr[0]=$1; |
|
294 |
+ $$->u.addr[1]=$3; |
|
295 |
+ $$->u.addr[2]=$5; |
|
296 |
+ $$->u.addr[3]=$7; |
|
297 |
+ /* |
|
298 |
+ $$=htonl( ($1<<24)| |
|
268 | 299 |
($3<<16)| ($5<<8)|$7 ); |
300 |
+ */ |
|
301 |
+ } |
|
269 | 302 |
} |
270 | 303 |
} |
271 | 304 |
; |
272 | 305 |
|
306 |
+ipv6: IPV6ADDR { |
|
307 |
+ $$=malloc(sizeof(struct ip_addr)); |
|
308 |
+ if ($$==0){ |
|
309 |
+ LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n"); |
|
310 |
+ }else{ |
|
311 |
+ memset($$, 0, sizeof(struct ip_addr)); |
|
312 |
+ $$->af=AF_INET6; |
|
313 |
+ $$->len=16; |
|
314 |
+ #ifndef USE_IPV6 |
|
315 |
+ yyerror("ipv6 address & no ipv6 support compiled in"); |
|
316 |
+ YYABORT; |
|
317 |
+ #endif |
|
318 |
+ if (inet_pton(AF_INET6, $1, $$->u.addr)<=0){ |
|
319 |
+ yyerror("bad ipv6 address"); |
|
320 |
+ } |
|
321 |
+ } |
|
322 |
+ } |
|
323 |
+ ; |
|
324 |
+ |
|
325 |
+ |
|
273 | 326 |
route_stm: ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); } |
274 | 327 |
|
275 | 328 |
| ROUTE LBRACK NUMBER RBRACK LBRACE actions RBRACE { |
... | ... |
@@ -343,7 +396,7 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
343 | 396 |
| URI error { $$=0; yyerror("invalid operator," |
344 | 397 |
" == or =~ expected"); |
345 | 398 |
} |
346 |
- | SRCIP EQUAL_T net4 { $$=mk_elem( EQUAL_OP, NET_ST, |
|
399 |
+ | SRCIP EQUAL_T ipnet { $$=mk_elem( EQUAL_OP, NET_ST, |
|
347 | 400 |
SRCIP_O, $3); |
348 | 401 |
} |
349 | 402 |
| SRCIP EQUAL_T STRING { $$=mk_elem( EQUAL_OP, STRING_ST, |
... | ... |
@@ -363,7 +416,7 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
363 | 416 |
| SRCIP MATCH error { $$=0; yyerror( "hostname expected"); } |
364 | 417 |
| SRCIP error { $$=0; |
365 | 418 |
yyerror("invalid operator, == or =~ expected");} |
366 |
- | DSTIP EQUAL_T net4 { $$=mk_elem( EQUAL_OP, NET_ST, |
|
419 |
+ | DSTIP EQUAL_T ipnet { $$=mk_elem( EQUAL_OP, NET_ST, |
|
367 | 420 |
DSTIP_O, $3); |
368 | 421 |
} |
369 | 422 |
| DSTIP EQUAL_T STRING { $$=mk_elem( EQUAL_OP, STRING_ST, |
... | ... |
@@ -387,18 +440,22 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
387 | 440 |
| NUMBER {$$=mk_elem( NO_OP, NUMBER_ST, NUMBER_O, (void*)$1 ); } |
388 | 441 |
; |
389 | 442 |
|
390 |
-net4: ipv4 SLASH ipv4 { $$=mk_net($1, $3); } |
|
391 |
- | ipv4 SLASH NUMBER { if (($3>32)|($3<0)){ |
|
443 |
+ipnet: ip SLASH ip { $$=mk_net($1, $3); } |
|
444 |
+ | ip SLASH NUMBER { if (($3<0) || ($3>$1->len*8)){ |
|
392 | 445 |
yyerror("invalid bit number in netmask"); |
393 | 446 |
$$=0; |
394 | 447 |
}else{ |
448 |
+ $$=mk_net_bitlen($1, $3); |
|
449 |
+ /* |
|
395 | 450 |
$$=mk_net($1, |
396 | 451 |
htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) ); |
452 |
+ */ |
|
397 | 453 |
} |
398 | 454 |
} |
399 |
- | ipv4 { $$=mk_net($1, 0xffffffff); } |
|
400 |
- | ipv4 SLASH error { $$=0; |
|
401 |
- yyerror("netmask (eg:255.0.0.0 or 8) expected");} |
|
455 |
+ | ip { $$=mk_net_bitlen($1, $1->len*8); } |
|
456 |
+ | ip SLASH error { $$=0; |
|
457 |
+ yyerror("netmask (eg:255.0.0.0 or 8) expected"); |
|
458 |
+ } |
|
402 | 459 |
; |
403 | 460 |
|
404 | 461 |
host: ID { $$=$1; } |
... | ... |
@@ -462,7 +519,7 @@ cmd: FORWARD LPAREN host RPAREN { $$=mk_action( FORWARD_T, |
462 | 519 |
$3, |
463 | 520 |
0); |
464 | 521 |
} |
465 |
- | FORWARD LPAREN ipv4 RPAREN { $$=mk_action( FORWARD_T, |
|
522 |
+ | FORWARD LPAREN ip RPAREN { $$=mk_action( FORWARD_T, |
|
466 | 523 |
IP_ST, |
467 | 524 |
NUMBER_ST, |
468 | 525 |
(void*)$3, |
... | ... |
@@ -480,7 +537,7 @@ cmd: FORWARD LPAREN host RPAREN { $$=mk_action( FORWARD_T, |
480 | 537 |
$3, |
481 | 538 |
(void*)$5); |
482 | 539 |
} |
483 |
- | FORWARD LPAREN ipv4 COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, |
|
540 |
+ | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, |
|
484 | 541 |
IP_ST, |
485 | 542 |
NUMBER_ST, |
486 | 543 |
(void*)$3, |
... | ... |
@@ -524,7 +581,7 @@ cmd: FORWARD LPAREN host RPAREN { $$=mk_action( FORWARD_T, |
524 | 581 |
$3, |
525 | 582 |
0); |
526 | 583 |
} |
527 |
- | SEND LPAREN ipv4 RPAREN { $$=mk_action( SEND_T, |
|
584 |
+ | SEND LPAREN ip RPAREN { $$=mk_action( SEND_T, |
|
528 | 585 |
IP_ST, |
529 | 586 |
NUMBER_ST, |
530 | 587 |
(void*)$3, |
... | ... |
@@ -542,7 +599,7 @@ cmd: FORWARD LPAREN host RPAREN { $$=mk_action( FORWARD_T, |
542 | 599 |
$3, |
543 | 600 |
(void*)$5); |
544 | 601 |
} |
545 |
- | SEND LPAREN ipv4 COMMA NUMBER RPAREN { $$=mk_action( SEND_T, |
|
602 |
+ | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action( SEND_T, |
|
546 | 603 |
IP_ST, |
547 | 604 |
NUMBER_ST, |
548 | 605 |
(void*)$3, |
... | ... |
@@ -8,7 +8,6 @@ |
8 | 8 |
|
9 | 9 |
#include <syslog.h> |
10 | 10 |
|
11 |
-#include "globals.h" |
|
12 | 11 |
|
13 | 12 |
#define L_ALERT -3 |
14 | 13 |
#define L_CRIT -2 |
... | ... |
@@ -18,6 +17,10 @@ |
18 | 17 |
#define L_INFO 3 |
19 | 18 |
#define L_DBG 4 |
20 | 19 |
|
20 |
+/* vars:*/ |
|
21 |
+ |
|
22 |
+extern int debug; |
|
23 |
+extern int log_stderr; |
|
21 | 24 |
|
22 | 25 |
|
23 | 26 |
#define DPRINT_LEV 1 |
... | ... |
@@ -25,6 +25,8 @@ |
25 | 25 |
#include "msg_translator.h" |
26 | 26 |
#include "sr_module.h" |
27 | 27 |
#include "stats.h" |
28 |
+#include "ip_addr.h" |
|
29 |
+#include "resolve.h" |
|
28 | 30 |
|
29 | 31 |
#ifdef DEBUG_DMALLOC |
30 | 32 |
#include <dmalloc.h> |
... | ... |
@@ -36,7 +38,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
36 | 38 |
{ |
37 | 39 |
unsigned int len; |
38 | 40 |
char* buf; |
39 |
- struct sockaddr_in* to; |
|
41 |
+ union sockaddr_union* to; |
|
40 | 42 |
|
41 | 43 |
to=0; |
42 | 44 |
buf = build_req_buf_from_sip_req( msg, &len); |
... | ... |
@@ -45,7 +47,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
45 | 47 |
goto error; |
46 | 48 |
} |
47 | 49 |
|
48 |
- to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in)); |
|
50 |
+ to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union)); |
|
49 | 51 |
if (to==0){ |
50 | 52 |
LOG(L_ERR, "ERROR: forward_request: out of memory\n"); |
51 | 53 |
goto error; |
... | ... |
@@ -55,26 +57,20 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p) |
55 | 57 |
DBG("Sending:\n%s.\n", buf); |
56 | 58 |
DBG("orig. len=%d, new_len=%d\n", msg->len, len ); |
57 | 59 |
|
58 |
- to->sin_family = AF_INET; |
|
59 |
- to->sin_port = (p->port)?htons(p->port):htons(SIP_PORT); |
|
60 | 60 |
/* if error try next ip address if possible */ |
61 | 61 |
if (p->ok==0){ |
62 | 62 |
if (p->host.h_addr_list[p->addr_idx+1]) |
63 | 63 |
p->addr_idx++; |
64 |
+ else p->addr_idx=0; |
|
64 | 65 |
p->ok=1; |
65 | 66 |
} |
66 |
- |
|
67 |
- memcpy(&(to->sin_addr.s_addr), p->host.h_addr_list[p->addr_idx], |
|
68 |
- sizeof(to->sin_addr.s_addr)); |
|
69 |
- /* |
|
70 |
- to->sin_addr.s_addr=*((long*)p->host.h_addr_list[p->addr_idx]); |
|
71 |
- */ |
|
72 | 67 |
|
68 |
+ hostent2su(to, &p->host, p->addr_idx, |
|
69 |
+ (p->port)?htons(p->port):htons(SIP_PORT)); |
|
73 | 70 |
p->tx++; |
74 | 71 |
p->tx_bytes+=len; |
75 | 72 |
|
76 |
- if (udp_send( buf, len, (struct sockaddr*) to, |
|
77 |
- sizeof(struct sockaddr_in))==-1){ |
|
73 |
+ if (udp_send( buf, len, to, sizeof(union sockaddr_union))==-1){ |
|
78 | 74 |
p->errors++; |
79 | 75 |
p->ok=0; |
80 | 76 |
STATS_TX_DROPS; |
... | ... |
@@ -93,43 +89,50 @@ error: |
93 | 89 |
} |
94 | 90 |
|
95 | 91 |
|
96 |
-int update_sock_struct_from_via( struct sockaddr_in* to, struct via_body* via ) |
|
92 |
+int update_sock_struct_from_via( union sockaddr_union* to, |
|
93 |
+ struct via_body* via ) |
|
97 | 94 |
{ |
98 | 95 |
int err; |
99 | 96 |
struct hostent* he; |
97 |
+ unsigned int ip; |
|
100 | 98 |
char *host_copy; |
101 | 99 |
|
102 |
- to->sin_family = AF_INET; |
|
103 |
- to->sin_port = (via->port)?htons(via->port): htons(SIP_PORT); |
|
104 | 100 |
|
105 | 101 |
#ifdef DNS_IP_HACK |
106 |
- to->sin_addr.s_addr=str2ip((unsigned char*)via->host.s,via->host.len,&err); |
|
107 |
- if (err) |
|
102 |
+ ip=str2ip((unsigned char*)via->host.s,via->host.len,&err); |
|
103 |
+ if (err==0){ |
|
104 |
+ to->sin.sin_family=AF_INET; |
|
105 |
+ to->sin.sin_port=(via->port)?htons(via->port): htons(SIP_PORT); |
|
106 |
+ memcpy(&to->sin.sin_addr, (char*)&ip, 4); |
|
107 |
+ }else |
|
108 | 108 |
#endif |
109 | 109 |
{ |
110 |
- /* fork? gethostbyname will probably block... */ |
|
111 | 110 |
/* we do now a malloc/memcpy because gethostbyname loves \0-terminated |
112 |
- strings; -jiri */ |
|
113 |
- if (!(host_copy=pkg_malloc( via->host.len+1 ))) { |
|
114 |
- LOG(L_NOTICE, "ERROR: update_sock_struct_from_via: not enough memory\n"); |
|
115 |
- return -1; |
|
111 |
+ strings; -jiri |
|
112 |
+ but only if host is not null terminated |
|
113 |
+ (host.s[len] will always be ok for a via) |
|
114 |
+ BTW: when is via->host.s non null terminated? tm copy? |
|
115 |
+ - andrei |
|
116 |
+ */ |
|
117 |
+ if (via->host.s[via->host.len]){ |
|
118 |
+ if (!(host_copy=pkg_malloc( via->host.len+1 ))) { |
|
119 |
+ LOG(L_NOTICE, "ERROR: update_sock_struct_from_via: not enough memory\n"); |
|
120 |
+ return -1; |
|
121 |
+ } |
|
122 |
+ memcpy(host_copy, via->host.s, via->host.len ); |
|
123 |
+ host_copy[via->host.len]=0; |
|
124 |
+ he=resolvehost(host_copy); |
|
125 |
+ pkg_free( host_copy ); |
|
126 |
+ }else{ |
|
127 |
+ he=resolvehost(via->host.s); |
|
116 | 128 |
} |
117 |
- memcpy(host_copy, via->host.s, via->host.len ); |
|
118 |
- host_copy[via->host.len]=0; |
|
119 |
- he=gethostbyname(host_copy); |
|
120 |
- /* he=gethostbyname(via->host.s); */ |
|
121 |
- pkg_free( host_copy ); |
|
122 | 129 |
|
123 | 130 |
if (he==0){ |
124 | 131 |
LOG(L_NOTICE, "ERROR:forward_reply:gethostbyname(%s) failure\n", |
125 | 132 |
via->host.s); |
126 | 133 |
return -1; |
127 | 134 |
} |
128 |
- memcpy(&(to->sin_addr.s_addr), he->h_addr_list[0], |
|
129 |
- sizeof(to->sin_addr.s_addr)); |
|
130 |
- /* |
|
131 |
- to->sin_addr.s_addr=*((long*)he->h_addr_list[0]); |
|
132 |
- */ |
|
135 |
+ hostent2su(to, he, 0, (via->port)?htons(via->port): htons(SIP_PORT)); |
|
133 | 136 |
} |
134 | 137 |
return 1; |
135 | 138 |
} |
... | ... |
@@ -140,7 +143,7 @@ int forward_reply(struct sip_msg* msg) |
140 | 143 |
{ |
141 | 144 |
int r; |
142 | 145 |
char* new_buf; |
143 |
- struct sockaddr_in* to; |
|
146 |
+ union sockaddr_union* to; |
|
144 | 147 |
unsigned int new_len; |
145 | 148 |
struct sr_module *mod; |
146 | 149 |
|
... | ... |
@@ -158,7 +161,6 @@ int forward_reply(struct sip_msg* msg) |
158 | 161 |
} |
159 | 162 |
} |
160 | 163 |
|
161 |
- /* here will be called the T Module !!!!!! */ |
|
162 | 164 |
/* quick hack, slower for mutliple modules*/ |
163 | 165 |
for (mod=modules;mod;mod=mod->next){ |
164 | 166 |
if ((mod->exports) && (mod->exports->response_f)){ |
... | ... |
@@ -176,7 +178,7 @@ int forward_reply(struct sip_msg* msg) |
176 | 178 |
goto error; |
177 | 179 |
} |
178 | 180 |
|
179 |
- to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr_in)); |
|
181 |
+ to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union)); |
|
180 | 182 |
if (to==0){ |
181 | 183 |
LOG(L_ERR, "ERROR: forward_reply: out of memory\n"); |
182 | 184 |
goto error; |
... | ... |
@@ -190,8 +192,8 @@ int forward_reply(struct sip_msg* msg) |
190 | 192 |
|
191 | 193 |
if (update_sock_struct_from_via( to, msg->via2 )==-1) goto error; |
192 | 194 |
|
193 |
- if (udp_send(new_buf,new_len, (struct sockaddr*) to, |
|
194 |
- sizeof(struct sockaddr_in))==-1) |
|
195 |
+ if (udp_send(new_buf,new_len, to, |
|
196 |
+ sizeof(union sockaddr_union))==-1) |
|
195 | 197 |
{ |
196 | 198 |
STATS_TX_DROPS; |
197 | 199 |
goto error; |
... | ... |
@@ -12,7 +12,8 @@ |
12 | 12 |
|
13 | 13 |
|
14 | 14 |
int forward_request( struct sip_msg* msg, struct proxy_l* p); |
15 |
-int update_sock_struct_from_via( struct sockaddr_in* to, struct via_body* via ); |
|
15 |
+int update_sock_struct_from_via( union sockaddr_union* to, |
|
16 |
+ struct via_body* via ); |
|
16 | 17 |
int forward_reply( struct sip_msg* msg); |
17 | 18 |
|
18 | 19 |
#endif |
... | ... |
@@ -10,6 +10,7 @@ |
10 | 10 |
#define globals_h |
11 | 11 |
|
12 | 12 |
#include "types.h" |
13 |
+#include "ip_addr.h" |
|
13 | 14 |
|
14 | 15 |
#define NO_DNS 0 |
15 | 16 |
#define DO_DNS 1 |
... | ... |
@@ -24,17 +25,17 @@ extern int port_no_str_len; |
24 | 25 |
extern unsigned int maxbuffer; |
25 | 26 |
extern char * names[]; |
26 | 27 |
extern int names_len[]; |
27 |
-extern unsigned int addresses[]; |
|
28 |
+extern struct ip_addr addresses[]; |
|
28 | 29 |
extern int addresses_no; |
29 |
-extern unsigned int bind_address; |
|
30 |
+extern struct ip_addr* bind_address; |
|
30 | 31 |
extern int children_no; |
31 |
-extern int debug; |
|
32 | 32 |
extern int dont_fork; |
33 |
-extern int log_stderr; |
|
34 | 33 |
extern int check_via; |
35 | 34 |
extern int received_dns; |
36 | 35 |
extern int loop_checks; |
37 | 36 |
extern int process_no; |
37 |
+/* |
|
38 |
+ * debug & log_stderr moved to dprint.h*/ |
|
38 | 39 |
|
39 | 40 |
extern process_bm_t process_bit; |
40 | 41 |
extern int *pids; |
41 | 42 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,126 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * |
|
5 |
+ * ip address & address family related functions |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+#include <stdio.h> |
|
9 |
+ |
|
10 |
+#include "ip_addr.h" |
|
11 |
+#include "dprint.h" |
|
12 |
+ |
|
13 |
+ |
|
14 |
+struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask) |
|
15 |
+{ |
|
16 |
+ struct net* n; |
|
17 |
+ |
|
18 |
+ if ((ip->af != mask->af) || (ip->len != mask->len)){ |
|
19 |
+ LOG(L_CRIT, "ERROR: mk_net: trying to use a different mask family" |
|
20 |
+ " (eg. ipv4/ipv6mask or ipv6/ipv4mask)\n"); |
|
21 |
+ goto error; |
|
22 |
+ } |
|
23 |
+ n=(struct net*)malloc(sizeof(struct net)); |
|
24 |
+ if (n==0){ |
|
25 |
+ LOG(L_CRIT, "ERROR: mk_net: memory allocation failure\n"); |
|
26 |
+ goto error; |
|
27 |
+ } |
|
28 |
+ n->ip=*ip; |
|
29 |
+ n->mask=*mask; |
|
30 |
+ return n; |
|
31 |
+error: |
|
32 |
+ return 0; |
|
33 |
+} |
|
34 |
+ |
|
35 |
+ |
|
36 |
+ |
|
37 |
+struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen) |
|
38 |
+{ |
|
39 |
+ struct net* n; |
|
40 |
+ int r; |
|
41 |
+ |
|
42 |
+ if (bitlen>ip->len*8){ |
|
43 |
+ LOG(L_CRIT, "ERROR: mk_net_bitlen: bad bitlen number %d\n", bitlen); |
|
44 |
+ goto error; |
|
45 |
+ } |
|
46 |
+ n=(struct net*)malloc(sizeof(struct net)); |
|
47 |
+ if (n==0){ |
|
48 |
+ LOG(L_CRIT, "ERROR: mk_net_bitlen: memory allocation failure\n"); |
|
49 |
+ goto error; |
|
50 |
+ } |
|
51 |
+ memset(n,0, sizeof(struct net)); |
|
52 |
+ n->ip=*ip; |
|
53 |
+ for (r=0;r<bitlen/8;r++) n->mask.u.addr[r]=0xff; |
|
54 |
+ if (bitlen%8) n->mask.u.addr[r]= ~((1<<(8-(bitlen%8)))-1); |
|
55 |
+ n->mask.af=ip->af; |
|
56 |
+ n->mask.len=ip->len; |
|
57 |
+ |
|
58 |
+ return n; |
|
59 |
+error: |
|
60 |
+ return 0; |
|
61 |
+} |
|
62 |
+ |
|
63 |
+ |
|
64 |
+ |
|
65 |
+void print_ip(struct ip_addr* ip) |
|
66 |
+{ |
|
67 |
+ switch(ip->af){ |
|
68 |
+ case AF_INET: |
|
69 |
+ DBG("%d.%d.%d.%d", ip->u.addr[0], |
|
70 |
+ ip->u.addr[1], |
|
71 |
+ ip->u.addr[2], |
|
72 |
+ ip->u.addr[3]); |
|
73 |
+ break; |
|
74 |
+ case AF_INET6: |
|
75 |
+ DBG("%x:%x:%x:%x:%x:%x:%x:%x", htons(ip->u.addr16[0]), |
|
76 |
+ htons(ip->u.addr16[1]), |
|
77 |
+ htons(ip->u.addr16[2]), |
|
78 |
+ htons(ip->u.addr16[3]), |
|
79 |
+ htons(ip->u.addr16[4]), |
|
80 |
+ htons(ip->u.addr16[5]), |
|
81 |
+ htons(ip->u.addr16[6]), |
|
82 |
+ htons(ip->u.addr16[7]) |
|
83 |
+ ); |
|
84 |
+ break; |
|
85 |
+ default: |
|
86 |
+ DBG("print_ip: warning unknown adress family %d\n", ip->af); |
|
87 |
+ } |
|
88 |
+} |
|
89 |
+ |
|
90 |
+ |
|
91 |
+ |
|
92 |
+void stdout_print_ip(struct ip_addr* ip) |
|
93 |
+{ |
|
94 |
+ switch(ip->af){ |
|
95 |
+ case AF_INET: |
|
96 |
+ printf("%d.%d.%d.%d", ip->u.addr[0], |
|
97 |
+ ip->u.addr[1], |
|
98 |
+ ip->u.addr[2], |
|
99 |
+ ip->u.addr[3]); |
|
100 |
+ break; |
|
101 |
+ case AF_INET6: |
|
102 |
+ printf("%x:%x:%x:%x:%x:%x:%x:%x", htons(ip->u.addr16[0]), |
|
103 |
+ htons(ip->u.addr16[1]), |
|
104 |
+ htons(ip->u.addr16[2]), |
|
105 |
+ htons(ip->u.addr16[3]), |
|
106 |
+ htons(ip->u.addr16[4]), |
|
107 |
+ htons(ip->u.addr16[5]), |
|
108 |
+ htons(ip->u.addr16[6]), |
|
109 |
+ htons(ip->u.addr16[7]) |
|
110 |
+ ); |
|
111 |
+ break; |
|
112 |
+ default: |
|
113 |
+ DBG("print_ip: warning unknown adress family %d\n", ip->af); |
|
114 |
+ } |
|
115 |
+} |
|
116 |
+ |
|
117 |
+ |
|
118 |
+ |
|
119 |
+void print_net(struct net* net) |
|
120 |
+{ |
|
121 |
+ if (net==0){ |
|
122 |
+ LOG(L_WARN, "ERROR: print net: null pointer\n"); |
|
123 |
+ return; |
|
124 |
+ } |
|
125 |
+ print_ip(&net->ip); DBG("/"); print_ip(&net->mask); |
|
126 |
+} |
0 | 127 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,336 @@ |
1 |
+/* $Id$ |
|
2 |
+ * |
|
3 |
+ * ip address family realted structures |
|
4 |
+ */ |
|
5 |
+ |
|
6 |
+#ifndef ip_addr_h |
|
7 |
+#define ip_addr_h |
|
8 |
+ |
|
9 |
+#include <string.h> |
|
10 |
+#include <netinet/in.h> |
|
11 |
+#include <netdb.h> |
|
12 |
+ |
|
13 |
+#ifdef USE_IPV6 |
|
14 |
+ #ifdef FreeBSD /* freebsd is brain damaged and needs a different |
|
15 |
+ include */ |
|
16 |
+#include <netinet6/in6.h> |
|
17 |
+ #endif |
|
18 |
+#endif |
|
19 |
+ |
|
20 |
+#include "dprint.h" |
|
21 |
+ |
|
22 |
+ |
|
23 |
+ |
|
24 |
+struct ip_addr{ |
|
25 |
+ unsigned int af; /* address family: AF_INET6 or AF_INET */ |
|
26 |
+ unsigned int len; /* address len, 16 or 4 */ |
|
27 |
+ |
|
28 |
+ /* 64 bits alligned address */ |
|
29 |
+ union { |
|
30 |
+ unsigned int addr32[4]; |
|
31 |
+ unsigned short addr16[8]; |
|
32 |
+ unsigned char addr[16]; |
|
33 |
+ }u; |
|
34 |
+}; |
|
35 |
+ |
|
36 |
+ |
|
37 |
+ |
|
38 |
+struct net{ |
|
39 |
+ struct ip_addr ip; |
|
40 |
+ struct ip_addr mask; |
|
41 |
+}; |
|
42 |
+ |
|
43 |
+union sockaddr_union{ |
|
44 |
+ struct sockaddr s; |
|
45 |
+ struct sockaddr_in sin; |
|
46 |
+ #ifdef USE_IPV6 |
|
47 |
+ struct sockaddr_in6 sin6; |
|
48 |
+ #endif |
|
49 |
+}; |
|
50 |
+ |
|
51 |
+ |
|
52 |
+ |
|
53 |
+ |
|
54 |
+/* inits an ip_addr with the addr. info from a hostent structure |
|
55 |
+ * ip = struct ip_addr* |
|
56 |
+ * he= struct hostent* |
|
57 |
+ */ |
|
58 |
+#define hostent2ip_addr(ip, he, addr_no) \ |
|
59 |
+ do{ \ |
|
60 |
+ (ip)->af=(he)->h_addrtype; \ |
|
61 |
+ (ip)->len=(he)->h_length; \ |
|
62 |
+ memcpy((ip)->u.addr, (he)->h_addr_list[(addr_no)], (ip)->len); \ |
|
63 |
+ }while(0) |
|
64 |
+ |
|
65 |
+ |
|
66 |
+ |
|
67 |
+ |
|
68 |
+/* gets the protocol family corresponding to a specific address family |
|
69 |
+ * ( PF_INET - AF_INET, PF_INET6 - AF_INET6, af for others) |
|
70 |
+ */ |
|
71 |
+#ifdef USE_IPV6 |
|
72 |
+#define AF2PF(af) (((af)==AF_INET)?PF_INET:((af)==AF_INET6)?PF_INET6:(af)) |
|
73 |
+#else |
|
74 |
+#define AF2PF(af) (((af)==AF_INET)?PF_INET:(af)) |
|
75 |
+#endif |
|
76 |
+ |
|
77 |
+ |
|
78 |
+ |
|
79 |
+ |
|
80 |
+struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask); |
|
81 |
+struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen); |
|
82 |
+ |
|
83 |
+void print_ip(struct ip_addr* ip); |
|
84 |
+void stdout_print_ip(struct ip_addr* ip); |
|
85 |
+void print_net(struct net* net); |
|
86 |
+ |
|
87 |
+ |
|
88 |
+ |
|
89 |
+ |
|
90 |
+/* returns 1 if ip & net.mask == net.ip ; 0 otherwise & -1 on error |
|
91 |
+ [ diff. adress fams ]) */ |
|
92 |
+inline static int matchnet(struct ip_addr* ip, struct net* net) |
|
93 |
+{ |
|
94 |
+ int r; |
|
95 |
+ int ret; |
|
96 |
+ |
|
97 |
+ ret=-1; |
|
98 |
+ if (ip->af == net->ip.af){ |
|
99 |
+ for(r=0; r<ip->len/4; r++){ /* ipv4 & ipv6 addresses are |
|
100 |
+ all multiple of 4*/ |
|
101 |
+ if ((ip->u.addr32[r]&net->mask.u.addr32[r])!= |
|
102 |
+ net->ip.u.addr32[r]){ |
|
103 |
+ return 0; |
|
104 |
+ } |
|
105 |
+ } |
|
106 |
+ return 1; |
|
107 |
+ }; |
|
108 |
+ return -1; |
|
109 |
+} |
|
110 |
+ |
|
111 |
+ |
|
112 |
+ |
|
113 |
+/* inits an ip_addr pointer from a sockaddr_union ip address */ |
|
114 |
+static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su) |
|
115 |
+{ |
|
116 |
+ switch(su->s.sa_family){ |
|
117 |
+ case AF_INET: |
|
118 |
+ ip->af=AF_INET; |
|
119 |
+ ip->len=4; |
|
120 |
+ memcpy(ip->u.addr, &su->sin.sin_addr, 4); |
|
121 |
+ break; |
|
122 |
+#ifdef USE_IPV6 |
|
123 |
+ case AF_INET6: |
|
124 |
+ ip->af=AF_INET6; |
|
125 |
+ ip->len=16; |
|
126 |
+ memcpy(ip->u.addr, &su->sin6.sin6_addr, 16); |
|
127 |
+ break; |
|
128 |
+#endif |
|
129 |
+ default: |
|
130 |
+ LOG(L_CRIT,"su2ip_addr: BUG: unknown address family %d\n", |
|
131 |
+ su->s.sa_family); |
|
132 |
+ } |
|
133 |
+} |
|
134 |
+ |
|
135 |
+ |
|
136 |
+ |
|
137 |
+/* inits a struct sockaddr_union from a struct ip_addr and a port no |
|
138 |
+ * returns 0 if ok, -1 on error (unknown address family) */ |
|
139 |
+static inline int init_su( union sockaddr_union* su, |
|
140 |
+ struct ip_addr* ip, |
|
141 |
+ unsigned short port ) |
|
142 |
+{ |
|
143 |
+ su->s.sa_family=ip->af; |
|
144 |
+ switch(ip->af){ |
|
145 |
+#ifdef USE_IPV6 |
|
146 |
+ case AF_INET6: |
|
147 |
+ memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len); |
|
148 |
+ #ifdef FreeBSD |
|
149 |
+ su->sin6.sin6_len=sizeof(struct sockaddr_in6); |
|
150 |
+ #endif |
|
151 |
+ su->sin6.sin6_port=port; |
|
152 |
+ break; |
|
153 |
+#endif |
|
154 |
+ case AF_INET: |
|
155 |
+ memcpy(&su->sin.sin_addr, ip->u.addr, ip->len); |
|
156 |
+ #ifdef FreeBSD |
|
157 |
+ su->sin.sin_len=sizeof(struct sockaddr_in); |
|
158 |
+ #endif |
|
159 |
+ su->sin.sin_port=port; |
|
160 |
+ break; |
|
161 |
+ default: |
|
162 |
+ LOG(L_CRIT, "init_ss: BUG: unknown address family %d\n", ip->af); |
|
163 |
+ return -1; |
|
164 |
+ } |
|
165 |
+ return 0; |
|
166 |
+} |
|
167 |
+ |
|
168 |
+ |
|
169 |
+ |
|
170 |
+/* inits a struct sockaddr_union from a struct hostent, an address index int |
|
171 |
+ * the hostent structure and a port no. |
|
172 |
+ * WARNING: no index overflow checks! |
|
173 |
+ * returns 0 if ok, -1 on error (unknown address family) */ |
|
174 |
+static inline int hostent2su( union sockaddr_union* su, |
|
175 |
+ struct hostent* he, |
|
176 |
+ unsigned int idx, |
|
177 |
+ unsigned short port ) |
|
178 |
+{ |
|
179 |
+ su->s.sa_family=he->h_addrtype; |
|
180 |
+ switch(he->h_addrtype){ |
|
181 |
+#ifdef USE_IPV6 |
|
182 |
+ case AF_INET6: |
|
183 |
+ memcpy(&su->sin6.sin6_addr, he->h_addr_list[idx], he->h_length); |
|
184 |
+ #ifdef FreeBSD |
|
185 |
+ su->sin6.sin6_len=sizeof(struct sockaddr_in6); |
|
186 |
+ #endif |
|
187 |
+ su->sin6.sin6_port=port; |
|
188 |
+ break; |
|
189 |
+#endif |
|
190 |
+ case AF_INET: |
|
191 |
+ memcpy(&su->sin.sin_addr, he->h_addr_list[idx], he->h_length); |
|
192 |
+ #ifdef FreeBSD |
|
193 |
+ su->sin.sin_len=sizeof(struct sockaddr_in); |
|
194 |
+ #endif |
|
195 |
+ su->sin.sin_port=port; |
|
196 |
+ break; |
|
197 |
+ default: |
|
198 |
+ LOG(L_CRIT, "hostent2su: BUG: unknown address family %d\n", |
|
199 |
+ he->h_addrtype); |
|
200 |
+ return -1; |
|
201 |
+ } |
|
202 |
+ return 0; |
|
203 |
+} |
|
204 |
+ |
|
205 |
+ |
|
206 |
+ |
|
207 |
+/* fast ip_addr -> string convertor; |
|
208 |
+ * it uses an internal buffer |
|
209 |
+ */ |
|
210 |
+static inline char* ip_addr2a(struct ip_addr* ip) |
|
211 |
+{ |
|
212 |
+ |
|
213 |
+ static char buff[40];/* 1234:5678:9012:3456:7890:1234:5678:9012\0 */ |
|
214 |
+ int offset; |
|
215 |
+ register unsigned char a,b,c; |
|
216 |
+#ifdef USE_IPV6 |
|
217 |
+ register unsigned char d; |
|
218 |
+#endif |
|
219 |
+ int r; |
|
220 |
+ #define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0') |
|
221 |
+ |
|
222 |
+ |
|
223 |
+ offset=0; |
|
224 |
+ switch(ip->af){ |
|
225 |
+ #ifdef USE_IPV6 |
|
226 |
+ case AF_INET6: |
|
227 |
+ for(r=0;r<7;r++){ |
|
228 |
+ a=ip->u.addr16[r]>>12; |
|
229 |
+ b=(ip->u.addr16[r]>>8)&0xf; |
|
230 |
+ c=(ip->u.addr16[r]>>4)&0xf; |
|
231 |
+ d=ip->u.addr16[r]&0xf; |
|
232 |
+ if (a){ |
|
233 |
+ buff[offset]=HEXDIG(a); |
|
234 |
+ buff[offset+1]=HEXDIG(b); |
|
235 |
+ buff[offset+2]=HEXDIG(c); |
|
236 |
+ buff[offset+3]=HEXDIG(d); |
|
237 |
+ buff[offset+4]=':'; |
|
238 |
+ offset+=5; |
|
239 |
+ }else if(b){ |
|
240 |
+ buff[offset]=HEXDIG(b); |
|
241 |
+ buff[offset+1]=HEXDIG(c); |
|
242 |
+ buff[offset+2]=HEXDIG(d); |
|
243 |
+ buff[offset+3]=':'; |
|
244 |
+ offset+=4; |
|
245 |
+ }else if(c){ |
|
246 |
+ buff[offset]=HEXDIG(c); |
|
247 |
+ buff[offset+1]=HEXDIG(d); |
|
248 |
+ buff[offset+2]=':'; |
|
249 |
+ offset+=3; |
|
250 |
+ }else{ |
|
251 |
+ buff[offset]=HEXDIG(d); |
|
252 |
+ buff[offset+1]=':'; |
|
253 |
+ offset+=2; |
|
254 |
+ } |
|
255 |
+ } |
|
256 |
+ /* last int16*/ |
|
257 |
+ a=ip->u.addr16[r]>>12; |
|
258 |
+ b=(ip->u.addr16[r]>>8)&0xf; |
|
259 |
+ c=(ip->u.addr16[r]>>4)&0xf; |
|
260 |
+ d=ip->u.addr16[r]&0xf; |
|
261 |
+ if (a){ |
|
262 |
+ buff[offset]=HEXDIG(a); |
|
263 |
+ buff[offset+1]=HEXDIG(b); |
|
264 |
+ buff[offset+2]=HEXDIG(c); |
|
265 |
+ buff[offset+3]=HEXDIG(d); |
|
266 |
+ buff[offset+4]=0; |
|
267 |
+ }else if(b){ |
|
268 |
+ buff[offset]=HEXDIG(b); |
|
269 |
+ buff[offset+1]=HEXDIG(c); |
|
270 |
+ buff[offset+2]=HEXDIG(d); |
|
271 |
+ buff[offset+3]=0; |
|
272 |
+ }else if(c){ |
|
273 |
+ buff[offset]=HEXDIG(c); |
|
274 |
+ buff[offset+1]=HEXDIG(d); |
|
275 |
+ buff[offset+2]=0; |
|
276 |
+ }else{ |
|
277 |
+ buff[offset]=HEXDIG(d); |
|
278 |
+ buff[offset+1]=0; |
|
279 |
+ } |
|
280 |
+ break; |
|
281 |
+ #endif |
|
282 |
+ case AF_INET: |
|
283 |
+ for(r=0;r<3;r++){ |
|
284 |
+ a=ip->u.addr[r]/100; |
|
285 |
+ c=ip->u.addr[r]%10; |
|
286 |
+ b=ip->u.addr[r]%100/10; |
|
287 |
+ if (a){ |
|
288 |
+ buff[offset]=a+'0'; |
|
289 |
+ buff[offset+1]=b+'0'; |
|
290 |
+ buff[offset+2]=c+'0'; |
|
291 |
+ buff[offset+3]='.'; |
|
292 |
+ offset+=4; |
|
293 |
+ }else if (b){ |
|
294 |
+ buff[offset]=b+'0'; |
|
295 |
+ buff[offset+1]=c+'0'; |
|
296 |
+ buff[offset+2]='.'; |
|
297 |
+ offset+=3; |
|
298 |
+ }else{ |
|
299 |
+ buff[offset]=c+'0'; |
|
300 |
+ buff[offset+1]='.'; |
|
301 |
+ offset+=2; |
|
302 |
+ } |
|
303 |
+ } |
|
304 |
+ /* last number */ |
|
305 |
+ a=ip->u.addr[r]/100; |
|
306 |
+ c=ip->u.addr[r]%10; |
|
307 |
+ b=ip->u.addr[r]%100/10; |
|
308 |
+ if (a){ |
|
309 |
+ buff[offset]=a+'0'; |
|
310 |
+ buff[offset+1]=b+'0'; |
|
311 |
+ buff[offset+2]=c+'0'; |
|
312 |
+ buff[offset+3]=0; |
|
313 |
+ }else if (b){ |
|
314 |
+ buff[offset]=b+'0'; |
|
315 |
+ buff[offset+1]=c+'0'; |
|
316 |
+ buff[offset+2]=0; |
|
317 |
+ }else{ |
|
318 |
+ buff[offset]=c+'0'; |
|
319 |
+ buff[offset+1]=0; |
|
320 |
+ } |
|
321 |
+ break; |
|
322 |
+ |
|
323 |
+ default: |
|
324 |
+ LOG(L_CRIT, "BUG: ip_addr2a: unknown address family %d\n", |
|
325 |
+ ip->af); |
|
326 |
+ return 0; |
|
327 |
+ } |
|
328 |
+ |
|
329 |
+ return buff; |
|
330 |
+} |
|
331 |
+ |
|
332 |
+ |
|
333 |
+ |
|
334 |
+ |
|
335 |
+ |
|
336 |
+#endif |
... | ... |
@@ -18,6 +18,7 @@ |
18 | 18 |
#include <sys/fcntl.h> |
19 | 19 |
#include <sys/time.h> |
20 | 20 |
#include <sys/wait.h> |
21 |
+#include <signal.h> |
|
21 | 22 |
|
22 | 23 |
#include "config.h" |
23 | 24 |
#include "dprint.h" |
... | ... |
@@ -31,9 +32,10 @@ |
31 | 32 |
#include "sr_module.h" |
32 | 33 |
#include "timer.h" |
33 | 34 |
#include "parser/msg_parser.h" |
35 |
+#include "ip_addr.h" |
|
36 |
+#include "resolve.h" |
|
34 | 37 |
|
35 | 38 |
|
36 |
-#include <signal.h> |
|
37 | 39 |
|
38 | 40 |
#include "stats.h" |
39 | 41 |
|
... | ... |
@@ -51,6 +53,9 @@ static char flags[]= |
51 | 53 |
#else |
52 | 54 |
"Off" |
53 | 55 |
#endif |
56 |
+#ifdef USE_IPV6 |
|
57 |
+", USE_IPV6" |
|
58 |
+#endif |
|
54 | 59 |
#ifdef NO_DEBUG |
55 | 60 |
", NO_DEBUG" |
56 | 61 |
#endif |
... | ... |
@@ -142,7 +147,7 @@ Options:\n\ |
142 | 147 |
-h This help message\n\ |
143 | 148 |
-b nr Maximum receive buffer size which will not be exceeded by\n\ |
144 | 149 |
auto-probing procedure even if OS allows\n\ |
145 |
- -m nr Size of shared memory allocated in Megabytes\n\ |
|
150 |
+ -m nr Size of shared memory allocated in Megabytes\n\ |
|
146 | 151 |
-w dir change the working directory to \"dir\" (default \"/\")\n\ |
147 | 152 |
-t dir chroot to \"dir\"\n\ |
148 | 153 |
-u uid change uid \n\ |
... | ... |
@@ -193,12 +198,13 @@ char* cfg_file = 0; |
193 | 198 |
unsigned short port_no = 0; /* port on which we listen */ |
194 | 199 |
char port_no_str[MAX_PORT_LEN]; |
195 | 200 |
int port_no_str_len=0; |
196 |
-unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do not want to exceed |
|
197 |
- durig the auto-probing procedure; may be |
|
198 |
- re-configured */ |
|
199 |
-int children_no = 0; /* number of children processing requests */ |
|
200 |
-int *pids=0; /*array with childrens pids, 0= main proc, |
|
201 |
- alloc'ed in shared mem if possible*/ |
|
201 |
+unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do |
|
202 |
+ not want to exceed durig the |
|
203 |
+ auto-probing procedure; may |
|
204 |
+ be re-configured */ |
|
205 |
+int children_no = 0; /* number of children processing requests */ |
|
206 |
+int *pids=0; /*array with childrens pids, 0= main proc, |
|
207 |
+ alloc'ed in shared mem if possible*/ |
|
202 | 208 |
int debug = 0; |
203 | 209 |
int dont_fork = 0; |
204 | 210 |
int log_stderr = 0; |
... | ... |
@@ -213,9 +219,9 @@ int gid = 0; |
213 | 219 |
|
214 | 220 |
char* names[MAX_LISTEN]; /* our names */ |
215 | 221 |
int names_len[MAX_LISTEN]; /* lengths of the names*/ |
216 |
-unsigned int addresses[MAX_LISTEN]; /* our ips */ |
|
222 |
+struct ip_addr addresses[MAX_LISTEN]; /* our ips */ |
|
217 | 223 |
int addresses_no=0; /* number of names/ips */ |
218 |
-unsigned int bind_address=0; /* listen address of the crt. process */ |
|
224 |
+struct ip_addr* bind_address; /* listen address of the crt. process */ |
|
219 | 225 |
|
220 | 226 |
/* ipc related globals */ |
221 | 227 |
int process_no = 0; |
... | ... |
@@ -373,7 +379,7 @@ int main_loop() |
373 | 379 |
setstats( 0 ); |
374 | 380 |
#endif |
375 | 381 |
/* only one address */ |
376 |
- if (udp_init(addresses[0],port_no)==-1) goto error; |
|
382 |
+ if (udp_init(&addresses[0],port_no)==-1) goto error; |
|
377 | 383 |
|
378 | 384 |
/* we need another process to act as the timer*/ |
379 | 385 |
if (timer_list){ |
... | ... |
@@ -414,7 +420,7 @@ int main_loop() |
414 | 420 |
}else{ |
415 | 421 |
for(r=0;r<addresses_no;r++){ |
416 | 422 |
/* create the listening socket (for each address)*/ |
417 |
- if (udp_init(addresses[r], port_no)==-1) goto error; |
|
423 |
+ if (udp_init(&addresses[r], port_no)==-1) goto error; |
|
418 | 424 |
for(i=0;i<children_no;i++){ |
419 | 425 |
if ((pid=fork())<0){ |
420 | 426 |
LOG(L_CRIT, "main_loop: Cannot fork\n"); |
... | ... |
@@ -784,8 +790,8 @@ int main(int argc, char** argv) |
784 | 790 |
fprintf(stderr, "ERROR: bad port number: %d\n", port_no); |
785 | 791 |
goto error; |
786 | 792 |
} |
787 |
- /* on some system snprintf return really strange things if it does not have |
|
788 |
- * enough space */ |
|
793 |
+ /* on some system snprintf return really strange things if it does not |
|
794 |
+ have enough space */ |
|
789 | 795 |
port_no_str_len= |
790 | 796 |
(port_no_str_len<MAX_PORT_LEN)?port_no_str_len:MAX_PORT_LEN; |
791 | 797 |
|
... | ... |
@@ -836,16 +842,17 @@ int main(int argc, char** argv) |
836 | 842 |
/* get ips */ |
837 | 843 |
printf("Listening on "); |
838 | 844 |
for (r=0; r<addresses_no;r++){ |
839 |
- he=gethostbyname(names[r]); |
|
845 |
+ he=resolvehost(names[r]); |
|
840 | 846 |
if (he==0){ |
841 | 847 |
DPrint("ERROR: could not resolve %s\n", names[r]); |
842 | 848 |
goto error; |
843 | 849 |
} |
844 |
- memcpy(&addresses[r], he->h_addr_list[0], sizeof(int)); |
|
850 |
+ hostent2ip_addr(&addresses[r], he, 0); /*convert to ip_addr format*/ |
|
851 |
+ /*memcpy(&addresses[r], he->h_addr_list[0], sizeof(int));*/ |
|
845 | 852 |
/*addresses[r]=*((long*)he->h_addr_list[0]);*/ |
846 |
- printf("%s [%s] : %d\n",names[r], |
|
847 |
- inet_ntoa(*(struct in_addr*)&addresses[r]), |
|
848 |
- (unsigned short)port_no); |
|
853 |
+ printf("%s [",names[r]); |
|
854 |
+ stdout_print_ip(&addresses[r]); |
|
855 |
+ printf("]:%d\n", (unsigned short)port_no); |
|
849 | 856 |
} |
850 | 857 |
|
851 | 858 |
#ifdef STATS |
... | ... |
@@ -7,6 +7,7 @@ |
7 | 7 |
|
8 | 8 |
#include "shm_mem.h" |
9 | 9 |
#include "../config.h" |
10 |
+#include "../globals.h" |
|
10 | 11 |
|
11 | 12 |
#ifdef SHM_MMAP |
12 | 13 |
|
... | ... |
@@ -23,6 +24,8 @@ |
23 | 24 |
#endif |
24 | 25 |
|
25 | 26 |
|
27 |
+ |
|
28 |
+ |
|
26 | 29 |
/* define semun */ |
27 | 30 |
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) |
28 | 31 |
/* union semun is defined by including <sys/sem.h> */ |
... | ... |
@@ -9,11 +9,14 @@ |
9 | 9 |
#include <stdio.h> |
10 | 10 |
|
11 | 11 |
#include "msg_translator.h" |
12 |
+#include "globals.h" |
|
12 | 13 |
#include "mem/mem.h" |
13 | 14 |
#include "dprint.h" |
14 | 15 |
#include "config.h" |
15 | 16 |
#include "md5utils.h" |
16 | 17 |
#include "data_lump_rpl.h" |
18 |
+#include "ip_addr.h" |
|
19 |
+#include "resolve.h" |
|
17 | 20 |
|
18 | 21 |
|
19 | 22 |
|
... | ... |
@@ -40,88 +43,35 @@ |
40 | 43 |
extern char version[]; |
41 | 44 |
extern int version_len; |
42 | 45 |
|
43 |
-/* faster than inet_ntoa */ |
|
44 |
-static inline char* q_inet_itoa(unsigned long ip) |
|
45 |
-{ |
|
46 |
- static char q_inet_itoa_buf[16]; /* 123.567.901.345\0 */ |
|
47 |
- unsigned char* p; |
|
48 |
- unsigned char a,b,c; /* abc.def.ghi.jkl */ |
|
49 |
- int offset; |
|
50 |
- int r; |
|
51 |
- p=(unsigned char*)&ip; |
|
52 |
- |
|
53 |
- offset=0; |
|
54 |
- /* unrolled loops (faster)*/ |
|
55 |
- for(r=0;r<3;r++){ |
|
56 |
- a=p[r]/100; |
|
57 |
- c=p[r]%10; |
|
58 |
- b=p[r]%100/10; |
|
59 |
- if (a){ |
|
60 |
- q_inet_itoa_buf[offset]=a+'0'; |
|
61 |
- q_inet_itoa_buf[offset+1]=b+'0'; |
|
62 |
- q_inet_itoa_buf[offset+2]=c+'0'; |
|
63 |
- q_inet_itoa_buf[offset+3]='.'; |
|
64 |
- offset+=4; |
|
65 |
- }else if (b){ |
|
66 |
- q_inet_itoa_buf[offset]=b+'0'; |
|
67 |
- q_inet_itoa_buf[offset+1]=c+'0'; |
|
68 |
- q_inet_itoa_buf[offset+2]='.'; |
|
69 |
- offset+=3; |
|
70 |
- }else{ |
|
71 |
- q_inet_itoa_buf[offset]=c+'0'; |
|
72 |
- q_inet_itoa_buf[offset+1]='.'; |
|
73 |
- offset+=2; |
|
74 |
- } |
|
75 |
- } |
|
76 |
- /* last number */ |
|
77 |
- a=p[r]/100; |
|
78 |
- c=p[r]%10; |
|
79 |
- b=p[r]%100/10; |
|
80 |
- if (a){ |
|
81 |
- q_inet_itoa_buf[offset]=a+'0'; |
|
82 |
- q_inet_itoa_buf[offset+1]=b+'0'; |
|
83 |
- q_inet_itoa_buf[offset+2]=c+'0'; |
|
84 |
- q_inet_itoa_buf[offset+3]=0; |
|
85 |
- }else if (b){ |
|
86 |
- q_inet_itoa_buf[offset]=b+'0'; |
|
87 |
- q_inet_itoa_buf[offset+1]=c+'0'; |
|
88 |
- q_inet_itoa_buf[offset+2]=0; |
|
89 |
- }else{ |
|
90 |
- q_inet_itoa_buf[offset]=c+'0'; |
|
91 |
- q_inet_itoa_buf[offset+1]=0; |
|
92 |
- } |
|
93 |
- |
|
94 |
- return q_inet_itoa_buf; |
|
95 |
-} |
|
96 |
- |
|
97 |
- |
|
98 | 46 |
|
99 | 47 |
|
100 | 48 |
/* checks if ip is in host(name) and ?host(ip)=name? |
101 | 49 |
* ip must be in network byte order! |
102 | 50 |
* resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made |
103 | 51 |
* return 0 if equal */ |
104 |
-int check_address(unsigned long ip, char *name, int resolver) |
|
52 |
+int check_address(struct ip_addr* ip, char *name, int resolver) |
|
105 | 53 |
{ |
106 | 54 |
struct hostent* he; |
107 | 55 |
int i; |
108 | 56 |
|
109 | 57 |
/* maybe we are lucky and name it's an ip */ |
110 |
- if (strcmp(name, q_inet_itoa(ip))==0) |
|
58 |
+ if (strcmp(name, ip_addr2a(ip))==0) |
|
111 | 59 |
return 0; |
112 | 60 |
if (resolver&DO_DNS){ |
113 | 61 |
DBG("check_address: doing dns lookup\n"); |
114 | 62 |
/* try all names ips */ |
115 |
- he=gethostbyname(name); |
|
116 |
- for(i=0;he && he->h_addr_list[i];i++){ |
|
117 |
- if (*(unsigned long*)he->h_addr_list[i]==ip) |
|
118 |
- return 0; |
|
63 |
+ he=resolvehost(name); |
|
64 |
+ if (ip->af==he->h_addrtype){ |
|
65 |
+ for(i=0;he && he->h_addr_list[i];i++){ |
|
66 |
+ if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0) |
|
67 |
+ return 0; |
|
68 |
+ } |
|
119 | 69 |
} |
120 | 70 |
} |
121 | 71 |
if (resolver&DO_REV_DNS){ |
122 | 72 |
DBG("check_address: doing rev. dns lookup\n"); |
123 | 73 |
/* try reverse dns */ |
124 |
- he=gethostbyaddr((char*)&ip, sizeof(ip), AF_INET); |
|
74 |
+ he=rev_resolvehost(ip); |
|
125 | 75 |
if (he && (strcmp(he->h_name, name)==0)) |
126 | 76 |
return 0; |
127 | 77 |
for (i=0; he && he->h_aliases[i];i++){ |
... | ... |
@@ -241,7 +191,7 @@ char * warning_builder( struct sip_msg *msg, unsigned int *returned_len) |
241 | 191 |
/*adding src_ip*/ |
242 | 192 |
if (p-buf+26+2>=MAX_WARNING_LEN) |
243 | 193 |
goto done; |
244 |
- p += sprintf(p,"req_src_ip=%s",q_inet_itoa(msg->src_ip)); |
|
194 |
+ p += sprintf(p,"req_src_ip=%s",ip_addr2a(&msg->src_ip)); |
|
245 | 195 |
*(p++)=' '; |
246 | 196 |
|
247 | 197 |
/*adding in_uri*/ |
... | ... |
@@ -274,7 +224,7 @@ done: |
274 | 224 |
char * build_req_buf_from_sip_req( struct sip_msg* msg, |
275 | 225 |
unsigned int *returned_len) |
276 | 226 |
{ |
277 |
- unsigned int len, new_len, received_len, uri_len, via_len; |
|
227 |
+ unsigned int len, new_len, received_len, uri_len, via_len, extra_len; |
|
278 | 228 |
char* line_buf; |
279 | 229 |
char* received_buf; |
280 | 230 |
char* tmp; |
... | ... |
@@ -284,7 +234,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, |
284 | 234 |
char* buf; |
285 | 235 |
char backup; |
286 | 236 |
unsigned int offset, s_offset, size; |
287 |
- unsigned long source_ip; |
|
237 |
+ struct ip_addr* source_ip; |
|
288 | 238 |
struct lump *t,*r; |
289 | 239 |
struct lump* anchor; |
290 | 240 |
|
... | ... |
@@ -292,10 +242,11 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, |
292 | 242 |
orig=msg->orig; |
293 | 243 |
buf=msg->buf; |
294 | 244 |
len=msg->len; |
295 |
- source_ip=msg->src_ip; |
|
245 |
+ source_ip=&msg->src_ip; |
|
296 | 246 |
received_len=0; |
297 | 247 |
new_buf=0; |
298 | 248 |
received_buf=0; |
249 |
+ extra_len=0; |
|
299 | 250 |
|
300 | 251 |
|
301 | 252 |
line_buf = via_builder( msg, &via_len ); |
... | ... |
@@ -318,10 +269,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, |
318 | 269 |
inet_ntoa(*(struct in_addr *)&source_ip)); |
319 | 270 |
*/ |
320 | 271 |
memcpy(received_buf, RECEIVED, RECEIVED_LEN); |
321 |
- tmp=q_inet_itoa( /* *(struct in_addr *)& */source_ip); |
|
272 |
+ tmp=ip_addr2a(source_ip); |
|
322 | 273 |
tmp_len=strlen(tmp); |
323 | 274 |
received_len=RECEIVED_LEN+tmp_len; |
324 |
- memcpy(received_buf+RECEIVED_LEN, tmp, tmp_len); |
|
275 |
+ if(source_ip->af==AF_INET6){ |
|
276 |
+ received_len+=2; |
|
277 |
+ received_buf[RECEIVED_LEN]='['; |
|
278 |
+ received_buf[RECEIVED_LEN+tmp_len+1]=']'; |
|
279 |
+ extra_len=1; |
|
280 |
+ } |
|
281 |
+ |
|
282 |
+ memcpy(received_buf+RECEIVED_LEN+extra_len, tmp, tmp_len); |
|
325 | 283 |
received_buf[received_len]=0; /*null terminate it */ |
326 | 284 |
} |
327 | 285 |
msg->via1->host.s[msg->via1->host.len] = backup; |
... | ... |
@@ -777,9 +777,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg) |
777 | 777 |
|
778 | 778 |
error: |
779 | 779 |
/* more debugging, msg->orig is/should be null terminated*/ |
780 |
- LOG(L_ERR, "ERROR: parse_msg: ip source=%x dest=%x; message=<%s>\n", |
|
781 |
- msg->src_ip, msg->dst_ip, |
|
782 |
- msg->orig); |
|
780 |
+ LOG(L_ERR, "ERROR: parse_msg: message=<%s>\n", msg->orig); |
|
783 | 781 |
return -1; |
784 | 782 |
} |
785 | 783 |
|
... | ... |
@@ -8,6 +8,7 @@ |
8 | 8 |
#include "../str.h" |
9 | 9 |
#include "../data_lump.h" |
10 | 10 |
#include "../flags.h" |
11 |
+#include "../ip_addr.h" |
|
11 | 12 |
|
12 | 13 |
#define SIP_REQUEST 1 |
13 | 14 |
#define SIP_REPLY 2 |
... | ... |
@@ -209,8 +210,8 @@ struct sip_msg{ |
209 | 210 |
char* eoh; /* pointer to the end of header (if found) or null */ |
210 | 211 |
char* unparsed; /* here we stopped parsing*/ |
211 | 212 |
|
212 |
- unsigned int src_ip; |
|
213 |
- unsigned int dst_ip; |
|
213 |
+ struct ip_addr src_ip; |
|
214 |
+ struct ip_addr dst_ip; |
|
214 | 215 |
char* orig; /* original message copy */ |
215 | 216 |
char* buf; /* scratch pad, holds a modfied message, |
216 | 217 |
via, etc. point into it */ |
... | ... |
@@ -1284,8 +1284,7 @@ main_via: |