... | ... |
@@ -2,6 +2,9 @@ $Id$ |
2 | 2 |
|
3 | 3 |
( - todo, x - done) |
4 | 4 |
|
5 |
+- fix aliases for tls_port (add_them?) |
|
6 |
+- fix check_sel_op -- add proto for uri proto checks |
|
7 |
+ |
|
5 | 8 |
- alias support fot tcp/tls port numbers |
6 | 9 |
- warning builder set_advertised address support |
7 | 10 |
- grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!) |
... | ... |
@@ -551,7 +551,7 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; } |
551 | 551 |
| ALIAS EQUAL id_lst { |
552 | 552 |
for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) |
553 | 553 |
add_alias(lst_tmp->s, strlen(lst_tmp->s), |
554 |
- lst_tmp->port); |
|
554 |
+ lst_tmp->port, lst_tmp->proto); |
|
555 | 555 |
} |
556 | 556 |
| ALIAS EQUAL error { yyerror(" hostname expected"); } |
557 | 557 |
| ADVERTISED_ADDRESS EQUAL listen_id { |
... | ... |
@@ -42,6 +42,7 @@ |
42 | 42 |
* 2003-04-12 update_sock_struct_form via uses also FL_FORCE_RPORT for |
43 | 43 |
* local replies (andrei) |
44 | 44 |
* 2003-08-21 check_self properly handles ipv6 addresses & refs (andrei) |
45 |
+ * 2003-10-21 check_self updated to handle proto (andrei) |
|
45 | 46 |
*/ |
46 | 47 |
|
47 | 48 |
|
... | ... |
@@ -218,17 +219,19 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto) |
218 | 219 |
|
219 | 220 |
|
220 | 221 |
|
221 |
-/* checks if the host:port is one of the address we listen on; |
|
222 |
+/* checks if the proto: host:port is one of the address we listen on; |
|
222 | 223 |
* if port==0, the port number is ignored |
224 |
+ * if proto==0 (PROTO_NONE) the protocol is ignored |
|
223 | 225 |
* returns 1 if true, 0 if false, -1 on error |
224 | 226 |
* WARNING: uses str2ip6 so it will overwrite any previous |
225 | 227 |
* unsaved result of this function (static buffer) |
226 | 228 |
*/ |
227 |
-int check_self(str* host, unsigned short port) |
|
229 |
+int check_self(str* host, unsigned short port, unsigned short proto) |
|
228 | 230 |
{ |
229 | 231 |
int r; |
230 | 232 |
char* hname; |
231 | 233 |
int h_len; |
234 |
+ struct socket_info* si; |
|
232 | 235 |
#ifdef USE_IPV6 |
233 | 236 |
struct ip_addr* ip6; |
234 | 237 |
#endif |
... | ... |
@@ -242,22 +245,39 @@ int check_self(str* host, unsigned short port) |
242 | 245 |
h_len-=2; |
243 | 246 |
} |
244 | 247 |
#endif |
248 |
+ /* get teh proper sock list */ |
|
249 |
+ switch(proto){ |
|
250 |
+ case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */ |
|
251 |
+ case PROTO_UDP: |
|
252 |
+ si=sock_info; |
|
253 |
+ break; |
|
254 |
+#ifdef USE_TCP |
|
255 |
+ case PROTO_TCP: |
|
256 |
+ si=tcp_info; |
|
257 |
+ break; |
|
258 |
+#endif |
|
259 |
+#ifdef USE_TLS |
|
260 |
+ case PROTO_TLS: |
|
261 |
+ si=tls_info; |
|
262 |
+ break; |
|
263 |
+#endif |
|
264 |
+ default: |
|
265 |
+ /* unknown proto */ |
|
266 |
+ LOG(L_WARN, "WARNING: check_self: unknown proto %d\n", proto); |
|
267 |
+ return 0; /* false */ |
|
268 |
+ } |
|
245 | 269 |
for (r=0; r<sock_no; r++){ |
246 | 270 |
DBG("check_self - checking if host==us: %d==%d && " |
247 | 271 |
" [%.*s] == [%.*s]\n", |
248 | 272 |
h_len, |
249 |
- sock_info[r].name.len, |
|
273 |
+ si[r].name.len, |
|
250 | 274 |
h_len, hname, |
251 |
- sock_info[r].name.len, sock_info[r].name.s |
|
275 |
+ si[r].name.len, si[r].name.s |
|
252 | 276 |
); |
253 | 277 |
if (port) { |
254 | 278 |
DBG("check_self - checking if port %d matches port %d\n", |
255 |
- sock_info[r].port_no, port); |
|
256 |
-#ifdef USE_TLS |
|
257 |
- if ((sock_info[r].port_no!=port) && (tls_info[r].port_no!=port)) { |
|
258 |
-#else |
|
259 |
- if (sock_info[r].port_no!=port) { |
|
260 |
-#endif |
|
279 |
+ si[r].port_no, port); |
|
280 |
+ if (si[r].port_no!=port) { |
|
261 | 281 |
continue; |
262 | 282 |
} |
263 | 283 |
} |
... | ... |
@@ -290,7 +310,7 @@ int check_self(str* host, unsigned short port) |
290 | 310 |
} |
291 | 311 |
if (r==sock_no){ |
292 | 312 |
/* try to look into the aliases*/ |
293 |
- if (grep_aliases(hname, h_len, port)==0){ |
|
313 |
+ if (grep_aliases(hname, h_len, port, proto)==0){ |
|
294 | 314 |
DBG("check_self: host != me\n"); |
295 | 315 |
return 0; |
296 | 316 |
} |
... | ... |
@@ -487,7 +507,8 @@ int forward_reply(struct sip_msg* msg) |
487 | 507 |
/*check if first via host = us */ |
488 | 508 |
if (check_via){ |
489 | 509 |
if (check_self(&msg->via1->host, |
490 |
- msg->via1->port?msg->via1->port:SIP_PORT)!=1){ |
|
510 |
+ msg->via1->port?msg->via1->port:SIP_PORT, |
|
511 |
+ msg->via1->proto)!=1){ |
|
491 | 512 |
LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :" |
492 | 513 |
" %.*s:%d\n", msg->via1->host.len, msg->via1->host.s, |
493 | 514 |
msg->via1->port); |
... | ... |
@@ -55,7 +55,7 @@ |
55 | 55 |
|
56 | 56 |
struct socket_info* get_send_socket(union sockaddr_union* su, int proto); |
57 | 57 |
struct socket_info* get_out_socket(union sockaddr_union* to, int proto); |
58 |
-int check_self(str* host, unsigned short port); |
|
58 |
+int check_self(str* host, unsigned short port, unsigned short proto); |
|
59 | 59 |
int forward_request( struct sip_msg* msg, struct proxy_l* p, int proto); |
60 | 60 |
int update_sock_struct_from_via( union sockaddr_union* to, |
61 | 61 |
struct sip_msg* msg, |
... | ... |
@@ -1601,7 +1601,7 @@ try_again: |
1601 | 1601 |
/* check if we got the official name */ |
1602 | 1602 |
if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){ |
1603 | 1603 |
if (add_alias(sock_info[r].name.s, sock_info[r].name.len, |
1604 |
- sock_info[r].port_no)<0){ |
|
1604 |
+ sock_info[r].port_no, 0)<0){ |
|
1605 | 1605 |
LOG(L_ERR, "ERROR: main: add_alias failed\n"); |
1606 | 1606 |
} |
1607 | 1607 |
/* change the oficial name */ |
... | ... |
@@ -1616,7 +1616,7 @@ try_again: |
1616 | 1616 |
} |
1617 | 1617 |
/* add the aliases*/ |
1618 | 1618 |
for(h=he->h_aliases; h && *h; h++) |
1619 |
- if (add_alias(*h, strlen(*h), sock_info[r].port_no)<0){ |
|
1619 |
+ if (add_alias(*h, strlen(*h), sock_info[r].port_no, 0)<0){ |
|
1620 | 1620 |
LOG(L_ERR, "ERROR: main: add_alias failed\n"); |
1621 | 1621 |
} |
1622 | 1622 |
hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr |
... | ... |
@@ -1643,11 +1643,11 @@ try_again: |
1643 | 1643 |
}else{ |
1644 | 1644 |
/* add the aliases*/ |
1645 | 1645 |
if (add_alias(he->h_name, strlen(he->h_name), |
1646 |
- sock_info[r].port_no)<0){ |
|
1646 |
+ sock_info[r].port_no, 0)<0){ |
|
1647 | 1647 |
LOG(L_ERR, "ERROR: main: add_alias failed\n"); |
1648 | 1648 |
} |
1649 | 1649 |
for(h=he->h_aliases; h && *h; h++) |
1650 |
- if (add_alias(*h,strlen(*h),sock_info[r].port_no)<0){ |
|
1650 |
+ if (add_alias(*h,strlen(*h),sock_info[r].port_no,0)<0){ |
|
1651 | 1651 |
LOG(L_ERR, "ERROR: main: add_alias failed\n"); |
1652 | 1652 |
} |
1653 | 1653 |
} |
... | ... |
@@ -1680,7 +1680,7 @@ try_again: |
1680 | 1680 |
sock_info[r].name.len)!=0)) |
1681 | 1681 |
) |
1682 | 1682 |
add_alias(sock_info[t].name.s, sock_info[t].name.len, |
1683 |
- sock_info[t].port_no); |
|
1683 |
+ sock_info[t].port_no, 0); |
|
1684 | 1684 |
|
1685 | 1685 |
/* free space*/ |
1686 | 1686 |
pkg_free(sock_info[t].name.s); |
... | ... |
@@ -29,6 +29,7 @@ |
29 | 29 |
* History: |
30 | 30 |
* -------- |
31 | 31 |
* 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
32 |
+ * 2003-10-21 support for proto added: proto:host:port (andrei) |
|
32 | 33 |
*/ |
33 | 34 |
|
34 | 35 |
|
... | ... |
@@ -42,6 +43,7 @@ |
42 | 43 |
struct host_alias{ |
43 | 44 |
str alias; |
44 | 45 |
unsigned short port; |
46 |
+ unsigned short proto; |
|
45 | 47 |
struct host_alias* next; |
46 | 48 |
}; |
47 | 49 |
|
... | ... |
@@ -50,19 +52,17 @@ extern struct host_alias* aliases; |
50 | 52 |
|
51 | 53 |
|
52 | 54 |
|
53 |
-/* returns 1 if name is in the alias list; if port=0, port no is ignored*/ |
|
54 |
-static inline int grep_aliases(char* name, int len, unsigned short port) |
|
55 |
+/* returns 1 if name is in the alias list; if port=0, port no is ignored |
|
56 |
+ * if proto=0, proto is ignored*/ |
|
57 |
+static inline int grep_aliases(char* name, int len, unsigned short port, |
|
58 |
+ unsigned short proto) |
|
55 | 59 |
{ |
56 | 60 |
struct host_alias* a; |
57 | 61 |
|
58 | 62 |
for(a=aliases;a;a=a->next) |
59 |
-#ifdef USE_TLS |
|
60 | 63 |
if ((a->alias.len==len) && ((a->port==0) || (port==0) || |
61 |
- (port==tls_port_no) || |
|
62 |
-#else |
|
63 |
- if ((a->alias.len==len) && ((a->port==0) || (port==0) || |
|
64 |
-#endif |
|
65 |
- (a->port==port)) && (strncasecmp(a->alias.s, name, len)==0)) |
|
64 |
+ (a->port==port)) && ((a->proto==0) || (proto==0) || |
|
65 |
+ (a->proto==proto)) && (strncasecmp(a->alias.s, name, len)==0)) |
|
66 | 66 |
return 1; |
67 | 67 |
return 0; |
68 | 68 |
} |
... | ... |
@@ -71,14 +71,24 @@ static inline int grep_aliases(char* name, int len, unsigned short port) |
71 | 71 |
|
72 | 72 |
/* adds an alias to the list (only if it isn't already there) |
73 | 73 |
* if port==0, the alias will match all the ports |
74 |
- * returns 1 if a new alias was added, 0 if the alias was already on the list |
|
75 |
- * and -1 on error */ |
|
76 |
-static inline int add_alias(char* name, int len, unsigned short port) |
|
74 |
+ * if proto==0, the alias will match all the protocols |
|
75 |
+ * returns 1 if a new alias was added, 0 if a matching alias was already on |
|
76 |
+ * the list and -1 on error */ |
|
77 |
+static inline int add_alias(char* name, int len, unsigned short port, |
|
78 |
+ unsigned short proto) |
|
77 | 79 |
{ |
78 | 80 |
struct host_alias* a; |
79 | 81 |
|
80 |
- if ((port) && grep_aliases(name,len, port)) return 0; |
|
81 |
- a=0; |
|
82 |
+ if ((port) && (proto)){ |
|
83 |
+ /* don't add if there is already an alias matching it */ |
|
84 |
+ if (grep_aliases(name,len, port, proto)) return 0; |
|
85 |
+ }else{ |
|
86 |
+ /* don't add if already in the list with port or proto ==0*/ |
|
87 |
+ for(a=aliases;a;a=a->next) |
|
88 |
+ if ((a->alias.len==len) && (a->port==port) && (a->proto==proto) && |
|
89 |
+ (strncasecmp(a->alias.s, name, len)==0)) |
|
90 |
+ return 0; |
|
91 |
+ } |
|
82 | 92 |
a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias)); |
83 | 93 |
if(a==0) goto error; |
84 | 94 |
a->alias.s=(char*)pkg_malloc(len+1); |
... | ... |
@@ -87,6 +97,7 @@ static inline int add_alias(char* name, int len, unsigned short port) |
87 | 97 |
memcpy(a->alias.s, name, len); |
88 | 98 |
a->alias.s[len]=0; /* null terminate for easier printing*/ |
89 | 99 |
a->port=port; |
100 |
+ a->proto=proto; |
|
90 | 101 |
a->next=aliases; |
91 | 102 |
aliases=a; |
92 | 103 |
return 1; |