Clean up IKE SPI resources if Create IKE is interrupted

This CL ensures IKE SPI resources are released if IKE Session
is terminated after Create IKE for IKE INIT or Rekey is sent
and before any response is received.

Without this fix, this is how SPI resources will get leaked
before caught by a CloseGuard:
- IKE enters CreateIkeLocalIkeInit and allocates an SPI
  for mLocalIkeSpiResource
- IkeSession#killSession or handleIkeFatalError is called;
  IKE state machine quits
- mLocalIkeSpiResource still holds the SPI resource until
  it is released by the CloseGuard

This will not be a problem for any functional code because it is
impossible to run out of IKE SPI values. However, for any tests
that are based on test-mode IKE and expect the IKE SPI to
always be a specific value, they may fail because the expected
SPI might be blocked by a previous test.

Bug: 357151634
Test: atest FrameworksIkeTests(new tests)
      atest CtsIkeTestCases
Flag: EXEMPT low risk bug fix
(cherry picked from https://android-review.googlesource.com/q/commit:7a1df1c43b5b8985e1da3a248c0c5204b71e4401)
Merged-In: I9059236989667ade113f844145f5813826cebf6a
Change-Id: I9059236989667ade113f844145f5813826cebf6a
7 files changed
tree: 3ecfb227b8f8eb159b3d5aa67d89b428e7ae1b12
  1. apex/
  2. api/
  3. flags/
  4. src/
  5. tests/
  6. Android.bp
  7. jarjar-rules-shared.txt
  8. jarjar-rules-test.txt
  9. lint-baseline.xml
  10. OWNERS
  11. PREUPLOAD.cfg
  12. README.md
  13. TEST_MAPPING
README.md

IKEv2 Library for Android

Introduction

This IKEv2 library is an in-process client library implementing the IKEv2 protocol as well as extensions necessary for the support of IWLAN. It is designed to work in a non-privileged fashion on top of the Android IPsec API surface.