From: Tobias Brunner Date: Wed, 8 Jun 2016 14:06:53 +0000 (+0200) Subject: ipsec: Add function to compare two ipsec_sa_cfg_t instances X-Git-Tag: 5.5.0dr1~36^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c1290510366dc8c0dea4202f24dc1e01198aefe;p=thirdparty%2Fstrongswan.git ipsec: Add function to compare two ipsec_sa_cfg_t instances memeq() is currently used to compare these but if there is padding that is not initialized the same for two instances the comparison fails. Using this function ensures the objects are compared correctly. --- diff --git a/src/libstrongswan/ipsec/ipsec_types.c b/src/libstrongswan/ipsec/ipsec_types.c index f2ee11ee85..a52a1eb517 100644 --- a/src/libstrongswan/ipsec/ipsec_types.c +++ b/src/libstrongswan/ipsec/ipsec_types.c @@ -37,6 +37,22 @@ ENUM(ipcomp_transform_names, IPCOMP_NONE, IPCOMP_LZJH, "IPCOMP_LZJH" ); +/* + * See header + */ +bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t *a, ipsec_sa_cfg_t *b) +{ + return a->mode == b->mode && + a->reqid == b->reqid && + a->policy_count == b->policy_count && + a->esp.use == b->esp.use && + a->esp.spi == b->esp.spi && + a->ah.use == b->ah.use && + a->ah.spi == b->ah.spi && + a->ipcomp.transform == b->ipcomp.transform && + a->ipcomp.cpi == b->ipcomp.cpi; +} + /* * See header */ diff --git a/src/libstrongswan/ipsec/ipsec_types.h b/src/libstrongswan/ipsec/ipsec_types.h index cbc0d089b2..c93d955622 100644 --- a/src/libstrongswan/ipsec/ipsec_types.h +++ b/src/libstrongswan/ipsec/ipsec_types.h @@ -142,6 +142,15 @@ struct ipsec_sa_cfg_t { } ipcomp; }; +/** + * Compare two ipsec_sa_cfg_t objects for equality. + * + * @param a first object + * @param b second object + * @return TRUE if both objects are equal + */ +bool ipsec_sa_cfg_equals(ipsec_sa_cfg_t *a, ipsec_sa_cfg_t *b); + /** * A lifetime_cfg_t defines the lifetime limits of an SA. *