Line data Source code
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 0 : struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type,
37 : const struct prefix *p)
38 : {
39 0 : struct agg_table *t = NULL;
40 0 : struct agg_node *rn = NULL;
41 0 : afi_t afi;
42 :
43 0 : if (!bgp || !bgp->rfapi)
44 : return NULL;
45 :
46 0 : afi = family2afi(p->family);
47 0 : assert(afi == AFI_IP || afi == AFI_IP6);
48 :
49 0 : switch (type) {
50 0 : case EXPORT_TYPE_BGP:
51 0 : if (!bgp->rfapi->rt_export_bgp[afi])
52 0 : bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
53 0 : t = bgp->rfapi->rt_export_bgp[afi];
54 0 : break;
55 :
56 0 : case EXPORT_TYPE_ZEBRA:
57 0 : if (!bgp->rfapi->rt_export_zebra[afi])
58 0 : bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
59 0 : t = bgp->rfapi->rt_export_zebra[afi];
60 0 : break;
61 : }
62 :
63 0 : if (t)
64 0 : rn = agg_node_get(t, p);
65 : return rn;
66 : }
67 :
68 0 : struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type,
69 : const struct prefix *p)
70 : {
71 0 : struct agg_table *t = NULL;
72 0 : struct agg_node *rn = NULL;
73 0 : afi_t afi;
74 :
75 0 : if (!bgp || !bgp->rfapi)
76 : return NULL;
77 :
78 0 : afi = family2afi(p->family);
79 0 : assert(afi == AFI_IP || afi == AFI_IP6);
80 :
81 0 : switch (type) {
82 0 : case EXPORT_TYPE_BGP:
83 0 : if (!bgp->rfapi->rt_export_bgp[afi])
84 0 : bgp->rfapi->rt_export_bgp[afi] = agg_table_init();
85 0 : t = bgp->rfapi->rt_export_bgp[afi];
86 0 : break;
87 :
88 0 : case EXPORT_TYPE_ZEBRA:
89 0 : if (!bgp->rfapi->rt_export_zebra[afi])
90 0 : bgp->rfapi->rt_export_zebra[afi] = agg_table_init();
91 0 : t = bgp->rfapi->rt_export_zebra[afi];
92 0 : break;
93 : }
94 :
95 0 : if (t)
96 0 : rn = agg_node_lookup(t, p);
97 : return rn;
98 : }
99 :
100 0 : 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 0 : struct agg_node *etn;
105 0 : struct vnc_export_info *eti;
106 :
107 0 : etn = vnc_etn_get(bgp, etype, p);
108 0 : assert(etn);
109 :
110 0 : for (eti = etn->info; eti; eti = eti->next) {
111 0 : if (peer == eti->peer && type == eti->type
112 0 : && subtype == eti->subtype) {
113 :
114 : break;
115 : }
116 : }
117 :
118 0 : if (eti) {
119 0 : agg_unlock_node(etn);
120 : } else {
121 0 : eti = XCALLOC(MTYPE_RFAPI_ETI, sizeof(struct vnc_export_info));
122 0 : eti->node = etn;
123 0 : eti->peer = peer;
124 0 : peer_lock(peer);
125 0 : eti->type = type;
126 0 : eti->subtype = subtype;
127 0 : eti->next = etn->info;
128 0 : etn->info = eti;
129 : }
130 :
131 0 : return eti;
132 : }
133 :
134 0 : void vnc_eti_delete(struct vnc_export_info *goner)
135 : {
136 0 : struct agg_node *etn;
137 0 : struct vnc_export_info *eti;
138 0 : struct vnc_export_info *eti_prev = NULL;
139 :
140 0 : etn = goner->node;
141 :
142 0 : for (eti = etn->info; eti; eti_prev = eti, eti = eti->next) {
143 0 : if (eti == goner)
144 : break;
145 : }
146 :
147 0 : if (!eti) {
148 0 : vnc_zlog_debug_verbose("%s: COULDN'T FIND ETI", __func__);
149 0 : return;
150 : }
151 :
152 0 : if (eti_prev) {
153 0 : eti_prev->next = goner->next;
154 : } else {
155 0 : etn->info = goner->next;
156 : }
157 :
158 0 : peer_unlock(eti->peer);
159 0 : goner->node = NULL;
160 0 : XFREE(MTYPE_RFAPI_ETI, goner);
161 :
162 0 : agg_unlock_node(etn);
163 : }
164 :
165 0 : 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 0 : struct agg_node *etn;
172 0 : struct vnc_export_info *eti;
173 :
174 0 : etn = vnc_etn_lookup(bgp, etype, p);
175 0 : if (!etn)
176 : return NULL;
177 :
178 0 : for (eti = etn->info; eti; eti = eti->next) {
179 0 : if (peer == eti->peer && type == eti->type
180 0 : && subtype == eti->subtype) {
181 :
182 : break;
183 : }
184 : }
185 :
186 0 : agg_unlock_node(etn);
187 :
188 0 : if (eti && eti->timer)
189 : return eti;
190 :
191 : return NULL;
192 : }
|