Skip to content

Commit

Permalink
fixed flags max_list bug for ds_select_*
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutrazvanionita committed Nov 4, 2014
1 parent 0b61cba commit 5ade2ad
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 236 deletions.
35 changes: 19 additions & 16 deletions modules/dispatcher/README
Expand Up @@ -69,8 +69,8 @@ Carsten Bock

1.4. Exported Functions

1.4.1. ds_select_dst(set, alg [, "[flags] [M
max_results]"])
1.4.1. ds_select_dst(set, alg [, (flags M
max_results)*])

1.4.2. ds_select_domain(set, alg [, "[flags] [M
max_results]"])
Expand Down Expand Up @@ -575,7 +575,7 @@ modparam("dispatcher", "socket_col", "my_sock")

1.4. Exported Functions

1.4.1. ds_select_dst(set, alg [, "[flags] [M max_results]"])
1.4.1. ds_select_dst(set, alg [, (flags M max_results)*])

The method selects a destination from the given set of
addresses. It will overwrite the "destination URI" of a SIP
Expand Down Expand Up @@ -606,22 +606,25 @@ modparam("dispatcher", "socket_col", "my_sock")
chosen.
+ “X” - if the algorithm is not implemented, the first
entry in set is chosen.
* flags - If specified, this will be the flags which in
previous versions were specified at startup. The flags are
the failover support flag('f'/'F') letters, the user only
flag('u'/'U') and will specify that only the uri user part
will be used for hashing, the force destination
* flags M max_results - If specified, this will be the flags
which in previous versions were specified at startup. The
flags are the failover support flag('f'/'F') letters, the
user only flag('u'/'U') and will specify that only the uri
user part will be used for hashing, the force destination
flag('S'/'s') which will Skip overwriting the destination
address if it is already set and the use default flag('D',
'd') which will use the last address in destination set as
last option to send the message.You can also specify these
flags using PVs. The flags are being kept per partition.
* max_results - If specified, only that many results will be
put into the specified avp for failover. This allows having
many destinations but limit the useless traffic in case of
a number that is bound to fail everywhere. It can accept
variables. The definition must begin with 'M' character
either you use static definition or PVs.
The second paramater, max_results represents that only a
maximum of max_results will be put into the specified avp
for failover. This allows having many destinations but
limit the useless traffic in case of a number that is bound
to fail everywhere. Since version 1.12, the last paramater
cand be represented by a list of flags and max_results,
separated by comma. If the 'M' character is not specified,
there will be no search for the flags, but you cand specify
the max_results paramater (flags will be 0).

If the character 'f' in 'flags' is set, the rest of the
addresses from the destination set is stored in AVP list. You
Expand All @@ -639,9 +642,9 @@ ds_select_dst("1", "0");
...
ds_select_dst("part2 : 1", "0", "M 5");
...
ds_select_dst("part3 : 1", "0", "fUsD");
ds_select_dst("part3 : 1", "0", "fUsD M");
...
ds_select_dst("part4 : 2", "0", "fuD M 5,2");
ds_select_dst("part4 : 2,3", "0,1", "fuD M 5, fuS M 2");
...
# dispatch over multiple dispatching groups
$var(partition_name) = "p4"
Expand Down
29 changes: 23 additions & 6 deletions modules/dispatcher/dispatch.c
Expand Up @@ -1229,8 +1229,7 @@ static inline int ds_get_index(int group, ds_set_p *index, ds_partition_t *parti
}


static inline int ds_update_dst(struct sip_msg *msg, str *uri,
struct socket_info *sock, int mode)
int ds_update_dst(struct sip_msg *msg, str *uri, struct socket_info *sock, int mode)
{
struct action act;
uri_type utype;
Expand Down Expand Up @@ -1288,10 +1287,10 @@ static int count_inactive_destinations(ds_set_p idx, int ds_use_default) {

static inline int push_ds_2_avps( ds_dest_t *ds, ds_partition_t *partition )
{
char buf[2+16+1]; /* a hexa string */
char buf[PTR_STRING_SIZE]; /* a hexa string */
int_str avp_val;

avp_val.s.len = 1 + sprintf( buf, "%p", ds->sock );
avp_val.s.len = 1 + snprintf( buf, PTR_STR_SIZE, "%p", ds->sock );
avp_val.s.s = buf;
if(add_avp(AVP_VAL_STR| partition->sock_avp_type,
partition->sock_avp_name, avp_val)!=0) {
Expand Down Expand Up @@ -1321,7 +1320,7 @@ static inline int push_ds_2_avps( ds_dest_t *ds, ds_partition_t *partition )
/**
*
*/
int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, int ds_flags)
int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, ds_selected_dst_p selected_dst, int ds_flags)
{
int i, cnt, i_unwrapped;
unsigned int ds_hash;
Expand Down Expand Up @@ -1464,6 +1463,7 @@ int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, int ds_fla
break;
}
}

LM_DBG("alg hash [%u], id [%u]\n", ds_hash, ds_id);
cnt = 0;

Expand Down Expand Up @@ -1502,6 +1502,23 @@ int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, int ds_fla
LM_ERR("cannot set dst addr\n");
goto error;
}

/* Save the selected destination for multilist failover */
if (selected_dst->uri.s != NULL) {
pkg_free(selected_dst->uri.s);
memset(&selected_dst->uri, 0, sizeof(str));
}
if (pkg_str_dup(&selected_dst->uri, &selected->dst_uri) != 0) {
LM_ERR("cannot set selected_dst uri\n");
goto error;
}
if (selected->sock) {
selected_dst->socket.len = 1 + snprintf( selected_dst->socket.s, PTR_STR_SIZE, "%p", selected->sock );
}
else {
selected_dst->socket.len = 0;
}

/* if alg is round-robin then update the shortcut to next to be used */
if(ds_select_ctl->alg==4)
idx->last = (ds_id+1) % idx->nr;
Expand Down Expand Up @@ -1636,12 +1653,12 @@ int ds_next_dst(struct sip_msg *msg, int mode, ds_partition_t *partition)
destroy_avp(tmp_avp);
}

LM_DBG("using [%.*s]\n", avp_value.s.len, avp_value.s.s);
if(ds_update_dst(msg, &avp_value.s, sock, mode)!=0)
{
LM_ERR("cannot set dst addr\n");
return -1;
}
LM_DBG("using [%.*s]\n", avp_value.s.len, avp_value.s.s);

return 1;
}
Expand Down
12 changes: 10 additions & 2 deletions modules/dispatcher/dispatch.h
Expand Up @@ -50,7 +50,7 @@
#define DS_HASH_USER_ONLY 1 /* use only the uri user part for hashing */
#define DS_FAILOVER_ON 2 /* store the other dest in avps */
#define DS_USE_DEFAULT 4 /* use last address in destination set as last option */
#define DS_FORCE_DST 8 /* if not set it will force overwriting the destination address
#define DS_FORCE_DST 8 /* if not set it will force overwriting the destination address
if already set */

