[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r109830 - /team/jpeeler/sip-dnsmgr/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 18 19:06:27 CDT 2008
Author: jpeeler
Date: Tue Mar 18 19:06:26 2008
New Revision: 109830
URL: http://svn.digium.com/view/asterisk?view=rev&rev=109830
Log:
checkpoint, working a little better now. just need to synchronize dnsmgr between sip_registry and sip_peer i think
Modified:
team/jpeeler/sip-dnsmgr/channels/chan_sip.c
Modified: team/jpeeler/sip-dnsmgr/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/channels/chan_sip.c?view=diff&rev=109830&r1=109829&r2=109830
==============================================================================
--- team/jpeeler/sip-dnsmgr/channels/chan_sip.c (original)
+++ team/jpeeler/sip-dnsmgr/channels/chan_sip.c Tue Mar 18 19:06:26 2008
@@ -1303,6 +1303,21 @@
struct sip_st_dlg *stimer; /*!< SIP Session-Timers */
};
+/* TODO: better placement? */
+struct ast_dnsmgr_entry {
+ /*! where we will store the resulting address */
+ struct in_addr *result;
+ /*! the last result, used to check if address has changed */
+ struct in_addr last;
+ /*! Set to 1 if the entry changes */
+ int changed:1;
+ ast_mutex_t lock;
+ AST_RWLIST_ENTRY(ast_dnsmgr_entry) list;
+ /*! just 1 here, but we use calloc to allocate the correct size */
+ char name[1];
+};
+
+
/*! Max entires in the history list for a sip_pvt */
#define MAX_HISTORY_ENTRIES 50
@@ -1961,7 +1976,7 @@
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
static void build_via(struct sip_pvt *p);
static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
-static int create_addr(struct sip_pvt *dialog, const char *opeer);
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_dnsmgr_entry *dnsmgr);
static char *generate_random_string(char *buf, size_t size);
static void build_callid_pvt(struct sip_pvt *pvt);
static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
@@ -4056,7 +4071,7 @@
/*! \brief create address structure from peer name
* Or, if peer not found, find it in the global DNS
* returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, const char *opeer)
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_dnsmgr_entry *dnsmgr)
{
struct hostent *hp;
struct ast_hostent ahp;
@@ -4065,6 +4080,8 @@
int portno;
char host[MAXHOSTNAMELEN], *hostn;
char peername[256];
+
+ ast_log(LOG_DEBUG, "Create_addr\n");
ast_copy_string(peername, opeer, sizeof(peername));
port = strchr(peername, ':');
@@ -4078,6 +4095,13 @@
if (peer) {
int res = create_addr_from_peer(dialog, peer);
unref_peer(peer);
+ ast_log(LOG_DEBUG, "Peer found with address of %s\n", ast_inet_ntoa(dialog->sa.sin_addr));
+
+ if (dnsmgr) {
+ memcpy(&dialog->sa.sin_addr, &dnsmgr->last, sizeof(dialog->sa.sin_addr));
+ ast_log(LOG_DEBUG, "IP lookup for hostname=%s, using dnsmgr resolved to %s...\n", peername, ast_inet_ntoa(dnsmgr->last));
+ }
+
return res;
} else {
/* Setup default parameters for this dialog's socket. Currently we only support regular UDP SIP as the default */
@@ -4096,6 +4120,7 @@
/* Let's see if we can find the host in DNS. First try DNS SRV records,
then hostname lookup */
+
hostn = peername;
portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
@@ -4117,6 +4142,14 @@
return -1;
}
memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
+
+ if (dnsmgr) {
+ memcpy(&dialog->sa.sin_addr, &dnsmgr->last, sizeof(dialog->sa.sin_addr));
+ ast_log(LOG_DEBUG, "IP lookup for hostname=%s, using dnsmgr resolved to %s...\n", peername, ast_inet_ntoa(dnsmgr->last));
+ } else {
+ ast_log(LOG_DEBUG, "No dnsmgr detected\n");
+ }
+
dialog->sa.sin_port = htons(portno);
dialog->recv = dialog->sa;
return 0;
@@ -9195,8 +9228,6 @@
struct in_addr sin;
int changed = 0;
- ast_log(LOG_DEBUG, "Transmit_Register\n");
-
/* exit if we are already in process with this registrar ?*/
if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) {
ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
@@ -9212,7 +9243,7 @@
ast_log(LOG_DEBUG, "Change status = %d\n", changed);
}
- if (r->call && !changed) { /* We have a registration and the IP has not changed*/
+ if (r->call) { /* We have a registration */
if (!auth) {
ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname);
return 0;
@@ -9241,7 +9272,7 @@
p->outboundproxy = obproxy_get(p, NULL);
/* Find address to hostname */
- if (create_addr(p, r->hostname)) {
+ if (create_addr(p, r->hostname, r->dnsmgr)) {
/* we have what we hope is a temporary network error,
* probably DNS. We need to reschedule a registration try */
sip_destroy(p);
@@ -9289,6 +9320,7 @@
p->socket.type = r->transport;
p->socket.port = htons(r->portno);
+/*
if (changed) {
//struct sockaddr_in real;
//real = sip_real_dst(r->call);
@@ -9296,6 +9328,7 @@
ast_log(LOG_DEBUG, "IP change detected for hostname=%s, updating to %s...\n", r->hostname, ast_inet_ntoa(sin));
memcpy(&r->call->sa.sin_addr, &sin, sizeof(sin));
}
+*/
/*
check which address we should use in our contact header
based on whether the remote host is on the external or
@@ -13893,7 +13926,7 @@
return CLI_FAILURE;
}
- if (create_addr(p, a->argv[i])) {
+ if (create_addr(p, a->argv[i], NULL)) {
/* Maybe they're not registered, etc. */
sip_destroy(p);
ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]);
@@ -19139,7 +19172,7 @@
ext = extension (user part of URI)
dnid = destination of the call (applies to the To: header)
*/
- if (create_addr(p, host)) {
+ if (create_addr(p, host, NULL)) {
*cause = AST_CAUSE_UNREGISTERED;
ast_debug(3, "Cant create SIP call - target device not registred\n");
sip_destroy(p);
More information about the asterisk-commits
mailing list