]>
Commit | Line | Data |
---|---|---|
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 | * | |
9b6d8fcf | 34 | * routes are not segregated by RD - the RD is stored in bgp_path_info_extra |
65efcfce LB |
35 | * and is needed to determine if two prefixes are the same. |
36 | */ | |
d62a17ae | 37 | struct 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 */ | |
fe08ba7e | 43 | struct agg_table *imported_vpn[AFI_MAX]; |
d62a17ae | 44 | struct rfapi_monitor_vpn *vpn0_queries[AFI_MAX]; |
45 | struct rfapi_monitor_eth *eth0_queries; | |
fe08ba7e | 46 | struct agg_table *imported_encap[AFI_MAX]; |
d62a17ae | 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 | ||
40381db7 DS |
54 | #define RFAPI_LOCAL_BI(bpi) \ |
55 | (((bpi)->type == ZEBRA_ROUTE_BGP) && ((bpi)->sub_type == BGP_ROUTE_RFP)) | |
65efcfce | 56 | |
40381db7 DS |
57 | #define RFAPI_DIRECT_IMPORT_BI(bpi) \ |
58 | (((bpi)->type == ZEBRA_ROUTE_BGP_DIRECT) \ | |
59 | || ((bpi)->type == ZEBRA_ROUTE_BGP_DIRECT_EXT)) | |
65efcfce | 60 | |
40381db7 DS |
61 | #define RFAPI_UPDATE_ITABLE_COUNT(bpi, itable, afi, cnt) \ |
62 | if (RFAPI_LOCAL_BI(bpi)) { \ | |
d62a17ae | 63 | (itable)->local_count[(afi)] += (cnt); \ |
64 | } else { \ | |
40381db7 | 65 | if (RFAPI_DIRECT_IMPORT_BI(bpi)) \ |
d62a17ae | 66 | (itable)->imported_count[(afi)] += (cnt); \ |
67 | else \ | |
68 | (itable)->remote_count[(afi)] += (cnt); \ | |
69 | } | |
65efcfce | 70 | |
d62a17ae | 71 | extern uint8_t rfapiRfpCost(struct attr *attr); |
65efcfce | 72 | |
d62a17ae | 73 | extern void rfapiDebugBacktrace(void); |
65efcfce | 74 | |
d62a17ae | 75 | extern void rfapiCheckRouteCount(void); |
65efcfce LB |
76 | |
77 | /* | |
40381db7 | 78 | * Print BPI in an Import Table |
65efcfce | 79 | */ |
40381db7 | 80 | extern void rfapiPrintBi(void *stream, struct bgp_path_info *bpi); |
65efcfce | 81 | |
d62a17ae | 82 | extern void rfapiShowImportTable(void *stream, const char *label, |
fe08ba7e | 83 | struct agg_table *rt, int isvpn); |
65efcfce | 84 | |
ffc50094 | 85 | extern struct rfapi_import_table * |
d62a17ae | 86 | rfapiImportTableRefAdd(struct bgp *bgp, struct ecommunity *rt_import_list, |
87 | struct rfapi_nve_group_cfg *rfg); | |
65efcfce | 88 | |
d62a17ae | 89 | extern 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 | * | |
9b6d8fcf | 97 | * If there are any routes that do NOT have BGP_PATH_REMOVED set, |
65efcfce LB |
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 | 102 | extern struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( |
fe08ba7e DS |
103 | struct agg_node *rn, uint32_t lifetime, /* put into nexthop entries */ |
104 | struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */ | |
105 | struct agg_table *rfd_rib_table, /* preload this NVE rib table */ | |
106 | struct prefix *pfx_target_original); /* query target */ | |
d62a17ae | 107 | |
108 | extern struct rfapi_next_hop_entry *rfapiRouteTable2NextHopList( | |
fe08ba7e DS |
109 | struct agg_table *rt, uint32_t lifetime, /* put into nexthop entries */ |
110 | struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */ | |
111 | struct agg_table *rfd_rib_table, /* preload this NVE rib table */ | |
112 | struct prefix *pfx_target_original); /* query target */ | |
d62a17ae | 113 | |
114 | extern struct rfapi_next_hop_entry *rfapiEthRouteTable2NextHopList( | |
115 | uint32_t logical_net_id, struct rfapi_ip_prefix *rprefix, | |
116 | uint32_t lifetime, /* put into nexthop entries */ | |
117 | struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */ | |
fe08ba7e | 118 | struct agg_table *rib_route_table, /* preload NVE rib node */ |
d62a17ae | 119 | struct prefix *pfx_target_original); /* query target */ |
120 | ||
121 | extern int rfapiEcommunitiesIntersect(struct ecommunity *e1, | |
122 | struct ecommunity *e2); | |
123 | ||
fe08ba7e | 124 | extern void rfapiCheckRefcount(struct agg_node *rn, safi_t safi, |
d62a17ae | 125 | int lockoffset); |
126 | ||
fe08ba7e | 127 | extern int rfapiHasNonRemovedRoutes(struct agg_node *rn); |
d62a17ae | 128 | |
129 | extern int rfapiProcessDeferredClose(struct thread *t); | |
130 | ||
40381db7 | 131 | extern int rfapiGetUnAddrOfVpnBi(struct bgp_path_info *bpi, struct prefix *p); |
d62a17ae | 132 | |
133 | extern void rfapiNexthop2Prefix(struct attr *attr, struct prefix *p); | |
134 | ||
135 | extern void rfapiUnicastNexthop2Prefix(afi_t afi, struct attr *attr, | |
136 | struct prefix *p); | |
65efcfce LB |
137 | |
138 | /* Filtered Import Function actions */ | |
139 | #define FIF_ACTION_UPDATE 0 | |
140 | #define FIF_ACTION_WITHDRAW 1 | |
141 | #define FIF_ACTION_KILL 2 | |
142 | ||
d62a17ae | 143 | extern void rfapiBgpInfoFilteredImportVPN( |
144 | struct rfapi_import_table *import_table, int action, struct peer *peer, | |
145 | void *rfd, /* set for looped back routes */ | |
146 | struct prefix *p, | |
147 | struct prefix *aux_prefix, /* AFI_ETHER: optional IP */ | |
148 | afi_t afi, struct prefix_rd *prd, | |
4b7e6066 DS |
149 | struct attr *attr, /* part of bgp_path_info */ |
150 | uint8_t type, /* part of bgp_path_info */ | |
151 | uint8_t sub_type, /* part of bgp_path_info */ | |
152 | uint32_t *label); /* part of bgp_path_info */ | |
65efcfce | 153 | |
d62a17ae | 154 | extern struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList( |
fe08ba7e | 155 | struct agg_node *rn, struct rfapi_ip_prefix *rprefix, |
d62a17ae | 156 | uint32_t lifetime, /* put into nexthop entries */ |
157 | struct rfapi_ip_addr *exclude_vnaddr, /* omit routes to same NVE */ | |
fe08ba7e | 158 | struct agg_table *rib_route_table, /* preload NVE rib table */ |
d62a17ae | 159 | struct prefix *pfx_target_original); /* query target */ |
65efcfce | 160 | |
d62a17ae | 161 | extern struct rfapi_import_table *rfapiMacImportTableGetNoAlloc(struct bgp *bgp, |
162 | uint32_t lni); | |
163 | ||
164 | extern struct rfapi_import_table *rfapiMacImportTableGet(struct bgp *bgp, | |
165 | uint32_t lni); | |
65efcfce | 166 | |
d62a17ae | 167 | extern int rfapiGetL2o(struct attr *attr, struct rfapi_l2address_option *l2o); |
65efcfce | 168 | |
d62a17ae | 169 | extern int rfapiEcommunityGetLNI(struct ecommunity *ecom, uint32_t *lni); |
65efcfce | 170 | |
d62a17ae | 171 | extern int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, |
172 | uint16_t *tag_id); | |
65efcfce LB |
173 | |
174 | /* enable for debugging; disable for performance */ | |
175 | #if 0 | |
176 | #define RFAPI_CHECK_REFCOUNT(rn, safi, lo) rfapiCheckRefcount((rn),(safi),(lo)) | |
177 | #else | |
178 | #define RFAPI_CHECK_REFCOUNT(rn, safi, lo) {} | |
179 | #endif | |
180 | ||
181 | /*------------------------------------------ | |
182 | * rfapiDeleteRemotePrefixes | |
183 | * | |
184 | * UI helper: For use by the "clear vnc prefixes" command | |
185 | * | |
d62a17ae | 186 | * input: |
65efcfce LB |
187 | * un if set, tunnel must match this prefix |
188 | * vn if set, nexthop prefix must match this prefix | |
189 | * p if set, prefix must match this prefix | |
5ff06872 | 190 | * it if set, only look in this import table |
65efcfce LB |
191 | * |
192 | * output | |
193 | * pARcount number of active routes deleted | |
194 | * pAHcount number of active nves deleted | |
195 | * pHRcount number of holddown routes deleted | |
196 | * pHHcount number of holddown nves deleted | |
197 | * | |
198 | * return value: | |
199 | * void | |
200 | --------------------------------------------*/ | |
d62a17ae | 201 | extern void rfapiDeleteRemotePrefixes(struct prefix *un, struct prefix *vn, |
202 | struct prefix *p, | |
203 | struct rfapi_import_table *it, | |
204 | int delete_active, int delete_holddown, | |
205 | uint32_t *pARcount, /* active routes */ | |
206 | uint32_t *pAHcount, /* active nves */ | |
207 | uint32_t *pHRcount, /* holddown routes */ | |
208 | uint32_t *pHHcount); /* holddown nves */ | |
65efcfce LB |
209 | |
210 | /*------------------------------------------ | |
211 | * rfapiCountAllItRoutes | |
212 | * | |
213 | * UI helper: count VRF routes from BGP side | |
214 | * | |
d62a17ae | 215 | * input: |
65efcfce LB |
216 | * |
217 | * output | |
218 | * pARcount count of active routes | |
219 | * pHRcount count of holddown routes | |
220 | * pIRcount count of holddown routes | |
221 | * | |
222 | * return value: | |
223 | * void | |
224 | --------------------------------------------*/ | |
d62a17ae | 225 | extern void rfapiCountAllItRoutes(int *pALRcount, /* active local routes */ |
226 | int *pARRcount, /* active remote routes */ | |
227 | int *pHRcount, /* holddown routes */ | |
228 | int *pIRcount); /* direct imported routes */ | |
65efcfce LB |
229 | |
230 | /*------------------------------------------ | |
231 | * rfapiGetHolddownFromLifetime | |
232 | * | |
233 | * calculate holddown value based on lifetime | |
234 | * | |
d62a17ae | 235 | * input: |
65efcfce LB |
236 | * lifetime lifetime |
237 | * | |
238 | * return value: | |
239 | * Holddown value based on lifetime, holddown_factor, | |
240 | * and RFAPI_LIFETIME_INFINITE_WITHDRAW_DELAY | |
241 | * | |
242 | --------------------------------------------*/ | |
d62a17ae | 243 | extern uint32_t rfapiGetHolddownFromLifetime(uint32_t lifetime); |
65efcfce LB |
244 | |
245 | #endif /* QUAGGA_HGP_RFAPI_IMPORT_H */ |