#define DS_INACTIVE_DST 1 /* inactive destination */
Expand Down Expand Up @@ -150,6 +150,7 @@ typedef struct _ds_select_ctl
int max_results; /* max destinaitons to process */
int reset_AVP; /* reset AVPs flag */
int set_destination; /* set destination flag */
int ds_flags;
} ds_select_ctl_t, *ds_select_ctl_p;

typedef struct
Expand All @@ -158,6 +159,12 @@ typedef struct
int set_id;
} ds_options_callback_param_t;

typedef struct _ds_selected_dst
{
str uri;
str socket;
} ds_selected_dst, *ds_selected_dst_p;

extern str ds_set_id_col;
extern str ds_dest_uri_col;
extern str ds_dest_sock_col;
Expand Down Expand Up @@ -188,7 +195,8 @@ int ds_reload_db(ds_partition_t *partition);
int init_ds_data(ds_partition_t *partition);
void ds_destroy_data(ds_partition_t *partition);

int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, int ds_flags);
int ds_update_dst(struct sip_msg *msg, str *uri, struct socket_info *sock, int mode);
int ds_select_dst(struct sip_msg *msg, ds_select_ctl_p ds_select_ctl, ds_selected_dst_p selected_dst, int ds_flags);
int ds_next_dst(struct sip_msg *msg, int mode, ds_partition_t *partition);
int ds_set_state(int group, str *address, int state, int type,
ds_partition_t *partition);
Expand Down

0 comments on commit 5ade2ad

Please sign in to comment.