bgp_table.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* BGP routing table
  2. Copyright (C) 1998, 2001 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #include <zebra.h>
  17. #include "prefix.h"
  18. #include "memory.h"
  19. #include "sockunion.h"
  20. #include "vty.h"
  21. #include "filter.h"
  22. #include "bgpd/bgpd.h"
  23. #include "bgpd/bgp_table.h"
  24. void
  25. bgp_table_lock (struct bgp_table *rt)
  26. {
  27. rt->lock++;
  28. }
  29. void
  30. bgp_table_unlock (struct bgp_table *rt)
  31. {
  32. assert (rt->lock > 0);
  33. rt->lock--;
  34. if (rt->lock != 0)
  35. {
  36. return;
  37. }
  38. route_table_finish (rt->route_table);
  39. rt->route_table = NULL;
  40. if (rt->owner)
  41. {
  42. peer_unlock (rt->owner);
  43. rt->owner = NULL;
  44. }
  45. XFREE (MTYPE_BGP_TABLE, rt);
  46. }
  47. void
  48. bgp_table_finish (struct bgp_table **rt)
  49. {
  50. if (*rt != NULL)
  51. {
  52. bgp_table_unlock(*rt);
  53. *rt = NULL;
  54. }
  55. }
  56. /*
  57. * bgp_node_create
  58. */
  59. static struct route_node *
  60. bgp_node_create (route_table_delegate_t *delegate, struct route_table *table)
  61. {
  62. struct bgp_node *node;
  63. node = XCALLOC (MTYPE_BGP_NODE, sizeof (struct bgp_node));
  64. return bgp_node_to_rnode (node);
  65. }
  66. /*
  67. * bgp_node_destroy
  68. */
  69. static void
  70. bgp_node_destroy (route_table_delegate_t *delegate,
  71. struct route_table *table, struct route_node *node)
  72. {
  73. struct bgp_node *bgp_node;
  74. bgp_node = bgp_node_from_rnode (node);
  75. XFREE (MTYPE_BGP_NODE, bgp_node);
  76. }
  77. /*
  78. * Function vector to customize the behavior of the route table
  79. * library for BGP route tables.
  80. */
  81. route_table_delegate_t bgp_table_delegate = {
  82. .create_node = bgp_node_create,
  83. .destroy_node = bgp_node_destroy
  84. };
  85. /*
  86. * bgp_table_init
  87. */
  88. struct bgp_table *
  89. bgp_table_init (afi_t afi, safi_t safi)
  90. {
  91. struct bgp_table *rt;
  92. rt = XCALLOC (MTYPE_BGP_TABLE, sizeof (struct bgp_table));
  93. rt->route_table = route_table_init_with_delegate (&bgp_table_delegate);
  94. /*
  95. * Set up back pointer to bgp_table.
  96. */
  97. rt->route_table->info = rt;
  98. bgp_table_lock (rt);
  99. rt->type = BGP_TABLE_MAIN;
  100. rt->afi = afi;
  101. rt->safi = safi;
  102. return rt;
  103. }