Line data Source code
1 : /* BGP routing table
2 : Copyright (C) 1998, 2001 Kunihiro Ishiguro
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
17 : along with GNU Zebra; see the file COPYING. If not, write to the Free
18 : Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 : 02111-1307, USA. */
20 :
21 : #include <zebra.h>
22 :
23 : #include "prefix.h"
24 : #include "memory.h"
25 : #include "sockunion.h"
26 : #include "vty.h"
27 :
28 : #include "bgpd/bgpd.h"
29 : #include "bgpd/bgp_table.h"
30 :
31 : void
32 72 : bgp_table_lock (struct bgp_table *rt)
33 : {
34 72 : rt->lock++;
35 72 : }
36 :
37 : void
38 24 : bgp_table_unlock (struct bgp_table *rt)
39 : {
40 24 : assert (rt->lock > 0);
41 24 : rt->lock--;
42 :
43 24 : if (rt->lock != 0)
44 : {
45 0 : return;
46 : }
47 :
48 24 : route_table_finish (rt->route_table);
49 24 : rt->route_table = NULL;
50 :
51 24 : if (rt->owner)
52 : {
53 0 : peer_unlock (rt->owner);
54 0 : rt->owner = NULL;
55 : }
56 :
57 24 : XFREE (MTYPE_BGP_TABLE, rt);
58 : }
59 :
60 : void
61 24 : bgp_table_finish (struct bgp_table **rt)
62 : {
63 24 : if (*rt != NULL)
64 : {
65 24 : bgp_table_unlock(*rt);
66 24 : *rt = NULL;
67 : }
68 24 : }
69 :
70 : /*
71 : * bgp_node_create
72 : */
73 : static struct route_node *
74 0 : bgp_node_create (route_table_delegate_t *delegate, struct route_table *table)
75 : {
76 : struct bgp_node *node;
77 0 : node = XCALLOC (MTYPE_BGP_NODE, sizeof (struct bgp_node));
78 0 : return bgp_node_to_rnode (node);
79 : }
80 :
81 : /*
82 : * bgp_node_destroy
83 : */
84 : static void
85 0 : bgp_node_destroy (route_table_delegate_t *delegate,
86 : struct route_table *table, struct route_node *node)
87 : {
88 : struct bgp_node *bgp_node;
89 0 : bgp_node = bgp_node_from_rnode (node);
90 0 : XFREE (MTYPE_BGP_NODE, bgp_node);
91 0 : }
92 :
93 : /*
94 : * Function vector to customize the behavior of the route table
95 : * library for BGP route tables.
96 : */
97 : route_table_delegate_t bgp_table_delegate = {
98 : .create_node = bgp_node_create,
99 : .destroy_node = bgp_node_destroy
100 : };
101 :
102 : /*
103 : * bgp_table_init
104 : */
105 : struct bgp_table *
106 72 : bgp_table_init (afi_t afi, safi_t safi)
107 : {
108 : struct bgp_table *rt;
109 :
110 72 : rt = XCALLOC (MTYPE_BGP_TABLE, sizeof (struct bgp_table));
111 :
112 72 : rt->route_table = route_table_init_with_delegate (&bgp_table_delegate);
113 :
114 : /*
115 : * Set up back pointer to bgp_table.
116 : */
117 72 : rt->route_table->info = rt;
118 :
119 72 : bgp_table_lock (rt);
120 72 : rt->type = BGP_TABLE_MAIN;
121 72 : rt->afi = afi;
122 72 : rt->safi = safi;
123 :
124 72 : return rt;
125 : }
|