]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/util.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / ldpd / util.c
index e735263f5fdcd316cb575ce10756286ccf206edd..85ba25c7707b5a9def847050368f295ba8ffb94b 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: ISC
 /*     $OpenBSD$ */
 
 /*
@@ -5,18 +6,6 @@
  * Copyright (c) 2012 Alexander Bluhm <bluhm@openbsd.org>
  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
 #include <zebra.h>
@@ -182,7 +171,7 @@ ldp_prefixcmp(int af, const union ldpd_addr *a, const union ldpd_addr *b,
        case AF_INET:
                if (prefixlen == 0)
                        return (0);
-               if (prefixlen > 32)
+               if (prefixlen > IPV4_MAX_BITLEN)
                        fatalx("ldp_prefixcmp: bad IPv4 prefixlen");
                mask = htonl(prefixlen2mask(prefixlen));
                aa = htonl(a->v4.s_addr) & mask;
@@ -191,7 +180,7 @@ ldp_prefixcmp(int af, const union ldpd_addr *a, const union ldpd_addr *b,
        case AF_INET6:
                if (prefixlen == 0)
                        return (0);
-               if (prefixlen > 128)
+               if (prefixlen > IPV6_MAX_BITLEN)
                        fatalx("ldp_prefixcmp: bad IPv6 prefixlen");
                for (i = 0; i < prefixlen / 8; i++)
                        if (a->v6.s6_addr[i] != b->v6.s6_addr[i])
@@ -259,7 +248,7 @@ embedscope(struct sockaddr_in6 *sin6)
        if (IN6_IS_SCOPE_EMBED(&sin6->sin6_addr)) {
                memcpy(&tmp16, &sin6->sin6_addr.s6_addr[2], sizeof(tmp16));
                if (tmp16 != 0) {
-                       log_warnx("%s: address %s already has embeded scope %u",
+                       log_warnx("%s: address %s already has embedded scope %u",
                            __func__, log_sockaddr(sin6), ntohs(tmp16));
                }
                tmp16 = htons(sin6->sin6_scope_id);
@@ -305,14 +294,13 @@ clearscope(struct in6_addr *in6)
        }
 }
 
-struct sockaddr *
-addr2sa(int af, union ldpd_addr *addr, uint16_t port)
+void
+addr2sa(int af, const union ldpd_addr *addr, uint16_t port, union sockunion *su)
 {
-       static struct sockaddr_storage   ss;
-       struct sockaddr_in              *sa_in = (struct sockaddr_in *)&ss;
-       struct sockaddr_in6             *sa_in6 = (struct sockaddr_in6 *)&ss;
+       struct sockaddr_in              *sa_in = &su->sin;
+       struct sockaddr_in6             *sa_in6 = &su->sin6;
 
-       memset(&ss, 0, sizeof(ss));
+       memset(su, 0, sizeof(*su));
        switch (af) {
        case AF_INET:
                sa_in->sin_family = AF_INET;
@@ -333,8 +321,6 @@ addr2sa(int af, union ldpd_addr *addr, uint16_t port)
        default:
                fatalx("addr2sa: unknown af");
        }
-
-       return ((struct sockaddr *)&ss);
 }
 
 void