[asterisk-dev] expensive call - ast_ouraddrfor()

Luigi Rizzo rizzo at icir.org
Tue Jul 17 19:17:32 CDT 2007


On Tue, Jul 17, 2007 at 06:08:02PM -0500, Kevin P. Fleming wrote:
> Luigi Rizzo wrote:
> 
> > because the risk is that you end up with 100's of open sockets,
> > one for each active dialog (and it's not just the number of descriptors,
> > is the fact that you need to poll() or select() on them, or have
> > one thread on each).
> 
> No, you misunderstood. I meant to open a socket each time we see that we
> have received a packet on a new IP address, then use that socket for all

ah ok, so by "new IP address" you mean the local address, not the remote one.

> > - What you really want here is do a route lookup, but i have no
> >   idea if there is any kernel interface that exposes such queries.
> 
> No there isn't, and I'm not sure you could rely on it anyway, because it
> can change at any time. Using a socket solves that problem, because the

now you misunderstand :)
Remember, the user-level lookup is done only at the start of the
'dialog' (i.e. when you now do an ast_ouraddfrom()), and besides it
is only used to build the info to put in the SIP/SDP/MyBogusProtocol
messages. Other than that, you still `transmit with a sendto() on a wildcard
socketi, so the kernel is still in charge of routing, and picking a valid
local address every time there is a new transmission.

> > ... [my static configuration approach, omitted]

> > What do you think ? Makes sense ?
> 
> And what happens when the network topology changes... on the fly, via
> BGP, because an upstream link went down? I don't think it would be wise
> to try to build this information into Asterisk at all, it's just too
> hard to do right.

i may be mistaken, but it seems to me that:
1. the normal case where you have only one "public" address plus
   some private ones should work fine: the lookup for 'public'
   destinations will match the only address which is good to talk to
   them, while others (e.g. private subnets etc.) will match other
   addresses. After all, this is what you get now with the "localnet"
   parameters (which in fact is similar to what i proposed, except
   that it only defines two "subnets");

2. when you have multiple public IP addresses, my proposal should still
   work as in principle they should be all reachable from the outside.
   So if you tell me any of your public IP addresses, I should still
   be able to talk to you, one route or another.

One case when my solution possibly breaks is when you are multihomed
and the network is partitioned (routingwise), so that e.g. one of the
"public" addresses is actually unable to receive from part of the
network.
   But then (remember that routing is asymmetric too) nothing will help
you here: even if by some magic (e.g. what ast_ouraddrfor() does now)
you pick a good source address to talk to me, that same address might not
be a good one in the other direction, i.e. for me to talk to you.

This said, the static configuration, and the semi-static one
(periodic updates of local addresses) that I suggested
can surely be extended with other available sources, e.g. if recvfrom
can tell you the matching local address (not sure it can do that
with the cmsg parameter), surely that's a good answer for
ast_ouraddrfor() .

	cheers
	luigi






More information about the asterisk-dev mailing list