AST_MUTEX_DEFINE_STATIC(dpcache_lock);
static void reg_source_db(struct iax2_peer *p);
-static struct iax2_peer *realtime_peer(const char *peername);
+static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
static void destroy_peer(struct iax2_peer *peer);
static int ast_cli_netstats(int fd, int limit_fmt);
}
ast_mutex_unlock(&peerl.lock);
if(!peer && realtime)
- peer = realtime_peer(name);
+ peer = realtime_peer(name, NULL);
return peer;
}
}
if (lockpeer)
ast_mutex_unlock(&peerl.lock);
+ if (!peer) {
+ peer = realtime_peer(NULL, &sin);
+ if (peer) {
+ ast_copy_string(host, peer->name, len);
+ if (ast_test_flag(peer, IAX_TEMPONLY))
+ destroy_peer(peer);
+ }
+ }
return res;
}
static void destroy_user(struct iax2_user *user);
static int expire_registry(void *data);
-static struct iax2_peer *realtime_peer(const char *peername)
+static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
{
struct ast_variable *var;
struct ast_variable *tmp;
time_t regseconds, nowtime;
int dynamic=0;
- var = ast_load_realtime("iaxpeers", "name", peername, NULL);
+ if (peername)
+ var = ast_load_realtime("iaxpeers", "name", peername, NULL);
+ else {
+ char iabuf[INET_ADDRSTRLEN];
+ char porta[25];
+ ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
+ sprintf(porta, "%d", ntohs(sin->sin_port));
+ var = ast_load_realtime("iaxpeers", "ipaddr", iabuf, "port", porta, NULL);
+ }
if (!var)
return NULL;
if (!peer) {
/* We checked our list and didn't find one. It's unlikely, but possible,
that we're trying to authenticate *to* a realtime peer */
- if ((peer = realtime_peer(p->peer))) {
+ if ((peer = realtime_peer(p->peer, NULL))) {
res = authenticate(p->challenge, peer->secret,peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
if (ast_test_flag(peer, IAX_TEMPONLY))
destroy_peer(peer);