Jelajahi Sumber

- timer will use first ipv4/ipv6 socket for sending and not the first
interface (which can be a loopback)
- rport related src_port fixes (all ports are now kept in host byte order)

Andrei Pelinescu-Onciul 22 tahun lalu
induk
melakukan
4c4e112f78
8 mengubah file dengan 30 tambahan dan 25 penghapusan
  1. 1 1
      Makefile.defs
  2. 15 14
      ip_addr.h
  3. 3 2
      main.c
  4. 2 2
      msg_translator.c
  5. 3 0
      parser/parse_param.c
  6. 2 2
      route.c
  7. 2 2
      tcp_main.c
  8. 2 2
      tcp_read.c

+ 1 - 1
Makefile.defs

@@ -18,7 +18,7 @@
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   11
 SUBLEVEL =   11
-EXTRAVERSION = pre10-allmost-there
+EXTRAVERSION = pre11-rport+ba
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 15 - 14
ip_addr.h

@@ -93,8 +93,8 @@ struct socket_info{
 struct receive_info{
 struct receive_info{
 	struct ip_addr src_ip;
 	struct ip_addr src_ip;
 	struct ip_addr dst_ip;
 	struct ip_addr dst_ip;
-	unsigned short src_port;
-	unsigned short dst_port;
+	unsigned short src_port; /* host byte order */
+	unsigned short dst_port; /* host byte order */
 	int proto;
 	int proto;
 	int proto_reserved1; /* tcp stores the connection id here */
 	int proto_reserved1; /* tcp stores the connection id here */
 	int proto_reserved2;
 	int proto_reserved2;
@@ -240,15 +240,15 @@ static inline int su_cmp(union sockaddr_union* s1, union sockaddr_union* s2)
 
 
 
 
 
 
-/* gets the port number */
+/* gets the port number (host byte order) */
 static inline short su_getport(union sockaddr_union* su)
 static inline short su_getport(union sockaddr_union* su)
 {
 {
 	switch(su->s.sa_family){
 	switch(su->s.sa_family){
 		case AF_INET:
 		case AF_INET:
-			return su->sin.sin_port;
+			return ntohs(su->sin.sin_port);
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 		case AF_INET6:
 		case AF_INET6:
-			return su->sin6.sin6_port;
+			return ntohs(su->sin6.sin6_port);
 #endif
 #endif
 		default:
 		default:
 			LOG(L_CRIT,"su_get_port: BUG: unknown address family %d\n",
 			LOG(L_CRIT,"su_get_port: BUG: unknown address family %d\n",
@@ -259,16 +259,16 @@ static inline short su_getport(union sockaddr_union* su)
 
 
 
 
 
 
-/* sets the port number */
+/* sets the port number (host byte order) */
 static inline void su_setport(union sockaddr_union* su, unsigned short port)
 static inline void su_setport(union sockaddr_union* su, unsigned short port)
 {
 {
 	switch(su->s.sa_family){
 	switch(su->s.sa_family){
 		case AF_INET:
 		case AF_INET:
-			su->sin.sin_port=port;
+			su->sin.sin_port=htons(port);
 			break;
 			break;
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 		case AF_INET6:
 		case AF_INET6:
-			 su->sin6.sin6_port=port;
+			 su->sin6.sin6_port=htons(port);
 			 break;
 			 break;
 #endif
 #endif
 		default:
 		default:
@@ -306,7 +306,8 @@ static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su)
 #define ip_addr2su init_su
 #define ip_addr2su init_su
 
 
 /* inits a struct sockaddr_union from a struct ip_addr and a port no 
 /* inits a struct sockaddr_union from a struct ip_addr and a port no 
- * returns 0 if ok, -1 on error (unknown address family) */
+ * returns 0 if ok, -1 on error (unknown address family)
+ * the port number is in host byte order */
 static inline int init_su( union sockaddr_union* su,
 static inline int init_su( union sockaddr_union* su,
 							struct ip_addr* ip,
 							struct ip_addr* ip,
 							unsigned short   port ) 
 							unsigned short   port ) 
@@ -320,7 +321,7 @@ static inline int init_su( union sockaddr_union* su,
 		#ifdef HAVE_SOCKADDR_SA_LEN
 		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		#endif
-		su->sin6.sin6_port=port;
+		su->sin6.sin6_port=htons(port);
 		break;
 		break;
 #endif
 #endif
 	case AF_INET:
 	case AF_INET:
@@ -328,7 +329,7 @@ static inline int init_su( union sockaddr_union* su,
 		#ifdef HAVE_SOCKADDR_SA_LEN
 		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		#endif
-		su->sin.sin_port=port;
+		su->sin.sin_port=htons(port);
 		break;
 		break;
 	default:
 	default:
 		LOG(L_CRIT, "init_ss: BUG: unknown address family %d\n", ip->af);
 		LOG(L_CRIT, "init_ss: BUG: unknown address family %d\n", ip->af);
@@ -340,7 +341,7 @@ static inline int init_su( union sockaddr_union* su,
 
 
 
 
 /* inits a struct sockaddr_union from a struct hostent, an address index in
 /* inits a struct sockaddr_union from a struct hostent, an address index in
- * the hostent structure and a port no.
+ * the hostent structure and a port no. (host byte order)
  * WARNING: no index overflow  checks!
  * WARNING: no index overflow  checks!
  * returns 0 if ok, -1 on error (unknown address family) */
  * returns 0 if ok, -1 on error (unknown address family) */
 static inline int hostent2su( union sockaddr_union* su,
 static inline int hostent2su( union sockaddr_union* su,
@@ -357,7 +358,7 @@ static inline int hostent2su( union sockaddr_union* su,
 		#ifdef HAVE_SOCKADDR_SA_LEN
 		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		#endif
-		su->sin6.sin6_port=port;
+		su->sin6.sin6_port=htons(port);
 		break;
 		break;
 #endif
 #endif
 	case AF_INET:
 	case AF_INET:
@@ -365,7 +366,7 @@ static inline int hostent2su( union sockaddr_union* su,
 		#ifdef HAVE_SOCKADDR_SA_LEN
 		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		#endif
-		su->sin.sin_port=port;
+		su->sin.sin_port=htons(port);
 		break;
 		break;
 	default:
 	default:
 		LOG(L_CRIT, "hostent2su: BUG: unknown address family %d\n", 
 		LOG(L_CRIT, "hostent2su: BUG: unknown address family %d\n", 

+ 3 - 2
main.c

@@ -755,8 +755,9 @@ int main_loop()
 	}
 	}
 
 
 	/*this is the main process*/
 	/*this is the main process*/
-	bind_address=&sock_info[0]; /* main proc -> it shoudln't send anything, */
-	bind_idx=0;					/* if it does it will use the first address */
+	bind_address=0;				/* main proc -> it shouldn't send anything, */
+	bind_idx=0;					/* if it does get_send_sock should return
+	                               a good socket */
 	
 	
 	/* if configured to do so, start a server for accepting FIFO commands */
 	/* if configured to do so, start a server for accepting FIFO commands */
 	if (open_fifo_server()<0) {
 	if (open_fifo_server()<0) {

+ 2 - 2
msg_translator.c

@@ -204,7 +204,7 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
 		str_int_print("pid=", my_pid());
 		str_int_print("pid=", my_pid());
 		/* req_src_ip= */
 		/* req_src_ip= */
 		str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
 		str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
-		str_int_print(" req_src_port=", ntohs(msg->rcv.src_port));
+		str_int_print(" req_src_port=", msg->rcv.src_port);
 		str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
 		str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
 									msg->first_line.u.request.uri.len);
 									msg->first_line.u.request.uri.len);
 		str_pair_print(" out_uri=", foo->s, foo->len);
 		str_pair_print(" out_uri=", foo->s, foo->len);
@@ -272,7 +272,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
 	int len;
 	int len;
 	
 	
 	tmp_len=0;
 	tmp_len=0;
-	tmp=int2str(ntohs(msg->rcv.src_port), &tmp_len);
+	tmp=int2str(msg->rcv.src_port, &tmp_len);
 	len=RPORT_LEN+tmp_len;
 	len=RPORT_LEN+tmp_len;
 	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
 	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
 	if (buf==0){
 	if (buf==0){

+ 3 - 0
parser/parse_param.c

@@ -247,6 +247,9 @@ static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, par
 }
 }
 
 
 
 
+
+
+
 /*
 /*
  * Parse body of a parameter. It can be quoted string or
  * Parse body of a parameter. It can be quoted string or
  * a single token.
  * a single token.

+ 2 - 2
route.c

@@ -441,13 +441,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 				else ret=1;
 				else ret=1;
 				break;
 				break;
 		case SRCPORT_O:
 		case SRCPORT_O:
-				ret=comp_no(ntohs(msg->rcv.src_port), 
+				ret=comp_no(msg->rcv.src_port, 
 					e->r.param, /* e.g., 5060 */
 					e->r.param, /* e.g., 5060 */
 					e->op, /* e.g. == */
 					e->op, /* e.g. == */
 					e->subtype /* 5060 is number */);
 					e->subtype /* 5060 is number */);
 				break;
 				break;
 		case DSTPORT_O:
 		case DSTPORT_O:
-				ret=comp_no(ntohs(msg->rcv.dst_port), e->r.param, e->op, 
+				ret=comp_no(msg->rcv.dst_port, e->r.param, e->op, 
 							e->subtype);
 							e->subtype);
 				break;
 				break;
 		case PROTO_O:
 		case PROTO_O:

+ 2 - 2
tcp_main.c

@@ -283,7 +283,7 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
 		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			print_ip(&c->rcv.src_ip);
 			print_ip(&c->rcv.src_ip);
-			DBG(" port=%d\n", ntohs(c->rcv.src_port));
+			DBG(" port=%d\n", c->rcv.src_port);
 			if ((id==c->id)&&(!c->bad)) return c;
 			if ((id==c->id)&&(!c->bad)) return c;
 		}
 		}
 	}else if (ip){
 	}else if (ip){
@@ -291,7 +291,7 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
 		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			DBG("c=%p, c->id=%d, ip=",c, c->id);
 			print_ip(&c->rcv.src_ip);
 			print_ip(&c->rcv.src_ip);
-			DBG(" port=%d\n", ntohs(c->rcv.src_port));
+			DBG(" port=%d\n", c->rcv.src_port);
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
 			if ( (!c->bad) && (port==c->rcv.src_port) &&
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
 					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
 				return c;
 				return c;

+ 2 - 2
tcp_read.c

@@ -391,14 +391,14 @@ again:
 					  "buf:\n%.*s\nparsed:\n%.*s\n", req->state, req->error,
 					  "buf:\n%.*s\nparsed:\n%.*s\n", req->state, req->error,
 					  (int)(req->pos-req->buf), req->buf,
 					  (int)(req->pos-req->buf), req->buf,
 					  (int)(req->parsed-req->start), req->start);
 					  (int)(req->parsed-req->start), req->start);
-			DBG("- received from: port %d, ip -", ntohs(con->rcv.src_port));
+			DBG("- received from: port %d, ip -", con->rcv.src_port);
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			resp=CONN_ERROR;
 			resp=CONN_ERROR;
 			goto end_req;
 			goto end_req;
 		}
 		}
 		if (req->complete){
 		if (req->complete){
 			DBG("tcp_read_req: end of header part\n");
 			DBG("tcp_read_req: end of header part\n");
-			DBG("- received from: port %d, ip - ", ntohs(con->rcv.src_port));
+			DBG("- received from: port %d, ip - ", con->rcv.src_port);
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			DBG("tcp_read_req: headers:\n%.*s.\n",
 			DBG("tcp_read_req: headers:\n%.*s.\n",
 					(int)(req->body-req->start), req->start);
 					(int)(req->body-req->start), req->start);