[asterisk-commits] oej: branch oej/pgtips-srv-and-outbound-stuff-1.8 r397641 - in /team/oej/pgti...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 26 10:30:57 CDT 2013


Author: oej
Date: Mon Aug 26 10:30:55 2013
New Revision: 397641

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397641
Log:
Using the standard ACL for this ACL did not work as the standard ACL has no port numbers.

Feel like I have made enough changes in core code for one patch, so I create a quick-and-dirty
linked list (hi Mattj!) to solve my immediate problem.

Modified:
    team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c
    team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h
    team/oej/pgtips-srv-and-outbound-stuff-1.8/main/srv.c

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c?view=diff&rev=397641&r1=397640&r2=397641
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/chan_sip.c Mon Aug 26 10:30:55 2013
@@ -1361,6 +1361,7 @@
 static void ast_quiet_chan(struct ast_channel *chan);
 static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target);
 static int do_magic_pickup(struct ast_channel *channel, const char *extension, const char *context);
+static void free_sip_host_ip(struct sip_host_ip *hostlist);
 
 /*--- Device monitoring and Device/extension state/event handling */
 static int cb_extensionstate(char *context, char* exten, int state, void *data);
@@ -4963,6 +4964,46 @@
 	ast_free(mailbox);
 }
 
+static void host_ip_list_debug(struct sip_host_ip *hostip)
+{
+	struct sip_host_ip *hip = hostip;
+	int count = 0;
+
+	while (hip) {
+		count++;
+		ast_debug(3, "    %-2.2d. %s %u\n", count, ast_sockaddr_stringify_addr(&hip->ip), hip->port);
+		hip = hip->next;
+	}
+	
+}
+
+static struct sip_host_ip *add_sip_host_ip(struct sip_host_ip *hostip, struct ast_sockaddr *ip, int port, const char *hostname)
+{
+	struct sip_host_ip *new;
+	new = ast_calloc(1, sizeof(struct sip_host_ip));
+	if (!new) {
+		return NULL;
+	}
+	ast_sockaddr_copy(&new->ip, ip);
+	ast_copy_string(new->hostname, hostname, sizeof(new->hostname));
+	new->port = port;
+	new->next = hostip;
+
+	return new;
+}
+
+/*! Release srv host entries */
+static void free_sip_host_ip(struct sip_host_ip *hostlist) 
+{
+	struct sip_host_ip *hup, *hip = hostlist;
+
+	while (hip) {
+		hup = hip->next;
+		ast_free(hip);
+		hip = hup;
+	}
+}
+
 /*! Destroy all peer-related mailbox subscriptions */
 static void clear_peer_mailboxes(struct sip_peer *peer)
 {
@@ -5019,7 +5060,9 @@
 	register_peer_exten(peer, FALSE);
 	ast_free_ha(peer->ha);
 	ast_free_ha(peer->directmediaha);
-	ast_free_ha(peer->srventries);		/* ACL based on IP addresses in SRV list for domain */
+
+	free_sip_host_ip(peer->srventries);
+
 	if (peer->selfdestruct)
 		ast_atomic_fetchadd_int(&apeerobjs, -1);
 	else if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->is_realtime) {
@@ -5796,7 +5839,7 @@
 	char host[MAXHOSTNAMELEN];
 	char service[MAXHOSTNAMELEN];
 	int srv_ret = 0;
-	int tportno;
+	unsigned short tportno;
 
 	AST_DECLARE_APP_ARGS(hostport,
 		AST_APP_ARG(host);
@@ -5882,6 +5925,7 @@
 					hostn = host;
 					tportno = (int) port;
 					ast_debug(3, "   ==> Trying SRV entry %d (prio %d weight %d): %s\n", rec, prio, weight, hostn);
+					/* We need to try all IP addresses if there are multiple A / AAAA records*/
 					if (!ast_sockaddr_resolve_first_transport(&dialog->sa, hostn, 0, dialog->socket.type ? dialog->socket.type : SIP_TRANSPORT_UDP)) {
 						/* We found a host to try on */
 						break;
@@ -28615,7 +28659,7 @@
 		char _srvlookup[MAXHOSTNAMELEN];
 		char host[MAXHOSTNAMELEN];
 		char *params;
-		int tportno;
+		unsigned short tportno;
 		int gotsrv = FALSE;
 
 		ast_copy_string(_srvlookup, srvlookup, sizeof(_srvlookup));
@@ -28666,6 +28710,7 @@
 					ast_debug(3, "   ==> Trying SRV entry %d (prio %d weight %d): %s\n", rec, prio, weight, hostname);
 				} while (ast_sockaddr_resolve_first_transport(&peer->addr, hostname, 0, peer->socket.type));
 
+
 				/* Set the port number */
 				ast_sockaddr_set_port(&peer->addr, tportno);
 
@@ -28674,7 +28719,8 @@
 				/* Now loop again and fill the ACL 
 				 */
 				if (peer->srventries) {
-					ast_free_ha(peer->srventries);
+					free_sip_host_ip(peer->srventries);
+					peer->srventries = NULL;
 				}
 				for (rec = 1; rec <= ast_srv_get_record_count(peer->srvcontext); rec++) {
 					int res;
@@ -28682,18 +28728,20 @@
 					/* Get host name */
 					res = ast_srv_get_nth_record(peer->srvcontext, rec, &hostname, &tportno, &prio, &weight);
 					if (!res) {
+						/* We need to test every address in the SRV record set. */
 						res = ast_sockaddr_resolve_first_transport(&ip, hostname, 0, peer->socket.type);
 						if (ast_sockaddr_isnull(&ip) || res ) {
 							ast_debug(3, " ==> Bad IP, could not resolve hostname %s to proper family. \n", hostname);
 						} else {
-							peer->srventries = ast_append_ha("p", ast_sockaddr_stringify_addr(&ip), peer->srventries, &res);
+							peer->srventries = add_sip_host_ip(peer->srventries, &ip, tportno, hostname);
+							//peer->srventries = ast_append_ha("p", ast_sockaddr_stringify_addr(&ip), peer->srventries, &res);
 							ast_debug(3, " ==> Adding IP to peer %s srv list: %s \n", name, ast_sockaddr_stringify_addr(&ip));
 						}
 					}
 				}
 				if (option_debug > 3) {
 					ast_debug(3, "======> List of IP matching entries for %s <============\n", name);
-					ha_list_debug(peer->srventries);
+					host_ip_list_debug(peer->srventries);
 				}
 
 		} else {
@@ -30763,7 +30811,6 @@
 			ast_debug(0, "           => %d: %s resolves into  %s\n", i, name, ast_sockaddr_stringify(&addrs[i]));
 		}
 	}
