Forráskód Böngészése

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 16 éve
szülő
commit
6d91574de7
2 módosított fájl, 49 hozzáadás és 1 törlés
  1. 35 0
      dst_blacklist.c
  2. 14 1
      dst_blacklist.h

+ 35 - 0
dst_blacklist.c

@@ -34,6 +34,7 @@
  *  2007-07-30  added dst_blacklist_del() and dst_blacklist_add_to()  (andrei)
  *  2007-07-30  dst blacklist measurements added (Gergo)
  *  2008-02-11  dns_blacklist_init cfg parameter is introduced (Miklos)
+ *  2009-02-26  added dst_blacklist_su* variant (andrei)
  */
 
 
@@ -785,6 +786,14 @@ inline static int dst_is_blacklisted_ip(unsigned char proto,
 
 
 
+/** add dst to the blacklist, specifying the timeout.
+ * @param err_flags - reason (bitmap)
+ * @param si - destination (protocol, ip and port)
+ * @param msg - sip message that triggered the blacklisting (can be 0 if 
+ *               not known)
+ * @param timeout - timeout in ticks
+ * @return 0 on success, -1 on error
+ */
 int dst_blacklist_add_to(unsigned char err_flags,  struct dest_info* si,
 						struct sip_msg* msg, ticks_t timeout)
 {
@@ -802,6 +811,32 @@ int dst_blacklist_add_to(unsigned char err_flags,  struct dest_info* si,
 
 
 
+/** add dst to the blacklist, specifying the timeout.
+ * (like @function dst_blacklist_add_to)= above, but uses 
+ * (proto, sockaddr_union) instead of struct dest_info)
+ */
+int dst_blacklist_su_to(unsigned char err_flags, unsigned char proto,
+							union sockaddr_union* dst,
+							struct sip_msg* msg, ticks_t timeout)
+{
+	struct ip_addr ip;
+#ifdef DST_BLACKLIST_HOOKS
+	struct dest_info si;
+	
+	init_dest_info(&si);
+	si.to=*dst;
+	si.proto=proto;
+	if (unlikely (blacklist_run_hooks(&blst_add_cb, &si, &err_flags, msg) ==
+					DST_BLACKLIST_DENY))
+		return 0;
+#endif
+	su2ip_addr(&ip, dst);
+	return dst_blacklist_add_ip(err_flags, proto, &ip,
+								su_getport(dst), timeout);
+}
+
+
+
 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg)
 {
 	int ires;

+ 14 - 1
dst_blacklist.h

@@ -88,12 +88,25 @@ void destroy_dst_blacklist();
 /* like dst_blacklist_add, but the timeout can be also set */
 int dst_blacklist_add_to(unsigned char err_flags, struct dest_info* si,
 						struct sip_msg* msg, ticks_t timeout);
+/* like above, but using a differnt way of passing the target */
+int dst_blacklist_su_to(unsigned char err_flags, unsigned char proto,
+							union sockaddr_union* dst,
+							struct sip_msg* msg, ticks_t timeout);
 
-/* adds a dst to the blacklist with default timeout */
+/** adds a dst to the blacklist with default timeout.
+ * @see dst_blacklist_add_to for more details.
+ */
 #define dst_blacklist_add(err_flags, si, msg) \
 	dst_blacklist_add_to((err_flags), (si), (msg), \
 		S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
 
+/** adds a dst to the blacklist with default timeout.
+ * @see dst_blacklist_su_to for more details.
+ */
+#define dst_blacklist_su(err_flags, proto, dst, msg) \
+	dst_blacklist_su_to((err_flags), (proto), (dst), (msg), \
+		S_TO_TICKS(cfg_get(core, core_cfg, blst_timeout)))
+
 int dst_is_blacklisted(struct dest_info* si, struct sip_msg* msg);
 /* delete an entry from the blacklist */
 int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);