Andrei Pelinescu-Onciul 22 роки тому
батько
коміт
50d5fa87f9
7 змінених файлів з 68 додано та 33 видалено
  1. 3 0
      TODO
  2. 1 1
      cfg.y
  3. 33 12
      forward.c
  4. 1 1
      forward.h
  5. 5 5
      main.c
  6. 24 13
      name_alias.h
  7. 1 1
      route.c

+ 3 - 0
TODO

@@ -2,6 +2,9 @@ $Id$
 
 
 ( - todo, x - done)
 ( - todo, x - done)
 
 
+- fix aliases for tls_port (add_them?)
+- fix check_sel_op -- add proto for uri proto checks
+
 - alias support fot tcp/tls port numbers
 - alias support fot tcp/tls port numbers
 - warning builder set_advertised address support
 - warning builder set_advertised address support
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)
 - grep parse_uri & replace with parse_sip_msg_uri (e.g do_action!)

+ 1 - 1
cfg.y

@@ -551,7 +551,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| ALIAS EQUAL  id_lst { 
 		| ALIAS EQUAL  id_lst { 
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
 								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
 								add_alias(lst_tmp->s, strlen(lst_tmp->s), 
-											lst_tmp->port);
+											lst_tmp->port, lst_tmp->proto);
 							  }
 							  }
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
 		| ADVERTISED_ADDRESS EQUAL listen_id {
 		| ADVERTISED_ADDRESS EQUAL listen_id {

+ 33 - 12
forward.c

@@ -42,6 +42,7 @@
  *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
  *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
  *               local replies (andrei)
  *               local replies (andrei)
  *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
  *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
+ *  2003-10-21  check_self updated to handle proto (andrei)
  */
  */
 
 
 
 
@@ -218,17 +219,19 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
 
 
 
 
 
 
-/* checks if the host:port is one of the address we listen on;
+/* checks if the proto: host:port is one of the address we listen on;
  * if port==0, the  port number is ignored
  * if port==0, the  port number is ignored
+ * if proto==0 (PROTO_NONE) the protocol is ignored
  * returns 1 if true, 0 if false, -1 on error
  * returns 1 if true, 0 if false, -1 on error
  * WARNING: uses str2ip6 so it will overwrite any previous
  * WARNING: uses str2ip6 so it will overwrite any previous
  *  unsaved result of this function (static buffer)
  *  unsaved result of this function (static buffer)
  */
  */
-int check_self(str* host, unsigned short port)
+int check_self(str* host, unsigned short port, unsigned short proto)
 {
 {
 	int r;
 	int r;
 	char* hname;
 	char* hname;
 	int h_len;
 	int h_len;
+	struct socket_info* si;
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	struct ip_addr* ip6;
 	struct ip_addr* ip6;
 #endif
 #endif
@@ -242,22 +245,39 @@ int check_self(str* host, unsigned short port)
 		h_len-=2;
 		h_len-=2;
 	}
 	}
 #endif
 #endif
+	/* get teh proper sock list */
+	switch(proto){
+		case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
+		case PROTO_UDP:
+			si=sock_info;
+			break;
+#ifdef USE_TCP
+		case PROTO_TCP:
+			si=tcp_info;
+			break;
+#endif
+#ifdef USE_TLS
+		case PROTO_TLS:
+			si=tls_info;
+			break;
+#endif
+		default:
+			/* unknown proto */
+			LOG(L_WARN, "WARNING: check_self: unknown proto %d\n", proto);
+			return 0; /* false */
+	}
 	for (r=0; r<sock_no; r++){
 	for (r=0; r<sock_no; r++){
 		DBG("check_self - checking if host==us: %d==%d && "
 		DBG("check_self - checking if host==us: %d==%d && "
 				" [%.*s] == [%.*s]\n", 
 				" [%.*s] == [%.*s]\n", 
 					h_len,
 					h_len,
-					sock_info[r].name.len,
+					si[r].name.len,
 					h_len, hname,
 					h_len, hname,
-					sock_info[r].name.len, sock_info[r].name.s
+					si[r].name.len, si[r].name.s
 			);
 			);
 		if (port) {
 		if (port) {
 			DBG("check_self - checking if port %d matches port %d\n", 
 			DBG("check_self - checking if port %d matches port %d\n", 
-					sock_info[r].port_no, port);
-#ifdef USE_TLS
-			if  ((sock_info[r].port_no!=port) && (tls_info[r].port_no!=port)) {
-#else
-			if (sock_info[r].port_no!=port) {
-#endif
+					si[r].port_no, port);
+			if (si[r].port_no!=port) {
 				continue;
 				continue;
 			}
 			}
 		}
 		}
@@ -290,7 +310,7 @@ int check_self(str* host, unsigned short port)
 	}
 	}
 	if (r==sock_no){
 	if (r==sock_no){
 		/* try to look into the aliases*/
 		/* try to look into the aliases*/
-		if (grep_aliases(hname, h_len, port)==0){
+		if (grep_aliases(hname, h_len, port, proto)==0){
 			DBG("check_self: host != me\n");
 			DBG("check_self: host != me\n");
 			return 0;
 			return 0;
 		}
 		}
@@ -487,7 +507,8 @@ int forward_reply(struct sip_msg* msg)
 	/*check if first via host = us */
 	/*check if first via host = us */
 	if (check_via){
 	if (check_via){
 		if (check_self(&msg->via1->host,
 		if (check_self(&msg->via1->host,
-					msg->via1->port?msg->via1->port:SIP_PORT)!=1){
+					msg->via1->port?msg->via1->port:SIP_PORT,
+					msg->via1->proto)!=1){
 			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :"
 			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :"
 					" %.*s:%d\n", msg->via1->host.len, msg->via1->host.s,
 					" %.*s:%d\n", msg->via1->host.len, msg->via1->host.s,
 									msg->via1->port);
 									msg->via1->port);

+ 1 - 1
forward.h

@@ -55,7 +55,7 @@
 
 
 struct socket_info* get_send_socket(union sockaddr_union* su, int proto);
 struct socket_info* get_send_socket(union sockaddr_union* su, int proto);
 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
-int check_self(str* host, unsigned short port);
+int check_self(str* host, unsigned short port, unsigned short proto);
 int forward_request( struct sip_msg* msg,  struct proxy_l* p, int proto);
 int forward_request( struct sip_msg* msg,  struct proxy_l* p, int proto);
 int update_sock_struct_from_via( union sockaddr_union* to,
 int update_sock_struct_from_via( union sockaddr_union* to,
 								 struct sip_msg* msg,
 								 struct sip_msg* msg,

+ 5 - 5
main.c

@@ -1601,7 +1601,7 @@ try_again:
 		/* check if we got the official name */
 		/* check if we got the official name */
 		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){
 		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){
 			if (add_alias(sock_info[r].name.s, sock_info[r].name.len,
 			if (add_alias(sock_info[r].name.s, sock_info[r].name.len,
-							sock_info[r].port_no)<0){
+							sock_info[r].port_no, 0)<0){
 				LOG(L_ERR, "ERROR: main: add_alias failed\n");
 				LOG(L_ERR, "ERROR: main: add_alias failed\n");
 			}
 			}
 			/* change the oficial name */
 			/* change the oficial name */
@@ -1616,7 +1616,7 @@ try_again:
 		}
 		}
 		/* add the aliases*/
 		/* add the aliases*/
 		for(h=he->h_aliases; h && *h; h++)
 		for(h=he->h_aliases; h && *h; h++)
-			if (add_alias(*h, strlen(*h), sock_info[r].port_no)<0){
+			if (add_alias(*h, strlen(*h), sock_info[r].port_no, 0)<0){
 				LOG(L_ERR, "ERROR: main: add_alias failed\n");
 				LOG(L_ERR, "ERROR: main: add_alias failed\n");
 			}
 			}
 		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
 		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
@@ -1643,11 +1643,11 @@ try_again:
 				}else{
 				}else{
 					/* add the aliases*/
 					/* add the aliases*/
 					if (add_alias(he->h_name, strlen(he->h_name),
 					if (add_alias(he->h_name, strlen(he->h_name),
-									sock_info[r].port_no)<0){
+									sock_info[r].port_no, 0)<0){
 						LOG(L_ERR, "ERROR: main: add_alias failed\n");
 						LOG(L_ERR, "ERROR: main: add_alias failed\n");
 					}
 					}
 					for(h=he->h_aliases; h && *h; h++)
 					for(h=he->h_aliases; h && *h; h++)
-						if (add_alias(*h,strlen(*h),sock_info[r].port_no)<0){
+						if (add_alias(*h,strlen(*h),sock_info[r].port_no,0)<0){
 							LOG(L_ERR, "ERROR: main: add_alias failed\n");
 							LOG(L_ERR, "ERROR: main: add_alias failed\n");
 						}
 						}
 				}
 				}
@@ -1680,7 +1680,7 @@ try_again:
 								 sock_info[r].name.len)!=0))
 								 sock_info[r].name.len)!=0))
 					)
 					)
 					add_alias(sock_info[t].name.s, sock_info[t].name.len,
 					add_alias(sock_info[t].name.s, sock_info[t].name.len,
-								sock_info[t].port_no);
+								sock_info[t].port_no, 0);
 						
 						
 				/* free space*/
 				/* free space*/
 				pkg_free(sock_info[t].name.s);
 				pkg_free(sock_info[t].name.s);

