Browse code

dst blacklist callbacks are extended with the sip msg parameter.

WARNING: the sip msg might be in shared memory without locking,
do not modify it!

Miklos Tirpak authored on 26/07/2007 11:52:22
Showing 5 changed files
... ...
@@ -133,8 +133,8 @@ struct dst_blst_lst_head* dst_blst_hash=0;
133 133
 
134 134
 /* there 2 types of callbacks supported: on add new entry to the blacklist
135 135
  *  (DST_BLACKLIST_ADD_CB) and on blacklist search (DST_BLACKLIST_SEARCH_CB).
136
- *  Both of them take a struct dest_info* and a flags pointer as parameters 
137
- *   (unsigned char*). The flags can be changed.
136
+ *  Both of them take a struct dest_info*, a flags pointer(unsigned char*),
137
+ *  and a struct sip_msg* as parameters. The flags can be changed.
138 138
  *  A callback should return one of:
139 139
  *    DST_BLACKLIST_CONTINUE - do nothing, let other callbacks run
140 140
  *    DST_BLACKLIST_ACCEPT   - for blacklist add: force accept immediately,
... ...
@@ -262,7 +262,7 @@ error:
262 262
 
263 263
 
264 264
 inline static int blacklist_run_hooks(struct blst_callbacks_lst *cb_lst,
265
-							struct dest_info* si, unsigned char* flags)
265
+							struct dest_info* si, unsigned char* flags, struct sip_msg* msg)
266 266
 {
267 267
 	int r;
268 268
 	int ret;
... ...
@@ -272,7 +272,7 @@ inline static int blacklist_run_hooks(struct blst_callbacks_lst *cb_lst,
272 272
 	if (likely(cb_lst->last_idx==0))
273 273
 		return ret;
274 274
 	for (r=0; r<cb_lst->last_idx; r++){
275
-		ret=cb_lst->hooks[r].on_blst_add(si, flags);
275
+		ret=cb_lst->hooks[r].on_blst_action(si, flags, msg);
276 276
 		if (ret!=DST_BLACKLIST_CONTINUE) break;
277 277
 	}
278 278
 	return ret;
... ...
@@ -674,12 +674,12 @@ inline static int dst_is_blacklisted_ip(unsigned char proto,
674 674
 
675 675
 
676 676
 
677
-int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si)
677
+int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si, struct sip_msg* msg)
678 678
 {
679 679
 	struct ip_addr ip;
680 680
 
681 681
 #ifdef DST_BLACKLIST_HOOKS
682
-	if (unlikely (blacklist_run_hooks(&blst_add_cb, si, &err_flags) ==
682
+	if (unlikely (blacklist_run_hooks(&blst_add_cb, si, &err_flags, msg) ==
683 683
 					DST_BLACKLIST_DENY))
684 684
 		return 0;
685 685
 #endif
... ...
@@ -690,7 +690,7 @@ int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si)
690 690
 
691 691
 
692 692
 
693
-int dst_is_blacklisted(struct dest_info* si)
693
+int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg)
694 694
 {
695 695
 	struct ip_addr ip;
696 696
 #ifdef DST_BLACKLIST_HOOKS
... ...
@@ -701,7 +701,7 @@ int dst_is_blacklisted(struct dest_info* si)
701 701
 
702 702
 #ifdef DST_BLACKLIST_HOOKS
703 703
 	err_flags=0;
704
-	if (unlikely((action=(blacklist_run_hooks(&blst_search_cb, si, &err_flags))
704
+	if (unlikely((action=(blacklist_run_hooks(&blst_search_cb, si, &err_flags, msg))
705 705
 					) != DST_BLACKLIST_CONTINUE)){
706 706
 		if (action==DST_BLACKLIST_DENY)
707 707
 			return 0;
... ...
@@ -35,6 +35,7 @@
35 35
 #define dst_black_list_h
36 36
 
37 37
 #include "ip_addr.h"
38
+#include "parser/msg_parser.h"
38 39
 
39 40
 /* flags: */
