+// 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
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "lib/network.h"
+
#include "babel_main.h"
#include "babeld.h"
#include "util.h"
else if(value <= 1)
return value;
else
- return value * 3 / 4 + random() % (value / 2);
+ return value * 3 / 4 + frr_weak_random() % (value / 2);
}
/* d = s1 - s2 */
{
if(d->tv_sec == 0 || d->tv_sec > secs) {
d->tv_sec = secs;
- d->tv_usec = random() % 1000000;
+ d->tv_usec = frr_weak_random() % 1000000;
}
}
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);
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;
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