[asterisk-dev] [Code Review]: Add update callback to dnsmgr since chan_sip peers need to be re-linked in peers_by_ip when the IP changes

Terry Wilson reviewboard at asterisk.org
Wed Jan 25 16:08:36 CST 2012



> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > I've made some comments below for specific issues in the SIP code.
> > 
> > More importantly though is that you're proposing this as a 1.8 change. It introduces an API change, which is a no-no. One way that you could alleviate this problem is by amending your patch to be an API addition instead of an API change. Add a function to dnsmgr.h to add a callback to a dnsmgr struct. This would have the benefit of not overloading the functionality of ast_dnsmgr_lookup, and you would not have to patch chan_iax2.c at all.

Adding an API change in something that is only used in two files seemed like it might be doable--especially in a feature that is disabled by default anyway. As I mentioned, I'd really like to remove passing in the addr at all. Just updating the address willy-nilly is something I consider a bug in the API.

If we can't (destructively) modify the API, I'll probably just make a new API lookup function that doesn't take an addr and instead takes callback and data pointers. Opinions?


> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > /branches/1.8/channels/chan_sip.c, lines 27721-27725
> > <https://reviewboard.asterisk.org/r/1691/diff/1/?file=23611#file23611line27721>
> >
> >     You've introduced a reference leak here. You add one to the reference that the dnsmgr will get. You need to remove that here. The unref currently here is only getting rid of the reference that build_peer acquired earlier in the function.

Fixed.


> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > /branches/1.8/channels/chan_sip.c, lines 27720-27729
> > <https://reviewboard.asterisk.org/r/1691/diff/1/?file=23611#file23611line27720>
> >
> >     Use peer_ref() and peer_unref().
> >     
> >     peer_ref returns the peer object back to you, so you can pass peer_ref(peer) as the final argument to ast_dnsmgr_lookup() if that appeals to you.

Changed.


> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > /branches/1.8/channels/chan_sip.c, lines 12339-12355
> > <https://reviewboard.asterisk.org/r/1691/diff/1/?file=23611#file23611line12339>
> >
> >     A couple of refcount notes:
> >     
> >     1. Use ref_peer() and unref_peer() for peer reference count updates.
> >     2. Why are these ref changes necessary? Anyone calling this function should already have a reference to the peer.

They aren't really necessary most likely, I just was a little paranoid about unlinking something I wanted to stay around without being absolutely certain that there was a proper reference held. I went ahead and removed them since it would be a pretty big bug to get here without holding an additional ref.


> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > /branches/1.8/channels/chan_sip.c, line 2883
> > <https://reviewboard.asterisk.org/r/1691/diff/1/?file=23611#file23611line2883>
> >
> >     Use peer_unref

Changed.


> On Jan. 25, 2012, 3:24 p.m., Mark Michelson wrote:
> > /branches/1.8/channels/chan_sip.c, line 12348
> > <https://reviewboard.asterisk.org/r/1691/diff/1/?file=23611#file23611line12348>
> >
> >     ast_sockaddr_stringify uses thread-local storage. The second call to the function will result in overwriting the string created by the first call. This will result in printing the same address twice in this debug line. You need to use something like ast_strdupa() on the result of each ast_sockaddr_stringify() function before using them.

Good catch. Fixed.


- Terry


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1691/#review5293
-----------------------------------------------------------


On Jan. 25, 2012, 12:30 p.m., Terry Wilson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1691/
> -----------------------------------------------------------
> 
> (Updated Jan. 25, 2012, 12:30 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Asterisk's dnsmgr currently takes a pointer to an ast_sockaddr and updates it anytime an address resolves to something different. There are a couple of issues with this. First, the ast_sockaddr is usually the address of an ast_sockaddr inside a refcounted struct and we never bump the refcount of those structs when using dnsmgr. This makes it possible that a refresh could happen after the destructor for that object is called (despite ast_dnsmgr_release being called in that destructor). Second, the module using dnsmgr cannot be aware of an address changing without polling for it in the code. If an action needs to be taken on address update (like re-linking a SIP peer in the peers_by_ip table), then polling for this change negates many of the benefits of having dnsmgr in the first place.
> 
> This patch adds an update callback that is called if a pointer to a callback function is provided to ast_dnsmgr_lookup(). It also moves calls to ast_dnsmgr_release outside of the destructor functions and into cleanup functions that are called when we no longer need the objects and increments the refcount of the objects using dnsmgr since those objects are stored on the ast_dnsmgr_entry struct. A helper function for returning the proper default SIP port (non-tls vs tls) is also added and used.
> 
> The current implementation in the patch is backward compatible with code that doesn't use the update callback. Seeing as this is only two calls in chan_iax2, it might be better to just update chan_iax2 and insist on using the update callback. This would allow us to stop passing in the ast_sockaddr pointer altogether. I'll update the documentation of the dnsmgr functions (and CHANGES) after we decide on the aforementioned point.
> 
> This patch also builds on the registry fixes suggested Timo Teräs in issue ASTERISK-19106 re: the port number being 0 after a dnsmgr update.
> 
> 
> This addresses bug ASTERISK-19106.
>     https://issues.asterisk.org/jira/browse/ASTERISK-19106
> 
> 
> Diffs
> -----
> 
>   /branches/1.8/channels/chan_iax2.c 352519 
>   /branches/1.8/channels/chan_sip.c 352551 
>   /branches/1.8/include/asterisk/dnsmgr.h 352519 
>   /branches/1.8/main/dnsmgr.c 352519 
> 
> Diff: https://reviewboard.asterisk.org/r/1691/diff
> 
> 
> Testing
> -------
> 
> I have tested registration via register => x at peer and via peers defined with callbackextension by having the host=invalid.address and selectively defining invalid.address in /etc/hosts with and without dnsmgr enabled. Timo Teräs in ASTERISK-19106 also reports that it fixes the issues he was experiencing.
> 
> 
> Thanks,
> 
> Terry
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120125/2fd4fc96/attachment-0001.htm>


More information about the asterisk-dev mailing list