-	
 
 	ast_sockaddr_copy(addr, &addrs[0]);
 

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h?view=diff&rev=397641&r1=397640&r2=397641
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/channels/sip/include/sip.h Mon Aug 26 10:30:55 2013
@@ -656,13 +656,22 @@
 struct sip_proxy {
 	char name[MAXHOSTNAMELEN];      /*!< DNS name of domain/host or IP */
 	struct ast_sockaddr ip;          /*!< Currently used IP address and port */
-	int port;
+	unsigned short port;
 	time_t last_dnsupdate;          /*!< When this was resolved */
 	enum sip_transport transport;	/*!< TCP, UDP or TCP/TLS - possibly WS in the future */
 	int force;                      /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */
 	/* Room for a SRV record chain based on the name */
 	struct sip_proxy *next;
 	struct srv_context *srvlist;	/*!< List of DNs entries */
+};
+
+/*! \brief A stupid simple linked list for storing host IPs and ports 
+ */
+struct sip_host_ip {
+	char hostname[MAXHOSTNAMELEN];	/* DNS NAME of host */
+	struct ast_sockaddr ip;		
+	unsigned short port;
+	struct sip_host_ip *next;
 };
 
 
@@ -1270,7 +1279,7 @@
 	struct ast_ha *ha;              /*!<  Access control list */
 	struct ast_ha *contactha;       /*!<  Restrict what IPs are allowed in the Contact header (for registration) */
 	struct ast_ha *directmediaha;   /*!<  Restrict what IPs are allowed to interchange direct media with */
-	struct ast_ha *srventries;      /*!<  DNS Srv entries at time of peer creation  */
+	struct sip_host_ip *srventries; /*!<  DNS Srv entries at time of peer creation  */
 	struct ast_variable *chanvars;  /*!<  Variables to set for channel created by user */
 	struct sip_pvt *mwipvt;         /*!<  Subscription for MWI */
 	struct sip_st_cfg stimer;       /*!<  SIP Session-Timers */

Modified: team/oej/pgtips-srv-and-outbound-stuff-1.8/main/srv.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pgtips-srv-and-outbound-stuff-1.8/main/srv.c?view=diff&rev=397641&r1=397640&r2=397641
==============================================================================
--- team/oej/pgtips-srv-and-outbound-stuff-1.8/main/srv.c (original)
+++ team/oej/pgtips-srv-and-outbound-stuff-1.8/main/srv.c Mon Aug 26 10:30:55 2013
@@ -27,7 +27,9 @@
  * \arg See also \ref AstENUM
  *
  * \note Funding provided by nic.at
+ * 
  */
+
 
 /*** MODULEINFO
 	<support_level>core</support_level>
@@ -65,8 +67,9 @@
 	unsigned short port;
 	unsigned int weight_sum;
 	struct timeval ttl_expire;		/* Expiry time */
+	struct srv_ip *ip;			/* List of multiple IP addresses - A and AAAA (or future families ) */
 	AST_LIST_ENTRY(srv_entry) list;
-	char host[1];
+	char host[1];				/* Last entry */
 };
 
 struct srv_context {
@@ -261,7 +264,7 @@
 		(*context)->prev = AST_LIST_FIRST(&(*context)->entries);
 		*host = (*context)->prev->host;
 		*port = (*context)->prev->port;
-		(*context)-> current = (*context)->prev;
+		(*context)->current = (*context)->prev;
 		return 0;
 	}
 
@@ -269,7 +272,7 @@
 		/* Retrieve next item in result */
 		*host = (*context)->prev->host;
 		*port = (*context)->prev->port;
-		(*context)-> current = (*context)->prev;
+		(*context)->current = (*context)->prev;
 		return 0;
 	} else {
 		/* No more results */




More information about the asterisk-commits mailing list