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