]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/network.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / network.c
index d2482bd55e7e53bc96c1ad2f1e5c56238c282a7f..af1c7db443e90cf5cb179e2a4ee461e409d8da7b 100644 (file)
@@ -1,22 +1,7 @@
+// 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>
@@ -78,7 +63,8 @@ int set_nonblocking(int fd)
        /* 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));
@@ -122,20 +108,23 @@ float ntohf(float net)
        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();
 }