mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-10 14:51:09 +00:00
Handle DNS failures on startup more gracefully (bug #3086)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4989 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
29
acl.c
29
acl.c
@@ -384,3 +384,32 @@ struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_co
|
|||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
|
||||||
|
{
|
||||||
|
char ourhost[256];
|
||||||
|
struct ast_hostent ahp;
|
||||||
|
struct hostent *hp;
|
||||||
|
struct in_addr saddr;
|
||||||
|
|
||||||
|
/* just use the bind address if it is nonzero */
|
||||||
|
if (ntohl(bindaddr.sin_addr.s_addr)) {
|
||||||
|
memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* try to use our hostname */
|
||||||
|
if (gethostname(ourhost, sizeof(ourhost))) {
|
||||||
|
ast_log(LOG_WARNING, "Unable to get hostname\n");
|
||||||
|
} else {
|
||||||
|
hp = ast_gethostbyname(ourhost, &ahp);
|
||||||
|
if (hp) {
|
||||||
|
memcpy(ourip, hp->h_addr, sizeof(*ourip));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* A.ROOT-SERVERS.NET. */
|
||||||
|
if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip))
|
||||||
|
return 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -191,7 +191,6 @@ static int restart_monitor(void);
|
|||||||
static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
|
static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
|
||||||
static int noncodeccapability = AST_RTP_DTMF;
|
static int noncodeccapability = AST_RTP_DTMF;
|
||||||
|
|
||||||
static char ourhost[256];
|
|
||||||
static struct in_addr __ourip;
|
static struct in_addr __ourip;
|
||||||
static struct sockaddr_in outboundproxyip;
|
static struct sockaddr_in outboundproxyip;
|
||||||
static int ourport;
|
static int ourport;
|
||||||
@@ -9059,10 +9058,6 @@ static int reload_config(void)
|
|||||||
char iabuf[INET_ADDRSTRLEN];
|
char iabuf[INET_ADDRSTRLEN];
|
||||||
struct ast_flags dummy;
|
struct ast_flags dummy;
|
||||||
|
|
||||||
if (gethostname(ourhost, sizeof(ourhost))) {
|
|
||||||
ast_log(LOG_WARNING, "Unable to get hostname, SIP disabled\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
cfg = ast_config_load(config);
|
cfg = ast_config_load(config);
|
||||||
|
|
||||||
/* We *must* have a config file otherwise stop immediately */
|
/* We *must* have a config file otherwise stop immediately */
|
||||||
@@ -9297,20 +9292,9 @@ static int reload_config(void)
|
|||||||
}
|
}
|
||||||
cat = ast_category_browse(cfg, cat);
|
cat = ast_category_browse(cfg, cat);
|
||||||
}
|
}
|
||||||
|
if (ast_find_ourip(&__ourip, bindaddr)) {
|
||||||
/* Find our IP address */
|
ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
|
||||||
if (ntohl(bindaddr.sin_addr.s_addr)) {
|
return 0;
|
||||||
memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip));
|
|
||||||
} else {
|
|
||||||
hp = ast_gethostbyname(ourhost, &ahp);
|
|
||||||
if (!hp) {
|
|
||||||
ast_log(LOG_WARNING, "Unable to get IP address for %s, SIP disabled\n", ourhost);
|
|
||||||
if (!__ourip.s_addr) {
|
|
||||||
ast_config_destroy(cfg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
|
|
||||||
}
|
}
|
||||||
if (!ntohs(bindaddr.sin_port))
|
if (!ntohs(bindaddr.sin_port))
|
||||||
bindaddr.sin_port = ntohs(DEFAULT_SIP_PORT);
|
bindaddr.sin_port = ntohs(DEFAULT_SIP_PORT);
|
||||||
|
@@ -50,6 +50,7 @@ extern struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, s
|
|||||||
extern int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
|
extern int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
|
||||||
extern int ast_netsock_release(struct ast_netsock_list *list);
|
extern int ast_netsock_release(struct ast_netsock_list *list);
|
||||||
extern int ast_netsock_sockfd(struct ast_netsock *ns);
|
extern int ast_netsock_sockfd(struct ast_netsock *ns);
|
||||||
|
extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
|
||||||
|
|
||||||
/*! Compares the source address and port of two sockaddr_in */
|
/*! Compares the source address and port of two sockaddr_in */
|
||||||
static inline int inaddrcmp(struct sockaddr_in *sin1, struct sockaddr_in *sin2)
|
static inline int inaddrcmp(struct sockaddr_in *sin1, struct sockaddr_in *sin2)
|
||||||
|
Reference in New Issue
Block a user