Browse Source

added functions to allow myself check ony based on port numbers

Nils Ohlmeier 17 years ago
parent
commit
2bf9371dea
4 changed files with 58 additions and 1 deletions
  1. 13 0
      forward.c
  2. 1 0
      forward.h
  3. 42 1
      socket_info.c
  4. 2 0
      socket_info.h

+ 13 - 0
forward.c

@@ -276,6 +276,19 @@ found:
 	return 1;
 }
 
+/* checks if the proto:port is one of the ports we listen on;
+ * if proto==0 (PROTO_NONE) the protocol is ignored
+ * returns 1 if true, 0 if false, -1 on error
+ */
+int check_self_port(unsigned short port, unsigned short proto)
+{
+	if (grep_sock_info_by_port(port, proto))
+		/* as aliases do not contain different ports we can skip them */
+		return 1;
+	else
+		return 0;
+}
+
 
 
 /* forwards a request to dst

+ 1 - 0
forward.h

@@ -64,6 +64,7 @@ struct socket_info* get_send_socket(struct sip_msg* msg,
 									union sockaddr_union* su, int proto);
 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
 int check_self(str* host, unsigned short port, unsigned short proto);
+int check_self_port(unsigned short port, unsigned short proto);
 int forward_request( struct sip_msg* msg, str* dst,  unsigned short port,
 						struct dest_info* send_info);
 int update_sock_struct_from_via( union sockaddr_union* to,

+ 42 - 1
socket_info.c

@@ -188,7 +188,6 @@ static struct socket_info** get_sock_info_list(unsigned short proto)
 }
 
 
-
 /* checks if the proto: host:port is one of the address we listen on
  * and returns the corresponding socket_info structure.
  * if port==0, the  port number is ignored
@@ -279,6 +278,48 @@ found:
 	return si;
 }
 
+/* checks if the proto:port is one of the ports we listen on
+ * and returns the corresponding socket_info structure.
+ * if proto==0 (PROTO_NONE) the protocol is ignored
+ * returns  0 if not found
+ */
+struct socket_info* grep_sock_info_by_port(unsigned short port, 
+											unsigned short proto)
+{
+	struct socket_info* si;
+	struct socket_info** list;
+	unsigned short c_proto;
+
+	if (!port) {
+		goto not_found;
+	}
+	c_proto=proto?proto:PROTO_UDP;
+	do{
+		/* get the proper sock_list */
+		if (c_proto==PROTO_NONE)
+			list=&udp_listen;
+		else
+			list=get_sock_info_list(c_proto);
+	
+		if (list==0){
+			LOG(L_WARN, "WARNING: grep_sock_info_by_port: "
+						"unknown proto %d\n", c_proto);
+			goto not_found; /* false */
+		}
+		for (si=*list; si; si=si->next){
+			DBG("grep_sock_info_by_port - checking if port %d matches port %d\n", 
+					si->port_no, port);
+			if (si->port_no==port) {
+				goto found;
+			}
+		}
+	}while( (proto==0) && (c_proto=next_proto(c_proto)) );
+not_found:
+	return 0;
+found:
+	return si;
+}
+
 
 
 /* checks if the proto: ip:port is one of the address we listen on

+ 2 - 0
socket_info.h

@@ -69,6 +69,8 @@ void print_aliases();
 
 struct socket_info* grep_sock_info(str* host, unsigned short port,
 										unsigned short proto);
+struct socket_info* grep_sock_info_by_port(unsigned short port,
+											unsigned short proto);
 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
 												unsigned short proto);