Browse code

added functions to allow myself check ony based on port numbers

Nils Ohlmeier authored on 17/04/2008 20:52:47
Showing 4 changed files
... ...
@@ -276,6 +276,19 @@ found:
276 276
 	return 1;
277 277
 }
278 278
 
279
+/* checks if the proto:port is one of the ports we listen on;
280
+ * if proto==0 (PROTO_NONE) the protocol is ignored
281
+ * returns 1 if true, 0 if false, -1 on error
282
+ */
283
+int check_self_port(unsigned short port, unsigned short proto)
284
+{
285
+	if (grep_sock_info_by_port(port, proto))
286
+		/* as aliases do not contain different ports we can skip them */
287
+		return 1;
288
+	else
289
+		return 0;
290
+}
291
+
279 292
 
280 293
 
281 294
 /* forwards a request to dst
... ...
@@ -64,6 +64,7 @@ struct socket_info* get_send_socket(struct sip_msg* msg,
64 64
 									union sockaddr_union* su, int proto);
65 65
 struct socket_info* get_out_socket(union sockaddr_union* to, int proto);
66 66
 int check_self(str* host, unsigned short port, unsigned short proto);
67
+int check_self_port(unsigned short port, unsigned short proto);
67 68
 int forward_request( struct sip_msg* msg, str* dst,  unsigned short port,
68 69
 						struct dest_info* send_info);
69 70
 int update_sock_struct_from_via( union sockaddr_union* to,
... ...
@@ -188,7 +188,6 @@ static struct socket_info** get_sock_info_list(unsigned short proto)
188 188
 }
189 189
 
190 190
 
191
-
192 191
 /* checks if the proto: host:port is one of the address we listen on
193 192
  * and returns the corresponding socket_info structure.
194 193
  * if port==0, the  port number is ignored
... ...
@@ -279,6 +278,48 @@ found:
279 279
 	return si;
280 280
 }
281 281
 
282
+/* checks if the proto:port is one of the ports we listen on
283
+ * and returns the corresponding socket_info structure.
284
+ * if proto==0 (PROTO_NONE) the protocol is ignored
285
+ * returns  0 if not found
286
+ */
287
+struct socket_info* grep_sock_info_by_port(unsigned short port, 
288
+											unsigned short proto)
289
+{
290
+	struct socket_info* si;
291
+	struct socket_info** list;
292
+	unsigned short c_proto;
293
+
294
+	if (!port) {
295
+		goto not_found;
296
+	}
297
+	c_proto=proto?proto:PROTO_UDP;
298
+	do{
299
+		/* get the proper sock_list */
300
+		if (c_proto==PROTO_NONE)
301
+			list=&udp_listen;
302
+		else
303
+			list=get_sock_info_list(c_proto);
304
+	
305
+		if (list==0){
306
+			LOG(L_WARN, "WARNING: grep_sock_info_by_port: "
307
+						"unknown proto %d\n", c_proto);
308
+			goto not_found; /* false */
309
+		}
310
+		for (si=*list; si; si=si->next){
311
+			DBG("grep_sock_info_by_port - checking if port %d matches port %d\n", 
312
+					si->port_no, port);
313
+			if (si->port_no==port) {
314
+				goto found;
315
+			}
316
+		}
317
+	}while( (proto==0) && (c_proto=next_proto(c_proto)) );
318
+not_found:
319
+	return 0;
320
+found:
321
+	return si;
322
+}
323
+
282 324
 
283 325
 
284 326
 /* checks if the proto: ip:port is one of the address we listen on
... ...
@@ -69,6 +69,8 @@ void print_aliases();
69 69
 
70 70
 struct socket_info* grep_sock_info(str* host, unsigned short port,
71 71
 										unsigned short proto);
72
+struct socket_info* grep_sock_info_by_port(unsigned short port,
73
+											unsigned short proto);
72 74
 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
73 75
 												unsigned short proto);
74 76