]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-netlink: When adding a policy do an update if it already exists
authorTobias Brunner <tobias@strongswan.org>
Wed, 3 Jun 2015 15:31:30 +0000 (17:31 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 13 Aug 2015 08:49:16 +0000 (10:49 +0200)
This may be the case when SAs are reestablished after a crash of the
IKE daemon.

We could actually always do updates.  The kernel doesn't care, the only
difference is the possible EEXIST if XFRM_MSG_NEWPOLICY is used.  The
advantage of not doing this, though, is that we get a warning in the log
if a policy already exists, as that should usually not be the case.

src/libhydra/plugins/kernel_netlink/kernel_netlink_ipsec.c

index e0f1dd70299ccfdf1850f6f398e2f9fe52ae077f..2958b59426c9f5bc4928a46a70033166615b63f5 100644 (file)
@@ -2059,6 +2059,7 @@ static status_t add_policy_internal(private_kernel_netlink_ipsec_t *this,
        ipsec_sa_t *ipsec = mapping->sa;
        struct xfrm_userpolicy_info *policy_info;
        struct nlmsghdr *hdr;
+       status_t status;
        int i;
 
        /* clone the policy so we are able to check it out again later */
@@ -2153,7 +2154,14 @@ static status_t add_policy_internal(private_kernel_netlink_ipsec_t *this,
        }
        this->mutex->unlock(this->mutex);
 
-       if (this->socket_xfrm->send_ack(this->socket_xfrm, hdr) != SUCCESS)
+       status = this->socket_xfrm->send_ack(this->socket_xfrm, hdr);
+       if (status == ALREADY_DONE && !update)
+       {
+               DBG1(DBG_KNL, "policy already exists, try to update it");
+               hdr->nlmsg_type = XFRM_MSG_UPDPOLICY;
+               status = this->socket_xfrm->send_ack(this->socket_xfrm, hdr);
+       }
+       if (status != SUCCESS)
        {
                return FAILED;
        }