dst blacklist callbacks are extended with the sip msg parameter.
authorMiklos Tirpak <miklos@iptel.org>
Thu, 26 Jul 2007 11:52:22 +0000 (11:52 +0000)
committerMiklos Tirpak <miklos@iptel.org>
Thu, 26 Jul 2007 11:52:22 +0000 (11:52 +0000)
WARNING: the sip msg might be in shared memory without locking,
do not modify it!

dst_blacklist.c
dst_blacklist.h
forward.c
modules/tm/t_fwd.c
modules/tm/timer.c

index b48df8a..fab4376 100644 (file)
@@ -133,8 +133,8 @@ struct dst_blst_lst_head* dst_blst_hash=0;
 
 /* there 2 types of callbacks supported: on add new entry to the blacklist
  *  (DST_BLACKLIST_ADD_CB) and on blacklist search (DST_BLACKLIST_SEARCH_CB).
- *  Both of them take a struct dest_info* and a flags pointer as parameters 
- *   (unsigned char*). The flags can be changed.
+ *  Both of them take a struct dest_info*, a flags pointer(unsigned char*),
+ *  and a struct sip_msg* as parameters. The flags can be changed.
  *  A callback should return one of:
  *    DST_BLACKLIST_CONTINUE - do nothing, let other callbacks run
  *    DST_BLACKLIST_ACCEPT   - for blacklist add: force accept immediately,
@@ -262,7 +262,7 @@ error:
 
 
 inline static int blacklist_run_hooks(struct blst_callbacks_lst *cb_lst,
-                                                       struct dest_info* si, unsigned char* flags)
+                                                       struct dest_info* si, unsigned char* flags, struct sip_msg* msg)
 {
        int r;
        int ret;
@@ -272,7 +272,7 @@ inline static int blacklist_run_hooks(struct blst_callbacks_lst *cb_lst,
        if (likely(cb_lst->last_idx==0))
                return ret;
        for (r=0; r<cb_lst->last_idx; r++){
-               ret=cb_lst->hooks[r].on_blst_add(si, flags);
+               ret=cb_lst->hooks[r].on_blst_action(si, flags, msg);
                if (ret!=DST_BLACKLIST_CONTINUE) break;
        }
        return ret;
@@ -674,12 +674,12 @@ inline static int dst_is_blacklisted_ip(unsigned char proto,
 
 
 
-int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si)
+int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si, struct sip_msg* msg)
 {
        struct ip_addr ip;
 
 #ifdef DST_BLACKLIST_HOOKS
-       if (unlikely (blacklist_run_hooks(&blst_add_cb, si, &err_flags) ==
+       if (unlikely (blacklist_run_hooks(&blst_add_cb, si, &err_flags, msg) ==
                                        DST_BLACKLIST_DENY))
                return 0;
 #endif
@@ -690,7 +690,7 @@ int dst_blacklist_add(unsigned char err_flags,  struct dest_info* si)
 
 
 
-int dst_is_blacklisted(struct dest_info* si)
+int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg)
 {
        struct ip_addr ip;
 #ifdef DST_BLACKLIST_HOOKS
@@ -701,7 +701,7 @@ int dst_is_blacklisted(struct dest_info* si)
 
 #ifdef DST_BLACKLIST_HOOKS
        err_flags=0;
-       if (unlikely((action=(blacklist_run_hooks(&blst_search_cb, si, &err_flags))
+       if (unlikely((action=(blacklist_run_hooks(&blst_search_cb, si, &err_flags, msg))
                                        ) != DST_BLACKLIST_CONTINUE)){
                if (action==DST_BLACKLIST_DENY)
                        return 0;
index 5f12297..59d7688 100644 (file)
@@ -35,6 +35,7 @@
 #define dst_black_list_h
 
 #include "ip_addr.h"
+#include "parser/msg_parser.h"
 
 /* flags: */
 #define BLST_IS_IPV6           1               /* set if the address is ipv6 */
 
 #ifdef DST_BLACKLIST_HOOKS
 struct blacklist_hook{
-       int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags);
+       /* WARNING: msg might be NULL, and it might point to shared memory
+        * without locking, do not modify it! msg can be used typically for checking
+        * the message flags with isflagset() */
+       int (*on_blst_action)(struct dest_info* si, unsigned char* err_flags, struct sip_msg* msg);
        /* called before ser shutdown */
        void (*destroy)(void);
 };
@@ -69,9 +73,9 @@ int register_blacklist_hook(struct blacklist_hook *h, int type);
 int init_dst_blacklist();
 void destroy_dst_blacklist();
 
-int dst_blacklist_add(unsigned char err_flags, struct dest_info* si);
+int dst_blacklist_add(unsigned char err_flags, struct dest_info* si, struct sip_msg* msg);
 
-int dst_is_blacklisted(struct dest_info* si);
+int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
 
 /* deletes all the entries from the blacklist except the permanent ones
  * (which are marked with BLST_PERMANENT)
index 0df5324..8112503 100644 (file)
--- a/forward.c
+++ b/forward.c
@@ -414,7 +414,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
                }
 #ifdef USE_DST_BLACKLIST
                if (use_dst_blacklist){
-                       if (dst_is_blacklisted(send_info)){
+                       if (dst_is_blacklisted(send_info, msg)){
                                su2ip_addr(&ip, &send_info->to);
                                LOG(L_DBG, "DEBUG: blacklisted destination:%s:%d (%d)\n",
                                                        ip_addr2a(&ip), su_getport(&send_info->to),
@@ -432,7 +432,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
                        ret=ser_error=E_SEND;
 #ifdef USE_DST_BLACKLIST
                        if (use_dst_blacklist)
-                               dst_blacklist_add(BLST_ERR_SEND, send_info);
+                               dst_blacklist_add(BLST_ERR_SEND, send_info, msg);
 #endif
 #ifdef USE_DNS_FAILOVER
                        continue; /* try another ip */
index e0f8209..22db447 100644 (file)
@@ -691,7 +691,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
        }
 #ifdef USE_DST_BLACKLIST
        if (use_dst_blacklist){
-               if (dst_is_blacklisted(&uac->request.dst)){
+               if (dst_is_blacklisted(&uac->request.dst, p_msg)){
                        su2ip_addr(&ip, &uac->request.dst.to);
                        DBG("t_send_branch: blacklisted destination: %s:%d (%d)\n",
                                                        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 ,
                                                        uac->request.dst.proto);
 #ifdef USE_DST_BLACKLIST
                if (use_dst_blacklist)
-                       dst_blacklist_add(BLST_ERR_SEND, &uac->request.dst);
+                       dst_blacklist_add(BLST_ERR_SEND, &uac->request.dst, p_msg);
 #endif
 #ifdef USE_DNS_FAILOVER
                /* if the destination resolves to more ips, add another
index 1d24023..e782df0 100644 (file)
@@ -456,7 +456,8 @@ inline static void final_response_handler(  struct retr_buf* r_buf,
                /* no reply received */
 #ifdef USE_DST_BLACKLIST
                if (use_dst_blacklist)
-                       dst_blacklist_add( BLST_ERR_TIMEOUT, &r_buf->dst);
+                       dst_blacklist_add( BLST_ERR_TIMEOUT, &r_buf->dst,
+                               (r_buf->my_T)?r_buf->my_T->uas.request:NULL);
 #endif
 #ifdef USE_DNS_FAILOVER
                /* if this is an invite, the destination resolves to more ips, and