snprintf(callid, len, "@%s", inet_ntoa(ourip));
}
-static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin)
+static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useglobalnat)
{
struct sip_pvt *p;
p->rtp = ast_rtp_new(NULL, NULL);
p->branch = rand();
p->tag = rand();
- p->nat = globalnat;
/* Start with 101 instead of 1 */
p->ocseq = 101;
if (!p->rtp) {
return NULL;
}
ast_rtp_settos(p->rtp, tos);
+ if (useglobalnat && sin) {
+ /* Setup NAT structure according to global settings if we have an address */
+ p->nat = globalnat;
+ memcpy(&p->recv, sin, sizeof(p->recv));
+ ast_rtp_setnat(p->rtp, p->nat);
+ }
ast_pthread_mutex_init(&p->lock);
#if 0
ast_rtp_set_data(p->rtp, p);
p = p->next;
}
ast_pthread_mutex_unlock(&iflock);
- return sip_alloc(callid, sin);
+ return sip_alloc(callid, sin, 1);
}
static int sip_register(char *value, int lineno)
build_callid(r->callid, sizeof(r->callid), __ourip);
r->callid_valid=1;
}
- p=sip_alloc( r->callid, &r->addr );
+ p=sip_alloc( r->callid, &r->addr, 0);
p->outgoing = 1;
r->call=p;
p->registry=r;
#undef FORMAT2
}
+static char *complete_sipch(char *line, char *word, int pos, int state)
+{
+ int which=0;
+ struct sip_pvt *cur;
+ char *c = NULL;
+ ast_pthread_mutex_lock(&iflock);
+ cur = iflist;
+ while(cur) {
+ if (!strncasecmp(word, cur->callid, strlen(word))) {
+ if (++which > state) {
+ c = strdup(cur->callid);
+ break;
+ }
+ }
+ cur = cur->next;
+ }
+ ast_pthread_mutex_unlock(&iflock);
+ return c;
+}
+
+static int sip_show_channel(int fd, int argc, char *argv[])
+{
+ struct sip_pvt *cur;
+ if (argc != 4)
+ return RESULT_SHOWUSAGE;
+ ast_pthread_mutex_lock(&iflock);
+ cur = iflist;
+ while(cur) {
+ if (!strcasecmp(cur->callid, argv[3])) {
+ ast_cli(fd, "Call-ID: %s\n", cur->callid);
+ ast_cli(fd, "Theoretical Address: %s:%d\n", inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
+ ast_cli(fd, "Received Address: %s:%d\n", inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
+ ast_cli(fd, "NAT Support: %s\n", cur->nat ? "Yes" : "No");
+ break;
+ }
+ cur = cur->next;
+ }
+ ast_pthread_mutex_unlock(&iflock);
+ if (!cur)
+ ast_cli(fd, "No such SIP Call ID '%s'\n", cur->callid);
+ return RESULT_SUCCESS;
+}
+
static void receive_info(struct sip_pvt *p, struct sip_request *req)
{
char buf[1024] = "";
"Usage: sip show channels\n"
" Lists all currently active SIP channels.\n";
+static char show_channel_usage[] =
+"Usage: sip show channel <channel>\n"
+" Provides detailed status on a given SIP channel.\n";
+
static char show_peers_usage[] =
"Usage: sip show peers\n"
" Lists all known SIP peers.\n";
static struct ast_cli_entry cli_show_users =
{ { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage };
static struct ast_cli_entry cli_show_channels =
- { { "sip", "show", "channels", NULL }, sip_show_channels, "Show active SIP channels", show_channels_usage };
+ { { "sip", "show", "channels", NULL }, sip_show_channels, "Show active SIP channels", show_channels_usage};
+static struct ast_cli_entry cli_show_channel =
+ { { "sip", "show", "channel", NULL }, sip_show_channel, "Show detailed SIP channel info", show_channel_usage, complete_sipch };
static struct ast_cli_entry cli_show_peers =
{ { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage };
static struct ast_cli_entry cli_show_registry =
return 0;
}
- p = sip_alloc(NULL, NULL);
+ p = sip_alloc(NULL, NULL, 0);
if (!p) {
ast_log(LOG_WARNING, "Unable to build sip pvt data for MWI\n");
ast_pthread_mutex_unlock(&peerl.lock);
ast_log(LOG_NOTICE, "Still have a call...\n");
sip_destroy(peer->call);
}
- p = peer->call = sip_alloc(NULL, NULL);
+ p = peer->call = sip_alloc(NULL, NULL, 0);
if (!peer->call) {
ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name);
return -1;
ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format %d while capability is %d\n", oldformat, capability);
return NULL;
}
- p = sip_alloc(NULL, NULL);
+ p = sip_alloc(NULL, NULL, 0);
if (!p) {
ast_log(LOG_WARNING, "Unable to build sip pvt data for '%s'\n", (char *)data);
return NULL;
}
ast_cli_register(&cli_show_users);
ast_cli_register(&cli_show_channels);
+ ast_cli_register(&cli_show_channel);
ast_cli_register(&cli_show_peers);
ast_cli_register(&cli_show_registry);
ast_cli_register(&cli_debug);