back to topotato report
topotato coverage report
Current view: top level - ospf6d - ospf6_proto.c (source / functions) Hit Total Coverage
Test: test_ospf6_p2xp.py::PtMPBasic Lines: 36 50 72.0 %
Date: 2023-02-24 18:38:14 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2003 Yasuhiro Ohara
       3             :  *
       4             :  * This file is part of GNU Zebra.
       5             :  *
       6             :  * GNU Zebra is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by the
       8             :  * Free Software Foundation; either version 2, or (at your option) any
       9             :  * later version.
      10             :  *
      11             :  * GNU Zebra is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * 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             : #include <zebra.h>
      22             : 
      23             : #include "log.h"
      24             : 
      25             : #include "ospf6_proto.h"
      26             : 
      27         147 : void ospf6_prefix_in6_addr(struct in6_addr *in6, const void *prefix_buf,
      28             :                            const struct ospf6_prefix *p)
      29             : {
      30         147 :         ptrdiff_t in6_off = (caddr_t)p->addr - (caddr_t)prefix_buf;
      31             : 
      32         147 :         memset(in6, 0, sizeof(struct in6_addr));
      33         147 :         memcpy(in6, (uint8_t *)prefix_buf + in6_off,
      34         147 :                OSPF6_PREFIX_SPACE(p->prefix_length));
      35         147 : }
      36             : 
      37           0 : void ospf6_prefix_apply_mask(struct ospf6_prefix *op)
      38             : {
      39           0 :         uint8_t *pnt, mask;
      40           0 :         int index, offset;
      41             : 
      42           0 :         pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix));
      43           0 :         index = op->prefix_length / 8;
      44           0 :         offset = op->prefix_length % 8;
      45           0 :         mask = 0xff << (8 - offset);
      46             : 
      47           0 :         if (index > 16) {
      48           0 :                 zlog_warn("Prefix length too long: %d", op->prefix_length);
      49           0 :                 return;
      50             :         }
      51             : 
      52             :         /* nonzero mask means no check for this byte because if it contains
      53             :          * prefix bits it must be there for us to write */
      54           0 :         if (mask)
      55           0 :                 pnt[index++] &= mask;
      56             : 
      57           0 :         while (index < OSPF6_PREFIX_SPACE(op->prefix_length))
      58           0 :                 pnt[index++] = 0;
      59             : }
      60             : 
      61         481 : void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size)
      62             : {
      63         481 :         const char *dn, *p, *mc, *la, *nu;
      64             : 
      65         481 :         dn = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_DN) ? "DN" : "--");
      66         481 :         p = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_P) ? "P" : "--");
      67         481 :         mc = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_MC) ? "MC" : "--");
      68         481 :         la = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_LA) ? "LA" : "--");
      69         481 :         nu = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_NU) ? "NU" : "--");
      70         481 :         snprintf(buf, size, "%s|%s|%s|%s|%s", dn, p, mc, la, nu);
      71         481 : }
      72             : 
      73         292 : void ospf6_capability_printbuf(char capability, char *buf, int size)
      74             : {
      75         292 :         char w, v, e, b;
      76         292 :         w = (capability & OSPF6_ROUTER_BIT_W ? 'W' : '-');
      77         292 :         v = (capability & OSPF6_ROUTER_BIT_V ? 'V' : '-');
      78         292 :         e = (capability & OSPF6_ROUTER_BIT_E ? 'E' : '-');
      79         292 :         b = (capability & OSPF6_ROUTER_BIT_B ? 'B' : '-');
      80         292 :         snprintf(buf, size, "----%c%c%c%c", w, v, e, b);
      81         292 : }
      82             : 
      83         587 : void ospf6_options_printbuf(uint8_t *options, char *buf, int size)
      84             : {
      85         587 :         const char *dc, *r, *n, *mc, *e, *v6, *af, *at, *l;
      86         587 :         dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--");
      87         587 :         r = (OSPF6_OPT_ISSET(options, OSPF6_OPT_R) ? "R" : "-");
      88         587 :         n = (OSPF6_OPT_ISSET(options, OSPF6_OPT_N) ? "N" : "-");
      89         587 :         mc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_MC) ? "MC" : "--");
      90         587 :         e = (OSPF6_OPT_ISSET(options, OSPF6_OPT_E) ? "E" : "-");
      91         587 :         v6 = (OSPF6_OPT_ISSET(options, OSPF6_OPT_V6) ? "V6" : "--");
      92         587 :         af = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AF) ? "AF" : "--");
      93         587 :         at = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AT) ? "AT" : "--");
      94         587 :         l = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_L) ? "L" : "-");
      95         587 :         snprintf(buf, size, "%s|%s|%s|-|-|%s|%s|%s|%s|%s|%s", at, l, af, dc, r,
      96             :                  n, mc, e, v6);
      97         587 : }

Generated by: LCOV version v1.16-topotato