]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/util.c
Merge pull request #13206 from opensourcerouting/fix/docker_build_alpine_protobuf
[mirror_frr.git] / babeld / util.c
index e99bd861dc87697114f640e22192bbc4c9b86905..4facdabbc6e34deb3fbfc90f2f89d989267ad9ce 100644 (file)
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: MIT
 /*
 Copyright (c) 2007, 2008 by Juliusz Chroboczek
 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
 */
 
 #ifdef HAVE_CONFIG_H
@@ -216,33 +199,13 @@ parse_nat(const char *string)
     return (int)l;
 }
 
-int
-in_prefix(const unsigned char *restrict address,
-          const unsigned char *restrict prefix, unsigned char plen)
-{
-    unsigned char m;
-
-    if(plen > 128)
-        plen = 128;
-
-    if(memcmp(address, prefix, plen / 8) != 0)
-        return 0;
-
-    if(plen % 8 == 0)
-        return 1;
-
-    m = 0xFF << (8 - (plen % 8));
-
-    return ((address[plen / 8] & m) == (prefix[plen / 8] & m));
-}
-
 unsigned char *
 mask_prefix(unsigned char *restrict ret,
             const unsigned char *restrict prefix, unsigned char plen)
 {
-    if(plen >= 128) {
-        memcpy(ret, prefix, 16);
-        return ret;
+       if (plen >= IPV6_MAX_BITLEN) {
+               memcpy(ret, prefix, IPV6_MAX_BYTELEN);
+               return ret;
     }
 
     memset(ret, 0, 16);
@@ -329,9 +292,10 @@ parse_address(const char *address, unsigned char *addr_r, int *af_r)
 
     rc = inet_pton(AF_INET6, address, &ina6);
     if(rc > 0) {
-        memcpy(addr_r, &ina6, 16);
-        if(af_r) *af_r = AF_INET6;
-        return 0;
+           memcpy(addr_r, &ina6, IPV6_MAX_BYTELEN);
+           if (af_r)
+                   *af_r = AF_INET6;
+           return 0;
     }
 
     return -1;
@@ -433,13 +397,13 @@ uchar_to_inaddr(struct in_addr *dest, const unsigned char *src)
 void
 in6addr_to_uchar(unsigned char *dest, const struct in6_addr *src)
 {
-    memcpy(dest, src, 16);
+       memcpy(dest, src, IPV6_MAX_BYTELEN);
 }
 
 void
 uchar_to_in6addr(struct in6_addr *dest, const unsigned char *src)
 {
-    memcpy(dest, src, 16);
+       memcpy(dest, src, IPV6_MAX_BYTELEN);
 }
 
 int