]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_table.c
Merge pull request #714 from opensourcerouting/cli_magic_defpy
[mirror_frr.git] / bgpd / bgp_table.c
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 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 "prefix.h"
24 #include "memory.h"
25 #include "sockunion.h"
26 #include "queue.h"
27 #include "filter.h"
28 #include "command.h"
29
30 #include "bgpd/bgpd.h"
31 #include "bgpd/bgp_table.h"
32
33 void
34 bgp_table_lock (struct bgp_table *rt)
35 {
36 rt->lock++;
37 }
38
39 void
40 bgp_table_unlock (struct bgp_table *rt)
41 {
42 assert (rt->lock > 0);
43 rt->lock--;
44
45 if (rt->lock != 0)
46 {
47 return;
48 }
49
50 route_table_finish (rt->route_table);
51 rt->route_table = NULL;
52
53 XFREE (MTYPE_BGP_TABLE, rt);
54 }
55
56 void
57 bgp_table_finish (struct bgp_table **rt)
58 {
59 if (*rt != NULL)
60 {
61 bgp_table_unlock(*rt);
62 *rt = NULL;
63 }
64 }
65
66 /*
67 * bgp_node_create
68 */
69 static struct route_node *
70 bgp_node_create (route_table_delegate_t *delegate, struct route_table *table)
71 {
72 struct bgp_node *node;
73 node = XCALLOC (MTYPE_BGP_NODE, sizeof (struct bgp_node));
74 return bgp_node_to_rnode (node);
75 }
76
77 /*
78 * bgp_node_destroy
79 */
80 static void
81 bgp_node_destroy (route_table_delegate_t *delegate,
82 struct route_table *table, struct route_node *node)
83 {
84 struct bgp_node *bgp_node;
85 bgp_node = bgp_node_from_rnode (node);
86 XFREE (MTYPE_BGP_NODE, bgp_node);
87 }
88
89 /*
90 * Function vector to customize the behavior of the route table
91 * library for BGP route tables.
92 */
93 route_table_delegate_t bgp_table_delegate = {
94 .create_node = bgp_node_create,
95 .destroy_node = bgp_node_destroy
96 };
97
98 /*
99 * bgp_table_init
100 */
101 struct bgp_table *
102 bgp_table_init (afi_t afi, safi_t safi)
103 {
104 struct bgp_table *rt;
105
106 rt = XCALLOC (MTYPE_BGP_TABLE, sizeof (struct bgp_table));
107
108 rt->route_table = route_table_init_with_delegate (&bgp_table_delegate);
109
110 /*
111 * Set up back pointer to bgp_table.
112 */
113 rt->route_table->info = rt;
114
115 bgp_table_lock (rt);
116 rt->afi = afi;
117 rt->safi = safi;
118
119 return rt;
120 }