1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
*
* Copyright 2009-2016, LabN Consulting, L.L.C.
*
*/
#include "lib/zebra.h"
#include "lib/prefix.h"
#include "lib/agg_table.h"
#include "lib/memory.h"
#include "lib/vty.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_route.h"
#include "bgpd/rfapi/vnc_export_table.h"
#include "bgpd/rfapi/rfapi_private.h"
#include "bgpd/rfapi/rfapi_import.h"
#include "bgpd/rfapi/vnc_debug.h"
struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type,
const struct prefix *p)
{
struct agg_table *t = NULL;
struct agg_node *rn = NULL;
afi_t afi;
if (!bgp || !bgp->rfapi)
return NULL;
afi = family2afi(p->family);
assert(afi == AFI_IP || afi == AFI_IP6);
switch (type) {
case EXPORT_TYPE_BGP:
if (!bgp->rfapi->rt_export_bgp[afi])
bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
t = bgp->rfapi->rt_export_bgp[afi];
break;
case EXPORT_TYPE_ZEBRA:
if (!bgp->rfapi->rt_export_zebra[afi])
bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
t = bgp->rfapi->rt_export_zebra[afi];
break;
}
if (t)
rn = agg_node_get(t, p);
return rn;
}
struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type,
const struct prefix *p)
{
struct agg_table *t = NULL;
struct agg_node *rn = NULL;
afi_t afi;
if (!bgp || !bgp->rfapi)
return NULL;
afi = family2afi(p->family);
assert(afi == AFI_IP || afi == AFI_IP6);
switch (type) {
case EXPORT_TYPE_BGP:
if (!bgp->rfapi->rt_export_bgp[afi])
bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
t = bgp->rfapi->rt_export_bgp[afi];
break;
case EXPORT_TYPE_ZEBRA:
if (!bgp->rfapi->rt_export_zebra[afi])
bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
t = bgp->rfapi->rt_export_zebra[afi];
break;
}
if (t)
rn = agg_node_lookup(t, p);
return rn;
}
struct vnc_export_info *vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype,
const struct prefix *p, struct peer *peer,
uint8_t type, uint8_t subtype)
{
struct agg_node *etn;
struct vnc_export_info *eti;
etn = vnc_etn_get(bgp, etype, p);
assert(etn);
for (eti = etn->info; eti; eti = eti->next) {
if (peer == eti->peer && type == eti->type
&& subtype == eti->subtype) {
break;
}
}
if (eti) {
agg_unlock_node(etn);
} else {
eti = XCALLOC(MTYPE_RFAPI_ETI, sizeof(struct vnc_export_info));
eti->node = etn;
eti->peer = peer;
peer_lock(peer);
eti->type = type;
eti->subtype = subtype;
eti->next = etn->info;
etn->info = eti;
}
return eti;
}
void vnc_eti_delete(struct vnc_export_info *goner)
{
struct agg_node *etn;
struct vnc_export_info *eti;
struct vnc_export_info *eti_prev = NULL;
etn = goner->node;
for (eti = etn->info; eti; eti_prev = eti, eti = eti->next) {
if (eti == goner)
break;
}
if (!eti) {
vnc_zlog_debug_verbose("%s: COULDN'T FIND ETI", __func__);
return;
}
if (eti_prev) {
eti_prev->next = goner->next;
} else {
etn->info = goner->next;
}
peer_unlock(eti->peer);
goner->node = NULL;
XFREE(MTYPE_RFAPI_ETI, goner);
agg_unlock_node(etn);
}
struct vnc_export_info *vnc_eti_checktimer(struct bgp *bgp,
vnc_export_type_t etype,
const struct prefix *p,
struct peer *peer, uint8_t type,
uint8_t subtype)
{
struct agg_node *etn;
struct vnc_export_info *eti;
etn = vnc_etn_lookup(bgp, etype, p);
if (!etn)
return NULL;
for (eti = etn->info; eti; eti = eti->next) {
if (peer == eti->peer && type == eti->type
&& subtype == eti->subtype) {
break;
}
}
agg_unlock_node(etn);
if (eti && eti->timer)
return eti;
return NULL;
}
|