Module: sip-router
Branch: sr_3.0
Commit: a375b567c86cf1e066e7a56cce4697674aa9d1b3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a375b56…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Thu Oct 29 10:27:54 2009 +0200
modules/lcr: bug fixes
- Fixed selection of gateways's attributes when same gateway has different
attributes in different groups.
- Fixed printing of gateway's tag by lcr.dump_gws.
---
modules/lcr/lcr_mod.c | 33 ++++++++++++++++++++-------------
modules/lcr/lcr_rpc.c | 6 +++---
2 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c
index 549e570..2b6c719 100644
--- a/modules/lcr/lcr_mod.c
+++ b/modules/lcr/lcr_mod.c
@@ -151,7 +151,7 @@ struct matched_gw_info {
unsigned short prefix_len;
unsigned short priority;
unsigned int weight;
- unsigned int defunct_until;
+ unsigned short duplicate;
};
/*
@@ -1412,7 +1412,7 @@ int mi_print_gws(struct mi_node* rpl)
attr = add_mi_attr(node, MI_DUP_VALUE, "TAG", 3,
gws[i].tag, gws[i].tag_len);
if (attr == NULL) goto err;
-
+
p = int2str((unsigned long)gws[i].weight, &len);
attr = add_mi_attr(node, MI_DUP_VALUE, "WEIGHT", 6, p, len);
if (attr == NULL) goto err;
@@ -1658,6 +1658,7 @@ void add_gws_into_avps(struct gw_info *gws, struct matched_gw_info
*matched_gws,
delete_avp(gw_uri_avp_type|AVP_VAL_STR, gw_uri_avp);
for (i = 0; i < gw_cnt; i++) {
+ if (matched_gws[i].duplicate == 1) continue;
index = matched_gws[i].gw_index;
hostname_len = gws[index].hostname_len;
strip = gws[index].strip;
@@ -1684,7 +1685,7 @@ void add_gws_into_avps(struct gw_info *gws, struct matched_gw_info
*matched_gws,
add_avp(gw_uri_avp_type|AVP_VAL_STR, gw_uri_avp, val);
LM_DBG("added gw_uri_avp <%.*s> with weight <%u>\n",
- value.len, value.s, matched_gws[i].weight);
+ value.len, value.s, matched_gws[i].weight);
skip:
continue;
}
@@ -1697,8 +1698,8 @@ void add_gws_into_avps(struct gw_info *gws, struct matched_gw_info
*matched_gws,
static int load_gws(struct sip_msg* _m, char *_lcr_id, char *_from_uri)
{
str ruri_user, from_uri;
- unsigned int j, k, gw_index, gw_count, now;
- int lcr_id;
+ int i, j, lcr_id;
+ unsigned int gw_index, gw_count, now, ip_addr;
int_str val;
struct matched_gw_info matched_gws[MAX_NO_OF_GWS + 1];
struct lcr_info **lcrs, *lcr_rec, *pl;
@@ -1770,18 +1771,12 @@ static int load_gws(struct sip_msg* _m, char *_lcr_id, char
*_from_uri)
while (j) {
/* If this gw is defunct, skip it */
if (gws[j].defunct_until > now) goto gw_found;
- for (k = 0; k < gw_index; k++) {
- if (gws[j].ip_addr ==
- gws[matched_gws[k].gw_index].ip_addr)
- /* Skip already existing gw */
- goto gw_found;
- }
- /* This is a new gw */
matched_gws[gw_index].gw_index = j;
matched_gws[gw_index].prefix_len = pl->prefix_len;
matched_gws[gw_index].priority = lcr_rec->priority;
matched_gws[gw_index].weight = gws[j].weight *
(rand() >> 8);
+ matched_gws[gw_index].duplicate = 0;
LM_DBG("added matched_gws[%d]=[%u, %u, %u, %u]\n",
gw_index, j, pl->prefix_len, lcr_rec->priority,
matched_gws[gw_index].weight);
@@ -1796,9 +1791,21 @@ static int load_gws(struct sip_msg* _m, char *_lcr_id, char
*_from_uri)
pl = pl->next;
}
- /* Sort gateways based on prefix_len, priority, and randomized weight */
+ /* Sort gateways in reverse order based on prefix_len, priority,
+ and randomized weight */
qsort(matched_gws, gw_index, sizeof(struct matched_gw_info), comp_matched);
+ /* Remove duplicate gws */
+ for (i = gw_index - 1; i >= 0; i--) {
+ if (matched_gws[i].duplicate == 1) continue;
+ ip_addr = gws[matched_gws[i].gw_index].ip_addr;
+ for (j = i - 1; j >= 0; j--) {
+ if (gws[matched_gws[j].gw_index].ip_addr == ip_addr) {
+ matched_gws[j].duplicate = 1;
+ }
+ }
+ }
+
/* Add gateways into gw_uris_avp */
add_gws_into_avps(gws, matched_gws, gw_index, &ruri_user);
diff --git a/modules/lcr/lcr_rpc.c b/modules/lcr/lcr_rpc.c
index d9f5e72..51ffd75 100644
--- a/modules/lcr/lcr_rpc.c
+++ b/modules/lcr/lcr_rpc.c
@@ -74,7 +74,7 @@ static void dump_gws(rpc_t* rpc, void* c)
if (rpc->add(c, "{", &st) < 0) return;
rpc->struct_add(st, "d", "lcr_id", j);
rpc->struct_add(st, "d", "grp_id", gws[i].grp_id);
- rpc->struct_printf(st, "ip_addr", "%d.%d.%d.%d",
+ rpc->struct_printf(st, "ip_addr", "%d.%d.%d.%d",
(gws[i].ip_addr << 24) >> 24,
((gws[i].ip_addr >> 8) << 24) >> 24,
((gws[i].ip_addr >> 16) << 24) >> 24,
@@ -110,9 +110,9 @@ static void dump_gws(rpc_t* rpc, void* c)
tag.len=gws[i].tag_len;
rpc->struct_add(st, "dSddd",
"strip", gws[i].strip,
- "tag", gws[i].tag, /* FIXME */
+ "tag", &tag,
"weight", gws[i].weight,
- "flags", &tag,
+ "flags", gws[i].flags,
"defunct_until", &gws[i].defunct_until
);
}