back to topotato report
topotato coverage report
Current view: top level - ripd - rip_offset.c (source / functions) Hit Total Coverage
Test: test_rip.py::RIPBasic Lines: 21 68 30.9 %
Date: 2023-02-24 18:39:46 Functions: 5 9 55.6 %

          Line data    Source code
       1             : /* RIP offset-list
       2             :  * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
       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 "if.h"
      24             : #include "prefix.h"
      25             : #include "filter.h"
      26             : #include "command.h"
      27             : #include "linklist.h"
      28             : #include "memory.h"
      29             : 
      30             : #include "ripd/ripd.h"
      31             : 
      32          12 : DEFINE_MTYPE_STATIC(RIPD, RIP_OFFSET_LIST, "RIP offset list");
      33             : 
      34             : #define OFFSET_LIST_IN_NAME(O)  ((O)->direct[RIP_OFFSET_LIST_IN].alist_name)
      35             : #define OFFSET_LIST_IN_METRIC(O)  ((O)->direct[RIP_OFFSET_LIST_IN].metric)
      36             : 
      37             : #define OFFSET_LIST_OUT_NAME(O)  ((O)->direct[RIP_OFFSET_LIST_OUT].alist_name)
      38             : #define OFFSET_LIST_OUT_METRIC(O)  ((O)->direct[RIP_OFFSET_LIST_OUT].metric)
      39             : 
      40           0 : struct rip_offset_list *rip_offset_list_new(struct rip *rip, const char *ifname)
      41             : {
      42           0 :         struct rip_offset_list *offset;
      43             : 
      44           0 :         offset = XCALLOC(MTYPE_RIP_OFFSET_LIST, sizeof(struct rip_offset_list));
      45           0 :         offset->rip = rip;
      46           0 :         offset->ifname = strdup(ifname);
      47           0 :         listnode_add_sort(rip->offset_list_master, offset);
      48             : 
      49           0 :         return offset;
      50             : }
      51             : 
      52           0 : void offset_list_del(struct rip_offset_list *offset)
      53             : {
      54           0 :         listnode_delete(offset->rip->offset_list_master, offset);
      55           0 :         offset_list_free(offset);
      56           0 : }
      57             : 
      58           0 : void offset_list_free(struct rip_offset_list *offset)
      59             : {
      60           0 :         if (OFFSET_LIST_IN_NAME(offset))
      61           0 :                 free(OFFSET_LIST_IN_NAME(offset));
      62           0 :         if (OFFSET_LIST_OUT_NAME(offset))
      63           0 :                 free(OFFSET_LIST_OUT_NAME(offset));
      64           0 :         free(offset->ifname);
      65           0 :         XFREE(MTYPE_RIP_OFFSET_LIST, offset);
      66           0 : }
      67             : 
      68          68 : struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
      69             :                                                const char *ifname)
      70             : {
      71          68 :         struct rip_offset_list *offset;
      72          68 :         struct listnode *node, *nnode;
      73             : 
      74         136 :         for (ALL_LIST_ELEMENTS(rip->offset_list_master, node, nnode, offset)) {
      75           0 :                 if (strcmp(offset->ifname, ifname) == 0)
      76           0 :                         return offset;
      77             :         }
      78             :         return NULL;
      79             : }
      80             : 
      81             : /* If metric is modified return 1. */
      82          17 : int rip_offset_list_apply_in(struct prefix_ipv4 *p, struct interface *ifp,
      83             :                              uint32_t *metric)
      84             : {
      85          17 :         struct rip_interface *ri = ifp->info;
      86          17 :         struct rip_offset_list *offset;
      87          17 :         struct access_list *alist;
      88             : 
      89             :         /* Look up offset-list with interface name. */
      90          17 :         offset = rip_offset_list_lookup(ri->rip, ifp->name);
      91          17 :         if (offset && OFFSET_LIST_IN_NAME(offset)) {
      92           0 :                 alist = access_list_lookup(AFI_IP, OFFSET_LIST_IN_NAME(offset));
      93             : 
      94           0 :                 if (alist
      95           0 :                     && access_list_apply(alist, (struct prefix *)p)
      96             :                                == FILTER_PERMIT) {
      97           0 :                         *metric += OFFSET_LIST_IN_METRIC(offset);
      98           0 :                         return 1;
      99             :                 }
     100           0 :                 return 0;
     101             :         }
     102             :         /* Look up offset-list without interface name. */
     103          17 :         offset = rip_offset_list_lookup(ri->rip, "*");
     104          17 :         if (offset && OFFSET_LIST_IN_NAME(offset)) {
     105           0 :                 alist = access_list_lookup(AFI_IP, OFFSET_LIST_IN_NAME(offset));
     106             : 
     107           0 :                 if (alist
     108           0 :                     && access_list_apply(alist, (struct prefix *)p)
     109             :                                == FILTER_PERMIT) {
     110           0 :                         *metric += OFFSET_LIST_IN_METRIC(offset);
     111           0 :                         return 1;
     112             :                 }
     113           0 :                 return 0;
     114             :         }
     115             :         return 0;
     116             : }
     117             : 
     118             : /* If metric is modified return 1. */
     119          17 : int rip_offset_list_apply_out(struct prefix_ipv4 *p, struct interface *ifp,
     120             :                               uint32_t *metric)
     121             : {
     122          17 :         struct rip_interface *ri = ifp->info;
     123          17 :         struct rip_offset_list *offset;
     124          17 :         struct access_list *alist;
     125             : 
     126             :         /* Look up offset-list with interface name. */
     127          17 :         offset = rip_offset_list_lookup(ri->rip, ifp->name);
     128          17 :         if (offset && OFFSET_LIST_OUT_NAME(offset)) {
     129           0 :                 alist = access_list_lookup(AFI_IP,
     130             :                                            OFFSET_LIST_OUT_NAME(offset));
     131             : 
     132           0 :                 if (alist
     133           0 :                     && access_list_apply(alist, (struct prefix *)p)
     134             :                                == FILTER_PERMIT) {
     135           0 :                         *metric += OFFSET_LIST_OUT_METRIC(offset);
     136           0 :                         return 1;
     137             :                 }
     138           0 :                 return 0;
     139             :         }
     140             : 
     141             :         /* Look up offset-list without interface name. */
     142          17 :         offset = rip_offset_list_lookup(ri->rip, "*");
     143          17 :         if (offset && OFFSET_LIST_OUT_NAME(offset)) {
     144           0 :                 alist = access_list_lookup(AFI_IP,
     145             :                                            OFFSET_LIST_OUT_NAME(offset));
     146             : 
     147           0 :                 if (alist
     148           0 :                     && access_list_apply(alist, (struct prefix *)p)
     149             :                                == FILTER_PERMIT) {
     150           0 :                         *metric += OFFSET_LIST_OUT_METRIC(offset);
     151           0 :                         return 1;
     152             :                 }
     153           0 :                 return 0;
     154             :         }
     155             :         return 0;
     156             : }
     157             : 
     158           0 : int offset_list_cmp(struct rip_offset_list *o1, struct rip_offset_list *o2)
     159             : {
     160           0 :         return strcmp(o1->ifname, o2->ifname);
     161             : }

Generated by: LCOV version v1.16-topotato