Hi!
Tanks for the answer. subst() did work but obviously didn't solve the problem.
Below is the debug trace for the subst and a snippet from the used ser.cfg. As you can see, subst works good, but ser still stores xx@100.100.100.100 as aor. Maybe my regex isn't good enough? Maybe the approach is wrong at all if ser extracts the vital header information already before entering the routing script at all.
(IPs in the dumps are replaced, ser is 100.100.100.100, phone is 100.100.100.131, domain is mydomain.org)
0(8293) method: <REGISTER> 0(8293) uri: sip:100.100.100.100:5060 0(8293) version: <SIP/2.0> 0(8293) parse_headers: flags=1 0(8293) end of header reached, state=5 0(8293) parse_headers: Via found, flags=1 0(8293) parse_headers: this is the first via 0(8293) After parse_msg... 0(8293) preparing to run routing scripts... 0(8293) parse_headers: flags=128 0(8293) end of header reached, state=9 0(8293) DEBUG: get_hdr_field: <To> [48]; uri=[sip:31@100.100.100.100:5060] 0(8293) DEBUG: to body ["optiPoint 1 (31)" sip:31@100.100.100.100:5060 ] 0(8293) get_hdr_field: cseq <CSeq>: <2012717775> <REGISTER> 0(8293) DEBUG: get_hdr_body : content_length=0 0(8293) found end of header 0(8293) DEBUG: is_maxfwd_present: max_forwards header not found! 0(8293) parse_headers: flags=256 0(8293) find_first_route(): No Route headers found 0(8293) loose_route(): There is no Route HF 0(8293) grep_sock_info - checking if host==us: 13==13 && [100.100.100.100] == [100.100.100.100] 0(8293) grep_sock_info - checking if port 5060 matches port 5060 0(8293) grep_sock_info - checking if host==us: 13==13 && [100.100.100.100] == [100.100.100.100] 0(8293) grep_sock_info - checking if port 5060 matches port 5060 0(8293) #### Authenticate ### 0(8293) check_nonce(): comparing [4187b4fa25e5e432b9e0bd204a429446c2a3ae9b] and [4187b4fa0e8bde761be567ab9dd0f201ab31ab49] 0(8293) pre_auth(): Invalid nonce value received 0(8293) build_auth_hf(): 'WWW-Authenticate: Digest realm="mydomain.org", nonce="4187b536507484b10dcc87b97b7ee4866bf23601" ' 0(8293) parse_headers: flags=-1 0(8293) check_via_address(100.100.100.131, 100.100.100.131, 0) 0(8293) DEBUG:destroy_avp_list: destroying list (nil) 0(8293) receive_msg: cleaning up 0(8293) SIP Request: 0(8293) method: <REGISTER> 0(8293) uri: sip:100.100.100.100:5060 0(8293) version: <SIP/2.0> 0(8293) parse_headers: flags=1 0(8293) end of header reached, state=5 0(8293) parse_headers: Via found, flags=1 0(8293) parse_headers: this is the first via 0(8293) After parse_msg... 0(8293) preparing to run routing scripts... 0(8293) parse_headers: flags=128 0(8293) end of header reached, state=9 0(8293) DEBUG: get_hdr_field: <To> [48]; uri=[sip:31@100.100.100.100:5060] 0(8293) DEBUG: to body ["optiPoint 1 (31)" sip:31@100.100.100.100:5060 ] 0(8293) get_hdr_field: cseq <CSeq>: <2012717776> <REGISTER> 0(8293) DEBUG: get_hdr_body : content_length=0 0(8293) found end of header 0(8293) DEBUG: is_maxfwd_present: max_forwards header not found! 0(8293) parse_headers: flags=256 0(8293) find_first_route(): No Route headers found 0(8293) loose_route(): There is no Route HF 0(8293) grep_sock_info - checking if host==us: 13==13 && [100.100.100.100] == [100.100.100.100] 0(8293) grep_sock_info - checking if port 5060 matches port 5060 0(8293) grep_sock_info - checking if host==us: 13==13 && [100.100.100.100] == [100.100.100.100] 0(8293) grep_sock_info - checking if port 5060 matches port 5060 0(8293) #### Authenticate ### 0(8293) check_nonce(): comparing [4187b536507484b10dcc87b97b7ee4866bf23601] and [4187b536507484b10dcc87b97b7ee4866bf23601] 0(8293) HA1 string calculated: 6a3f36c88615ea8517a2806d05102e83 0(8293) check_response(): Our result = 'c8fd067f0bb9cdb7a4688cde18a5d3cb' 0(8293) check_response(): Authorization is OK 0(8293) save_rpid(): rpid value is '' 0(8293) subst_run: running. r=0 0(8293) subst_run: matched (60, 20): [sip:31@100.100.100.100] 0(8293) subst_run: running. r=0 0(8293) subst_run: matched (114, 20): [sip:31@100.100.100.100] 0(8293) subst_run: running. r=1 0(8293) textops: subst_f: replacing at offset 101 [sip:31@100.100.100.100] with [sip:31@mydomain.org] 0(8293) textops: subst_f: replacing at offset 155 [sip:31@100.100.100.100] with [sip:31@mydomain.org] 0(8293) subst_f: lst was 0x80fd498 0(8293) #### IP replaced! ### 0(8293) #### saving location ### 0(8293) parse_headers: flags=-1 0(8293) parse_headers: flags=33554432 0(8293) build_contact(): Created Contact HF: Contact: sip:31@100.100.100.131:5060;expires=90
0(8293) parse_headers: flags=-1 0(8293) check_via_address(100.100.100.131, 100.100.100.131, 0) 0(8293) #### break ### 0(8293) DEBUG:destroy_avp_list: destroying list (nil) 0(8293) receive_msg: cleaning up
snippet of ser.cfg:
if (uri==myself) {
if (method=="REGISTER") {
log (1, "#### Authenticate ###\n"); # Uncomment this if you want to use digest authentication if (!www_authorize("mydomain.org", "subscriber")) { www_challenge("mydomain.org", "0"); break; };
if ( subst('/sip:([^@]*)@100.100.100.100/sip:\1@mydomain.org/ig') ) { log (1, "#### IP replaced! ###\n"); };
log (1, "#### saving location ###\n"); save("location"); log (1, "#### break ###\n"); break; };
Hope someone can help me out of this one. Used version of ser is 0.8.99-dev12 (cvs checkout around 15:30 UTC on Nov 2 2004) Thanks.
Alex Mack.
Claus Futtrup wrote:
Hi Alex,
The subst() cannot fix the problem. If you use it to alter the To header, you will have to forward the message to your self to allow the modifications to take place (for each message SER keeps the original message and a list of changes which are applied only when sending out he message). Even if you modify the To hdr and spiral the message back to you, you will have to catch the reply to undo the modification on To - otherwise, the UAC will no be able to match the reply with the request it sent. And to be able to catch the reply you need to use tm, but you cannot do so because the transaction will be broken because of the modified To hdr. I hope my words make some sens to you :-).
there is a way, but very ugly and inefficient - try lookup using both forms user@ip and user@domain:
if (!lookup("location)) { # try to replace domain with IP or IP with domain if ( subst_uri("/(sip:.*@)mydomain.com(;.*)/\1xxx.xxx.xxx.xxx\2/") || subst_uri("/(sip:.*@)xxx.xxx.xxx(;.*).xxx/\1mydomain.com\2/") ) { if (!lookup("location")) { # not found } } }
I haven't test this, it's just an idea.
Best regards, Marian Dumitru
Alex Mack wrote:
Hi Marian!
You're right, that way IS very ugly. You also could leave out the "if"-clause completely: transform *every* request into "user@ip"-form rendering wrong requests only and transform those back to the correct form. That's not an approach, that's a proof of misconcept.
It can't be we're the only ones facing this problem. What does ser have included to handle malformed/wrong REGISTER-requests? It has to be able to mangle incoming REGISTER-requests beyond checking them. How can one control what ser is puting into 'aor'? There have to be more parameters for the save() function.
In the CVS one can see, that "use_domain" was removed for multi-domain capability, but there has to be implemented a feature to "alias" domains, e.g., all "100.100.100.100" are also "mydomain.org".
Best regards, Alex Mack.
Marian Dumitru wrote:
Hi Alex,
As I said, that was a very ugly solution.
The problem you are facing can be approached from two direction: 1) mangle the REGISTER - SER takes the aor from TO header, so you have to mangle it; but doing this will screw up badly the transaction matching (see my previous email). 2) try to fix it on lookup - try to do lookup both as user@ip and user@domain - but is the ugly solution.
Maybe doing code changing will help you. Something like having a "use_domain" parameter for registrar module which will force to ignore the domain part when building the aor.
Best regards, Marian Dumitru
Alex Mack wrote:
Hi Marian!
I'm already working on serdev mailinglist to bring back a solution like "use_domain 0" - it was dropped due to multi-domain capability. Now *every* lookup uses the complete aor to match.
The cleanest approach would be a change in the code since RFC 3261 (SIP) states clearly that an uri can also contain IPv4 numeric adresses instead of a host. So it's not a bug of the phones, instead ser has to handle that correctly.
Ciao, Alex.
Marian Dumitru wrote: