Two iked(8) instances sometimes get of sync after rekeying their SAs,
which breaks the IPsec tunnel until the daemons are restarted.
One reason for this seems to be that when one peer succeeds
rekeying the IKE SA while the other is waiting for a response to a Child SA
rekey exchange, the first can no longer decrypt and answer the
Child SA request (because it is encrypted for the old SA).
The diff prevents iked(8) from replying to IKE SA rekey request
while it is waiting for a Child SA response.
Another symptom of this behaviour is that sometimes an iked tries to rekey a
Child SA that the other has lost track of, resulting in a
CHILD_SA_NOT_FOUND notify. The second diff adds a handler for this notify type
so that it no longer waits for a Child SA rekeying reply after receiving
CHILD_SA_NOT_FOUND.
Ok?
Index: ikev2.c
===================================================================
RCS file: /mount/openbsd/cvs/src/sbin/iked/ikev2.c,v
retrieving revision 1.168
diff -u -p -u -r1.168 ikev2.c
--- ikev2.c 27 Feb 2019 06:33:56 -0000 1.168
+++ ikev2.c 1 Aug 2019 08:42:35 -0000
@@ -3637,6 +3637,15 @@ ikev2_resp_create_child_sa(struct iked *
print_map(protoid, ikev2_saproto_map));
if (protoid == IKEV2_SAPROTO_IKE) {
+ if ((sa->sa_stateflags & IKED_REQ_CHILDSA)
+ && !(sa->sa_nexti)) {
+ log_debug("%s: Ignore IKE SA rekey: waiting for Child "
+ "SA response.", __func__);
+ /* Ignore, don't send error */
+ msg->msg_valid = 0;
+ return (0);
+ }
+
/* IKE SA rekeying */
spi = &msg->msg_prop->prop_peerspi;
Index: ikev2_pld.c
===================================================================
RCS file: /mount/openbsd/cvs/src/sbin/iked/ikev2_pld.c,v
retrieving revision 1.70
diff -u -p -u -r1.70 ikev2_pld.c
--- ikev2_pld.c 22 Mar 2018 21:11:49 -0000 1.70
+++ ikev2_pld.c 1 Aug 2019 08:39:25 -0000
@@ -1170,6 +1170,15 @@ ikev2_pld_notify(struct iked *env, struc
msg->msg_sa->sa_cpi_out = betoh16(cpi);
}
break;
+ case IKEV2_N_CHILD_SA_NOT_FOUND:
+ if (!msg->msg_e) {
+ log_debug("%s: N_CHILD_SA_NOT_FOUND not encrypted",
+ __func__);
+ return (-1);
+ }
+ /* Stop expecting response */
+ msg->msg_sa->sa_stateflags &= ~IKED_REQ_CHILDSA;
+ break;
case IKEV2_N_MOBIKE_SUPPORTED:
if (!msg->msg_e) {
log_debug("%s: N_MOBIKE_SUPPORTED not encrypted",