[asterisk-users] chan_sip sending from wrong source address when multiple interfaces are used

Benny Amorsen benny+usenet at amorsen.dk
Fri Jul 13 06:22:40 CDT 2012


"Kevin P. Fleming" <kpfleming at digium.com> writes:

> I've just looked into this a bit, and I don't see how using connect()
> would actually solve the problem. If we receive a UDP datagram from a
> SIP endpoint, we could use socket() and connect() to create a socket
> specifically for sending to (and receiving from) that endpoint in the
> future, but we can't specify the source address to be used by that
> socket. The only way I know of to specify the source address for
> outbound packets is to use a raw socket and compose the IP header
> ourselves, which would be overkill.

You just bind() to the source address you want to use for outgoing
packets. I have just tested it, it works here at least. The tricky bit
is knowing which source address you want to use. That you can get from
IP_PKTINFO, somewhat portably.

Once you have a socket with connect() and bind(), the full 5-tuplet of
protocol, srcaddr, srcport, dstaddr, dstport is defined, and all further
traffic related to that "connection" should be going to that socket.
However, in between the time that the first packet arrived and that
socket is up and running, more packets may have been queued on the
original server socket. This cannot happen with TCP because accept() is
atomic (the client cannot send more data before the three-way-handshake
is done), but there is no such luck with UDP.


/Benny




More information about the asterisk-users mailing list