]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/vnc_export_table.c
tests: Enhance error msgs for static route auto.
[mirror_frr.git] / bgpd / rfapi / vnc_export_table.c
1 /*
2 *
3 * Copyright 2009-2016, LabN Consulting, L.L.C.
4 *
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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
22 #include "lib/zebra.h"
23 #include "lib/prefix.h"
24 #include "lib/agg_table.h"
25 #include "lib/memory.h"
26 #include "lib/vty.h"
27
28 #include "bgpd/bgpd.h"
29 #include "bgpd/bgp_route.h"
30
31 #include "bgpd/rfapi/vnc_export_table.h"
32 #include "bgpd/rfapi/rfapi_private.h"
33 #include "bgpd/rfapi/rfapi_import.h"
34 #include "bgpd/rfapi/vnc_debug.h"
35
36 struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type,
37 const struct prefix *p)
38 {
39 struct agg_table *t = NULL;
40 struct agg_node *rn = NULL;
41 afi_t afi;
42
43 if (!bgp || !bgp->rfapi)
44 return NULL;
45
46 afi = family2afi(p->family);
47 assert(afi == AFI_IP || afi == AFI_IP6);
48
49 switch (type) {
50 case EXPORT_TYPE_BGP:
51 if (!bgp->rfapi->rt_export_bgp[afi])
52 bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
53 t = bgp->rfapi->rt_export_bgp[afi];
54 break;
55
56 case EXPORT_TYPE_ZEBRA:
57 if (!bgp->rfapi->rt_export_zebra[afi])
58 bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
59 t = bgp->rfapi->rt_export_zebra[afi];
60 break;
61 }
62
63 if (t)
64 rn = agg_node_get(t, p);
65 return rn;
66 }
67
68 struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type,
69 const struct prefix *p)
70 {
71 struct agg_table *t = NULL;
72 struct agg_node *rn = NULL;
73 afi_t afi;
74
75 if (!bgp || !bgp->rfapi)
76 return NULL;
77
78 afi = family2afi(p->family);
79 assert(afi == AFI_IP || afi == AFI_IP6);
80
81 switch (type) {
82 case EXPORT_TYPE_BGP:
83 if (!bgp->rfapi->rt_export_bgp[afi])
84 bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
85 t = bgp->rfapi->rt_export_bgp[afi];
86 break;
87
88 case EXPORT_TYPE_ZEBRA:
89 if (!bgp->rfapi->rt_export_zebra[afi])
90 bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
91 t = bgp->rfapi->rt_export_zebra[afi];
92 break;
93 }
94
95 if (t)
96 rn = agg_node_lookup(t, p);
97 return rn;
98 }
99
100 struct vnc_export_info *vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype,
101 const struct prefix *p, struct peer *peer,
102 uint8_t type, uint8_t subtype)
103 {
104 struct agg_node *etn;
105 struct vnc_export_info *eti;
106
107 etn = vnc_etn_get(bgp, etype, p);
108 assert(etn);
109
110 for (eti = etn->info; eti; eti = eti->next) {
111 if (peer == eti->peer && type == eti->type
112 && subtype == eti->subtype) {
113
114 break;
115 }
116 }
117
118 if (eti) {
119 agg_unlock_node(etn);
120 } else {
121 eti = XCALLOC(MTYPE_RFAPI_ETI, sizeof(struct vnc_export_info));
122 eti->node = etn;
123 eti->peer = peer;
124 peer_lock(peer);
125 eti->type = type;
126 eti->subtype = subtype;
127 eti->next = etn->info;
128 etn->info = eti;
129 }
130
131 return eti;
132 }
133
134 void vnc_eti_delete(struct vnc_export_info *goner)
135 {
136 struct agg_node *etn;
137 struct vnc_export_info *eti;
138 struct vnc_export_info *eti_prev = NULL;
139
140 etn = goner->node;
141
142 for (eti = etn->info; eti; eti_prev = eti, eti = eti->next) {
143 if (eti == goner)
144 break;
145 }
146
147 if (!eti) {
148 vnc_zlog_debug_verbose("%s: COULDN'T FIND ETI", __func__);
149 return;
150 }
151
152 if (eti_prev) {
153 eti_prev->next = goner->next;
154 } else {
155 etn->info = goner->next;
156 }
157
158 peer_unlock(eti->peer);
159 goner->node = NULL;
160 XFREE(MTYPE_RFAPI_ETI, goner);
161
162 agg_unlock_node(etn);
163 }
164
165 struct vnc_export_info *vnc_eti_checktimer(struct bgp *bgp,
166 vnc_export_type_t etype,
167 const struct prefix *p,
168 struct peer *peer, uint8_t type,
169 uint8_t subtype)
170 {
171 struct agg_node *etn;
172 struct vnc_export_info *eti;
173
174 etn = vnc_etn_lookup(bgp, etype, p);
175 if (!etn)
176 return NULL;
177
178 for (eti = etn->info; eti; eti = eti->next) {
179 if (peer == eti->peer && type == eti->type
180 && subtype == eti->subtype) {
181
182 break;
183 }
184 }
185
186 agg_unlock_node(etn);
187
188 if (eti && eti->timer)
189 return eti;
190
191 return NULL;
192 }