... | ... |
@@ -8,7 +8,7 @@ |
8 | 8 |
VERSION = 0 |
9 | 9 |
PATCHLEVEL = 8 |
10 | 10 |
SUBLEVEL = 7 |
11 |
-EXTRAVERSION = -8-srv |
|
11 |
+EXTRAVERSION = -9-self |
|
12 | 12 |
|
13 | 13 |
RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) |
14 | 14 |
OS = $(shell uname -s) |
... | ... |
@@ -99,7 +99,8 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \ |
99 | 99 |
-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \ |
100 | 100 |
-DUSE_IPV6 \ |
101 | 101 |
-DEXTRA_DEBUG \ |
102 |
- -DVQ_MALLOC -DDBG_QM_MALLOC \ |
|
102 |
+ -DDBG_QM_MALLOC \ |
|
103 |
+ #-DVQ_MALLOC |
|
103 | 104 |
#-DCONTACT_BUG |
104 | 105 |
#-DF_MALLOC \ |
105 | 106 |
#-DDBG_LOCK |
... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
#include "udp_server.h" |
14 | 14 |
#include "route.h" |
15 | 15 |
#include "parser/msg_parser.h" |
16 |
+#include "parser/parse_uri.h" |
|
16 | 17 |
#include "ut.h" |
17 | 18 |
#include "sr_module.h" |
18 | 19 |
#include "mem/mem.h" |
... | ... |
@@ -48,6 +49,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
48 | 49 |
int user; |
49 | 50 |
int err; |
50 | 51 |
struct sip_uri uri; |
52 |
+ struct sip_uri* u; |
|
51 | 53 |
unsigned short port; |
52 | 54 |
|
53 | 55 |
/* reset the value of error to E_UNSPEC so avoid unknowledgable |
... | ... |
@@ -65,30 +67,24 @@ int do_action(struct action* a, struct sip_msg* msg) |
65 | 67 |
case FORWARD_T: |
66 | 68 |
if (a->p1_type==URIHOST_ST){ |
67 | 69 |
/*parse uri*/ |
68 |
- if (msg->new_uri.s){ |
|
69 |
- tmp=msg->new_uri.s; |
|
70 |
- len=msg->new_uri.len; |
|
71 |
- }else{ |
|
72 |
- tmp=msg->first_line.u.request.uri.s; |
|
73 |
- len=msg->first_line.u.request.uri.len; |
|
74 |
- } |
|
75 |
- ret=parse_uri(tmp, len, &uri ); |
|
70 |
+ ret=parse_sip_msg_uri(msg); |
|
76 | 71 |
if (ret<0) { |
77 |
- LOG(L_ERR, "ERROR: do_action: forward: bad_uri <%s>," |
|
78 |
- " dropping packet\n",tmp); |
|
72 |
+ LOG(L_ERR, "ERROR: do_action: forward: bad_uri " |
|
73 |
+ " dropping packet\n"); |
|
79 | 74 |
break; |
80 | 75 |
} |
76 |
+ u=&msg->parsed_uri; |
|
81 | 77 |
switch (a->p2_type){ |
82 | 78 |
case URIPORT_ST: |
83 |
- if (uri.port.s){ |
|
79 |
+ if (u->port.s){ |
|
84 | 80 |
/*port=strtol(uri.port.s,&end,10);*/ |
85 |
- port=str2s((unsigned char*)uri.port.s, |
|
86 |
- uri.port.len, &err); |
|
81 |
+ port=str2s((unsigned char*)u->port.s, |
|
82 |
+ u->port.len, &err); |
|
87 | 83 |
/*if ((end)&&(*end)){*/ |
88 | 84 |
if (err){ |
89 | 85 |
LOG(L_ERR, "ERROR: do_action: " |
90 | 86 |
"forward: bad port in " |
91 |
- "uri: <%s>\n", uri.port.s); |
|
87 |
+ "uri: <%s>\n", u->port.s); |
|
92 | 88 |
ret=E_BAD_URI; |
93 | 89 |
goto error_fwd_uri; |
94 | 90 |
} |
... | ... |
@@ -104,7 +100,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
104 | 100 |
goto error_fwd_uri; |
105 | 101 |
} |
106 | 102 |
/* create a temporary proxy*/ |
107 |
- p=mk_proxy(uri.host.s, port); |
|
103 |
+ p=mk_proxy(u->host.s, port); |
|
108 | 104 |
if (p==0){ |
109 | 105 |
LOG(L_ERR, "ERROR: bad host name in uri," |
110 | 106 |
" dropping packet\n"); |
... | ... |
@@ -112,7 +108,7 @@ int do_action(struct action* a, struct sip_msg* msg) |
112 | 108 |
goto error_fwd_uri; |
113 | 109 |
} |
114 | 110 |
ret=forward_request(msg, p); |
115 |
- free_uri(&uri); |
|
111 |
+ /*free_uri(&uri); -- no longer needed, in sip_msg*/ |
|
116 | 112 |
free_proxy(p); /* frees only p content, not p itself */ |
117 | 113 |
free(p); |
118 | 114 |
if (ret>=0) ret=1; |
... | ... |
@@ -299,6 +295,10 @@ int do_action(struct action* a, struct sip_msg* msg) |
299 | 295 |
pkg_free(msg->new_uri.s); |
300 | 296 |
msg->new_uri.len=0; |
301 | 297 |
msg->new_uri.s=0; |
298 |
+ if (msg->parsed_uri_ok){ |
|
299 |
+ msg->parsed_uri_ok=0; /* invalidate current parsed uri*/ |
|
300 |
+ free_uri(&msg->parsed_uri); |
|
301 |
+ } |
|
302 | 302 |
}; |
303 | 303 |
ret=1; |
304 | 304 |
break; |
... | ... |
@@ -327,6 +327,10 @@ int do_action(struct action* a, struct sip_msg* msg) |
327 | 327 |
if (msg->new_uri.s) { |
328 | 328 |
pkg_free(msg->new_uri.s); |
329 | 329 |
msg->new_uri.len=0; |
330 |
+ if (msg->parsed_uri_ok){ |
|
331 |
+ msg->parsed_uri_ok=0; |
|
332 |
+ free_uri(&msg->parsed_uri); |
|
333 |
+ } |
|
330 | 334 |
} |
331 | 335 |
len=strlen(a->p1.string); |
332 | 336 |
msg->new_uri.s=pkg_malloc(len+1); |
... | ... |
@@ -460,6 +464,10 @@ int do_action(struct action* a, struct sip_msg* msg) |
460 | 464 |
if (msg->new_uri.s) pkg_free(msg->new_uri.s); |
461 | 465 |
msg->new_uri.s=new_uri; |
462 | 466 |
msg->new_uri.len=crt-new_uri; |
467 |
+ if (msg->parsed_uri_ok){ |
|
468 |
+ msg->parsed_uri_ok=0; |
|
469 |
+ free_uri(&msg->parsed_uri); |
|
470 |
+ } |
|
463 | 471 |
free_uri(&uri); |
464 | 472 |
ret=1; |
465 | 473 |
break; |
... | ... |
@@ -508,7 +516,7 @@ error_uri: |
508 | 516 |
if (new_uri) free(new_uri); |
509 | 517 |
return E_UNSPEC; |
510 | 518 |
error_fwd_uri: |
511 |
- free_uri(&uri); |
|
519 |
+ /*free_uri(&uri); -- not needed anymore, using msg->parsed_uri*/ |
|
512 | 520 |
return ret; |
513 | 521 |
} |
514 | 522 |
|
... | ... |
@@ -77,6 +77,7 @@ METHOD method |
77 | 77 |
URI uri |
78 | 78 |
SRCIP src_ip |
79 | 79 |
DSTIP dst_ip |
80 |
+MYSELF myself |
|
80 | 81 |
/* operators */ |
81 | 82 |
EQUAL = |
82 | 83 |
EQUAL_T == |
... | ... |
@@ -180,6 +181,7 @@ EAT_ABLE [\ \t\b\r] |
180 | 181 |
<INITIAL>{URI} { count(); yylval.strval=yytext; return URI; } |
181 | 182 |
<INITIAL>{SRCIP} { count(); yylval.strval=yytext; return SRCIP; } |
182 | 183 |
<INITIAL>{DSTIP} { count(); yylval.strval=yytext; return DSTIP; } |
184 |
+<INITIAL>{MYSELF} { count(); yylval.strval=yytext; return MYSELF; } |
|
183 | 185 |
|
184 | 186 |
<INITIAL>{DEBUG} { count(); yylval.strval=yytext; return DEBUG; } |
185 | 187 |
<INITIAL>{FORK} { count(); yylval.strval=yytext; return FORK; } |
... | ... |
@@ -81,6 +81,7 @@ void* f_tmp; |
81 | 81 |
%token URI |
82 | 82 |
%token SRCIP |
83 | 83 |
%token DSTIP |
84 |
+%token MYSELF |
|
84 | 85 |
|
85 | 86 |
/* config vars. */ |
86 | 87 |
%token DEBUG |
... | ... |
@@ -427,6 +428,9 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
427 | 428 |
| URI EQUAL_T ID {$$ = mk_elem( EQUAL_OP, STRING_ST, |
428 | 429 |
URI_O, $3); |
429 | 430 |
} |
431 |
+ | URI EQUAL_T MYSELF { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
432 |
+ URI_O, 0); |
|
433 |
+ } |
|
430 | 434 |
| URI EQUAL_T error { $$=0; yyerror("string expected"); } |
431 | 435 |
| URI MATCH STRING { $$=mk_elem( MATCH_OP, STRING_ST, |
432 | 436 |
URI_O, $3); |
... | ... |
@@ -447,6 +451,9 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
447 | 451 |
| SRCIP EQUAL_T host { $$=mk_elem( EQUAL_OP, STRING_ST, |
448 | 452 |
SRCIP_O, $3); |
449 | 453 |
} |
454 |
+ | SRCIP EQUAL_T MYSELF { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
455 |
+ SRCIP_O, 0); |
|
456 |
+ } |
|
450 | 457 |
| SRCIP EQUAL_T error { $$=0; yyerror( "ip address or hostname" |
451 | 458 |
"expected" ); } |
452 | 459 |
| SRCIP MATCH STRING { $$=mk_elem( MATCH_OP, STRING_ST, |
... | ... |
@@ -467,6 +474,9 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
467 | 474 |
| DSTIP EQUAL_T host { $$=mk_elem( EQUAL_OP, STRING_ST, |
468 | 475 |
DSTIP_O, $3); |
469 | 476 |
} |
477 |
+ | DSTIP EQUAL_T MYSELF { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
478 |
+ DSTIP_O, 0); |
|
479 |
+ } |
|
470 | 480 |
| DSTIP EQUAL_T error { $$=0; yyerror( "ip address or hostname" |
471 | 481 |
"expected" ); } |
472 | 482 |
| DSTIP MATCH STRING { $$=mk_elem( MATCH_OP, STRING_ST, |
... | ... |
@@ -478,6 +488,18 @@ exp_elem: METHOD EQUAL_T STRING {$$= mk_elem( EQUAL_OP, STRING_ST, |
478 | 488 |
| DSTIP MATCH error { $$=0; yyerror ( "hostname expected" ); } |
479 | 489 |
| DSTIP error { $$=0; |
480 | 490 |
yyerror("invalid operator, == or =~ expected");} |
491 |
+ | MYSELF EQUAL_T URI { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
492 |
+ URI_O, 0); |
|
493 |
+ } |
|
494 |
+ | MYSELF EQUAL_T SRCIP { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
495 |
+ SRCIP_O, 0); |
|
496 |
+ } |
|
497 |
+ | MYSELF EQUAL_T DSTIP { $$=mk_elem( EQUAL_OP, MYSELF_ST, |
|
498 |
+ DSTIP_O, 0); |
|
499 |
+ } |
|
500 |
+ | MYSELF EQUAL_T error { $$=0; |
|
501 |
+ yyerror(" URI, SRCIP or DSTIP expected"); } |
|
502 |
+ | MYSELF error { $$=0; yyerror ("invalid operator, == expected"); } |
|
481 | 503 |
| stm { $$=mk_elem( NO_OP, ACTIONS_ST, ACTION_O, $1 ); } |
482 | 504 |
| NUMBER {$$=mk_elem( NO_OP, NUMBER_ST, NUMBER_O, (void*)$1 ); } |
483 | 505 |
; |
... | ... |
@@ -62,6 +62,52 @@ struct socket_info* get_send_socket(union sockaddr_union* to) |
62 | 62 |
|
63 | 63 |
|
64 | 64 |
|
65 |
+/* checks if the host is one of the address we listen on |
|
66 |
+* returns 1 if true, 0 if false, -1 on error |
|
67 |
+*/ |
|
68 |
+int check_self(str* host) |
|
69 |
+{ |
|
70 |
+ int r; |
|
71 |
+ |
|
72 |
+ for (r=0; r<sock_no; r++){ |
|
73 |
+ DBG("check_self - checking if host==us: %d==%d && " |
|
74 |
+ " [%.*s] == [%.*s]\n", |
|
75 |
+ host->len, |
|
76 |
+ sock_info[r].name.len, |
|
77 |
+ host->len, host->s, |
|
78 |
+ sock_info[r].name.len, sock_info[r].name.s |
|
79 |
+ ); |
|
80 |
+ if ( (host->len==sock_info[r].name.len) && |
|
81 |
+ #ifdef USE_IPV6 |
|
82 |
+ (strncasecmp(host->s, sock_info[r].name.s, |
|
83 |
+ sock_info[r].name.len)==0) /*slower*/ |
|
84 |
+ #else |
|
85 |
+ (memcmp(host->s, sock_info[r].name.s, |
|
86 |
+ sock_info[r].name.len)==0) |
|
87 |
+ #endif |
|
88 |
+ ) |
|
89 |
+ break; |
|
90 |
+ /* check if host == ip address */ |
|
91 |
+ if ( (!sock_info[r].is_ip) && |
|
92 |
+ (host->len==sock_info[r].address_str.len) && |
|
93 |
+ #ifdef USE_IPV6 |
|
94 |
+ (strncasecmp(host->s, sock_info[r].address_str.s, |
|
95 |
+ sock_info[r].address_str.len)==0) /*slower*/ |
|
96 |
+ #else |
|
97 |
+ (memcmp(host->s, sock_info[r].address_str.s, |
|
98 |
+ sock_info[r].address_str.len)==0) |
|
99 |
+ #endif |
|
100 |
+ ) |
|
101 |
+ break; |
|
102 |
+ } |
|
103 |
+ if (r==sock_no){ |
|
104 |
+ DBG("check_self: host != me\n"); |
|
105 |
+ return 0; |
|
106 |
+ } |
|
107 |
+ return 1; |
|
108 |
+} |
|
109 |
+ |
|
110 |
+ |
|
65 | 111 |
int forward_request( struct sip_msg* msg, struct proxy_l * p) |
66 | 112 |
{ |
67 | 113 |
unsigned int len; |
... | ... |
@@ -247,7 +293,6 @@ int update_sock_struct_from_via( union sockaddr_union* to, |
247 | 293 |
/* removes first via & sends msg to the second */ |
248 | 294 |
int forward_reply(struct sip_msg* msg) |
249 | 295 |
{ |
250 |
- int r; |
|
251 | 296 |
char* new_buf; |
252 | 297 |
union sockaddr_union* to; |
253 | 298 |
struct socket_info* send_sock; |
... | ... |
@@ -258,27 +303,7 @@ int forward_reply(struct sip_msg* msg) |
258 | 303 |
new_buf=0; |
259 | 304 |
/*check if first via host = us */ |
260 | 305 |
if (check_via){ |
261 |
- for (r=0; r<sock_no; r++) |
|
262 |
- { |
|
263 |
- DBG("forward_reply - checking if via==us: %d==%d && " |
|
264 |
- " [%.*s] == [%.*s]\n", |
|
265 |
- msg->via1->host.len, |
|
266 |
- sock_info[r].name.len, |
|
267 |
- msg->via1->host.len, msg->via1->host.s, |
|
268 |
- sock_info[r].name.len, sock_info[r].name.s |
|
269 |
- ); |
|
270 |
- if ( (msg->via1->host.len==sock_info[r].name.len) && |
|
271 |
- #ifdef USE_IPV6 |
|
272 |
- (strncasecmp(msg->via1->host.s, sock_info[r].name.s, |
|
273 |
- sock_info[r].name.len)==0) /*slower*/ |
|
274 |
- #else |
|
275 |
- (memcmp(msg->via1->host.s, sock_info[r].name.s, |
|
276 |
- sock_info[r].name.len)==0) |
|
277 |
- #endif |
|
278 |
- ) |
|
279 |
- break; |
|
280 |
- } |
|
281 |
- if (r==sock_no){ |
|
306 |
+ if (check_self(&(msg->via1->host))!=1){ |
|
282 | 307 |
LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :" |
283 | 308 |
" %.*s\n", msg->via1->host.len, msg->via1->host.s); |
284 | 309 |
/* send error msg back? */ |
... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
|
14 | 14 |
|
15 | 15 |
struct socket_info* get_send_socket(union sockaddr_union* su); |
16 |
+int check_self(str* host); |
|
16 | 17 |
int forward_request( struct sip_msg* msg, struct proxy_l* p); |
17 | 18 |
int update_sock_struct_from_via( union sockaddr_union* to, |
18 | 19 |
struct via_body* via ); |
... | ... |
@@ -53,6 +53,7 @@ struct socket_info{ |
53 | 53 |
str address_str; /* ip address converted to string -- optimization*/ |
54 | 54 |
unsigned short port_no; /* port number */ |
55 | 55 |
str port_no_str; /* port number converted to string -- optimization*/ |
56 |
+ int is_ip; /* 1 if name is an ip address, 0 if not -- optimization*/ |
|
56 | 57 |
}; |
57 | 58 |
|
58 | 59 |
|
... | ... |
@@ -197,7 +197,7 @@ int log_stderr = 0; |
197 | 197 |
/* check if reply first via host==us */ |
198 | 198 |
int check_via = 0; |
199 | 199 |
/* shall use stateful synonym branches? faster but not reboot-safe */ |
200 |
-int syn_branch = 0; |
|
200 |
+int syn_branch = 1; |
|
201 | 201 |
/* should replies include extensive warnings? by default yes, |
202 | 202 |
good for trouble-shooting |
203 | 203 |
*/ |
... | ... |
@@ -956,8 +956,14 @@ int main(int argc, char** argv) |
956 | 956 |
goto error; |
957 | 957 |
} |
958 | 958 |
strncpy(sock_info[r].address_str.s, tmp, strlen(tmp)+1); |
959 |
+ /* set is_ip (1 if name is an ip address, 0 otherwise) */ |
|
959 | 960 |
sock_info[r].address_str.len=strlen(tmp); |
960 |
- |
|
961 |
+ if ( (sock_info[r].address_str.len==sock_info[r].name.len)&& |
|
962 |
+ (strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s, |
|
963 |
+ sock_info[r].address_str.len)==0) |
|
964 |
+ ) sock_info[r].is_ip=1; |
|
965 |
+ else sock_info[r].is_ip=0; |
|
966 |
+ |
|
961 | 967 |
if (sock_info[r].port_no==0) sock_info[r].port_no=port_no; |
962 | 968 |
port_no_str_len=snprintf(port_no_str, MAX_PORT_LEN, ":%d", |
963 | 969 |
(unsigned short) sock_info[r].port_no); |
... | ... |
@@ -18,6 +18,7 @@ |
18 | 18 |
#include "../error.h" |
19 | 19 |
#include "../globals.h" |
20 | 20 |
#include "parse_hname2.h" |
21 |
+#include "parse_uri.h" |
|
21 | 22 |
|
22 | 23 |
#ifdef DEBUG_DMALLOC |
23 | 24 |
#include <mem/dmalloc.h> |
... | ... |
@@ -463,6 +464,7 @@ void free_sip_msg(struct sip_msg* msg) |
463 | 464 |
if (msg->add_rm) free_lump_list(msg->add_rm); |
464 | 465 |
if (msg->repl_add_rm) free_lump_list(msg->repl_add_rm); |
465 | 466 |
if (msg->reply_lump) free_reply_lump(msg->reply_lump); |
467 |
+ if (msg->parsed_uri_ok) free_uri(&msg->parsed_uri); |
|
466 | 468 |
pkg_free(msg->orig); |
467 | 469 |
/* don't free anymore -- now a pointer to a static buffer */ |
468 | 470 |
# ifdef DYN_BUF |
... | ... |
@@ -14,7 +14,6 @@ |
14 | 14 |
#include "parse_cseq.h" |
15 | 15 |
#include "parse_to.h" |
16 | 16 |
#include "parse_via.h" |
17 |
-#include "parse_uri.h" |
|
18 | 17 |
#include "parse_fline.h" |
19 | 18 |
#include "hf.h" |
20 | 19 |
|
... | ... |
@@ -46,6 +45,18 @@ if ( (*tmp==(firstchar) || *tmp==((firstchar) | 32)) && \ |
46 | 45 |
} |
47 | 46 |
|
48 | 47 |
|
48 |
+ |
|
49 |
+struct sip_uri { |
|
50 |
+ str user; /* Username */ |
|
51 |
+ str passwd; /* Password */ |
|
52 |
+ str host; /* Host name */ |
|
53 |
+ str port; /* Port number */ |
|
54 |
+ str params; /* Parameters */ |
|
55 |
+ str headers; |
|
56 |
+}; |
|
57 |
+ |
|
58 |
+ |
|
59 |
+ |
|
49 | 60 |
struct sip_msg { |
50 | 61 |
unsigned int id; /* message id, unique/process*/ |
51 | 62 |
struct msg_start first_line; /* Message first line */ |
... | ... |
@@ -96,6 +107,8 @@ struct sip_msg { |
96 | 107 |
/* modifications */ |
97 | 108 |
|
98 | 109 |
str new_uri; /* changed first line uri*/ |
110 |
+ int parsed_uri_ok; /* 1 if parsed_uri is valid, 0 if not */ |
|
111 |
+ struct sip_uri parsed_uri; /* speed-up > keep here the parsed uri*/ |
|
99 | 112 |
|
100 | 113 |
struct lump* add_rm; /* used for all the forwarded requests */ |
101 | 114 |
struct lump* repl_add_rm; /* used for all the forwarded replies */ |
... | ... |
@@ -192,6 +192,33 @@ error: |
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
|
195 |
+ |
|
196 |
+int parse_sip_msg_uri(struct sip_msg* msg) |
|
197 |
+{ |
|
198 |
+ char* tmp; |
|
199 |
+ int tmp_len; |
|
200 |
+ if (msg->parsed_uri_ok) return 1; |
|
201 |
+ else{ |
|
202 |
+ if (msg->new_uri.s){ |
|
203 |
+ tmp=msg->new_uri.s; |
|
204 |
+ tmp_len=msg->new_uri.len; |
|
205 |
+ }else{ |
|
206 |
+ tmp=msg->first_line.u.request.uri.s; |
|
207 |
+ tmp_len=msg->first_line.u.request.uri.len; |
|
208 |
+ } |
|
209 |
+ if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){ |
|
210 |
+ LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%*s>\n", |
|
211 |
+ tmp_len, tmp); |
|
212 |
+ msg->parsed_uri_ok=0; |
|
213 |
+ return -1; |
|
214 |
+ } |
|
215 |
+ msg->parsed_uri_ok=1; |
|
216 |
+ return 1; |
|
217 |
+ } |
|
218 |
+} |
|
219 |
+ |
|
220 |
+ |
|
221 |
+ |
|
195 | 222 |
void free_uri(struct sip_uri* u) |
196 | 223 |
{ |
197 | 224 |
if (u) { |
... | ... |
@@ -11,15 +11,8 @@ |
11 | 11 |
|
12 | 12 |
|
13 | 13 |
#include "../str.h" |
14 |
+#include "../parser/msg_parser.h" |
|
14 | 15 |
|
15 |
-struct sip_uri { |
|
16 |
- str user; /* Username */ |
|
17 |
- str passwd; /* Password */ |
|
18 |
- str host; /* Host name */ |
|
19 |
- str port; /* Port number */ |
|
20 |
- str params; /* Parameters */ |
|
21 |
- str headers; |
|
22 |
-}; |
|
23 | 16 |
|
24 | 17 |
|
25 | 18 |
/* buf= pointer to begining of uri (sip:x@foo.bar:5060;a=b?h=i) |
... | ... |
@@ -27,6 +20,7 @@ struct sip_uri { |
27 | 20 |
* returns: fills uri & returns <0 on error or 0 if ok |
28 | 21 |
*/ |
29 | 22 |
int parse_uri(char *buf, int len, struct sip_uri* uri); |
23 |
+int parse_sip_msg_uri(struct sip_msg* msg); |
|
30 | 24 |
|
31 | 25 |
void free_uri(struct sip_uri* u); |
32 | 26 |
|
... | ... |
@@ -16,12 +16,14 @@ |
16 | 16 |
#include <netdb.h> |
17 | 17 |
|
18 | 18 |
#include "route.h" |
19 |
+#include "forward.h" |
|
19 | 20 |
#include "dprint.h" |
20 | 21 |
#include "proxy.h" |
21 | 22 |
#include "action.h" |
22 | 23 |
#include "sr_module.h" |
23 | 24 |
#include "ip_addr.h" |
24 | 25 |
#include "resolve.h" |
26 |
+#include "parser/parse_uri.h" |
|
25 | 27 |
|
26 | 28 |
#ifdef DEBUG_DMALLOC |
27 | 29 |
#include <dmalloc.h> |
... | ... |
@@ -242,6 +244,7 @@ static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype) |
242 | 244 |
struct hostent* he; |
243 | 245 |
char ** h; |
244 | 246 |
int ret; |
247 |
+ str tmp; |
|
245 | 248 |
|
246 | 249 |
ret=-1; |
247 | 250 |
switch(subtype){ |
... | ... |
@@ -275,6 +278,11 @@ static int comp_ip(struct ip_addr* ip, void* param, int op, int subtype) |
275 | 278 |
} |
276 | 279 |
} |
277 | 280 |
break; |
281 |
+ case MYSELF_ST: /* check if it's one of our addresses*/ |
|
282 |
+ tmp.s=ip_addr2a(ip); |
|
283 |
+ tmp.len=strlen(tmp.s); |
|
284 |
+ ret=check_self(&tmp); |
|
285 |
+ break; |
|
278 | 286 |
default: |
279 | 287 |
LOG(L_CRIT, "BUG: comp_ip: invalid type for " |
280 | 288 |
" src_ip or dst_ip (%d)\n", subtype); |
... | ... |
@@ -304,11 +312,21 @@ static int eval_elem(struct expr* e, struct sip_msg* msg) |
304 | 312 |
break; |
305 | 313 |
case URI_O: |
306 | 314 |
if(msg->new_uri.s){ |
307 |
- ret=comp_str(msg->new_uri.s, e->r.param, |
|
308 |
- e->op, e->subtype); |
|
315 |
+ if (e->subtype==MYSELF_ST){ |
|
316 |
+ if (parse_sip_msg_uri(msg)<0) ret=-1; |
|
317 |
+ else ret=check_self(&msg->parsed_uri.host); |
|
318 |
+ }else{ |
|
319 |
+ ret=comp_str(msg->new_uri.s, e->r.param, |
|
320 |
+ e->op, e->subtype); |
|
321 |
+ } |
|
309 | 322 |
}else{ |
310 |
- ret=comp_str(msg->first_line.u.request.uri.s, e->r.param, |
|
311 |
- e->op, e->subtype); |
|
323 |
+ if (e->subtype==MYSELF_ST){ |
|
324 |
+ if (parse_sip_msg_uri(msg)<0) ret=-1; |
|
325 |
+ else ret=check_self(&msg->parsed_uri.host); |
|
326 |
+ }else{ |
|
327 |
+ ret=comp_str(msg->first_line.u.request.uri.s, |
|
328 |
+ e->r.param, e->op, e->subtype); |
|
329 |
+ } |
|
312 | 330 |
} |
313 | 331 |
break; |
314 | 332 |
case SRCIP_O: |
... | ... |
@@ -32,7 +32,8 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T, |
32 | 32 |
APPEND_BRANCH_T, |
33 | 33 |
REVERT_URI_T }; |
34 | 34 |
enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST, |
35 |
- EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST }; |
|
35 |
+ EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST, |
|
36 |
+ MYSELF_ST }; |
|
36 | 37 |
|
37 | 38 |
|
38 | 39 |
struct expr{ |
... | ... |
@@ -22,12 +22,16 @@ rev_dns=off # (cmd. line: -R) |
22 | 22 |
#listen=127.0.0.1 |
23 | 23 |
#listen=192.168.57.33 |
24 | 24 |
#listen=192.168.57.72 |
25 |
-loop_checks=0 |
|
25 |
+#loop_checks=0 |
|
26 | 26 |
# for more info: sip_router -h |
27 | 27 |
|
28 | 28 |
#modules |
29 | 29 |
|
30 | 30 |
|
31 | 31 |
route{ |
32 |
+ if (myself==uri){ |
|
33 |
+ log("\n\nfrom myself\n\n"); drop; |
|
34 |
+ }; |
|
35 |
+ log("\n\n continue \n\n"); |
|
32 | 36 |
forward(uri:host, uri:port); |
33 | 37 |
} |