Filipe Brandenburger
2007-Aug-03 18:50 UTC
[asterisk-users] Several doubts on Asterisk as an UAC
Hi, I'm new to Asterisk and I've been trying to configure it to talk to several SIP providers (such as FWD). I found that, although there are some "recipes" on how to do it, there are few documents that really explain *why* the settings are used, and overall I found very little documentation on sip.conf. I've been using this page as a reference: http://www.voip-info.org/wiki-Asterisk+config+sip.conf It's very good. However, there's no explanation on "register" command, for instance. There are also some other things that are not completely clear. That's why I wanted to ask lots of questions about it, and hopefully I'll get some good answers here. I'll focus only on having Asterisk being a SIP *client* (I believe this is called UAC [User Agent Client] in the SIP world, right?) connecting to a SIP provider (such as FWD). I'm using asterisk 1.4.6, so I would like to talk *only* about configuration on asterisk 1.4.x. * SIP channels on outgoing calls If on my sip.conf I have a section [myprovider], it always creates a new SIP channel "SIP/myprovider", right? If I want to use it on extensions.conf to call extension 464646 there, I can use: Dial(SIP/myprovider/464646) or: Dial(SIP/464646 at myprovider) Is that right? If I don't want to keep the section on sip.conf, and myprovider's host is "hostname.myprovider.com", and I login with user "myuser" and secret "mypasswd", I can also use this information directly on the "Dial" like this: Dial(SIP/myuser:mypasswd at hostname.myprovider.com/464646) Is that right? Do I always have to authenticate to make outgoing calls? For instance, could I do just this? Dial(SIP/hostname.myprovider.com/464646) Would it work for some outgoing numbers but not others? I believe with a provider that allows me to do outgoing PSTN calls it wouldn't work, but with free providers it might... someone has some info on this? * Difference between type=user and type=peer I saw this: http://www.voip-info.org/wiki/view/Asterisk+SIP+user+vs+peer But I still didn't understand completely how it works... First of all, the configuration type=... will affect only *incoming* calls, right? If I got it right, when Asterisk receives a call it will try to match to all the type=peer sections by matching the "Host:" field of the INVITE packet to the host=... configurations of type=peer sections. Right? If that fails, it will ask for an authenticated INVITE, then it will take the username/secret from the authenticated INVITE packet, and then will look for type=user sections and match with username=... fields. Now, what does happen for type=friend sections? Can they have both host=... and username=... fields and they'll match on both? Could someone really explain what is the algorithm (or at least the idea) of how the call is matched when it's being received? * context= in [default] and on outgoing calls Ok, so if I have [myprovider] section with context=something. When I do an outgoing call by using "Dial(SIP/myprovider/464646)", does context=... affect anything? As I understand it, it only affects incoming calls, but I might be wrong. Another thing, the setting of context=... on [default] section will affect all [provider] sections without context=..., right? What if I don't specify any context on [default], what would be the default context? What if there's no context or an invalid context on a section, what would happen to incoming calls that match that section? * What exactly are "fromuser" and "fromdomain"? As I get it, they're used only in outgoing calls, right? As I understand, they change some fields on the INVITE packet sent to the provider. Right? Now, why do I need them? If I don't specify them, what is the behaviour? What's the default value for these options? * The use of "register => ..." When I use "register", the *only* thing it does is that Asterisk will send periodic REGISTER packets to the provider, right? This is useful for the provider to know to which IP it should direct calls that it receives for my extension. When I use "register => ...", does it create a "SIP/..." channel? I think it doesn't, but if you use the same syntax, which is "SIP/myuser:mypasswd at hostname.myprovider.com/${EXTEN}" it will create a channel "on-the-fly", am I right? When I use "register => ...", if after that I use "SIP/hostname.myprovider.com/${EXTEN}", will it use the same username/secret I used for registering? Is it possible to register without a secret? Does it make sense? Do I always have to put "register => ..." commands on the [default] section? Does it make sense to put them on other sections? What would be the side effects of that? * The use of "insecure" If I got this right, I should use "insecure" when I want specific tasks to be done without authentication. For example, if I'm registered to a provider and someone wants to call me, the provider's host will send me an INVITE packet, right? If I don't use "insecure", the Asterisk will answer with an error code that requires the provider to authenticate. If the provider can authenticate *with the same secret I use to register and to authenticate to the provider*, then it will authenticate the INVITE and the call will complete. But I believe this is not the case for most providers, usually they don't authenticate calls to UAC's, am I right? In this case, I should use "insecure=invite" for these providers. This has a security issue involved, that is, anyone on the Internet might send me an INVITE packet with "Host: hostname.myprovider.com" on the SIP header, and my Asterisk box would accept the call as it was really coming from myprovider, that means, it will route the call to the context=... set on the [myprovider] section where there's the definition of "host=hostname.myprovider.com", right? * "canreinvite=no" I believe is different if I use "canreinvite=no" for my SIP phone and "canreinvite=no" to a provider. Using "canreinvite=no" means that for every call I make using my SIP phone, throught the Asterisk box, to a SIP provider, Asterisk will *NOT* try to send a redirect to the SIP phone saying that the phone should send RTP to the provider's servers or even to the other endpoint directly, instead of sending RTP to the Asterisk box and then the Asterisk box sending it to the endpoint. Using "canreinvite=no" on a provider configuration, for every call using a SIP provider, I'll force Asterisk to send all audio data to the provider and won't allow Asterisk to send RTP directly to the other endpoint. Am I right? In this case, the recommended setting would be using "canreinvite=no" for my SIP phones on my internal network, because I want them to talk to the Asterisk server only. But, on the other hand, I should probably set "canreinvite=yes" on the provider configuration, because then I may end up having a more direct path to the destination, without using the provider as a proxy, and also with less latency. Am I right? Well, I think that's it... I thank you very much for having the time to see my doubts! Thanks for making Asterisk the great product it is. Filipe