I had same problem - with BYE also.
My "go around" was (replaced name of domain and IP of kamailio):
route[ACKBYE] {
#!ifdef WITH_MYFORWARD
if(($sht(forw=>$ft))=~$td){
$du=$sht(forw=>$ft);
}else
if((($td=="name.of.company.com")||($td=="ip"))&&($si=="ip")){
$du=$sht(forw=>$ft);
return;
}
#!endif
return;
}
route[PSTNINVITE] {
#!ifdef WITH_MYFORWARD
if(is_method("INVITE")){
ds_select_dst("1","4");
$sht(forw=>$ft)=$du;
sl_send_reply("100","Trying");
route(RELAY);
exit();
}
#!endif
return;
}
Meaning - during invite, I store du (to allow more then one Asterisk behind
kamailio)
and on ACK or BYE - I check td and si. Not sure I am correct, but it works
from long time, although load is not high.
PS
You will need to set in the beginning
modparam("htable", "htable",
"forw=>size=8;autoexpire=7200;")
and you need to put routes in proper places.