]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/rfapi/vnc_export_table.c
tests: ospf gr helper topotests with scapy.
[mirror_frr.git] / bgpd / rfapi / vnc_export_table.c
CommitLineData
d62a17ae 1/*
65efcfce
LB
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 *
896014f4
DL
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
65efcfce
LB
19 */
20
21
f8b6f499
LB
22#include "lib/zebra.h"
23#include "lib/prefix.h"
fe08ba7e 24#include "lib/agg_table.h"
f8b6f499
LB
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"
a3b55c25 34#include "bgpd/rfapi/vnc_debug.h"
65efcfce 35
fe08ba7e 36struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type,
5a1ae2c2 37 const struct prefix *p)
65efcfce 38{
fe08ba7e
DS
39 struct agg_table *t = NULL;
40 struct agg_node *rn = NULL;
d62a17ae 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])
fe08ba7e 52 bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
d62a17ae 53 t = bgp->rfapi->rt_export_bgp[afi];
54 break;
55
56 case EXPORT_TYPE_ZEBRA:
57 if (!bgp->rfapi->rt_export_zebra[afi])
fe08ba7e 58 bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
d62a17ae 59 t = bgp->rfapi->rt_export_zebra[afi];
60 break;
61 }
62
63 if (t)
fe08ba7e 64 rn = agg_node_get(t, p);
d62a17ae 65 return rn;
65efcfce
LB
66}
67
fe08ba7e 68struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type,
5a1ae2c2 69 const struct prefix *p)
65efcfce 70{
fe08ba7e
DS
71 struct agg_table *t = NULL;
72 struct agg_node *rn = NULL;
d62a17ae 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])
fe08ba7e 84 bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
d62a17ae 85 t = bgp->rfapi->rt_export_bgp[afi];
86 break;
87
88 case EXPORT_TYPE_ZEBRA:
89 if (!bgp->rfapi->rt_export_zebra[afi])
fe08ba7e 90 bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
d62a17ae 91 t = bgp->rfapi->rt_export_zebra[afi];
92 break;
93 }
94
95 if (t)
fe08ba7e 96 rn = agg_node_lookup(t, p);
d62a17ae 97 return rn;
65efcfce
LB
98}
99
d62a17ae 100struct vnc_export_info *vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype,
5a1ae2c2 101 const struct prefix *p, struct peer *peer,
d62a17ae 102 uint8_t type, uint8_t subtype)
65efcfce 103{
fe08ba7e 104 struct agg_node *etn;
d62a17ae 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) {
fe08ba7e 119 agg_unlock_node(etn);
d62a17ae 120 } else {
121 eti = XCALLOC(MTYPE_RFAPI_ETI, sizeof(struct vnc_export_info));
122 assert(eti);
123 eti->node = etn;
124 eti->peer = peer;
125 peer_lock(peer);
126 eti->type = type;
127 eti->subtype = subtype;
128 eti->next = etn->info;
129 etn->info = eti;
130 }
131
132 return eti;
65efcfce
LB
133}
134
d62a17ae 135void vnc_eti_delete(struct vnc_export_info *goner)
65efcfce 136{
fe08ba7e 137 struct agg_node *etn;
d62a17ae 138 struct vnc_export_info *eti;
139 struct vnc_export_info *eti_prev = NULL;
140
141 etn = goner->node;
142
143 for (eti = etn->info; eti; eti_prev = eti, eti = eti->next) {
144 if (eti == goner)
145 break;
146 }
147
148 if (!eti) {
149 vnc_zlog_debug_verbose("%s: COULDN'T FIND ETI", __func__);
150 return;
151 }
152
153 if (eti_prev) {
154 eti_prev->next = goner->next;
155 } else {
156 etn->info = goner->next;
157 }
158
159 peer_unlock(eti->peer);
160 goner->node = NULL;
161 XFREE(MTYPE_RFAPI_ETI, goner);
162
fe08ba7e 163 agg_unlock_node(etn);
65efcfce
LB
164}
165
d62a17ae 166struct vnc_export_info *vnc_eti_checktimer(struct bgp *bgp,
167 vnc_export_type_t etype,
5f040085
DS
168 const struct prefix *p,
169 struct peer *peer, uint8_t type,
170 uint8_t subtype)
65efcfce 171{
fe08ba7e 172 struct agg_node *etn;
d62a17ae 173 struct vnc_export_info *eti;
65efcfce 174
d62a17ae 175 etn = vnc_etn_lookup(bgp, etype, p);
176 if (!etn)
177 return NULL;
65efcfce 178
d62a17ae 179 for (eti = etn->info; eti; eti = eti->next) {
180 if (peer == eti->peer && type == eti->type
181 && subtype == eti->subtype) {
65efcfce 182
d62a17ae 183 break;
184 }
185 }
65efcfce 186
fe08ba7e 187 agg_unlock_node(etn);
65efcfce 188
d62a17ae 189 if (eti && eti->timer)
190 return eti;
65efcfce 191
d62a17ae 192 return NULL;
65efcfce 193}