瀏覽代碼

rr: use default port for protocol if it is omitted in route header

When using double route headers the selection of the outgoing
socket is only done on IP address if the port is omitted in that
route header. This fix defaults the port to 5060/5061 depending on
protocol so the correct listen socket is chosen. When no socket is
found it will fallback to the current behaviour keeping backwards
interoperability.
Timmo Verlaan 9 年之前
父節點
當前提交
aaec127fbf
共有 2 個文件被更改,包括 5 次插入2 次删除
  1. 3 2
      modules/rr/loose.c
  2. 2 0
      socket_info.h

+ 3 - 2
modules/rr/loose.c

@@ -827,8 +827,9 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
 			}
 			}
 
 
 			if (!use_ob) {
 			if (!use_ob) {
-				si = grep_sock_info( &puri.host, puri.port_no, puri.proto);
-				if (si) {
+				if ((si = grep_sock_info( &puri.host, puri.port_no?puri.port_no:proto_default_port(puri.proto), puri.proto)) != 0) {
+					set_force_socket(_m, si);
+				} else if ((si = grep_sock_info( &puri.host, puri.port_no, puri.proto)) != 0) {
 					set_force_socket(_m, si);
 					set_force_socket(_m, si);
 				} else {
 				} else {
 					if (enable_socket_mismatch_warning)
 					if (enable_socket_mismatch_warning)

+ 2 - 0
socket_info.h

@@ -44,6 +44,8 @@
 int socket2str(char* s, int* len, struct socket_info* si);
 int socket2str(char* s, int* len, struct socket_info* si);
 int socketinfo2str(char* s, int* len, struct socket_info* si, int mode);
 int socketinfo2str(char* s, int* len, struct socket_info* si, int mode);
 
 
+/* Helper macro that results in the default port based on the protocol */
+#define proto_default_port(proto) ((proto==PROTO_TLS)?SIPS_PORT:SIP_PORT)
 
 
 /* struct socket_info is defined in ip_addr.h */
 /* struct socket_info is defined in ip_addr.h */