[asterisk-dev] externaddr in chan_sip.c - locking required?

Kevin P. Fleming kpfleming at digium.com
Tue Nov 1 13:02:24 CDT 2011


On 11/01/2011 10:12 AM, Ian Pilcher wrote:
> This is a follow-up to my "STUN support idea" thread.
>
> I have reached the point in my effort of actually updating the value of
> externaddr when a AST_EVENT_NETWORK_CHANGE event occurs, so I'm trying
> to understand how this variable is (or is not) accessed by multiple
> threads.
>
> Here's what I've been able to determine:
>
> * externaddr is set in reload_config().
>
> * externaddr is read in sip_show_settings().
>
> * externaddr is both read and written in ast_sip_ouraddrfor().
>
> None of these access use any locking, which seems wrong to me --
> assuming that ast_sip_ouraddrfor() is supposed to be thread-safe.
>
> Is my analysis correct?  If so, I would propose to protect accesses to
> externaddr with a read/write lock, since changes should be infrequent.

That seems logical and a good approach to solving the problem, although 
I'm surprised that ast_sip_ouraddrfor() can write into the externaddr 
variable(s).

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
Jabber: kfleming at digium.com | SIP: kpfleming at digium.com | Skype: kpfleming
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at www.digium.com & www.asterisk.org



More information about the asterisk-dev mailing list