]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/rfapi/rfapi_import.h
Merge pull request #13060 from opensourcerouting/feature/allow_peering_with_127.0.0.1
[mirror_frr.git] / bgpd / rfapi / rfapi_import.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
d62a17ae 2/*
65efcfce
LB
3 *
4 * Copyright 2009-2016, LabN Consulting, L.L.C.
5 *
65efcfce
LB
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
24a58196 16#include "frrevent.h"
65efcfce
LB
17
18/*
19 * These are per-rt-import-list
20 *
9b6d8fcf 21 * routes are not segregated by RD - the RD is stored in bgp_path_info_extra
65efcfce
LB
22 * and is needed to determine if two prefixes are the same.
23 */
d62a17ae 24struct 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 */
fe08ba7e 30 struct agg_table *imported_vpn[AFI_MAX];
d62a17ae 31 struct rfapi_monitor_vpn *vpn0_queries[AFI_MAX];
32 struct rfapi_monitor_eth *eth0_queries;
fe08ba7e 33 struct agg_table *imported_encap[AFI_MAX];
d62a17ae 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];
65efcfce
LB
39};
40
40381db7
DS
41#define RFAPI_LOCAL_BI(bpi) \
42 (((bpi)->type == ZEBRA_ROUTE_BGP) && ((bpi)->sub_type == BGP_ROUTE_RFP))
65efcfce 43
40381db7
DS
44#define RFAPI_DIRECT_IMPORT_BI(bpi) \
45 (((bpi)->type == ZEBRA_ROUTE_BGP_DIRECT) \
46 || ((bpi)->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))
65efcfce 47
40381db7
DS
48#define RFAPI_UPDATE_ITABLE_COUNT(bpi, itable, afi, cnt) \
49 if (RFAPI_LOCAL_BI(bpi)) { \
d62a17ae 50 (itable)->local_count[(afi)] += (cnt); \
51 } else { \
40381db7 52 if (RFAPI_DIRECT_IMPORT_BI(bpi)) \
d62a17ae 53 (itable)->imported_count[(afi)] += (cnt); \
54 else \
55 (itable)->remote_count[(afi)] += (cnt); \
56 }
65efcfce 57
d62a17ae 58extern uint8_t rfapiRfpCost(struct attr *attr);
65efcfce 59
d62a17ae 60extern void rfapiDebugBacktrace(void);
65efcfce 61
d62a17ae 62extern void rfapiCheckRouteCount(void);
65efcfce
LB
63
64/*
40381db7 65 * Print BPI in an Import Table
65efcfce 66 */
40381db7 67extern void rfapiPrintBi(void *stream, struct bgp_path_info *bpi);
65efcfce 68
d62a17ae 69extern void rfapiShowImportTable(void *stream, const char *label,
fe08ba7e 70 struct agg_table *rt, int isvpn);
65efcfce 71
ffc50094 72extern struct rfapi_import_table *
d62a17ae 73rfapiImportTableRefAdd(struct bgp *bgp, struct ecommunity *rt_import_list,
74 struct rfapi_nve_group_cfg *rfg);
65efcfce 75
d62a17ae 76extern void rfapiImportTableRefDelByIt(struct bgp *bgp,
77 struct rfapi_import_table *it_target);
65efcfce
LB
78
79
80/*
81 * Construct an rfapi nexthop list based on the routes attached to
82 * the specified node.
83 *
9b6d8fcf 84 * If there are any routes that do NOT have BGP_PATH_REMOVED set,
65efcfce
LB
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 */
d62a17ae 89extern struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList(
fe08ba7e
DS
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 */
d62a17ae 94
95extern struct rfapi_next_hop_entry *rfapiRouteTable2NextHopList(
fe08ba7e
DS
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 */
d62a17ae 100
101extern 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 */
fe08ba7e 105 struct agg_table *rib_route_table, /* preload NVE rib node */
d62a17ae 106 struct prefix *pfx_target_original); /* query target */
107
108extern int rfapiEcommunitiesIntersect(struct ecommunity *e1,
109 struct ecommunity *e2);
110
fe08ba7e 111extern void rfapiCheckRefcount(struct agg_node *rn, safi_t safi,
d62a17ae 112 int lockoffset);
113
fe08ba7e 114extern int rfapiHasNonRemovedRoutes(struct agg_node *rn);
d62a17ae 115
40381db7 116extern int rfapiGetUnAddrOfVpnBi(struct bgp_path_info *bpi, struct prefix *p);
d62a17ae 117
118extern void rfapiNexthop2Prefix(struct attr *attr, struct prefix *p);
119
120extern void rfapiUnicastNexthop2Prefix(afi_t afi, struct attr *attr,
121 struct prefix *p);
65efcfce
LB
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
d62a17ae 128extern void rfapiBgpInfoFilteredImportVPN(
129 struct rfapi_import_table *import_table, int action, struct peer *peer,
130 void *rfd, /* set for looped back routes */
5a1ae2c2
DS
131 const struct prefix *p,
132 const struct prefix *aux_prefix, /* AFI_ETHER: optional IP */
d62a17ae 133 afi_t afi, struct prefix_rd *prd,
4b7e6066 134 struct attr *attr, /* part of bgp_path_info */
5a1ae2c2 135 uint8_t type, /* part of bgp_path_info */
4b7e6066
DS
136 uint8_t sub_type, /* part of bgp_path_info */
137 uint32_t *label); /* part of bgp_path_info */
65efcfce 138
d62a17ae 139extern struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList(
fe08ba7e 140 struct agg_node *rn, struct rfapi_ip_prefix *rprefix,
d62a17ae 141 uint32_t lifetime, /* put into nexthop entries */
142 struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */
fe08ba7e 143 struct agg_table *rib_route_table, /* preload NVE rib table */
d62a17ae 144 struct prefix *pfx_target_original); /* query target */
65efcfce 145
d62a17ae 146extern struct rfapi_import_table *rfapiMacImportTableGetNoAlloc(struct bgp *bgp,
147 uint32_t lni);
148
149extern struct rfapi_import_table *rfapiMacImportTableGet(struct bgp *bgp,
150 uint32_t lni);
65efcfce 151
d62a17ae 152extern int rfapiGetL2o(struct attr *attr, struct rfapi_l2address_option *l2o);
65efcfce 153
d62a17ae 154extern int rfapiEcommunityGetLNI(struct ecommunity *ecom, uint32_t *lni);
65efcfce 155
d62a17ae 156extern int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom,
157 uint16_t *tag_id);
65efcfce
LB
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 *
d62a17ae 171 * input:
65efcfce
LB
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
5ff06872 175 * it if set, only look in this import table
65efcfce
LB
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 --------------------------------------------*/
d62a17ae 186extern 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 */
65efcfce
LB
194
195/*------------------------------------------
196 * rfapiCountAllItRoutes
197 *
198 * UI helper: count VRF routes from BGP side
199 *
d62a17ae 200 * input:
65efcfce
LB
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 --------------------------------------------*/
d62a17ae 210extern void rfapiCountAllItRoutes(int *pALRcount, /* active local routes */
211 int *pARRcount, /* active remote routes */
212 int *pHRcount, /* holddown routes */
213 int *pIRcount); /* direct imported routes */
65efcfce
LB
214
215/*------------------------------------------
216 * rfapiGetHolddownFromLifetime
217 *
218 * calculate holddown value based on lifetime
219 *
d62a17ae 220 * input:
65efcfce
LB
221 * lifetime lifetime
222 *
223 * return value:
224 * Holddown value based on lifetime, holddown_factor,
225 * and RFAPI_LIFETIME_INFINITE_WITHDRAW_DELAY
226 *
227 --------------------------------------------*/
d62a17ae 228extern uint32_t rfapiGetHolddownFromLifetime(uint32_t lifetime);
65efcfce
LB
229
230#endif /* QUAGGA_HGP_RFAPI_IMPORT_H */