]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_import.h
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / bgpd / rfapi / rfapi_import.h
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 * File: rfapi_import.h
23 * Purpose: Handle import of routes from BGP to RFAPI
24 */
25
26 #ifndef QUAGGA_HGP_RFAPI_IMPORT_H
27 #define QUAGGA_HGP_RFAPI_IMPORT_H
28
29 #include "lib/thread.h"
30
31 /*
32 * These are per-rt-import-list
33 *
34 * routes are not segregated by RD - the RD is stored in bgp_info_extra
35 * and is needed to determine if two prefixes are the same.
36 */
37 struct rfapi_import_table
38 {
39 struct rfapi_import_table *next;
40 struct rfapi_nve_group_cfg *rfg;
41 struct ecommunity *rt_import_list; /* copied from nve grp */
42 int refcount; /* nve grps and nves */
43 uint32_t l2_logical_net_id; /* L2 only: EVPN Eth Seg Id */
44 struct route_table *imported_vpn[AFI_MAX];
45 struct rfapi_monitor_vpn *vpn0_queries[AFI_MAX];
46 struct rfapi_monitor_eth *eth0_queries;
47 struct route_table *imported_encap[AFI_MAX];
48 struct skiplist *monitor_exterior_orphans;
49 int local_count[AFI_MAX];
50 int remote_count[AFI_MAX];
51 int holddown_count[AFI_MAX];
52 int imported_count[AFI_MAX];
53 };
54
55 #define RFAPI_LOCAL_BI(bi) \
56 (((bi)->type == ZEBRA_ROUTE_BGP) && ((bi)->sub_type == BGP_ROUTE_RFP))
57
58 #define RFAPI_DIRECT_IMPORT_BI(bi) \
59 (((bi)->type == ZEBRA_ROUTE_BGP_DIRECT) || ((bi)->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))
60
61 #define RFAPI_UPDATE_ITABLE_COUNT(bi, itable, afi, cnt) \
62 if (RFAPI_LOCAL_BI(bi)) { \
63 (itable)->local_count[(afi)] += (cnt); \
64 } else { \
65 if (RFAPI_DIRECT_IMPORT_BI(bi)) \
66 (itable)->imported_count[(afi)] += (cnt); \
67 else \
68 (itable)->remote_count[(afi)] += (cnt); \
69 }
70
71 extern uint8_t
72 rfapiRfpCost (struct attr *attr);
73
74 extern void
75 rfapiDebugBacktrace (void);
76
77 extern void
78 rfapiCheckRouteCount (void);
79
80 /*
81 * Print BI in an Import Table
82 */
83 extern void
84 rfapiPrintBi (void *stream, struct bgp_info *bi);
85
86 extern void
87 rfapiShowImportTable (
88 void *stream,
89 const char *label,
90 struct route_table *rt,
91 int isvpn);
92
93 extern struct rfapi_import_table *
94 rfapiImportTableRefAdd (
95 struct bgp *bgp,
96 struct ecommunity *rt_import_list,
97 struct rfapi_nve_group_cfg *rfg);
98
99 extern void
100 rfapiImportTableRefDelByIt (
101 struct bgp *bgp,
102 struct rfapi_import_table *it_target);
103
104
105 /*
106 * Construct an rfapi nexthop list based on the routes attached to
107 * the specified node.
108 *
109 * If there are any routes that do NOT have BGP_INFO_REMOVED set,
110 * return those only. If there are ONLY routes with BGP_INFO_REMOVED,
111 * then return those, and also include all the non-removed routes from the
112 * next less-specific node (i.e., this node's parent) at the end.
113 */
114 extern struct rfapi_next_hop_entry *
115 rfapiRouteNode2NextHopList (
116 struct route_node *rn,
117 uint32_t lifetime, /* put into nexthop entries */
118 struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */
119 struct route_table *rfd_rib_table, /* preload this NVE rib table */
120 struct prefix *pfx_target_original); /* query target */
121
122 extern struct rfapi_next_hop_entry *
123 rfapiRouteTable2NextHopList (
124 struct route_table *rt,
125 uint32_t lifetime, /* put into nexthop entries */
126 struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */
127 struct route_table *rfd_rib_table, /* preload this NVE rib table */
128 struct prefix *pfx_target_original); /* query target */
129
130 extern struct rfapi_next_hop_entry *
131 rfapiEthRouteTable2NextHopList (
132 uint32_t logical_net_id,
133 struct rfapi_ip_prefix *rprefix,
134 uint32_t lifetime, /* put into nexthop entries */
135 struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */
136 struct route_table *rib_route_table,/* preload NVE rib node */
137 struct prefix *pfx_target_original); /* query target */
138
139 extern int
140 rfapiEcommunitiesIntersect (struct ecommunity *e1, struct ecommunity *e2);
141
142 extern void
143 rfapiCheckRefcount (struct route_node *rn, safi_t safi, int lockoffset);
144
145 extern int
146 rfapiHasNonRemovedRoutes (struct route_node *rn);
147
148 extern int
149 rfapiProcessDeferredClose (struct thread *t);
150
151 extern int
152 rfapiGetUnAddrOfVpnBi (struct bgp_info *bi, struct prefix *p);
153
154 extern void
155 rfapiNexthop2Prefix (struct attr *attr, struct prefix *p);
156
157 extern void
158 rfapiUnicastNexthop2Prefix (
159 afi_t afi,
160 struct attr *attr,
161 struct prefix *p);
162
163 /* Filtered Import Function actions */
164 #define FIF_ACTION_UPDATE 0
165 #define FIF_ACTION_WITHDRAW 1
166 #define FIF_ACTION_KILL 2
167
168 extern void
169 rfapiBgpInfoFilteredImportVPN (
170 struct rfapi_import_table *import_table,
171 int action,
172 struct peer *peer,
173 void *rfd, /* set for looped back routes */
174 struct prefix *p,
175 struct prefix *aux_prefix, /* AFI_ETHER: optional IP */
176 afi_t afi,
177 struct prefix_rd *prd,
178 struct attr *attr, /* part of bgp_info */
179 u_char type, /* part of bgp_info */
180 u_char sub_type, /* part of bgp_info */
181 uint32_t *label); /* part of bgp_info */
182
183 extern struct rfapi_next_hop_entry *
184 rfapiEthRouteNode2NextHopList (
185 struct route_node *rn,
186 struct rfapi_ip_prefix *rprefix,
187 uint32_t lifetime, /* put into nexthop entries */
188 struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */
189 struct route_table *rib_route_table,/* preload NVE rib table */
190 struct prefix *pfx_target_original); /* query target */
191
192 extern struct rfapi_import_table *
193 rfapiMacImportTableGetNoAlloc (
194 struct bgp *bgp,
195 uint32_t lni);
196
197 extern struct rfapi_import_table *
198 rfapiMacImportTableGet (
199 struct bgp *bgp,
200 uint32_t lni);
201
202 extern int
203 rfapiGetL2o (
204 struct attr *attr,
205 struct rfapi_l2address_option *l2o);
206
207 extern int rfapiEcommunityGetLNI (
208 struct ecommunity *ecom,
209 uint32_t *lni);
210
211 extern int rfapiEcommunityGetEthernetTag (
212 struct ecommunity *ecom,
213 uint16_t * tag_id);
214
215 /* enable for debugging; disable for performance */
216 #if 0
217 #define RFAPI_CHECK_REFCOUNT(rn, safi, lo) rfapiCheckRefcount((rn),(safi),(lo))
218 #else
219 #define RFAPI_CHECK_REFCOUNT(rn, safi, lo) {}
220 #endif
221
222 /*------------------------------------------
223 * rfapiDeleteRemotePrefixes
224 *
225 * UI helper: For use by the "clear vnc prefixes" command
226 *
227 * input:
228 * un if set, tunnel must match this prefix
229 * vn if set, nexthop prefix must match this prefix
230 * p if set, prefix must match this prefix
231 * it if set, only look in this import table
232 *
233 * output
234 * pARcount number of active routes deleted
235 * pAHcount number of active nves deleted
236 * pHRcount number of holddown routes deleted
237 * pHHcount number of holddown nves deleted
238 *
239 * return value:
240 * void
241 --------------------------------------------*/
242 extern void
243 rfapiDeleteRemotePrefixes (
244 struct prefix *un,
245 struct prefix *vn,
246 struct prefix *p,
247 struct rfapi_import_table *it,
248 int delete_active,
249 int delete_holddown,
250 uint32_t *pARcount, /* active routes */
251 uint32_t *pAHcount, /* active nves */
252 uint32_t *pHRcount, /* holddown routes */
253 uint32_t *pHHcount); /* holddown nves */
254
255 /*------------------------------------------
256 * rfapiCountAllItRoutes
257 *
258 * UI helper: count VRF routes from BGP side
259 *
260 * input:
261 *
262 * output
263 * pARcount count of active routes
264 * pHRcount count of holddown routes
265 * pIRcount count of holddown routes
266 *
267 * return value:
268 * void
269 --------------------------------------------*/
270 extern void
271 rfapiCountAllItRoutes (
272 int *pALRcount, /* active local routes */
273 int *pARRcount, /* active remote routes */
274 int *pHRcount, /* holddown routes */
275 int *pIRcount); /* direct imported routes */
276
277 /*------------------------------------------
278 * rfapiGetHolddownFromLifetime
279 *
280 * calculate holddown value based on lifetime
281 *
282 * input:
283 * lifetime lifetime
284 *
285 * return value:
286 * Holddown value based on lifetime, holddown_factor,
287 * and RFAPI_LIFETIME_INFINITE_WITHDRAW_DELAY
288 *
289 --------------------------------------------*/
290 extern uint32_t
291 rfapiGetHolddownFromLifetime (uint32_t lifetime);
292
293 #endif /* QUAGGA_HGP_RFAPI_IMPORT_H */