[asterisk-dev] expensive call - ast_ouraddrfor()

Kevin P. Fleming kpfleming at digium.com
Tue Jul 17 14:56:52 CDT 2007


Luigi Rizzo wrote:
> just noticed that chan_sip() does a number of calls to
> ast_ouraddrfor(), which is used to determine the local
> address to use when talking to a remote peer.

I have a magic plan for this... but have never had time to implement it.
Partially that is because portions of the plan are Linux-specific, and
would be difficult to port to other platforms. However, I will describe
it anyway in the hopes that someone will find it interesting and
implement it :-) I was hoping that this stuff would make it into the
next chan_sip, but we haven't seen serious progress on that yet. It also
needs to leverage the IPV6 netsock stuff that Marc Blanchet has already
written; it would be good to get some community feedback on that code
and get it merged ASAP.

Anyway, the general idea is as follows:

1) Right now (unlike chan_iax2), chan_sip only supports a single socket
being opened, and that socket can be bound to either a wildcard address
or a specific address. Step #1 is to enhance chan_sip to support
multiple sockets being bound, using ast_netsock.

2) For sockets that are bound to a specific IP address, chan_sip should
remember that, and not need to all ast_ouraddrfor() at all.

3) For sockets that are bound to a wildcard address, chan_sip can use
recvmsg() and cmsg() to find out what IP address each received packet
was *received on*, and then open a direct socket for that IP address.
That socket should be used for all further communication related to the
sip_pvt that is involved with that packet (and be kept open until some
error occurs that causes it to be closed).

This has multiple advantages; not only do we know what IP address we
received the packets on so we can use it in signaling, but we also can
get the source IP address of our replies to match the address that the
reception occurred on, which allows people using multiple IP addresses
on a single interface to respond using the proper address. As a side
effect, it eliminates the need for ast_ouraddrfor() in most cases <G>

-- 
Kevin P. Fleming
Director of Software Technologies
Digium, Inc. - "The Genuine Asterisk Experience" (TM)



More information about the asterisk-dev mailing list