+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Network library.
* Copyright (C) 1997 Kunihiro Ishiguro
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
/* According to the Single UNIX Spec, the return value for F_GETFL
should
never be negative. */
- if ((flags = fcntl(fd, F_GETFL)) < 0) {
+ flags = fcntl(fd, F_GETFL);
+ if (flags < 0) {
flog_err(EC_LIB_SYSTEM_CALL,
"fcntl(F_GETFL) failed for fd %d: %s", fd,
safe_strerror(errno));
return htonf(net);
}
-/**
- * Helper function that returns a random long value. The main purpose of
- * this function is to hide a `random()` call that gets flagged by coverity
- * scan and put it into one place.
- *
- * The main usage of this function should be for generating jitter or weak
- * random values for simple purposes.
- *
- * See 'man 3 random' for more information.
- *
- * \returns random long integer.
- */
-long frr_weak_random(void)
+uint64_t frr_sequence_next(void)
+{
+ static uint64_t last_sequence;
+ struct timespec ts;
+
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (last_sequence == (uint64_t)ts.tv_sec) {
+ last_sequence++;
+ return last_sequence;
+ }
+
+ last_sequence = ts.tv_sec;
+ return last_sequence;
+}
+
+uint32_t frr_sequence32_next(void)
{
- /* coverity[dont_call] */
- return random();
+ /* coverity[Y2K38_SAFETY] */
+ return (uint32_t)frr_sequence_next();
}