I doing some tests using calls originated from many IP address, but using a same IP address at the Via header of the SIP message. However, Asterisk has ignoring the Via header and sends the responses to IP address from which the request came. How to force Asterisk to use the address contained in the Via header?
Defining the peers as on the local network should also disable the forced rport behaviour. NB, if the via header contains rport, I’m not sure that you can override it.
Also note that the handling of maddr, in chan_sip, is flakey.
Looking at what RFC 3261 says, you are actually asking Asterisk to violate a mandatory requirement of the protocol!
When the server transport receives a request over any transport, it
MUST examine the value of the “sent-by” parameter in the top Via
header field value. If the host portion of the “sent-by” parameter
contains a domain name, or if it contains an IP address that differs
from the packet source address, the server MUST add a “received”
parameter to that Via header field value. This parameter MUST
contain the source address from which the packet was received. This
is to assist the server transport layer in sending the response,
since it must be sent to the source IP address from which the request
came.
…
Otherwise (for unreliable unicast transports), if the top Via
has a “received” parameter, the response MUST be sent to the
address in the “received” parameter, using the port indicated
in the “sent-by” value, or using port 5060 if none is specified
explicitly. If this fails, for example, elicits an ICMP “port
unreachable” response, the procedures of Section 5 of [4]
SHOULD be used to determine where to send the response.
The only way of overriding this is with maddr, but Asterisk support of maddr is weak.