DON'T FORGET TO TAKE THE DEMO CONTEXT OUT OF YOUR DEFAULT CONTEXT. There
isn't really a security reason, it just will keep people from wanting to
play with your Asterisk setup remotely.
+
+* LOG SECURITY
+
+Please note that the Asterisk log files, as well as information printed to the
+Asterisk CLI, may contain sensitive information such as passwords and call
+history. Keep this in mind when providing access to these resources.
char *tokb=NULL, *p=NULL;
int channel=0, port=0;
struct misdn_bchannel *newbc = NULL;
+ int dec=0;
struct chan_list *cl=init_chan_list(ORG_AST);
else {
port = atoi(port_str);
}
-
-
} else {
ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITHOUT PORT/Group, check extension.conf\n",ext);
return NULL;
}
+ if (misdn_cfg_is_group_method(group, METHOD_STANDARD_DEC)) {
+ chan_misdn_log(0, port, " --> STARTING STANDARDDEC...\n");
+ dec=1;
+ }
+
if (!ast_strlen_zero(group)) {
char cfg_group[BUFFERSIZE+1];
struct robin_list *rr = NULL;
if (misdn_cfg_is_group_method(group, METHOD_ROUND_ROBIN)) {
- chan_misdn_log(4, port, " --> STARTING ROUND ROBIN...");
+ chan_misdn_log(4, port, " --> STARTING ROUND ROBIN...\n");
rr = get_robin_position(group);
}
+
if (rr) {
int robin_channel = rr->channel;
int port_start;
if ( port_up>0 ) {
- newbc = misdn_lib_get_free_bc(port, robin_channel,0);
+ newbc = misdn_lib_get_free_bc(port, robin_channel,0, 0);
if (newbc) {
chan_misdn_log(4, port, " Success! Found port:%d channel:%d\n", newbc->port, newbc->channel);
if (port_up)
if (!newbc)
chan_misdn_log(-1, port, " Failed! No free channel in group %d!", group);
- }
-
- else {
+ } else {
for (port=misdn_cfg_get_next_port(0); port > 0;
port=misdn_cfg_get_next_port(port)) {
chan_misdn_log(4, port, "portup:%d\n", port_up);
if ( port_up>0 ) {
- newbc = misdn_lib_get_free_bc(port, 0, 0);
+ newbc = misdn_lib_get_free_bc(port, 0, 0, dec);
if (newbc)
break;
}
}
}
}
-
} else {
if (channel)
chan_misdn_log(1, port," --> preselected_channel: %d\n",channel);
- newbc = misdn_lib_get_free_bc(port, channel, 0);
+ newbc = misdn_lib_get_free_bc(port, channel, 0, dec);
}
if (!newbc) {
case 'c':
keyidx=atoi(++tok);
- if (keyidx > misdn_key_vector_size || keyidx < 0 ) {
- ast_log(LOG_WARNING, "You entered the keyidx: %d but we have only %d keys\n",keyidx, misdn_key_vector_size );
- continue;
+ char keys[4096];
+ char *key=NULL, *tmp;
+ int i;
+ misdn_cfg_get( 0, MISDN_GEN_CRYPT_KEYS, keys, sizeof(keys));
+
+ tmp=keys;
+
+ for (i=0; i<keyidx; i++) {
+ key=strsep(&tmp,",");
}
-
- {
- ast_copy_string(ch->bc->crypt_key, misdn_key_vector[keyidx], sizeof(ch->bc->crypt_key));
+
+ if (key) {
+ ast_copy_string(ch->bc->crypt_key, key, sizeof(ch->bc->crypt_key));
}
- chan_misdn_log(0, ch->bc->port, "SETOPT: crypt with key:%s\n",misdn_key_vector[keyidx]);
+ chan_misdn_log(0, ch->bc->port, "SETOPT: crypt with key:%s\n",ch->bc->crypt_key);
break;
case 'e':
/* Fromdomain is what we are registering to, regardless of actual
host name from SRV */
- if (!ast_strlen_zero(p->fromdomain))
- snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
- else
- snprintf(addr, sizeof(addr), "sip:%s", r->hostname);
+ if (!ast_strlen_zero(p->fromdomain)) {
+ if (r->portno && r->portno != DEFAULT_SIP_PORT)
+ snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);
+ else
+ snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+ } else {
+ if (r->portno && r->portno != DEFAULT_SIP_PORT)
+ snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno);
+ else
+ snprintf(addr, sizeof(addr), "sip:%s", r->hostname);
+ }
ast_copy_string(p->uri, addr, sizeof(p->uri));
p->branch ^= thread_safe_rand();
enum misdn_cfg_method {
METHOD_STANDARD = 0,
- METHOD_ROUND_ROBIN
+ METHOD_ROUND_ROBIN,
+ METHOD_STANDARD_DEC
};
/* you must call misdn_cfg_init before any other function of this header file */
-static int find_free_chan_in_stack(struct misdn_stack *stack, int channel)
+static int find_free_chan_in_stack(struct misdn_stack *stack, int channel, int dec)
{
int i;
}
channel--;
-
- for (i = 0; i < stack->b_num; i++) {
- if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
- if (!stack->channels[i]) {
- cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
- return i+1;
+
+ if (dec) {
+ for (i = stack->b_num-1; i >=0; i--) {
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (!stack->channels[i]) {
+ cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
+ return i+1;
+ }
+ }
+ }
+ } else {
+ for (i = 0; i < stack->b_num; i++) {
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (!stack->channels[i]) {
+ cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
+ return i+1;
+ }
}
}
}
bc->in_use= 0;
bc->cw= 0;
+ bc->dec=0;
bc->channel = 0;
bc->sending_complete = 0;
if (!stack->channels[channel-1])
stack->channels[channel-1] = 1;
else {
- cb_log(0,stack->port,"channel already in use:%d\n", channel );
+ cb_log(4,stack->port,"channel already in use:%d\n", channel );
return -1;
}
} else {
int free_chan;
if (stack->nt) {
- free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
+ free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0, 0);
if (!free_chan) return -1;
bc->channel=free_chan;
} else {
if (stack->ptp || bc->te_choose_channel) {
/* we know exactly which channels are in use */
- free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
+ free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0, bc->dec);
if (!free_chan) return -1;
bc->channel=free_chan;
cb_log(2,stack->port, " --> found channel: %d\n",free_chan);
case EVENT_SETUP:
{
if (bc->channel == 0xff) {
- bc->channel=find_free_chan_in_stack(stack, 0);
+ bc->channel=find_free_chan_in_stack(stack, 0, 0);
if (!bc->channel) {
cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
bc->out_cause=34;
case CC_NEW_CR|INDICATION:
cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
- struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
+ struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
if (!bc) {
cb_log(0, stack->port, " --> !! lib: No free channel!\n");
return -1;
case CC_SETUP|INDICATION:
{
- struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
+ struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
if (!bc)
ERR_NO_CHANNEL:
{
switch (event) {
case EVENT_SETUP:
if (bc->channel<=0 || bc->channel==0xff) {
- bc->channel=find_free_chan_in_stack(stack,0);
+ bc->channel=find_free_chan_in_stack(stack,0,0);
if (bc->channel<=0)
goto ERR_NO_CHANNEL;
#endif
}
-struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout)
+struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
{
struct misdn_stack *stack;
int i;
}
int maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num;
- for (i = 0; i <maxnum; i++) {
- if (!stack->bc[i].in_use) {
- /* 3. channel on bri means CW*/
- if (!stack->pri && i==stack->b_num)
- stack->bc[i].cw=1;
-
- prepare_bc(&stack->bc[i], channel);
- return &stack->bc[i];
+
+ if (dec) {
+ for (i = maxnum-1; i>=0; i--) {
+ if (!stack->bc[i].in_use) {
+ /* 3. channel on bri means CW*/
+ if (!stack->pri && i==stack->b_num)
+ stack->bc[i].cw=1;
+
+ prepare_bc(&stack->bc[i], channel);
+ stack->bc[i].dec=1;
+ return &stack->bc[i];
+ }
+ }
+ } else {
+ for (i = 0; i <maxnum; i++) {
+ if (!stack->bc[i].in_use) {
+ /* 3. channel on bri means CW*/
+ if (!stack->pri && i==stack->b_num)
+ stack->bc[i].cw=1;
+
+ prepare_bc(&stack->bc[i], channel);
+ return &stack->bc[i];
+ }
}
}
if (stack->nt) {
if (bc->channel <=0 ) { /* else we have the channel already */
- bc->channel = find_free_chan_in_stack(stack, 0);
+ bc->channel = find_free_chan_in_stack(stack, 0, 0);
if (!bc->channel) {
cb_log(0, stack->port, " No free channel at the moment\n");
/*FIXME: add disconnect*/
int need_release;
int need_release_complete;
+ int dec;
/** var stuff**/
int l3_id;
int pid;
void misdn_lib_transfer(struct misdn_bchannel* holded_bc);
-struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout);
+struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout, int dec);
void manager_bchannel_activate(struct misdn_bchannel *bc);
void manager_bchannel_deactivate(struct misdn_bchannel * bc);
int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth)
{
int i, re = 0;
- char *method = NULL;
+ char *method ;
misdn_cfg_lock();
+
+ method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
+
for (i = 1; i <= max_ports; i++) {
if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
}
}
+
if (method) {
switch (meth) {
case METHOD_STANDARD: re = !strcasecmp(method, "standard");
break;
case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin");
break;
+ case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec");
+ break;
}
}
misdn_cfg_unlock();
#include "asterisk/inline_api.h"
-#if defined (__i386__)
+#if defined (__i386__) && !defined(__APPLE__)
AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
{
__asm __volatile (