Browse code

blst: another blacklist dest. function version

- added dst_blacklist_su(), which is a variant of dst_blacklist_add()
(different way of passing the blacklist target)

Andrei Pelinescu-Onciul authored on 26/02/2009 23:09:22
Showing 2 changed files
... ...
@@ -34,6 +34,7 @@
34 34
  *  2007-07-30  added dst_blacklist_del() and dst_blacklist_add_to()  (andrei)
35 35
  *  2007-07-30  dst blacklist measurements added (Gergo)
36 36
  *  2008-02-11  dns_blacklist_init cfg parameter is introduced (Miklos)
37
+ *  2009-02-26  added dst_blacklist_su* variant (andrei)
37 38
  */
38 39
 
39 40
 
... ...
@@ -785,6 +786,14 @@ inline static int dst_is_blacklisted_ip(unsigned char proto,
785 785
 
786 786
 
787 787
 
788
+/** add dst to the blacklist, specifying the timeout.
789
+ * @param err_flags - reason (bitmap)
790
+ * @param si - destination (protocol, ip and port)
791
+ * @param msg - sip message that triggered the blacklisting (can be 0 if 
792
+ *               not known)
793
+ * @param timeout - timeout in ticks
794
+ * @return 0 on success, -1 on error
795
+ */
788 796
 int dst_blacklist_add_to(unsigned char err_flags,  struct dest_info* si,
789 797
 						struct sip_msg* msg, ticks_t timeout)
790 798
 {
... ...
@@ -802,6 +811,32 @@ int dst_blacklist_add_to(unsigned char err_flags,  struct dest_info* si,
802 802
 
803 803
 
804 804
 
805
+/** add dst to the blacklist, specifying the timeout.
806
+ * (like @function dst_blacklist_add_to)= above, but uses 
807
+ * (proto, sockaddr_union) instead of struct dest_info)
808
+ */
809
+int dst_blacklist_su_to(unsigned char err_flags, unsigned char proto,
810
+							union sockaddr_union* dst,
811
+							struct sip_msg* msg, ticks_t timeout)
812
+{
813
+	struct ip_addr ip;
814
+#ifdef DST_BLACKLIST_HOOKS
815
+	struct dest_info si;
816
+	
817
+	init_dest_info(&si);
818
+	si.to=*dst;
819
+	si.proto=proto;
820
+	if (unlikely (blacklist_run_hooks(&blst_add_cb, &si, &err_flags, msg) ==
821
+					DST_BLACKLIST_DENY))
822
+		return 0;
823
+#endif
824
+	su2ip_addr(&ip, dst);
825
+	return dst_blacklist_add_ip(err_flags, proto, &ip,
826
+								su_getport(dst), timeout);
827
+}
828
+
829
+
830
+
805 831
 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg)
806 832
 {
807 833
 	int ires;
... ...
@@ -88,12 +88,25 @@ void destroy_dst_blacklist();
88 88
 /* like dst_blacklist_add, but the timeout can be also set */
89 89
 int dst_blacklist_add_to(unsigned char err_flags, struct dest_info* si,
90 90
 						struct sip_msg* msg, ticks_t timeout);
91
+/* like above, but using a differnt way of passing the target */
92
+int dst_blacklist_su_to(unsigned char err_flags, unsigned char proto,
93
+							union sockaddr_union* dst,
94
+							struct sip_msg* msg, ticks_t timeout);
91 95
 
92
-/* adds a dst to the blacklist with default timeout */
96
+/** adds a dst to the blacklist with default timeout.
97
+ * @see dst_blacklist_add_to for more details.
98
+ */
93 99
 #define dst_blacklist_add(err_flags, si, msg) \
94 100
 	dst_blacklist_add_to((err_flags), (si), (msg), \
95 101
 		S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
96 102
 
103
+/** adds a dst to the blacklist with default timeout.
104
+ * @see dst_blacklist_su_to for more details.
105
+ */
106
+#define dst_blacklist_su(err_flags, proto, dst, msg) \
107
+	dst_blacklist_su_to((err_flags), (proto), (dst), (msg), \
108
+		S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
109
+
97 110
 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
98 111
 /* delete an entry from the blacklist */
99 112
 int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);