[Swan-dev] libswan: ip_endpoint.c: endpoint_eq(): simplify

Andrew Cagney andrew.cagney at gmail.com
Wed Dec 30 00:18:48 UTC 2020


Shorter? Yes.
Simpler? No.

        const struct ip_info *lt = address_type(l);
        const struct ip_info *rt = address_type(r);
-       if (lt == NULL || rt == NULL) {
-               /* AF_UNSPEC/NULL are never equal; think NaN */
-               return false;
-       }
-       if (lt != rt) {
-               return false;
-       }
-       if (l->hport != r->hport) {
-               return false;
-       }
-       if (!memeq(&l->bytes, &r->bytes, sizeof(l->bytes))) {
-               return false;
-       }
-       if (l->ipproto != 0 && r->ipproto != 0 &&
-           l->ipproto != r->ipproto) {
-               return false;
-       }
-       if (l->ipproto == 0 || r->ipproto == 0) {
-               dbg("endpoint fuzzy ipproto match");
-       }
-       return true;
+       return
+               lt == rt &&
+               lt != NULL &&   /* AF_UNSPEC/NULL are never equal */
+               l->hport == r->hport &&
+               memeq(&l->bytes, &r->bytes, sizeof(l->bytes)) &&
+               ( l->ipproto == 0 || r->ipproto == 0 ||
+                 l->ipproto == r->ipproto );


On Tue, 29 Dec 2020 at 18:15, D. Hugh Redelmeier
<hugh at vault.libreswan.fi> wrote:
>
> New commits:
> commit 826c11f4f0834abde7812302239f9ca0b71c9834
> Author: D. Hugh Redelmeier <hugh at mimosa.com>
> Date:   Tue Dec 29 18:14:37 2020 -0500
>
>     libswan: ip_endpoint.c: endpoint_eq(): simplify
>
> _______________________________________________
> Swan-commit mailing list
> Swan-commit at lists.libreswan.org
> https://lists.libreswan.org/mailman/listinfo/swan-commit


More information about the Swan-dev mailing list