<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Paul,<div class=""><br class=""></div><div class="">thanks for sharing the state machine. Now I understnad what is going on. I see in logs following sequence:</div><div class=""><br class=""></div><div class=""><font face="Courier New" style="font-size: 12px;" class="">00:12:59 no rekeying on traffic selector override connection</font></div><div class=""><font face="Courier New" style="font-size: 12px;" class="">00:17:29 deleting state (STATE_QUICK_R2) aged 3600.122s and sending notification</font></div><div class=""><span style="font-family: "Courier New"; font-size: 12px;" class="">00:17:29 ESP traffic information in=513KB out=745KB</span></div><div class=""><span style="font-family: "Courier New"; font-size: 12px;" class="">00:17:44 terminating SAa using this connection</span></div><div class=""><span style="font-size: 12px;" class=""><span style="font-family: "Courier New";" class="">00:17:44 </span><span style="font-family: "Courier New";" class="">deleting state (STATE_MAIN_R3) aged 7228.122s </span><span style="font-family: "Courier New";" class="">and sending notification</span></span></div><div class=""><span style="font-family: "Courier New"; font-size: 12px;" class="">00:17:44 added connection description "xxxx"</span></div><div class=""><span style="font-family: "Courier New"; font-size: 12px;" class="">00:17:44 listening for IKE messages</span></div><div class=""><span style="font-family: "Courier New"; font-size: 12px;" class="">00:17:44 forgetting secrets</span></div><div class=""><br class=""></div><div class="">The VPN is established between Oracle OCI and Azure. I'm not sure which technology is ued by Oracle OCI, but it look like Libreswan. I received information from partner operating Azure that they have bug in SA lifetime configuration for IKEv1; provided setting is ignored and they always use value of 27000 s. It's not compatible with OCI side configuration of 3600 s. OCI side expects to renegotiate phase 2 after 1h, waits 15 seconds for this to happen (17:29 - 17:44) and gives up. Whole connection is destroyed and recreated. It's noticed by Azure. Finally as Azure as the Initiator (OCI is the responder what is even visible in states *_R*) tries to recreate the VPN. It's done with success after 5 minutes.</div><div class=""><br class=""></div><div class="">Mystery solved. 15 seconds timeout may be custom tuning at OCI implementation.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Ryszard</div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 9 Apr 2021, at 03:22, Paul Wouters <<a href="mailto:paul@nohats.ca" class="">paul@nohats.ca</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Thu, 8 Apr 2021, Ryszard Styczynski wrote:<br class=""><br class=""><blockquote type="cite" class="">I'm looking for IPsec state machine implemented in Libreswan. I may guess how states are correlated, but having a state machine will give me a final answer.<br class=""></blockquote><br class="">For IKEv1, the state machine is in programs/pluto/ikev1.c<br class=""><br class=""><blockquote type="cite" class="">My current question is what is a next state after STATE_QUICK_R2? Should IPsec engine wait for rekeying? How long? How many times should repeat waiting step? Should go back to STATE_MAIN and delete SA? When?<br class=""><br class="">I currently see i my system that:<br class="">1. STATE_QUICK_R2 may go to STATE_MAIN_R3, delete SA, and reestablish connection from Phase 1 - it happens after 15 seconds<br class="">2. STATE_QUICK_R2 may go to STATE_QUICK_R1 and process rekeying - it happens when peer responds quicker than 15 seconds<br class=""><br class="">How to understand why sometimes SA is deleted (what causes 5 minutes line drop), and sometimes rekeying is completed? How to control time limits?<br class=""></blockquote><br class="">A proper exchange looks like:<br class=""><br class="">paul@thinkpad:~/libreswan.git/testing/pluto/basic-pluto-01 (main=)$ grep STATE_ OUTPUT/east.pluto.log  |grep transition<br class="">| IKEv1: transition from state STATE_MAIN_R0 to state STATE_MAIN_R1<br class="">| IKEv1: transition from state STATE_MAIN_R1 to state STATE_MAIN_R2<br class="">| IKEv1: transition from state STATE_MAIN_R2 to state STATE_MAIN_R3<br class="">| IKEv1: transition from state STATE_QUICK_R0 to state STATE_QUICK_R1<br class="">| IKEv1: transition from state STATE_QUICK_R1 to state STATE_QUICK_R2<br class=""><br class="">Nothing should really happen after 15 seconds, so perhaps you should<br class="">show us your logs to see what is happening?<br class=""><br class="">Paul<br class=""></div></div></blockquote></div><br class=""></div></body></html>