{"action":"created","issue":{"url":"https://api.github.com/repos/kamailio/kamailio/issues/280","labels_url":"https://api.github.com/repos/kamailio/kamailio/issues/280/labels{/name}","comments_url":"https://api.github.com/repos/kamailio/kamailio/issues/280/comments","events_url":"https://api.github.com/repos/kamailio/kamailio/issues/280/events","html_url":"https://github.com/kamailio/kamailio/issues/280","id":99506499,"number":280,"title":"Kamailio not compatible with registration refresh by lax UAs","user":{"login":"benlangfeld","id":210221,"avatar_url":"https://avatars.githubusercontent.com/u/210221?v=3","gravatar_id":"","url":"https://api.github.com/users/benlangfeld","html_url":"https://github.com/benlangfeld","followers_url":"https://api.github.com/users/benlangfeld/followers","following_url":"https://api.github.com/users/benlangfeld/following{/other_user}","gists_url":"https://api.github.com/users/benlangfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/benlangfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benlangfeld/subscriptions","organizations_url":"https://api.github.com/users/benlangfeld/orgs","repos_url":"https://api.github.com/users/benlangfeld/repos","events_url":"https://api.github.com/users/benlangfeld/events{/privacy}","received_events_url":"https://api.github.com/users/benlangfeld/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-08-06T19:21:26Z","updated_at":"2015-08-07T13:57:47Z","closed_at":null,"body":"First, a spec reference: https://tools.ietf.org/html/rfc3261#section-10.2.4\r\n\r\n> A UA SHOULD use the same Call-ID for all registrations during a single boot cycle.\r\n\r\nOn the surface is is then reasonable for Kamailio to default to contact lookup by contact and Call-ID. It does, however, [default to contact only lookup](http://kamailio.org/docs/modules/4.2.x/modules/usrloc.html#usrloc.p.matching_mode).\r\n\r\nIn a repeat registration scenario like this:\r\n\r\n~15:32:28\r\n```\r\nREGISTER sip:ben-test.callix.com.br SIP/2.0\r\nCall-ID: aa26998a7a2648a6243a11eda51a3aa6@172.31.31.221\r\nCSeq: 2 REGISTER\r\nFrom: <sip:destination_007@ben-test.callix.com.br>;tag=61616278_117e27da_7c77d0dd_13a609f6-c985-463b-b43f-ac43090d221e\r\nTo: <sip:destination_007@ben-test.callix.com.br>\r\nMax-Forwards: 70\r\nContact: <sip:destination_007@172.31.31.221:5080>\r\nUser-Agent: Callix/Click2Call\r\nExpires: 180\r\nVia: SIP/2.0/UDP chandler.localdomain:5080;branch=z9hG4bK13a609f6-c985-463b-b43f-ac43090d221e_7c77d0dd_e6dd0acb-255f-4c1c-afe6-67a360a7f581\r\nAuthorization: Digest username=\"destination_007\",realm=\"ben-test.callix.com.br\",nonce=\"VcItt1XCLIsaLIdqq1Uo9wYmRIbpfQhP\",uri=\"sip:ben-test.callix.com.br\",response=\"0a014dd4613deb4b89fc9457d43d5cee\"\r\nRoute: <sip:registrar.oneclick.callix.com.br;lr>\r\nContent-Length: 0\r\n\r\nSIP/2.0 200 OK\r\nCall-ID: aa26998a7a2648a6243a11eda51a3aa6@172.31.31.221\r\nCSeq: 2 REGISTER\r\nFrom: <sip:destination_007@ben-test.callix.com.br>;tag=61616278_117e27da_7c77d0dd_13a609f6-c985-463b-b43f-ac43090d221e\r\nTo: <sip:destination_007@ben-test.callix.com.br>;tag=b27e1a1d33761e85846fc98f5f3a7e58.73ee\r\nVia: SIP/2.0/UDP chandler.localdomain:5080;branch=z9hG4bK13a609f6-c985-463b-b43f-ac43090d221e_7c77d0dd_e6dd0acb-255f-4c1c-afe6-67a360a7f581;received=172.31.31.221\r\nContact: <sip:destination_007@172.31.31.221:5080>;expires=180\r\nSupported: outbound\r\nServer: kamailio (4.1.6 (x86_64/linux))\r\nContent-Length: 0\r\n```\r\n\r\n~15:34:28\r\n\r\n```\r\nREGISTER sip:ben-test.callix.com.br SIP/2.0\r\nCall-ID: d6a13584901f0336dd9f877f125f1574@172.31.31.221\r\nCSeq: 2 REGISTER\r\nFrom: <sip:destination_007@ben-test.callix.com.br>;tag=10060555_117e27da_7c77d0dd_13a609f6-c985-463b-b43f-ac43090d221e\r\nTo: <sip:destination_007@ben-test.callix.com.br>\r\nMax-Forwards: 70\r\nContact: <sip:destination_007@172.31.31.221:5080>\r\nUser-Agent: Callix/Click2Call\r\nExpires: 180\r\nVia: SIP/2.0/UDP chandler.localdomain:5080;branch=z9hG4bK13a609f6-c985-463b-b43f-ac43090d221e_7c77d0dd_4c667124-f13e-4bae-b637-4f19472bd417\r\nAuthorization: Digest username=\"destination_007\",realm=\"ben-test.callix.com.br\",nonce=\"VcIuMFXCLQQbB0Z4Q92WkVEu4iM2wjU3\",uri=\"sip:ben-test.callix.com.br\",response=\"8161b70052e50a5e3f51a843080c1eac\"\r\nRoute: <sip:registrar.oneclick.callix.com.br;lr>\r\nContent-Length: 0\r\n\r\nSIP/2.0 200 OK\r\nCall-ID: d6a13584901f0336dd9f877f125f1574@172.31.31.221\r\nCSeq: 2 REGISTER\r\nFrom: <sip:destination_007@ben-test.callix.com.br>;tag=10060555_117e27da_7c77d0dd_13a609f6-c985-463b-b43f-ac43090d221e\r\nTo: <sip:destination_007@ben-test.callix.com.br>;tag=b27e1a1d33761e85846fc98f5f3a7e58.6229\r\nVia: SIP/2.0/UDP chandler.localdomain:5080;branch=z9hG4bK13a609f6-c985-463b-b43f-ac43090d221e_7c77d0dd_4c667124-f13e-4bae-b637-4f19472bd417;received=172.31.31.221\r\nContact: <sip:destination_007@172.31.31.221:5080>;expires=180\r\nSupported: outbound\r\nServer: kamailio (4.1.6 (x86_64/linux))\r\nContent-Length: 0\r\n```\r\n\r\nI see the following queries in the Kamailio logs:\r\n\r\n```\r\nAug  5 15:32:28 lexington /usr/sbin/kamailio[12366]: DEBUG: db_postgres [km_dbase.c:230]: db_postgres_submit_query(): sending query ok: 0x7fc5155669a0 (1) - [insert into location (username,contact,expires,q,callid,cseq,flags,cflags,user_agent,received,path,socket,methods,last_modified,ruid,instance,reg_id,domain ) values ('destination_007','sip:destination_007@172.31.31.221:5080','2015-08-05 15:35:28',-1.00     ,'aa26998a7a2648a6243a11eda51a3aa6@172.31.31.221',2,0,0,'Callix/Click2Call',NULL,NULL,'udp:172.31.26.82:5060',NULL,'2015-08-05 15:32:28','uloc-55c220c7-304e-96',NULL,0,'ben-test.callix.com.br')]\r\n\r\nAug  5 15:34:28 lexington /usr/sbin/kamailio[12364]: DEBUG: db_postgres [km_dbase.c:230]: db_postgres_submit_query(): sending query ok: 0x7fc5155669a0 (2) - [select contact,expires,q,callid,cseq,flags,cflags,user_agent,received,path,socket,methods,last_modified,ruid,instance,reg_id from location where username='destination_007' AND domain='ben-test.callix.com.br' order by q]\r\n\r\nAug  5 15:34:28 lexington /usr/sbin/kamailio[12364]: DEBUG: db_postgres [km_dbase.c:230]: db_postgres_submit_query(): sending query ok: 0x7fc5155669a0 (1) - [update location set expires='2015-08-05 15:37:28',q=-1.00     ,cseq=2,flags=0,cflags=0,user_agent='Callix/Click2Call',received=NULL,path=NULL,socket='udp:172.31.26.82:5060',methods=NULL,last_modified='2015-08-05 15:34:28',ruid='uloc-55c220c7-304e-96',instance=NULL,reg_id=0,contact='sip:destination_007@172.31.31.221:5080' where username='destination_007' AND contact='sip:destination_007@172.31.31.221:5080' AND callid='d6a13584901f0336dd9f877f125f1574@172.31.31.221' AND domain='ben-test.callix.com.br']\r\n```\r\n\r\nEvidently the contact-only nature of usrloc lookup is not being respected when a follow-up registration is attempted. This means that every pre-expiry registration for a static contact from a UA which does not comply with RFC3621's normative `SHOULD` will silently fail. This is not a big deal; most do comply and I could fix mine to comply.\r\n\r\nWhat is a bigger deal is that if the UA is restarted, it is not to be reasonably expected to maintain the same CallID. It will use a new CallID (precisely the same way as my \"faulty\" UA does) on its first registration. If this occurs while there is an active registration for the same Contact, this new registration will effectively be ignored.\r\n\r\nI *think*, though I'm likely to be corrected, that we should only be including the CallID in the UPDATE's WHERE clause if we used it in the SELECT and got a result. In my \"faulty\" UA case, this would at least leave me with duplicate registrations rather than 0 registrations. I could then follow the normative `SHOULD` and eliminate the duplication.\r\n\r\nCaveat that I have only tested with usrloc's `dbmode` parameter as `3`. I am using Postgres."},"comment":{"url":"https://api.github.com/repos/kamailio/kamailio/issues/comments/128706816","html_url":"https://github.com/kamailio/kamailio/issues/280#issuecomment-128706816","issue_url":"https://api.github.com/repos/kamailio/kamailio/issues/280","id":128706816,"user":{"login":"linuxmaniac","id":63080,"avatar_url":"https://avatars.githubusercontent.com/u/63080?v=3","gravatar_id":"","url":"https://api.github.com/users/linuxmaniac","html_url":"https://github.com/linuxmaniac","followers_url":"https://api.github.com/users/linuxmaniac/followers","following_url":"https://api.github.com/users/linuxmaniac/following{/other_user}","gists_url":"https://api.github.com/users/linuxmaniac/gists{/gist_id}","starred_url":"https://api.github.com/users/linuxmaniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linuxmaniac/subscriptions","organizations_url":"https://api.github.com/users/linuxmaniac/orgs","repos_url":"https://api.github.com/users/linuxmaniac/repos","events_url":"https://api.github.com/users/linuxmaniac/events{/privacy}","received_events_url":"https://api.github.com/users/linuxmaniac/received_events","type":"User","site_admin":false},"created_at":"2015-08-07T13:57:47Z","updated_at":"2015-08-07T13:57:47Z","body":"I fixed that!\r\n56b54a5767a3ad0df446fe181aee0ee5fd64276d\r\ne8a795a6a413ae453f619e3deaf36c26b85b0077"}}