ripng_route.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include "prefix.h"
  24. #include "table.h"
  25. #include "memory.h"
  26. #include "if.h"
  27. #include "vty.h"
  28. #include "ripngd/ripngd.h"
  29. #include "ripngd/ripng_route.h"
  30. static struct ripng_aggregate *
  31. ripng_aggregate_new ()
  32. {
  33. struct ripng_aggregate *new;
  34. new = XCALLOC (MTYPE_RIPNG_AGGREGATE, sizeof (struct ripng_aggregate));
  35. return new;
  36. }
  37. void
  38. ripng_aggregate_free (struct ripng_aggregate *aggregate)
  39. {
  40. XFREE (MTYPE_RIPNG_AGGREGATE, aggregate);
  41. }
  42. /* Aggregate count increment check. */
  43. void
  44. ripng_aggregate_increment (struct route_node *child, struct ripng_info *rinfo)
  45. {
  46. struct route_node *np;
  47. struct ripng_aggregate *aggregate;
  48. for (np = child; np; np = np->parent)
  49. if ((aggregate = np->aggregate) != NULL)
  50. {
  51. aggregate->count++;
  52. rinfo->suppress++;
  53. }
  54. }
  55. /* Aggregate count decrement check. */
  56. void
  57. ripng_aggregate_decrement (struct route_node *child, struct ripng_info *rinfo)
  58. {
  59. struct route_node *np;
  60. struct ripng_aggregate *aggregate;
  61. for (np = child; np; np = np->parent)
  62. if ((aggregate = np->aggregate) != NULL)
  63. {
  64. aggregate->count--;
  65. rinfo->suppress--;
  66. }
  67. }
  68. /* Aggregate count decrement check for a list. */
  69. void
  70. ripng_aggregate_decrement_list (struct route_node *child, struct list *list)
  71. {
  72. struct route_node *np;
  73. struct ripng_aggregate *aggregate;
  74. struct ripng_info *rinfo = NULL;
  75. struct listnode *node = NULL;
  76. for (np = child; np; np = np->parent)
  77. if ((aggregate = np->aggregate) != NULL)
  78. aggregate->count -= listcount (list);
  79. for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
  80. rinfo->suppress--;
  81. }
  82. /* RIPng routes treatment. */
  83. int
  84. ripng_aggregate_add (struct prefix *p)
  85. {
  86. struct route_node *top;
  87. struct route_node *rp;
  88. struct ripng_info *rinfo;
  89. struct ripng_aggregate *aggregate;
  90. struct ripng_aggregate *sub;
  91. struct list *list = NULL;
  92. struct listnode *node = NULL;
  93. /* Get top node for aggregation. */
  94. top = route_node_get (ripng->table, p);
  95. /* Allocate new aggregate. */
  96. aggregate = ripng_aggregate_new ();
  97. aggregate->metric = 1;
  98. top->aggregate = aggregate;
  99. /* Suppress routes match to the aggregate. */
  100. for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
  101. {
  102. /* Suppress normal route. */
  103. if ((list = rp->info) != NULL)
  104. for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
  105. {
  106. aggregate->count++;
  107. rinfo->suppress++;
  108. }
  109. /* Suppress aggregate route. This may not need. */
  110. if (rp != top && (sub = rp->aggregate) != NULL)
  111. {
  112. aggregate->count++;
  113. sub->suppress++;
  114. }
  115. }
  116. return 0;
  117. }
  118. /* Delete RIPng static route. */
  119. int
  120. ripng_aggregate_delete (struct prefix *p)
  121. {
  122. struct route_node *top;
  123. struct route_node *rp;
  124. struct ripng_info *rinfo;
  125. struct ripng_aggregate *aggregate;
  126. struct ripng_aggregate *sub;
  127. struct list *list = NULL;
  128. struct listnode *node = NULL;
  129. /* Get top node for aggregation. */
  130. top = route_node_get (ripng->table, p);
  131. /* Allocate new aggregate. */
  132. aggregate = top->aggregate;
  133. /* Suppress routes match to the aggregate. */
  134. for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top))
  135. {
  136. /* Suppress normal route. */
  137. if ((list = rp->info) != NULL)
  138. for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
  139. {
  140. aggregate->count--;
  141. rinfo->suppress--;
  142. }
  143. if (rp != top && (sub = rp->aggregate) != NULL)
  144. {
  145. aggregate->count--;
  146. sub->suppress--;
  147. }
  148. }
  149. top->aggregate = NULL;
  150. ripng_aggregate_free (aggregate);
  151. route_unlock_node (top);
  152. route_unlock_node (top);
  153. return 0;
  154. }