+ 24 - 13
name_alias.h

@@ -29,6 +29,7 @@
  * History:
  * History:
  * --------
  * --------
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ *  2003-10-21  support for proto added: proto:host:port (andrei)
  */
  */
 
 
 
 
@@ -42,6 +43,7 @@
 struct host_alias{
 struct host_alias{
 	str alias;
 	str alias;
 	unsigned short port;
 	unsigned short port;
+	unsigned short proto;
 	struct host_alias* next;
 	struct host_alias* next;
 };
 };
 
 
@@ -50,19 +52,17 @@ extern struct host_alias* aliases;
 
 
 
 
 
 
-/* returns 1 if  name is in the alias list; if port=0, port no is ignored*/
-static inline int grep_aliases(char* name, int len, unsigned short port)
+/* returns 1 if  name is in the alias list; if port=0, port no is ignored
+ * if proto=0, proto is ignored*/
+static inline int grep_aliases(char* name, int len, unsigned short port,
+								unsigned short proto)
 {
 {
 	struct  host_alias* a;
 	struct  host_alias* a;
 	
 	
 	for(a=aliases;a;a=a->next)
 	for(a=aliases;a;a=a->next)
-#ifdef USE_TLS
 		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
 		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
-					(port==tls_port_no) ||
-#else
-		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
-#endif
-				(a->port==port)) && (strncasecmp(a->alias.s, name, len)==0))
+				(a->port==port)) && ((a->proto==0) || (proto==0) || 
+				(a->proto==proto)) && (strncasecmp(a->alias.s, name, len)==0))
 			return 1;
 			return 1;
 	return 0;
 	return 0;
 }
 }
