From: Bogdan-Andrei Iancu <bogdan@opensips.org>
Date: Tue, 12 Jul 2016 00:11:50 +0300
Subject: [PATCH] Fix populating blacklists.
When creating the blacklists, use the port and protocol of the destination too, otherwise the rules may conflict or be too wide to be used (like 2 destinations with same IP but different ports).
(cherry picked from commit 7fa9cee5037af26fd1c63b70710f2bc03e6a31f4)
diff --git a/modules/load_balancer/lb_bl.c b/modules/load_balancer/lb_bl.c
index 97ba000..c02cd0c 100644
--- a/modules/load_balancer/lb_bl.c
+++ b/modules/load_balancer/lb_bl.c
@@ -190,8 +190,8 @@ int populate_lb_bls(struct lb_dst *dest_list)
add_rule_to_list( &lbbl_first, &lbbl_last,
group_net,
NULL/*body*/,
- 0/*port*/,
- PROTO_NONE/*proto*/,
+ dst->ports[j],
+ dst->protos[j],
0/*flags*/);
pkg_free(group_net);
}
diff --git a/modules/load_balancer/lb_data.c b/modules/load_balancer/lb_data.c
index 1cf1721..aeeee8e 100644
--- a/modules/load_balancer/lb_data.c
+++ b/modules/load_balancer/lb_data.c
@@ -303,6 +303,7 @@ int add_lb_dsturi( struct lb_data *data, int id, int group, char *uri,
}
hostent2ip_addr( &dst->ips[0], &proxy->host, proxy->addr_idx);
dst->ports[0] = proxy->port;
+ dst->protos[0] = proxy->proto;
dst->ips_cnt = 1;
LM_DBG("first dst ip addr [%s]:%d\n",
ip_addr2a(&dst->ips[0]), dst->ports[0]);
@@ -310,8 +311,10 @@ int add_lb_dsturi( struct lb_data *data, int id, int group, char *uri,
while (dst->ips_cnt<LB_MAX_IPS && (get_next_su( proxy, &sau, 0)==0) ) {
su2ip_addr( &dst->ips[dst->ips_cnt], &sau);
dst->ports[dst->ips_cnt] = proxy->port;
- LM_DBG("additional dst ip addr [%s]:%d\n",
- ip_addr2a(&dst->ips[dst->ips_cnt]), dst->ports[dst->ips_cnt]);
+ dst->protos[dst->ips_cnt] = proxy->proto;
+ LM_DBG("additional dst ip addr [%s]:%d, proto %d\n",
+ ip_addr2a(&dst->ips[dst->ips_cnt]),
+ dst->ports[dst->ips_cnt], dst->protos[dst->ips_cnt] );
/* one more IP found */
dst->ips_cnt++;
}
diff --git a/modules/load_balancer/lb_data.h b/modules/load_balancer/lb_data.h
index 33a4688..38c942a 100644
--- a/modules/load_balancer/lb_data.h
+++ b/modules/load_balancer/lb_data.h
@@ -73,6 +73,7 @@ struct lb_dst {
struct lb_resource_map *rmap;
struct ip_addr ips[LB_MAX_IPS]; /* IP-Address of the entry */
unsigned short int ports[LB_MAX_IPS]; /* Port of the request URI */
+ unsigned short int protos[LB_MAX_IPS]; /* Protocol of the request URI */
unsigned short ips_cnt;
struct lb_dst *next;
};