back to topotato report
topotato coverage report
Current view: top level - ripngd - ripng_route.c (source / functions) Hit Total Coverage
Test: aggregated run ( view descriptions ) Lines: 7 79 8.9 %
Date: 2023-02-24 19:38:44 Functions: 3 8 37.5 %

          Line data    Source code
       1             : /*
       2             :  * RIPng routes function.
       3             :  * Copyright (C) 1998 Kunihiro Ishiguro
       4             :  *
       5             :  * This file is part of GNU Zebra.
       6             :  *
       7             :  * GNU Zebra is free software; you can redistribute it and/or modify it
       8             :  * under the terms of the GNU General Public License as published by the
       9             :  * Free Software Foundation; either version 2, or (at your option) any
      10             :  * later version.
      11             :  *
      12             :  * GNU Zebra is distributed in the hope that it will be useful, but
      13             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU General Public License along
      18             :  * with this program; see the file COPYING; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include <zebra.h>
      23             : 
      24             : #include "prefix.h"
      25             : #include "agg_table.h"
      26             : #include "memory.h"
      27             : #include "if.h"
      28             : #include "vty.h"
      29             : 
      30             : #include "ripngd/ripngd.h"
      31             : #include "ripngd/ripng_route.h"
      32             : 
      33           3 : DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_AGGREGATE, "RIPng aggregate");
      34             : 
      35           0 : static struct ripng_aggregate *ripng_aggregate_new(void)
      36             : {
      37           0 :         struct ripng_aggregate *new;
      38             : 
      39           0 :         new = XCALLOC(MTYPE_RIPNG_AGGREGATE, sizeof(struct ripng_aggregate));
      40           0 :         return new;
      41             : }
      42             : 
      43           0 : void ripng_aggregate_free(struct ripng_aggregate *aggregate)
      44             : {
      45           0 :         XFREE(MTYPE_RIPNG_AGGREGATE, aggregate);
      46           0 : }
      47             : 
      48             : /* Aggregate count increment check. */
      49           1 : void ripng_aggregate_increment(struct agg_node *child, struct ripng_info *rinfo)
      50             : {
      51           1 :         struct agg_node *np;
      52           1 :         struct ripng_aggregate *aggregate;
      53             : 
      54           2 :         for (np = child; np; np = agg_node_parent(np))
      55           1 :                 if ((aggregate = np->aggregate) != NULL) {
      56           0 :                         aggregate->count++;
      57           0 :                         rinfo->suppress++;
      58             :                 }
      59           1 : }
      60             : 
      61             : /* Aggregate count decrement check. */
      62           0 : void ripng_aggregate_decrement(struct agg_node *child, struct ripng_info *rinfo)
      63             : {
      64           0 :         struct agg_node *np;
      65           0 :         struct ripng_aggregate *aggregate;
      66             : 
      67           0 :         for (np = child; np; np = agg_node_parent(np))
      68           0 :                 if ((aggregate = np->aggregate) != NULL) {
      69           0 :                         aggregate->count--;
      70           0 :                         rinfo->suppress--;
      71             :                 }
      72           0 : }
      73             : 
      74             : /* Aggregate count decrement check for a list. */
      75           0 : void ripng_aggregate_decrement_list(struct agg_node *child, struct list *list)
      76             : {
      77           0 :         struct agg_node *np;
      78           0 :         struct ripng_aggregate *aggregate;
      79           0 :         struct ripng_info *rinfo = NULL;
      80           0 :         struct listnode *node = NULL;
      81             : 
      82           0 :         for (np = child; np; np = agg_node_parent(np))
      83           0 :                 if ((aggregate = np->aggregate) != NULL)
      84           0 :                         aggregate->count -= listcount(list);
      85             : 
      86           0 :         for (ALL_LIST_ELEMENTS_RO(list, node, rinfo))
      87           0 :                 rinfo->suppress--;
      88           0 : }
      89             : 
      90             : /* RIPng routes treatment. */
      91           0 : int ripng_aggregate_add(struct ripng *ripng, struct prefix *p)
      92             : {
      93           0 :         struct agg_node *top;
      94           0 :         struct agg_node *rp;
      95           0 :         struct ripng_info *rinfo;
      96           0 :         struct ripng_aggregate *aggregate;
      97           0 :         struct ripng_aggregate *sub;
      98           0 :         struct list *list = NULL;
      99           0 :         struct listnode *node = NULL;
     100             : 
     101             :         /* Get top node for aggregation. */
     102           0 :         top = agg_node_get(ripng->table, p);
     103             : 
     104             :         /* Allocate new aggregate. */
     105           0 :         aggregate = ripng_aggregate_new();
     106           0 :         aggregate->metric = 1;
     107             : 
     108           0 :         top->aggregate = aggregate;
     109             : 
     110             :         /* Suppress routes match to the aggregate. */
     111           0 :         for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
     112             :                 /* Suppress normal route. */
     113           0 :                 if ((list = rp->info) != NULL)
     114           0 :                         for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
     115           0 :                                 aggregate->count++;
     116           0 :                                 rinfo->suppress++;
     117             :                         }
     118             :                 /* Suppress aggregate route.  This may not need. */
     119           0 :                 if (rp != top && (sub = rp->aggregate) != NULL) {
     120           0 :                         aggregate->count++;
     121           0 :                         sub->suppress++;
     122             :                 }
     123             :         }
     124             : 
     125           0 :         return 0;
     126             : }
     127             : 
     128             : /* Delete RIPng static route. */
     129           0 : int ripng_aggregate_delete(struct ripng *ripng, struct prefix *p)
     130             : {
     131           0 :         struct agg_node *top;
     132           0 :         struct agg_node *rp;
     133           0 :         struct ripng_info *rinfo;
     134           0 :         struct ripng_aggregate *aggregate;
     135           0 :         struct ripng_aggregate *sub;
     136           0 :         struct list *list = NULL;
     137           0 :         struct listnode *node = NULL;
     138             : 
     139             :         /* Get top node for aggregation. */
     140           0 :         top = agg_node_get(ripng->table, p);
     141             : 
     142             :         /* Allocate new aggregate. */
     143           0 :         aggregate = top->aggregate;
     144             : 
     145             :         /* Suppress routes match to the aggregate. */
     146           0 :         for (rp = agg_lock_node(top); rp; rp = agg_route_next_until(rp, top)) {
     147             :                 /* Suppress normal route. */
     148           0 :                 if ((list = rp->info) != NULL)
     149           0 :                         for (ALL_LIST_ELEMENTS_RO(list, node, rinfo)) {
     150           0 :                                 aggregate->count--;
     151           0 :                                 rinfo->suppress--;
     152             :                         }
     153             : 
     154           0 :                 if (rp != top && (sub = rp->aggregate) != NULL) {
     155           0 :                         aggregate->count--;
     156           0 :                         sub->suppress--;
     157             :                 }
     158             :         }
     159             : 
     160           0 :         top->aggregate = NULL;
     161           0 :         ripng_aggregate_free(aggregate);
     162             : 
     163           0 :         agg_unlock_node(top);
     164           0 :         agg_unlock_node(top);
     165             : 
     166           0 :         return 0;
     167             : }

Generated by: LCOV version v1.16-topotato