@@ -71,14 +71,24 @@ static inline int grep_aliases(char* name, int len, unsigned short port)
 
 
 /* adds an alias to the list (only if it isn't already there)
 /* adds an alias to the list (only if it isn't already there)
  * if port==0, the alias will match all the ports
  * if port==0, the alias will match all the ports
- * returns 1 if a new alias was added, 0 if the alias was already on the list
- * and  -1 on error */
-static inline int add_alias(char* name, int len, unsigned short port)
+ * if proto==0, the alias will match all the protocols
+ * returns 1 if a new alias was added, 0 if a matching alias was already on
+ * the list and  -1 on error */
+static inline int add_alias(char* name, int len, unsigned short port, 
+								unsigned short proto)
 {
 {
 	struct host_alias* a;
 	struct host_alias* a;
 	
 	
-	if ((port) && grep_aliases(name,len, port)) return 0;
-	a=0;
+	if ((port) && (proto)){
+		/* don't add if there is already an alias matching it */
+		if (grep_aliases(name,len, port, proto)) return 0;
+	}else{
+		/* don't add if already in the list with port or proto ==0*/
+		for(a=aliases;a;a=a->next)
+			if ((a->alias.len==len) && (a->port==port) && (a->proto==proto) &&
+					(strncasecmp(a->alias.s, name, len)==0))
+				return 0;
+	}
 	a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
 	a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
 	if(a==0) goto error;
 	if(a==0) goto error;
 	a->alias.s=(char*)pkg_malloc(len+1);
 	a->alias.s=(char*)pkg_malloc(len+1);
@@ -87,6 +97,7 @@ static inline int add_alias(char* name, int len, unsigned short port)
 	memcpy(a->alias.s, name, len);
 	memcpy(a->alias.s, name, len);
 	a->alias.s[len]=0; /* null terminate for easier printing*/
 	a->alias.s[len]=0; /* null terminate for easier printing*/
 	a->port=port;
 	a->port=port;
+	a->proto=proto;
 	a->next=aliases;
 	a->next=aliases;
 	aliases=a;
 	aliases=a;
 	return 1;
 	return 1;

+ 1 - 1
route.c

@@ -376,7 +376,7 @@ inline static int check_self_op(int op, str* s, unsigned short p)
 {
 {
 	int ret;
 	int ret;
 	
 	
-	ret=check_self(s, p);
+	ret=check_self(s, p, 0);
 	switch(op){
 	switch(op){
 		case EQUAL_OP:
 		case EQUAL_OP:
 			break;
 			break;