[Users] Re: OpenSER as a Load Balancer for Asterisk and RE-INVITEs

Edoardo Serra edoardo.serra at webrainstorm.it
Sun Mar 25 21:14:48 CEST 2007


Christian Schlatter ha scritto:
> The call hold RE-INVITE issued by the called UA should include an R-URI 
> including the contact address of the GW who initiated the SIP call. So 
> if a call comes from asterisk.1 the RE-INVITE should include a R-URI 
> like "INVITE sip:ip.of.asterisk.1" (depending of what asterisk.1 puts in 
> its contact header).
> 
> In your script you always call ds_select_dst and the RE-INVITEs get 
> routed to a destination from the dispatcher destination set instead of 
> using the R-URI to route the call to the correct GW.

You're right, looking better at the script our loose-route processing 
doesn't make sense.
I'm wondering which was its intended meaning....

Tnx for your suggestion it looks good and works like a charm !

Regards

Edoardo

> Since you record route each request you could test if the following works:
> 
>  >         # loose-route processing
>  >         if (loose_route()) {
>  >                 # mark routing logic in request
>  >                 append_hf("P-hint: rr-enforced\r\n");
>  >
>  >                 # don't do ds_select_dst here since the R-URI
>  >                 # of RE-INVITEs should
>  >                 # contain the correct GW address
>  >                 t_relay();
>  >                 exit;
>  >         };
> 
> 
> Christian
> 
>>
>> Tnx in advance for help
>>
>> Edoardo
>>
>> My openser.cfg follows
>>
>> # $Id: ser.cfg,v 1.21.4.1 2003/11/10 15:35:15 andrei Exp $
>> # ----------- global configuration parameters ------------------------
>>
>> check_via=yes    # (cmd. line: -v)
>> dns=no          # (cmd. line: -r)
>> rev_dns=no      # (cmd. line: -R)
>> fifo="/tmp/ser_fifo"
>>
>> #uid=nobody
>> #gid=nobody
>>
>> # ------------------ module loading ----------------------------------
>> loadmodule "/usr/lib/openser/modules/sl.so"
>> loadmodule "/usr/lib/openser/modules/tm.so"
>> loadmodule "/usr/lib/openser/modules/rr.so"
>> loadmodule "/usr/lib/openser/modules/maxfwd.so"
>> loadmodule "/usr/lib/openser/modules/usrloc.so"
>> loadmodule "/usr/lib/openser/modules/registrar.so"
>> loadmodule "/usr/lib/openser/modules/nathelper.so"
>> loadmodule "/usr/lib/openser/modules/textops.so"
>> loadmodule "/usr/lib/openser/modules/exec.so"
>> loadmodule "/usr/lib/openser/modules/uri.so"
>> loadmodule "/usr/lib/openser/modules/uri_db.so"
>> loadmodule "/usr/lib/openser/modules/dispatcher.so"
>> loadmodule "/usr/lib/openser/modules/mysql.so"
>> loadmodule "/usr/lib/openser/modules/auth.so"
>> loadmodule "/usr/lib/openser/modules/auth_db.so"
>>
>> modparam("usrloc", "db_mode", 2)
>> modparam("usrloc", "db_url", 
>> "mysql://user:pass@192.168.252.5/openser")
>> modparam("usrloc", "timer_interval", 120)
>> modparam("auth_db", "calculate_ha1", 0)
>> modparam("auth_db", "db_url", 
>> "mysql://user:pass@192.168.252.5/db")
>> modparam("uri_db", "db_url", 
>> "mysql://user:pass@192.168.252.5/openser")
>> modparam("rr", "enable_full_lr", 1)
>> modparam("registrar", "nat_flag", 6)
>> modparam("registrar", "max_expires", 3600)
>> modparam("registrar", "min_expires", 60)
>> modparam("registrar", "append_branches", 0)
>> modparam("registrar", "desc_time_order", 1)
>> modparam("nathelper", "natping_interval", 20) # Ping interval 20 s
>> modparam("nathelper", "ping_nated_only", 1)   # Ping only clients 
>> behind NAT
>> modparam("dispatcher", "force_dst", 1)
>>
>> # -------------------------  request routing logic -------------------
>> # main routing logic
>>
>> route{
>>         if (!mf_process_maxfwd_header("10")) {
>>                 sl_send_reply("483","Too Many Hops");
>>                 exit;
>>         };
>>         if ( msg:len > max_len ) {
>>                 sl_send_reply("513", "Message too big");
>>                 exit;
>>         };
>>
>>         if ( (method=="OPTIONS") || (method=="SUBSCRIBE") || 
>> (method=="NOTIFY") ) {
>>                 sl_send_reply("405", "Method Not Allowed");
>>                 exit;
>>         }
>>
>>         if (!method=="REGISTER") {
>>                 record_route();
>>         };
>>
>>
>>         if ((src_ip==ip.of.asterisk.1) || (src_ip==ip.of.asterisk.1)) {
>>                 if (!lookup("location")) {
>>                         sl_send_reply("486", "Busy here");
>>                         exit;
>>                 };
>>                 if (!t_relay()) {
>>                         sl_reply_error();
>>                 };
>>                 exit;
>>         };
>>
>>         if (nat_uac_test("3")) {
>>                 if ((method=="REGISTER") || (method=="INVITE") || 
>> (method=="OPTIONS")) {
>>                         fix_nated_contact();
>>                         force_rport();
>>                         setflag(6);    # Mark as NATed
>>                 }
>>         }
>>
>>         if (method=="REGISTER") {
>>                 if (!proxy_authorize("exorsa", "openser_view")) {
>>                         proxy_challenge("exorsa", "0");
>>                         exit;
>>                 }
>>                 if (!check_to()) {
>>                         sl_send_reply("403", "Digest username and URI 
>> username do NOT match! Stay away!");
>>                         exit;
>>                 }
>>
>>                 save("location");
>>
>>                 exit;
>>         };
>>
>>
>>     if (method=="INVITE") {
>>         if (!proxy_authorize("exorsa", "openser_view")) {
>>             proxy_challenge("exorsa", "0");
>>             exit;
>>         }
>>
>>         if (!check_from()) {
>>             sl_send_reply("403", "Digest username and URI username do 
>> NOT match! Stay away!");
>>             exit;
>>         }
>>     }
>>
>>         # loose-route processing
>>         if (loose_route()) {
>>                 # mark routing logic in request
>>                 append_hf("P-hint: rr-enforced\r\n");
>>                 route(1);
>>                 exit;
>>         };
>>
>>         if (!uri==myself) {
>>                 # mark routing logic in request
>>                 append_hf("P-hint: outbound\r\n");
>>                 route(1);
>>                 exit;
>>         };
>>
>>         append_hf("P-hint: usrloc applied\r\n");
>>         route(1);
>> }
>>
>> route[1]
>> {
>>         # !! Nathelper
>>         if (uri=~"[@:](192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)" 
>> && !search("^Route:")){
>>             sl_send_reply("479", "We don't forward to private IP 
>> addresses");
>>             exit;
>>         };
>>
>>         # NAT processing of replies; apply to all transactions (for 
>> example,
>>         # re-INVITEs from public to private UA are hard to identify as
>>         # NATed at the moment of request processing); look at replies
>>         t_on_reply("1");
>>
>>     if ((src_ip!=ip.of.asterisk.1) && (src_ip!=ip.of.asterisk.2)) {
>>             ds_select_dst("1", "0");
>>         }
>>
>>         if (!t_relay()) {
>>                 sl_reply_error();
>>         };
>> }
>>
>> # !! Nathelper
>> onreply_route[1] {
>>     # NATed transaction ?
>>     if (isflagset(6) && status =~ "(183)|2[0-9][0-9]") {
>>         fix_nated_contact();
>>     # otherwise, is it a transaction behind a NAT and we did not
>>     # know at time of request processing ? (RFC1918 contacts)
>>     } else if (nat_uac_test("1")) {
>>         fix_nated_contact();
>>     };
>> }
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at openser.org
>> http://openser.org/cgi-bin/mailman/listinfo/users
> 
> 





More information about the Users mailing list