40 41
 #define BLST_IS_IPV6		1		/* set if the address is ipv6 */
... ...
@@ -58,7 +59,10 @@
58 58
 
59 59
 #ifdef DST_BLACKLIST_HOOKS
60 60
 struct blacklist_hook{
61
-	int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags);
61
+	/* WARNING: msg might be NULL, and it might point to shared memory
62
+	 * without locking, do not modify it! msg can be used typically for checking
63
+	 * the message flags with isflagset() */
64
+	int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags, struct sip_msg* msg);
62 65
 	/* called before ser shutdown */
63 66
 	void (*destroy)(void);
64 67
 };
... ...
@@ -69,9 +73,9 @@ int register_blacklist_hook(struct blacklist_hook *h, int type);
69 69
 int init_dst_blacklist();
70 70
 void destroy_dst_blacklist();
71 71
 
72
-int dst_blacklist_add(unsigned char err_flags, struct dest_info* si);
72
+int dst_blacklist_add(unsigned char err_flags, struct dest_info* si, struct sip_msg* msg);
73 73
 
74
-int dst_is_blacklisted(struct dest_info* si);
74
+int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
75 75
 
76 76
 /* deletes all the entries from the blacklist except the permanent ones
77 77
  * (which are marked with BLST_PERMANENT)
... ...
@@ -414,7 +414,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
414 414
 		}
415 415
 #ifdef USE_DST_BLACKLIST
416 416
 		if (use_dst_blacklist){
417
-			if (dst_is_blacklisted(send_info)){
417
+			if (dst_is_blacklisted(send_info, msg)){
418 418
 				su2ip_addr(&ip, &send_info->to);
419 419
 				LOG(L_DBG, "DEBUG: blacklisted destination:%s:%d (%d)\n",
420 420
 							ip_addr2a(&ip), su_getport(&send_info->to),
... ...
@@ -432,7 +432,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
432 432
 			ret=ser_error=E_SEND;
433 433
 #ifdef USE_DST_BLACKLIST
434 434
 			if (use_dst_blacklist)
435
-				dst_blacklist_add(BLST_ERR_SEND, send_info);
435
+				dst_blacklist_add(BLST_ERR_SEND, send_info, msg);
436 436
 #endif
437 437
 #ifdef USE_DNS_FAILOVER
438 438
 			continue; /* try another ip */
... ...
@@ -691,7 +691,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
691 691
 	}
692 692
 #ifdef USE_DST_BLACKLIST
693 693
 	if (use_dst_blacklist){
694
-		if (dst_is_blacklisted(&uac->request.dst)){
694
+		if (dst_is_blacklisted(&uac->request.dst, p_msg)){
695 695
 			su2ip_addr(&ip, &uac->request.dst.to);
696 696
 			DBG("t_send_branch: blacklisted destination: %s:%d (%d)\n",
697 697
 							ip_addr2a(&ip), su_getport(&uac->request.dst.to),
... ...
@@ -735,7 +735,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
735 735
 							uac->request.dst.proto);
736 736
 #ifdef USE_DST_BLACKLIST
737 737
 		if (use_dst_blacklist)
738
-			dst_blacklist_add(BLST_ERR_SEND, &uac->request.dst);
738
+			dst_blacklist_add(BLST_ERR_SEND, &uac->request.dst, p_msg);
739 739
 #endif
740 740
 #ifdef USE_DNS_FAILOVER
741 741
 		/* if the destination resolves to more ips, add another
... ...
@@ -456,7 +456,8 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
456 456
 		/* no reply received */
457 457
 #ifdef USE_DST_BLACKLIST
458 458
 		if (use_dst_blacklist)
459
-			dst_blacklist_add( BLST_ERR_TIMEOUT, &r_buf->dst);
459
+			dst_blacklist_add( BLST_ERR_TIMEOUT, &r_buf->dst,
460
+				(r_buf->my_T)?r_buf->my_T->uas.request:NULL);
460 461
 #endif
461 462
 #ifdef USE_DNS_FAILOVER
462 463
 		/* if this is an invite, the destination resolves to more ips, and