back to topotato report
topotato coverage report
Current view: top level - bgpd/rfapi - rfapi_nve_addr.c (source / functions) Hit Total Coverage
Test: test_exabgp_demo.py::ExaBGPDemo Lines: 0 38 0.0 %
Date: 2023-02-24 18:37:55 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2009-2016, LabN Consulting, L.L.C.
       4             :  *
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU General Public License
       8             :  * as published by the Free Software Foundation; either version 2
       9             :  * of the License, or (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with this program; see the file COPYING; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : 
      22             : #include "lib/zebra.h"
      23             : #include "lib/prefix.h"
      24             : #include "lib/agg_table.h"
      25             : #include "lib/vty.h"
      26             : #include "lib/memory.h"
      27             : #include "lib/skiplist.h"
      28             : 
      29             : 
      30             : #include "bgpd/bgpd.h"
      31             : 
      32             : #include "bgpd/rfapi/bgp_rfapi_cfg.h"
      33             : #include "bgpd/rfapi/rfapi.h"
      34             : #include "bgpd/rfapi/rfapi_backend.h"
      35             : 
      36             : #include "bgpd/rfapi/rfapi_import.h"
      37             : #include "bgpd/rfapi/rfapi_private.h"
      38             : #include "bgpd/rfapi/rfapi_nve_addr.h"
      39             : #include "bgpd/rfapi/rfapi_vty.h"
      40             : #include "bgpd/rfapi/vnc_debug.h"
      41             : 
      42             : #define DEBUG_NVE_ADDR 0
      43             : 
      44             : void rfapiNveAddr2Str(struct rfapi_nve_addr *, char *, int);
      45             : 
      46             : 
      47             : #if DEBUG_NVE_ADDR
      48             : static void logdifferent(const char *tag, struct rfapi_nve_addr *a,
      49             :                          struct rfapi_nve_addr *b)
      50             : {
      51             :         char a_str[BUFSIZ];
      52             :         char b_str[BUFSIZ];
      53             : 
      54             :         rfapiNveAddr2Str(a, a_str, BUFSIZ);
      55             :         rfapiNveAddr2Str(b, b_str, BUFSIZ);
      56             :         vnc_zlog_debug_verbose("%s: [%s] [%s]", tag, a_str, b_str);
      57             : }
      58             : #endif
      59             : 
      60             : 
      61           0 : int rfapi_nve_addr_cmp(const void *k1, const void *k2)
      62             : {
      63           0 :         const struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1;
      64           0 :         const struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2;
      65           0 :         int ret = 0;
      66             : 
      67           0 :         if (!a || !b) {
      68             : #if DEBUG_NVE_ADDR
      69             :                 vnc_zlog_debug_verbose("%s: missing address a=%p b=%p",
      70             :                                        __func__, a, b);
      71             : #endif
      72           0 :                 return (a - b);
      73             :         }
      74           0 :         if (a->un.addr_family != b->un.addr_family) {
      75             : #if DEBUG_NVE_ADDR
      76             :                 vnc_zlog_debug_verbose(
      77             :                         "diff: UN addr fam a->un.af=%d, b->un.af=%d",
      78             :                         a->un.addr_family, b->un.addr_family);
      79             : #endif
      80           0 :                 return (a->un.addr_family - b->un.addr_family);
      81             :         }
      82           0 :         if (a->un.addr_family == AF_INET) {
      83           0 :                 ret = IPV4_ADDR_CMP(&a->un.addr.v4, &b->un.addr.v4);
      84           0 :                 if (ret != 0) {
      85             : #if DEBUG_NVE_ADDR
      86             :                         logdifferent("diff: UN addr", a, b);
      87             : #endif
      88             :                         return ret;
      89             :                 }
      90           0 :         } else if (a->un.addr_family == AF_INET6) {
      91           0 :                 ret = IPV6_ADDR_CMP(&a->un.addr.v6, &b->un.addr.v6);
      92           0 :                 if (ret == 0) {
      93             : #if DEBUG_NVE_ADDR
      94             :                         logdifferent("diff: UN addr", a, b);
      95             : #endif
      96             :                         return ret;
      97             :                 }
      98             :         } else {
      99           0 :                 assert(0);
     100             :         }
     101           0 :         if (a->vn.addr_family != b->vn.addr_family) {
     102             : #if DEBUG_NVE_ADDR
     103             :                 vnc_zlog_debug_verbose(
     104             :                         "diff: pT addr fam a->vn.af=%d, b->vn.af=%d",
     105             :                         a->vn.addr_family, b->vn.addr_family);
     106             : #endif
     107           0 :                 return (a->vn.addr_family - b->vn.addr_family);
     108             :         }
     109           0 :         if (a->vn.addr_family == AF_INET) {
     110           0 :                 ret = IPV4_ADDR_CMP(&a->vn.addr.v4, &b->vn.addr.v4);
     111           0 :                 if (ret != 0) {
     112             : #if DEBUG_NVE_ADDR
     113             :                         logdifferent("diff: VN addr", a, b);
     114             : #endif
     115             :                         return ret;
     116             :                 }
     117           0 :         } else if (a->vn.addr_family == AF_INET6) {
     118           0 :                 ret = IPV6_ADDR_CMP(&a->vn.addr.v6, &b->vn.addr.v6);
     119             :                 if (ret == 0) {
     120             : #if DEBUG_NVE_ADDR
     121             :                         logdifferent("diff: VN addr", a, b);
     122             : #endif
     123             :                         return ret;
     124             :                 }
     125             :         } else {
     126           0 :                 assert(0);
     127             :         }
     128             :         return 0;
     129             : }
     130             : 
     131           0 : void rfapiNveAddr2Str(struct rfapi_nve_addr *na, char *buf, int bufsize)
     132             : {
     133           0 :         char *p = buf;
     134           0 :         int r;
     135             : 
     136             : #define REMAIN (bufsize - (p-buf))
     137             : #define INCP {p += (r > REMAIN)? REMAIN: r;}
     138             : 
     139           0 :         if (bufsize < 1)
     140             :                 return;
     141             : 
     142           0 :         r = snprintf(p, REMAIN, "VN=");
     143           0 :         INCP;
     144             : 
     145           0 :         if (!rfapiRfapiIpAddr2Str(&na->vn, p, REMAIN))
     146           0 :                 goto done;
     147             : 
     148           0 :         buf[bufsize - 1] = 0;
     149           0 :         p = buf + strlen(buf);
     150             : 
     151           0 :         r = snprintf(p, REMAIN, ", UN=");
     152           0 :         INCP;
     153             : 
     154           0 :         rfapiRfapiIpAddr2Str(&na->un, p, REMAIN);
     155             : 
     156           0 : done:
     157           0 :         buf[bufsize - 1] = 0;
     158             : }

Generated by: LCOV version v1.16-topotato