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