thank you for your answer.
I tried to catch the BYE with event_route[dialog:end] but I'm facing another problem.
When the timeout for the dialog is reached Kamailio correctly sends a BYE to the caller and to the callee but in the logs I see this:
DEBUG: dialog [dlg_timer.c:240]: start with tl=0x7f10937f0138 tl->prev=0x7f10937b4f20 tl->next=0x7f10937b4f20 (42641998) at 42641998 and end with end=0x7f10937b4f20
end->prev=0x7f10937f0138 end->next=0x7f10937f0138
DEBUG: dialog [dlg_timer.c:243]: getting tl=0x7f10937f0138 tl->prev=0x7f10937b4f20 tl->next=0x7f10937b4f20 with 42641998
DEBUG: dialog [dlg_timer.c:249]: end with tl=0x7f10937b4f20 tl->prev=0x7f10937f0138 tl->next=0x7f10937f0138 and d_timer->first.next->prev=(nil)
DEBUG: dialog [dlg_timer.c:282]: tl=0x7f10937f0138 next=(nil)
DEBUG: dialog [dlg_req_within.c:302]: sending BYE to caller
DEBUG: tm [uac.c:243]: DEBUG:tm:t_uac: next_hop=<sip:xxx@yyy.yyy.yyy.yyy:zzzz;transport=udp>
DEBUG: tm [uac.c:182]: DEBUG: dlg2hash: 343
DEBUG: dialog [dlg_req_within.c:323]: BYE sent to caller
DEBUG: dialog [dlg_req_within.c:302]: sending BYE to callee
DEBUG: tm [uac.c:243]: DEBUG:tm:t_uac: next_hop=<sip:xxx@yyy.yyy.yyy.yyy:zzzz;transport=udp>
DEBUG: tm [uac.c:182]: DEBUG: dlg2hash: 343
DEBUG: dialog [dlg_req_within.c:323]: BYE sent to callee
DEBUG: dialog [dlg_hash.c:735]: ref dlg 0x7f10937f00e0 with 1 -> 3
DEBUG: dialog [dlg_handlers.c:1474]: executing event_route 1 on state 5
DEBUG: dialog [dlg_hash.c:588]: ref dlg 0x7f10937f00e0 with 1 -> 4
DEBUG: dialog [dlg_hash.c:590]: dialog id=11591 found on entry 3289
DEBUG: dialog [dlg_hash.c:753]: unref dlg 0x7f10937f00e0 with 1 -> 3
DEBUG: dialog [dlg_hash.c:588]: ref dlg 0x7f10937f00e0 with 1 -> 4
DEBUG: dialog [dlg_hash.c:590]: dialog id=11591 found on entry 3289
DEBUG: dialog [dlg_hash.c:753]: unref dlg 0x7f10937f00e0 with 1 -> 3
DEBUG: <core> [parser/parse_to.c:799]: end of header reached, state=10
DEBUG: <core> [parser/msg_parser.c:190]: DEBUG: get_hdr_field: <To> [20]; uri=[
you@kamailio.org]
DEBUG: <core> [parser/msg_parser.c:192]: DEBUG: to body [<
you@kamailio.org>#015#012]
DEBUG: <core> [parser/parse_to.c:176]: DEBUG: add_param: tag=123
DEBUG: <core> [parser/parse_to.c:799]: end of header reached, state=29
DEBUG: <core> [parser/parse_uri.c:1292]: parse_uri: bad uri, state 0 parsed: <you@> (4) / <
you@kamailio.org> (16)
ERROR: <core> [parser/parse_from.c:113]: failed to parse From uri
ERROR: pv [pv_core.c:400]: cannot parse From URI
DEBUG: <core> [parser/parse_uri.c:1292]: parse_uri: bad uri, state 0 parsed: <you@> (4) / <
you@kamailio.org> (16)
ERROR: <core> [parser/parse_to.c:879]: failed to parse To uri
ERROR: pv [pv_core.c:394]: cannot parse To URI
INFO: <script>: event_route[dialog:end]: call-id=123 from=<null> to=<null> : (method= OPTIONS) :: dlg flag: 18446744073709551615 :: DLG_lifetime: <null>
The parser error problem seems to be related to the To and From headers of FAKED_SIP_MSG, defined in lib/kcore/faked_msg.c.
If I change those URIs adding "sip: " the pv error disappears but once entered the event_route[dialog:end]
As you can see, the $DLG_lifetime is <null> and we also have the message on the inconsistent dlg timer.
Probably there is something that I'm not understanding but why the event_route in this case is processing a "fake" OPTIONS message?
Another thing I noticed is that event_route[dialog:end] is not executed when a dialog is terminated by dlg_end_dlg or dlg_terminate_dlg fifo commands.
We really need to access the DLG_lifetime value in both cases (internal timeout or external command), any hint on how to do it?
Thank you in advance.