]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP routing information |
2 | Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro | |
3 | ||
4 | This file is part of GNU Zebra. | |
5 | ||
6 | GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
8 | Free Software Foundation; either version 2, or (at your option) any | |
9 | later version. | |
10 | ||
11 | GNU Zebra is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
20 | ||
21 | #include <zebra.h> | |
22 | ||
856ca177 | 23 | #include "lib/json.h" |
718e3744 | 24 | #include "prefix.h" |
25 | #include "linklist.h" | |
26 | #include "memory.h" | |
27 | #include "command.h" | |
28 | #include "stream.h" | |
29 | #include "filter.h" | |
30 | #include "str.h" | |
31 | #include "log.h" | |
32 | #include "routemap.h" | |
33 | #include "buffer.h" | |
34 | #include "sockunion.h" | |
35 | #include "plist.h" | |
36 | #include "thread.h" | |
200df115 | 37 | #include "workqueue.h" |
3f9c7369 | 38 | #include "queue.h" |
6e919709 | 39 | #include "memory.h" |
718e3744 | 40 | |
41 | #include "bgpd/bgpd.h" | |
42 | #include "bgpd/bgp_table.h" | |
43 | #include "bgpd/bgp_route.h" | |
44 | #include "bgpd/bgp_attr.h" | |
45 | #include "bgpd/bgp_debug.h" | |
46 | #include "bgpd/bgp_aspath.h" | |
47 | #include "bgpd/bgp_regex.h" | |
48 | #include "bgpd/bgp_community.h" | |
49 | #include "bgpd/bgp_ecommunity.h" | |
50 | #include "bgpd/bgp_clist.h" | |
51 | #include "bgpd/bgp_packet.h" | |
52 | #include "bgpd/bgp_filter.h" | |
53 | #include "bgpd/bgp_fsm.h" | |
54 | #include "bgpd/bgp_mplsvpn.h" | |
55 | #include "bgpd/bgp_nexthop.h" | |
56 | #include "bgpd/bgp_damp.h" | |
57 | #include "bgpd/bgp_advertise.h" | |
58 | #include "bgpd/bgp_zebra.h" | |
0a486e5f | 59 | #include "bgpd/bgp_vty.h" |
96450faf | 60 | #include "bgpd/bgp_mpath.h" |
fc9a856f | 61 | #include "bgpd/bgp_nht.h" |
3f9c7369 | 62 | #include "bgpd/bgp_updgrp.h" |
718e3744 | 63 | |
64 | /* Extern from bgp_dump.c */ | |
dde72586 SH |
65 | extern const char *bgp_origin_str[]; |
66 | extern const char *bgp_origin_long_str[]; | |
6b0655a2 | 67 | |
4125bb67 | 68 | struct bgp_node * |
fee0f4c6 | 69 | bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p, |
718e3744 | 70 | struct prefix_rd *prd) |
71 | { | |
72 | struct bgp_node *rn; | |
73 | struct bgp_node *prn = NULL; | |
da5b30f6 PJ |
74 | |
75 | assert (table); | |
76 | if (!table) | |
77 | return NULL; | |
78 | ||
718e3744 | 79 | if (safi == SAFI_MPLS_VPN) |
80 | { | |
fee0f4c6 | 81 | prn = bgp_node_get (table, (struct prefix *) prd); |
718e3744 | 82 | |
83 | if (prn->info == NULL) | |
64e580a7 | 84 | prn->info = bgp_table_init (afi, safi); |
718e3744 | 85 | else |
86 | bgp_unlock_node (prn); | |
87 | table = prn->info; | |
88 | } | |
718e3744 | 89 | |
90 | rn = bgp_node_get (table, p); | |
91 | ||
92 | if (safi == SAFI_MPLS_VPN) | |
93 | rn->prn = prn; | |
94 | ||
95 | return rn; | |
96 | } | |
6b0655a2 | 97 | |
fb982c25 PJ |
98 | /* Allocate bgp_info_extra */ |
99 | static struct bgp_info_extra * | |
100 | bgp_info_extra_new (void) | |
101 | { | |
102 | struct bgp_info_extra *new; | |
103 | new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra)); | |
104 | return new; | |
105 | } | |
106 | ||
107 | static void | |
108 | bgp_info_extra_free (struct bgp_info_extra **extra) | |
109 | { | |
110 | if (extra && *extra) | |
111 | { | |
112 | if ((*extra)->damp_info) | |
113 | bgp_damp_info_free ((*extra)->damp_info, 0); | |
114 | ||
115 | (*extra)->damp_info = NULL; | |
116 | ||
117 | XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra); | |
118 | ||
119 | *extra = NULL; | |
120 | } | |
121 | } | |
122 | ||
123 | /* Get bgp_info extra information for the given bgp_info, lazy allocated | |
124 | * if required. | |
125 | */ | |
126 | struct bgp_info_extra * | |
127 | bgp_info_extra_get (struct bgp_info *ri) | |
128 | { | |
129 | if (!ri->extra) | |
130 | ri->extra = bgp_info_extra_new(); | |
131 | return ri->extra; | |
132 | } | |
133 | ||
718e3744 | 134 | /* Free bgp route information. */ |
200df115 | 135 | static void |
718e3744 | 136 | bgp_info_free (struct bgp_info *binfo) |
137 | { | |
138 | if (binfo->attr) | |
f6f434b2 | 139 | bgp_attr_unintern (&binfo->attr); |
fb018d25 DS |
140 | |
141 | bgp_unlink_nexthop(binfo); | |
fb982c25 | 142 | bgp_info_extra_free (&binfo->extra); |
de8d5dff | 143 | bgp_info_mpath_free (&binfo->mpath); |
718e3744 | 144 | |
200df115 | 145 | peer_unlock (binfo->peer); /* bgp_info peer reference */ |
146 | ||
718e3744 | 147 | XFREE (MTYPE_BGP_ROUTE, binfo); |
148 | } | |
149 | ||
200df115 | 150 | struct bgp_info * |
151 | bgp_info_lock (struct bgp_info *binfo) | |
152 | { | |
153 | binfo->lock++; | |
154 | return binfo; | |
155 | } | |
156 | ||
157 | struct bgp_info * | |
158 | bgp_info_unlock (struct bgp_info *binfo) | |
159 | { | |
160 | assert (binfo && binfo->lock > 0); | |
161 | binfo->lock--; | |
162 | ||
163 | if (binfo->lock == 0) | |
164 | { | |
165 | #if 0 | |
166 | zlog_debug ("%s: unlocked and freeing", __func__); | |
167 | zlog_backtrace (LOG_DEBUG); | |
168 | #endif | |
169 | bgp_info_free (binfo); | |
170 | return NULL; | |
171 | } | |
172 | ||
173 | #if 0 | |
174 | if (binfo->lock == 1) | |
175 | { | |
176 | zlog_debug ("%s: unlocked to 1", __func__); | |
177 | zlog_backtrace (LOG_DEBUG); | |
178 | } | |
179 | #endif | |
180 | ||
181 | return binfo; | |
182 | } | |
183 | ||
718e3744 | 184 | void |
185 | bgp_info_add (struct bgp_node *rn, struct bgp_info *ri) | |
186 | { | |
187 | struct bgp_info *top; | |
188 | ||
189 | top = rn->info; | |
200df115 | 190 | |
718e3744 | 191 | ri->next = rn->info; |
192 | ri->prev = NULL; | |
193 | if (top) | |
194 | top->prev = ri; | |
195 | rn->info = ri; | |
200df115 | 196 | |
197 | bgp_info_lock (ri); | |
198 | bgp_lock_node (rn); | |
199 | peer_lock (ri->peer); /* bgp_info peer reference */ | |
718e3744 | 200 | } |
201 | ||
b40d939b | 202 | /* Do the actual removal of info from RIB, for use by bgp_process |
203 | completion callback *only* */ | |
204 | static void | |
205 | bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri) | |
718e3744 | 206 | { |
207 | if (ri->next) | |
208 | ri->next->prev = ri->prev; | |
209 | if (ri->prev) | |
210 | ri->prev->next = ri->next; | |
211 | else | |
212 | rn->info = ri->next; | |
200df115 | 213 | |
de8d5dff | 214 | bgp_info_mpath_dequeue (ri); |
200df115 | 215 | bgp_info_unlock (ri); |
216 | bgp_unlock_node (rn); | |
718e3744 | 217 | } |
218 | ||
b40d939b | 219 | void |
220 | bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri) | |
221 | { | |
1a392d46 PJ |
222 | bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED); |
223 | /* set of previous already took care of pcount */ | |
b40d939b | 224 | UNSET_FLAG (ri->flags, BGP_INFO_VALID); |
225 | } | |
226 | ||
8d45210e AS |
227 | /* undo the effects of a previous call to bgp_info_delete; typically |
228 | called when a route is deleted and then quickly re-added before the | |
229 | deletion has been processed */ | |
230 | static void | |
231 | bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri) | |
232 | { | |
233 | bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED); | |
234 | /* unset of previous already took care of pcount */ | |
235 | SET_FLAG (ri->flags, BGP_INFO_VALID); | |
236 | } | |
237 | ||
1a392d46 PJ |
238 | /* Adjust pcount as required */ |
239 | static void | |
240 | bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri) | |
241 | { | |
67174041 AS |
242 | struct bgp_table *table; |
243 | ||
244 | assert (rn && bgp_node_table (rn)); | |
6f58544d PJ |
245 | assert (ri && ri->peer && ri->peer->bgp); |
246 | ||
67174041 AS |
247 | table = bgp_node_table (rn); |
248 | ||
2a3d5731 | 249 | if (ri->peer == ri->peer->bgp->peer_self) |
1a392d46 PJ |
250 | return; |
251 | ||
80e0ad24 | 252 | if (!BGP_INFO_COUNTABLE (ri) |
1a392d46 PJ |
253 | && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
254 | { | |
255 | ||
256 | UNSET_FLAG (ri->flags, BGP_INFO_COUNTED); | |
257 | ||
258 | /* slight hack, but more robust against errors. */ | |
67174041 AS |
259 | if (ri->peer->pcount[table->afi][table->safi]) |
260 | ri->peer->pcount[table->afi][table->safi]--; | |
1a392d46 PJ |
261 | else |
262 | { | |
263 | zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s", | |
264 | __func__, ri->peer->host); | |
265 | zlog_backtrace (LOG_WARNING); | |
266 | zlog_warn ("%s: Please report to Quagga bugzilla", __func__); | |
267 | } | |
268 | } | |
80e0ad24 | 269 | else if (BGP_INFO_COUNTABLE (ri) |
1a392d46 PJ |
270 | && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
271 | { | |
272 | SET_FLAG (ri->flags, BGP_INFO_COUNTED); | |
67174041 | 273 | ri->peer->pcount[table->afi][table->safi]++; |
1a392d46 PJ |
274 | } |
275 | } | |
276 | ||
277 | ||
278 | /* Set/unset bgp_info flags, adjusting any other state as needed. | |
279 | * This is here primarily to keep prefix-count in check. | |
280 | */ | |
281 | void | |
282 | bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) | |
283 | { | |
284 | SET_FLAG (ri->flags, flag); | |
285 | ||
80e0ad24 DS |
286 | /* early bath if we know it's not a flag that changes countability state */ |
287 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED)) | |
1a392d46 PJ |
288 | return; |
289 | ||
290 | bgp_pcount_adjust (rn, ri); | |
291 | } | |
292 | ||
293 | void | |
294 | bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) | |
295 | { | |
296 | UNSET_FLAG (ri->flags, flag); | |
297 | ||
80e0ad24 DS |
298 | /* early bath if we know it's not a flag that changes countability state */ |
299 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_HISTORY|BGP_INFO_REMOVED)) | |
1a392d46 PJ |
300 | return; |
301 | ||
302 | bgp_pcount_adjust (rn, ri); | |
303 | } | |
304 | ||
718e3744 | 305 | /* Get MED value. If MED value is missing and "bgp bestpath |
306 | missing-as-worst" is specified, treat it as the worst value. */ | |
94f2b392 | 307 | static u_int32_t |
718e3744 | 308 | bgp_med_value (struct attr *attr, struct bgp *bgp) |
309 | { | |
310 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
311 | return attr->med; | |
312 | else | |
313 | { | |
314 | if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST)) | |
3b424979 | 315 | return BGP_MED_MAX; |
718e3744 | 316 | else |
317 | return 0; | |
318 | } | |
319 | } | |
320 | ||
2ec1e66f DW |
321 | void |
322 | bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf) | |
323 | { | |
324 | if (ri->addpath_rx_id) | |
325 | sprintf(buf, "path %s (addpath rxid %d)", ri->peer->host, ri->addpath_rx_id); | |
326 | else | |
327 | sprintf(buf, "path %s", ri->peer->host); | |
328 | } | |
329 | ||
9fbdd100 | 330 | /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */ |
94f2b392 | 331 | static int |
96450faf | 332 | bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist, |
9fbdd100 DS |
333 | int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug, |
334 | char *pfx_buf) | |
718e3744 | 335 | { |
8ff56318 JBD |
336 | struct attr *newattr, *existattr; |
337 | struct attr_extra *newattre, *existattre; | |
338 | bgp_peer_sort_t new_sort; | |
339 | bgp_peer_sort_t exist_sort; | |
718e3744 | 340 | u_int32_t new_pref; |
341 | u_int32_t exist_pref; | |
342 | u_int32_t new_med; | |
343 | u_int32_t exist_med; | |
8ff56318 JBD |
344 | u_int32_t new_weight; |
345 | u_int32_t exist_weight; | |
346 | uint32_t newm, existm; | |
718e3744 | 347 | struct in_addr new_id; |
348 | struct in_addr exist_id; | |
349 | int new_cluster; | |
350 | int exist_cluster; | |
8ff56318 JBD |
351 | int internal_as_route; |
352 | int confed_as_route; | |
718e3744 | 353 | int ret; |
2ec1e66f DW |
354 | char new_buf[PATH_ADDPATH_STR_BUFFER]; |
355 | char exist_buf[PATH_ADDPATH_STR_BUFFER]; | |
96450faf JB |
356 | |
357 | *paths_eq = 0; | |
718e3744 | 358 | |
359 | /* 0. Null check. */ | |
360 | if (new == NULL) | |
9fbdd100 DS |
361 | { |
362 | if (debug) | |
363 | zlog_debug("%s: new is NULL", pfx_buf); | |
364 | return 0; | |
365 | } | |
366 | ||
2ec1e66f DW |
367 | if (debug) |
368 | bgp_info_path_with_addpath_rx_str (new, new_buf); | |
369 | ||
718e3744 | 370 | if (exist == NULL) |
9fbdd100 DS |
371 | { |
372 | if (debug) | |
2ec1e66f | 373 | zlog_debug("%s: %s is the initial bestpath", pfx_buf, new_buf); |
9fbdd100 DS |
374 | return 1; |
375 | } | |
718e3744 | 376 | |
2ec1e66f DW |
377 | if (debug) |
378 | bgp_info_path_with_addpath_rx_str (exist, exist_buf); | |
379 | ||
8ff56318 JBD |
380 | newattr = new->attr; |
381 | existattr = exist->attr; | |
382 | newattre = newattr->extra; | |
383 | existattre = existattr->extra; | |
384 | ||
718e3744 | 385 | /* 1. Weight check. */ |
8ff56318 JBD |
386 | new_weight = exist_weight = 0; |
387 | ||
388 | if (newattre) | |
389 | new_weight = newattre->weight; | |
390 | if (existattre) | |
391 | exist_weight = existattre->weight; | |
392 | ||
fb982c25 | 393 | if (new_weight > exist_weight) |
9fbdd100 DS |
394 | { |
395 | if (debug) | |
2ec1e66f DW |
396 | zlog_debug("%s: %s wins over %s due to weight %d > %d", |
397 | pfx_buf, new_buf, exist_buf, new_weight, exist_weight); | |
9fbdd100 DS |
398 | return 1; |
399 | } | |
400 | ||
fb982c25 | 401 | if (new_weight < exist_weight) |
9fbdd100 DS |
402 | { |
403 | if (debug) | |
2ec1e66f DW |
404 | zlog_debug("%s: %s loses to %s due to weight %d < %d", |
405 | pfx_buf, new_buf, exist_buf, new_weight, exist_weight); | |
9fbdd100 DS |
406 | return 0; |
407 | } | |
718e3744 | 408 | |
409 | /* 2. Local preference check. */ | |
8ff56318 JBD |
410 | new_pref = exist_pref = bgp->default_local_pref; |
411 | ||
412 | if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
413 | new_pref = newattr->local_pref; | |
414 | if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
415 | exist_pref = existattr->local_pref; | |
718e3744 | 416 | |
718e3744 | 417 | if (new_pref > exist_pref) |
9fbdd100 DS |
418 | { |
419 | if (debug) | |
2ec1e66f DW |
420 | zlog_debug("%s: %s wins over %s due to localpref %d > %d", |
421 | pfx_buf, new_buf, exist_buf, new_pref, exist_pref); | |
9fbdd100 DS |
422 | return 1; |
423 | } | |
424 | ||
718e3744 | 425 | if (new_pref < exist_pref) |
9fbdd100 DS |
426 | { |
427 | if (debug) | |
2ec1e66f DW |
428 | zlog_debug("%s: %s loses to %s due to localpref %d < %d", |
429 | pfx_buf, new_buf, exist_buf, new_pref, exist_pref); | |
9fbdd100 DS |
430 | return 0; |
431 | } | |
718e3744 | 432 | |
8ff56318 JBD |
433 | /* 3. Local route check. We prefer: |
434 | * - BGP_ROUTE_STATIC | |
435 | * - BGP_ROUTE_AGGREGATE | |
436 | * - BGP_ROUTE_REDISTRIBUTE | |
437 | */ | |
438 | if (! (new->sub_type == BGP_ROUTE_NORMAL)) | |
9fbdd100 DS |
439 | { |
440 | if (debug) | |
2ec1e66f DW |
441 | zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type", |
442 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
443 | return 1; |
444 | } | |
445 | ||
8ff56318 | 446 | if (! (exist->sub_type == BGP_ROUTE_NORMAL)) |
9fbdd100 DS |
447 | { |
448 | if (debug) | |
2ec1e66f DW |
449 | zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type", |
450 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
451 | return 0; |
452 | } | |
718e3744 | 453 | |
454 | /* 4. AS path length check. */ | |
455 | if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE)) | |
456 | { | |
8ff56318 JBD |
457 | int exist_hops = aspath_count_hops (existattr->aspath); |
458 | int exist_confeds = aspath_count_confeds (existattr->aspath); | |
fe69a505 | 459 | |
6811845b | 460 | if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED)) |
461 | { | |
fe69a505 | 462 | int aspath_hops; |
463 | ||
8ff56318 JBD |
464 | aspath_hops = aspath_count_hops (newattr->aspath); |
465 | aspath_hops += aspath_count_confeds (newattr->aspath); | |
fe69a505 | 466 | |
467 | if ( aspath_hops < (exist_hops + exist_confeds)) | |
9fbdd100 DS |
468 | { |
469 | if (debug) | |
2ec1e66f DW |
470 | zlog_debug("%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d", |
471 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
472 | aspath_hops, (exist_hops + exist_confeds)); |
473 | return 1; | |
474 | } | |
475 | ||
fe69a505 | 476 | if ( aspath_hops > (exist_hops + exist_confeds)) |
9fbdd100 DS |
477 | { |
478 | if (debug) | |
2ec1e66f DW |
479 | zlog_debug("%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d", |
480 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
481 | aspath_hops, (exist_hops + exist_confeds)); |
482 | return 0; | |
483 | } | |
6811845b | 484 | } |
485 | else | |
486 | { | |
8ff56318 | 487 | int newhops = aspath_count_hops (newattr->aspath); |
fe69a505 | 488 | |
489 | if (newhops < exist_hops) | |
9fbdd100 DS |
490 | { |
491 | if (debug) | |
2ec1e66f DW |
492 | zlog_debug("%s: %s wins over %s due to aspath hopcount %d < %d", |
493 | pfx_buf, new_buf, exist_buf, newhops, exist_hops); | |
9fbdd100 DS |
494 | return 1; |
495 | } | |
496 | ||
fe69a505 | 497 | if (newhops > exist_hops) |
9fbdd100 DS |
498 | { |
499 | if (debug) | |
2ec1e66f DW |
500 | zlog_debug("%s: %s loses to %s due to aspath hopcount %d > %d", |
501 | pfx_buf, new_buf, exist_buf, newhops, exist_hops); | |
9fbdd100 DS |
502 | return 0; |
503 | } | |
6811845b | 504 | } |
718e3744 | 505 | } |
506 | ||
507 | /* 5. Origin check. */ | |
8ff56318 | 508 | if (newattr->origin < existattr->origin) |
9fbdd100 DS |
509 | { |
510 | if (debug) | |
2ec1e66f DW |
511 | zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s", |
512 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
513 | bgp_origin_long_str[newattr->origin], |
514 | bgp_origin_long_str[existattr->origin]); | |
515 | return 1; | |
516 | } | |
517 | ||
8ff56318 | 518 | if (newattr->origin > existattr->origin) |
9fbdd100 DS |
519 | { |
520 | if (debug) | |
2ec1e66f DW |
521 | zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s", |
522 | pfx_buf, new_buf, exist_buf, | |
9fbdd100 DS |
523 | bgp_origin_long_str[newattr->origin], |
524 | bgp_origin_long_str[existattr->origin]); | |
525 | return 0; | |
526 | } | |
718e3744 | 527 | |
528 | /* 6. MED check. */ | |
8ff56318 JBD |
529 | internal_as_route = (aspath_count_hops (newattr->aspath) == 0 |
530 | && aspath_count_hops (existattr->aspath) == 0); | |
531 | confed_as_route = (aspath_count_confeds (newattr->aspath) > 0 | |
532 | && aspath_count_confeds (existattr->aspath) > 0 | |
533 | && aspath_count_hops (newattr->aspath) == 0 | |
534 | && aspath_count_hops (existattr->aspath) == 0); | |
718e3744 | 535 | |
536 | if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED) | |
537 | || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED) | |
538 | && confed_as_route) | |
8ff56318 JBD |
539 | || aspath_cmp_left (newattr->aspath, existattr->aspath) |
540 | || aspath_cmp_left_confed (newattr->aspath, existattr->aspath) | |
718e3744 | 541 | || internal_as_route) |
542 | { | |
543 | new_med = bgp_med_value (new->attr, bgp); | |
544 | exist_med = bgp_med_value (exist->attr, bgp); | |
545 | ||
546 | if (new_med < exist_med) | |
9fbdd100 DS |
547 | { |
548 | if (debug) | |
2ec1e66f DW |
549 | zlog_debug("%s: %s wins over %s due to MED %d < %d", |
550 | pfx_buf, new_buf, exist_buf, new_med, exist_med); | |
9fbdd100 DS |
551 | return 1; |
552 | } | |
553 | ||
718e3744 | 554 | if (new_med > exist_med) |
9fbdd100 DS |
555 | { |
556 | if (debug) | |
2ec1e66f DW |
557 | zlog_debug("%s: %s loses to %s due to MED %d > %d", |
558 | pfx_buf, new_buf, exist_buf, new_med, exist_med); | |
9fbdd100 DS |
559 | return 0; |
560 | } | |
718e3744 | 561 | } |
562 | ||
563 | /* 7. Peer type check. */ | |
8ff56318 JBD |
564 | new_sort = new->peer->sort; |
565 | exist_sort = exist->peer->sort; | |
566 | ||
567 | if (new_sort == BGP_PEER_EBGP | |
568 | && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) | |
9fbdd100 DS |
569 | { |
570 | if (debug) | |
2ec1e66f DW |
571 | zlog_debug("%s: %s wins over %s due to eBGP peer > iBGP peer", |
572 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
573 | return 1; |
574 | } | |
575 | ||
8ff56318 JBD |
576 | if (exist_sort == BGP_PEER_EBGP |
577 | && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED)) | |
9fbdd100 DS |
578 | { |
579 | if (debug) | |
2ec1e66f DW |
580 | zlog_debug("%s: %s loses to %s due to iBGP peer < eBGP peer", |
581 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
582 | return 0; |
583 | } | |
718e3744 | 584 | |
585 | /* 8. IGP metric check. */ | |
8ff56318 JBD |
586 | newm = existm = 0; |
587 | ||
588 | if (new->extra) | |
589 | newm = new->extra->igpmetric; | |
590 | if (exist->extra) | |
591 | existm = exist->extra->igpmetric; | |
592 | ||
96450faf | 593 | if (newm < existm) |
9fbdd100 DS |
594 | { |
595 | if (debug) | |
2ec1e66f DW |
596 | zlog_debug("%s: %s wins over %s due to IGP metric %d < %d", |
597 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
598 | ret = 1; |
599 | } | |
600 | ||
96450faf | 601 | if (newm > existm) |
9fbdd100 DS |
602 | { |
603 | if (debug) | |
2ec1e66f DW |
604 | zlog_debug("%s: %s loses to %s due to IGP metric %d > %d", |
605 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
606 | ret = 0; |
607 | } | |
718e3744 | 608 | |
31a4638f | 609 | /* 9. Same IGP metric. Compare the cluster list length as |
5e242b0d DS |
610 | representative of IGP hops metric. Rewrite the metric value |
611 | pair (newm, existm) with the cluster list length. Prefer the | |
612 | path with smaller cluster list length. */ | |
613 | if (newm == existm) | |
614 | { | |
615 | if (peer_sort (new->peer) == BGP_PEER_IBGP | |
616 | && peer_sort (exist->peer) == BGP_PEER_IBGP | |
617 | && CHECK_FLAG (mpath_cfg->ibgp_flags, | |
618 | BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN)) | |
619 | { | |
620 | newm = BGP_CLUSTER_LIST_LENGTH(new->attr); | |
621 | existm = BGP_CLUSTER_LIST_LENGTH(exist->attr); | |
9fbdd100 | 622 | |
5e242b0d | 623 | if (newm < existm) |
9fbdd100 DS |
624 | { |
625 | if (debug) | |
2ec1e66f DW |
626 | zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d", |
627 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
628 | ret = 1; |
629 | } | |
630 | ||
5e242b0d | 631 | if (newm > existm) |
9fbdd100 DS |
632 | { |
633 | if (debug) | |
2ec1e66f DW |
634 | zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d", |
635 | pfx_buf, new_buf, exist_buf, newm, existm); | |
9fbdd100 DS |
636 | ret = 0; |
637 | } | |
5e242b0d DS |
638 | } |
639 | } | |
640 | ||
31a4638f DS |
641 | /* 10. confed-external vs. confed-internal */ |
642 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) | |
643 | { | |
644 | if (new_sort == BGP_PEER_CONFED && exist_sort == BGP_PEER_IBGP) | |
645 | { | |
646 | if (debug) | |
2ec1e66f DW |
647 | zlog_debug("%s: %s wins over %s due to confed-external peer > confed-internal peer", |
648 | pfx_buf, new_buf, exist_buf); | |
31a4638f DS |
649 | return 1; |
650 | } | |
651 | ||
652 | if (exist_sort == BGP_PEER_CONFED && new_sort == BGP_PEER_IBGP) | |
653 | { | |
654 | if (debug) | |
2ec1e66f DW |
655 | zlog_debug("%s: %s loses to %s due to confed-internal peer < confed-external peer", |
656 | pfx_buf, new_buf, exist_buf); | |
31a4638f DS |
657 | return 0; |
658 | } | |
659 | } | |
660 | ||
661 | /* 11. Maximum path check. */ | |
96450faf JB |
662 | if (newm == existm) |
663 | { | |
2fdd455c PM |
664 | if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) |
665 | { | |
666 | ||
667 | /* | |
668 | * For the two paths, all comparison steps till IGP metric | |
669 | * have succeeded - including AS_PATH hop count. Since 'bgp | |
670 | * bestpath as-path multipath-relax' knob is on, we don't need | |
671 | * an exact match of AS_PATH. Thus, mark the paths are equal. | |
672 | * That will trigger both these paths to get into the multipath | |
673 | * array. | |
674 | */ | |
675 | *paths_eq = 1; | |
9fbdd100 DS |
676 | |
677 | if (debug) | |
2ec1e66f DW |
678 | zlog_debug("%s: %s and %s are equal via multipath-relax", |
679 | pfx_buf, new_buf, exist_buf); | |
2fdd455c PM |
680 | } |
681 | else if (new->peer->sort == BGP_PEER_IBGP) | |
96450faf JB |
682 | { |
683 | if (aspath_cmp (new->attr->aspath, exist->attr->aspath)) | |
9fbdd100 DS |
684 | { |
685 | *paths_eq = 1; | |
686 | ||
687 | if (debug) | |
2ec1e66f DW |
688 | zlog_debug("%s: %s and %s are equal via matching aspaths", |
689 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 | 690 | } |
96450faf JB |
691 | } |
692 | else if (new->peer->as == exist->peer->as) | |
9fbdd100 DS |
693 | { |
694 | *paths_eq = 1; | |
695 | ||
696 | if (debug) | |
2ec1e66f DW |
697 | zlog_debug("%s: %s and %s are equal via same remote-as", |
698 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 | 699 | } |
96450faf JB |
700 | } |
701 | else | |
702 | { | |
703 | /* | |
704 | * TODO: If unequal cost ibgp multipath is enabled we can | |
705 | * mark the paths as equal here instead of returning | |
706 | */ | |
707 | return ret; | |
708 | } | |
718e3744 | 709 | |
31a4638f | 710 | /* 12. If both paths are external, prefer the path that was received |
718e3744 | 711 | first (the oldest one). This step minimizes route-flap, since a |
712 | newer path won't displace an older one, even if it was the | |
713 | preferred route based on the additional decision criteria below. */ | |
714 | if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID) | |
8ff56318 JBD |
715 | && new_sort == BGP_PEER_EBGP |
716 | && exist_sort == BGP_PEER_EBGP) | |
718e3744 | 717 | { |
718 | if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED)) | |
9fbdd100 DS |
719 | { |
720 | if (debug) | |
2ec1e66f DW |
721 | zlog_debug("%s: %s wins over %s due to oldest external", |
722 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
723 | return 1; |
724 | } | |
725 | ||
718e3744 | 726 | if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED)) |
9fbdd100 DS |
727 | { |
728 | if (debug) | |
2ec1e66f DW |
729 | zlog_debug("%s: %s loses to %s due to oldest external", |
730 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
731 | return 0; |
732 | } | |
718e3744 | 733 | } |
734 | ||
31a4638f | 735 | /* 13. Router-ID comparision. */ |
0de5153c DS |
736 | /* If one of the paths is "stale", the corresponding peer router-id will |
737 | * be 0 and would always win over the other path. If originator id is | |
738 | * used for the comparision, it will decide which path is better. | |
739 | */ | |
8ff56318 JBD |
740 | if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
741 | new_id.s_addr = newattre->originator_id.s_addr; | |
718e3744 | 742 | else |
743 | new_id.s_addr = new->peer->remote_id.s_addr; | |
8ff56318 JBD |
744 | if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
745 | exist_id.s_addr = existattre->originator_id.s_addr; | |
718e3744 | 746 | else |
747 | exist_id.s_addr = exist->peer->remote_id.s_addr; | |
748 | ||
749 | if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr)) | |
9fbdd100 DS |
750 | { |
751 | if (debug) | |
2ec1e66f DW |
752 | zlog_debug("%s: %s wins over %s due to Router-ID comparison", |
753 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
754 | return 1; |
755 | } | |
756 | ||
718e3744 | 757 | if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr)) |
9fbdd100 DS |
758 | { |
759 | if (debug) | |
2ec1e66f DW |
760 | zlog_debug("%s: %s loses to %s due to Router-ID comparison", |
761 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
762 | return 0; |
763 | } | |
718e3744 | 764 | |
31a4638f | 765 | /* 14. Cluster length comparision. */ |
5e242b0d DS |
766 | new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr); |
767 | exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr); | |
718e3744 | 768 | |
769 | if (new_cluster < exist_cluster) | |
9fbdd100 DS |
770 | { |
771 | if (debug) | |
2ec1e66f DW |
772 | zlog_debug("%s: %s wins over %s due to CLUSTER_LIST length %d < %d", |
773 | pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster); | |
9fbdd100 DS |
774 | return 1; |
775 | } | |
776 | ||
718e3744 | 777 | if (new_cluster > exist_cluster) |
9fbdd100 DS |
778 | { |
779 | if (debug) | |
2ec1e66f DW |
780 | zlog_debug("%s: %s loses to %s due to CLUSTER_LIST length %d > %d", |
781 | pfx_buf, new_buf, exist_buf, new_cluster, exist_cluster); | |
9fbdd100 DS |
782 | return 0; |
783 | } | |
718e3744 | 784 | |
31a4638f | 785 | /* 15. Neighbor address comparision. */ |
0de5153c DS |
786 | /* Do this only if neither path is "stale" as stale paths do not have |
787 | * valid peer information (as the connection may or may not be up). | |
788 | */ | |
789 | if (CHECK_FLAG (exist->flags, BGP_INFO_STALE)) | |
9fbdd100 DS |
790 | { |
791 | if (debug) | |
2ec1e66f DW |
792 | zlog_debug("%s: %s wins over %s due to latter path being STALE", |
793 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
794 | return 1; |
795 | } | |
796 | ||
0de5153c | 797 | if (CHECK_FLAG (new->flags, BGP_INFO_STALE)) |
9fbdd100 DS |
798 | { |
799 | if (debug) | |
2ec1e66f DW |
800 | zlog_debug("%s: %s loses to %s due to former path being STALE", |
801 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
802 | return 0; |
803 | } | |
0de5153c | 804 | |
718e3744 | 805 | ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote); |
806 | ||
807 | if (ret == 1) | |
9fbdd100 DS |
808 | { |
809 | if (debug) | |
2ec1e66f DW |
810 | zlog_debug("%s: %s loses to %s due to Neighor IP comparison", |
811 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
812 | return 0; |
813 | } | |
814 | ||
718e3744 | 815 | if (ret == -1) |
9fbdd100 DS |
816 | { |
817 | if (debug) | |
2ec1e66f DW |
818 | zlog_debug("%s: %s wins over %s due to Neighor IP comparison", |
819 | pfx_buf, new_buf, exist_buf); | |
9fbdd100 DS |
820 | return 1; |
821 | } | |
822 | ||
823 | if (debug) | |
2ec1e66f DW |
824 | zlog_debug("%s: %s wins over %s due to nothing left to compare", |
825 | pfx_buf, new_buf, exist_buf); | |
718e3744 | 826 | |
827 | return 1; | |
828 | } | |
829 | ||
94f2b392 | 830 | static enum filter_type |
718e3744 | 831 | bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
832 | afi_t afi, safi_t safi) | |
833 | { | |
834 | struct bgp_filter *filter; | |
835 | ||
836 | filter = &peer->filter[afi][safi]; | |
837 | ||
650f76c2 PJ |
838 | #define FILTER_EXIST_WARN(F,f,filter) \ |
839 | if (BGP_DEBUG (update, UPDATE_IN) \ | |
840 | && !(F ## _IN (filter))) \ | |
16286195 | 841 | zlog_warn ("%s: Could not find configured input %s-list %s!", \ |
650f76c2 PJ |
842 | peer->host, #f, F ## _IN_NAME(filter)); |
843 | ||
844 | if (DISTRIBUTE_IN_NAME (filter)) { | |
845 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); | |
846 | ||
718e3744 | 847 | if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY) |
848 | return FILTER_DENY; | |
650f76c2 | 849 | } |
718e3744 | 850 | |
650f76c2 PJ |
851 | if (PREFIX_LIST_IN_NAME (filter)) { |
852 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); | |
853 | ||
718e3744 | 854 | if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY) |
855 | return FILTER_DENY; | |
650f76c2 | 856 | } |
718e3744 | 857 | |
650f76c2 PJ |
858 | if (FILTER_LIST_IN_NAME (filter)) { |
859 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); | |
860 | ||
718e3744 | 861 | if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY) |
862 | return FILTER_DENY; | |
650f76c2 PJ |
863 | } |
864 | ||
718e3744 | 865 | return FILTER_PERMIT; |
650f76c2 | 866 | #undef FILTER_EXIST_WARN |
718e3744 | 867 | } |
868 | ||
94f2b392 | 869 | static enum filter_type |
718e3744 | 870 | bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
871 | afi_t afi, safi_t safi) | |
872 | { | |
873 | struct bgp_filter *filter; | |
874 | ||
875 | filter = &peer->filter[afi][safi]; | |
876 | ||
650f76c2 PJ |
877 | #define FILTER_EXIST_WARN(F,f,filter) \ |
878 | if (BGP_DEBUG (update, UPDATE_OUT) \ | |
879 | && !(F ## _OUT (filter))) \ | |
16286195 | 880 | zlog_warn ("%s: Could not find configured output %s-list %s!", \ |
650f76c2 PJ |
881 | peer->host, #f, F ## _OUT_NAME(filter)); |
882 | ||
883 | if (DISTRIBUTE_OUT_NAME (filter)) { | |
884 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); | |
885 | ||
718e3744 | 886 | if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY) |
887 | return FILTER_DENY; | |
650f76c2 | 888 | } |
718e3744 | 889 | |
650f76c2 PJ |
890 | if (PREFIX_LIST_OUT_NAME (filter)) { |
891 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); | |
892 | ||
718e3744 | 893 | if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY) |
894 | return FILTER_DENY; | |
650f76c2 | 895 | } |
718e3744 | 896 | |
650f76c2 PJ |
897 | if (FILTER_LIST_OUT_NAME (filter)) { |
898 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); | |
899 | ||
718e3744 | 900 | if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY) |
901 | return FILTER_DENY; | |
650f76c2 | 902 | } |
718e3744 | 903 | |
904 | return FILTER_PERMIT; | |
650f76c2 | 905 | #undef FILTER_EXIST_WARN |
718e3744 | 906 | } |
907 | ||
908 | /* If community attribute includes no_export then return 1. */ | |
94f2b392 | 909 | static int |
718e3744 | 910 | bgp_community_filter (struct peer *peer, struct attr *attr) |
911 | { | |
912 | if (attr->community) | |
913 | { | |
914 | /* NO_ADVERTISE check. */ | |
915 | if (community_include (attr->community, COMMUNITY_NO_ADVERTISE)) | |
916 | return 1; | |
917 | ||
918 | /* NO_EXPORT check. */ | |
6d85b15b | 919 | if (peer->sort == BGP_PEER_EBGP && |
718e3744 | 920 | community_include (attr->community, COMMUNITY_NO_EXPORT)) |
921 | return 1; | |
922 | ||
923 | /* NO_EXPORT_SUBCONFED check. */ | |
6d85b15b JBD |
924 | if (peer->sort == BGP_PEER_EBGP |
925 | || peer->sort == BGP_PEER_CONFED) | |
718e3744 | 926 | if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED)) |
927 | return 1; | |
928 | } | |
929 | return 0; | |
930 | } | |
931 | ||
932 | /* Route reflection loop check. */ | |
933 | static int | |
934 | bgp_cluster_filter (struct peer *peer, struct attr *attr) | |
935 | { | |
936 | struct in_addr cluster_id; | |
937 | ||
fb982c25 | 938 | if (attr->extra && attr->extra->cluster) |
718e3744 | 939 | { |
940 | if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID) | |
941 | cluster_id = peer->bgp->cluster_id; | |
942 | else | |
943 | cluster_id = peer->bgp->router_id; | |
944 | ||
fb982c25 | 945 | if (cluster_loop_check (attr->extra->cluster, cluster_id)) |
718e3744 | 946 | return 1; |
947 | } | |
948 | return 0; | |
949 | } | |
6b0655a2 | 950 | |
94f2b392 | 951 | static int |
718e3744 | 952 | bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr, |
ffd0c037 | 953 | afi_t afi, safi_t safi, const char *rmap_name) |
718e3744 | 954 | { |
955 | struct bgp_filter *filter; | |
956 | struct bgp_info info; | |
957 | route_map_result_t ret; | |
0b16f239 | 958 | struct route_map *rmap = NULL; |
718e3744 | 959 | |
960 | filter = &peer->filter[afi][safi]; | |
961 | ||
962 | /* Apply default weight value. */ | |
fb982c25 PJ |
963 | if (peer->weight) |
964 | (bgp_attr_extra_get (attr))->weight = peer->weight; | |
718e3744 | 965 | |
0b16f239 DS |
966 | if (rmap_name) |
967 | { | |
968 | rmap = route_map_lookup_by_name(rmap_name); | |
98a4a44e DS |
969 | |
970 | if (rmap == NULL) | |
971 | return RMAP_DENY; | |
0b16f239 DS |
972 | } |
973 | else | |
974 | { | |
975 | if (ROUTE_MAP_IN_NAME(filter)) | |
98a4a44e DS |
976 | { |
977 | rmap = ROUTE_MAP_IN (filter); | |
978 | ||
979 | if (rmap == NULL) | |
980 | return RMAP_DENY; | |
981 | } | |
0b16f239 DS |
982 | } |
983 | ||
718e3744 | 984 | /* Route map apply. */ |
0b16f239 | 985 | if (rmap) |
718e3744 | 986 | { |
987 | /* Duplicate current value to new strucutre for modification. */ | |
988 | info.peer = peer; | |
989 | info.attr = attr; | |
990 | ||
ac41b2a2 | 991 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN); |
992 | ||
718e3744 | 993 | /* Apply BGP route map to the attribute. */ |
0b16f239 DS |
994 | ret = route_map_apply (rmap, p, RMAP_BGP, &info); |
995 | ||
996 | peer->rmap_type = 0; | |
997 | ||
998 | if (ret == RMAP_DENYMATCH) | |
999 | { | |
1000 | /* Free newly generated AS path and community by route-map. */ | |
1001 | bgp_attr_flush (attr); | |
1002 | return RMAP_DENY; | |
1003 | } | |
1004 | } | |
1005 | return RMAP_PERMIT; | |
1006 | } | |
1007 | ||
1008 | static int | |
1009 | bgp_output_modifier (struct peer *peer, struct prefix *p, struct attr *attr, | |
ffd0c037 | 1010 | afi_t afi, safi_t safi, const char *rmap_name) |
0b16f239 DS |
1011 | { |
1012 | struct bgp_filter *filter; | |
1013 | struct bgp_info info; | |
1014 | route_map_result_t ret; | |
1015 | struct route_map *rmap = NULL; | |
1016 | ||
1017 | filter = &peer->filter[afi][safi]; | |
1018 | ||
1019 | /* Apply default weight value. */ | |
1020 | if (peer->weight) | |
1021 | (bgp_attr_extra_get (attr))->weight = peer->weight; | |
1022 | ||
1023 | if (rmap_name) | |
1024 | { | |
1025 | rmap = route_map_lookup_by_name(rmap_name); | |
98a4a44e DS |
1026 | |
1027 | if (rmap == NULL) | |
1028 | return RMAP_DENY; | |
0b16f239 DS |
1029 | } |
1030 | else | |
1031 | { | |
1032 | if (ROUTE_MAP_OUT_NAME(filter)) | |
98a4a44e DS |
1033 | { |
1034 | rmap = ROUTE_MAP_OUT (filter); | |
1035 | ||
1036 | if (rmap == NULL) | |
1037 | return RMAP_DENY; | |
1038 | } | |
0b16f239 DS |
1039 | } |
1040 | ||
1041 | /* Route map apply. */ | |
1042 | if (rmap) | |
1043 | { | |
1044 | /* Duplicate current value to new strucutre for modification. */ | |
1045 | info.peer = peer; | |
1046 | info.attr = attr; | |
1047 | ||
1048 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); | |
1049 | ||
1050 | /* Apply BGP route map to the attribute. */ | |
1051 | ret = route_map_apply (rmap, p, RMAP_BGP, &info); | |
ac41b2a2 | 1052 | |
1053 | peer->rmap_type = 0; | |
1054 | ||
718e3744 | 1055 | if (ret == RMAP_DENYMATCH) |
c460e572 DL |
1056 | /* caller has multiple error paths with bgp_attr_flush() */ |
1057 | return RMAP_DENY; | |
718e3744 | 1058 | } |
1059 | return RMAP_PERMIT; | |
1060 | } | |
6b0655a2 | 1061 | |
5000f21c | 1062 | /* If this is an EBGP peer with remove-private-AS */ |
ffd0c037 | 1063 | static void |
5000f21c DS |
1064 | bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi, |
1065 | struct peer *peer, struct attr *attr) | |
1066 | { | |
1067 | if (peer->sort == BGP_PEER_EBGP && | |
88b8ed8d DW |
1068 | (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) || |
1069 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) || | |
1070 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL) || | |
1071 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS))) | |
5000f21c DS |
1072 | { |
1073 | // Take action on the entire aspath | |
88b8ed8d DW |
1074 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE) || |
1075 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) | |
5000f21c | 1076 | { |
88b8ed8d | 1077 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)) |
5000f21c DS |
1078 | attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as); |
1079 | ||
1080 | // The entire aspath consists of private ASNs so create an empty aspath | |
1081 | else if (aspath_private_as_check (attr->aspath)) | |
1082 | attr->aspath = aspath_empty_get (); | |
1083 | ||
1084 | // There are some public and some private ASNs, remove the private ASNs | |
1085 | else | |
1086 | attr->aspath = aspath_remove_private_asns (attr->aspath); | |
1087 | } | |
1088 | ||
1089 | // 'all' was not specified so the entire aspath must be private ASNs | |
1090 | // for us to do anything | |
1091 | else if (aspath_private_as_check (attr->aspath)) | |
1092 | { | |
1093 | if (peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)) | |
1094 | attr->aspath = aspath_replace_private_asns (attr->aspath, bgp->as); | |
1095 | else | |
1096 | attr->aspath = aspath_empty_get (); | |
1097 | } | |
1098 | } | |
1099 | } | |
1100 | ||
c7122e14 DS |
1101 | /* If this is an EBGP peer with as-override */ |
1102 | static void | |
1103 | bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi, | |
1104 | struct peer *peer, struct attr *attr) | |
1105 | { | |
1106 | if (peer->sort == BGP_PEER_EBGP && | |
1107 | peer_af_flag_check (peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) | |
1108 | { | |
1109 | if (aspath_single_asn_check (attr->aspath, peer->as)) | |
1110 | attr->aspath = aspath_replace_specific_asn (attr->aspath, peer->as, bgp->as); | |
1111 | } | |
1112 | } | |
1113 | ||
3f9c7369 DS |
1114 | static void |
1115 | subgroup_announce_reset_nhop (u_char family, struct attr *attr) | |
1116 | { | |
1117 | if (family == AF_INET) | |
1118 | attr->nexthop.s_addr = 0; | |
1119 | #ifdef HAVE_IPV6 | |
1120 | if (family == AF_INET6) | |
1121 | memset (&attr->extra->mp_nexthop_global, 0, IPV6_MAX_BYTELEN); | |
1122 | #endif | |
1123 | } | |
1124 | ||
1125 | int | |
1126 | subgroup_announce_check (struct bgp_info *ri, struct update_subgroup *subgrp, | |
1127 | struct prefix *p, struct attr *attr) | |
1128 | { | |
1129 | struct bgp_filter *filter; | |
1130 | struct peer *from; | |
1131 | struct peer *peer; | |
1132 | struct peer *onlypeer; | |
1133 | struct bgp *bgp; | |
1134 | struct attr *riattr; | |
1135 | struct peer_af *paf; | |
1136 | char buf[SU_ADDRSTRLEN]; | |
1137 | int ret; | |
1138 | int transparent; | |
1139 | int reflect; | |
1140 | afi_t afi; | |
1141 | safi_t safi; | |
1142 | ||
1143 | if (DISABLE_BGP_ANNOUNCE) | |
1144 | return 0; | |
1145 | ||
1146 | afi = SUBGRP_AFI(subgrp); | |
1147 | safi = SUBGRP_SAFI(subgrp); | |
1148 | peer = SUBGRP_PEER(subgrp); | |
1149 | onlypeer = NULL; | |
1150 | if (CHECK_FLAG (peer->flags, PEER_FLAG_LONESOUL)) | |
1151 | onlypeer = SUBGRP_PFIRST(subgrp)->peer; | |
1152 | ||
1153 | from = ri->peer; | |
1154 | filter = &peer->filter[afi][safi]; | |
1155 | bgp = SUBGRP_INST(subgrp); | |
1156 | riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr; | |
1157 | ||
adbac85e DW |
1158 | /* With addpath we may be asked to TX all kinds of paths so make sure |
1159 | * ri is valid */ | |
1160 | if (!CHECK_FLAG (ri->flags, BGP_INFO_VALID) || | |
1161 | CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) || | |
1162 | CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)) | |
1163 | { | |
1164 | return 0; | |
1165 | } | |
1166 | ||
06370dac DW |
1167 | /* If this is not the bestpath then check to see if there is an enabled addpath |
1168 | * feature that requires us to advertise it */ | |
1169 | if (! CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
1170 | { | |
1171 | if (! bgp_addpath_tx_path(peer, afi, safi, ri)) | |
1172 | { | |
1173 | return 0; | |
1174 | } | |
1175 | } | |
1176 | ||
3f9c7369 DS |
1177 | /* Aggregate-address suppress check. */ |
1178 | if (ri->extra && ri->extra->suppress) | |
1179 | if (! UNSUPPRESS_MAP_NAME (filter)) | |
1180 | { | |
1181 | return 0; | |
1182 | } | |
1183 | ||
3f9c7369 DS |
1184 | /* Do not send back route to sender. */ |
1185 | if (onlypeer && from == onlypeer) | |
1186 | { | |
1187 | return 0; | |
1188 | } | |
1189 | ||
4125bb67 DS |
1190 | /* Do not send the default route in the BGP table if the neighbor is |
1191 | * configured for default-originate */ | |
1192 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) | |
1193 | { | |
1194 | if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) | |
1195 | return 0; | |
1196 | #ifdef HAVE_IPV6 | |
1197 | else if (p->family == AF_INET6 && p->prefixlen == 0) | |
1198 | return 0; | |
1199 | #endif /* HAVE_IPV6 */ | |
1200 | } | |
1201 | ||
3f9c7369 DS |
1202 | /* Transparency check. */ |
1203 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) | |
1204 | && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) | |
1205 | transparent = 1; | |
1206 | else | |
1207 | transparent = 0; | |
1208 | ||
1209 | /* If community is not disabled check the no-export and local. */ | |
1210 | if (! transparent && bgp_community_filter (peer, riattr)) | |
1211 | { | |
1212 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1213 | zlog_debug ("subgrpannouncecheck: community filter check fail"); | |
1214 | return 0; | |
1215 | } | |
1216 | ||
1217 | /* If the attribute has originator-id and it is same as remote | |
1218 | peer's id. */ | |
1219 | if (onlypeer && | |
1220 | riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) && | |
1221 | (IPV4_ADDR_SAME (&onlypeer->remote_id, &riattr->extra->originator_id))) | |
1222 | { | |
1223 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1224 | zlog_debug ("%s [Update:SEND] %s/%d originator-id is same as " | |
1225 | "remote router-id", | |
1226 | onlypeer->host, | |
1227 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1228 | p->prefixlen); | |
1229 | return 0; | |
1230 | } | |
1231 | ||
1232 | /* ORF prefix-list filter check */ | |
1233 | if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) | |
1234 | && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) | |
1235 | || CHECK_FLAG (peer->af_cap[afi][safi], | |
1236 | PEER_CAP_ORF_PREFIX_SM_OLD_RCV))) | |
1237 | if (peer->orf_plist[afi][safi]) | |
1238 | { | |
1239 | if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY) | |
1240 | { | |
40d2700d DW |
1241 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) |
1242 | zlog_debug ("%s [Update:SEND] %s/%d is filtered via ORF", | |
1243 | peer->host, | |
1244 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1245 | p->prefixlen); | |
3f9c7369 DS |
1246 | return 0; |
1247 | } | |
1248 | } | |
1249 | ||
1250 | /* Output filter check. */ | |
1251 | if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY) | |
1252 | { | |
1253 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1254 | zlog_debug ("%s [Update:SEND] %s/%d is filtered", | |
1255 | peer->host, | |
1256 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
1257 | p->prefixlen); | |
1258 | return 0; | |
1259 | } | |
1260 | ||
1261 | #ifdef BGP_SEND_ASPATH_CHECK | |
1262 | /* AS path loop check. */ | |
1263 | if (onlypeer && aspath_loop_check (riattr->aspath, onlypeer->as)) | |
1264 | { | |
1265 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1266 | zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u " | |
1267 | "that is part of AS path.", | |
1268 | onlypeer->host, onlypeer->as); | |
1269 | return 0; | |
1270 | } | |
1271 | #endif /* BGP_SEND_ASPATH_CHECK */ | |
1272 | ||
1273 | /* If we're a CONFED we need to loop check the CONFED ID too */ | |
1274 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) | |
1275 | { | |
1276 | if (aspath_loop_check(riattr->aspath, bgp->confed_id)) | |
1277 | { | |
1278 | if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) | |
1279 | zlog_debug ("%s [Update:SEND] suppress announcement to peer AS %u" | |
1280 | " is AS path.", | |
1281 | peer->host, | |
1282 | bgp->confed_id); | |
1283 | return 0; | |
1284 | } | |
1285 | } | |
1286 | ||
1287 | /* Route-Reflect check. */ | |
1288 | if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) | |
1289 | reflect = 1; | |
1290 | else | |
1291 | reflect = 0; | |
1292 | ||
1293 | /* IBGP reflection check. */ | |
1294 | if (reflect) | |
1295 | { | |
1296 | /* A route from a Client peer. */ | |
1297 | if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) | |
1298 | { | |
1299 | /* Reflect to all the Non-Client peers and also to the | |
1300 | Client peers other than the originator. Originator check | |
1301 | is already done. So there is noting to do. */ | |
1302 | /* no bgp client-to-client reflection check. */ | |
1303 | if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT)) | |
1304 | if (CHECK_FLAG (peer->af_flags[afi][safi], | |
1305 | PEER_FLAG_REFLECTOR_CLIENT)) | |
1306 | return 0; | |
1307 | } | |
1308 | else | |
1309 | { | |
1310 | /* A route from a Non-client peer. Reflect to all other | |
1311 | clients. */ | |
1312 | if (! CHECK_FLAG (peer->af_flags[afi][safi], | |
1313 | PEER_FLAG_REFLECTOR_CLIENT)) | |
1314 | return 0; | |
1315 | } | |
1316 | } | |
1317 | ||
1318 | /* For modify attribute, copy it to temporary structure. */ | |
1319 | bgp_attr_dup (attr, riattr); | |
1320 | ||
1321 | /* If local-preference is not set. */ | |
1322 | if ((peer->sort == BGP_PEER_IBGP | |
1323 | || peer->sort == BGP_PEER_CONFED) | |
1324 | && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))) | |
1325 | { | |
1326 | attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF); | |
1327 | attr->local_pref = bgp->default_local_pref; | |
1328 | } | |
1329 | ||
1330 | /* If originator-id is not set and the route is to be reflected, | |
1331 | set the originator id */ | |
1332 | if (reflect && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))) | |
1333 | { | |
1334 | attr->extra = bgp_attr_extra_get(attr); | |
1335 | IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id)); | |
1336 | SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID); | |
1337 | } | |
1338 | ||
1339 | /* Remove MED if its an EBGP peer - will get overwritten by route-maps */ | |
1340 | if (peer->sort == BGP_PEER_EBGP | |
1341 | && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
1342 | { | |
003c1ba0 | 1343 | if (from != bgp->peer_self && ! transparent |
3f9c7369 DS |
1344 | && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED)) |
1345 | attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)); | |
1346 | } | |
1347 | ||
1348 | /* Since the nexthop attribute can vary per peer, it is not explicitly set | |
1349 | * in announce check, only certain flags and length (or number of nexthops | |
1350 | * -- for IPv6/MP_REACH) are set here in order to guide the update formation | |
1351 | * code in setting the nexthop(s) on a per peer basis in reformat_peer(). | |
1352 | * Typically, the source nexthop in the attribute is preserved but in the | |
1353 | * scenarios where we know it will always be overwritten, we reset the | |
1354 | * nexthop to "0" in an attempt to achieve better Update packing. An | |
1355 | * example of this is when a prefix from each of 2 IBGP peers needs to be | |
1356 | * announced to an EBGP peer (and they have the same attributes barring | |
1357 | * their nexthop). | |
1358 | */ | |
1359 | if (reflect) | |
1360 | SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED); | |
1361 | ||
1362 | #ifdef HAVE_IPV6 | |
3811f1e2 DS |
1363 | /* IPv6/MP starts with 1 nexthop. The link-local address is passed only if |
1364 | * the peer (group) is configured to receive link-local nexthop unchanged | |
1365 | * and it is available in the prefix OR we're not reflecting the route and | |
1366 | * the peer (group) to whom we're going to announce is on a shared network | |
003c1ba0 | 1367 | * and this is either a self-originated route or the peer is EBGP. |
3f9c7369 | 1368 | */ |
8a92a8a0 | 1369 | if (p->family == AF_INET6 || peer_cap_enhe(peer)) |
3f9c7369 | 1370 | { |
801a9bcc | 1371 | attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; |
3811f1e2 DS |
1372 | if ((CHECK_FLAG (peer->af_flags[afi][safi], |
1373 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) && | |
1374 | IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local)) || | |
003c1ba0 | 1375 | (!reflect && peer->shared_network && |
1376 | (from == bgp->peer_self || peer->sort == BGP_PEER_EBGP))) | |
3f9c7369 | 1377 | { |
3811f1e2 | 1378 | attr->extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; |
3f9c7369 DS |
1379 | } |
1380 | ||
3811f1e2 DS |
1381 | /* Clear off link-local nexthop in source, whenever it is not needed to |
1382 | * ensure more prefixes share the same attribute for announcement. | |
3f9c7369 DS |
1383 | */ |
1384 | if (!(CHECK_FLAG (peer->af_flags[afi][safi], | |
1385 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED))) | |
1386 | memset (&attr->extra->mp_nexthop_local, 0, IPV6_MAX_BYTELEN); | |
1387 | } | |
1388 | #endif /* HAVE_IPV6 */ | |
1389 | ||
1390 | bgp_peer_remove_private_as(bgp, afi, safi, peer, attr); | |
1391 | bgp_peer_as_override(bgp, afi, safi, peer, attr); | |
1392 | ||
1393 | /* Route map & unsuppress-map apply. */ | |
1394 | if (ROUTE_MAP_OUT_NAME (filter) | |
1395 | || (ri->extra && ri->extra->suppress) ) | |
1396 | { | |
1397 | struct bgp_info info; | |
1398 | struct attr dummy_attr; | |
1399 | struct attr_extra dummy_extra; | |
1400 | ||
1401 | dummy_attr.extra = &dummy_extra; | |
1402 | ||
1403 | info.peer = peer; | |
1404 | info.attr = attr; | |
316e074d DS |
1405 | /* don't confuse inbound and outbound setting */ |
1406 | RESET_FLAG(attr->rmap_change_flags); | |
3f9c7369 DS |
1407 | |
1408 | /* | |
1409 | * The route reflector is not allowed to modify the attributes | |
1410 | * of the reflected IBGP routes unless explicitly allowed. | |
1411 | */ | |
1412 | if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) | |
1413 | && !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) | |
1414 | { | |
1415 | bgp_attr_dup (&dummy_attr, attr); | |
1416 | info.attr = &dummy_attr; | |
1417 | } | |
1418 | ||
1419 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); | |
1420 | ||
1421 | if (ri->extra && ri->extra->suppress) | |
1422 | ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info); | |
1423 | else | |
1424 | ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info); | |
1425 | ||
1426 | peer->rmap_type = 0; | |
1427 | ||
1428 | if (ret == RMAP_DENYMATCH) | |
1429 | { | |
1430 | bgp_attr_flush (attr); | |
1431 | return 0; | |
1432 | } | |
1433 | } | |
1434 | ||
1435 | /* After route-map has been applied, we check to see if the nexthop to | |
1436 | * be carried in the attribute (that is used for the announcement) can | |
1437 | * be cleared off or not. We do this in all cases where we would be | |
1438 | * setting the nexthop to "ourselves". For IPv6, we only need to consider | |
1439 | * the global nexthop here; the link-local nexthop would have been cleared | |
1440 | * already, and if not, it is required by the update formation code. | |
1441 | * Also see earlier comments in this function. | |
43fdf718 | 1442 | */ |
3811f1e2 DS |
1443 | /* |
1444 | * If route-map has performed some operation on the nexthop or the peer | |
1445 | * configuration says to pass it unchanged, we cannot reset the nexthop | |
1446 | * here, so only attempt to do it if these aren't true. Note that the | |
1447 | * route-map handler itself might have cleared the nexthop, if for example, | |
1448 | * it is configured as 'peer-address'. | |
3f9c7369 | 1449 | */ |
3811f1e2 DS |
1450 | if (!bgp_rmap_nhop_changed(attr->rmap_change_flags, |
1451 | riattr->rmap_change_flags) && | |
1452 | !transparent && | |
1453 | !CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)) | |
3f9c7369 | 1454 | { |
3811f1e2 | 1455 | /* We can reset the nexthop, if setting (or forcing) it to 'self' */ |
88b8ed8d DW |
1456 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) || |
1457 | CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF)) | |
3f9c7369 DS |
1458 | { |
1459 | if (!reflect || | |
1460 | CHECK_FLAG (peer->af_flags[afi][safi], | |
43fdf718 | 1461 | PEER_FLAG_FORCE_NEXTHOP_SELF)) |
3811f1e2 DS |
1462 | subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? |
1463 | AF_INET6 : p->family), attr); | |
3f9c7369 DS |
1464 | } |
1465 | else if (peer->sort == BGP_PEER_EBGP) | |
1466 | { | |
3811f1e2 DS |
1467 | /* Can also reset the nexthop if announcing to EBGP, but only if |
1468 | * no peer in the subgroup is on a shared subnet. | |
1469 | * Note: 3rd party nexthop currently implemented for IPv4 only. | |
1470 | */ | |
3f9c7369 DS |
1471 | SUBGRP_FOREACH_PEER (subgrp, paf) |
1472 | { | |
1473 | if (bgp_multiaccess_check_v4 (riattr->nexthop, paf->peer)) | |
1474 | break; | |
1475 | } | |
1476 | if (!paf) | |
8a92a8a0 | 1477 | subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr); |
3f9c7369 | 1478 | } |
003c1ba0 | 1479 | /* If IPv6/MP and nexthop does not have any override and happens to |
1480 | * be a link-local address, reset it so that we don't pass along the | |
1481 | * source's link-local IPv6 address to recipients who may not be on | |
1482 | * the same interface. | |
1483 | */ | |
1484 | if (p->family == AF_INET6 || peer_cap_enhe(peer)) | |
1485 | { | |
1486 | if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) | |
1487 | subgroup_announce_reset_nhop (AF_INET6, attr); | |
1488 | } | |
3f9c7369 DS |
1489 | } |
1490 | ||
1491 | return 1; | |
1492 | } | |
1493 | ||
fee0f4c6 | 1494 | struct bgp_info_pair |
1495 | { | |
1496 | struct bgp_info *old; | |
1497 | struct bgp_info *new; | |
1498 | }; | |
1499 | ||
94f2b392 | 1500 | static void |
96450faf JB |
1501 | bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, |
1502 | struct bgp_maxpaths_cfg *mpath_cfg, | |
1503 | struct bgp_info_pair *result) | |
718e3744 | 1504 | { |
718e3744 | 1505 | struct bgp_info *new_select; |
1506 | struct bgp_info *old_select; | |
fee0f4c6 | 1507 | struct bgp_info *ri; |
718e3744 | 1508 | struct bgp_info *ri1; |
1509 | struct bgp_info *ri2; | |
b40d939b | 1510 | struct bgp_info *nextri = NULL; |
9fbdd100 | 1511 | int paths_eq, do_mpath, debug; |
96450faf | 1512 | struct list mp_list; |
4690c7d7 | 1513 | char pfx_buf[PREFIX2STR_BUFFER]; |
2ec1e66f | 1514 | char path_buf[PATH_ADDPATH_STR_BUFFER]; |
96450faf JB |
1515 | |
1516 | bgp_mp_list_init (&mp_list); | |
99030da1 | 1517 | do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1); |
96450faf | 1518 | |
9fbdd100 DS |
1519 | debug = bgp_debug_bestpath(&rn->p); |
1520 | ||
1521 | if (debug) | |
1522 | prefix2str (&rn->p, pfx_buf, sizeof (pfx_buf)); | |
1523 | ||
718e3744 | 1524 | /* bgp deterministic-med */ |
1525 | new_select = NULL; | |
1526 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) | |
06370dac DW |
1527 | { |
1528 | ||
1529 | /* Clear BGP_INFO_DMED_SELECTED for all paths */ | |
1530 | for (ri1 = rn->info; ri1; ri1 = ri1->next) | |
1531 | bgp_info_unset_flag (rn, ri1, BGP_INFO_DMED_SELECTED); | |
1532 | ||
1533 | for (ri1 = rn->info; ri1; ri1 = ri1->next) | |
1534 | { | |
1535 | if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK)) | |
1536 | continue; | |
1537 | if (BGP_INFO_HOLDDOWN (ri1)) | |
2fed8887 | 1538 | continue; |
06370dac DW |
1539 | if (ri1->peer && ri1->peer != bgp->peer_self) |
1540 | if (ri1->peer->status != Established) | |
1541 | continue; | |
718e3744 | 1542 | |
06370dac DW |
1543 | new_select = ri1; |
1544 | old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL; | |
1545 | if (ri1->next) | |
1546 | { | |
1547 | for (ri2 = ri1->next; ri2; ri2 = ri2->next) | |
1548 | { | |
1549 | if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK)) | |
1550 | continue; | |
1551 | if (BGP_INFO_HOLDDOWN (ri2)) | |
1552 | continue; | |
1553 | if (ri2->peer && | |
1554 | ri2->peer != bgp->peer_self && | |
1555 | !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1556 | if (ri2->peer->status != Established) | |
1557 | continue; | |
1558 | ||
1559 | if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath) | |
1560 | || aspath_cmp_left_confed (ri1->attr->aspath, | |
1561 | ri2->attr->aspath)) | |
1562 | { | |
1563 | if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED)) | |
1564 | old_select = ri2; | |
1565 | if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq, | |
1566 | mpath_cfg, debug, pfx_buf)) | |
1567 | { | |
1568 | bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED); | |
1569 | new_select = ri2; | |
1570 | } | |
1571 | ||
1572 | bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK); | |
1573 | } | |
1574 | } | |
1575 | } | |
1576 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK); | |
1577 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED); | |
718e3744 | 1578 | |
06370dac | 1579 | if (debug) |
2ec1e66f DW |
1580 | { |
1581 | bgp_info_path_with_addpath_rx_str (new_select, path_buf); | |
1582 | zlog_debug("%s: %s is the bestpath from AS %d", | |
1583 | pfx_buf, path_buf, aspath_get_firstas(new_select->attr->aspath)); | |
1584 | } | |
06370dac DW |
1585 | } |
1586 | } | |
718e3744 | 1587 | |
1588 | /* Check old selected route and new selected route. */ | |
1589 | old_select = NULL; | |
1590 | new_select = NULL; | |
b40d939b | 1591 | for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri) |
718e3744 | 1592 | { |
1593 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
1594 | old_select = ri; | |
1595 | ||
1596 | if (BGP_INFO_HOLDDOWN (ri)) | |
b40d939b | 1597 | { |
1598 | /* reap REMOVED routes, if needs be | |
1599 | * selected route must stay for a while longer though | |
1600 | */ | |
1601 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) | |
1602 | && (ri != old_select)) | |
1603 | bgp_info_reap (rn, ri); | |
1604 | ||
1605 | continue; | |
1606 | } | |
718e3744 | 1607 | |
2fed8887 DS |
1608 | if (ri->peer && |
1609 | ri->peer != bgp->peer_self && | |
1610 | !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1611 | if (ri->peer->status != Established) | |
1612 | continue; | |
1613 | ||
718e3744 | 1614 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED) |
1615 | && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED))) | |
1616 | { | |
1a392d46 | 1617 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
718e3744 | 1618 | continue; |
1619 | } | |
06370dac | 1620 | |
1a392d46 | 1621 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
718e3744 | 1622 | |
9fbdd100 | 1623 | if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf)) |
96450faf JB |
1624 | { |
1625 | new_select = ri; | |
96450faf | 1626 | } |
718e3744 | 1627 | } |
b40d939b | 1628 | |
f4eeff72 DS |
1629 | /* Now that we know which path is the bestpath see if any of the other paths |
1630 | * qualify as multipaths | |
1631 | */ | |
1632 | if (do_mpath && new_select) | |
1633 | { | |
9fbdd100 | 1634 | if (debug) |
2ec1e66f DW |
1635 | { |
1636 | bgp_info_path_with_addpath_rx_str (new_select, path_buf); | |
1637 | zlog_debug("%s: %s is the bestpath, now find multipaths", pfx_buf, path_buf); | |
1638 | } | |
9fbdd100 | 1639 | |
f4eeff72 DS |
1640 | for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri) |
1641 | { | |
2ec1e66f DW |
1642 | |
1643 | if (debug) | |
1644 | bgp_info_path_with_addpath_rx_str (ri, path_buf); | |
1645 | ||
f4eeff72 DS |
1646 | if (ri == new_select) |
1647 | { | |
9fbdd100 | 1648 | if (debug) |
2ec1e66f DW |
1649 | zlog_debug("%s: %s is the bestpath, add to the multipath list", |
1650 | pfx_buf, path_buf); | |
f4eeff72 DS |
1651 | bgp_mp_list_add (&mp_list, ri); |
1652 | continue; | |
1653 | } | |
1654 | ||
1655 | if (BGP_INFO_HOLDDOWN (ri)) | |
1656 | continue; | |
1657 | ||
1658 | if (ri->peer && | |
1659 | ri->peer != bgp->peer_self && | |
1660 | !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT)) | |
1661 | if (ri->peer->status != Established) | |
1662 | continue; | |
1663 | ||
7dc9d4e4 DW |
1664 | if (!bgp_info_nexthop_cmp (ri, new_select)) |
1665 | { | |
1666 | if (debug) | |
2ec1e66f DW |
1667 | zlog_debug("%s: %s has the same nexthop as the bestpath, skip it", |
1668 | pfx_buf, path_buf); | |
7dc9d4e4 DW |
1669 | continue; |
1670 | } | |
1671 | ||
9fbdd100 | 1672 | bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf); |
f4eeff72 DS |
1673 | |
1674 | if (paths_eq) | |
1675 | { | |
9fbdd100 | 1676 | if (debug) |
2ec1e66f DW |
1677 | zlog_debug("%s: %s is equivalent to the bestpath, add to the multipath list", |
1678 | pfx_buf, path_buf); | |
f4eeff72 DS |
1679 | bgp_mp_list_add (&mp_list, ri); |
1680 | } | |
1681 | } | |
1682 | } | |
fee0f4c6 | 1683 | |
b354c427 | 1684 | bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg); |
0b597ef0 | 1685 | bgp_info_mpath_aggregate_update (new_select, old_select); |
96450faf JB |
1686 | bgp_mp_list_clear (&mp_list); |
1687 | ||
1688 | result->old = old_select; | |
1689 | result->new = new_select; | |
1690 | ||
1691 | return; | |
fee0f4c6 | 1692 | } |
1693 | ||
3f9c7369 DS |
1694 | /* |
1695 | * A new route/change in bestpath of an existing route. Evaluate the path | |
1696 | * for advertisement to the subgroup. | |
1697 | */ | |
1698 | int | |
1699 | subgroup_process_announce_selected (struct update_subgroup *subgrp, | |
1700 | struct bgp_info *selected, | |
adbac85e DW |
1701 | struct bgp_node *rn, |
1702 | u_int32_t addpath_tx_id) | |
9eda90ce | 1703 | { |
fee0f4c6 | 1704 | struct prefix *p; |
3f9c7369 | 1705 | struct peer *onlypeer; |
558d1fec JBD |
1706 | struct attr attr; |
1707 | struct attr_extra extra; | |
3f9c7369 DS |
1708 | afi_t afi; |
1709 | safi_t safi; | |
fee0f4c6 | 1710 | |
1711 | p = &rn->p; | |
3f9c7369 DS |
1712 | afi = SUBGRP_AFI(subgrp); |
1713 | safi = SUBGRP_SAFI(subgrp); | |
1714 | onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? | |
1715 | (SUBGRP_PFIRST(subgrp))->peer : NULL); | |
718e3744 | 1716 | |
9eda90ce | 1717 | /* First update is deferred until ORF or ROUTE-REFRESH is received */ |
3f9c7369 DS |
1718 | if (onlypeer && CHECK_FLAG (onlypeer->af_sflags[afi][safi], |
1719 | PEER_STATUS_ORF_WAIT_REFRESH)) | |
fee0f4c6 | 1720 | return 0; |
718e3744 | 1721 | |
2a3d5731 | 1722 | /* It's initialized in bgp_announce_check() */ |
558d1fec JBD |
1723 | attr.extra = &extra; |
1724 | ||
2a3d5731 DW |
1725 | /* Announcement to the subgroup. If the route is filtered withdraw it. */ |
1726 | if (selected) | |
fee0f4c6 | 1727 | { |
2a3d5731 DW |
1728 | if (subgroup_announce_check(selected, subgrp, p, &attr)) |
1729 | bgp_adj_out_set_subgroup(rn, subgrp, &attr, selected); | |
1730 | else | |
1731 | bgp_adj_out_unset_subgroup(rn, subgrp, 1, selected->addpath_tx_id); | |
1732 | } | |
adbac85e | 1733 | |
2a3d5731 DW |
1734 | /* If selected is NULL we must withdraw the path using addpath_tx_id */ |
1735 | else | |
1736 | { | |
1737 | bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id); | |
fee0f4c6 | 1738 | } |
558d1fec | 1739 | |
fee0f4c6 | 1740 | return 0; |
200df115 | 1741 | } |
fee0f4c6 | 1742 | |
3f9c7369 | 1743 | struct bgp_process_queue |
fee0f4c6 | 1744 | { |
200df115 | 1745 | struct bgp *bgp; |
1746 | struct bgp_node *rn; | |
1747 | afi_t afi; | |
1748 | safi_t safi; | |
1749 | }; | |
1750 | ||
200df115 | 1751 | static wq_item_status |
0fb58d5d | 1752 | bgp_process_main (struct work_queue *wq, void *data) |
200df115 | 1753 | { |
0fb58d5d | 1754 | struct bgp_process_queue *pq = data; |
200df115 | 1755 | struct bgp *bgp = pq->bgp; |
1756 | struct bgp_node *rn = pq->rn; | |
1757 | afi_t afi = pq->afi; | |
1758 | safi_t safi = pq->safi; | |
1759 | struct prefix *p = &rn->p; | |
fee0f4c6 | 1760 | struct bgp_info *new_select; |
1761 | struct bgp_info *old_select; | |
1762 | struct bgp_info_pair old_and_new; | |
cb1faec9 DS |
1763 | |
1764 | /* Is it end of initial update? (after startup) */ | |
1765 | if (!rn) | |
1766 | { | |
4a16ae86 DS |
1767 | quagga_timestamp(3, bgp->update_delay_zebra_resume_time, |
1768 | sizeof(bgp->update_delay_zebra_resume_time)); | |
1769 | ||
1770 | bgp->main_zebra_update_hold = 0; | |
1771 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
1772 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
1773 | { | |
1774 | bgp_zebra_announce_table(bgp, afi, safi); | |
1775 | } | |
1776 | bgp->main_peers_update_hold = 0; | |
1777 | ||
cb1faec9 DS |
1778 | bgp_start_routeadv(bgp); |
1779 | return WQ_SUCCESS; | |
1780 | } | |
1781 | ||
fee0f4c6 | 1782 | /* Best path selection. */ |
96450faf | 1783 | bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new); |
fee0f4c6 | 1784 | old_select = old_and_new.old; |
1785 | new_select = old_and_new.new; | |
1786 | ||
1787 | /* Nothing to do. */ | |
adbac85e DW |
1788 | if (old_select && old_select == new_select && |
1789 | !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR) && | |
1790 | !CHECK_FLAG(old_select->flags, BGP_INFO_ATTR_CHANGED) && | |
1791 | !bgp->addpath_tx_used[afi][safi]) | |
1792 | { | |
1793 | if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) || | |
1794 | CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG)) | |
1795 | bgp_zebra_announce (p, old_select, bgp, afi, safi); | |
200df115 | 1796 | |
adbac85e DW |
1797 | UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG); |
1798 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); | |
1799 | return WQ_SUCCESS; | |
fee0f4c6 | 1800 | } |
1801 | ||
8ad7271d DS |
1802 | /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */ |
1803 | UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR); | |
1804 | ||
3f9c7369 DS |
1805 | /* bestpath has changed; bump version */ |
1806 | if (old_select || new_select) | |
0de4848d DS |
1807 | { |
1808 | bgp_bump_version(rn); | |
1809 | ||
1810 | if (!bgp->t_rmap_def_originate_eval) | |
1811 | { | |
1812 | bgp_lock (bgp); | |
9229d914 | 1813 | THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval, |
0de4848d DS |
1814 | update_group_refresh_default_originate_route_map, |
1815 | bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER); | |
1816 | } | |
1817 | } | |
3f9c7369 | 1818 | |
338b3424 | 1819 | if (old_select) |
1a392d46 | 1820 | bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED); |
338b3424 | 1821 | if (new_select) |
1822 | { | |
1a392d46 PJ |
1823 | bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED); |
1824 | bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED); | |
8196f13d | 1825 | UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG); |
338b3424 | 1826 | } |
1827 | ||
3f9c7369 | 1828 | group_announce_route(bgp, afi, safi, rn, new_select); |
718e3744 | 1829 | |
1830 | /* FIB update. */ | |
ad4cbda1 | 1831 | if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && |
1832 | (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) && | |
1833 | !bgp_option_check (BGP_OPT_NO_FIB)) | |
718e3744 | 1834 | { |
1835 | if (new_select | |
1836 | && new_select->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
1837 | && (new_select->sub_type == BGP_ROUTE_NORMAL || |
1838 | new_select->sub_type == BGP_ROUTE_AGGREGATE)) | |
73ac8160 | 1839 | bgp_zebra_announce (p, new_select, bgp, afi, safi); |
718e3744 | 1840 | else |
1841 | { | |
1842 | /* Withdraw the route from the kernel. */ | |
1843 | if (old_select | |
1844 | && old_select->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
1845 | && (old_select->sub_type == BGP_ROUTE_NORMAL || |
1846 | old_select->sub_type == BGP_ROUTE_AGGREGATE)) | |
5a616c08 | 1847 | bgp_zebra_withdraw (p, old_select, safi); |
718e3744 | 1848 | } |
1849 | } | |
b40d939b | 1850 | |
adbac85e | 1851 | /* Reap old select bgp_info, if it has been removed */ |
b40d939b | 1852 | if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED)) |
1853 | bgp_info_reap (rn, old_select); | |
1854 | ||
200df115 | 1855 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
1856 | return WQ_SUCCESS; | |
718e3744 | 1857 | } |
1858 | ||
200df115 | 1859 | static void |
0fb58d5d | 1860 | bgp_processq_del (struct work_queue *wq, void *data) |
200df115 | 1861 | { |
0fb58d5d | 1862 | struct bgp_process_queue *pq = data; |
cb1faec9 DS |
1863 | struct bgp_table *table; |
1864 | ||
228da428 | 1865 | bgp_unlock (pq->bgp); |
cb1faec9 DS |
1866 | if (pq->rn) |
1867 | { | |
1868 | table = bgp_node_table (pq->rn); | |
1869 | bgp_unlock_node (pq->rn); | |
1870 | bgp_table_unlock (table); | |
1871 | } | |
200df115 | 1872 | XFREE (MTYPE_BGP_PROCESS_QUEUE, pq); |
1873 | } | |
1874 | ||
f188f2c4 | 1875 | void |
200df115 | 1876 | bgp_process_queue_init (void) |
1877 | { | |
495f0b13 DS |
1878 | if (!bm->process_main_queue) |
1879 | { | |
1880 | bm->process_main_queue | |
87d4a781 | 1881 | = work_queue_new (bm->master, "process_main_queue"); |
495f0b13 | 1882 | |
2a3d5731 DW |
1883 | if ( !bm->process_main_queue) |
1884 | { | |
1885 | zlog_err ("%s: Failed to allocate work queue", __func__); | |
1886 | exit (1); | |
1887 | } | |
200df115 | 1888 | } |
1889 | ||
1890 | bm->process_main_queue->spec.workfunc = &bgp_process_main; | |
200df115 | 1891 | bm->process_main_queue->spec.del_item_data = &bgp_processq_del; |
838bbde0 PJ |
1892 | bm->process_main_queue->spec.max_retries = 0; |
1893 | bm->process_main_queue->spec.hold = 50; | |
d889623f DS |
1894 | /* Use a higher yield value of 50ms for main queue processing */ |
1895 | bm->process_main_queue->spec.yield = 50 * 1000L; | |
200df115 | 1896 | } |
1897 | ||
1898 | void | |
fee0f4c6 | 1899 | bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) |
1900 | { | |
200df115 | 1901 | struct bgp_process_queue *pqnode; |
1902 | ||
1903 | /* already scheduled for processing? */ | |
1904 | if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED)) | |
1905 | return; | |
495f0b13 | 1906 | |
2a3d5731 | 1907 | if (bm->process_main_queue == NULL) |
2e02b9b2 DS |
1908 | bgp_process_queue_init (); |
1909 | ||
200df115 | 1910 | pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, |
1911 | sizeof (struct bgp_process_queue)); | |
1912 | if (!pqnode) | |
1913 | return; | |
228da428 CC |
1914 | |
1915 | /* all unlocked in bgp_processq_del */ | |
67174041 | 1916 | bgp_table_lock (bgp_node_table (rn)); |
228da428 | 1917 | pqnode->rn = bgp_lock_node (rn); |
200df115 | 1918 | pqnode->bgp = bgp; |
228da428 | 1919 | bgp_lock (bgp); |
200df115 | 1920 | pqnode->afi = afi; |
1921 | pqnode->safi = safi; | |
2a3d5731 | 1922 | work_queue_add (bm->process_main_queue, pqnode); |
07ff4dc4 | 1923 | SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
200df115 | 1924 | return; |
fee0f4c6 | 1925 | } |
0a486e5f | 1926 | |
cb1faec9 | 1927 | void |
2a3d5731 | 1928 | bgp_add_eoiu_mark (struct bgp *bgp) |
cb1faec9 DS |
1929 | { |
1930 | struct bgp_process_queue *pqnode; | |
1931 | ||
2a3d5731 | 1932 | if (bm->process_main_queue == NULL) |
2e02b9b2 DS |
1933 | bgp_process_queue_init (); |
1934 | ||
cb1faec9 DS |
1935 | pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, |
1936 | sizeof (struct bgp_process_queue)); | |
1937 | if (!pqnode) | |
1938 | return; | |
1939 | ||
1940 | pqnode->rn = NULL; | |
1941 | pqnode->bgp = bgp; | |
1942 | bgp_lock (bgp); | |
2a3d5731 | 1943 | work_queue_add (bm->process_main_queue, pqnode); |
cb1faec9 DS |
1944 | } |
1945 | ||
94f2b392 | 1946 | static int |
0a486e5f | 1947 | bgp_maximum_prefix_restart_timer (struct thread *thread) |
1948 | { | |
1949 | struct peer *peer; | |
1950 | ||
1951 | peer = THREAD_ARG (thread); | |
1952 | peer->t_pmax_restart = NULL; | |
1953 | ||
16286195 | 1954 | if (bgp_debug_neighbor_events(peer)) |
0a486e5f | 1955 | zlog_debug ("%s Maximum-prefix restart timer expired, restore peering", |
1956 | peer->host); | |
1957 | ||
1ff9a340 | 1958 | peer_clear (peer, NULL); |
0a486e5f | 1959 | |
1960 | return 0; | |
1961 | } | |
1962 | ||
718e3744 | 1963 | int |
5228ad27 | 1964 | bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, |
1965 | safi_t safi, int always) | |
718e3744 | 1966 | { |
e0701b79 | 1967 | if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) |
1968 | return 0; | |
1969 | ||
1970 | if (peer->pcount[afi][safi] > peer->pmax[afi][safi]) | |
718e3744 | 1971 | { |
e0701b79 | 1972 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT) |
1973 | && ! always) | |
1974 | return 0; | |
1975 | ||
16286195 DS |
1976 | zlog_info ("%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, " |
1977 | "limit %ld", afi_safi_print (afi, safi), peer->host, | |
1978 | peer->pcount[afi][safi], peer->pmax[afi][safi]); | |
e0701b79 | 1979 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); |
1980 | ||
1981 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)) | |
1982 | return 0; | |
1983 | ||
1984 | { | |
5228ad27 | 1985 | u_int8_t ndata[7]; |
e0701b79 | 1986 | |
1987 | if (safi == SAFI_MPLS_VPN) | |
42e6d745 | 1988 | safi = SAFI_MPLS_LABELED_VPN; |
5228ad27 | 1989 | |
1990 | ndata[0] = (afi >> 8); | |
1991 | ndata[1] = afi; | |
1992 | ndata[2] = safi; | |
1993 | ndata[3] = (peer->pmax[afi][safi] >> 24); | |
1994 | ndata[4] = (peer->pmax[afi][safi] >> 16); | |
1995 | ndata[5] = (peer->pmax[afi][safi] >> 8); | |
1996 | ndata[6] = (peer->pmax[afi][safi]); | |
e0701b79 | 1997 | |
1998 | SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); | |
1999 | bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE, | |
2000 | BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7); | |
2001 | } | |
0a486e5f | 2002 | |
f14e6fdb DS |
2003 | /* Dynamic peers will just close their connection. */ |
2004 | if (peer_dynamic_neighbor (peer)) | |
2005 | return 1; | |
2006 | ||
0a486e5f | 2007 | /* restart timer start */ |
2008 | if (peer->pmax_restart[afi][safi]) | |
2009 | { | |
2010 | peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60; | |
2011 | ||
16286195 | 2012 | if (bgp_debug_neighbor_events(peer)) |
0a486e5f | 2013 | zlog_debug ("%s Maximum-prefix restart timer started for %d secs", |
2014 | peer->host, peer->v_pmax_restart); | |
2015 | ||
2016 | BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer, | |
2017 | peer->v_pmax_restart); | |
2018 | } | |
2019 | ||
e0701b79 | 2020 | return 1; |
2021 | } | |
2022 | else | |
2023 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); | |
2024 | ||
2025 | if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) | |
2026 | { | |
2027 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD) | |
2028 | && ! always) | |
2029 | return 0; | |
2030 | ||
16286195 DS |
2031 | zlog_info ("%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld", |
2032 | afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi], | |
2033 | peer->pmax[afi][safi]); | |
e0701b79 | 2034 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); |
718e3744 | 2035 | } |
e0701b79 | 2036 | else |
2037 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); | |
718e3744 | 2038 | return 0; |
2039 | } | |
2040 | ||
b40d939b | 2041 | /* Unconditionally remove the route from the RIB, without taking |
2042 | * damping into consideration (eg, because the session went down) | |
2043 | */ | |
94f2b392 | 2044 | static void |
718e3744 | 2045 | bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
2046 | afi_t afi, safi_t safi) | |
2047 | { | |
902212c3 | 2048 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
2049 | ||
2050 | if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
2051 | bgp_info_delete (rn, ri); /* keep historical info */ | |
2052 | ||
b40d939b | 2053 | bgp_process (peer->bgp, rn, afi, safi); |
718e3744 | 2054 | } |
2055 | ||
94f2b392 | 2056 | static void |
718e3744 | 2057 | bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
b40d939b | 2058 | afi_t afi, safi_t safi) |
718e3744 | 2059 | { |
718e3744 | 2060 | int status = BGP_DAMP_NONE; |
2061 | ||
b40d939b | 2062 | /* apply dampening, if result is suppressed, we'll be retaining |
2063 | * the bgp_info in the RIB for historical reference. | |
2064 | */ | |
2065 | if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2066 | && peer->sort == BGP_PEER_EBGP) |
b40d939b | 2067 | if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0)) |
2068 | == BGP_DAMP_SUPPRESSED) | |
902212c3 | 2069 | { |
902212c3 | 2070 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
2071 | return; | |
2072 | } | |
2073 | ||
2074 | bgp_rib_remove (rn, ri, peer, afi, safi); | |
718e3744 | 2075 | } |
2076 | ||
fb018d25 | 2077 | static struct bgp_info * |
7c8ff89e | 2078 | info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr, |
fb018d25 DS |
2079 | struct bgp_node *rn) |
2080 | { | |
2081 | struct bgp_info *new; | |
2082 | ||
2083 | /* Make new BGP info. */ | |
2084 | new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info)); | |
2085 | new->type = type; | |
7c8ff89e | 2086 | new->instance = instance; |
fb018d25 DS |
2087 | new->sub_type = sub_type; |
2088 | new->peer = peer; | |
2089 | new->attr = attr; | |
2090 | new->uptime = bgp_clock (); | |
2091 | new->net = rn; | |
adbac85e | 2092 | new->addpath_tx_id = ++peer->bgp->addpath_tx_id; |
fb018d25 DS |
2093 | return new; |
2094 | } | |
2095 | ||
94f2b392 | 2096 | static void |
2ec1e66f | 2097 | bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf) |
cd808e74 | 2098 | { |
2ec1e66f DW |
2099 | if (addpath_id) |
2100 | sprintf(buf, " with addpath ID %d", addpath_id); | |
cd808e74 DS |
2101 | } |
2102 | ||
2ec1e66f | 2103 | |
c265ee22 DS |
2104 | /* Check if received nexthop is valid or not. */ |
2105 | static int | |
6aeb9e78 | 2106 | bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr) |
c265ee22 DS |
2107 | { |
2108 | struct attr_extra *attre = attr->extra; | |
2109 | int ret = 0; | |
2110 | ||
2111 | /* Only validated for unicast and multicast currently. */ | |
2112 | if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST) | |
2113 | return 0; | |
2114 | ||
2115 | /* If NEXT_HOP is present, validate it. */ | |
2116 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)) | |
2117 | { | |
2118 | if (attr->nexthop.s_addr == 0 || | |
2119 | IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) || | |
6aeb9e78 | 2120 | bgp_nexthop_self (bgp, attr)) |
c265ee22 DS |
2121 | ret = 1; |
2122 | } | |
2123 | ||
2124 | /* If MP_NEXTHOP is present, validate it. */ | |
2125 | /* Note: For IPv6 nexthops, we only validate the global (1st) nexthop; | |
2126 | * there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if | |
2127 | * it is not an IPv6 link-local address. | |
2128 | */ | |
2129 | if (attre && attre->mp_nexthop_len) | |
2130 | { | |
2131 | switch (attre->mp_nexthop_len) | |
2132 | { | |
2133 | case BGP_ATTR_NHLEN_IPV4: | |
2134 | case BGP_ATTR_NHLEN_VPNV4: | |
2135 | ret = (attre->mp_nexthop_global_in.s_addr == 0 || | |
2136 | IPV4_CLASS_DE (ntohl (attre->mp_nexthop_global_in.s_addr))); | |
2137 | break; | |
2138 | ||
2139 | #ifdef HAVE_IPV6 | |
2140 | case BGP_ATTR_NHLEN_IPV6_GLOBAL: | |
2141 | case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL: | |
2142 | ret = (IN6_IS_ADDR_UNSPECIFIED(&attre->mp_nexthop_global) || | |
2143 | IN6_IS_ADDR_LOOPBACK(&attre->mp_nexthop_global) || | |
2144 | IN6_IS_ADDR_MULTICAST(&attre->mp_nexthop_global)); | |
2145 | break; | |
2146 | #endif /* HAVE_IPV6 */ | |
2147 | ||
2148 | default: | |
2149 | ret = 1; | |
2150 | break; | |
2151 | } | |
2152 | } | |
2153 | ||
2154 | return ret; | |
2155 | } | |
2156 | ||
a7ee645d DS |
2157 | int |
2158 | bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id, | |
2159 | struct attr *attr, afi_t afi, safi_t safi, int type, | |
2160 | int sub_type, struct prefix_rd *prd, u_char *tag, | |
2161 | int soft_reconfig) | |
718e3744 | 2162 | { |
2163 | int ret; | |
2164 | int aspath_loop_count = 0; | |
2165 | struct bgp_node *rn; | |
2166 | struct bgp *bgp; | |
558d1fec JBD |
2167 | struct attr new_attr; |
2168 | struct attr_extra new_extra; | |
718e3744 | 2169 | struct attr *attr_new; |
2170 | struct bgp_info *ri; | |
2171 | struct bgp_info *new; | |
fd79ac91 | 2172 | const char *reason; |
718e3744 | 2173 | char buf[SU_ADDRSTRLEN]; |
cd808e74 | 2174 | char buf2[30]; |
fc9a856f | 2175 | int connected = 0; |
718e3744 | 2176 | |
2177 | bgp = peer->bgp; | |
fee0f4c6 | 2178 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
fb982c25 | 2179 | |
718e3744 | 2180 | /* When peer's soft reconfiguration enabled. Record input packet in |
2181 | Adj-RIBs-In. */ | |
343aa822 JBD |
2182 | if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) |
2183 | && peer != bgp->peer_self) | |
43143c8f | 2184 | bgp_adj_in_set (rn, peer, attr, addpath_id); |
718e3744 | 2185 | |
2186 | /* Check previously received route. */ | |
2187 | for (ri = rn->info; ri; ri = ri->next) | |
a82478b9 DS |
2188 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type && |
2189 | ri->addpath_rx_id == addpath_id) | |
718e3744 | 2190 | break; |
2191 | ||
2192 | /* AS path local-as loop check. */ | |
2193 | if (peer->change_local_as) | |
2194 | { | |
2195 | if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)) | |
2196 | aspath_loop_count = 1; | |
2197 | ||
2198 | if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count) | |
2199 | { | |
2200 | reason = "as-path contains our own AS;"; | |
2201 | goto filtered; | |
2202 | } | |
2203 | } | |
2204 | ||
2205 | /* AS path loop check. */ | |
2206 | if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi] | |
2207 | || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) | |
2208 | && aspath_loop_check(attr->aspath, bgp->confed_id) | |
2209 | > peer->allowas_in[afi][safi])) | |
2210 | { | |
2211 | reason = "as-path contains our own AS;"; | |
2212 | goto filtered; | |
2213 | } | |
2214 | ||
2215 | /* Route reflector originator ID check. */ | |
2216 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) | |
fb982c25 | 2217 | && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id)) |
718e3744 | 2218 | { |
2219 | reason = "originator is us;"; | |
2220 | goto filtered; | |
2221 | } | |
2222 | ||
2223 | /* Route reflector cluster ID check. */ | |
2224 | if (bgp_cluster_filter (peer, attr)) | |
2225 | { | |
2226 | reason = "reflected from the same cluster;"; | |
2227 | goto filtered; | |
2228 | } | |
2229 | ||
2230 | /* Apply incoming filter. */ | |
2231 | if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY) | |
2232 | { | |
2233 | reason = "filter;"; | |
2234 | goto filtered; | |
2235 | } | |
2236 | ||
558d1fec | 2237 | new_attr.extra = &new_extra; |
fb982c25 | 2238 | bgp_attr_dup (&new_attr, attr); |
718e3744 | 2239 | |
c460e572 DL |
2240 | /* Apply incoming route-map. |
2241 | * NB: new_attr may now contain newly allocated values from route-map "set" | |
2242 | * commands, so we need bgp_attr_flush in the error paths, until we intern | |
2243 | * the attr (which takes over the memory references) */ | |
0b16f239 | 2244 | if (bgp_input_modifier (peer, p, &new_attr, afi, safi, NULL) == RMAP_DENY) |
718e3744 | 2245 | { |
2246 | reason = "route-map;"; | |
c460e572 | 2247 | bgp_attr_flush (&new_attr); |
718e3744 | 2248 | goto filtered; |
2249 | } | |
2250 | ||
c265ee22 | 2251 | /* next hop check. */ |
6aeb9e78 | 2252 | if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr)) |
718e3744 | 2253 | { |
c265ee22 DS |
2254 | reason = "martian or self next-hop;"; |
2255 | bgp_attr_flush (&new_attr); | |
2256 | goto filtered; | |
718e3744 | 2257 | } |
2258 | ||
2259 | attr_new = bgp_attr_intern (&new_attr); | |
2260 | ||
2261 | /* If the update is implicit withdraw. */ | |
2262 | if (ri) | |
2263 | { | |
65957886 | 2264 | ri->uptime = bgp_clock (); |
718e3744 | 2265 | |
2266 | /* Same attribute comes in. */ | |
16d2e241 PJ |
2267 | if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) |
2268 | && attrhash_cmp (ri->attr, attr_new)) | |
718e3744 | 2269 | { |
718e3744 | 2270 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
6d85b15b | 2271 | && peer->sort == BGP_PEER_EBGP |
718e3744 | 2272 | && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
2273 | { | |
3f9c7369 | 2274 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2275 | { |
2ec1e66f | 2276 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2277 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2278 | peer->host, |
2279 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 DS |
2280 | p->prefixlen, buf2); |
2281 | } | |
718e3744 | 2282 | |
902212c3 | 2283 | if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED) |
2284 | { | |
2285 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
2286 | bgp_process (bgp, rn, afi, safi); | |
2287 | } | |
718e3744 | 2288 | } |
16d2e241 | 2289 | else /* Duplicate - odd */ |
718e3744 | 2290 | { |
3f9c7369 | 2291 | if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2292 | { |
2293 | if (!peer->rcvd_attr_printed) | |
2294 | { | |
2295 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2296 | peer->rcvd_attr_printed = 1; | |
2297 | } | |
2298 | ||
2ec1e66f | 2299 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2300 | zlog_debug ("%s rcvd %s/%d%s...duplicate ignored", |
16286195 DS |
2301 | peer->host, |
2302 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2303 | p->prefixlen, buf2); |
16286195 | 2304 | } |
93406d87 | 2305 | |
2306 | /* graceful restart STALE flag unset. */ | |
2307 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
2308 | { | |
1a392d46 | 2309 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
902212c3 | 2310 | bgp_process (bgp, rn, afi, safi); |
93406d87 | 2311 | } |
718e3744 | 2312 | } |
2313 | ||
2314 | bgp_unlock_node (rn); | |
f6f434b2 | 2315 | bgp_attr_unintern (&attr_new); |
558d1fec | 2316 | |
718e3744 | 2317 | return 0; |
2318 | } | |
2319 | ||
16d2e241 PJ |
2320 | /* Withdraw/Announce before we fully processed the withdraw */ |
2321 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) | |
2322 | { | |
3f9c7369 | 2323 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2324 | { |
2ec1e66f | 2325 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 DS |
2326 | zlog_debug ("%s rcvd %s/%d%s, flapped quicker than processing", |
2327 | peer->host, | |
2328 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2329 | p->prefixlen, buf2); | |
2330 | } | |
16d2e241 PJ |
2331 | bgp_info_restore (rn, ri); |
2332 | } | |
2333 | ||
718e3744 | 2334 | /* Received Logging. */ |
3f9c7369 | 2335 | if (bgp_debug_update(peer, p, NULL, 1)) |
cd808e74 | 2336 | { |
2ec1e66f | 2337 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2338 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2339 | peer->host, |
2340 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 DS |
2341 | p->prefixlen, buf2); |
2342 | } | |
718e3744 | 2343 | |
93406d87 | 2344 | /* graceful restart STALE flag unset. */ |
2345 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
1a392d46 | 2346 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
93406d87 | 2347 | |
718e3744 | 2348 | /* The attribute is changed. */ |
1a392d46 | 2349 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
902212c3 | 2350 | |
2351 | /* implicit withdraw, decrement aggregate and pcount here. | |
2352 | * only if update is accepted, they'll increment below. | |
2353 | */ | |
902212c3 | 2354 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
2355 | ||
718e3744 | 2356 | /* Update bgp route dampening information. */ |
2357 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2358 | && peer->sort == BGP_PEER_EBGP) |
718e3744 | 2359 | { |
2360 | /* This is implicit withdraw so we should update dampening | |
2361 | information. */ | |
2362 | if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
2363 | bgp_damp_withdraw (ri, rn, afi, safi, 1); | |
718e3744 | 2364 | } |
2365 | ||
718e3744 | 2366 | /* Update to new attribute. */ |
f6f434b2 | 2367 | bgp_attr_unintern (&ri->attr); |
718e3744 | 2368 | ri->attr = attr_new; |
2369 | ||
2370 | /* Update MPLS tag. */ | |
2371 | if (safi == SAFI_MPLS_VPN) | |
fb982c25 | 2372 | memcpy ((bgp_info_extra_get (ri))->tag, tag, 3); |
718e3744 | 2373 | |
2374 | /* Update bgp route dampening information. */ | |
2375 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) | |
6d85b15b | 2376 | && peer->sort == BGP_PEER_EBGP) |
718e3744 | 2377 | { |
2378 | /* Now we do normal update dampening. */ | |
2379 | ret = bgp_damp_update (ri, rn, afi, safi); | |
2380 | if (ret == BGP_DAMP_SUPPRESSED) | |
2381 | { | |
2382 | bgp_unlock_node (rn); | |
2383 | return 0; | |
2384 | } | |
2385 | } | |
2386 | ||
2387 | /* Nexthop reachability check. */ | |
fc9a856f | 2388 | if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST) |
718e3744 | 2389 | { |
fc9a856f | 2390 | if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 && |
907f92c8 DS |
2391 | ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) |
2392 | && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) | |
fc9a856f DS |
2393 | connected = 1; |
2394 | else | |
2395 | connected = 0; | |
2396 | ||
75aead62 | 2397 | if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, connected)) |
1a392d46 | 2398 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
718e3744 | 2399 | else |
fc9a856f DS |
2400 | { |
2401 | if (BGP_DEBUG(nht, NHT)) | |
2402 | { | |
2403 | char buf1[INET6_ADDRSTRLEN]; | |
2404 | inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN); | |
2405 | zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1); | |
2406 | } | |
2407 | bgp_info_unset_flag (rn, ri, BGP_INFO_VALID); | |
2408 | } | |
718e3744 | 2409 | } |
2410 | else | |
fc9a856f | 2411 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
718e3744 | 2412 | |
2413 | /* Process change. */ | |
2414 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
2415 | ||
2416 | bgp_process (bgp, rn, afi, safi); | |
2417 | bgp_unlock_node (rn); | |
558d1fec | 2418 | |
718e3744 | 2419 | return 0; |
a82478b9 | 2420 | } // End of implicit withdraw |
718e3744 | 2421 | |
2422 | /* Received Logging. */ | |
3f9c7369 | 2423 | if (bgp_debug_update(peer, p, NULL, 1)) |
718e3744 | 2424 | { |
16286195 DS |
2425 | if (!peer->rcvd_attr_printed) |
2426 | { | |
2427 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2428 | peer->rcvd_attr_printed = 1; | |
2429 | } | |
2430 | ||
2ec1e66f | 2431 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2432 | zlog_debug ("%s rcvd %s/%d%s", |
16286195 DS |
2433 | peer->host, |
2434 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2435 | p->prefixlen, buf2); |
718e3744 | 2436 | } |
2437 | ||
718e3744 | 2438 | /* Make new BGP info. */ |
7c8ff89e | 2439 | new = info_make(type, sub_type, 0, peer, attr_new, rn); |
718e3744 | 2440 | |
2441 | /* Update MPLS tag. */ | |
2442 | if (safi == SAFI_MPLS_VPN) | |
fb982c25 | 2443 | memcpy ((bgp_info_extra_get (new))->tag, tag, 3); |
718e3744 | 2444 | |
2445 | /* Nexthop reachability check. */ | |
fc9a856f DS |
2446 | if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST) |
2447 | { | |
2448 | if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 && | |
907f92c8 DS |
2449 | ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) |
2450 | && ! bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) | |
fc9a856f DS |
2451 | connected = 1; |
2452 | else | |
2453 | connected = 0; | |
2454 | ||
75aead62 | 2455 | if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, connected)) |
1a392d46 | 2456 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
718e3744 | 2457 | else |
fc9a856f DS |
2458 | { |
2459 | if (BGP_DEBUG(nht, NHT)) | |
2460 | { | |
2461 | char buf1[INET6_ADDRSTRLEN]; | |
2462 | inet_ntop(AF_INET, (const void *)&attr_new->nexthop, buf1, INET6_ADDRSTRLEN); | |
2463 | zlog_debug("%s(%s): NH unresolved", __FUNCTION__, buf1); | |
2464 | } | |
2465 | bgp_info_unset_flag (rn, new, BGP_INFO_VALID); | |
2466 | } | |
718e3744 | 2467 | } |
2468 | else | |
1a392d46 | 2469 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
718e3744 | 2470 | |
a82478b9 DS |
2471 | /* Addpath ID */ |
2472 | new->addpath_rx_id = addpath_id; | |
a82478b9 | 2473 | |
902212c3 | 2474 | /* Increment prefix */ |
718e3744 | 2475 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
2476 | ||
2477 | /* Register new BGP information. */ | |
2478 | bgp_info_add (rn, new); | |
200df115 | 2479 | |
2480 | /* route_node_get lock */ | |
2481 | bgp_unlock_node (rn); | |
558d1fec | 2482 | |
718e3744 | 2483 | /* If maximum prefix count is configured and current prefix |
2484 | count exeed it. */ | |
e0701b79 | 2485 | if (bgp_maximum_prefix_overflow (peer, afi, safi, 0)) |
2486 | return -1; | |
718e3744 | 2487 | |
2488 | /* Process change. */ | |
2489 | bgp_process (bgp, rn, afi, safi); | |
2490 | ||
2491 | return 0; | |
2492 | ||
2493 | /* This BGP update is filtered. Log the reason then update BGP | |
2494 | entry. */ | |
2495 | filtered: | |
3f9c7369 | 2496 | if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2497 | { |
2498 | if (!peer->rcvd_attr_printed) | |
2499 | { | |
2500 | zlog_debug ("%s rcvd UPDATE w/ attr: %s", peer->host, peer->rcvd_attr_str); | |
2501 | peer->rcvd_attr_printed = 1; | |
2502 | } | |
2503 | ||
2ec1e66f | 2504 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 | 2505 | zlog_debug ("%s rcvd UPDATE about %s/%d%s -- DENIED due to: %s", |
16286195 DS |
2506 | peer->host, |
2507 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
cd808e74 | 2508 | p->prefixlen, buf2, reason); |
16286195 | 2509 | } |
718e3744 | 2510 | |
2511 | if (ri) | |
b40d939b | 2512 | bgp_rib_remove (rn, ri, peer, afi, safi); |
718e3744 | 2513 | |
2514 | bgp_unlock_node (rn); | |
558d1fec | 2515 | |
718e3744 | 2516 | return 0; |
2517 | } | |
2518 | ||
2519 | int | |
a82478b9 DS |
2520 | bgp_withdraw (struct peer *peer, struct prefix *p, u_int32_t addpath_id, |
2521 | struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, | |
2522 | struct prefix_rd *prd, u_char *tag) | |
718e3744 | 2523 | { |
2524 | struct bgp *bgp; | |
2525 | char buf[SU_ADDRSTRLEN]; | |
cd808e74 | 2526 | char buf2[30]; |
718e3744 | 2527 | struct bgp_node *rn; |
2528 | struct bgp_info *ri; | |
2529 | ||
2530 | bgp = peer->bgp; | |
2531 | ||
718e3744 | 2532 | /* Lookup node. */ |
fee0f4c6 | 2533 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
718e3744 | 2534 | |
2535 | /* If peer is soft reconfiguration enabled. Record input packet for | |
2536 | further calculation. */ | |
2537 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) | |
2538 | && peer != bgp->peer_self) | |
43143c8f | 2539 | bgp_adj_in_unset (rn, peer, addpath_id); |
718e3744 | 2540 | |
2541 | /* Lookup withdrawn route. */ | |
2542 | for (ri = rn->info; ri; ri = ri->next) | |
a82478b9 DS |
2543 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type && |
2544 | ri->addpath_rx_id == addpath_id) | |
718e3744 | 2545 | break; |
2546 | ||
cd808e74 DS |
2547 | /* Logging. */ |
2548 | if (bgp_debug_update(peer, p, NULL, 1)) | |
2549 | { | |
2ec1e66f | 2550 | bgp_info_addpath_rx_str(addpath_id, buf2); |
cd808e74 DS |
2551 | zlog_debug ("%s rcvd UPDATE about %s/%d%s -- withdrawn", |
2552 | peer->host, | |
2553 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2554 | p->prefixlen, buf2); | |
2555 | } | |
2556 | ||
718e3744 | 2557 | /* Withdraw specified route from routing table. */ |
2558 | if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
b40d939b | 2559 | bgp_rib_withdraw (rn, ri, peer, afi, safi); |
3f9c7369 | 2560 | else if (bgp_debug_update(peer, p, NULL, 1)) |
16286195 DS |
2561 | zlog_debug ("%s Can't find the route %s/%d", peer->host, |
2562 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), | |
2563 | p->prefixlen); | |
718e3744 | 2564 | |
2565 | /* Unlock bgp_node_get() lock. */ | |
2566 | bgp_unlock_node (rn); | |
2567 | ||
2568 | return 0; | |
2569 | } | |
6b0655a2 | 2570 | |
718e3744 | 2571 | void |
2572 | bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw) | |
2573 | { | |
3f9c7369 DS |
2574 | struct update_subgroup *subgrp; |
2575 | subgrp = peer_subgroup(peer, afi, safi); | |
2576 | subgroup_default_originate(subgrp, withdraw); | |
2577 | } | |
6182d65b | 2578 | |
718e3744 | 2579 | |
3f9c7369 DS |
2580 | /* |
2581 | * bgp_stop_announce_route_timer | |
2582 | */ | |
2583 | void | |
2584 | bgp_stop_announce_route_timer (struct peer_af *paf) | |
2585 | { | |
2586 | if (!paf->t_announce_route) | |
2587 | return; | |
718e3744 | 2588 | |
3f9c7369 | 2589 | THREAD_TIMER_OFF (paf->t_announce_route); |
718e3744 | 2590 | } |
6b0655a2 | 2591 | |
3f9c7369 DS |
2592 | /* |
2593 | * bgp_announce_route_timer_expired | |
2594 | * | |
2595 | * Callback that is invoked when the route announcement timer for a | |
2596 | * peer_af expires. | |
2597 | */ | |
2598 | static int | |
2599 | bgp_announce_route_timer_expired (struct thread *t) | |
718e3744 | 2600 | { |
3f9c7369 DS |
2601 | struct peer_af *paf; |
2602 | struct peer *peer; | |
558d1fec | 2603 | |
718e3744 | 2604 | |
3f9c7369 DS |
2605 | paf = THREAD_ARG (t); |
2606 | peer = paf->peer; | |
718e3744 | 2607 | |
3f9c7369 DS |
2608 | assert (paf->t_announce_route); |
2609 | paf->t_announce_route = NULL; | |
558d1fec | 2610 | |
3f9c7369 DS |
2611 | if (peer->status != Established) |
2612 | return 0; | |
2613 | ||
2614 | if (!peer->afc_nego[paf->afi][paf->safi]) | |
2615 | return 0; | |
2616 | ||
2617 | peer_af_announce_route (paf, 1); | |
2618 | return 0; | |
718e3744 | 2619 | } |
2620 | ||
3f9c7369 DS |
2621 | /* |
2622 | * bgp_announce_route | |
2623 | * | |
2624 | * *Triggers* announcement of routes of a given AFI/SAFI to a peer. | |
2625 | */ | |
718e3744 | 2626 | void |
2627 | bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi) | |
2628 | { | |
3f9c7369 DS |
2629 | struct peer_af *paf; |
2630 | struct update_subgroup *subgrp; | |
718e3744 | 2631 | |
3f9c7369 DS |
2632 | paf = peer_af_find (peer, afi, safi); |
2633 | if (!paf) | |
718e3744 | 2634 | return; |
3f9c7369 | 2635 | subgrp = PAF_SUBGRP(paf); |
718e3744 | 2636 | |
3f9c7369 DS |
2637 | /* |
2638 | * Ignore if subgroup doesn't exist (implies AF is not negotiated) | |
2639 | * or a refresh has already been triggered. | |
2640 | */ | |
2641 | if (!subgrp || paf->t_announce_route) | |
718e3744 | 2642 | return; |
2643 | ||
d889623f | 2644 | /* |
3f9c7369 DS |
2645 | * Start a timer to stagger/delay the announce. This serves |
2646 | * two purposes - announcement can potentially be combined for | |
2647 | * multiple peers and the announcement doesn't happen in the | |
2648 | * vty context. | |
d889623f | 2649 | */ |
9229d914 | 2650 | THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route, |
3f9c7369 DS |
2651 | bgp_announce_route_timer_expired, paf, |
2652 | (subgrp->peer_count == 1) ? | |
2653 | BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS : | |
2654 | BGP_ANNOUNCE_ROUTE_DELAY_MS); | |
2655 | } | |
2656 | ||
2657 | /* | |
2658 | * Announce routes from all AF tables to a peer. | |
2659 | * | |
2660 | * This should ONLY be called when there is a need to refresh the | |
2661 | * routes to the peer based on a policy change for this peer alone | |
2662 | * or a route refresh request received from the peer. | |
2663 | * The operation will result in splitting the peer from its existing | |
2664 | * subgroups and putting it in new subgroups. | |
2665 | */ | |
718e3744 | 2666 | void |
2667 | bgp_announce_route_all (struct peer *peer) | |
2668 | { | |
2669 | afi_t afi; | |
2670 | safi_t safi; | |
2671 | ||
2672 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
2673 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
2674 | bgp_announce_route (peer, afi, safi); | |
2675 | } | |
6b0655a2 | 2676 | |
fee0f4c6 | 2677 | static void |
718e3744 | 2678 | bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi, |
8692c506 | 2679 | struct bgp_table *table, struct prefix_rd *prd) |
718e3744 | 2680 | { |
2681 | int ret; | |
2682 | struct bgp_node *rn; | |
2683 | struct bgp_adj_in *ain; | |
2684 | ||
2685 | if (! table) | |
2686 | table = peer->bgp->rib[afi][safi]; | |
2687 | ||
2688 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
2689 | for (ain = rn->adj_in; ain; ain = ain->next) | |
2690 | { | |
2691 | if (ain->peer == peer) | |
2692 | { | |
8692c506 | 2693 | struct bgp_info *ri = rn->info; |
d53d8fda | 2694 | u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL; |
8692c506 | 2695 | |
43143c8f | 2696 | ret = bgp_update (peer, &rn->p, ain->addpath_rx_id, ain->attr, |
a82478b9 | 2697 | afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, |
d53d8fda | 2698 | prd, tag, 1); |
8692c506 | 2699 | |
718e3744 | 2700 | if (ret < 0) |
2701 | { | |
2702 | bgp_unlock_node (rn); | |
2703 | return; | |
2704 | } | |
718e3744 | 2705 | } |
2706 | } | |
2707 | } | |
2708 | ||
2709 | void | |
2710 | bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi) | |
2711 | { | |
2712 | struct bgp_node *rn; | |
2713 | struct bgp_table *table; | |
2714 | ||
2715 | if (peer->status != Established) | |
2716 | return; | |
2717 | ||
2718 | if (safi != SAFI_MPLS_VPN) | |
8692c506 | 2719 | bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL); |
718e3744 | 2720 | else |
2721 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; | |
2722 | rn = bgp_route_next (rn)) | |
2723 | if ((table = rn->info) != NULL) | |
8692c506 JBD |
2724 | { |
2725 | struct prefix_rd prd; | |
2726 | prd.family = AF_UNSPEC; | |
2727 | prd.prefixlen = 64; | |
2728 | memcpy(&prd.val, rn->p.u.val, 8); | |
2729 | ||
2730 | bgp_soft_reconfig_table (peer, afi, safi, table, &prd); | |
2731 | } | |
718e3744 | 2732 | } |
6b0655a2 | 2733 | |
228da428 CC |
2734 | |
2735 | struct bgp_clear_node_queue | |
2736 | { | |
2737 | struct bgp_node *rn; | |
228da428 CC |
2738 | }; |
2739 | ||
200df115 | 2740 | static wq_item_status |
0fb58d5d | 2741 | bgp_clear_route_node (struct work_queue *wq, void *data) |
200df115 | 2742 | { |
228da428 CC |
2743 | struct bgp_clear_node_queue *cnq = data; |
2744 | struct bgp_node *rn = cnq->rn; | |
64e580a7 | 2745 | struct peer *peer = wq->spec.data; |
718e3744 | 2746 | struct bgp_info *ri; |
67174041 AS |
2747 | afi_t afi = bgp_node_table (rn)->afi; |
2748 | safi_t safi = bgp_node_table (rn)->safi; | |
200df115 | 2749 | |
64e580a7 | 2750 | assert (rn && peer); |
200df115 | 2751 | |
43143c8f DS |
2752 | /* It is possible that we have multiple paths for a prefix from a peer |
2753 | * if that peer is using AddPath. | |
2754 | */ | |
64e580a7 | 2755 | for (ri = rn->info; ri; ri = ri->next) |
2a3d5731 | 2756 | if (ri->peer == peer) |
200df115 | 2757 | { |
2758 | /* graceful restart STALE flag set. */ | |
64e580a7 PJ |
2759 | if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT) |
2760 | && peer->nsf[afi][safi] | |
200df115 | 2761 | && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE) |
1a392d46 PJ |
2762 | && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
2763 | bgp_info_set_flag (rn, ri, BGP_INFO_STALE); | |
200df115 | 2764 | else |
64e580a7 | 2765 | bgp_rib_remove (rn, ri, peer, afi, safi); |
200df115 | 2766 | } |
200df115 | 2767 | return WQ_SUCCESS; |
2768 | } | |
2769 | ||
2770 | static void | |
0fb58d5d | 2771 | bgp_clear_node_queue_del (struct work_queue *wq, void *data) |
200df115 | 2772 | { |
228da428 CC |
2773 | struct bgp_clear_node_queue *cnq = data; |
2774 | struct bgp_node *rn = cnq->rn; | |
67174041 | 2775 | struct bgp_table *table = bgp_node_table (rn); |
64e580a7 PJ |
2776 | |
2777 | bgp_unlock_node (rn); | |
228da428 CC |
2778 | bgp_table_unlock (table); |
2779 | XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq); | |
200df115 | 2780 | } |
2781 | ||
2782 | static void | |
94f2b392 | 2783 | bgp_clear_node_complete (struct work_queue *wq) |
200df115 | 2784 | { |
64e580a7 PJ |
2785 | struct peer *peer = wq->spec.data; |
2786 | ||
3e0c78ef | 2787 | /* Tickle FSM to start moving again */ |
ca058a30 | 2788 | BGP_EVENT_ADD (peer, Clearing_Completed); |
228da428 CC |
2789 | |
2790 | peer_unlock (peer); /* bgp_clear_route */ | |
200df115 | 2791 | } |
2792 | ||
2793 | static void | |
64e580a7 | 2794 | bgp_clear_node_queue_init (struct peer *peer) |
200df115 | 2795 | { |
a2943657 | 2796 | char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")]; |
64e580a7 | 2797 | |
a2943657 | 2798 | snprintf (wname, sizeof(wname), "clear %s", peer->host); |
64e580a7 PJ |
2799 | #undef CLEAR_QUEUE_NAME_LEN |
2800 | ||
87d4a781 | 2801 | if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL) |
200df115 | 2802 | { |
2803 | zlog_err ("%s: Failed to allocate work queue", __func__); | |
2804 | exit (1); | |
2805 | } | |
64e580a7 PJ |
2806 | peer->clear_node_queue->spec.hold = 10; |
2807 | peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node; | |
2808 | peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del; | |
2809 | peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete; | |
2810 | peer->clear_node_queue->spec.max_retries = 0; | |
2811 | ||
2812 | /* we only 'lock' this peer reference when the queue is actually active */ | |
2813 | peer->clear_node_queue->spec.data = peer; | |
200df115 | 2814 | } |
718e3744 | 2815 | |
200df115 | 2816 | static void |
2817 | bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi, | |
2a3d5731 | 2818 | struct bgp_table *table) |
200df115 | 2819 | { |
200df115 | 2820 | struct bgp_node *rn; |
2821 | ||
f2c31acb | 2822 | |
718e3744 | 2823 | if (! table) |
2a3d5731 | 2824 | table = peer->bgp->rib[afi][safi]; |
64e580a7 | 2825 | |
6cf159b9 | 2826 | /* If still no table => afi/safi isn't configured at all or smth. */ |
2827 | if (! table) | |
2828 | return; | |
65ca75e0 PJ |
2829 | |
2830 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
2831 | { | |
f2c31acb PJ |
2832 | struct bgp_info *ri; |
2833 | struct bgp_adj_in *ain; | |
43143c8f | 2834 | struct bgp_adj_in *ain_next; |
f2c31acb PJ |
2835 | |
2836 | /* XXX:TODO: This is suboptimal, every non-empty route_node is | |
2837 | * queued for every clearing peer, regardless of whether it is | |
2838 | * relevant to the peer at hand. | |
2839 | * | |
2840 | * Overview: There are 3 different indices which need to be | |
2841 | * scrubbed, potentially, when a peer is removed: | |
2842 | * | |
2843 | * 1 peer's routes visible via the RIB (ie accepted routes) | |
2844 | * 2 peer's routes visible by the (optional) peer's adj-in index | |
2845 | * 3 other routes visible by the peer's adj-out index | |
2846 | * | |
2847 | * 3 there is no hurry in scrubbing, once the struct peer is | |
2848 | * removed from bgp->peer, we could just GC such deleted peer's | |
2849 | * adj-outs at our leisure. | |
2850 | * | |
2851 | * 1 and 2 must be 'scrubbed' in some way, at least made | |
2852 | * invisible via RIB index before peer session is allowed to be | |
2853 | * brought back up. So one needs to know when such a 'search' is | |
2854 | * complete. | |
2855 | * | |
2856 | * Ideally: | |
2857 | * | |
2858 | * - there'd be a single global queue or a single RIB walker | |
2859 | * - rather than tracking which route_nodes still need to be | |
2860 | * examined on a peer basis, we'd track which peers still | |
2861 | * aren't cleared | |
2862 | * | |
2863 | * Given that our per-peer prefix-counts now should be reliable, | |
2864 | * this may actually be achievable. It doesn't seem to be a huge | |
2865 | * problem at this time, | |
43143c8f DS |
2866 | * |
2867 | * It is possible that we have multiple paths for a prefix from a peer | |
2868 | * if that peer is using AddPath. | |
f2c31acb | 2869 | */ |
43143c8f DS |
2870 | ain = rn->adj_in; |
2871 | while (ain) | |
2872 | { | |
2873 | ain_next = ain->next; | |
2874 | ||
2a3d5731 | 2875 | if (ain->peer == peer) |
43143c8f DS |
2876 | { |
2877 | bgp_adj_in_remove (rn, ain); | |
2878 | bgp_unlock_node (rn); | |
2879 | } | |
2880 | ||
2881 | ain = ain_next; | |
2882 | } | |
3f9c7369 | 2883 | |
f2c31acb | 2884 | for (ri = rn->info; ri; ri = ri->next) |
2a3d5731 | 2885 | if (ri->peer == peer) |
f2c31acb | 2886 | { |
228da428 CC |
2887 | struct bgp_clear_node_queue *cnq; |
2888 | ||
2889 | /* both unlocked in bgp_clear_node_queue_del */ | |
67174041 | 2890 | bgp_table_lock (bgp_node_table (rn)); |
228da428 CC |
2891 | bgp_lock_node (rn); |
2892 | cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE, | |
2893 | sizeof (struct bgp_clear_node_queue)); | |
2894 | cnq->rn = rn; | |
228da428 CC |
2895 | work_queue_add (peer->clear_node_queue, cnq); |
2896 | break; | |
f2c31acb | 2897 | } |
65ca75e0 PJ |
2898 | } |
2899 | return; | |
2900 | } | |
2901 | ||
2902 | void | |
2a3d5731 | 2903 | bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi) |
65ca75e0 PJ |
2904 | { |
2905 | struct bgp_node *rn; | |
2906 | struct bgp_table *table; | |
6cf159b9 | 2907 | |
64e580a7 PJ |
2908 | if (peer->clear_node_queue == NULL) |
2909 | bgp_clear_node_queue_init (peer); | |
200df115 | 2910 | |
ca058a30 PJ |
2911 | /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to |
2912 | * Idle until it receives a Clearing_Completed event. This protects | |
2913 | * against peers which flap faster than we can we clear, which could | |
2914 | * lead to: | |
64e580a7 PJ |
2915 | * |
2916 | * a) race with routes from the new session being installed before | |
2917 | * clear_route_node visits the node (to delete the route of that | |
2918 | * peer) | |
2919 | * b) resource exhaustion, clear_route_node likely leads to an entry | |
2920 | * on the process_main queue. Fast-flapping could cause that queue | |
2921 | * to grow and grow. | |
200df115 | 2922 | */ |
dc83d712 DS |
2923 | |
2924 | /* lock peer in assumption that clear-node-queue will get nodes; if so, | |
2925 | * the unlock will happen upon work-queue completion; other wise, the | |
2926 | * unlock happens at the end of this function. | |
2927 | */ | |
ca058a30 | 2928 | if (!peer->clear_node_queue->thread) |
dc83d712 | 2929 | peer_lock (peer); |
fee0f4c6 | 2930 | |
2a3d5731 DW |
2931 | if (safi != SAFI_MPLS_VPN) |
2932 | bgp_clear_route_table (peer, afi, safi, NULL); | |
2933 | else | |
2934 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; | |
2935 | rn = bgp_route_next (rn)) | |
2936 | if ((table = rn->info) != NULL) | |
2937 | bgp_clear_route_table (peer, afi, safi, table); | |
dc83d712 DS |
2938 | |
2939 | /* unlock if no nodes got added to the clear-node-queue. */ | |
65ca75e0 | 2940 | if (!peer->clear_node_queue->thread) |
dc83d712 DS |
2941 | peer_unlock (peer); |
2942 | ||
718e3744 | 2943 | } |
2944 | ||
2945 | void | |
2946 | bgp_clear_route_all (struct peer *peer) | |
2947 | { | |
2948 | afi_t afi; | |
2949 | safi_t safi; | |
2950 | ||
2951 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
2952 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
2a3d5731 | 2953 | bgp_clear_route (peer, afi, safi); |
718e3744 | 2954 | } |
2955 | ||
2956 | void | |
2957 | bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi) | |
2958 | { | |
2959 | struct bgp_table *table; | |
2960 | struct bgp_node *rn; | |
2961 | struct bgp_adj_in *ain; | |
43143c8f | 2962 | struct bgp_adj_in *ain_next; |
718e3744 | 2963 | |
2964 | table = peer->bgp->rib[afi][safi]; | |
2965 | ||
43143c8f DS |
2966 | /* It is possible that we have multiple paths for a prefix from a peer |
2967 | * if that peer is using AddPath. | |
2968 | */ | |
718e3744 | 2969 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
43143c8f DS |
2970 | { |
2971 | ain = rn->adj_in; | |
2972 | ||
2973 | while (ain) | |
2974 | { | |
2975 | ain_next = ain->next; | |
2976 | ||
2977 | if (ain->peer == peer) | |
2978 | { | |
2979 | bgp_adj_in_remove (rn, ain); | |
2980 | bgp_unlock_node (rn); | |
2981 | } | |
2982 | ||
2983 | ain = ain_next; | |
2984 | } | |
2985 | } | |
718e3744 | 2986 | } |
93406d87 | 2987 | |
2988 | void | |
2989 | bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi) | |
2990 | { | |
2991 | struct bgp_node *rn; | |
2992 | struct bgp_info *ri; | |
2993 | struct bgp_table *table; | |
2994 | ||
2995 | table = peer->bgp->rib[afi][safi]; | |
2996 | ||
2997 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
2998 | { | |
2999 | for (ri = rn->info; ri; ri = ri->next) | |
3000 | if (ri->peer == peer) | |
3001 | { | |
3002 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) | |
3003 | bgp_rib_remove (rn, ri, peer, afi, safi); | |
3004 | break; | |
3005 | } | |
3006 | } | |
3007 | } | |
6b0655a2 | 3008 | |
718e3744 | 3009 | /* Delete all kernel routes. */ |
3010 | void | |
66e5cd87 | 3011 | bgp_cleanup_routes (void) |
718e3744 | 3012 | { |
3013 | struct bgp *bgp; | |
1eb8ef25 | 3014 | struct listnode *node, *nnode; |
718e3744 | 3015 | struct bgp_node *rn; |
3016 | struct bgp_table *table; | |
3017 | struct bgp_info *ri; | |
3018 | ||
1eb8ef25 | 3019 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
718e3744 | 3020 | { |
3021 | table = bgp->rib[AFI_IP][SAFI_UNICAST]; | |
3022 | ||
3023 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3024 | for (ri = rn->info; ri; ri = ri->next) | |
3025 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) | |
3026 | && ri->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
3027 | && (ri->sub_type == BGP_ROUTE_NORMAL || |
3028 | ri->sub_type == BGP_ROUTE_AGGREGATE)) | |
5a616c08 | 3029 | bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); |
718e3744 | 3030 | |
3031 | table = bgp->rib[AFI_IP6][SAFI_UNICAST]; | |
3032 | ||
3033 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3034 | for (ri = rn->info; ri; ri = ri->next) | |
3035 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) | |
3036 | && ri->type == ZEBRA_ROUTE_BGP | |
f992e2a9 DS |
3037 | && (ri->sub_type == BGP_ROUTE_NORMAL || |
3038 | ri->sub_type == BGP_ROUTE_AGGREGATE)) | |
5a616c08 | 3039 | bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); |
718e3744 | 3040 | } |
3041 | } | |
3042 | ||
3043 | void | |
66e5cd87 | 3044 | bgp_reset (void) |
718e3744 | 3045 | { |
3046 | vty_reset (); | |
3047 | bgp_zclient_reset (); | |
3048 | access_list_reset (); | |
3049 | prefix_list_reset (); | |
3050 | } | |
6b0655a2 | 3051 | |
adbac85e DW |
3052 | static int |
3053 | bgp_addpath_encode_rx (struct peer *peer, afi_t afi, safi_t safi) | |
3054 | { | |
3055 | return (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) && | |
3056 | CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV)); | |
3057 | } | |
3058 | ||
718e3744 | 3059 | /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr |
3060 | value. */ | |
3061 | int | |
3062 | bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet) | |
3063 | { | |
3064 | u_char *pnt; | |
3065 | u_char *lim; | |
3066 | struct prefix p; | |
3067 | int psize; | |
3068 | int ret; | |
a82478b9 DS |
3069 | afi_t afi; |
3070 | safi_t safi; | |
adbac85e | 3071 | int addpath_encoded; |
a82478b9 | 3072 | u_int32_t addpath_id; |
718e3744 | 3073 | |
3074 | /* Check peer status. */ | |
3075 | if (peer->status != Established) | |
3076 | return 0; | |
3077 | ||
3078 | pnt = packet->nlri; | |
3079 | lim = pnt + packet->length; | |
a82478b9 DS |
3080 | afi = packet->afi; |
3081 | safi = packet->safi; | |
3082 | addpath_id = 0; | |
adbac85e | 3083 | addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi); |
718e3744 | 3084 | |
3085 | for (; pnt < lim; pnt += psize) | |
3086 | { | |
3087 | /* Clear prefix structure. */ | |
3088 | memset (&p, 0, sizeof (struct prefix)); | |
3089 | ||
a82478b9 DS |
3090 | if (addpath_encoded) |
3091 | { | |
cd808e74 DS |
3092 | |
3093 | /* When packet overflow occurs return immediately. */ | |
3094 | if (pnt + BGP_ADDPATH_ID_LEN > lim) | |
3095 | return -1; | |
3096 | ||
a82478b9 DS |
3097 | addpath_id = ntohl(*((uint32_t*) pnt)); |
3098 | pnt += BGP_ADDPATH_ID_LEN; | |
3099 | } | |
3100 | ||
718e3744 | 3101 | /* Fetch prefix length. */ |
3102 | p.prefixlen = *pnt++; | |
a82478b9 | 3103 | p.family = afi2family (afi); |
718e3744 | 3104 | |
3105 | /* Already checked in nlri_sanity_check(). We do double check | |
3106 | here. */ | |
a82478b9 DS |
3107 | if ((afi == AFI_IP && p.prefixlen > 32) |
3108 | || (afi == AFI_IP6 && p.prefixlen > 128)) | |
718e3744 | 3109 | return -1; |
3110 | ||
3111 | /* Packet size overflow check. */ | |
3112 | psize = PSIZE (p.prefixlen); | |
3113 | ||
3114 | /* When packet overflow occur return immediately. */ | |
3115 | if (pnt + psize > lim) | |
3116 | return -1; | |
3117 | ||
3118 | /* Fetch prefix from NLRI packet. */ | |
3119 | memcpy (&p.u.prefix, pnt, psize); | |
3120 | ||
3121 | /* Check address. */ | |
a82478b9 | 3122 | if (afi == AFI_IP && safi == SAFI_UNICAST) |
718e3744 | 3123 | { |
3124 | if (IN_CLASSD (ntohl (p.u.prefix4.s_addr))) | |
3125 | { | |
f5ba3874 | 3126 | /* |
3127 | * From draft-ietf-idr-bgp4-22, Section 6.3: | |
3128 | * If a BGP router receives an UPDATE message with a | |
3129 | * semantically incorrect NLRI field, in which a prefix is | |
3130 | * semantically incorrect (eg. an unexpected multicast IP | |
3131 | * address), it should ignore the prefix. | |
3132 | */ | |
16286195 DS |
3133 | zlog_err ("IPv4 unicast NLRI is multicast address %s", |
3134 | inet_ntoa (p.u.prefix4)); | |
f5ba3874 | 3135 | |
718e3744 | 3136 | return -1; |
3137 | } | |
3138 | } | |
3139 | ||
3140 | #ifdef HAVE_IPV6 | |
3141 | /* Check address. */ | |
a82478b9 | 3142 | if (afi == AFI_IP6 && safi == SAFI_UNICAST) |
718e3744 | 3143 | { |
3144 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
3145 | { | |
3146 | char buf[BUFSIZ]; | |
3147 | ||
16286195 DS |
3148 | zlog_warn ("IPv6 link-local NLRI received %s ignore this NLRI", |
3149 | inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ)); | |
718e3744 | 3150 | |
3151 | continue; | |
3152 | } | |
3153 | } | |
3154 | #endif /* HAVE_IPV6 */ | |
3155 | ||
3156 | /* Normal process. */ | |
3157 | if (attr) | |
a82478b9 | 3158 | ret = bgp_update (peer, &p, addpath_id, attr, afi, safi, |
718e3744 | 3159 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0); |
3160 | else | |
a82478b9 | 3161 | ret = bgp_withdraw (peer, &p, addpath_id, attr, afi, safi, |
718e3744 | 3162 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL); |
3163 | ||
3164 | /* Address family configuration mismatch or maximum-prefix count | |
3165 | overflow. */ | |
3166 | if (ret < 0) | |
3167 | return -1; | |
3168 | } | |
3169 | ||
3170 | /* Packet length consistency check. */ | |
3171 | if (pnt != lim) | |
3172 | return -1; | |
3173 | ||
3174 | return 0; | |
3175 | } | |
3176 | ||
3177 | /* NLRI encode syntax check routine. */ | |
3178 | int | |
a82478b9 | 3179 | bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi, u_char *pnt, |
d889623f | 3180 | bgp_size_t length, int *numpfx) |
718e3744 | 3181 | { |
3182 | u_char *end; | |
3183 | u_char prefixlen; | |
3184 | int psize; | |
adbac85e | 3185 | int addpath_encoded; |
718e3744 | 3186 | |
d889623f | 3187 | *numpfx = 0; |
718e3744 | 3188 | end = pnt + length; |
adbac85e | 3189 | addpath_encoded = bgp_addpath_encode_rx (peer, afi, safi); |
a82478b9 | 3190 | |
718e3744 | 3191 | /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for |
3192 | syntactic validity. If the field is syntactically incorrect, | |
3193 | then the Error Subcode is set to Invalid Network Field. */ | |
3194 | ||
3195 | while (pnt < end) | |
3196 | { | |
cd808e74 | 3197 | |
a82478b9 DS |
3198 | /* If the NLRI is encoded using addpath then the first 4 bytes are |
3199 | * the addpath ID. */ | |
3200 | if (addpath_encoded) | |
cd808e74 DS |
3201 | { |
3202 | if (pnt + BGP_ADDPATH_ID_LEN > end) | |
3203 | { | |
3204 | zlog_err ("%s [Error] Update packet error" | |
3205 | " (prefix data addpath overflow)", | |
3206 | peer->host); | |
3207 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, | |
3208 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); | |
3209 | return -1; | |
3210 | } | |
3211 | pnt += BGP_ADDPATH_ID_LEN; | |
3212 | } | |
a82478b9 | 3213 | |
718e3744 | 3214 | prefixlen = *pnt++; |
3215 | ||
3216 | /* Prefix length check. */ | |
3217 | if ((afi == AFI_IP && prefixlen > 32) | |
3218 | || (afi == AFI_IP6 && prefixlen > 128)) | |
3219 | { | |
16286195 | 3220 | zlog_err ("%s [Error] Update packet error (wrong prefix length %d)", |
718e3744 | 3221 | peer->host, prefixlen); |
3222 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, | |
3223 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); | |
3224 | return -1; | |
3225 | } | |
3226 | ||
3227 | /* Packet size overflow check. */ | |
3228 | psize = PSIZE (prefixlen); | |
3229 | ||
3230 | if (pnt + psize > end) | |
3231 | { | |
16286195 | 3232 | zlog_err ("%s [Error] Update packet error" |
718e3744 | 3233 | " (prefix data overflow prefix size is %d)", |
3234 | peer->host, psize); | |
3235 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, | |
3236 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); | |
3237 | return -1; | |
3238 | } | |
3239 | ||
3240 | pnt += psize; | |
d889623f | 3241 | (*numpfx)++; |
718e3744 | 3242 | } |
3243 | ||
3244 | /* Packet length consistency check. */ | |
3245 | if (pnt != end) | |
3246 | { | |
16286195 | 3247 | zlog_err ("%s [Error] Update packet error" |
718e3744 | 3248 | " (prefix length mismatch with total length)", |
3249 | peer->host); | |
3250 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, | |
3251 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); | |
3252 | return -1; | |
3253 | } | |
3254 | return 0; | |
3255 | } | |
6b0655a2 | 3256 | |
94f2b392 | 3257 | static struct bgp_static * |
66e5cd87 | 3258 | bgp_static_new (void) |
718e3744 | 3259 | { |
393deb9b | 3260 | return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static)); |
718e3744 | 3261 | } |
3262 | ||
94f2b392 | 3263 | static void |
718e3744 | 3264 | bgp_static_free (struct bgp_static *bgp_static) |
3265 | { | |
3266 | if (bgp_static->rmap.name) | |
6e919709 | 3267 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
718e3744 | 3268 | XFREE (MTYPE_BGP_STATIC, bgp_static); |
3269 | } | |
3270 | ||
94f2b392 | 3271 | static void |
2a3d5731 DW |
3272 | bgp_static_update_main (struct bgp *bgp, struct prefix *p, |
3273 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) | |
fee0f4c6 | 3274 | { |
3275 | struct bgp_node *rn; | |
3276 | struct bgp_info *ri; | |
2a3d5731 DW |
3277 | struct bgp_info *new; |
3278 | struct bgp_info info; | |
3279 | struct attr attr; | |
3280 | struct attr *attr_new; | |
3281 | int ret; | |
fee0f4c6 | 3282 | |
2a3d5731 DW |
3283 | assert (bgp_static); |
3284 | if (!bgp_static) | |
3285 | return; | |
dd8103a9 | 3286 | |
fee0f4c6 | 3287 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
718e3744 | 3288 | |
3289 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); | |
dd8103a9 PJ |
3290 | |
3291 | attr.nexthop = bgp_static->igpnexthop; | |
3292 | attr.med = bgp_static->igpmetric; | |
3293 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); | |
718e3744 | 3294 | |
41367172 PJ |
3295 | if (bgp_static->atomic) |
3296 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); | |
3297 | ||
718e3744 | 3298 | /* Apply route-map. */ |
3299 | if (bgp_static->rmap.name) | |
3300 | { | |
fb982c25 | 3301 | struct attr attr_tmp = attr; |
718e3744 | 3302 | info.peer = bgp->peer_self; |
286e1e71 | 3303 | info.attr = &attr_tmp; |
718e3744 | 3304 | |
fee0f4c6 | 3305 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); |
3306 | ||
718e3744 | 3307 | ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info); |
286e1e71 | 3308 | |
fee0f4c6 | 3309 | bgp->peer_self->rmap_type = 0; |
3310 | ||
718e3744 | 3311 | if (ret == RMAP_DENYMATCH) |
3312 | { | |
3313 | /* Free uninterned attribute. */ | |
286e1e71 | 3314 | bgp_attr_flush (&attr_tmp); |
718e3744 | 3315 | |
3316 | /* Unintern original. */ | |
f6f434b2 | 3317 | aspath_unintern (&attr.aspath); |
fb982c25 | 3318 | bgp_attr_extra_free (&attr); |
718e3744 | 3319 | bgp_static_withdraw (bgp, p, afi, safi); |
3320 | return; | |
3321 | } | |
286e1e71 | 3322 | attr_new = bgp_attr_intern (&attr_tmp); |
718e3744 | 3323 | } |
286e1e71 | 3324 | else |
3325 | attr_new = bgp_attr_intern (&attr); | |
718e3744 | 3326 | |
3327 | for (ri = rn->info; ri; ri = ri->next) | |
3328 | if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP | |
3329 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3330 | break; | |
3331 | ||
3332 | if (ri) | |
3333 | { | |
8d45210e | 3334 | if (attrhash_cmp (ri->attr, attr_new) && |
078430f6 DS |
3335 | !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) && |
3336 | !bgp_flag_check(bgp, BGP_FLAG_FORCE_STATIC_PROCESS)) | |
718e3744 | 3337 | { |
3338 | bgp_unlock_node (rn); | |
f6f434b2 PJ |
3339 | bgp_attr_unintern (&attr_new); |
3340 | aspath_unintern (&attr.aspath); | |
fb982c25 | 3341 | bgp_attr_extra_free (&attr); |
718e3744 | 3342 | return; |
3343 | } | |
3344 | else | |
3345 | { | |
3346 | /* The attribute is changed. */ | |
1a392d46 | 3347 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 3348 | |
3349 | /* Rewrite BGP route information. */ | |
8d45210e AS |
3350 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
3351 | bgp_info_restore(rn, ri); | |
3352 | else | |
3353 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
f6f434b2 | 3354 | bgp_attr_unintern (&ri->attr); |
718e3744 | 3355 | ri->attr = attr_new; |
65957886 | 3356 | ri->uptime = bgp_clock (); |
718e3744 | 3357 | |
fc9a856f DS |
3358 | /* Nexthop reachability check. */ |
3359 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) | |
3360 | { | |
75aead62 | 3361 | if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0)) |
fc9a856f DS |
3362 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
3363 | else | |
3364 | { | |
3365 | if (BGP_DEBUG(nht, NHT)) | |
3366 | { | |
3367 | char buf1[INET6_ADDRSTRLEN]; | |
078430f6 DS |
3368 | inet_ntop(p->family, &p->u.prefix, buf1, |
3369 | INET6_ADDRSTRLEN); | |
3370 | zlog_debug("%s(%s): Route not in table, not advertising", | |
3371 | __FUNCTION__, buf1); | |
fc9a856f DS |
3372 | } |
3373 | bgp_info_unset_flag (rn, ri, BGP_INFO_VALID); | |
3374 | } | |
3375 | } | |
078430f6 DS |
3376 | else |
3377 | { | |
3378 | /* Delete the NHT structure if any, if we're toggling between | |
3379 | * enabling/disabling import check. We deregister the route | |
3380 | * from NHT to avoid overloading NHT and the process interaction | |
3381 | */ | |
3382 | bgp_unlink_nexthop(ri); | |
3383 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); | |
3384 | } | |
718e3744 | 3385 | /* Process change. */ |
3386 | bgp_aggregate_increment (bgp, p, ri, afi, safi); | |
3387 | bgp_process (bgp, rn, afi, safi); | |
3388 | bgp_unlock_node (rn); | |
f6f434b2 | 3389 | aspath_unintern (&attr.aspath); |
fb982c25 | 3390 | bgp_attr_extra_free (&attr); |
718e3744 | 3391 | return; |
3392 | } | |
3393 | } | |
3394 | ||
3395 | /* Make new BGP info. */ | |
7c8ff89e | 3396 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new, |
fb018d25 | 3397 | rn); |
fc9a856f DS |
3398 | /* Nexthop reachability check. */ |
3399 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) | |
3400 | { | |
75aead62 | 3401 | if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0)) |
fc9a856f DS |
3402 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
3403 | else | |
3404 | { | |
3405 | if (BGP_DEBUG(nht, NHT)) | |
3406 | { | |
3407 | char buf1[INET6_ADDRSTRLEN]; | |
078430f6 | 3408 | inet_ntop(p->family, &p->u.prefix, buf1, |
fc9a856f | 3409 | INET6_ADDRSTRLEN); |
078430f6 DS |
3410 | zlog_debug("%s(%s): Route not in table, not advertising", |
3411 | __FUNCTION__, buf1); | |
fc9a856f DS |
3412 | } |
3413 | bgp_info_unset_flag (rn, new, BGP_INFO_VALID); | |
3414 | } | |
3415 | } | |
3416 | else | |
078430f6 DS |
3417 | { |
3418 | /* Delete the NHT structure if any, if we're toggling between | |
3419 | * enabling/disabling import check. We deregister the route | |
3420 | * from NHT to avoid overloading NHT and the process interaction | |
3421 | */ | |
3422 | bgp_unlink_nexthop(new); | |
3423 | ||
3424 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); | |
3425 | } | |
718e3744 | 3426 | |
3427 | /* Aggregate address increment. */ | |
3428 | bgp_aggregate_increment (bgp, p, new, afi, safi); | |
3429 | ||
3430 | /* Register new BGP information. */ | |
3431 | bgp_info_add (rn, new); | |
200df115 | 3432 | |
3433 | /* route_node_get lock */ | |
3434 | bgp_unlock_node (rn); | |
3435 | ||
718e3744 | 3436 | /* Process change. */ |
3437 | bgp_process (bgp, rn, afi, safi); | |
3438 | ||
3439 | /* Unintern original. */ | |
f6f434b2 | 3440 | aspath_unintern (&attr.aspath); |
fb982c25 | 3441 | bgp_attr_extra_free (&attr); |
718e3744 | 3442 | } |
3443 | ||
fee0f4c6 | 3444 | void |
3445 | bgp_static_update (struct bgp *bgp, struct prefix *p, | |
3446 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) | |
3447 | { | |
fee0f4c6 | 3448 | bgp_static_update_main (bgp, p, bgp_static, afi, safi); |
fee0f4c6 | 3449 | } |
3450 | ||
94f2b392 | 3451 | static void |
4c9641ba ML |
3452 | bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi, |
3453 | safi_t safi, struct prefix_rd *prd, u_char *tag) | |
718e3744 | 3454 | { |
3455 | struct bgp_node *rn; | |
3456 | struct bgp_info *new; | |
fb982c25 | 3457 | |
fee0f4c6 | 3458 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
718e3744 | 3459 | |
3460 | /* Make new BGP info. */ | |
7c8ff89e | 3461 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, |
fb018d25 DS |
3462 | bgp_attr_default_intern(BGP_ORIGIN_IGP), rn); |
3463 | ||
718e3744 | 3464 | SET_FLAG (new->flags, BGP_INFO_VALID); |
fb982c25 PJ |
3465 | new->extra = bgp_info_extra_new(); |
3466 | memcpy (new->extra->tag, tag, 3); | |
718e3744 | 3467 | |
3468 | /* Aggregate address increment. */ | |
200df115 | 3469 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
718e3744 | 3470 | |
3471 | /* Register new BGP information. */ | |
200df115 | 3472 | bgp_info_add (rn, new); |
718e3744 | 3473 | |
200df115 | 3474 | /* route_node_get lock */ |
3475 | bgp_unlock_node (rn); | |
3476 | ||
718e3744 | 3477 | /* Process change. */ |
3478 | bgp_process (bgp, rn, afi, safi); | |
3479 | } | |
3480 | ||
3481 | void | |
3482 | bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi, | |
3483 | safi_t safi) | |
3484 | { | |
3485 | struct bgp_node *rn; | |
3486 | struct bgp_info *ri; | |
3487 | ||
fee0f4c6 | 3488 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
718e3744 | 3489 | |
3490 | /* Check selected route and self inserted route. */ | |
3491 | for (ri = rn->info; ri; ri = ri->next) | |
3492 | if (ri->peer == bgp->peer_self | |
3493 | && ri->type == ZEBRA_ROUTE_BGP | |
3494 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3495 | break; | |
3496 | ||
3497 | /* Withdraw static BGP route from routing table. */ | |
3498 | if (ri) | |
3499 | { | |
3500 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
fc9a856f | 3501 | bgp_unlink_nexthop(ri); |
718e3744 | 3502 | bgp_info_delete (rn, ri); |
1a392d46 | 3503 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 3504 | } |
3505 | ||
3506 | /* Unlock bgp_node_lookup. */ | |
3507 | bgp_unlock_node (rn); | |
3508 | } | |
3509 | ||
94f2b392 | 3510 | static void |
4c9641ba ML |
3511 | bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi, |
3512 | safi_t safi, struct prefix_rd *prd, u_char *tag) | |
718e3744 | 3513 | { |
3514 | struct bgp_node *rn; | |
3515 | struct bgp_info *ri; | |
3516 | ||
fee0f4c6 | 3517 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
718e3744 | 3518 | |
3519 | /* Check selected route and self inserted route. */ | |
3520 | for (ri = rn->info; ri; ri = ri->next) | |
3521 | if (ri->peer == bgp->peer_self | |
3522 | && ri->type == ZEBRA_ROUTE_BGP | |
3523 | && ri->sub_type == BGP_ROUTE_STATIC) | |
3524 | break; | |
3525 | ||
3526 | /* Withdraw static BGP route from routing table. */ | |
3527 | if (ri) | |
3528 | { | |
3529 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); | |
718e3744 | 3530 | bgp_info_delete (rn, ri); |
1a392d46 | 3531 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 3532 | } |
3533 | ||
3534 | /* Unlock bgp_node_lookup. */ | |
3535 | bgp_unlock_node (rn); | |
3536 | } | |
3537 | ||
3538 | /* Configure static BGP network. When user don't run zebra, static | |
3539 | route should be installed as valid. */ | |
94f2b392 | 3540 | static int |
fd79ac91 | 3541 | bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str, |
c8f3fe30 | 3542 | afi_t afi, safi_t safi, const char *rmap, int backdoor) |
718e3744 | 3543 | { |
3544 | int ret; | |
3545 | struct prefix p; | |
3546 | struct bgp_static *bgp_static; | |
3547 | struct bgp_node *rn; | |
41367172 | 3548 | u_char need_update = 0; |
718e3744 | 3549 | |
3550 | /* Convert IP prefix string to struct prefix. */ | |
3551 | ret = str2prefix (ip_str, &p); | |
3552 | if (! ret) | |
3553 | { | |
3554 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
3555 | return CMD_WARNING; | |
3556 | } | |
3557 | #ifdef HAVE_IPV6 | |
3558 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
3559 | { | |
3560 | vty_out (vty, "%% Malformed prefix (link-local address)%s", | |
3561 | VTY_NEWLINE); | |
3562 | return CMD_WARNING; | |
3563 | } | |
3564 | #endif /* HAVE_IPV6 */ | |
3565 | ||
3566 | apply_mask (&p); | |
3567 | ||
3568 | /* Set BGP static route configuration. */ | |
3569 | rn = bgp_node_get (bgp->route[afi][safi], &p); | |
3570 | ||
3571 | if (rn->info) | |
3572 | { | |
3573 | /* Configuration change. */ | |
3574 | bgp_static = rn->info; | |
3575 | ||
3576 | /* Check previous routes are installed into BGP. */ | |
c8f3fe30 PJ |
3577 | if (bgp_static->valid && bgp_static->backdoor != backdoor) |
3578 | need_update = 1; | |
41367172 | 3579 | |
718e3744 | 3580 | bgp_static->backdoor = backdoor; |
41367172 | 3581 | |
718e3744 | 3582 | if (rmap) |
3583 | { | |
3584 | if (bgp_static->rmap.name) | |
6e919709 DS |
3585 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
3586 | bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); | |
718e3744 | 3587 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
3588 | } | |
3589 | else | |
3590 | { | |
3591 | if (bgp_static->rmap.name) | |
6e919709 | 3592 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
718e3744 | 3593 | bgp_static->rmap.name = NULL; |
3594 | bgp_static->rmap.map = NULL; | |
3595 | bgp_static->valid = 0; | |
3596 | } | |
3597 | bgp_unlock_node (rn); | |
3598 | } | |
3599 | else | |
3600 | { | |
3601 | /* New configuration. */ | |
3602 | bgp_static = bgp_static_new (); | |
3603 | bgp_static->backdoor = backdoor; | |
3604 | bgp_static->valid = 0; | |
3605 | bgp_static->igpmetric = 0; | |
3606 | bgp_static->igpnexthop.s_addr = 0; | |
41367172 | 3607 | |
718e3744 | 3608 | if (rmap) |
3609 | { | |
3610 | if (bgp_static->rmap.name) | |
6e919709 DS |
3611 | XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); |
3612 | bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); | |
718e3744 | 3613 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
3614 | } | |
3615 | rn->info = bgp_static; | |
3616 | } | |
3617 | ||
fc9a856f DS |
3618 | bgp_static->valid = 1; |
3619 | if (need_update) | |
3620 | bgp_static_withdraw (bgp, &p, afi, safi); | |
718e3744 | 3621 | |
fc9a856f DS |
3622 | if (! bgp_static->backdoor) |
3623 | bgp_static_update (bgp, &p, bgp_static, afi, safi); | |
718e3744 | 3624 | |
3625 | return CMD_SUCCESS; | |
3626 | } | |
3627 | ||
3628 | /* Configure static BGP network. */ | |
94f2b392 | 3629 | static int |
fd79ac91 | 3630 | bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str, |
4c9641ba | 3631 | afi_t afi, safi_t safi) |
718e3744 | 3632 | { |
3633 | int ret; | |
3634 | struct prefix p; | |
3635 | struct bgp_static *bgp_static; | |
3636 | struct bgp_node *rn; | |
3637 | ||
3638 | /* Convert IP prefix string to struct prefix. */ | |
3639 | ret = str2prefix (ip_str, &p); | |
3640 | if (! ret) | |
3641 | { | |
3642 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
3643 | return CMD_WARNING; | |
3644 | } | |
3645 | #ifdef HAVE_IPV6 | |
3646 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
3647 | { | |
3648 | vty_out (vty, "%% Malformed prefix (link-local address)%s", | |
3649 | VTY_NEWLINE); | |
3650 | return CMD_WARNING; | |
3651 | } | |
3652 | #endif /* HAVE_IPV6 */ | |
3653 | ||
3654 | apply_mask (&p); | |
3655 | ||
3656 | rn = bgp_node_lookup (bgp->route[afi][safi], &p); | |
3657 | if (! rn) | |
3658 | { | |
3659 | vty_out (vty, "%% Can't find specified static route configuration.%s", | |
3660 | VTY_NEWLINE); | |
3661 | return CMD_WARNING; | |
3662 | } | |
3663 | ||
3664 | bgp_static = rn->info; | |
41367172 | 3665 | |
718e3744 | 3666 | /* Update BGP RIB. */ |
3667 | if (! bgp_static->backdoor) | |
3668 | bgp_static_withdraw (bgp, &p, afi, safi); | |
3669 | ||
3670 | /* Clear configuration. */ | |
3671 | bgp_static_free (bgp_static); | |
3672 | rn->info = NULL; | |
3673 | bgp_unlock_node (rn); | |
3674 | bgp_unlock_node (rn); | |
3675 | ||
3676 | return CMD_SUCCESS; | |
3677 | } | |
3678 | ||
6aeb9e78 DS |
3679 | void |
3680 | bgp_static_add (struct bgp *bgp) | |
3681 | { | |
3682 | afi_t afi; | |
3683 | safi_t safi; | |
3684 | struct bgp_node *rn; | |
3685 | struct bgp_node *rm; | |
3686 | struct bgp_table *table; | |
3687 | struct bgp_static *bgp_static; | |
3688 | ||
3689 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3690 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
3691 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
3692 | if (rn->info != NULL) | |
3693 | { | |
3694 | if (safi == SAFI_MPLS_VPN) | |
3695 | { | |
3696 | table = rn->info; | |
3697 | ||
3698 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
3699 | { | |
3700 | bgp_static = rn->info; | |
3701 | bgp_static_update_vpnv4 (bgp, &rm->p, | |
3702 | AFI_IP, SAFI_MPLS_VPN, | |
3703 | (struct prefix_rd *)&rn->p, | |
3704 | bgp_static->tag); | |
3705 | } | |
3706 | } | |
3707 | else | |
3708 | { | |
3709 | bgp_static_update (bgp, &rn->p, rn->info, afi, safi); | |
3710 | } | |
3711 | } | |
3712 | } | |
3713 | ||
718e3744 | 3714 | /* Called from bgp_delete(). Delete all static routes from the BGP |
3715 | instance. */ | |
3716 | void | |
3717 | bgp_static_delete (struct bgp *bgp) | |
3718 | { | |
3719 | afi_t afi; | |
3720 | safi_t safi; | |
3721 | struct bgp_node *rn; | |
3722 | struct bgp_node *rm; | |
3723 | struct bgp_table *table; | |
3724 | struct bgp_static *bgp_static; | |
3725 | ||
3726 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3727 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
3728 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
3729 | if (rn->info != NULL) | |
3730 | { | |
3731 | if (safi == SAFI_MPLS_VPN) | |
3732 | { | |
3733 | table = rn->info; | |
3734 | ||
3735 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
3736 | { | |
3737 | bgp_static = rn->info; | |
3738 | bgp_static_withdraw_vpnv4 (bgp, &rm->p, | |
3739 | AFI_IP, SAFI_MPLS_VPN, | |
3740 | (struct prefix_rd *)&rn->p, | |
3741 | bgp_static->tag); | |
3742 | bgp_static_free (bgp_static); | |
3743 | rn->info = NULL; | |
3744 | bgp_unlock_node (rn); | |
3745 | } | |
3746 | } | |
3747 | else | |
3748 | { | |
3749 | bgp_static = rn->info; | |
3750 | bgp_static_withdraw (bgp, &rn->p, afi, safi); | |
3751 | bgp_static_free (bgp_static); | |
3752 | rn->info = NULL; | |
3753 | bgp_unlock_node (rn); | |
3754 | } | |
3755 | } | |
3756 | } | |
3757 | ||
078430f6 DS |
3758 | void |
3759 | bgp_static_redo_import_check (struct bgp *bgp) | |
3760 | { | |
3761 | afi_t afi; | |
3762 | safi_t safi; | |
3763 | struct bgp_node *rn; | |
078430f6 DS |
3764 | struct bgp_static *bgp_static; |
3765 | ||
3766 | /* Use this flag to force reprocessing of the route */ | |
3767 | bgp_flag_set(bgp, BGP_FLAG_FORCE_STATIC_PROCESS); | |
3768 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3769 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
3770 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
3771 | if (rn->info != NULL) | |
3772 | { | |
3773 | bgp_static = rn->info; | |
3774 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); | |
3775 | } | |
3776 | bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS); | |
3777 | } | |
3778 | ||
ad4cbda1 | 3779 | static void |
3780 | bgp_purge_af_static_redist_routes (struct bgp *bgp, afi_t afi, safi_t safi) | |
3781 | { | |
3782 | struct bgp_table *table; | |
3783 | struct bgp_node *rn; | |
3784 | struct bgp_info *ri; | |
3785 | ||
3786 | table = bgp->rib[afi][safi]; | |
3787 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
3788 | { | |
3789 | for (ri = rn->info; ri; ri = ri->next) | |
3790 | { | |
3791 | if (ri->peer == bgp->peer_self && | |
3792 | ((ri->type == ZEBRA_ROUTE_BGP && | |
3793 | ri->sub_type == BGP_ROUTE_STATIC) || | |
3794 | (ri->type != ZEBRA_ROUTE_BGP && | |
3795 | ri->sub_type == BGP_ROUTE_REDISTRIBUTE))) | |
3796 | { | |
3797 | bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi); | |
3798 | bgp_unlink_nexthop(ri); | |
3799 | bgp_info_delete (rn, ri); | |
3800 | bgp_process (bgp, rn, afi, safi); | |
3801 | } | |
3802 | } | |
3803 | } | |
3804 | } | |
3805 | ||
3806 | /* | |
3807 | * Purge all networks and redistributed routes from routing table. | |
3808 | * Invoked upon the instance going down. | |
3809 | */ | |
3810 | void | |
3811 | bgp_purge_static_redist_routes (struct bgp *bgp) | |
3812 | { | |
3813 | afi_t afi; | |
3814 | safi_t safi; | |
3815 | ||
3816 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3817 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) | |
3818 | bgp_purge_af_static_redist_routes (bgp, afi, safi); | |
3819 | } | |
3820 | ||
718e3744 | 3821 | int |
fd79ac91 | 3822 | bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str, |
3823 | const char *tag_str) | |
718e3744 | 3824 | { |
3825 | int ret; | |
3826 | struct prefix p; | |
3827 | struct prefix_rd prd; | |
3828 | struct bgp *bgp; | |
3829 | struct bgp_node *prn; | |
3830 | struct bgp_node *rn; | |
3831 | struct bgp_table *table; | |
3832 | struct bgp_static *bgp_static; | |
3833 | u_char tag[3]; | |
3834 | ||
3835 | bgp = vty->index; | |
3836 | ||
3837 | ret = str2prefix (ip_str, &p); | |
3838 | if (! ret) | |
3839 | { | |
3840 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
3841 | return CMD_WARNING; | |
3842 | } | |
3843 | apply_mask (&p); | |
3844 | ||
3845 | ret = str2prefix_rd (rd_str, &prd); | |
3846 | if (! ret) | |
3847 | { | |
3848 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
3849 | return CMD_WARNING; | |
3850 | } | |
3851 | ||
3852 | ret = str2tag (tag_str, tag); | |
3853 | if (! ret) | |
3854 | { | |
3855 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); | |
3856 | return CMD_WARNING; | |
3857 | } | |
3858 | ||
3859 | prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], | |
3860 | (struct prefix *)&prd); | |
3861 | if (prn->info == NULL) | |
64e580a7 | 3862 | prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN); |
718e3744 | 3863 | else |
3864 | bgp_unlock_node (prn); | |
3865 | table = prn->info; | |
3866 | ||
3867 | rn = bgp_node_get (table, &p); | |
3868 | ||
3869 | if (rn->info) | |
3870 | { | |
3871 | vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE); | |
3872 | bgp_unlock_node (rn); | |
3873 | } | |
3874 | else | |
3875 | { | |
3876 | /* New configuration. */ | |
3877 | bgp_static = bgp_static_new (); | |
3878 | bgp_static->valid = 1; | |
3879 | memcpy (bgp_static->tag, tag, 3); | |
3880 | rn->info = bgp_static; | |
3881 | ||
3882 | bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); | |
3883 | } | |
3884 | ||
3885 | return CMD_SUCCESS; | |
3886 | } | |
3887 | ||
3888 | /* Configure static BGP network. */ | |
3889 | int | |
fd79ac91 | 3890 | bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str, |
3891 | const char *rd_str, const char *tag_str) | |
718e3744 | 3892 | { |
3893 | int ret; | |
3894 | struct bgp *bgp; | |
3895 | struct prefix p; | |
3896 | struct prefix_rd prd; | |
3897 | struct bgp_node *prn; | |
3898 | struct bgp_node *rn; | |
3899 | struct bgp_table *table; | |
3900 | struct bgp_static *bgp_static; | |
3901 | u_char tag[3]; | |
3902 | ||
3903 | bgp = vty->index; | |
3904 | ||
3905 | /* Convert IP prefix string to struct prefix. */ | |
3906 | ret = str2prefix (ip_str, &p); | |
3907 | if (! ret) | |
3908 | { | |
3909 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); | |
3910 | return CMD_WARNING; | |
3911 | } | |
3912 | apply_mask (&p); | |
3913 | ||
3914 | ret = str2prefix_rd (rd_str, &prd); | |
3915 | if (! ret) | |
3916 | { | |
3917 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); | |
3918 | return CMD_WARNING; | |
3919 | } | |
3920 | ||
3921 | ret = str2tag (tag_str, tag); | |
3922 | if (! ret) | |
3923 | { | |
3924 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); | |
3925 | return CMD_WARNING; | |
3926 | } | |
3927 | ||
3928 | prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], | |
3929 | (struct prefix *)&prd); | |
3930 | if (prn->info == NULL) | |
64e580a7 | 3931 | prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN); |
718e3744 | 3932 | else |
3933 | bgp_unlock_node (prn); | |
3934 | table = prn->info; | |
3935 | ||
3936 | rn = bgp_node_lookup (table, &p); | |
3937 | ||
3938 | if (rn) | |
3939 | { | |
3940 | bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); | |
3941 | ||
3942 | bgp_static = rn->info; | |
3943 | bgp_static_free (bgp_static); | |
3944 | rn->info = NULL; | |
3945 | bgp_unlock_node (rn); | |
3946 | bgp_unlock_node (rn); | |
3947 | } | |
3948 | else | |
3949 | vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE); | |
3950 | ||
3951 | return CMD_SUCCESS; | |
3952 | } | |
6b0655a2 | 3953 | |
73ac8160 DS |
3954 | static int |
3955 | bgp_table_map_set (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, | |
3956 | const char *rmap_name) | |
3957 | { | |
3958 | struct bgp_rmap *rmap; | |
3959 | ||
3960 | rmap = &bgp->table_map[afi][safi]; | |
3961 | if (rmap_name) | |
3962 | { | |
3963 | if (rmap->name) | |
6e919709 DS |
3964 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
3965 | rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name); | |
73ac8160 DS |
3966 | rmap->map = route_map_lookup_by_name (rmap_name); |
3967 | } | |
3968 | else | |
3969 | { | |
3970 | if (rmap->name) | |
6e919709 | 3971 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
73ac8160 DS |
3972 | rmap->name = NULL; |
3973 | rmap->map = NULL; | |
3974 | } | |
3975 | ||
3976 | bgp_zebra_announce_table(bgp, afi, safi); | |
3977 | ||
3978 | return CMD_SUCCESS; | |
3979 | } | |
3980 | ||
3981 | static int | |
3982 | bgp_table_map_unset (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, | |
3983 | const char *rmap_name) | |
3984 | { | |
3985 | struct bgp_rmap *rmap; | |
3986 | ||
3987 | rmap = &bgp->table_map[afi][safi]; | |
3988 | if (rmap->name) | |
6e919709 | 3989 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name); |
73ac8160 DS |
3990 | rmap->name = NULL; |
3991 | rmap->map = NULL; | |
3992 | ||
3993 | bgp_zebra_announce_table(bgp, afi, safi); | |
3994 | ||
3995 | return CMD_SUCCESS; | |
3996 | } | |
3997 | ||
3998 | int | |
3999 | bgp_config_write_table_map (struct vty *vty, struct bgp *bgp, afi_t afi, | |
4000 | safi_t safi, int *write) | |
4001 | { | |
4002 | if (bgp->table_map[afi][safi].name) | |
4003 | { | |
4004 | bgp_config_write_family_header (vty, afi, safi, write); | |
0b960b4d | 4005 | vty_out (vty, " table-map %s%s", |
73ac8160 DS |
4006 | bgp->table_map[afi][safi].name, VTY_NEWLINE); |
4007 | } | |
4008 | ||
4009 | return 0; | |
4010 | } | |
4011 | ||
4012 | ||
4013 | DEFUN (bgp_table_map, | |
4014 | bgp_table_map_cmd, | |
4015 | "table-map WORD", | |
4016 | "BGP table to RIB route download filter\n" | |
4017 | "Name of the route map\n") | |
4018 | { | |
4019 | return bgp_table_map_set (vty, vty->index, | |
4020 | bgp_node_afi (vty), bgp_node_safi (vty), argv[0]); | |
4021 | } | |
4022 | DEFUN (no_bgp_table_map, | |
4023 | no_bgp_table_map_cmd, | |
4024 | "no table-map WORD", | |
4025 | "BGP table to RIB route download filter\n" | |
4026 | "Name of the route map\n") | |
4027 | { | |
4028 | return bgp_table_map_unset (vty, vty->index, | |
4029 | bgp_node_afi (vty), bgp_node_safi (vty), argv[0]); | |
4030 | } | |
4031 | ||
718e3744 | 4032 | DEFUN (bgp_network, |
4033 | bgp_network_cmd, | |
4034 | "network A.B.C.D/M", | |
4035 | "Specify a network to announce via BGP\n" | |
4036 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
4037 | { | |
4038 | return bgp_static_set (vty, vty->index, argv[0], | |
c8f3fe30 | 4039 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4040 | } |
4041 | ||
4042 | DEFUN (bgp_network_route_map, | |
4043 | bgp_network_route_map_cmd, | |
4044 | "network A.B.C.D/M route-map WORD", | |
4045 | "Specify a network to announce via BGP\n" | |
4046 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4047 | "Route-map to modify the attributes\n" | |
4048 | "Name of the route map\n") | |
4049 | { | |
4050 | return bgp_static_set (vty, vty->index, argv[0], | |
c8f3fe30 | 4051 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4052 | } |
4053 | ||
4054 | DEFUN (bgp_network_backdoor, | |
4055 | bgp_network_backdoor_cmd, | |
4056 | "network A.B.C.D/M backdoor", | |
4057 | "Specify a network to announce via BGP\n" | |
4058 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4059 | "Specify a BGP backdoor route\n") | |
4060 | { | |
41367172 | 4061 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4062 | NULL, 1); |
718e3744 | 4063 | } |
4064 | ||
4065 | DEFUN (bgp_network_mask, | |
4066 | bgp_network_mask_cmd, | |
4067 | "network A.B.C.D mask A.B.C.D", | |
4068 | "Specify a network to announce via BGP\n" | |
4069 | "Network number\n" | |
4070 | "Network mask\n" | |
4071 | "Network mask\n") | |
4072 | { | |
4073 | int ret; | |
4074 | char prefix_str[BUFSIZ]; | |
41367172 | 4075 | |
718e3744 | 4076 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4077 | if (! ret) | |
4078 | { | |
4079 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4080 | return CMD_WARNING; | |
4081 | } | |
4082 | ||
4083 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4084 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4085 | } |
4086 | ||
4087 | DEFUN (bgp_network_mask_route_map, | |
4088 | bgp_network_mask_route_map_cmd, | |
4089 | "network A.B.C.D mask A.B.C.D route-map WORD", | |
4090 | "Specify a network to announce via BGP\n" | |
4091 | "Network number\n" | |
4092 | "Network mask\n" | |
4093 | "Network mask\n" | |
4094 | "Route-map to modify the attributes\n" | |
4095 | "Name of the route map\n") | |
4096 | { | |
4097 | int ret; | |
4098 | char prefix_str[BUFSIZ]; | |
41367172 | 4099 | |
718e3744 | 4100 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4101 | if (! ret) | |
4102 | { | |
4103 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4104 | return CMD_WARNING; | |
4105 | } | |
4106 | ||
4107 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4108 | AFI_IP, bgp_node_safi (vty), argv[2], 0); |
718e3744 | 4109 | } |
4110 | ||
4111 | DEFUN (bgp_network_mask_backdoor, | |
4112 | bgp_network_mask_backdoor_cmd, | |
4113 | "network A.B.C.D mask A.B.C.D backdoor", | |
4114 | "Specify a network to announce via BGP\n" | |
4115 | "Network number\n" | |
4116 | "Network mask\n" | |
4117 | "Network mask\n" | |
4118 | "Specify a BGP backdoor route\n") | |
4119 | { | |
4120 | int ret; | |
4121 | char prefix_str[BUFSIZ]; | |
41367172 | 4122 | |
718e3744 | 4123 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
4124 | if (! ret) | |
4125 | { | |
4126 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4127 | return CMD_WARNING; | |
4128 | } | |
4129 | ||
41367172 | 4130 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4131 | NULL, 1); |
718e3744 | 4132 | } |
4133 | ||
4134 | DEFUN (bgp_network_mask_natural, | |
4135 | bgp_network_mask_natural_cmd, | |
4136 | "network A.B.C.D", | |
4137 | "Specify a network to announce via BGP\n" | |
4138 | "Network number\n") | |
4139 | { | |
4140 | int ret; | |
4141 | char prefix_str[BUFSIZ]; | |
4142 | ||
4143 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4144 | if (! ret) | |
4145 | { | |
4146 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4147 | return CMD_WARNING; | |
4148 | } | |
4149 | ||
4150 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4151 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
718e3744 | 4152 | } |
4153 | ||
4154 | DEFUN (bgp_network_mask_natural_route_map, | |
4155 | bgp_network_mask_natural_route_map_cmd, | |
4156 | "network A.B.C.D route-map WORD", | |
4157 | "Specify a network to announce via BGP\n" | |
4158 | "Network number\n" | |
4159 | "Route-map to modify the attributes\n" | |
4160 | "Name of the route map\n") | |
4161 | { | |
4162 | int ret; | |
4163 | char prefix_str[BUFSIZ]; | |
4164 | ||
4165 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4166 | if (! ret) | |
4167 | { | |
4168 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4169 | return CMD_WARNING; | |
4170 | } | |
4171 | ||
4172 | return bgp_static_set (vty, vty->index, prefix_str, | |
c8f3fe30 | 4173 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4174 | } |
4175 | ||
4176 | DEFUN (bgp_network_mask_natural_backdoor, | |
4177 | bgp_network_mask_natural_backdoor_cmd, | |
4178 | "network A.B.C.D backdoor", | |
4179 | "Specify a network to announce via BGP\n" | |
4180 | "Network number\n" | |
4181 | "Specify a BGP backdoor route\n") | |
4182 | { | |
4183 | int ret; | |
4184 | char prefix_str[BUFSIZ]; | |
4185 | ||
4186 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4187 | if (! ret) | |
4188 | { | |
4189 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4190 | return CMD_WARNING; | |
4191 | } | |
4192 | ||
41367172 | 4193 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
c8f3fe30 | 4194 | NULL, 1); |
718e3744 | 4195 | } |
4196 | ||
4197 | DEFUN (no_bgp_network, | |
4198 | no_bgp_network_cmd, | |
4199 | "no network A.B.C.D/M", | |
4200 | NO_STR | |
4201 | "Specify a network to announce via BGP\n" | |
4202 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
4203 | { | |
4204 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP, | |
4205 | bgp_node_safi (vty)); | |
4206 | } | |
4207 | ||
4208 | ALIAS (no_bgp_network, | |
4209 | no_bgp_network_route_map_cmd, | |
4210 | "no network A.B.C.D/M route-map WORD", | |
4211 | NO_STR | |
4212 | "Specify a network to announce via BGP\n" | |
4213 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4214 | "Route-map to modify the attributes\n" | |
4215 | "Name of the route map\n") | |
4216 | ||
4217 | ALIAS (no_bgp_network, | |
4218 | no_bgp_network_backdoor_cmd, | |
4219 | "no network A.B.C.D/M backdoor", | |
4220 | NO_STR | |
4221 | "Specify a network to announce via BGP\n" | |
4222 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
4223 | "Specify a BGP backdoor route\n") | |
4224 | ||
4225 | DEFUN (no_bgp_network_mask, | |
4226 | no_bgp_network_mask_cmd, | |
4227 | "no network A.B.C.D mask A.B.C.D", | |
4228 | NO_STR | |
4229 | "Specify a network to announce via BGP\n" | |
4230 | "Network number\n" | |
4231 | "Network mask\n" | |
4232 | "Network mask\n") | |
4233 | { | |
4234 | int ret; | |
4235 | char prefix_str[BUFSIZ]; | |
4236 | ||
4237 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
4238 | if (! ret) | |
4239 | { | |
4240 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4241 | return CMD_WARNING; | |
4242 | } | |
4243 | ||
4244 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, | |
4245 | bgp_node_safi (vty)); | |
4246 | } | |
4247 | ||
4248 | ALIAS (no_bgp_network_mask, | |
4249 | no_bgp_network_mask_route_map_cmd, | |
4250 | "no network A.B.C.D mask A.B.C.D route-map WORD", | |
4251 | NO_STR | |
4252 | "Specify a network to announce via BGP\n" | |
4253 | "Network number\n" | |
4254 | "Network mask\n" | |
4255 | "Network mask\n" | |
4256 | "Route-map to modify the attributes\n" | |
4257 | "Name of the route map\n") | |
4258 | ||
4259 | ALIAS (no_bgp_network_mask, | |
4260 | no_bgp_network_mask_backdoor_cmd, | |
4261 | "no network A.B.C.D mask A.B.C.D backdoor", | |
4262 | NO_STR | |
4263 | "Specify a network to announce via BGP\n" | |
4264 | "Network number\n" | |
4265 | "Network mask\n" | |
4266 | "Network mask\n" | |
4267 | "Specify a BGP backdoor route\n") | |
4268 | ||
4269 | DEFUN (no_bgp_network_mask_natural, | |
4270 | no_bgp_network_mask_natural_cmd, | |
4271 | "no network A.B.C.D", | |
4272 | NO_STR | |
4273 | "Specify a network to announce via BGP\n" | |
4274 | "Network number\n") | |
4275 | { | |
4276 | int ret; | |
4277 | char prefix_str[BUFSIZ]; | |
4278 | ||
4279 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); | |
4280 | if (! ret) | |
4281 | { | |
4282 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4283 | return CMD_WARNING; | |
4284 | } | |
4285 | ||
4286 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, | |
4287 | bgp_node_safi (vty)); | |
4288 | } | |
4289 | ||
4290 | ALIAS (no_bgp_network_mask_natural, | |
4291 | no_bgp_network_mask_natural_route_map_cmd, | |
4292 | "no network A.B.C.D route-map WORD", | |
4293 | NO_STR | |
4294 | "Specify a network to announce via BGP\n" | |
4295 | "Network number\n" | |
4296 | "Route-map to modify the attributes\n" | |
4297 | "Name of the route map\n") | |
4298 | ||
4299 | ALIAS (no_bgp_network_mask_natural, | |
4300 | no_bgp_network_mask_natural_backdoor_cmd, | |
4301 | "no network A.B.C.D backdoor", | |
4302 | NO_STR | |
4303 | "Specify a network to announce via BGP\n" | |
4304 | "Network number\n" | |
4305 | "Specify a BGP backdoor route\n") | |
4306 | ||
4307 | #ifdef HAVE_IPV6 | |
4308 | DEFUN (ipv6_bgp_network, | |
4309 | ipv6_bgp_network_cmd, | |
4310 | "network X:X::X:X/M", | |
4311 | "Specify a network to announce via BGP\n" | |
4312 | "IPv6 prefix <network>/<length>\n") | |
4313 | { | |
73bfe0bd | 4314 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty), |
c8f3fe30 | 4315 | NULL, 0); |
718e3744 | 4316 | } |
4317 | ||
4318 | DEFUN (ipv6_bgp_network_route_map, | |
4319 | ipv6_bgp_network_route_map_cmd, | |
4320 | "network X:X::X:X/M route-map WORD", | |
4321 | "Specify a network to announce via BGP\n" | |
4322 | "IPv6 prefix <network>/<length>\n" | |
4323 | "Route-map to modify the attributes\n" | |
4324 | "Name of the route map\n") | |
4325 | { | |
4326 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, | |
c8f3fe30 | 4327 | bgp_node_safi (vty), argv[1], 0); |
718e3744 | 4328 | } |
4329 | ||
4330 | DEFUN (no_ipv6_bgp_network, | |
4331 | no_ipv6_bgp_network_cmd, | |
4332 | "no network X:X::X:X/M", | |
4333 | NO_STR | |
4334 | "Specify a network to announce via BGP\n" | |
4335 | "IPv6 prefix <network>/<length>\n") | |
4336 | { | |
73bfe0bd | 4337 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty)); |
718e3744 | 4338 | } |
4339 | ||
4340 | ALIAS (no_ipv6_bgp_network, | |
4341 | no_ipv6_bgp_network_route_map_cmd, | |
4342 | "no network X:X::X:X/M route-map WORD", | |
4343 | NO_STR | |
4344 | "Specify a network to announce via BGP\n" | |
4345 | "IPv6 prefix <network>/<length>\n" | |
4346 | "Route-map to modify the attributes\n" | |
4347 | "Name of the route map\n") | |
4348 | ||
4349 | ALIAS (ipv6_bgp_network, | |
4350 | old_ipv6_bgp_network_cmd, | |
4351 | "ipv6 bgp network X:X::X:X/M", | |
4352 | IPV6_STR | |
4353 | BGP_STR | |
4354 | "Specify a network to announce via BGP\n" | |
4355 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") | |
4356 | ||
4357 | ALIAS (no_ipv6_bgp_network, | |
4358 | old_no_ipv6_bgp_network_cmd, | |
4359 | "no ipv6 bgp network X:X::X:X/M", | |
4360 | NO_STR | |
4361 | IPV6_STR | |
4362 | BGP_STR | |
4363 | "Specify a network to announce via BGP\n" | |
4364 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") | |
4365 | #endif /* HAVE_IPV6 */ | |
c8f3fe30 | 4366 | |
718e3744 | 4367 | /* Aggreagete address: |
4368 | ||
4369 | advertise-map Set condition to advertise attribute | |
4370 | as-set Generate AS set path information | |
4371 | attribute-map Set attributes of aggregate | |
4372 | route-map Set parameters of aggregate | |
4373 | summary-only Filter more specific routes from updates | |
4374 | suppress-map Conditionally filter more specific routes from updates | |
4375 | <cr> | |
4376 | */ | |
4377 | struct bgp_aggregate | |
4378 | { | |
4379 | /* Summary-only flag. */ | |
4380 | u_char summary_only; | |
4381 | ||
4382 | /* AS set generation. */ | |
4383 | u_char as_set; | |
4384 | ||
4385 | /* Route-map for aggregated route. */ | |
4386 | struct route_map *map; | |
4387 | ||
4388 | /* Suppress-count. */ | |
4389 | unsigned long count; | |
4390 | ||
4391 | /* SAFI configuration. */ | |
4392 | safi_t safi; | |
4393 | }; | |
4394 | ||
94f2b392 | 4395 | static struct bgp_aggregate * |
66e5cd87 | 4396 | bgp_aggregate_new (void) |
718e3744 | 4397 | { |
393deb9b | 4398 | return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate)); |
718e3744 | 4399 | } |
4400 | ||
94f2b392 | 4401 | static void |
718e3744 | 4402 | bgp_aggregate_free (struct bgp_aggregate *aggregate) |
4403 | { | |
4404 | XFREE (MTYPE_BGP_AGGREGATE, aggregate); | |
4405 | } | |
4406 | ||
b5d58c32 | 4407 | /* Update an aggregate as routes are added/removed from the BGP table */ |
94f2b392 | 4408 | static void |
718e3744 | 4409 | bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew, |
4410 | afi_t afi, safi_t safi, struct bgp_info *del, | |
4411 | struct bgp_aggregate *aggregate) | |
4412 | { | |
4413 | struct bgp_table *table; | |
4414 | struct bgp_node *top; | |
4415 | struct bgp_node *rn; | |
4416 | u_char origin; | |
4417 | struct aspath *aspath = NULL; | |
4418 | struct aspath *asmerge = NULL; | |
4419 | struct community *community = NULL; | |
4420 | struct community *commerge = NULL; | |
ffd0c037 | 4421 | #if defined(AGGREGATE_NEXTHOP_CHECK) |
718e3744 | 4422 | struct in_addr nexthop; |
4423 | u_int32_t med = 0; | |
ffd0c037 | 4424 | #endif |
718e3744 | 4425 | struct bgp_info *ri; |
4426 | struct bgp_info *new; | |
4427 | int first = 1; | |
4428 | unsigned long match = 0; | |
42f7e184 | 4429 | u_char atomic_aggregate = 0; |
718e3744 | 4430 | |
4431 | /* Record adding route's nexthop and med. */ | |
ffd0c037 DS |
4432 | if (rinew) |
4433 | { | |
4434 | #if defined(AGGREGATE_NEXTHOP_CHECK) | |
4435 | nexthop = rinew->attr->nexthop; | |
4436 | med = rinew->attr->med; | |
4437 | #endif | |
4438 | } | |
718e3744 | 4439 | |
4440 | /* ORIGIN attribute: If at least one route among routes that are | |
4441 | aggregated has ORIGIN with the value INCOMPLETE, then the | |
4442 | aggregated route must have the ORIGIN attribute with the value | |
4443 | INCOMPLETE. Otherwise, if at least one route among routes that | |
4444 | are aggregated has ORIGIN with the value EGP, then the aggregated | |
4445 | route must have the origin attribute with the value EGP. In all | |
4446 | other case the value of the ORIGIN attribute of the aggregated | |
4447 | route is INTERNAL. */ | |
4448 | origin = BGP_ORIGIN_IGP; | |
4449 | ||
4450 | table = bgp->rib[afi][safi]; | |
4451 | ||
4452 | top = bgp_node_get (table, p); | |
4453 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
4454 | if (rn->p.prefixlen > p->prefixlen) | |
4455 | { | |
4456 | match = 0; | |
4457 | ||
4458 | for (ri = rn->info; ri; ri = ri->next) | |
4459 | { | |
4460 | if (BGP_INFO_HOLDDOWN (ri)) | |
4461 | continue; | |
4462 | ||
4463 | if (del && ri == del) | |
4464 | continue; | |
4465 | ||
4466 | if (! rinew && first) | |
4467 | { | |
ffd0c037 | 4468 | #if defined(AGGREGATE_NEXTHOP_CHECK) |
718e3744 | 4469 | nexthop = ri->attr->nexthop; |
4470 | med = ri->attr->med; | |
ffd0c037 | 4471 | #endif |
718e3744 | 4472 | first = 0; |
4473 | } | |
4474 | ||
4475 | #ifdef AGGREGATE_NEXTHOP_CHECK | |
4476 | if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop) | |
4477 | || ri->attr->med != med) | |
4478 | { | |
4479 | if (aspath) | |
4480 | aspath_free (aspath); | |
4481 | if (community) | |
4482 | community_free (community); | |
4483 | bgp_unlock_node (rn); | |
4484 | bgp_unlock_node (top); | |
4485 | return; | |
4486 | } | |
4487 | #endif /* AGGREGATE_NEXTHOP_CHECK */ | |
4488 | ||
42f7e184 DS |
4489 | if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
4490 | atomic_aggregate = 1; | |
4491 | ||
718e3744 | 4492 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
4493 | { | |
4494 | if (aggregate->summary_only) | |
4495 | { | |
fb982c25 | 4496 | (bgp_info_extra_get (ri))->suppress++; |
1a392d46 | 4497 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 4498 | match++; |
4499 | } | |
4500 | ||
4501 | aggregate->count++; | |
4502 | ||
b5d58c32 DS |
4503 | if (origin < ri->attr->origin) |
4504 | origin = ri->attr->origin; | |
4505 | ||
718e3744 | 4506 | if (aggregate->as_set) |
4507 | { | |
718e3744 | 4508 | if (aspath) |
4509 | { | |
4510 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); | |
4511 | aspath_free (aspath); | |
4512 | aspath = asmerge; | |
4513 | } | |
4514 | else | |
4515 | aspath = aspath_dup (ri->attr->aspath); | |
4516 | ||
4517 | if (ri->attr->community) | |
4518 | { | |
4519 | if (community) | |
4520 | { | |
4521 | commerge = community_merge (community, | |
4522 | ri->attr->community); | |
4523 | community = community_uniq_sort (commerge); | |
4524 | community_free (commerge); | |
4525 | } | |
4526 | else | |
4527 | community = community_dup (ri->attr->community); | |
4528 | } | |
4529 | } | |
4530 | } | |
4531 | } | |
4532 | if (match) | |
4533 | bgp_process (bgp, rn, afi, safi); | |
4534 | } | |
4535 | bgp_unlock_node (top); | |
4536 | ||
4537 | if (rinew) | |
4538 | { | |
4539 | aggregate->count++; | |
4540 | ||
4541 | if (aggregate->summary_only) | |
fb982c25 | 4542 | (bgp_info_extra_get (rinew))->suppress++; |
718e3744 | 4543 | |
b5d58c32 DS |
4544 | if (origin < rinew->attr->origin) |
4545 | origin = rinew->attr->origin; | |
4546 | ||
718e3744 | 4547 | if (aggregate->as_set) |
4548 | { | |
718e3744 | 4549 | if (aspath) |
4550 | { | |
4551 | asmerge = aspath_aggregate (aspath, rinew->attr->aspath); | |
4552 | aspath_free (aspath); | |
4553 | aspath = asmerge; | |
4554 | } | |
4555 | else | |
4556 | aspath = aspath_dup (rinew->attr->aspath); | |
4557 | ||
4558 | if (rinew->attr->community) | |
4559 | { | |
4560 | if (community) | |
4561 | { | |
4562 | commerge = community_merge (community, | |
4563 | rinew->attr->community); | |
4564 | community = community_uniq_sort (commerge); | |
4565 | community_free (commerge); | |
4566 | } | |
4567 | else | |
4568 | community = community_dup (rinew->attr->community); | |
4569 | } | |
4570 | } | |
4571 | } | |
4572 | ||
4573 | if (aggregate->count > 0) | |
4574 | { | |
4575 | rn = bgp_node_get (table, p); | |
7c8ff89e | 4576 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self, |
fb018d25 | 4577 | bgp_attr_aggregate_intern(bgp, origin, aspath, community, |
42f7e184 DS |
4578 | aggregate->as_set, |
4579 | atomic_aggregate), rn); | |
718e3744 | 4580 | SET_FLAG (new->flags, BGP_INFO_VALID); |
718e3744 | 4581 | |
4582 | bgp_info_add (rn, new); | |
200df115 | 4583 | bgp_unlock_node (rn); |
718e3744 | 4584 | bgp_process (bgp, rn, afi, safi); |
4585 | } | |
4586 | else | |
4587 | { | |
4588 | if (aspath) | |
4589 | aspath_free (aspath); | |
4590 | if (community) | |
4591 | community_free (community); | |
4592 | } | |
4593 | } | |
4594 | ||
4595 | void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t, | |
4596 | struct bgp_aggregate *); | |
4597 | ||
4598 | void | |
4599 | bgp_aggregate_increment (struct bgp *bgp, struct prefix *p, | |
4600 | struct bgp_info *ri, afi_t afi, safi_t safi) | |
4601 | { | |
4602 | struct bgp_node *child; | |
4603 | struct bgp_node *rn; | |
4604 | struct bgp_aggregate *aggregate; | |
f018db83 | 4605 | struct bgp_table *table; |
718e3744 | 4606 | |
4607 | /* MPLS-VPN aggregation is not yet supported. */ | |
4608 | if (safi == SAFI_MPLS_VPN) | |
4609 | return; | |
4610 | ||
f018db83 JBD |
4611 | table = bgp->aggregate[afi][safi]; |
4612 | ||
4613 | /* No aggregates configured. */ | |
67174041 | 4614 | if (bgp_table_top_nolock (table) == NULL) |
f018db83 JBD |
4615 | return; |
4616 | ||
718e3744 | 4617 | if (p->prefixlen == 0) |
4618 | return; | |
4619 | ||
4620 | if (BGP_INFO_HOLDDOWN (ri)) | |
4621 | return; | |
4622 | ||
bb782fb5 | 4623 | child = bgp_node_get (table, p); |
718e3744 | 4624 | |
4625 | /* Aggregate address configuration check. */ | |
67174041 | 4626 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
718e3744 | 4627 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
4628 | { | |
4629 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); | |
286e1e71 | 4630 | bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate); |
718e3744 | 4631 | } |
4632 | bgp_unlock_node (child); | |
4633 | } | |
4634 | ||
4635 | void | |
4636 | bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p, | |
4637 | struct bgp_info *del, afi_t afi, safi_t safi) | |
4638 | { | |
4639 | struct bgp_node *child; | |
4640 | struct bgp_node *rn; | |
4641 | struct bgp_aggregate *aggregate; | |
f018db83 | 4642 | struct bgp_table *table; |
718e3744 | 4643 | |
4644 | /* MPLS-VPN aggregation is not yet supported. */ | |
4645 | if (safi == SAFI_MPLS_VPN) | |
4646 | return; | |
4647 | ||
f018db83 JBD |
4648 | table = bgp->aggregate[afi][safi]; |
4649 | ||
4650 | /* No aggregates configured. */ | |
67174041 | 4651 | if (bgp_table_top_nolock (table) == NULL) |
f018db83 JBD |
4652 | return; |
4653 | ||
718e3744 | 4654 | if (p->prefixlen == 0) |
4655 | return; | |
4656 | ||
bb782fb5 | 4657 | child = bgp_node_get (table, p); |
718e3744 | 4658 | |
4659 | /* Aggregate address configuration check. */ | |
67174041 | 4660 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
718e3744 | 4661 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
4662 | { | |
4663 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); | |
286e1e71 | 4664 | bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate); |
718e3744 | 4665 | } |
4666 | bgp_unlock_node (child); | |
4667 | } | |
4668 | ||
b5d58c32 | 4669 | /* Called via bgp_aggregate_set when the user configures aggregate-address */ |
94f2b392 | 4670 | static void |
718e3744 | 4671 | bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi, |
4672 | struct bgp_aggregate *aggregate) | |
4673 | { | |
4674 | struct bgp_table *table; | |
4675 | struct bgp_node *top; | |
4676 | struct bgp_node *rn; | |
4677 | struct bgp_info *new; | |
4678 | struct bgp_info *ri; | |
4679 | unsigned long match; | |
4680 | u_char origin = BGP_ORIGIN_IGP; | |
4681 | struct aspath *aspath = NULL; | |
4682 | struct aspath *asmerge = NULL; | |
4683 | struct community *community = NULL; | |
4684 | struct community *commerge = NULL; | |
42f7e184 | 4685 | u_char atomic_aggregate = 0; |
718e3744 | 4686 | |
4687 | table = bgp->rib[afi][safi]; | |
4688 | ||
4689 | /* Sanity check. */ | |
4690 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) | |
4691 | return; | |
4692 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) | |
4693 | return; | |
4694 | ||
4695 | /* If routes exists below this node, generate aggregate routes. */ | |
4696 | top = bgp_node_get (table, p); | |
4697 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
4698 | if (rn->p.prefixlen > p->prefixlen) | |
4699 | { | |
4700 | match = 0; | |
4701 | ||
4702 | for (ri = rn->info; ri; ri = ri->next) | |
4703 | { | |
4704 | if (BGP_INFO_HOLDDOWN (ri)) | |
4705 | continue; | |
4706 | ||
42f7e184 DS |
4707 | if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
4708 | atomic_aggregate = 1; | |
4709 | ||
718e3744 | 4710 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
4711 | { | |
4712 | /* summary-only aggregate route suppress aggregated | |
4713 | route announcement. */ | |
4714 | if (aggregate->summary_only) | |
4715 | { | |
fb982c25 | 4716 | (bgp_info_extra_get (ri))->suppress++; |
1a392d46 | 4717 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 4718 | match++; |
4719 | } | |
b5d58c32 DS |
4720 | |
4721 | /* If at least one route among routes that are aggregated has | |
4722 | * ORIGIN with the value INCOMPLETE, then the aggregated route | |
4723 | * MUST have the ORIGIN attribute with the value INCOMPLETE. | |
4724 | * Otherwise, if at least one route among routes that are | |
4725 | * aggregated has ORIGIN with the value EGP, then the aggregated | |
4726 | * route MUST have the ORIGIN attribute with the value EGP. | |
4727 | */ | |
4728 | if (origin < ri->attr->origin) | |
4729 | origin = ri->attr->origin; | |
4730 | ||
718e3744 | 4731 | /* as-set aggregate route generate origin, as path, |
4732 | community aggregation. */ | |
4733 | if (aggregate->as_set) | |
4734 | { | |
718e3744 | 4735 | if (aspath) |
4736 | { | |
4737 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); | |
4738 | aspath_free (aspath); | |
4739 | aspath = asmerge; | |
4740 | } | |
4741 | else | |
4742 | aspath = aspath_dup (ri->attr->aspath); | |
4743 | ||
4744 | if (ri->attr->community) | |
4745 | { | |
4746 | if (community) | |
4747 | { | |
4748 | commerge = community_merge (community, | |
4749 | ri->attr->community); | |
4750 | community = community_uniq_sort (commerge); | |
4751 | community_free (commerge); | |
4752 | } | |
4753 | else | |
4754 | community = community_dup (ri->attr->community); | |
4755 | } | |
4756 | } | |
4757 | aggregate->count++; | |
4758 | } | |
4759 | } | |
4760 | ||
4761 | /* If this node is suppressed, process the change. */ | |
4762 | if (match) | |
4763 | bgp_process (bgp, rn, afi, safi); | |
4764 | } | |
4765 | bgp_unlock_node (top); | |
4766 | ||
4767 | /* Add aggregate route to BGP table. */ | |
4768 | if (aggregate->count) | |
4769 | { | |
4770 | rn = bgp_node_get (table, p); | |
7c8ff89e | 4771 | new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0, bgp->peer_self, |
fb018d25 | 4772 | bgp_attr_aggregate_intern(bgp, origin, aspath, community, |
42f7e184 DS |
4773 | aggregate->as_set, |
4774 | atomic_aggregate), rn); | |
718e3744 | 4775 | SET_FLAG (new->flags, BGP_INFO_VALID); |
718e3744 | 4776 | |
4777 | bgp_info_add (rn, new); | |
200df115 | 4778 | bgp_unlock_node (rn); |
4779 | ||
718e3744 | 4780 | /* Process change. */ |
4781 | bgp_process (bgp, rn, afi, safi); | |
4782 | } | |
610f23cf DV |
4783 | else |
4784 | { | |
4785 | if (aspath) | |
4786 | aspath_free (aspath); | |
4787 | if (community) | |
4788 | community_free (community); | |
4789 | } | |
718e3744 | 4790 | } |
4791 | ||
4792 | void | |
4793 | bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi, | |
4794 | safi_t safi, struct bgp_aggregate *aggregate) | |
4795 | { | |
4796 | struct bgp_table *table; | |
4797 | struct bgp_node *top; | |
4798 | struct bgp_node *rn; | |
4799 | struct bgp_info *ri; | |
4800 | unsigned long match; | |
4801 | ||
4802 | table = bgp->rib[afi][safi]; | |
4803 | ||
4804 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) | |
4805 | return; | |
4806 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) | |
4807 | return; | |
4808 | ||
4809 | /* If routes exists below this node, generate aggregate routes. */ | |
4810 | top = bgp_node_get (table, p); | |
4811 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) | |
4812 | if (rn->p.prefixlen > p->prefixlen) | |
4813 | { | |
4814 | match = 0; | |
4815 | ||
4816 | for (ri = rn->info; ri; ri = ri->next) | |
4817 | { | |
4818 | if (BGP_INFO_HOLDDOWN (ri)) | |
4819 | continue; | |
4820 | ||
4821 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) | |
4822 | { | |
fb982c25 | 4823 | if (aggregate->summary_only && ri->extra) |
718e3744 | 4824 | { |
fb982c25 | 4825 | ri->extra->suppress--; |
718e3744 | 4826 | |
fb982c25 | 4827 | if (ri->extra->suppress == 0) |
718e3744 | 4828 | { |
1a392d46 | 4829 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
718e3744 | 4830 | match++; |
4831 | } | |
4832 | } | |
4833 | aggregate->count--; | |
4834 | } | |
4835 | } | |
4836 | ||
fb982c25 | 4837 | /* If this node was suppressed, process the change. */ |
718e3744 | 4838 | if (match) |
4839 | bgp_process (bgp, rn, afi, safi); | |
4840 | } | |
4841 | bgp_unlock_node (top); | |
4842 | ||
4843 | /* Delete aggregate route from BGP table. */ | |
4844 | rn = bgp_node_get (table, p); | |
4845 | ||
4846 | for (ri = rn->info; ri; ri = ri->next) | |
4847 | if (ri->peer == bgp->peer_self | |
4848 | && ri->type == ZEBRA_ROUTE_BGP | |
4849 | && ri->sub_type == BGP_ROUTE_AGGREGATE) | |
4850 | break; | |
4851 | ||
4852 | /* Withdraw static BGP route from routing table. */ | |
4853 | if (ri) | |
4854 | { | |
718e3744 | 4855 | bgp_info_delete (rn, ri); |
1a392d46 | 4856 | bgp_process (bgp, rn, afi, safi); |
718e3744 | 4857 | } |
4858 | ||
4859 | /* Unlock bgp_node_lookup. */ | |
4860 | bgp_unlock_node (rn); | |
4861 | } | |
4862 | ||
4863 | /* Aggregate route attribute. */ | |
4864 | #define AGGREGATE_SUMMARY_ONLY 1 | |
4865 | #define AGGREGATE_AS_SET 1 | |
4866 | ||
94f2b392 | 4867 | static int |
f6269b4f RB |
4868 | bgp_aggregate_unset (struct vty *vty, const char *prefix_str, |
4869 | afi_t afi, safi_t safi) | |
718e3744 | 4870 | { |
4871 | int ret; | |
4872 | struct prefix p; | |
4873 | struct bgp_node *rn; | |
4874 | struct bgp *bgp; | |
4875 | struct bgp_aggregate *aggregate; | |
4876 | ||
4877 | /* Convert string to prefix structure. */ | |
4878 | ret = str2prefix (prefix_str, &p); | |
4879 | if (!ret) | |
4880 | { | |
4881 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
4882 | return CMD_WARNING; | |
4883 | } | |
4884 | apply_mask (&p); | |
4885 | ||
4886 | /* Get BGP structure. */ | |
4887 | bgp = vty->index; | |
4888 | ||
4889 | /* Old configuration check. */ | |
f6269b4f RB |
4890 | rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p); |
4891 | if (! rn) | |
718e3744 | 4892 | { |
f6269b4f RB |
4893 | vty_out (vty, "%% There is no aggregate-address configuration.%s", |
4894 | VTY_NEWLINE); | |
718e3744 | 4895 | return CMD_WARNING; |
4896 | } | |
4897 | ||
f6269b4f RB |
4898 | aggregate = rn->info; |
4899 | if (aggregate->safi & SAFI_UNICAST) | |
4900 | bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate); | |
4901 | if (aggregate->safi & SAFI_MULTICAST) | |
4902 | bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate); | |
718e3744 | 4903 | |
f6269b4f RB |
4904 | /* Unlock aggregate address configuration. */ |
4905 | rn->info = NULL; | |
4906 | bgp_aggregate_free (aggregate); | |
4907 | bgp_unlock_node (rn); | |
4908 | bgp_unlock_node (rn); | |
718e3744 | 4909 | |
4910 | return CMD_SUCCESS; | |
4911 | } | |
4912 | ||
94f2b392 | 4913 | static int |
f6269b4f RB |
4914 | bgp_aggregate_set (struct vty *vty, const char *prefix_str, |
4915 | afi_t afi, safi_t safi, | |
4916 | u_char summary_only, u_char as_set) | |
718e3744 | 4917 | { |
4918 | int ret; | |
4919 | struct prefix p; | |
4920 | struct bgp_node *rn; | |
4921 | struct bgp *bgp; | |
4922 | struct bgp_aggregate *aggregate; | |
4923 | ||
4924 | /* Convert string to prefix structure. */ | |
4925 | ret = str2prefix (prefix_str, &p); | |
4926 | if (!ret) | |
4927 | { | |
4928 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
4929 | return CMD_WARNING; | |
4930 | } | |
4931 | apply_mask (&p); | |
4932 | ||
4933 | /* Get BGP structure. */ | |
4934 | bgp = vty->index; | |
4935 | ||
4936 | /* Old configuration check. */ | |
f6269b4f RB |
4937 | rn = bgp_node_get (bgp->aggregate[afi][safi], &p); |
4938 | ||
4939 | if (rn->info) | |
718e3744 | 4940 | { |
f6269b4f | 4941 | vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE); |
368473f6 | 4942 | /* try to remove the old entry */ |
f6269b4f RB |
4943 | ret = bgp_aggregate_unset (vty, prefix_str, afi, safi); |
4944 | if (ret) | |
4945 | { | |
368473f6 RB |
4946 | vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE); |
4947 | bgp_unlock_node (rn); | |
f6269b4f RB |
4948 | return CMD_WARNING; |
4949 | } | |
718e3744 | 4950 | } |
4951 | ||
f6269b4f RB |
4952 | /* Make aggregate address structure. */ |
4953 | aggregate = bgp_aggregate_new (); | |
4954 | aggregate->summary_only = summary_only; | |
4955 | aggregate->as_set = as_set; | |
4956 | aggregate->safi = safi; | |
4957 | rn->info = aggregate; | |
718e3744 | 4958 | |
f6269b4f RB |
4959 | /* Aggregate address insert into BGP routing table. */ |
4960 | if (safi & SAFI_UNICAST) | |
4961 | bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate); | |
4962 | if (safi & SAFI_MULTICAST) | |
4963 | bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate); | |
718e3744 | 4964 | |
4965 | return CMD_SUCCESS; | |
4966 | } | |
4967 | ||
4968 | DEFUN (aggregate_address, | |
4969 | aggregate_address_cmd, | |
4970 | "aggregate-address A.B.C.D/M", | |
4971 | "Configure BGP aggregate entries\n" | |
4972 | "Aggregate prefix\n") | |
4973 | { | |
4974 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0); | |
4975 | } | |
4976 | ||
4977 | DEFUN (aggregate_address_mask, | |
4978 | aggregate_address_mask_cmd, | |
4979 | "aggregate-address A.B.C.D A.B.C.D", | |
4980 | "Configure BGP aggregate entries\n" | |
4981 | "Aggregate address\n" | |
4982 | "Aggregate mask\n") | |
4983 | { | |
4984 | int ret; | |
4985 | char prefix_str[BUFSIZ]; | |
4986 | ||
4987 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
4988 | ||
4989 | if (! ret) | |
4990 | { | |
4991 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
4992 | return CMD_WARNING; | |
4993 | } | |
4994 | ||
4995 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
4996 | 0, 0); | |
4997 | } | |
4998 | ||
4999 | DEFUN (aggregate_address_summary_only, | |
5000 | aggregate_address_summary_only_cmd, | |
5001 | "aggregate-address A.B.C.D/M summary-only", | |
5002 | "Configure BGP aggregate entries\n" | |
5003 | "Aggregate prefix\n" | |
5004 | "Filter more specific routes from updates\n") | |
5005 | { | |
5006 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5007 | AGGREGATE_SUMMARY_ONLY, 0); | |
5008 | } | |
5009 | ||
5010 | DEFUN (aggregate_address_mask_summary_only, | |
5011 | aggregate_address_mask_summary_only_cmd, | |
5012 | "aggregate-address A.B.C.D A.B.C.D summary-only", | |
5013 | "Configure BGP aggregate entries\n" | |
5014 | "Aggregate address\n" | |
5015 | "Aggregate mask\n" | |
5016 | "Filter more specific routes from updates\n") | |
5017 | { | |
5018 | int ret; | |
5019 | char prefix_str[BUFSIZ]; | |
5020 | ||
5021 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5022 | ||
5023 | if (! ret) | |
5024 | { | |
5025 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5026 | return CMD_WARNING; | |
5027 | } | |
5028 | ||
5029 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5030 | AGGREGATE_SUMMARY_ONLY, 0); | |
5031 | } | |
5032 | ||
5033 | DEFUN (aggregate_address_as_set, | |
5034 | aggregate_address_as_set_cmd, | |
5035 | "aggregate-address A.B.C.D/M as-set", | |
5036 | "Configure BGP aggregate entries\n" | |
5037 | "Aggregate prefix\n" | |
5038 | "Generate AS set path information\n") | |
5039 | { | |
5040 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5041 | 0, AGGREGATE_AS_SET); | |
5042 | } | |
5043 | ||
5044 | DEFUN (aggregate_address_mask_as_set, | |
5045 | aggregate_address_mask_as_set_cmd, | |
5046 | "aggregate-address A.B.C.D A.B.C.D as-set", | |
5047 | "Configure BGP aggregate entries\n" | |
5048 | "Aggregate address\n" | |
5049 | "Aggregate mask\n" | |
5050 | "Generate AS set path information\n") | |
5051 | { | |
5052 | int ret; | |
5053 | char prefix_str[BUFSIZ]; | |
5054 | ||
5055 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5056 | ||
5057 | if (! ret) | |
5058 | { | |
5059 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5060 | return CMD_WARNING; | |
5061 | } | |
5062 | ||
5063 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5064 | 0, AGGREGATE_AS_SET); | |
5065 | } | |
5066 | ||
5067 | ||
5068 | DEFUN (aggregate_address_as_set_summary, | |
5069 | aggregate_address_as_set_summary_cmd, | |
5070 | "aggregate-address A.B.C.D/M as-set summary-only", | |
5071 | "Configure BGP aggregate entries\n" | |
5072 | "Aggregate prefix\n" | |
5073 | "Generate AS set path information\n" | |
5074 | "Filter more specific routes from updates\n") | |
5075 | { | |
5076 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), | |
5077 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); | |
5078 | } | |
5079 | ||
5080 | ALIAS (aggregate_address_as_set_summary, | |
5081 | aggregate_address_summary_as_set_cmd, | |
5082 | "aggregate-address A.B.C.D/M summary-only as-set", | |
5083 | "Configure BGP aggregate entries\n" | |
5084 | "Aggregate prefix\n" | |
5085 | "Filter more specific routes from updates\n" | |
5086 | "Generate AS set path information\n") | |
5087 | ||
5088 | DEFUN (aggregate_address_mask_as_set_summary, | |
5089 | aggregate_address_mask_as_set_summary_cmd, | |
5090 | "aggregate-address A.B.C.D A.B.C.D as-set summary-only", | |
5091 | "Configure BGP aggregate entries\n" | |
5092 | "Aggregate address\n" | |
5093 | "Aggregate mask\n" | |
5094 | "Generate AS set path information\n" | |
5095 | "Filter more specific routes from updates\n") | |
5096 | { | |
5097 | int ret; | |
5098 | char prefix_str[BUFSIZ]; | |
5099 | ||
5100 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5101 | ||
5102 | if (! ret) | |
5103 | { | |
5104 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5105 | return CMD_WARNING; | |
5106 | } | |
5107 | ||
5108 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), | |
5109 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); | |
5110 | } | |
5111 | ||
5112 | ALIAS (aggregate_address_mask_as_set_summary, | |
5113 | aggregate_address_mask_summary_as_set_cmd, | |
5114 | "aggregate-address A.B.C.D A.B.C.D summary-only as-set", | |
5115 | "Configure BGP aggregate entries\n" | |
5116 | "Aggregate address\n" | |
5117 | "Aggregate mask\n" | |
5118 | "Filter more specific routes from updates\n" | |
5119 | "Generate AS set path information\n") | |
5120 | ||
5121 | DEFUN (no_aggregate_address, | |
5122 | no_aggregate_address_cmd, | |
5123 | "no aggregate-address A.B.C.D/M", | |
5124 | NO_STR | |
5125 | "Configure BGP aggregate entries\n" | |
5126 | "Aggregate prefix\n") | |
5127 | { | |
5128 | return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty)); | |
5129 | } | |
5130 | ||
5131 | ALIAS (no_aggregate_address, | |
5132 | no_aggregate_address_summary_only_cmd, | |
5133 | "no aggregate-address A.B.C.D/M summary-only", | |
5134 | NO_STR | |
5135 | "Configure BGP aggregate entries\n" | |
5136 | "Aggregate prefix\n" | |
5137 | "Filter more specific routes from updates\n") | |
5138 | ||
5139 | ALIAS (no_aggregate_address, | |
5140 | no_aggregate_address_as_set_cmd, | |
5141 | "no aggregate-address A.B.C.D/M as-set", | |
5142 | NO_STR | |
5143 | "Configure BGP aggregate entries\n" | |
5144 | "Aggregate prefix\n" | |
5145 | "Generate AS set path information\n") | |
5146 | ||
5147 | ALIAS (no_aggregate_address, | |
5148 | no_aggregate_address_as_set_summary_cmd, | |
5149 | "no aggregate-address A.B.C.D/M as-set summary-only", | |
5150 | NO_STR | |
5151 | "Configure BGP aggregate entries\n" | |
5152 | "Aggregate prefix\n" | |
5153 | "Generate AS set path information\n" | |
5154 | "Filter more specific routes from updates\n") | |
5155 | ||
5156 | ALIAS (no_aggregate_address, | |
5157 | no_aggregate_address_summary_as_set_cmd, | |
5158 | "no aggregate-address A.B.C.D/M summary-only as-set", | |
5159 | NO_STR | |
5160 | "Configure BGP aggregate entries\n" | |
5161 | "Aggregate prefix\n" | |
5162 | "Filter more specific routes from updates\n" | |
5163 | "Generate AS set path information\n") | |
5164 | ||
5165 | DEFUN (no_aggregate_address_mask, | |
5166 | no_aggregate_address_mask_cmd, | |
5167 | "no aggregate-address A.B.C.D A.B.C.D", | |
5168 | NO_STR | |
5169 | "Configure BGP aggregate entries\n" | |
5170 | "Aggregate address\n" | |
5171 | "Aggregate mask\n") | |
5172 | { | |
5173 | int ret; | |
5174 | char prefix_str[BUFSIZ]; | |
5175 | ||
5176 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
5177 | ||
5178 | if (! ret) | |
5179 | { | |
5180 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
5181 | return CMD_WARNING; | |
5182 | } | |
5183 | ||
5184 | return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty)); | |
5185 | } | |
5186 | ||
5187 | ALIAS (no_aggregate_address_mask, | |
5188 | no_aggregate_address_mask_summary_only_cmd, | |
5189 | "no aggregate-address A.B.C.D A.B.C.D summary-only", | |
5190 | NO_STR | |
5191 | "Configure BGP aggregate entries\n" | |
5192 | "Aggregate address\n" | |
5193 | "Aggregate mask\n" | |
5194 | "Filter more specific routes from updates\n") | |
5195 | ||
5196 | ALIAS (no_aggregate_address_mask, | |
5197 | no_aggregate_address_mask_as_set_cmd, | |
5198 | "no aggregate-address A.B.C.D A.B.C.D as-set", | |
5199 | NO_STR | |
5200 | "Configure BGP aggregate entries\n" | |
5201 | "Aggregate address\n" | |
5202 | "Aggregate mask\n" | |
5203 | "Generate AS set path information\n") | |
5204 | ||
5205 | ALIAS (no_aggregate_address_mask, | |
5206 | no_aggregate_address_mask_as_set_summary_cmd, | |
5207 | "no aggregate-address A.B.C.D A.B.C.D as-set summary-only", | |
5208 | NO_STR | |
5209 | "Configure BGP aggregate entries\n" | |
5210 | "Aggregate address\n" | |
5211 | "Aggregate mask\n" | |
5212 | "Generate AS set path information\n" | |
5213 | "Filter more specific routes from updates\n") | |
5214 | ||
5215 | ALIAS (no_aggregate_address_mask, | |
5216 | no_aggregate_address_mask_summary_as_set_cmd, | |
5217 | "no aggregate-address A.B.C.D A.B.C.D summary-only as-set", | |
5218 | NO_STR | |
5219 | "Configure BGP aggregate entries\n" | |
5220 | "Aggregate address\n" | |
5221 | "Aggregate mask\n" | |
5222 | "Filter more specific routes from updates\n" | |
5223 | "Generate AS set path information\n") | |
5224 | ||
5225 | #ifdef HAVE_IPV6 | |
5226 | DEFUN (ipv6_aggregate_address, | |
5227 | ipv6_aggregate_address_cmd, | |
5228 | "aggregate-address X:X::X:X/M", | |
5229 | "Configure BGP aggregate entries\n" | |
5230 | "Aggregate prefix\n") | |
5231 | { | |
5232 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0); | |
5233 | } | |
5234 | ||
5235 | DEFUN (ipv6_aggregate_address_summary_only, | |
5236 | ipv6_aggregate_address_summary_only_cmd, | |
5237 | "aggregate-address X:X::X:X/M summary-only", | |
5238 | "Configure BGP aggregate entries\n" | |
5239 | "Aggregate prefix\n" | |
5240 | "Filter more specific routes from updates\n") | |
5241 | { | |
5242 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
5243 | AGGREGATE_SUMMARY_ONLY, 0); | |
5244 | } | |
5245 | ||
5246 | DEFUN (no_ipv6_aggregate_address, | |
5247 | no_ipv6_aggregate_address_cmd, | |
5248 | "no aggregate-address X:X::X:X/M", | |
5249 | NO_STR | |
5250 | "Configure BGP aggregate entries\n" | |
5251 | "Aggregate prefix\n") | |
5252 | { | |
5253 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); | |
5254 | } | |
5255 | ||
5256 | DEFUN (no_ipv6_aggregate_address_summary_only, | |
5257 | no_ipv6_aggregate_address_summary_only_cmd, | |
5258 | "no aggregate-address X:X::X:X/M summary-only", | |
5259 | NO_STR | |
5260 | "Configure BGP aggregate entries\n" | |
5261 | "Aggregate prefix\n" | |
5262 | "Filter more specific routes from updates\n") | |
5263 | { | |
5264 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); | |
5265 | } | |
5266 | ||
5267 | ALIAS (ipv6_aggregate_address, | |
5268 | old_ipv6_aggregate_address_cmd, | |
5269 | "ipv6 bgp aggregate-address X:X::X:X/M", | |
5270 | IPV6_STR | |
5271 | BGP_STR | |
5272 | "Configure BGP aggregate entries\n" | |
5273 | "Aggregate prefix\n") | |
5274 | ||
5275 | ALIAS (ipv6_aggregate_address_summary_only, | |
5276 | old_ipv6_aggregate_address_summary_only_cmd, | |
5277 | "ipv6 bgp aggregate-address X:X::X:X/M summary-only", | |
5278 | IPV6_STR | |
5279 | BGP_STR | |
5280 | "Configure BGP aggregate entries\n" | |
5281 | "Aggregate prefix\n" | |
5282 | "Filter more specific routes from updates\n") | |
5283 | ||
5284 | ALIAS (no_ipv6_aggregate_address, | |
5285 | old_no_ipv6_aggregate_address_cmd, | |
5286 | "no ipv6 bgp aggregate-address X:X::X:X/M", | |
5287 | NO_STR | |
5288 | IPV6_STR | |
5289 | BGP_STR | |
5290 | "Configure BGP aggregate entries\n" | |
5291 | "Aggregate prefix\n") | |
5292 | ||
5293 | ALIAS (no_ipv6_aggregate_address_summary_only, | |
5294 | old_no_ipv6_aggregate_address_summary_only_cmd, | |
5295 | "no ipv6 bgp aggregate-address X:X::X:X/M summary-only", | |
5296 | NO_STR | |
5297 | IPV6_STR | |
5298 | BGP_STR | |
5299 | "Configure BGP aggregate entries\n" | |
5300 | "Aggregate prefix\n" | |
5301 | "Filter more specific routes from updates\n") | |
5302 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 5303 | |
718e3744 | 5304 | /* Redistribute route treatment. */ |
5305 | void | |
6aeb9e78 | 5306 | bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop, |
bc413143 | 5307 | const struct in6_addr *nexthop6, unsigned int ifindex, |
7c8ff89e | 5308 | u_int32_t metric, u_char type, u_short instance, u_short tag) |
718e3744 | 5309 | { |
718e3744 | 5310 | struct bgp_info *new; |
5311 | struct bgp_info *bi; | |
5312 | struct bgp_info info; | |
5313 | struct bgp_node *bn; | |
e16a4133 | 5314 | struct attr attr; |
718e3744 | 5315 | struct attr *new_attr; |
5316 | afi_t afi; | |
5317 | int ret; | |
7c8ff89e | 5318 | struct bgp_redist *red; |
718e3744 | 5319 | |
5320 | /* Make default attribute. */ | |
5321 | bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE); | |
5322 | if (nexthop) | |
5323 | attr.nexthop = *nexthop; | |
bc413143 | 5324 | attr.nh_ifindex = ifindex; |
718e3744 | 5325 | |
f04a80a5 SH |
5326 | #ifdef HAVE_IPV6 |
5327 | if (nexthop6) | |
5328 | { | |
5329 | struct attr_extra *extra = bgp_attr_extra_get(&attr); | |
5330 | extra->mp_nexthop_global = *nexthop6; | |
801a9bcc | 5331 | extra->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; |
f04a80a5 SH |
5332 | } |
5333 | #endif | |
5334 | ||
718e3744 | 5335 | attr.med = metric; |
5336 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); | |
0d9551dc | 5337 | attr.extra->tag = tag; |
718e3744 | 5338 | |
6aeb9e78 DS |
5339 | afi = family2afi (p->family); |
5340 | ||
5341 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
5342 | if (red) | |
718e3744 | 5343 | { |
6aeb9e78 DS |
5344 | struct attr attr_new; |
5345 | struct attr_extra extra_new; | |
718e3744 | 5346 | |
6aeb9e78 DS |
5347 | /* Copy attribute for modification. */ |
5348 | attr_new.extra = &extra_new; | |
5349 | bgp_attr_dup (&attr_new, &attr); | |
558d1fec | 5350 | |
6aeb9e78 DS |
5351 | if (red->redist_metric_flag) |
5352 | attr_new.med = red->redist_metric; | |
718e3744 | 5353 | |
6aeb9e78 DS |
5354 | /* Apply route-map. */ |
5355 | if (red->rmap.name) | |
5356 | { | |
5357 | info.peer = bgp->peer_self; | |
5358 | info.attr = &attr_new; | |
718e3744 | 5359 | |
6aeb9e78 | 5360 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE); |
718e3744 | 5361 | |
6aeb9e78 | 5362 | ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info); |
fee0f4c6 | 5363 | |
6aeb9e78 | 5364 | bgp->peer_self->rmap_type = 0; |
fee0f4c6 | 5365 | |
6aeb9e78 DS |
5366 | if (ret == RMAP_DENYMATCH) |
5367 | { | |
5368 | /* Free uninterned attribute. */ | |
5369 | bgp_attr_flush (&attr_new); | |
5370 | ||
5371 | /* Unintern original. */ | |
5372 | aspath_unintern (&attr.aspath); | |
5373 | bgp_attr_extra_free (&attr); | |
5374 | bgp_redistribute_delete (bgp, p, type, instance); | |
5375 | return; | |
5376 | } | |
5377 | } | |
fee0f4c6 | 5378 | |
6aeb9e78 DS |
5379 | bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], |
5380 | afi, SAFI_UNICAST, p, NULL); | |
718e3744 | 5381 | |
6aeb9e78 | 5382 | new_attr = bgp_attr_intern (&attr_new); |
558d1fec | 5383 | |
6aeb9e78 DS |
5384 | for (bi = bn->info; bi; bi = bi->next) |
5385 | if (bi->peer == bgp->peer_self | |
5386 | && bi->sub_type == BGP_ROUTE_REDISTRIBUTE) | |
5387 | break; | |
5388 | ||
5389 | if (bi) | |
5390 | { | |
5391 | /* Ensure the (source route) type is updated. */ | |
5392 | bi->type = type; | |
5393 | if (attrhash_cmp (bi->attr, new_attr) && | |
5394 | !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) | |
5395 | { | |
5396 | bgp_attr_unintern (&new_attr); | |
5397 | aspath_unintern (&attr.aspath); | |
5398 | bgp_attr_extra_free (&attr); | |
5399 | bgp_unlock_node (bn); | |
5400 | return; | |
5401 | } | |
5402 | else | |
5403 | { | |
5404 | /* The attribute is changed. */ | |
5405 | bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED); | |
718e3744 | 5406 | |
6aeb9e78 DS |
5407 | /* Rewrite BGP route information. */ |
5408 | if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) | |
5409 | bgp_info_restore(bn, bi); | |
5410 | else | |
5411 | bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST); | |
5412 | bgp_attr_unintern (&bi->attr); | |
5413 | bi->attr = new_attr; | |
5414 | bi->uptime = bgp_clock (); | |
5415 | ||
5416 | /* Process change. */ | |
5417 | bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST); | |
5418 | bgp_process (bgp, bn, afi, SAFI_UNICAST); | |
5419 | bgp_unlock_node (bn); | |
5420 | aspath_unintern (&attr.aspath); | |
5421 | bgp_attr_extra_free (&attr); | |
5422 | return; | |
5423 | } | |
5424 | } | |
718e3744 | 5425 | |
6aeb9e78 DS |
5426 | new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self, |
5427 | new_attr, bn); | |
5428 | SET_FLAG (new->flags, BGP_INFO_VALID); | |
5429 | ||
5430 | bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST); | |
5431 | bgp_info_add (bn, new); | |
5432 | bgp_unlock_node (bn); | |
5433 | bgp_process (bgp, bn, afi, SAFI_UNICAST); | |
718e3744 | 5434 | } |
5435 | ||
5436 | /* Unintern original. */ | |
f6f434b2 | 5437 | aspath_unintern (&attr.aspath); |
fb982c25 | 5438 | bgp_attr_extra_free (&attr); |
718e3744 | 5439 | } |
5440 | ||
5441 | void | |
6aeb9e78 | 5442 | bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance) |
718e3744 | 5443 | { |
718e3744 | 5444 | afi_t afi; |
5445 | struct bgp_node *rn; | |
5446 | struct bgp_info *ri; | |
7c8ff89e | 5447 | struct bgp_redist *red; |
718e3744 | 5448 | |
6aeb9e78 | 5449 | afi = family2afi (p->family); |
718e3744 | 5450 | |
6aeb9e78 DS |
5451 | red = bgp_redist_lookup(bgp, afi, type, instance); |
5452 | if (red) | |
5453 | { | |
5454 | rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL); | |
718e3744 | 5455 | |
6aeb9e78 DS |
5456 | for (ri = rn->info; ri; ri = ri->next) |
5457 | if (ri->peer == bgp->peer_self | |
5458 | && ri->type == type) | |
5459 | break; | |
718e3744 | 5460 | |
6aeb9e78 DS |
5461 | if (ri) |
5462 | { | |
5463 | bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST); | |
5464 | bgp_info_delete (rn, ri); | |
5465 | bgp_process (bgp, rn, afi, SAFI_UNICAST); | |
5466 | } | |
5467 | bgp_unlock_node (rn); | |
718e3744 | 5468 | } |
5469 | } | |
5470 | ||
5471 | /* Withdraw specified route type's route. */ | |
5472 | void | |
7c8ff89e | 5473 | bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type, u_short instance) |
718e3744 | 5474 | { |
5475 | struct bgp_node *rn; | |
5476 | struct bgp_info *ri; | |
5477 | struct bgp_table *table; | |
5478 | ||
5479 | table = bgp->rib[afi][SAFI_UNICAST]; | |
5480 | ||
5481 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
5482 | { | |
5483 | for (ri = rn->info; ri; ri = ri->next) | |
5484 | if (ri->peer == bgp->peer_self | |
7c8ff89e DS |
5485 | && ri->type == type |
5486 | && ri->instance == instance) | |
718e3744 | 5487 | break; |
5488 | ||
5489 | if (ri) | |
5490 | { | |
5491 | bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST); | |
718e3744 | 5492 | bgp_info_delete (rn, ri); |
1a392d46 | 5493 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
718e3744 | 5494 | } |
5495 | } | |
5496 | } | |
6b0655a2 | 5497 | |
718e3744 | 5498 | /* Static function to display route. */ |
94f2b392 | 5499 | static void |
718e3744 | 5500 | route_vty_out_route (struct prefix *p, struct vty *vty) |
5501 | { | |
5502 | int len; | |
5503 | u_int32_t destination; | |
5504 | char buf[BUFSIZ]; | |
5505 | ||
5506 | if (p->family == AF_INET) | |
5507 | { | |
5508 | len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ)); | |
5509 | destination = ntohl (p->u.prefix4.s_addr); | |
5510 | ||
5511 | if ((IN_CLASSC (destination) && p->prefixlen == 24) | |
856ca177 MS |
5512 | || (IN_CLASSB (destination) && p->prefixlen == 16) |
5513 | || (IN_CLASSA (destination) && p->prefixlen == 8) | |
5514 | || p->u.prefix4.s_addr == 0) | |
5515 | { | |
5516 | /* When mask is natural, mask is not displayed. */ | |
5517 | } | |
718e3744 | 5518 | else |
856ca177 | 5519 | len += vty_out (vty, "/%d", p->prefixlen); |
718e3744 | 5520 | } |
5521 | else | |
5522 | len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), | |
5523 | p->prefixlen); | |
5524 | ||
5525 | len = 17 - len; | |
5526 | if (len < 1) | |
5527 | vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " "); | |
5528 | else | |
5529 | vty_out (vty, "%*s", len, " "); | |
5530 | } | |
5531 | ||
718e3744 | 5532 | enum bgp_display_type |
5533 | { | |
5534 | normal_list, | |
5535 | }; | |
5536 | ||
b40d939b | 5537 | /* Print the short form route status for a bgp_info */ |
5538 | static void | |
b05a1c8b DS |
5539 | route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo, |
5540 | json_object *json_path) | |
718e3744 | 5541 | { |
b05a1c8b DS |
5542 | if (json_path) |
5543 | { | |
b05a1c8b DS |
5544 | |
5545 | /* Route status display. */ | |
5546 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) | |
f1aa5d8a | 5547 | json_object_boolean_true_add(json_path, "removed"); |
b05a1c8b DS |
5548 | |
5549 | if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) | |
f1aa5d8a | 5550 | json_object_boolean_true_add(json_path, "stale"); |
b05a1c8b DS |
5551 | |
5552 | if (binfo->extra && binfo->extra->suppress) | |
f1aa5d8a | 5553 | json_object_boolean_true_add(json_path, "suppressed"); |
b05a1c8b DS |
5554 | |
5555 | if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) && | |
5556 | ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
f1aa5d8a | 5557 | json_object_boolean_true_add(json_path, "valid"); |
b05a1c8b DS |
5558 | |
5559 | /* Selected */ | |
5560 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
f1aa5d8a | 5561 | json_object_boolean_true_add(json_path, "history"); |
b05a1c8b DS |
5562 | |
5563 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) | |
f1aa5d8a | 5564 | json_object_boolean_true_add(json_path, "damped"); |
b05a1c8b DS |
5565 | |
5566 | if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) | |
f1aa5d8a | 5567 | json_object_boolean_true_add(json_path, "bestpath"); |
b05a1c8b DS |
5568 | |
5569 | if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH)) | |
f1aa5d8a | 5570 | json_object_boolean_true_add(json_path, "multipath"); |
b05a1c8b DS |
5571 | |
5572 | /* Internal route. */ | |
5573 | if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as)) | |
62d6dca0 | 5574 | json_object_string_add(json_path, "pathFrom", "internal"); |
b05a1c8b | 5575 | else |
62d6dca0 | 5576 | json_object_string_add(json_path, "pathFrom", "external"); |
b05a1c8b DS |
5577 | |
5578 | return; | |
5579 | } | |
5580 | ||
b40d939b | 5581 | /* Route status display. */ |
5582 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) | |
5583 | vty_out (vty, "R"); | |
5584 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) | |
93406d87 | 5585 | vty_out (vty, "S"); |
fb982c25 | 5586 | else if (binfo->extra && binfo->extra->suppress) |
718e3744 | 5587 | vty_out (vty, "s"); |
31eba040 DS |
5588 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) && |
5589 | ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
718e3744 | 5590 | vty_out (vty, "*"); |
5591 | else | |
5592 | vty_out (vty, " "); | |
5593 | ||
5594 | /* Selected */ | |
5595 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
5596 | vty_out (vty, "h"); | |
5597 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) | |
5598 | vty_out (vty, "d"); | |
5599 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) | |
5600 | vty_out (vty, ">"); | |
b366b518 BB |
5601 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH)) |
5602 | vty_out (vty, "="); | |
718e3744 | 5603 | else |
5604 | vty_out (vty, " "); | |
5605 | ||
5606 | /* Internal route. */ | |
b05a1c8b DS |
5607 | if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as)) |
5608 | vty_out (vty, "i"); | |
5609 | else | |
5610 | vty_out (vty, " "); | |
b40d939b | 5611 | } |
5612 | ||
5613 | /* called from terminal list command */ | |
5614 | void | |
5615 | route_vty_out (struct vty *vty, struct prefix *p, | |
b05a1c8b DS |
5616 | struct bgp_info *binfo, int display, safi_t safi, |
5617 | json_object *json_paths) | |
b40d939b | 5618 | { |
5619 | struct attr *attr; | |
f1aa5d8a DS |
5620 | json_object *json_path = NULL; |
5621 | json_object *json_nexthops = NULL; | |
5622 | json_object *json_nexthop_global = NULL; | |
5623 | json_object *json_nexthop_ll = NULL; | |
47fc97cc | 5624 | |
b05a1c8b DS |
5625 | if (json_paths) |
5626 | json_path = json_object_new_object(); | |
b05a1c8b DS |
5627 | |
5628 | /* short status lead text */ | |
5629 | route_vty_short_status_out (vty, binfo, json_path); | |
718e3744 | 5630 | |
b05a1c8b DS |
5631 | if (!json_paths) |
5632 | { | |
5633 | /* print prefix and mask */ | |
5634 | if (! display) | |
5635 | route_vty_out_route (p, vty); | |
5636 | else | |
5637 | vty_out (vty, "%*s", 17, " "); | |
5638 | } | |
47fc97cc | 5639 | |
718e3744 | 5640 | /* Print attribute */ |
5641 | attr = binfo->attr; | |
5642 | if (attr) | |
5643 | { | |
b05a1c8b DS |
5644 | |
5645 | /* IPv4 Next Hop */ | |
8a92a8a0 DS |
5646 | if (p->family == AF_INET |
5647 | && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
718e3744 | 5648 | { |
b05a1c8b DS |
5649 | if (json_paths) |
5650 | { | |
f1aa5d8a DS |
5651 | json_nexthop_global = json_object_new_object(); |
5652 | ||
b05a1c8b | 5653 | if (safi == SAFI_MPLS_VPN) |
f1aa5d8a | 5654 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in)); |
b05a1c8b | 5655 | else |
f1aa5d8a DS |
5656 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop)); |
5657 | ||
5658 | json_object_string_add(json_nexthop_global, "afi", "ipv4"); | |
5659 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
b05a1c8b DS |
5660 | } |
5661 | else | |
5662 | { | |
5663 | if (safi == SAFI_MPLS_VPN) | |
5664 | vty_out (vty, "%-16s", | |
5665 | inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
5666 | else | |
5667 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
5668 | } | |
718e3744 | 5669 | } |
b05a1c8b DS |
5670 | |
5671 | #ifdef HAVE_IPV6 | |
5672 | /* IPv6 Next Hop */ | |
8a92a8a0 | 5673 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) |
718e3744 | 5674 | { |
5675 | int len; | |
5676 | char buf[BUFSIZ]; | |
5677 | ||
b05a1c8b DS |
5678 | if (json_paths) |
5679 | { | |
f1aa5d8a DS |
5680 | json_nexthop_global = json_object_new_object(); |
5681 | json_object_string_add(json_nexthop_global, "ip", | |
5682 | inet_ntop (AF_INET6, | |
5683 | &attr->extra->mp_nexthop_global, | |
5684 | buf, BUFSIZ)); | |
5685 | json_object_string_add(json_nexthop_global, "afi", "ipv6"); | |
5686 | json_object_string_add(json_nexthop_global, "scope", "global"); | |
5687 | ||
5688 | /* We display both LL & GL if both have been received */ | |
5689 | if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if)) | |
5690 | { | |
5691 | json_nexthop_ll = json_object_new_object(); | |
5692 | json_object_string_add(json_nexthop_ll, "ip", | |
5693 | inet_ntop (AF_INET6, | |
5694 | &attr->extra->mp_nexthop_local, | |
5695 | buf, BUFSIZ)); | |
5696 | json_object_string_add(json_nexthop_ll, "afi", "ipv6"); | |
5697 | json_object_string_add(json_nexthop_ll, "scope", "link-local"); | |
5698 | ||
5699 | if (IPV6_ADDR_CMP (&attr->extra->mp_nexthop_global, | |
5700 | &attr->extra->mp_nexthop_local) != 0) | |
5701 | json_object_boolean_true_add(json_nexthop_ll, "used"); | |
5702 | else | |
5703 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
5704 | } | |
5705 | else | |
5706 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
b05a1c8b DS |
5707 | } |
5708 | else | |
5709 | { | |
433e8b67 DS |
5710 | if ((attr->extra->mp_nexthop_len == 32) || (binfo->peer->conf_if)) |
5711 | { | |
5712 | if (binfo->peer->conf_if) | |
5713 | { | |
5714 | len = vty_out (vty, "%s", | |
5715 | binfo->peer->conf_if); | |
5716 | len = 7 - len; /* len of IPv6 addr + max len of def ifname */ | |
5717 | ||
5718 | if (len < 1) | |
5719 | vty_out (vty, "%s%*s", VTY_NEWLINE, 45, " "); | |
5720 | else | |
5721 | vty_out (vty, "%*s", len, " "); | |
5722 | } | |
5723 | else | |
5724 | { | |
5725 | len = vty_out (vty, "%s", | |
5726 | inet_ntop (AF_INET6, | |
5727 | &attr->extra->mp_nexthop_local, | |
5728 | buf, BUFSIZ)); | |
5729 | len = 16 - len; | |
5730 | ||
5731 | if (len < 1) | |
5732 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
5733 | else | |
5734 | vty_out (vty, "%*s", len, " "); | |
5735 | } | |
5736 | } | |
5737 | else | |
5738 | { | |
5739 | len = vty_out (vty, "%s", | |
5740 | inet_ntop (AF_INET6, | |
5741 | &attr->extra->mp_nexthop_global, | |
5742 | buf, BUFSIZ)); | |
5743 | len = 16 - len; | |
5744 | ||
5745 | if (len < 1) | |
5746 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
5747 | else | |
5748 | vty_out (vty, "%*s", len, " "); | |
5749 | } | |
b05a1c8b | 5750 | } |
718e3744 | 5751 | } |
5752 | #endif /* HAVE_IPV6 */ | |
5753 | ||
b05a1c8b | 5754 | /* MED/Metric */ |
718e3744 | 5755 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
b05a1c8b | 5756 | if (json_paths) |
f1aa5d8a | 5757 | json_object_int_add(json_path, "med", attr->med); |
b05a1c8b DS |
5758 | else |
5759 | vty_out (vty, "%10u", attr->med); | |
718e3744 | 5760 | else |
b05a1c8b DS |
5761 | if (!json_paths) |
5762 | vty_out (vty, " "); | |
47fc97cc | 5763 | |
b05a1c8b | 5764 | /* Local Pref */ |
718e3744 | 5765 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
b05a1c8b | 5766 | if (json_paths) |
f1aa5d8a | 5767 | json_object_int_add(json_path, "localpref", attr->local_pref); |
b05a1c8b DS |
5768 | else |
5769 | vty_out (vty, "%7u", attr->local_pref); | |
718e3744 | 5770 | else |
b05a1c8b DS |
5771 | if (!json_paths) |
5772 | vty_out (vty, " "); | |
718e3744 | 5773 | |
b05a1c8b DS |
5774 | if (json_paths) |
5775 | { | |
5776 | if (attr->extra) | |
f1aa5d8a | 5777 | json_object_int_add(json_path, "weight", attr->extra->weight); |
b05a1c8b | 5778 | else |
f1aa5d8a | 5779 | json_object_int_add(json_path, "weight", 0); |
b05a1c8b DS |
5780 | } |
5781 | else | |
5782 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); | |
47fc97cc | 5783 | |
b2518c1e PJ |
5784 | /* Print aspath */ |
5785 | if (attr->aspath) | |
b05a1c8b DS |
5786 | { |
5787 | if (json_paths) | |
f1aa5d8a | 5788 | json_object_string_add(json_path, "aspath", attr->aspath->str); |
b05a1c8b | 5789 | else |
f1aa5d8a | 5790 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
b05a1c8b | 5791 | } |
47fc97cc | 5792 | |
b2518c1e | 5793 | /* Print origin */ |
b05a1c8b | 5794 | if (json_paths) |
f1aa5d8a | 5795 | json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]); |
b05a1c8b DS |
5796 | else |
5797 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
b2518c1e | 5798 | } |
856ca177 MS |
5799 | else |
5800 | { | |
5801 | if (json_paths) | |
5802 | json_object_string_add(json_path, "alert", "No attributes"); | |
5803 | else | |
5804 | vty_out (vty, "No attributes to print%s", VTY_NEWLINE); | |
5805 | } | |
b05a1c8b DS |
5806 | |
5807 | if (json_paths) | |
f1aa5d8a DS |
5808 | { |
5809 | if (json_nexthop_global || json_nexthop_ll) | |
5810 | { | |
5811 | json_nexthops = json_object_new_array(); | |
5812 | ||
5813 | if (json_nexthop_global) | |
5814 | json_object_array_add(json_nexthops, json_nexthop_global); | |
5815 | ||
5816 | if (json_nexthop_ll) | |
5817 | json_object_array_add(json_nexthops, json_nexthop_ll); | |
5818 | ||
5819 | json_object_object_add(json_path, "nexthops", json_nexthops); | |
5820 | } | |
5821 | ||
5822 | json_object_array_add(json_paths, json_path); | |
5823 | } | |
b05a1c8b DS |
5824 | else |
5825 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 5826 | } |
5827 | ||
5828 | /* called from terminal list command */ | |
5829 | void | |
856ca177 MS |
5830 | route_vty_out_tmp (struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi, |
5831 | u_char use_json, json_object *json_ar) | |
718e3744 | 5832 | { |
856ca177 MS |
5833 | json_object *json_status = NULL; |
5834 | json_object *json_net = NULL; | |
5835 | char buff[BUFSIZ]; | |
718e3744 | 5836 | /* Route status display. */ |
856ca177 MS |
5837 | if (use_json) |
5838 | { | |
5839 | json_status = json_object_new_object(); | |
5840 | json_net = json_object_new_object(); | |
5841 | } | |
5842 | else | |
5843 | { | |
5844 | vty_out (vty, "*"); | |
5845 | vty_out (vty, ">"); | |
5846 | vty_out (vty, " "); | |
5847 | } | |
718e3744 | 5848 | |
5849 | /* print prefix and mask */ | |
856ca177 MS |
5850 | if (use_json) |
5851 | json_object_string_add(json_net, "addrPrefix", inet_ntop (p->family, &p->u.prefix, buff, BUFSIZ)); | |
5852 | else | |
5853 | route_vty_out_route (p, vty); | |
718e3744 | 5854 | |
5855 | /* Print attribute */ | |
5856 | if (attr) | |
5857 | { | |
856ca177 | 5858 | if (use_json) |
718e3744 | 5859 | { |
856ca177 MS |
5860 | if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) |
5861 | { | |
5862 | if (safi == SAFI_MPLS_VPN) | |
5863 | json_object_string_add(json_net, "nextHop", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
5864 | else | |
5865 | json_object_string_add(json_net, "nextHop", inet_ntoa (attr->nexthop)); | |
5866 | } | |
5867 | #ifdef HAVE_IPV6 | |
5868 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
5869 | { | |
5870 | char buf[BUFSIZ]; | |
718e3744 | 5871 | |
856ca177 MS |
5872 | json_object_string_add(json_net, "netHopGloabal", inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
5873 | buf, BUFSIZ)); | |
5874 | } | |
5875 | #endif /* HAVE_IPV6 */ | |
5876 | ||
5877 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) | |
5878 | json_object_int_add(json_net, "metric", attr->med); | |
5879 | ||
5880 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) | |
5881 | json_object_int_add(json_net, "localPref", attr->local_pref); | |
5882 | ||
5883 | if (attr->extra) | |
5884 | json_object_int_add(json_net, "weight", attr->extra->weight); | |
718e3744 | 5885 | else |
856ca177 MS |
5886 | json_object_int_add(json_net, "weight", 0); |
5887 | ||
5888 | /* Print aspath */ | |
5889 | if (attr->aspath) | |
5890 | json_object_string_add(json_net, "asPath", attr->aspath->str); | |
5891 | ||
5892 | /* Print origin */ | |
5893 | json_object_string_add(json_net, "bgpOriginCode", bgp_origin_str[attr->origin]); | |
718e3744 | 5894 | } |
856ca177 MS |
5895 | else |
5896 | { | |
5897 | if (p->family == AF_INET && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
5898 | { | |
5899 | if (safi == SAFI_MPLS_VPN) | |
5900 | vty_out (vty, "%-16s", | |
5901 | inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
5902 | else | |
5903 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
5904 | } | |
5905 | #ifdef HAVE_IPV6 | |
5906 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
5907 | { | |
5908 | int len; | |
5909 | char buf[BUFSIZ]; | |
5910 | ||
5911 | assert (attr->extra); | |
5912 | ||
5913 | len = vty_out (vty, "%s", | |
5914 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
5915 | buf, BUFSIZ)); | |
5916 | len = 16 - len; | |
5917 | if (len < 1) | |
5918 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); | |
5919 | else | |
5920 | vty_out (vty, "%*s", len, " "); | |
5921 | } | |
718e3744 | 5922 | #endif /* HAVE_IPV6 */ |
856ca177 MS |
5923 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
5924 | vty_out (vty, "%10u", attr->med); | |
5925 | else | |
5926 | vty_out (vty, " "); | |
718e3744 | 5927 | |
856ca177 MS |
5928 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
5929 | vty_out (vty, "%7u", attr->local_pref); | |
5930 | else | |
5931 | vty_out (vty, " "); | |
718e3744 | 5932 | |
856ca177 | 5933 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); |
718e3744 | 5934 | |
856ca177 MS |
5935 | /* Print aspath */ |
5936 | if (attr->aspath) | |
5937 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
718e3744 | 5938 | |
856ca177 MS |
5939 | /* Print origin */ |
5940 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
5941 | } | |
5942 | } | |
5943 | if (use_json) | |
5944 | { | |
5945 | json_object_boolean_true_add(json_status, "*"); | |
5946 | json_object_boolean_true_add(json_status, ">"); | |
5947 | json_object_object_add(json_net, "appliedStatusSymbols", json_status); | |
5948 | char buf_cut[BUFSIZ]; | |
5949 | json_object_object_add(json_ar, inet_ntop (p->family, &p->u.prefix, buf_cut, BUFSIZ), json_net); | |
5950 | } | |
5951 | else | |
5952 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 5953 | } |
5954 | ||
5a646650 | 5955 | void |
718e3744 | 5956 | route_vty_out_tag (struct vty *vty, struct prefix *p, |
856ca177 | 5957 | struct bgp_info *binfo, int display, safi_t safi, json_object *json) |
718e3744 | 5958 | { |
856ca177 | 5959 | json_object *json_out = NULL; |
718e3744 | 5960 | struct attr *attr; |
718e3744 | 5961 | u_int32_t label = 0; |
fb982c25 PJ |
5962 | |
5963 | if (!binfo->extra) | |
5964 | return; | |
856ca177 MS |
5965 | |
5966 | if (json) | |
5967 | json_out = json_object_new_object(); | |
fb982c25 | 5968 | |
b40d939b | 5969 | /* short status lead text */ |
856ca177 | 5970 | route_vty_short_status_out (vty, binfo, json_out); |
b40d939b | 5971 | |
718e3744 | 5972 | /* print prefix and mask */ |
856ca177 MS |
5973 | if (json == NULL) |
5974 | { | |
5975 | if (! display) | |
5976 | route_vty_out_route (p, vty); | |
5977 | else | |
5978 | vty_out (vty, "%*s", 17, " "); | |
5979 | } | |
718e3744 | 5980 | |
5981 | /* Print attribute */ | |
5982 | attr = binfo->attr; | |
5983 | if (attr) | |
5984 | { | |
8a92a8a0 DS |
5985 | if (p->family == AF_INET |
5986 | && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
718e3744 | 5987 | { |
5988 | if (safi == SAFI_MPLS_VPN) | |
856ca177 MS |
5989 | { |
5990 | if (json) | |
5991 | json_object_string_add(json_out, "mpNexthopGlobalIn", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
5992 | else | |
5993 | vty_out (vty, "%-16s", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
5994 | } | |
718e3744 | 5995 | else |
856ca177 MS |
5996 | { |
5997 | if (json) | |
5998 | json_object_string_add(json_out, "nexthop", inet_ntoa (attr->nexthop)); | |
5999 | else | |
6000 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); | |
6001 | } | |
718e3744 | 6002 | } |
6003 | #ifdef HAVE_IPV6 | |
8a92a8a0 | 6004 | else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) |
718e3744 | 6005 | { |
fb982c25 | 6006 | assert (attr->extra); |
856ca177 MS |
6007 | char buf_a[BUFSIZ]; |
6008 | char buf_b[BUFSIZ]; | |
6009 | char buf_c[BUFSIZ]; | |
801a9bcc | 6010 | if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) |
856ca177 MS |
6011 | { |
6012 | if (json) | |
6013 | json_object_string_add(json_out, "mpNexthopGlobalIn", | |
6014 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, buf_a, BUFSIZ)); | |
6015 | else | |
6016 | vty_out (vty, "%s", | |
6017 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6018 | buf_a, BUFSIZ)); | |
6019 | } | |
801a9bcc | 6020 | else if (attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
856ca177 MS |
6021 | { |
6022 | if (json) | |
6023 | { | |
6024 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6025 | buf_a, BUFSIZ); | |
6026 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
6027 | buf_b, BUFSIZ); | |
6028 | sprintf(buf_c, "%s(%s)", buf_a, buf_b); | |
6029 | json_object_string_add(json_out, "mpNexthopGlobalLocal", buf_c); | |
6030 | } | |
6031 | else | |
6032 | vty_out (vty, "%s(%s)", | |
6033 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6034 | buf_a, BUFSIZ), | |
6035 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
6036 | buf_b, BUFSIZ)); | |
6037 | } | |
6038 | ||
718e3744 | 6039 | } |
6040 | #endif /* HAVE_IPV6 */ | |
6041 | } | |
6042 | ||
fb982c25 | 6043 | label = decode_label (binfo->extra->tag); |
718e3744 | 6044 | |
856ca177 MS |
6045 | if (json) |
6046 | { | |
6047 | if (label) | |
6048 | json_object_int_add(json_out, "notag", label); | |
6049 | json_object_array_add(json, json_out); | |
6050 | } | |
6051 | else | |
6052 | { | |
6053 | vty_out (vty, "notag/%d", label); | |
6054 | vty_out (vty, "%s", VTY_NEWLINE); | |
6055 | } | |
718e3744 | 6056 | } |
6057 | ||
6058 | /* dampening route */ | |
5a646650 | 6059 | static void |
856ca177 MS |
6060 | damp_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo, |
6061 | int display, safi_t safi, u_char use_json, json_object *json) | |
718e3744 | 6062 | { |
6063 | struct attr *attr; | |
718e3744 | 6064 | int len; |
50aef6f3 | 6065 | char timebuf[BGP_UPTIME_LEN]; |
718e3744 | 6066 | |
b40d939b | 6067 | /* short status lead text */ |
856ca177 | 6068 | route_vty_short_status_out (vty, binfo, json); |
b40d939b | 6069 | |
718e3744 | 6070 | /* print prefix and mask */ |
856ca177 MS |
6071 | if (!use_json) |
6072 | { | |
6073 | if (! display) | |
6074 | route_vty_out_route (p, vty); | |
6075 | else | |
6076 | vty_out (vty, "%*s", 17, " "); | |
6077 | } | |
718e3744 | 6078 | |
6079 | len = vty_out (vty, "%s", binfo->peer->host); | |
6080 | len = 17 - len; | |
6081 | if (len < 1) | |
856ca177 MS |
6082 | { |
6083 | if (!use_json) | |
6084 | vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " "); | |
6085 | } | |
718e3744 | 6086 | else |
856ca177 MS |
6087 | { |
6088 | if (use_json) | |
6089 | json_object_int_add(json, "peerHost", len); | |
6090 | else | |
6091 | vty_out (vty, "%*s", len, " "); | |
6092 | } | |
718e3744 | 6093 | |
856ca177 MS |
6094 | if (use_json) |
6095 | bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6096 | else | |
6097 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json)); | |
718e3744 | 6098 | |
6099 | /* Print attribute */ | |
6100 | attr = binfo->attr; | |
6101 | if (attr) | |
6102 | { | |
6103 | /* Print aspath */ | |
6104 | if (attr->aspath) | |
856ca177 MS |
6105 | { |
6106 | if (use_json) | |
6107 | json_object_string_add(json, "asPath", attr->aspath->str); | |
6108 | else | |
6109 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
6110 | } | |
718e3744 | 6111 | |
6112 | /* Print origin */ | |
856ca177 MS |
6113 | if (use_json) |
6114 | json_object_string_add(json, "origin", bgp_origin_str[attr->origin]); | |
6115 | else | |
6116 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
718e3744 | 6117 | } |
856ca177 MS |
6118 | if (!use_json) |
6119 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6120 | } |
6121 | ||
718e3744 | 6122 | /* flap route */ |
5a646650 | 6123 | static void |
856ca177 MS |
6124 | flap_route_vty_out (struct vty *vty, struct prefix *p, struct bgp_info *binfo, |
6125 | int display, safi_t safi, u_char use_json, json_object *json) | |
718e3744 | 6126 | { |
6127 | struct attr *attr; | |
6128 | struct bgp_damp_info *bdi; | |
718e3744 | 6129 | char timebuf[BGP_UPTIME_LEN]; |
6130 | int len; | |
fb982c25 PJ |
6131 | |
6132 | if (!binfo->extra) | |
6133 | return; | |
6134 | ||
6135 | bdi = binfo->extra->damp_info; | |
718e3744 | 6136 | |
b40d939b | 6137 | /* short status lead text */ |
856ca177 | 6138 | route_vty_short_status_out (vty, binfo, json); |
b40d939b | 6139 | |
718e3744 | 6140 | /* print prefix and mask */ |
856ca177 MS |
6141 | if (!use_json) |
6142 | { | |
6143 | if (! display) | |
6144 | route_vty_out_route (p, vty); | |
6145 | else | |
6146 | vty_out (vty, "%*s", 17, " "); | |
6147 | } | |
718e3744 | 6148 | |
6149 | len = vty_out (vty, "%s", binfo->peer->host); | |
6150 | len = 16 - len; | |
6151 | if (len < 1) | |
856ca177 MS |
6152 | { |
6153 | if (!use_json) | |
6154 | vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " "); | |
6155 | } | |
718e3744 | 6156 | else |
856ca177 MS |
6157 | { |
6158 | if (use_json) | |
6159 | json_object_int_add(json, "peerHost", len); | |
6160 | else | |
6161 | vty_out (vty, "%*s", len, " "); | |
6162 | } | |
718e3744 | 6163 | |
6164 | len = vty_out (vty, "%d", bdi->flap); | |
6165 | len = 5 - len; | |
6166 | if (len < 1) | |
856ca177 MS |
6167 | { |
6168 | if (!use_json) | |
6169 | vty_out (vty, " "); | |
6170 | } | |
718e3744 | 6171 | else |
856ca177 MS |
6172 | { |
6173 | if (use_json) | |
6174 | json_object_int_add(json, "bdiFlap", len); | |
6175 | else | |
6176 | vty_out (vty, "%*s", len, " "); | |
6177 | } | |
6178 | ||
6179 | if (use_json) | |
6180 | peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6181 | else | |
6182 | vty_out (vty, "%s ", peer_uptime (bdi->start_time, | |
6183 | timebuf, BGP_UPTIME_LEN, 0, NULL)); | |
718e3744 | 6184 | |
6185 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED) | |
6186 | && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) | |
856ca177 MS |
6187 | { |
6188 | if (use_json) | |
6189 | bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json); | |
6190 | else | |
6191 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN, use_json, json)); | |
6192 | } | |
718e3744 | 6193 | else |
856ca177 MS |
6194 | { |
6195 | if (!use_json) | |
6196 | vty_out (vty, "%*s ", 8, " "); | |
6197 | } | |
718e3744 | 6198 | |
6199 | /* Print attribute */ | |
6200 | attr = binfo->attr; | |
6201 | if (attr) | |
6202 | { | |
6203 | /* Print aspath */ | |
6204 | if (attr->aspath) | |
856ca177 MS |
6205 | { |
6206 | if (use_json) | |
6207 | json_object_string_add(json, "asPath", attr->aspath->str); | |
6208 | else | |
6209 | aspath_print_vty (vty, "%s", attr->aspath, " "); | |
6210 | } | |
718e3744 | 6211 | |
6212 | /* Print origin */ | |
856ca177 MS |
6213 | if (use_json) |
6214 | json_object_string_add(json, "origin", bgp_origin_str[attr->origin]); | |
6215 | else | |
6216 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); | |
718e3744 | 6217 | } |
856ca177 MS |
6218 | if (!use_json) |
6219 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6220 | } |
6221 | ||
adbac85e DW |
6222 | static void |
6223 | route_vty_out_advertised_to (struct vty *vty, struct peer *peer, int *first, | |
6224 | const char *header, json_object *json_adv_to) | |
6225 | { | |
6226 | char buf1[INET6_ADDRSTRLEN]; | |
6227 | json_object *json_peer = NULL; | |
6228 | ||
6229 | if (json_adv_to) | |
6230 | { | |
6231 | /* 'advertised-to' is a dictionary of peers we have advertised this | |
6232 | * prefix too. The key is the peer's IP or swpX, the value is the | |
6233 | * hostname if we know it and "" if not. | |
6234 | */ | |
6235 | json_peer = json_object_new_object(); | |
6236 | ||
6237 | if (peer->hostname) | |
6238 | json_object_string_add(json_peer, "hostname", peer->hostname); | |
6239 | ||
6240 | if (peer->conf_if) | |
6241 | json_object_object_add(json_adv_to, peer->conf_if, json_peer); | |
6242 | else | |
6243 | json_object_object_add(json_adv_to, | |
6244 | sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN), | |
6245 | json_peer); | |
6246 | } | |
6247 | else | |
6248 | { | |
6249 | if (*first) | |
6250 | { | |
6251 | vty_out (vty, "%s", header); | |
6252 | *first = 0; | |
6253 | } | |
6254 | ||
6255 | if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
6256 | { | |
6257 | if (peer->conf_if) | |
6258 | vty_out (vty, " %s(%s)", peer->hostname, peer->conf_if); | |
6259 | else | |
6260 | vty_out (vty, " %s(%s)", peer->hostname, | |
6261 | sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN)); | |
6262 | } | |
6263 | else | |
6264 | { | |
6265 | if (peer->conf_if) | |
6266 | vty_out (vty, " %s", peer->conf_if); | |
6267 | else | |
6268 | vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN)); | |
6269 | } | |
6270 | } | |
6271 | } | |
6272 | ||
94f2b392 | 6273 | static void |
718e3744 | 6274 | route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p, |
b05a1c8b DS |
6275 | struct bgp_info *binfo, afi_t afi, safi_t safi, |
6276 | json_object *json_paths) | |
718e3744 | 6277 | { |
6278 | char buf[INET6_ADDRSTRLEN]; | |
6279 | char buf1[BUFSIZ]; | |
6280 | struct attr *attr; | |
6281 | int sockunion_vty_out (struct vty *, union sockunion *); | |
30b00176 JK |
6282 | #ifdef HAVE_CLOCK_MONOTONIC |
6283 | time_t tbuf; | |
6284 | #endif | |
f1aa5d8a | 6285 | json_object *json_bestpath = NULL; |
ffd0c037 | 6286 | json_object *json_cluster_list = NULL; |
f1aa5d8a DS |
6287 | json_object *json_cluster_list_list = NULL; |
6288 | json_object *json_ext_community = NULL; | |
6289 | json_object *json_last_update = NULL; | |
6290 | json_object *json_nexthop_global = NULL; | |
6291 | json_object *json_nexthop_ll = NULL; | |
6292 | json_object *json_nexthops = NULL; | |
6293 | json_object *json_path = NULL; | |
6294 | json_object *json_peer = NULL; | |
6295 | json_object *json_string = NULL; | |
adbac85e DW |
6296 | json_object *json_adv_to = NULL; |
6297 | int first = 0; | |
6298 | struct listnode *node, *nnode; | |
6299 | struct peer *peer; | |
6300 | int addpath_capable; | |
6301 | int has_adj; | |
06370dac | 6302 | int first_as; |
b05a1c8b DS |
6303 | |
6304 | if (json_paths) | |
6305 | { | |
6306 | json_path = json_object_new_object(); | |
f1aa5d8a DS |
6307 | json_peer = json_object_new_object(); |
6308 | json_nexthop_global = json_object_new_object(); | |
b05a1c8b DS |
6309 | } |
6310 | ||
718e3744 | 6311 | attr = binfo->attr; |
6312 | ||
6313 | if (attr) | |
6314 | { | |
6315 | /* Line1 display AS-path, Aggregator */ | |
6316 | if (attr->aspath) | |
6317 | { | |
f1aa5d8a DS |
6318 | if (json_paths) |
6319 | { | |
6320 | json_object_lock(attr->aspath->json); | |
6321 | json_object_object_add(json_path, "aspath", attr->aspath->json); | |
6322 | } | |
6323 | else | |
b05a1c8b | 6324 | { |
f1aa5d8a DS |
6325 | if (attr->aspath->segments) |
6326 | aspath_print_vty (vty, " %s", attr->aspath, ""); | |
b05a1c8b | 6327 | else |
f1aa5d8a | 6328 | vty_out (vty, " Local"); |
b05a1c8b | 6329 | } |
718e3744 | 6330 | } |
6331 | ||
b40d939b | 6332 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) |
b05a1c8b DS |
6333 | { |
6334 | if (json_paths) | |
f1aa5d8a | 6335 | json_object_boolean_true_add(json_path, "removed"); |
b05a1c8b DS |
6336 | else |
6337 | vty_out (vty, ", (removed)"); | |
6338 | } | |
6339 | ||
93406d87 | 6340 | if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) |
b05a1c8b DS |
6341 | { |
6342 | if (json_paths) | |
f1aa5d8a | 6343 | json_object_boolean_true_add(json_path, "stale"); |
b05a1c8b DS |
6344 | else |
6345 | vty_out (vty, ", (stale)"); | |
6346 | } | |
6347 | ||
93406d87 | 6348 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR))) |
b05a1c8b DS |
6349 | { |
6350 | if (json_paths) | |
6351 | { | |
62d6dca0 DS |
6352 | json_object_int_add(json_path, "aggregatorAs", attr->extra->aggregator_as); |
6353 | json_object_string_add(json_path, "aggregatorId", inet_ntoa (attr->extra->aggregator_addr)); | |
b05a1c8b DS |
6354 | } |
6355 | else | |
6356 | { | |
6357 | vty_out (vty, ", (aggregated by %u %s)", | |
6358 | attr->extra->aggregator_as, | |
6359 | inet_ntoa (attr->extra->aggregator_addr)); | |
6360 | } | |
6361 | } | |
6362 | ||
93406d87 | 6363 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
b05a1c8b DS |
6364 | { |
6365 | if (json_paths) | |
62d6dca0 | 6366 | json_object_boolean_true_add(json_path, "rxedFromRrClient"); |
b05a1c8b DS |
6367 | else |
6368 | vty_out (vty, ", (Received from a RR-client)"); | |
6369 | } | |
6370 | ||
93406d87 | 6371 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
b05a1c8b DS |
6372 | { |
6373 | if (json_paths) | |
62d6dca0 | 6374 | json_object_boolean_true_add(json_path, "rxedFromRsClient"); |
b05a1c8b DS |
6375 | else |
6376 | vty_out (vty, ", (Received from a RS-client)"); | |
6377 | } | |
6378 | ||
93406d87 | 6379 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
b05a1c8b DS |
6380 | { |
6381 | if (json_paths) | |
62d6dca0 | 6382 | json_object_boolean_true_add(json_path, "dampeningHistoryEntry"); |
b05a1c8b DS |
6383 | else |
6384 | vty_out (vty, ", (history entry)"); | |
6385 | } | |
93406d87 | 6386 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) |
b05a1c8b DS |
6387 | { |
6388 | if (json_paths) | |
62d6dca0 | 6389 | json_object_boolean_true_add(json_path, "dampeningSuppressed"); |
b05a1c8b DS |
6390 | else |
6391 | vty_out (vty, ", (suppressed due to dampening)"); | |
6392 | } | |
6393 | ||
6394 | if (!json_paths) | |
6395 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6396 | |
6397 | /* Line2 display Next-hop, Neighbor, Router-id */ | |
f1aa5d8a | 6398 | /* Display the nexthop */ |
8a92a8a0 DS |
6399 | if (p->family == AF_INET |
6400 | && (safi == SAFI_MPLS_VPN || !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) | |
718e3744 | 6401 | { |
b05a1c8b DS |
6402 | if (safi == SAFI_MPLS_VPN) |
6403 | { | |
6404 | if (json_paths) | |
f1aa5d8a | 6405 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in)); |
b05a1c8b DS |
6406 | else |
6407 | vty_out (vty, " %s", inet_ntoa (attr->extra->mp_nexthop_global_in)); | |
6408 | } | |
6409 | else | |
6410 | { | |
6411 | if (json_paths) | |
f1aa5d8a | 6412 | json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop)); |
b05a1c8b DS |
6413 | else |
6414 | vty_out (vty, " %s", inet_ntoa (attr->nexthop)); | |
6415 | } | |
6416 | ||
6417 | if (json_paths) | |
f1aa5d8a | 6418 | json_object_string_add(json_nexthop_global, "afi", "ipv4"); |
718e3744 | 6419 | } |
6420 | #ifdef HAVE_IPV6 | |
6421 | else | |
6422 | { | |
fb982c25 | 6423 | assert (attr->extra); |
b05a1c8b DS |
6424 | if (json_paths) |
6425 | { | |
f1aa5d8a DS |
6426 | json_object_string_add(json_nexthop_global, "ip", |
6427 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6428 | buf, INET6_ADDRSTRLEN)); | |
6429 | json_object_string_add(json_nexthop_global, "afi", "ipv6"); | |
6430 | json_object_string_add(json_nexthop_global, "scope", "global"); | |
b05a1c8b DS |
6431 | } |
6432 | else | |
6433 | { | |
6434 | vty_out (vty, " %s", | |
6435 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, | |
6436 | buf, INET6_ADDRSTRLEN)); | |
6437 | } | |
718e3744 | 6438 | } |
6439 | #endif /* HAVE_IPV6 */ | |
6440 | ||
b05a1c8b | 6441 | |
f1aa5d8a DS |
6442 | /* Display the IGP cost or 'inaccessible' */ |
6443 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID)) | |
6444 | { | |
6445 | if (json_paths) | |
6446 | json_object_boolean_false_add(json_nexthop_global, "accessible"); | |
6447 | else | |
6448 | vty_out (vty, " (inaccessible)"); | |
6449 | } | |
6450 | else | |
6451 | { | |
6452 | if (binfo->extra && binfo->extra->igpmetric) | |
b05a1c8b DS |
6453 | { |
6454 | if (json_paths) | |
f1aa5d8a | 6455 | json_object_int_add(json_nexthop_global, "metric", binfo->extra->igpmetric); |
b05a1c8b | 6456 | else |
f1aa5d8a | 6457 | vty_out (vty, " (metric %u)", binfo->extra->igpmetric); |
b05a1c8b | 6458 | } |
f1aa5d8a DS |
6459 | |
6460 | /* IGP cost is 0, display this only for json */ | |
b05a1c8b DS |
6461 | else |
6462 | { | |
6463 | if (json_paths) | |
f1aa5d8a | 6464 | json_object_int_add(json_nexthop_global, "metric", 0); |
b05a1c8b DS |
6465 | } |
6466 | ||
6467 | if (json_paths) | |
f1aa5d8a DS |
6468 | json_object_boolean_true_add(json_nexthop_global, "accessible"); |
6469 | } | |
6470 | ||
6471 | /* Display peer "from" output */ | |
6472 | /* This path was originated locally */ | |
6473 | if (binfo->peer == bgp->peer_self) | |
718e3744 | 6474 | { |
f1aa5d8a DS |
6475 | |
6476 | if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) | |
b05a1c8b DS |
6477 | { |
6478 | if (json_paths) | |
62d6dca0 | 6479 | json_object_string_add(json_peer, "peerId", "0.0.0.0"); |
b05a1c8b | 6480 | else |
f1aa5d8a | 6481 | vty_out (vty, " from 0.0.0.0 "); |
b05a1c8b | 6482 | } |
f1aa5d8a | 6483 | else |
b05a1c8b DS |
6484 | { |
6485 | if (json_paths) | |
62d6dca0 | 6486 | json_object_string_add(json_peer, "peerId", "::"); |
b05a1c8b | 6487 | else |
f1aa5d8a | 6488 | vty_out (vty, " from :: "); |
b05a1c8b DS |
6489 | } |
6490 | ||
f1aa5d8a | 6491 | if (json_paths) |
62d6dca0 | 6492 | json_object_string_add(json_peer, "routerId", inet_ntoa(bgp->router_id)); |
b05a1c8b | 6493 | else |
f1aa5d8a DS |
6494 | vty_out (vty, "(%s)", inet_ntoa(bgp->router_id)); |
6495 | } | |
6496 | ||
6497 | /* We RXed this path from one of our peers */ | |
6498 | else | |
6499 | { | |
b05a1c8b DS |
6500 | |
6501 | if (json_paths) | |
6502 | { | |
62d6dca0 DS |
6503 | json_object_string_add(json_peer, "peerId", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); |
6504 | json_object_string_add(json_peer, "routerId", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ)); | |
f1aa5d8a | 6505 | |
04b6bdc0 DW |
6506 | if (binfo->peer->hostname) |
6507 | json_object_string_add(json_peer, "hostname", binfo->peer->hostname); | |
6508 | ||
6509 | if (binfo->peer->domainname) | |
6510 | json_object_string_add(json_peer, "domainname", binfo->peer->domainname); | |
6511 | ||
036a4e7d | 6512 | if (binfo->peer->conf_if) |
f1aa5d8a | 6513 | json_object_string_add(json_peer, "interface", binfo->peer->conf_if); |
b05a1c8b DS |
6514 | } |
6515 | else | |
6516 | { | |
036a4e7d | 6517 | if (binfo->peer->conf_if) |
04b6bdc0 DW |
6518 | { |
6519 | if (binfo->peer->hostname && | |
6520 | bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
6521 | vty_out (vty, " from %s(%s)", binfo->peer->hostname, | |
6522 | binfo->peer->conf_if); | |
6523 | else | |
6524 | vty_out (vty, " from %s", binfo->peer->conf_if); | |
6525 | } | |
036a4e7d | 6526 | else |
04b6bdc0 DW |
6527 | { |
6528 | if (binfo->peer->hostname && | |
6529 | bgp_flag_check(binfo->peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
6530 | vty_out (vty, " from %s(%s)", binfo->peer->hostname, | |
6531 | binfo->peer->host); | |
6532 | else | |
6533 | vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); | |
6534 | } | |
b05a1c8b | 6535 | |
f1aa5d8a DS |
6536 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
6537 | vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id)); | |
6538 | else | |
6539 | vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ)); | |
b05a1c8b | 6540 | } |
718e3744 | 6541 | } |
b05a1c8b DS |
6542 | |
6543 | if (!json_paths) | |
6544 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6545 | |
6546 | #ifdef HAVE_IPV6 | |
f1aa5d8a | 6547 | /* display the link-local nexthop */ |
801a9bcc | 6548 | if (attr->extra && attr->extra->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
718e3744 | 6549 | { |
b05a1c8b DS |
6550 | if (json_paths) |
6551 | { | |
f1aa5d8a DS |
6552 | json_nexthop_ll = json_object_new_object(); |
6553 | json_object_string_add(json_nexthop_ll, "ip", | |
6554 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, | |
6555 | buf, INET6_ADDRSTRLEN)); | |
6556 | json_object_string_add(json_nexthop_ll, "afi", "ipv6"); | |
6557 | json_object_string_add(json_nexthop_ll, "scope", "link-local"); | |
6558 | ||
6559 | json_object_boolean_true_add(json_nexthop_ll, "accessible"); | |
6560 | json_object_boolean_true_add(json_nexthop_ll, "used"); | |
b05a1c8b DS |
6561 | } |
6562 | else | |
6563 | { | |
356b3294 | 6564 | vty_out (vty, " (%s) (used)%s", |
b05a1c8b DS |
6565 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, |
6566 | buf, INET6_ADDRSTRLEN), | |
6567 | VTY_NEWLINE); | |
6568 | } | |
718e3744 | 6569 | } |
f1aa5d8a DS |
6570 | /* If we do not have a link-local nexthop then we must flag the global as "used" */ |
6571 | else | |
6572 | { | |
6573 | if (json_paths) | |
6574 | json_object_boolean_true_add(json_nexthop_global, "used"); | |
6575 | } | |
718e3744 | 6576 | #endif /* HAVE_IPV6 */ |
6577 | ||
0d9551dc | 6578 | /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */ |
b05a1c8b | 6579 | if (json_paths) |
f1aa5d8a | 6580 | json_object_string_add(json_path, "origin", bgp_origin_long_str[attr->origin]); |
b05a1c8b | 6581 | else |
f1aa5d8a | 6582 | vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]); |
718e3744 | 6583 | |
6584 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) | |
b05a1c8b DS |
6585 | { |
6586 | if (json_paths) | |
f1aa5d8a | 6587 | json_object_int_add(json_path, "med", attr->med); |
b05a1c8b | 6588 | else |
f1aa5d8a | 6589 | vty_out (vty, ", metric %u", attr->med); |
b05a1c8b | 6590 | } |
718e3744 | 6591 | |
6592 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) | |
b05a1c8b DS |
6593 | { |
6594 | if (json_paths) | |
f1aa5d8a | 6595 | json_object_int_add(json_path, "localpref", attr->local_pref); |
b05a1c8b | 6596 | else |
f1aa5d8a | 6597 | vty_out (vty, ", localpref %u", attr->local_pref); |
b05a1c8b | 6598 | } |
718e3744 | 6599 | else |
b05a1c8b DS |
6600 | { |
6601 | if (json_paths) | |
f1aa5d8a | 6602 | json_object_int_add(json_path, "localpref", bgp->default_local_pref); |
b05a1c8b | 6603 | else |
f1aa5d8a | 6604 | vty_out (vty, ", localpref %u", bgp->default_local_pref); |
b05a1c8b | 6605 | } |
718e3744 | 6606 | |
fb982c25 | 6607 | if (attr->extra && attr->extra->weight != 0) |
b05a1c8b DS |
6608 | { |
6609 | if (json_paths) | |
f1aa5d8a | 6610 | json_object_int_add(json_path, "weight", attr->extra->weight); |
b05a1c8b | 6611 | else |
f1aa5d8a | 6612 | vty_out (vty, ", weight %u", attr->extra->weight); |
b05a1c8b | 6613 | } |
0d9551dc DS |
6614 | |
6615 | if (attr->extra && attr->extra->tag != 0) | |
b05a1c8b DS |
6616 | { |
6617 | if (json_paths) | |
f1aa5d8a | 6618 | json_object_int_add(json_path, "tag", attr->extra->tag); |
b05a1c8b | 6619 | else |
f1aa5d8a | 6620 | vty_out (vty, ", tag %d", attr->extra->tag); |
b05a1c8b | 6621 | } |
718e3744 | 6622 | |
31eba040 | 6623 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID)) |
b05a1c8b DS |
6624 | { |
6625 | if (json_paths) | |
f1aa5d8a | 6626 | json_object_boolean_false_add(json_path, "valid"); |
b05a1c8b DS |
6627 | else |
6628 | vty_out (vty, ", invalid"); | |
6629 | } | |
31eba040 | 6630 | else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
b05a1c8b DS |
6631 | { |
6632 | if (json_paths) | |
f1aa5d8a | 6633 | json_object_boolean_true_add(json_path, "valid"); |
b05a1c8b DS |
6634 | else |
6635 | vty_out (vty, ", valid"); | |
6636 | } | |
718e3744 | 6637 | |
6638 | if (binfo->peer != bgp->peer_self) | |
6639 | { | |
f1aa5d8a | 6640 | if (binfo->peer->as == binfo->peer->local_as) |
b05a1c8b | 6641 | { |
66b199b2 DS |
6642 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) |
6643 | { | |
6644 | if (json_paths) | |
f1aa5d8a | 6645 | json_object_string_add(json_peer, "type", "confed-internal"); |
66b199b2 | 6646 | else |
f1aa5d8a | 6647 | vty_out (vty, ", confed-internal"); |
66b199b2 | 6648 | } |
b05a1c8b | 6649 | else |
66b199b2 DS |
6650 | { |
6651 | if (json_paths) | |
f1aa5d8a | 6652 | json_object_string_add(json_peer, "type", "internal"); |
66b199b2 | 6653 | else |
f1aa5d8a | 6654 | vty_out (vty, ", internal"); |
66b199b2 | 6655 | } |
b05a1c8b | 6656 | } |
f1aa5d8a | 6657 | else |
b05a1c8b DS |
6658 | { |
6659 | if (bgp_confederation_peers_check(bgp, binfo->peer->as)) | |
6660 | { | |
6661 | if (json_paths) | |
f1aa5d8a | 6662 | json_object_string_add(json_peer, "type", "confed-external"); |
b05a1c8b | 6663 | else |
f1aa5d8a | 6664 | vty_out (vty, ", confed-external"); |
b05a1c8b DS |
6665 | } |
6666 | else | |
6667 | { | |
6668 | if (json_paths) | |
f1aa5d8a | 6669 | json_object_string_add(json_peer, "type", "external"); |
b05a1c8b | 6670 | else |
f1aa5d8a | 6671 | vty_out (vty, ", external"); |
b05a1c8b DS |
6672 | } |
6673 | } | |
718e3744 | 6674 | } |
6675 | else if (binfo->sub_type == BGP_ROUTE_AGGREGATE) | |
b05a1c8b DS |
6676 | { |
6677 | if (json_paths) | |
6678 | { | |
f1aa5d8a DS |
6679 | json_object_boolean_true_add(json_path, "aggregated"); |
6680 | json_object_boolean_true_add(json_path, "local"); | |
b05a1c8b DS |
6681 | } |
6682 | else | |
6683 | { | |
6684 | vty_out (vty, ", aggregated, local"); | |
6685 | } | |
6686 | } | |
718e3744 | 6687 | else if (binfo->type != ZEBRA_ROUTE_BGP) |
b05a1c8b DS |
6688 | { |
6689 | if (json_paths) | |
f1aa5d8a | 6690 | json_object_boolean_true_add(json_path, "sourced"); |
b05a1c8b DS |
6691 | else |
6692 | vty_out (vty, ", sourced"); | |
6693 | } | |
718e3744 | 6694 | else |
b05a1c8b DS |
6695 | { |
6696 | if (json_paths) | |
6697 | { | |
f1aa5d8a DS |
6698 | json_object_boolean_true_add(json_path, "sourced"); |
6699 | json_object_boolean_true_add(json_path, "local"); | |
b05a1c8b DS |
6700 | } |
6701 | else | |
6702 | { | |
6703 | vty_out (vty, ", sourced, local"); | |
6704 | } | |
6705 | } | |
718e3744 | 6706 | |
6707 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) | |
b05a1c8b DS |
6708 | { |
6709 | if (json_paths) | |
62d6dca0 | 6710 | json_object_boolean_true_add(json_path, "atomicAggregate"); |
b05a1c8b DS |
6711 | else |
6712 | vty_out (vty, ", atomic-aggregate"); | |
6713 | } | |
718e3744 | 6714 | |
de8d5dff JB |
6715 | if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) || |
6716 | (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) && | |
6717 | bgp_info_mpath_count (binfo))) | |
b05a1c8b DS |
6718 | { |
6719 | if (json_paths) | |
f1aa5d8a | 6720 | json_object_boolean_true_add(json_path, "multipath"); |
b05a1c8b DS |
6721 | else |
6722 | vty_out (vty, ", multipath"); | |
6723 | } | |
de8d5dff | 6724 | |
06370dac DW |
6725 | // Mark the bestpath(s) |
6726 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DMED_SELECTED)) | |
6727 | { | |
6728 | first_as = aspath_get_firstas(attr->aspath); | |
6729 | ||
6730 | if (json_paths) | |
6731 | { | |
6732 | if (!json_bestpath) | |
6733 | json_bestpath = json_object_new_object(); | |
6734 | json_object_int_add(json_bestpath, "bestpathFromAs", first_as); | |
6735 | } | |
6736 | else | |
6737 | { | |
6738 | if (first_as) | |
6739 | vty_out (vty, ", bestpath-from-AS %d", first_as); | |
6740 | else | |
6741 | vty_out (vty, ", bestpath-from-AS Local"); | |
6742 | } | |
6743 | } | |
6744 | ||
718e3744 | 6745 | if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) |
b05a1c8b DS |
6746 | { |
6747 | if (json_paths) | |
f1aa5d8a | 6748 | { |
06370dac DW |
6749 | if (!json_bestpath) |
6750 | json_bestpath = json_object_new_object(); | |
f1aa5d8a | 6751 | json_object_boolean_true_add(json_bestpath, "overall"); |
f1aa5d8a | 6752 | } |
b05a1c8b DS |
6753 | else |
6754 | vty_out (vty, ", best"); | |
6755 | } | |
718e3744 | 6756 | |
06370dac DW |
6757 | if (json_bestpath) |
6758 | json_object_object_add(json_path, "bestpath", json_bestpath); | |
6759 | ||
b05a1c8b DS |
6760 | if (!json_paths) |
6761 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6762 | |
6763 | /* Line 4 display Community */ | |
6764 | if (attr->community) | |
b05a1c8b DS |
6765 | { |
6766 | if (json_paths) | |
6767 | { | |
f1aa5d8a DS |
6768 | json_object_lock(attr->community->json); |
6769 | json_object_object_add(json_path, "community", attr->community->json); | |
b05a1c8b DS |
6770 | } |
6771 | else | |
6772 | { | |
6773 | vty_out (vty, " Community: %s%s", attr->community->str, | |
6774 | VTY_NEWLINE); | |
6775 | } | |
6776 | } | |
718e3744 | 6777 | |
6778 | /* Line 5 display Extended-community */ | |
6779 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) | |
b05a1c8b DS |
6780 | { |
6781 | if (json_paths) | |
6782 | { | |
f1aa5d8a DS |
6783 | json_ext_community = json_object_new_object(); |
6784 | json_object_string_add(json_ext_community, "string", attr->extra->ecommunity->str); | |
62d6dca0 | 6785 | json_object_object_add(json_path, "extendedCommunity", json_ext_community); |
b05a1c8b DS |
6786 | } |
6787 | else | |
6788 | { | |
6789 | vty_out (vty, " Extended Community: %s%s", | |
6790 | attr->extra->ecommunity->str, VTY_NEWLINE); | |
6791 | } | |
6792 | } | |
6793 | ||
718e3744 | 6794 | /* Line 6 display Originator, Cluster-id */ |
6795 | if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) || | |
6796 | (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) | |
6797 | { | |
fb982c25 | 6798 | assert (attr->extra); |
718e3744 | 6799 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
b05a1c8b DS |
6800 | { |
6801 | if (json_paths) | |
62d6dca0 | 6802 | json_object_string_add(json_path, "originatorId", inet_ntoa (attr->extra->originator_id)); |
b05a1c8b | 6803 | else |
f1aa5d8a DS |
6804 | vty_out (vty, " Originator: %s", |
6805 | inet_ntoa (attr->extra->originator_id)); | |
b05a1c8b | 6806 | } |
718e3744 | 6807 | |
6808 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) | |
6809 | { | |
6810 | int i; | |
b05a1c8b DS |
6811 | |
6812 | if (json_paths) | |
6813 | { | |
f1aa5d8a DS |
6814 | json_cluster_list = json_object_new_object(); |
6815 | json_cluster_list_list = json_object_new_array(); | |
6816 | ||
b05a1c8b DS |
6817 | for (i = 0; i < attr->extra->cluster->length / 4; i++) |
6818 | { | |
6819 | json_string = json_object_new_string(inet_ntoa (attr->extra->cluster->list[i])); | |
f1aa5d8a | 6820 | json_object_array_add(json_cluster_list_list, json_string); |
b05a1c8b | 6821 | } |
f1aa5d8a DS |
6822 | |
6823 | /* struct cluster_list does not have "str" variable like | |
6824 | * aspath and community do. Add this someday if someone | |
6825 | * asks for it. | |
6826 | json_object_string_add(json_cluster_list, "string", attr->extra->cluster->str); | |
6827 | */ | |
6828 | json_object_object_add(json_cluster_list, "list", json_cluster_list_list); | |
62d6dca0 | 6829 | json_object_object_add(json_path, "clusterList", json_cluster_list); |
b05a1c8b DS |
6830 | } |
6831 | else | |
6832 | { | |
6833 | vty_out (vty, ", Cluster list: "); | |
6834 | ||
6835 | for (i = 0; i < attr->extra->cluster->length / 4; i++) | |
6836 | { | |
6837 | vty_out (vty, "%s ", | |
6838 | inet_ntoa (attr->extra->cluster->list[i])); | |
6839 | } | |
6840 | } | |
718e3744 | 6841 | } |
b05a1c8b DS |
6842 | |
6843 | if (!json_paths) | |
6844 | vty_out (vty, "%s", VTY_NEWLINE); | |
718e3744 | 6845 | } |
b05a1c8b | 6846 | |
fb982c25 | 6847 | if (binfo->extra && binfo->extra->damp_info) |
b05a1c8b | 6848 | bgp_damp_info_vty (vty, binfo, json_path); |
718e3744 | 6849 | |
a82478b9 DS |
6850 | /* Line 7 display Addpath IDs */ |
6851 | if (binfo->addpath_rx_id || binfo->addpath_tx_id) | |
b05a1c8b DS |
6852 | { |
6853 | if (json_paths) | |
6854 | { | |
62d6dca0 DS |
6855 | json_object_int_add(json_path, "addpathRxId", binfo->addpath_rx_id); |
6856 | json_object_int_add(json_path, "addpathTxId", binfo->addpath_tx_id); | |
b05a1c8b DS |
6857 | } |
6858 | else | |
6859 | { | |
6860 | vty_out (vty, " AddPath ID: RX %u, TX %u%s", | |
6861 | binfo->addpath_rx_id, binfo->addpath_tx_id, | |
6862 | VTY_NEWLINE); | |
6863 | } | |
6864 | } | |
a82478b9 | 6865 | |
adbac85e DW |
6866 | /* If we used addpath to TX a non-bestpath we need to display |
6867 | * "Advertised to" on a path-by-path basis */ | |
6868 | if (bgp->addpath_tx_used[afi][safi]) | |
6869 | { | |
6870 | first = 1; | |
6871 | ||
6872 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) | |
6873 | { | |
6874 | addpath_capable = bgp_addpath_encode_tx (peer, afi, safi); | |
6875 | has_adj = bgp_adj_out_lookup (peer, binfo->net, binfo->addpath_tx_id); | |
6876 | ||
6877 | if ((addpath_capable && has_adj) || | |
6878 | (!addpath_capable && has_adj && CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))) | |
6879 | { | |
6880 | if (json_path && !json_adv_to) | |
6881 | json_adv_to = json_object_new_object(); | |
6882 | ||
6883 | route_vty_out_advertised_to(vty, peer, &first, | |
6884 | " Advertised to:", | |
6885 | json_adv_to); | |
6886 | } | |
6887 | } | |
6888 | ||
6889 | if (json_path) | |
6890 | { | |
6891 | if (json_adv_to) | |
6892 | { | |
6893 | json_object_object_add(json_path, "advertisedTo", json_adv_to); | |
6894 | } | |
6895 | } | |
6896 | else | |
6897 | { | |
6898 | if (!first) | |
6899 | { | |
6900 | vty_out (vty, "%s", VTY_NEWLINE); | |
6901 | } | |
6902 | } | |
6903 | } | |
6904 | ||
a82478b9 | 6905 | /* Line 8 display Uptime */ |
30b00176 JK |
6906 | #ifdef HAVE_CLOCK_MONOTONIC |
6907 | tbuf = time(NULL) - (bgp_clock() - binfo->uptime); | |
b05a1c8b | 6908 | if (json_paths) |
f1aa5d8a DS |
6909 | { |
6910 | json_last_update = json_object_new_object(); | |
6911 | json_object_int_add(json_last_update, "epoch", tbuf); | |
6912 | json_object_string_add(json_last_update, "string", ctime(&tbuf)); | |
62d6dca0 | 6913 | json_object_object_add(json_path, "lastUpdate", json_last_update); |
f1aa5d8a | 6914 | } |
b05a1c8b DS |
6915 | else |
6916 | vty_out (vty, " Last update: %s", ctime(&tbuf)); | |
30b00176 | 6917 | #else |
b05a1c8b | 6918 | if (json_paths) |
f1aa5d8a DS |
6919 | { |
6920 | json_last_update = json_object_new_object(); | |
6921 | json_object_int_add(json_last_update, "epoch", tbuf); | |
6922 | json_object_string_add(json_last_update, "string", ctime(&binfo->uptime)); | |
62d6dca0 | 6923 | json_object_object_add(json_path, "lastUpdate", json_last_update); |
f1aa5d8a | 6924 | } |
b05a1c8b DS |
6925 | else |
6926 | vty_out (vty, " Last update: %s", ctime(&binfo->uptime)); | |
30b00176 | 6927 | #endif /* HAVE_CLOCK_MONOTONIC */ |
718e3744 | 6928 | } |
b05a1c8b DS |
6929 | |
6930 | /* We've constructed the json object for this path, add it to the json | |
6931 | * array of paths | |
6932 | */ | |
6933 | if (json_paths) | |
f1aa5d8a DS |
6934 | { |
6935 | if (json_nexthop_global || json_nexthop_ll) | |
6936 | { | |
6937 | json_nexthops = json_object_new_array(); | |
6938 | ||
6939 | if (json_nexthop_global) | |
6940 | json_object_array_add(json_nexthops, json_nexthop_global); | |
6941 | ||
6942 | if (json_nexthop_ll) | |
6943 | json_object_array_add(json_nexthops, json_nexthop_ll); | |
6944 | ||
6945 | json_object_object_add(json_path, "nexthops", json_nexthops); | |
6946 | } | |
6947 | ||
6948 | json_object_object_add(json_path, "peer", json_peer); | |
6949 | json_object_array_add(json_paths, json_path); | |
6950 | } | |
b05a1c8b DS |
6951 | else |
6952 | vty_out (vty, "%s", VTY_NEWLINE); | |
b366b518 BB |
6953 | } |
6954 | ||
47fc97cc | 6955 | #define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path%s" |
718e3744 | 6956 | #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s" |
6957 | #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s" | |
6958 | ||
6959 | enum bgp_show_type | |
6960 | { | |
6961 | bgp_show_type_normal, | |
6962 | bgp_show_type_regexp, | |
6963 | bgp_show_type_prefix_list, | |
6964 | bgp_show_type_filter_list, | |
6965 | bgp_show_type_route_map, | |
6966 | bgp_show_type_neighbor, | |
6967 | bgp_show_type_cidr_only, | |
6968 | bgp_show_type_prefix_longer, | |
6969 | bgp_show_type_community_all, | |
6970 | bgp_show_type_community, | |
6971 | bgp_show_type_community_exact, | |
6972 | bgp_show_type_community_list, | |
6973 | bgp_show_type_community_list_exact, | |
6974 | bgp_show_type_flap_statistics, | |
6975 | bgp_show_type_flap_address, | |
6976 | bgp_show_type_flap_prefix, | |
6977 | bgp_show_type_flap_cidr_only, | |
6978 | bgp_show_type_flap_regexp, | |
6979 | bgp_show_type_flap_filter_list, | |
6980 | bgp_show_type_flap_prefix_list, | |
6981 | bgp_show_type_flap_prefix_longer, | |
6982 | bgp_show_type_flap_route_map, | |
6983 | bgp_show_type_flap_neighbor, | |
6984 | bgp_show_type_dampend_paths, | |
6985 | bgp_show_type_damp_neighbor | |
6986 | }; | |
6987 | ||
5a646650 | 6988 | static int |
fee0f4c6 | 6989 | bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id, |
856ca177 | 6990 | enum bgp_show_type type, void *output_arg, u_char use_json) |
718e3744 | 6991 | { |
718e3744 | 6992 | struct bgp_info *ri; |
6993 | struct bgp_node *rn; | |
718e3744 | 6994 | int header = 1; |
718e3744 | 6995 | int display; |
5a646650 | 6996 | unsigned long output_count; |
b05a1c8b DS |
6997 | struct prefix *p; |
6998 | char buf[BUFSIZ]; | |
6999 | char buf2[BUFSIZ]; | |
f1aa5d8a DS |
7000 | json_object *json = NULL; |
7001 | json_object *json_paths = NULL; | |
7002 | json_object *json_routes = NULL; | |
b05a1c8b DS |
7003 | |
7004 | if (use_json) | |
7005 | { | |
7006 | json = json_object_new_object(); | |
62d6dca0 DS |
7007 | json_object_int_add(json, "tableVersion", table->version); |
7008 | json_object_string_add(json, "routerId", inet_ntoa (*router_id)); | |
b05a1c8b DS |
7009 | json_routes = json_object_new_object(); |
7010 | } | |
718e3744 | 7011 | |
7012 | /* This is first entry point, so reset total line. */ | |
5a646650 | 7013 | output_count = 0; |
718e3744 | 7014 | |
718e3744 | 7015 | /* Start processing of routes. */ |
7016 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
7017 | if (rn->info != NULL) | |
7018 | { | |
856ca177 | 7019 | display = 0; |
718e3744 | 7020 | |
b05a1c8b DS |
7021 | if (use_json) |
7022 | json_paths = json_object_new_array(); | |
7023 | else | |
7024 | json_paths = NULL; | |
7025 | ||
856ca177 MS |
7026 | for (ri = rn->info; ri; ri = ri->next) |
7027 | { | |
7028 | if (type == bgp_show_type_flap_statistics | |
7029 | || type == bgp_show_type_flap_address | |
7030 | || type == bgp_show_type_flap_prefix | |
7031 | || type == bgp_show_type_flap_cidr_only | |
7032 | || type == bgp_show_type_flap_regexp | |
7033 | || type == bgp_show_type_flap_filter_list | |
7034 | || type == bgp_show_type_flap_prefix_list | |
7035 | || type == bgp_show_type_flap_prefix_longer | |
7036 | || type == bgp_show_type_flap_route_map | |
7037 | || type == bgp_show_type_flap_neighbor | |
7038 | || type == bgp_show_type_dampend_paths | |
7039 | || type == bgp_show_type_damp_neighbor) | |
7040 | { | |
7041 | if (!(ri->extra && ri->extra->damp_info)) | |
7042 | continue; | |
7043 | } | |
7044 | if (type == bgp_show_type_regexp | |
7045 | || type == bgp_show_type_flap_regexp) | |
7046 | { | |
7047 | regex_t *regex = output_arg; | |
718e3744 | 7048 | |
856ca177 MS |
7049 | if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH) |
7050 | continue; | |
7051 | } | |
7052 | if (type == bgp_show_type_prefix_list | |
7053 | || type == bgp_show_type_flap_prefix_list) | |
7054 | { | |
7055 | struct prefix_list *plist = output_arg; | |
718e3744 | 7056 | |
856ca177 MS |
7057 | if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT) |
7058 | continue; | |
7059 | } | |
7060 | if (type == bgp_show_type_filter_list | |
7061 | || type == bgp_show_type_flap_filter_list) | |
7062 | { | |
7063 | struct as_list *as_list = output_arg; | |
558d1fec | 7064 | |
856ca177 MS |
7065 | if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT) |
7066 | continue; | |
7067 | } | |
7068 | if (type == bgp_show_type_route_map | |
7069 | || type == bgp_show_type_flap_route_map) | |
7070 | { | |
7071 | struct route_map *rmap = output_arg; | |
7072 | struct bgp_info binfo; | |
7073 | struct attr dummy_attr; | |
7074 | struct attr_extra dummy_extra; | |
7075 | int ret; | |
718e3744 | 7076 | |
856ca177 MS |
7077 | dummy_attr.extra = &dummy_extra; |
7078 | bgp_attr_dup (&dummy_attr, ri->attr); | |
718e3744 | 7079 | |
856ca177 MS |
7080 | binfo.peer = ri->peer; |
7081 | binfo.attr = &dummy_attr; | |
718e3744 | 7082 | |
856ca177 MS |
7083 | ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo); |
7084 | if (ret == RMAP_DENYMATCH) | |
7085 | continue; | |
7086 | } | |
7087 | if (type == bgp_show_type_neighbor | |
7088 | || type == bgp_show_type_flap_neighbor | |
7089 | || type == bgp_show_type_damp_neighbor) | |
7090 | { | |
7091 | union sockunion *su = output_arg; | |
718e3744 | 7092 | |
856ca177 MS |
7093 | if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su)) |
7094 | continue; | |
7095 | } | |
7096 | if (type == bgp_show_type_cidr_only | |
7097 | || type == bgp_show_type_flap_cidr_only) | |
7098 | { | |
7099 | u_int32_t destination; | |
718e3744 | 7100 | |
856ca177 MS |
7101 | destination = ntohl (rn->p.u.prefix4.s_addr); |
7102 | if (IN_CLASSC (destination) && rn->p.prefixlen == 24) | |
7103 | continue; | |
7104 | if (IN_CLASSB (destination) && rn->p.prefixlen == 16) | |
7105 | continue; | |
7106 | if (IN_CLASSA (destination) && rn->p.prefixlen == 8) | |
7107 | continue; | |
7108 | } | |
7109 | if (type == bgp_show_type_prefix_longer | |
7110 | || type == bgp_show_type_flap_prefix_longer) | |
7111 | { | |
7112 | struct prefix *p = output_arg; | |
718e3744 | 7113 | |
856ca177 MS |
7114 | if (! prefix_match (p, &rn->p)) |
7115 | continue; | |
7116 | } | |
7117 | if (type == bgp_show_type_community_all) | |
7118 | { | |
7119 | if (! ri->attr->community) | |
7120 | continue; | |
7121 | } | |
7122 | if (type == bgp_show_type_community) | |
7123 | { | |
7124 | struct community *com = output_arg; | |
718e3744 | 7125 | |
856ca177 MS |
7126 | if (! ri->attr->community || |
7127 | ! community_match (ri->attr->community, com)) | |
7128 | continue; | |
7129 | } | |
7130 | if (type == bgp_show_type_community_exact) | |
7131 | { | |
7132 | struct community *com = output_arg; | |
718e3744 | 7133 | |
856ca177 MS |
7134 | if (! ri->attr->community || |
7135 | ! community_cmp (ri->attr->community, com)) | |
7136 | continue; | |
7137 | } | |
7138 | if (type == bgp_show_type_community_list) | |
7139 | { | |
7140 | struct community_list *list = output_arg; | |
718e3744 | 7141 | |
856ca177 MS |
7142 | if (! community_list_match (ri->attr->community, list)) |
7143 | continue; | |
7144 | } | |
7145 | if (type == bgp_show_type_community_list_exact) | |
7146 | { | |
7147 | struct community_list *list = output_arg; | |
718e3744 | 7148 | |
856ca177 MS |
7149 | if (! community_list_exact_match (ri->attr->community, list)) |
7150 | continue; | |
7151 | } | |
7152 | if (type == bgp_show_type_flap_address | |
7153 | || type == bgp_show_type_flap_prefix) | |
7154 | { | |
7155 | struct prefix *p = output_arg; | |
718e3744 | 7156 | |
856ca177 MS |
7157 | if (! prefix_match (&rn->p, p)) |
7158 | continue; | |
b05a1c8b | 7159 | |
856ca177 MS |
7160 | if (type == bgp_show_type_flap_prefix) |
7161 | if (p->prefixlen != rn->p.prefixlen) | |
7162 | continue; | |
7163 | } | |
7164 | if (type == bgp_show_type_dampend_paths | |
7165 | || type == bgp_show_type_damp_neighbor) | |
7166 | { | |
7167 | if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED) | |
7168 | || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) | |
7169 | continue; | |
7170 | } | |
7171 | ||
7172 | if (!use_json && header) | |
7173 | { | |
7174 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (*router_id), VTY_NEWLINE); | |
7175 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
7176 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
7177 | if (type == bgp_show_type_dampend_paths | |
7178 | || type == bgp_show_type_damp_neighbor) | |
7179 | vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE); | |
7180 | else if (type == bgp_show_type_flap_statistics | |
7181 | || type == bgp_show_type_flap_address | |
7182 | || type == bgp_show_type_flap_prefix | |
7183 | || type == bgp_show_type_flap_cidr_only | |
7184 | || type == bgp_show_type_flap_regexp | |
7185 | || type == bgp_show_type_flap_filter_list | |
7186 | || type == bgp_show_type_flap_prefix_list | |
7187 | || type == bgp_show_type_flap_prefix_longer | |
7188 | || type == bgp_show_type_flap_route_map | |
7189 | || type == bgp_show_type_flap_neighbor) | |
7190 | vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE); | |
7191 | else | |
7192 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
7193 | header = 0; | |
7194 | } | |
7195 | ||
7196 | if (type == bgp_show_type_dampend_paths | |
7197 | || type == bgp_show_type_damp_neighbor) | |
7198 | damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths); | |
7199 | else if (type == bgp_show_type_flap_statistics | |
7200 | || type == bgp_show_type_flap_address | |
7201 | || type == bgp_show_type_flap_prefix | |
7202 | || type == bgp_show_type_flap_cidr_only | |
7203 | || type == bgp_show_type_flap_regexp | |
7204 | || type == bgp_show_type_flap_filter_list | |
7205 | || type == bgp_show_type_flap_prefix_list | |
7206 | || type == bgp_show_type_flap_prefix_longer | |
7207 | || type == bgp_show_type_flap_route_map | |
7208 | || type == bgp_show_type_flap_neighbor) | |
7209 | flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, use_json, json_paths); | |
7210 | else | |
7211 | route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST, json_paths); | |
7212 | display++; | |
b05a1c8b DS |
7213 | } |
7214 | ||
856ca177 MS |
7215 | if (display) |
7216 | { | |
7217 | output_count++; | |
7218 | if (use_json) | |
7219 | { | |
7220 | p = &rn->p; | |
7221 | sprintf(buf2, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); | |
7222 | json_object_object_add(json_routes, buf2, json_paths); | |
7223 | } | |
7224 | } | |
718e3744 | 7225 | } |
7226 | ||
b05a1c8b | 7227 | if (use_json) |
718e3744 | 7228 | { |
d1d16a96 | 7229 | json_object_object_add(json, "routes", json_routes); |
b05a1c8b | 7230 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); |
f1aa5d8a | 7231 | json_object_free(json); |
718e3744 | 7232 | } |
7233 | else | |
b05a1c8b DS |
7234 | { |
7235 | /* No route is displayed */ | |
7236 | if (output_count == 0) | |
7237 | { | |
7238 | if (type == bgp_show_type_normal) | |
856ca177 | 7239 | vty_out (vty, "No BGP network exists%s", VTY_NEWLINE); |
b05a1c8b DS |
7240 | } |
7241 | else | |
7242 | vty_out (vty, "%sTotal number of prefixes %ld%s", | |
856ca177 | 7243 | VTY_NEWLINE, output_count, VTY_NEWLINE); |
b05a1c8b | 7244 | } |
718e3744 | 7245 | |
7246 | return CMD_SUCCESS; | |
7247 | } | |
7248 | ||
5a646650 | 7249 | static int |
fee0f4c6 | 7250 | bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, |
856ca177 | 7251 | enum bgp_show_type type, void *output_arg, u_char use_json) |
fee0f4c6 | 7252 | { |
7253 | struct bgp_table *table; | |
7254 | ||
856ca177 MS |
7255 | if (bgp == NULL) |
7256 | { | |
7257 | bgp = bgp_get_default (); | |
7258 | } | |
fee0f4c6 | 7259 | |
7260 | if (bgp == NULL) | |
7261 | { | |
856ca177 MS |
7262 | if (!use_json) |
7263 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
fee0f4c6 | 7264 | return CMD_WARNING; |
7265 | } | |
7266 | ||
fee0f4c6 | 7267 | table = bgp->rib[afi][safi]; |
7268 | ||
b05a1c8b | 7269 | return bgp_show_table (vty, table, &bgp->router_id, type, output_arg, use_json); |
fee0f4c6 | 7270 | } |
7271 | ||
718e3744 | 7272 | /* Header of detailed BGP route information */ |
94f2b392 | 7273 | static void |
718e3744 | 7274 | route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, |
7275 | struct bgp_node *rn, | |
b05a1c8b DS |
7276 | struct prefix_rd *prd, afi_t afi, safi_t safi, |
7277 | json_object *json) | |
718e3744 | 7278 | { |
7279 | struct bgp_info *ri; | |
7280 | struct prefix *p; | |
7281 | struct peer *peer; | |
1eb8ef25 | 7282 | struct listnode *node, *nnode; |
718e3744 | 7283 | char buf1[INET6_ADDRSTRLEN]; |
7284 | char buf2[INET6_ADDRSTRLEN]; | |
7285 | int count = 0; | |
7286 | int best = 0; | |
7287 | int suppress = 0; | |
7288 | int no_export = 0; | |
7289 | int no_advertise = 0; | |
7290 | int local_as = 0; | |
adbac85e | 7291 | int first = 1; |
ffd0c037 | 7292 | json_object *json_adv_to = NULL; |
718e3744 | 7293 | |
7294 | p = &rn->p; | |
b05a1c8b DS |
7295 | |
7296 | if (json) | |
7297 | { | |
f1aa5d8a DS |
7298 | json_object_string_add(json, "prefix", inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN)); |
7299 | json_object_int_add(json, "prefixlen", p->prefixlen); | |
b05a1c8b DS |
7300 | } |
7301 | else | |
7302 | { | |
7303 | vty_out (vty, "BGP routing table entry for %s%s%s/%d%s", | |
7304 | (safi == SAFI_MPLS_VPN ? | |
7305 | prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""), | |
7306 | safi == SAFI_MPLS_VPN ? ":" : "", | |
7307 | inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN), | |
7308 | p->prefixlen, VTY_NEWLINE); | |
7309 | } | |
718e3744 | 7310 | |
7311 | for (ri = rn->info; ri; ri = ri->next) | |
7312 | { | |
7313 | count++; | |
7314 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) | |
7315 | { | |
7316 | best = count; | |
fb982c25 | 7317 | if (ri->extra && ri->extra->suppress) |
718e3744 | 7318 | suppress = 1; |
7319 | if (ri->attr->community != NULL) | |
7320 | { | |
7321 | if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE)) | |
7322 | no_advertise = 1; | |
7323 | if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT)) | |
7324 | no_export = 1; | |
7325 | if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS)) | |
7326 | local_as = 1; | |
7327 | } | |
7328 | } | |
7329 | } | |
7330 | ||
b05a1c8b | 7331 | if (!json) |
718e3744 | 7332 | { |
b05a1c8b DS |
7333 | vty_out (vty, "Paths: (%d available", count); |
7334 | if (best) | |
7335 | { | |
7336 | vty_out (vty, ", best #%d", best); | |
7337 | if (safi == SAFI_UNICAST) | |
7338 | vty_out (vty, ", table Default-IP-Routing-Table"); | |
7339 | } | |
7340 | else | |
7341 | vty_out (vty, ", no best path"); | |
7342 | ||
7343 | if (no_advertise) | |
7344 | vty_out (vty, ", not advertised to any peer"); | |
7345 | else if (no_export) | |
7346 | vty_out (vty, ", not advertised to EBGP peer"); | |
7347 | else if (local_as) | |
7348 | vty_out (vty, ", not advertised outside local AS"); | |
7349 | ||
7350 | if (suppress) | |
7351 | vty_out (vty, ", Advertisements suppressed by an aggregate."); | |
7352 | vty_out (vty, ")%s", VTY_NEWLINE); | |
718e3744 | 7353 | } |
718e3744 | 7354 | |
adbac85e DW |
7355 | /* If we are not using addpath then we can display Advertised to and that will |
7356 | * show what peers we advertised the bestpath to. If we are using addpath | |
7357 | * though then we must display Advertised to on a path-by-path basis. */ | |
7358 | if (!bgp->addpath_tx_used[afi][safi]) | |
718e3744 | 7359 | { |
adbac85e DW |
7360 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
7361 | { | |
7362 | if (bgp_adj_out_lookup (peer, rn, 0)) | |
b05a1c8b | 7363 | { |
adbac85e | 7364 | if (json && !json_adv_to) |
f1aa5d8a | 7365 | json_adv_to = json_object_new_object(); |
6410e93a | 7366 | |
adbac85e DW |
7367 | route_vty_out_advertised_to(vty, peer, &first, |
7368 | " Advertised to non peer-group peers:\n ", | |
7369 | json_adv_to); | |
b05a1c8b | 7370 | } |
adbac85e | 7371 | } |
036a4e7d | 7372 | |
adbac85e DW |
7373 | if (json) |
7374 | { | |
7375 | if (json_adv_to) | |
7376 | { | |
7377 | json_object_object_add(json, "advertisedTo", json_adv_to); | |
b05a1c8b | 7378 | } |
adbac85e DW |
7379 | } |
7380 | else | |
b05a1c8b | 7381 | { |
adbac85e DW |
7382 | if (first) |
7383 | vty_out (vty, " Not advertised to any peer"); | |
7384 | vty_out (vty, "%s", VTY_NEWLINE); | |
b05a1c8b DS |
7385 | } |
7386 | } | |
718e3744 | 7387 | } |
7388 | ||
7389 | /* Display specified route of BGP table. */ | |
94f2b392 | 7390 | static int |
fee0f4c6 | 7391 | bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, |
fd79ac91 | 7392 | struct bgp_table *rib, const char *ip_str, |
7393 | afi_t afi, safi_t safi, struct prefix_rd *prd, | |
b05a1c8b DS |
7394 | int prefix_check, enum bgp_path_type pathtype, |
7395 | u_char use_json) | |
718e3744 | 7396 | { |
7397 | int ret; | |
7398 | int header; | |
7399 | int display = 0; | |
7400 | struct prefix match; | |
7401 | struct bgp_node *rn; | |
7402 | struct bgp_node *rm; | |
7403 | struct bgp_info *ri; | |
718e3744 | 7404 | struct bgp_table *table; |
f1aa5d8a DS |
7405 | json_object *json = NULL; |
7406 | json_object *json_paths = NULL; | |
718e3744 | 7407 | |
718e3744 | 7408 | /* Check IP address argument. */ |
7409 | ret = str2prefix (ip_str, &match); | |
7410 | if (! ret) | |
7411 | { | |
7412 | vty_out (vty, "address is malformed%s", VTY_NEWLINE); | |
7413 | return CMD_WARNING; | |
7414 | } | |
7415 | ||
7416 | match.family = afi2family (afi); | |
7417 | ||
b05a1c8b DS |
7418 | if (use_json) |
7419 | { | |
7420 | json = json_object_new_object(); | |
7421 | json_paths = json_object_new_array(); | |
7422 | } | |
b05a1c8b | 7423 | |
718e3744 | 7424 | if (safi == SAFI_MPLS_VPN) |
7425 | { | |
fee0f4c6 | 7426 | for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn)) |
718e3744 | 7427 | { |
7428 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
7429 | continue; | |
7430 | ||
7431 | if ((table = rn->info) != NULL) | |
7432 | { | |
7433 | header = 1; | |
7434 | ||
7435 | if ((rm = bgp_node_match (table, &match)) != NULL) | |
7436 | { | |
7437 | if (prefix_check && rm->p.prefixlen != match.prefixlen) | |
6c88b44d CC |
7438 | { |
7439 | bgp_unlock_node (rm); | |
7440 | continue; | |
7441 | } | |
718e3744 | 7442 | |
7443 | for (ri = rm->info; ri; ri = ri->next) | |
7444 | { | |
7445 | if (header) | |
7446 | { | |
7447 | route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p, | |
b05a1c8b | 7448 | AFI_IP, SAFI_MPLS_VPN, json); |
718e3744 | 7449 | |
7450 | header = 0; | |
7451 | } | |
7452 | display++; | |
4092b06c DS |
7453 | |
7454 | if (pathtype == BGP_PATH_ALL || | |
7455 | (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) || | |
7456 | (pathtype == BGP_PATH_MULTIPATH && | |
7457 | (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)))) | |
b05a1c8b | 7458 | route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN, json_paths); |
718e3744 | 7459 | } |
6c88b44d CC |
7460 | |
7461 | bgp_unlock_node (rm); | |
718e3744 | 7462 | } |
7463 | } | |
7464 | } | |
7465 | } | |
7466 | else | |
7467 | { | |
7468 | header = 1; | |
7469 | ||
fee0f4c6 | 7470 | if ((rn = bgp_node_match (rib, &match)) != NULL) |
718e3744 | 7471 | { |
7472 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) | |
7473 | { | |
7474 | for (ri = rn->info; ri; ri = ri->next) | |
7475 | { | |
7476 | if (header) | |
7477 | { | |
b05a1c8b | 7478 | route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi, json); |
718e3744 | 7479 | header = 0; |
7480 | } | |
7481 | display++; | |
4092b06c DS |
7482 | |
7483 | if (pathtype == BGP_PATH_ALL || | |
7484 | (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) || | |
7485 | (pathtype == BGP_PATH_MULTIPATH && | |
7486 | (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)))) | |
b05a1c8b | 7487 | route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi, json_paths); |
718e3744 | 7488 | } |
7489 | } | |
6c88b44d CC |
7490 | |
7491 | bgp_unlock_node (rn); | |
718e3744 | 7492 | } |
7493 | } | |
7494 | ||
e5eee9af | 7495 | if (use_json) |
718e3744 | 7496 | { |
e5eee9af DS |
7497 | if (display) |
7498 | json_object_object_add(json, "paths", json_paths); | |
7499 | ||
7500 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
f1aa5d8a | 7501 | json_object_free(json); |
b05a1c8b DS |
7502 | } |
7503 | else | |
7504 | { | |
e5eee9af | 7505 | if (!display) |
b05a1c8b DS |
7506 | { |
7507 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); | |
7508 | return CMD_WARNING; | |
7509 | } | |
7510 | } | |
7511 | ||
718e3744 | 7512 | return CMD_SUCCESS; |
7513 | } | |
7514 | ||
fee0f4c6 | 7515 | /* Display specified route of Main RIB */ |
94f2b392 | 7516 | static int |
fd79ac91 | 7517 | bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str, |
fee0f4c6 | 7518 | afi_t afi, safi_t safi, struct prefix_rd *prd, |
b05a1c8b DS |
7519 | int prefix_check, enum bgp_path_type pathtype, |
7520 | u_char use_json) | |
fee0f4c6 | 7521 | { |
7522 | struct bgp *bgp; | |
7523 | ||
7524 | /* BGP structure lookup. */ | |
7525 | if (view_name) | |
7526 | { | |
7527 | bgp = bgp_lookup_by_name (view_name); | |
7528 | if (bgp == NULL) | |
7529 | { | |
6aeb9e78 | 7530 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
fee0f4c6 | 7531 | return CMD_WARNING; |
7532 | } | |
7533 | } | |
7534 | else | |
7535 | { | |
7536 | bgp = bgp_get_default (); | |
7537 | if (bgp == NULL) | |
7538 | { | |
7539 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
7540 | return CMD_WARNING; | |
7541 | } | |
7542 | } | |
7543 | ||
7544 | return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str, | |
b05a1c8b DS |
7545 | afi, safi, prd, prefix_check, pathtype, |
7546 | use_json); | |
fee0f4c6 | 7547 | } |
7548 | ||
718e3744 | 7549 | /* BGP route print out function. */ |
7550 | DEFUN (show_ip_bgp, | |
7551 | show_ip_bgp_cmd, | |
b05a1c8b | 7552 | "show ip bgp {json}", |
47fc97cc DS |
7553 | SHOW_STR |
7554 | IP_STR | |
b05a1c8b DS |
7555 | BGP_STR |
7556 | "JavaScript Object Notation\n") | |
47fc97cc | 7557 | { |
db7c8528 | 7558 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); |
718e3744 | 7559 | } |
7560 | ||
7561 | DEFUN (show_ip_bgp_ipv4, | |
7562 | show_ip_bgp_ipv4_cmd, | |
b05a1c8b | 7563 | "show ip bgp ipv4 (unicast|multicast) {json}", |
718e3744 | 7564 | SHOW_STR |
7565 | IP_STR | |
7566 | BGP_STR | |
7567 | "Address family\n" | |
7568 | "Address Family modifier\n" | |
b05a1c8b DS |
7569 | "Address Family modifier\n" |
7570 | "JavaScript Object Notation\n") | |
718e3744 | 7571 | { |
db7c8528 | 7572 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7573 | |
718e3744 | 7574 | if (strncmp (argv[0], "m", 1) == 0) |
5a646650 | 7575 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal, |
db7c8528 | 7576 | NULL, uj); |
718e3744 | 7577 | |
db7c8528 | 7578 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, uj); |
718e3744 | 7579 | } |
7580 | ||
95cbbd2a ML |
7581 | ALIAS (show_ip_bgp_ipv4, |
7582 | show_bgp_ipv4_safi_cmd, | |
b05a1c8b | 7583 | "show bgp ipv4 (unicast|multicast) {json}", |
95cbbd2a ML |
7584 | SHOW_STR |
7585 | BGP_STR | |
7586 | "Address family\n" | |
7587 | "Address Family modifier\n" | |
47fc97cc | 7588 | "Address Family modifier\n" |
b05a1c8b | 7589 | "JavaScript Object Notation\n") |
47fc97cc | 7590 | |
718e3744 | 7591 | DEFUN (show_ip_bgp_route, |
7592 | show_ip_bgp_route_cmd, | |
b05a1c8b | 7593 | "show ip bgp A.B.C.D {json}", |
718e3744 | 7594 | SHOW_STR |
7595 | IP_STR | |
7596 | BGP_STR | |
b05a1c8b DS |
7597 | "Network in the BGP routing table to display\n" |
7598 | "JavaScript Object Notation\n") | |
718e3744 | 7599 | { |
db7c8528 | 7600 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
4092b06c DS |
7601 | } |
7602 | ||
7603 | DEFUN (show_ip_bgp_route_pathtype, | |
7604 | show_ip_bgp_route_pathtype_cmd, | |
b05a1c8b | 7605 | "show ip bgp A.B.C.D (bestpath|multipath) {json}", |
4092b06c DS |
7606 | SHOW_STR |
7607 | IP_STR | |
7608 | BGP_STR | |
7609 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
7610 | "Display only the bestpath\n" | |
b05a1c8b DS |
7611 | "Display only multipaths\n" |
7612 | "JavaScript Object Notation\n") | |
4092b06c | 7613 | { |
db7c8528 | 7614 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7615 | |
4092b06c | 7616 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 7617 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 7618 | else |
db7c8528 | 7619 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
7620 | } |
7621 | ||
7622 | DEFUN (show_bgp_ipv4_safi_route_pathtype, | |
7623 | show_bgp_ipv4_safi_route_pathtype_cmd, | |
b05a1c8b | 7624 | "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath) {json}", |
4092b06c DS |
7625 | SHOW_STR |
7626 | BGP_STR | |
7627 | "Address family\n" | |
7628 | "Address Family modifier\n" | |
7629 | "Address Family modifier\n" | |
7630 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
7631 | "Display only the bestpath\n" | |
b05a1c8b DS |
7632 | "Display only multipaths\n" |
7633 | "JavaScript Object Notation\n") | |
4092b06c | 7634 | { |
db7c8528 | 7635 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7636 | |
4092b06c DS |
7637 | if (strncmp (argv[0], "m", 1) == 0) |
7638 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 7639 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 7640 | else |
db7c8528 | 7641 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
7642 | else |
7643 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 7644 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 7645 | else |
db7c8528 | 7646 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
718e3744 | 7647 | } |
7648 | ||
7649 | DEFUN (show_ip_bgp_ipv4_route, | |
7650 | show_ip_bgp_ipv4_route_cmd, | |
b05a1c8b | 7651 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D {json}", |
718e3744 | 7652 | SHOW_STR |
7653 | IP_STR | |
7654 | BGP_STR | |
7655 | "Address family\n" | |
7656 | "Address Family modifier\n" | |
7657 | "Address Family modifier\n" | |
b05a1c8b DS |
7658 | "Network in the BGP routing table to display\n" |
7659 | "JavaScript Object Notation\n") | |
718e3744 | 7660 | { |
db7c8528 | 7661 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7662 | |
718e3744 | 7663 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 7664 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj); |
718e3744 | 7665 | |
db7c8528 | 7666 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj); |
718e3744 | 7667 | } |
7668 | ||
95cbbd2a ML |
7669 | ALIAS (show_ip_bgp_ipv4_route, |
7670 | show_bgp_ipv4_safi_route_cmd, | |
b05a1c8b | 7671 | "show bgp ipv4 (unicast|multicast) A.B.C.D {json}", |
95cbbd2a ML |
7672 | SHOW_STR |
7673 | BGP_STR | |
7674 | "Address family\n" | |
7675 | "Address Family modifier\n" | |
7676 | "Address Family modifier\n" | |
b05a1c8b DS |
7677 | "Network in the BGP routing table to display\n" |
7678 | "JavaScript Object Notation\n") | |
95cbbd2a | 7679 | |
718e3744 | 7680 | DEFUN (show_ip_bgp_vpnv4_all_route, |
7681 | show_ip_bgp_vpnv4_all_route_cmd, | |
b05a1c8b | 7682 | "show ip bgp vpnv4 all A.B.C.D {json}", |
718e3744 | 7683 | SHOW_STR |
7684 | IP_STR | |
7685 | BGP_STR | |
7686 | "Display VPNv4 NLRI specific information\n" | |
7687 | "Display information about all VPNv4 NLRIs\n" | |
b05a1c8b DS |
7688 | "Network in the BGP routing table to display\n" |
7689 | "JavaScript Object Notation\n") | |
718e3744 | 7690 | { |
db7c8528 | 7691 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7692 | } |
7693 | ||
4092b06c | 7694 | |
718e3744 | 7695 | DEFUN (show_ip_bgp_vpnv4_rd_route, |
7696 | show_ip_bgp_vpnv4_rd_route_cmd, | |
b05a1c8b | 7697 | "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D {json}", |
718e3744 | 7698 | SHOW_STR |
7699 | IP_STR | |
7700 | BGP_STR | |
7701 | "Display VPNv4 NLRI specific information\n" | |
7702 | "Display information for a route distinguisher\n" | |
7703 | "VPN Route Distinguisher\n" | |
b05a1c8b DS |
7704 | "Network in the BGP routing table to display\n" |
7705 | "JavaScript Object Notation\n") | |
718e3744 | 7706 | { |
7707 | int ret; | |
7708 | struct prefix_rd prd; | |
db7c8528 | 7709 | u_char uj= use_json(argc, argv); |
718e3744 | 7710 | |
7711 | ret = str2prefix_rd (argv[0], &prd); | |
7712 | if (! ret) | |
7713 | { | |
7714 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
7715 | return CMD_WARNING; | |
7716 | } | |
db7c8528 | 7717 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, uj); |
718e3744 | 7718 | } |
7719 | ||
7720 | DEFUN (show_ip_bgp_prefix, | |
7721 | show_ip_bgp_prefix_cmd, | |
b05a1c8b | 7722 | "show ip bgp A.B.C.D/M {json}", |
718e3744 | 7723 | SHOW_STR |
7724 | IP_STR | |
7725 | BGP_STR | |
b05a1c8b DS |
7726 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7727 | "JavaScript Object Notation\n") | |
718e3744 | 7728 | { |
db7c8528 | 7729 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
4092b06c DS |
7730 | } |
7731 | ||
7732 | DEFUN (show_ip_bgp_prefix_pathtype, | |
7733 | show_ip_bgp_prefix_pathtype_cmd, | |
b05a1c8b | 7734 | "show ip bgp A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
7735 | SHOW_STR |
7736 | IP_STR | |
7737 | BGP_STR | |
7738 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
7739 | "Display only the bestpath\n" | |
b05a1c8b DS |
7740 | "Display only multipaths\n" |
7741 | "JavaScript Object Notation\n") | |
4092b06c | 7742 | { |
db7c8528 | 7743 | u_char uj = use_json(argc, argv); |
4092b06c | 7744 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 7745 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 7746 | else |
db7c8528 | 7747 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
718e3744 | 7748 | } |
7749 | ||
7750 | DEFUN (show_ip_bgp_ipv4_prefix, | |
7751 | show_ip_bgp_ipv4_prefix_cmd, | |
b05a1c8b | 7752 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M {json}", |
718e3744 | 7753 | SHOW_STR |
7754 | IP_STR | |
7755 | BGP_STR | |
7756 | "Address family\n" | |
7757 | "Address Family modifier\n" | |
7758 | "Address Family modifier\n" | |
b05a1c8b DS |
7759 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7760 | "JavaScript Object Notation\n") | |
718e3744 | 7761 | { |
db7c8528 | 7762 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7763 | |
718e3744 | 7764 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 7765 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj); |
718e3744 | 7766 | |
db7c8528 | 7767 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj); |
718e3744 | 7768 | } |
7769 | ||
95cbbd2a ML |
7770 | ALIAS (show_ip_bgp_ipv4_prefix, |
7771 | show_bgp_ipv4_safi_prefix_cmd, | |
b05a1c8b | 7772 | "show bgp ipv4 (unicast|multicast) A.B.C.D/M {json}", |
95cbbd2a ML |
7773 | SHOW_STR |
7774 | BGP_STR | |
7775 | "Address family\n" | |
7776 | "Address Family modifier\n" | |
7777 | "Address Family modifier\n" | |
b05a1c8b DS |
7778 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7779 | "JavaScript Object Notation\n") | |
95cbbd2a | 7780 | |
4092b06c DS |
7781 | DEFUN (show_ip_bgp_ipv4_prefix_pathtype, |
7782 | show_ip_bgp_ipv4_prefix_pathtype_cmd, | |
b05a1c8b | 7783 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
7784 | SHOW_STR |
7785 | IP_STR | |
7786 | BGP_STR | |
7787 | "Address family\n" | |
7788 | "Address Family modifier\n" | |
7789 | "Address Family modifier\n" | |
7790 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
7791 | "Display only the bestpath\n" | |
b05a1c8b DS |
7792 | "Display only multipaths\n" |
7793 | "JavaScript Object Notation\n") | |
4092b06c | 7794 | { |
db7c8528 | 7795 | u_char uj = use_json(argc, argv); |
b05a1c8b | 7796 | |
4092b06c DS |
7797 | if (strncmp (argv[0], "m", 1) == 0) |
7798 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 7799 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 7800 | else |
db7c8528 | 7801 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
7802 | else |
7803 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 7804 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 7805 | else |
db7c8528 | 7806 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
7807 | } |
7808 | ||
7809 | ALIAS (show_ip_bgp_ipv4_prefix_pathtype, | |
7810 | show_bgp_ipv4_safi_prefix_pathtype_cmd, | |
b05a1c8b | 7811 | "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath) {json}", |
4092b06c DS |
7812 | SHOW_STR |
7813 | BGP_STR | |
7814 | "Address family\n" | |
7815 | "Address Family modifier\n" | |
7816 | "Address Family modifier\n" | |
7817 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
7818 | "Display only the bestpath\n" | |
b05a1c8b DS |
7819 | "Display only multipaths\n" |
7820 | "JavaScript Object Notation\n") | |
4092b06c | 7821 | |
718e3744 | 7822 | DEFUN (show_ip_bgp_vpnv4_all_prefix, |
7823 | show_ip_bgp_vpnv4_all_prefix_cmd, | |
b05a1c8b | 7824 | "show ip bgp vpnv4 all A.B.C.D/M {json}", |
718e3744 | 7825 | SHOW_STR |
7826 | IP_STR | |
7827 | BGP_STR | |
7828 | "Display VPNv4 NLRI specific information\n" | |
7829 | "Display information about all VPNv4 NLRIs\n" | |
b05a1c8b DS |
7830 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7831 | "JavaScript Object Notation\n") | |
718e3744 | 7832 | { |
db7c8528 | 7833 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7834 | } |
7835 | ||
7836 | DEFUN (show_ip_bgp_vpnv4_rd_prefix, | |
7837 | show_ip_bgp_vpnv4_rd_prefix_cmd, | |
b05a1c8b | 7838 | "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M {json}", |
718e3744 | 7839 | SHOW_STR |
7840 | IP_STR | |
7841 | BGP_STR | |
7842 | "Display VPNv4 NLRI specific information\n" | |
7843 | "Display information for a route distinguisher\n" | |
7844 | "VPN Route Distinguisher\n" | |
b05a1c8b DS |
7845 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7846 | "JavaScript Object Notation\n") | |
718e3744 | 7847 | { |
7848 | int ret; | |
7849 | struct prefix_rd prd; | |
7850 | ||
7851 | ret = str2prefix_rd (argv[0], &prd); | |
7852 | if (! ret) | |
7853 | { | |
7854 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
7855 | return CMD_WARNING; | |
7856 | } | |
db7c8528 | 7857 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7858 | } |
7859 | ||
7860 | DEFUN (show_ip_bgp_view, | |
7861 | show_ip_bgp_view_cmd, | |
6aeb9e78 | 7862 | "show ip bgp (view|vrf) WORD {json}", |
718e3744 | 7863 | SHOW_STR |
7864 | IP_STR | |
7865 | BGP_STR | |
6aeb9e78 DS |
7866 | "BGP view\nBGP VRF\n" |
7867 | "View/VRF name\n" | |
b05a1c8b | 7868 | "JavaScript Object Notation\n") |
718e3744 | 7869 | { |
bb46e94f | 7870 | struct bgp *bgp; |
7871 | ||
7872 | /* BGP structure lookup. */ | |
6aeb9e78 | 7873 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 7874 | if (bgp == NULL) |
7875 | { | |
6aeb9e78 | 7876 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
bb46e94f | 7877 | return CMD_WARNING; |
7878 | } | |
7879 | ||
db7c8528 | 7880 | return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); |
718e3744 | 7881 | } |
7882 | ||
7883 | DEFUN (show_ip_bgp_view_route, | |
7884 | show_ip_bgp_view_route_cmd, | |
6aeb9e78 | 7885 | "show ip bgp (view|vrf) WORD A.B.C.D {json}", |
718e3744 | 7886 | SHOW_STR |
7887 | IP_STR | |
7888 | BGP_STR | |
6aeb9e78 DS |
7889 | "BGP view\nBGP VRF\n" |
7890 | "View/VRF name\n" | |
b05a1c8b DS |
7891 | "Network in the BGP routing table to display\n" |
7892 | "JavaScript Object Notation\n") | |
718e3744 | 7893 | { |
6aeb9e78 | 7894 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7895 | } |
7896 | ||
7897 | DEFUN (show_ip_bgp_view_prefix, | |
7898 | show_ip_bgp_view_prefix_cmd, | |
6aeb9e78 | 7899 | "show ip bgp (view|vrf) WORD A.B.C.D/M {json}", |
718e3744 | 7900 | SHOW_STR |
7901 | IP_STR | |
7902 | BGP_STR | |
6aeb9e78 DS |
7903 | "BGP view\nBGP VRF\n" |
7904 | "View/VRF name\n" | |
b05a1c8b DS |
7905 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
7906 | "JavaScript Object Notation\n") | |
718e3744 | 7907 | { |
6aeb9e78 | 7908 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7909 | } |
7910 | ||
7911 | #ifdef HAVE_IPV6 | |
7912 | DEFUN (show_bgp, | |
7913 | show_bgp_cmd, | |
b05a1c8b | 7914 | "show bgp {json}", |
718e3744 | 7915 | SHOW_STR |
b05a1c8b DS |
7916 | BGP_STR |
7917 | "JavaScript Object Notation\n") | |
718e3744 | 7918 | { |
5a646650 | 7919 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
db7c8528 | 7920 | NULL, use_json(argc, argv)); |
718e3744 | 7921 | } |
7922 | ||
7923 | ALIAS (show_bgp, | |
7924 | show_bgp_ipv6_cmd, | |
b05a1c8b | 7925 | "show bgp ipv6 {json}", |
718e3744 | 7926 | SHOW_STR |
7927 | BGP_STR | |
b05a1c8b DS |
7928 | "Address family\n" |
7929 | "JavaScript Object Notation\n") | |
718e3744 | 7930 | |
95cbbd2a ML |
7931 | DEFUN (show_bgp_ipv6_safi, |
7932 | show_bgp_ipv6_safi_cmd, | |
b05a1c8b | 7933 | "show bgp ipv6 (unicast|multicast) {json}", |
95cbbd2a ML |
7934 | SHOW_STR |
7935 | BGP_STR | |
7936 | "Address family\n" | |
7937 | "Address Family modifier\n" | |
47fc97cc | 7938 | "Address Family modifier\n" |
b05a1c8b | 7939 | "JavaScript Object Notation\n") |
47fc97cc | 7940 | { |
db7c8528 | 7941 | u_char uj = use_json(argc, argv); |
47fc97cc DS |
7942 | if (strncmp (argv[0], "m", 1) == 0) |
7943 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal, | |
db7c8528 | 7944 | NULL, uj); |
47fc97cc | 7945 | |
db7c8528 | 7946 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, uj); |
95cbbd2a ML |
7947 | } |
7948 | ||
47e9b292 DW |
7949 | static void |
7950 | bgp_show_ipv6_bgp_deprecate_warning (struct vty *vty) | |
7951 | { | |
7952 | vty_out (vty, "WARNING: The 'show ipv6 bgp' parse tree will be deprecated in our" | |
7953 | " next release%sPlese use 'show bgp ipv6' instead%s%s", | |
7954 | VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); | |
7955 | } | |
7956 | ||
718e3744 | 7957 | /* old command */ |
7958 | DEFUN (show_ipv6_bgp, | |
7959 | show_ipv6_bgp_cmd, | |
b05a1c8b | 7960 | "show ipv6 bgp {json}", |
718e3744 | 7961 | SHOW_STR |
7962 | IP_STR | |
b05a1c8b DS |
7963 | BGP_STR |
7964 | "JavaScript Object Notation\n") | |
718e3744 | 7965 | { |
47e9b292 | 7966 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
5a646650 | 7967 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
db7c8528 | 7968 | NULL, use_json(argc, argv)); |
718e3744 | 7969 | } |
7970 | ||
7971 | DEFUN (show_bgp_route, | |
7972 | show_bgp_route_cmd, | |
b05a1c8b | 7973 | "show bgp X:X::X:X {json}", |
718e3744 | 7974 | SHOW_STR |
7975 | BGP_STR | |
b05a1c8b DS |
7976 | "Network in the BGP routing table to display\n" |
7977 | "JavaScript Object Notation\n") | |
718e3744 | 7978 | { |
db7c8528 | 7979 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 7980 | } |
7981 | ||
7982 | ALIAS (show_bgp_route, | |
7983 | show_bgp_ipv6_route_cmd, | |
b05a1c8b | 7984 | "show bgp ipv6 X:X::X:X {json}", |
718e3744 | 7985 | SHOW_STR |
7986 | BGP_STR | |
7987 | "Address family\n" | |
b05a1c8b DS |
7988 | "Network in the BGP routing table to display\n" |
7989 | "JavaScript Object Notation\n") | |
718e3744 | 7990 | |
95cbbd2a ML |
7991 | DEFUN (show_bgp_ipv6_safi_route, |
7992 | show_bgp_ipv6_safi_route_cmd, | |
b05a1c8b | 7993 | "show bgp ipv6 (unicast|multicast) X:X::X:X {json}", |
95cbbd2a ML |
7994 | SHOW_STR |
7995 | BGP_STR | |
7996 | "Address family\n" | |
7997 | "Address Family modifier\n" | |
7998 | "Address Family modifier\n" | |
b05a1c8b DS |
7999 | "Network in the BGP routing table to display\n" |
8000 | "JavaScript Object Notation\n") | |
95cbbd2a | 8001 | { |
db7c8528 | 8002 | u_char uj = use_json(argc, argv); |
95cbbd2a | 8003 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 8004 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, uj); |
95cbbd2a | 8005 | |
db7c8528 | 8006 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, uj); |
4092b06c DS |
8007 | } |
8008 | ||
8009 | DEFUN (show_bgp_route_pathtype, | |
8010 | show_bgp_route_pathtype_cmd, | |
b05a1c8b | 8011 | "show bgp X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8012 | SHOW_STR |
8013 | BGP_STR | |
8014 | "Network in the BGP routing table to display\n" | |
8015 | "Display only the bestpath\n" | |
b05a1c8b DS |
8016 | "Display only multipaths\n" |
8017 | "JavaScript Object Notation\n") | |
4092b06c | 8018 | { |
db7c8528 | 8019 | u_char uj = use_json(argc, argv); |
4092b06c | 8020 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8021 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 8022 | else |
db7c8528 | 8023 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8024 | } |
8025 | ||
8026 | ALIAS (show_bgp_route_pathtype, | |
8027 | show_bgp_ipv6_route_pathtype_cmd, | |
b05a1c8b | 8028 | "show bgp ipv6 X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8029 | SHOW_STR |
8030 | BGP_STR | |
8031 | "Address family\n" | |
8032 | "Network in the BGP routing table to display\n" | |
8033 | "Display only the bestpath\n" | |
b05a1c8b DS |
8034 | "Display only multipaths\n" |
8035 | "JavaScript Object Notation\n") | |
4092b06c DS |
8036 | |
8037 | DEFUN (show_bgp_ipv6_safi_route_pathtype, | |
8038 | show_bgp_ipv6_safi_route_pathtype_cmd, | |
b05a1c8b | 8039 | "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath) {json}", |
4092b06c DS |
8040 | SHOW_STR |
8041 | BGP_STR | |
8042 | "Address family\n" | |
8043 | "Address Family modifier\n" | |
8044 | "Address Family modifier\n" | |
8045 | "Network in the BGP routing table to display\n" | |
8046 | "Display only the bestpath\n" | |
b05a1c8b DS |
8047 | "Display only multipaths\n" |
8048 | "JavaScript Object Notation\n") | |
4092b06c | 8049 | { |
db7c8528 | 8050 | u_char uj = use_json(argc, argv); |
4092b06c DS |
8051 | if (strncmp (argv[0], "m", 1) == 0) |
8052 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 8053 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 8054 | else |
db7c8528 | 8055 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8056 | else |
8057 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 8058 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH, uj); |
4092b06c | 8059 | else |
db7c8528 | 8060 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH, uj); |
95cbbd2a ML |
8061 | } |
8062 | ||
718e3744 | 8063 | /* old command */ |
8064 | DEFUN (show_ipv6_bgp_route, | |
8065 | show_ipv6_bgp_route_cmd, | |
b05a1c8b | 8066 | "show ipv6 bgp X:X::X:X {json}", |
718e3744 | 8067 | SHOW_STR |
8068 | IP_STR | |
8069 | BGP_STR | |
b05a1c8b DS |
8070 | "Network in the BGP routing table to display\n" |
8071 | "JavaScript Object Notation\n") | |
718e3744 | 8072 | { |
47e9b292 | 8073 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8074 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8075 | } |
8076 | ||
8077 | DEFUN (show_bgp_prefix, | |
8078 | show_bgp_prefix_cmd, | |
b05a1c8b | 8079 | "show bgp X:X::X:X/M {json}", |
718e3744 | 8080 | SHOW_STR |
8081 | BGP_STR | |
b05a1c8b DS |
8082 | "IPv6 prefix <network>/<length>\n" |
8083 | "JavaScript Object Notation\n") | |
718e3744 | 8084 | { |
db7c8528 | 8085 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8086 | } |
8087 | ||
8088 | ALIAS (show_bgp_prefix, | |
8089 | show_bgp_ipv6_prefix_cmd, | |
b05a1c8b | 8090 | "show bgp ipv6 X:X::X:X/M {json}", |
718e3744 | 8091 | SHOW_STR |
8092 | BGP_STR | |
8093 | "Address family\n" | |
b05a1c8b DS |
8094 | "IPv6 prefix <network>/<length>\n" |
8095 | "JavaScript Object Notation\n") | |
718e3744 | 8096 | |
95cbbd2a ML |
8097 | DEFUN (show_bgp_ipv6_safi_prefix, |
8098 | show_bgp_ipv6_safi_prefix_cmd, | |
b05a1c8b | 8099 | "show bgp ipv6 (unicast|multicast) X:X::X:X/M {json}", |
95cbbd2a ML |
8100 | SHOW_STR |
8101 | BGP_STR | |
8102 | "Address family\n" | |
8103 | "Address Family modifier\n" | |
8104 | "Address Family modifier\n" | |
b05a1c8b DS |
8105 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8106 | "JavaScript Object Notation\n") | |
95cbbd2a | 8107 | { |
db7c8528 | 8108 | u_char uj = use_json(argc, argv); |
95cbbd2a | 8109 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 8110 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, uj); |
95cbbd2a | 8111 | |
db7c8528 | 8112 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, uj); |
4092b06c DS |
8113 | } |
8114 | ||
8115 | DEFUN (show_bgp_prefix_pathtype, | |
8116 | show_bgp_prefix_pathtype_cmd, | |
b05a1c8b | 8117 | "show bgp X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8118 | SHOW_STR |
8119 | BGP_STR | |
8120 | "IPv6 prefix <network>/<length>\n" | |
8121 | "Display only the bestpath\n" | |
b05a1c8b DS |
8122 | "Display only multipaths\n" |
8123 | "JavaScript Object Notation\n") | |
4092b06c | 8124 | { |
db7c8528 | 8125 | u_char uj = use_json(argc, argv); |
4092b06c | 8126 | if (strncmp (argv[1], "b", 1) == 0) |
db7c8528 | 8127 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 8128 | else |
db7c8528 | 8129 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8130 | } |
8131 | ||
8132 | ALIAS (show_bgp_prefix_pathtype, | |
8133 | show_bgp_ipv6_prefix_pathtype_cmd, | |
b05a1c8b | 8134 | "show bgp ipv6 X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8135 | SHOW_STR |
8136 | BGP_STR | |
8137 | "Address family\n" | |
8138 | "IPv6 prefix <network>/<length>\n" | |
8139 | "Display only the bestpath\n" | |
b05a1c8b DS |
8140 | "Display only multipaths\n" |
8141 | "JavaScript Object Notation\n") | |
4092b06c DS |
8142 | |
8143 | DEFUN (show_bgp_ipv6_safi_prefix_pathtype, | |
8144 | show_bgp_ipv6_safi_prefix_pathtype_cmd, | |
b05a1c8b | 8145 | "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath) {json}", |
4092b06c DS |
8146 | SHOW_STR |
8147 | BGP_STR | |
8148 | "Address family\n" | |
8149 | "Address Family modifier\n" | |
8150 | "Address Family modifier\n" | |
8151 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" | |
8152 | "Display only the bestpath\n" | |
b05a1c8b DS |
8153 | "Display only multipaths\n" |
8154 | "JavaScript Object Notation\n") | |
4092b06c | 8155 | { |
db7c8528 | 8156 | u_char uj = use_json(argc, argv); |
4092b06c DS |
8157 | if (strncmp (argv[0], "m", 1) == 0) |
8158 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 8159 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 8160 | else |
db7c8528 | 8161 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
4092b06c DS |
8162 | else |
8163 | if (strncmp (argv[2], "b", 1) == 0) | |
db7c8528 | 8164 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH, uj); |
4092b06c | 8165 | else |
db7c8528 | 8166 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH, uj); |
95cbbd2a ML |
8167 | } |
8168 | ||
718e3744 | 8169 | /* old command */ |
8170 | DEFUN (show_ipv6_bgp_prefix, | |
8171 | show_ipv6_bgp_prefix_cmd, | |
b05a1c8b | 8172 | "show ipv6 bgp X:X::X:X/M {json}", |
718e3744 | 8173 | SHOW_STR |
8174 | IP_STR | |
8175 | BGP_STR | |
b05a1c8b DS |
8176 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8177 | "JavaScript Object Notation\n") | |
718e3744 | 8178 | { |
47e9b292 | 8179 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8180 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8181 | } |
8182 | ||
bb46e94f | 8183 | DEFUN (show_bgp_view, |
8184 | show_bgp_view_cmd, | |
6aeb9e78 | 8185 | "show bgp (view|vrf) WORD {json}", |
bb46e94f | 8186 | SHOW_STR |
8187 | BGP_STR | |
6aeb9e78 DS |
8188 | "BGP view\nBGP VRF\n" |
8189 | "View/VRF name\n" | |
b05a1c8b | 8190 | "JavaScript Object Notation\n") |
bb46e94f | 8191 | { |
8192 | struct bgp *bgp; | |
8193 | ||
8194 | /* BGP structure lookup. */ | |
6aeb9e78 | 8195 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 8196 | if (bgp == NULL) |
db7c8528 | 8197 | { |
6aeb9e78 | 8198 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
db7c8528 DS |
8199 | return CMD_WARNING; |
8200 | } | |
8201 | ||
8202 | return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL, use_json(argc, argv)); | |
bb46e94f | 8203 | } |
8204 | ||
8205 | ALIAS (show_bgp_view, | |
8206 | show_bgp_view_ipv6_cmd, | |
6aeb9e78 | 8207 | "show bgp (view|vrf) WORD ipv6 {json}", |
bb46e94f | 8208 | SHOW_STR |
8209 | BGP_STR | |
6aeb9e78 DS |
8210 | "BGP view\nBGP VRF\n" |
8211 | "View/VRF name\n" | |
b05a1c8b DS |
8212 | "Address family\n" |
8213 | "JavaScript Object Notation\n") | |
bb46e94f | 8214 | |
8215 | DEFUN (show_bgp_view_route, | |
8216 | show_bgp_view_route_cmd, | |
6aeb9e78 | 8217 | "show bgp (view|vrf) WORD X:X::X:X {json}", |
bb46e94f | 8218 | SHOW_STR |
8219 | BGP_STR | |
6aeb9e78 DS |
8220 | "BGP view\nBGP VRF\n" |
8221 | "View/VRF name\n" | |
b05a1c8b DS |
8222 | "Network in the BGP routing table to display\n" |
8223 | "JavaScript Object Notation\n") | |
bb46e94f | 8224 | { |
6aeb9e78 | 8225 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
bb46e94f | 8226 | } |
8227 | ||
8228 | ALIAS (show_bgp_view_route, | |
8229 | show_bgp_view_ipv6_route_cmd, | |
6aeb9e78 | 8230 | "show bgp (view|vrf) WORD ipv6 X:X::X:X {json}", |
bb46e94f | 8231 | SHOW_STR |
8232 | BGP_STR | |
6aeb9e78 DS |
8233 | "BGP view\nBGP VRF\n" |
8234 | "View/VRF name\n" | |
bb46e94f | 8235 | "Address family\n" |
b05a1c8b DS |
8236 | "Network in the BGP routing table to display\n" |
8237 | "JavaScript Object Notation\n") | |
bb46e94f | 8238 | |
8239 | DEFUN (show_bgp_view_prefix, | |
8240 | show_bgp_view_prefix_cmd, | |
6aeb9e78 | 8241 | "show bgp (view|vrf) WORD X:X::X:X/M {json}", |
bb46e94f | 8242 | SHOW_STR |
8243 | BGP_STR | |
6aeb9e78 DS |
8244 | "BGP view\nBGP VRF\n" |
8245 | "View/VRF name\n" | |
b05a1c8b DS |
8246 | "IPv6 prefix <network>/<length>\n" |
8247 | "JavaScript Object Notation\n") | |
bb46e94f | 8248 | { |
6aeb9e78 | 8249 | return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
bb46e94f | 8250 | } |
8251 | ||
8252 | ALIAS (show_bgp_view_prefix, | |
8253 | show_bgp_view_ipv6_prefix_cmd, | |
6aeb9e78 | 8254 | "show bgp (view|vrf) WORD ipv6 X:X::X:X/M {json}", |
bb46e94f | 8255 | SHOW_STR |
8256 | BGP_STR | |
6aeb9e78 DS |
8257 | "BGP view\nBGP VRF\n" |
8258 | "View/VRF name\n" | |
bb46e94f | 8259 | "Address family\n" |
b05a1c8b DS |
8260 | "IPv6 prefix <network>/<length>\n" |
8261 | "JavaScript Object Notation\n") | |
bb46e94f | 8262 | |
718e3744 | 8263 | /* old command */ |
8264 | DEFUN (show_ipv6_mbgp, | |
8265 | show_ipv6_mbgp_cmd, | |
b05a1c8b | 8266 | "show ipv6 mbgp {json}", |
718e3744 | 8267 | SHOW_STR |
8268 | IP_STR | |
b05a1c8b DS |
8269 | MBGP_STR |
8270 | "JavaScript Object Notation\n") | |
718e3744 | 8271 | { |
47e9b292 | 8272 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
5a646650 | 8273 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal, |
db7c8528 | 8274 | NULL, use_json(argc, argv)); |
718e3744 | 8275 | } |
8276 | ||
8277 | /* old command */ | |
8278 | DEFUN (show_ipv6_mbgp_route, | |
8279 | show_ipv6_mbgp_route_cmd, | |
b05a1c8b | 8280 | "show ipv6 mbgp X:X::X:X {json}", |
718e3744 | 8281 | SHOW_STR |
8282 | IP_STR | |
8283 | MBGP_STR | |
b05a1c8b DS |
8284 | "Network in the MBGP routing table to display\n" |
8285 | "JavaScript Object Notation\n") | |
718e3744 | 8286 | { |
47e9b292 | 8287 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8288 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8289 | } |
8290 | ||
8291 | /* old command */ | |
8292 | DEFUN (show_ipv6_mbgp_prefix, | |
8293 | show_ipv6_mbgp_prefix_cmd, | |
b05a1c8b | 8294 | "show ipv6 mbgp X:X::X:X/M {json}", |
718e3744 | 8295 | SHOW_STR |
8296 | IP_STR | |
8297 | MBGP_STR | |
b05a1c8b DS |
8298 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
8299 | "JavaScript Object Notation\n") | |
718e3744 | 8300 | { |
47e9b292 | 8301 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 8302 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv)); |
718e3744 | 8303 | } |
8304 | #endif | |
6b0655a2 | 8305 | |
718e3744 | 8306 | |
94f2b392 | 8307 | static int |
fd79ac91 | 8308 | bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi, |
718e3744 | 8309 | safi_t safi, enum bgp_show_type type) |
8310 | { | |
8311 | int i; | |
8312 | struct buffer *b; | |
8313 | char *regstr; | |
8314 | int first; | |
8315 | regex_t *regex; | |
5a646650 | 8316 | int rc; |
718e3744 | 8317 | |
8318 | first = 0; | |
8319 | b = buffer_new (1024); | |
8320 | for (i = 0; i < argc; i++) | |
8321 | { | |
8322 | if (first) | |
8323 | buffer_putc (b, ' '); | |
8324 | else | |
8325 | { | |
8326 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) | |
8327 | continue; | |
8328 | first = 1; | |
8329 | } | |
8330 | ||
8331 | buffer_putstr (b, argv[i]); | |
8332 | } | |
8333 | buffer_putc (b, '\0'); | |
8334 | ||
8335 | regstr = buffer_getstr (b); | |
8336 | buffer_free (b); | |
8337 | ||
8338 | regex = bgp_regcomp (regstr); | |
3b8b1855 | 8339 | XFREE(MTYPE_TMP, regstr); |
718e3744 | 8340 | if (! regex) |
8341 | { | |
8342 | vty_out (vty, "Can't compile regexp %s%s", argv[0], | |
8343 | VTY_NEWLINE); | |
8344 | return CMD_WARNING; | |
8345 | } | |
8346 | ||
b05a1c8b | 8347 | rc = bgp_show (vty, NULL, afi, safi, type, regex, 0); |
5a646650 | 8348 | bgp_regex_free (regex); |
8349 | return rc; | |
718e3744 | 8350 | } |
8351 | ||
8352 | DEFUN (show_ip_bgp_regexp, | |
8353 | show_ip_bgp_regexp_cmd, | |
8354 | "show ip bgp regexp .LINE", | |
8355 | SHOW_STR | |
8356 | IP_STR | |
8357 | BGP_STR | |
8358 | "Display routes matching the AS path regular expression\n" | |
8359 | "A regular-expression to match the BGP AS paths\n") | |
8360 | { | |
8361 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, | |
8362 | bgp_show_type_regexp); | |
8363 | } | |
8364 | ||
8365 | DEFUN (show_ip_bgp_flap_regexp, | |
8366 | show_ip_bgp_flap_regexp_cmd, | |
8367 | "show ip bgp flap-statistics regexp .LINE", | |
8368 | SHOW_STR | |
8369 | IP_STR | |
8370 | BGP_STR | |
8371 | "Display flap statistics of routes\n" | |
8372 | "Display routes matching the AS path regular expression\n" | |
8373 | "A regular-expression to match the BGP AS paths\n") | |
8374 | { | |
8375 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, | |
8376 | bgp_show_type_flap_regexp); | |
8377 | } | |
8378 | ||
8379 | DEFUN (show_ip_bgp_ipv4_regexp, | |
8380 | show_ip_bgp_ipv4_regexp_cmd, | |
8381 | "show ip bgp ipv4 (unicast|multicast) regexp .LINE", | |
8382 | SHOW_STR | |
8383 | IP_STR | |
8384 | BGP_STR | |
8385 | "Address family\n" | |
8386 | "Address Family modifier\n" | |
8387 | "Address Family modifier\n" | |
8388 | "Display routes matching the AS path regular expression\n" | |
8389 | "A regular-expression to match the BGP AS paths\n") | |
8390 | { | |
8391 | if (strncmp (argv[0], "m", 1) == 0) | |
8392 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST, | |
8393 | bgp_show_type_regexp); | |
8394 | ||
8395 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, | |
8396 | bgp_show_type_regexp); | |
8397 | } | |
8398 | ||
8399 | #ifdef HAVE_IPV6 | |
8400 | DEFUN (show_bgp_regexp, | |
8401 | show_bgp_regexp_cmd, | |
8402 | "show bgp regexp .LINE", | |
8403 | SHOW_STR | |
8404 | BGP_STR | |
8405 | "Display routes matching the AS path regular expression\n" | |
8406 | "A regular-expression to match the BGP AS paths\n") | |
8407 | { | |
8408 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, | |
8409 | bgp_show_type_regexp); | |
8410 | } | |
8411 | ||
8412 | ALIAS (show_bgp_regexp, | |
8413 | show_bgp_ipv6_regexp_cmd, | |
8414 | "show bgp ipv6 regexp .LINE", | |
8415 | SHOW_STR | |
8416 | BGP_STR | |
8417 | "Address family\n" | |
8418 | "Display routes matching the AS path regular expression\n" | |
8419 | "A regular-expression to match the BGP AS paths\n") | |
8420 | ||
8421 | /* old command */ | |
8422 | DEFUN (show_ipv6_bgp_regexp, | |
8423 | show_ipv6_bgp_regexp_cmd, | |
8424 | "show ipv6 bgp regexp .LINE", | |
8425 | SHOW_STR | |
8426 | IP_STR | |
8427 | BGP_STR | |
8428 | "Display routes matching the AS path regular expression\n" | |
8429 | "A regular-expression to match the BGP AS paths\n") | |
8430 | { | |
47e9b292 | 8431 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8432 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, |
8433 | bgp_show_type_regexp); | |
8434 | } | |
8435 | ||
8436 | /* old command */ | |
8437 | DEFUN (show_ipv6_mbgp_regexp, | |
8438 | show_ipv6_mbgp_regexp_cmd, | |
8439 | "show ipv6 mbgp regexp .LINE", | |
8440 | SHOW_STR | |
8441 | IP_STR | |
8442 | BGP_STR | |
8443 | "Display routes matching the AS path regular expression\n" | |
8444 | "A regular-expression to match the MBGP AS paths\n") | |
8445 | { | |
47e9b292 | 8446 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8447 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST, |
8448 | bgp_show_type_regexp); | |
8449 | } | |
8450 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 8451 | |
94f2b392 | 8452 | static int |
fd79ac91 | 8453 | bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi, |
718e3744 | 8454 | safi_t safi, enum bgp_show_type type) |
8455 | { | |
8456 | struct prefix_list *plist; | |
8457 | ||
8458 | plist = prefix_list_lookup (afi, prefix_list_str); | |
8459 | if (plist == NULL) | |
8460 | { | |
8461 | vty_out (vty, "%% %s is not a valid prefix-list name%s", | |
8462 | prefix_list_str, VTY_NEWLINE); | |
8463 | return CMD_WARNING; | |
8464 | } | |
8465 | ||
b05a1c8b | 8466 | return bgp_show (vty, NULL, afi, safi, type, plist, 0); |
718e3744 | 8467 | } |
8468 | ||
8469 | DEFUN (show_ip_bgp_prefix_list, | |
8470 | show_ip_bgp_prefix_list_cmd, | |
8471 | "show ip bgp prefix-list WORD", | |
8472 | SHOW_STR | |
8473 | IP_STR | |
8474 | BGP_STR | |
8475 | "Display routes conforming to the prefix-list\n" | |
8476 | "IP prefix-list name\n") | |
8477 | { | |
8478 | return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8479 | bgp_show_type_prefix_list); | |
8480 | } | |
8481 | ||
8482 | DEFUN (show_ip_bgp_flap_prefix_list, | |
8483 | show_ip_bgp_flap_prefix_list_cmd, | |
8484 | "show ip bgp flap-statistics prefix-list WORD", | |
8485 | SHOW_STR | |
8486 | IP_STR | |
8487 | BGP_STR | |
8488 | "Display flap statistics of routes\n" | |
8489 | "Display routes conforming to the prefix-list\n" | |
8490 | "IP prefix-list name\n") | |
8491 | { | |
8492 | return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8493 | bgp_show_type_flap_prefix_list); | |
8494 | } | |
8495 | ||
8496 | DEFUN (show_ip_bgp_ipv4_prefix_list, | |
8497 | show_ip_bgp_ipv4_prefix_list_cmd, | |
8498 | "show ip bgp ipv4 (unicast|multicast) prefix-list WORD", | |
8499 | SHOW_STR | |
8500 | IP_STR | |
8501 | BGP_STR | |
8502 | "Address family\n" | |
8503 | "Address Family modifier\n" | |
8504 | "Address Family modifier\n" | |
8505 | "Display routes conforming to the prefix-list\n" | |
8506 | "IP prefix-list name\n") | |
8507 | { | |
8508 | if (strncmp (argv[0], "m", 1) == 0) | |
8509 | return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST, | |
8510 | bgp_show_type_prefix_list); | |
8511 | ||
8512 | return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST, | |
8513 | bgp_show_type_prefix_list); | |
8514 | } | |
8515 | ||
8516 | #ifdef HAVE_IPV6 | |
8517 | DEFUN (show_bgp_prefix_list, | |
8518 | show_bgp_prefix_list_cmd, | |
8519 | "show bgp prefix-list WORD", | |
8520 | SHOW_STR | |
8521 | BGP_STR | |
8522 | "Display routes conforming to the prefix-list\n" | |
8523 | "IPv6 prefix-list name\n") | |
8524 | { | |
8525 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
8526 | bgp_show_type_prefix_list); | |
8527 | } | |
8528 | ||
8529 | ALIAS (show_bgp_prefix_list, | |
8530 | show_bgp_ipv6_prefix_list_cmd, | |
8531 | "show bgp ipv6 prefix-list WORD", | |
8532 | SHOW_STR | |
8533 | BGP_STR | |
8534 | "Address family\n" | |
8535 | "Display routes conforming to the prefix-list\n" | |
8536 | "IPv6 prefix-list name\n") | |
8537 | ||
8538 | /* old command */ | |
8539 | DEFUN (show_ipv6_bgp_prefix_list, | |
8540 | show_ipv6_bgp_prefix_list_cmd, | |
8541 | "show ipv6 bgp prefix-list WORD", | |
8542 | SHOW_STR | |
8543 | IPV6_STR | |
8544 | BGP_STR | |
8545 | "Display routes matching the prefix-list\n" | |
8546 | "IPv6 prefix-list name\n") | |
8547 | { | |
47e9b292 | 8548 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8549 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
8550 | bgp_show_type_prefix_list); | |
8551 | } | |
8552 | ||
8553 | /* old command */ | |
8554 | DEFUN (show_ipv6_mbgp_prefix_list, | |
8555 | show_ipv6_mbgp_prefix_list_cmd, | |
8556 | "show ipv6 mbgp prefix-list WORD", | |
8557 | SHOW_STR | |
8558 | IPV6_STR | |
8559 | MBGP_STR | |
8560 | "Display routes matching the prefix-list\n" | |
8561 | "IPv6 prefix-list name\n") | |
8562 | { | |
47e9b292 | 8563 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8564 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
8565 | bgp_show_type_prefix_list); | |
8566 | } | |
8567 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 8568 | |
94f2b392 | 8569 | static int |
fd79ac91 | 8570 | bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi, |
718e3744 | 8571 | safi_t safi, enum bgp_show_type type) |
8572 | { | |
8573 | struct as_list *as_list; | |
8574 | ||
8575 | as_list = as_list_lookup (filter); | |
8576 | if (as_list == NULL) | |
8577 | { | |
8578 | vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE); | |
8579 | return CMD_WARNING; | |
8580 | } | |
8581 | ||
b05a1c8b | 8582 | return bgp_show (vty, NULL, afi, safi, type, as_list, 0); |
718e3744 | 8583 | } |
8584 | ||
8585 | DEFUN (show_ip_bgp_filter_list, | |
8586 | show_ip_bgp_filter_list_cmd, | |
8587 | "show ip bgp filter-list WORD", | |
8588 | SHOW_STR | |
8589 | IP_STR | |
8590 | BGP_STR | |
8591 | "Display routes conforming to the filter-list\n" | |
8592 | "Regular expression access list name\n") | |
8593 | { | |
8594 | return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8595 | bgp_show_type_filter_list); | |
8596 | } | |
8597 | ||
8598 | DEFUN (show_ip_bgp_flap_filter_list, | |
8599 | show_ip_bgp_flap_filter_list_cmd, | |
8600 | "show ip bgp flap-statistics filter-list WORD", | |
8601 | SHOW_STR | |
8602 | IP_STR | |
8603 | BGP_STR | |
8604 | "Display flap statistics of routes\n" | |
8605 | "Display routes conforming to the filter-list\n" | |
8606 | "Regular expression access list name\n") | |
8607 | { | |
8608 | return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8609 | bgp_show_type_flap_filter_list); | |
8610 | } | |
8611 | ||
8612 | DEFUN (show_ip_bgp_ipv4_filter_list, | |
8613 | show_ip_bgp_ipv4_filter_list_cmd, | |
8614 | "show ip bgp ipv4 (unicast|multicast) filter-list WORD", | |
8615 | SHOW_STR | |
8616 | IP_STR | |
8617 | BGP_STR | |
8618 | "Address family\n" | |
8619 | "Address Family modifier\n" | |
8620 | "Address Family modifier\n" | |
8621 | "Display routes conforming to the filter-list\n" | |
8622 | "Regular expression access list name\n") | |
8623 | { | |
8624 | if (strncmp (argv[0], "m", 1) == 0) | |
8625 | return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST, | |
8626 | bgp_show_type_filter_list); | |
8627 | ||
8628 | return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST, | |
8629 | bgp_show_type_filter_list); | |
8630 | } | |
8631 | ||
8632 | #ifdef HAVE_IPV6 | |
8633 | DEFUN (show_bgp_filter_list, | |
8634 | show_bgp_filter_list_cmd, | |
8635 | "show bgp filter-list WORD", | |
8636 | SHOW_STR | |
8637 | BGP_STR | |
8638 | "Display routes conforming to the filter-list\n" | |
8639 | "Regular expression access list name\n") | |
8640 | { | |
8641 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
8642 | bgp_show_type_filter_list); | |
8643 | } | |
8644 | ||
8645 | ALIAS (show_bgp_filter_list, | |
8646 | show_bgp_ipv6_filter_list_cmd, | |
8647 | "show bgp ipv6 filter-list WORD", | |
8648 | SHOW_STR | |
8649 | BGP_STR | |
8650 | "Address family\n" | |
8651 | "Display routes conforming to the filter-list\n" | |
8652 | "Regular expression access list name\n") | |
8653 | ||
8654 | /* old command */ | |
8655 | DEFUN (show_ipv6_bgp_filter_list, | |
8656 | show_ipv6_bgp_filter_list_cmd, | |
8657 | "show ipv6 bgp filter-list WORD", | |
8658 | SHOW_STR | |
8659 | IPV6_STR | |
8660 | BGP_STR | |
8661 | "Display routes conforming to the filter-list\n" | |
8662 | "Regular expression access list name\n") | |
8663 | { | |
47e9b292 | 8664 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8665 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
8666 | bgp_show_type_filter_list); | |
8667 | } | |
8668 | ||
8669 | /* old command */ | |
8670 | DEFUN (show_ipv6_mbgp_filter_list, | |
8671 | show_ipv6_mbgp_filter_list_cmd, | |
8672 | "show ipv6 mbgp filter-list WORD", | |
8673 | SHOW_STR | |
8674 | IPV6_STR | |
8675 | MBGP_STR | |
8676 | "Display routes conforming to the filter-list\n" | |
8677 | "Regular expression access list name\n") | |
8678 | { | |
47e9b292 | 8679 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8680 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
8681 | bgp_show_type_filter_list); | |
8682 | } | |
8683 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 8684 | |
94f2b392 | 8685 | static int |
fd79ac91 | 8686 | bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi, |
718e3744 | 8687 | safi_t safi, enum bgp_show_type type) |
8688 | { | |
8689 | struct route_map *rmap; | |
8690 | ||
8691 | rmap = route_map_lookup_by_name (rmap_str); | |
8692 | if (! rmap) | |
8693 | { | |
8694 | vty_out (vty, "%% %s is not a valid route-map name%s", | |
8695 | rmap_str, VTY_NEWLINE); | |
8696 | return CMD_WARNING; | |
8697 | } | |
8698 | ||
b05a1c8b | 8699 | return bgp_show (vty, NULL, afi, safi, type, rmap, 0); |
718e3744 | 8700 | } |
8701 | ||
8702 | DEFUN (show_ip_bgp_route_map, | |
8703 | show_ip_bgp_route_map_cmd, | |
8704 | "show ip bgp route-map WORD", | |
8705 | SHOW_STR | |
8706 | IP_STR | |
8707 | BGP_STR | |
8708 | "Display routes matching the route-map\n" | |
8709 | "A route-map to match on\n") | |
8710 | { | |
8711 | return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8712 | bgp_show_type_route_map); | |
8713 | } | |
8714 | ||
8715 | DEFUN (show_ip_bgp_flap_route_map, | |
8716 | show_ip_bgp_flap_route_map_cmd, | |
8717 | "show ip bgp flap-statistics route-map WORD", | |
8718 | SHOW_STR | |
8719 | IP_STR | |
8720 | BGP_STR | |
8721 | "Display flap statistics of routes\n" | |
8722 | "Display routes matching the route-map\n" | |
8723 | "A route-map to match on\n") | |
8724 | { | |
8725 | return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
8726 | bgp_show_type_flap_route_map); | |
8727 | } | |
8728 | ||
8729 | DEFUN (show_ip_bgp_ipv4_route_map, | |
8730 | show_ip_bgp_ipv4_route_map_cmd, | |
8731 | "show ip bgp ipv4 (unicast|multicast) route-map WORD", | |
8732 | SHOW_STR | |
8733 | IP_STR | |
8734 | BGP_STR | |
8735 | "Address family\n" | |
8736 | "Address Family modifier\n" | |
8737 | "Address Family modifier\n" | |
8738 | "Display routes matching the route-map\n" | |
8739 | "A route-map to match on\n") | |
8740 | { | |
8741 | if (strncmp (argv[0], "m", 1) == 0) | |
8742 | return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST, | |
8743 | bgp_show_type_route_map); | |
8744 | ||
8745 | return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST, | |
8746 | bgp_show_type_route_map); | |
8747 | } | |
8748 | ||
8749 | DEFUN (show_bgp_route_map, | |
8750 | show_bgp_route_map_cmd, | |
8751 | "show bgp route-map WORD", | |
8752 | SHOW_STR | |
8753 | BGP_STR | |
8754 | "Display routes matching the route-map\n" | |
8755 | "A route-map to match on\n") | |
8756 | { | |
8757 | return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
8758 | bgp_show_type_route_map); | |
8759 | } | |
8760 | ||
8761 | ALIAS (show_bgp_route_map, | |
8762 | show_bgp_ipv6_route_map_cmd, | |
8763 | "show bgp ipv6 route-map WORD", | |
8764 | SHOW_STR | |
8765 | BGP_STR | |
8766 | "Address family\n" | |
8767 | "Display routes matching the route-map\n" | |
8768 | "A route-map to match on\n") | |
6b0655a2 | 8769 | |
718e3744 | 8770 | DEFUN (show_ip_bgp_cidr_only, |
8771 | show_ip_bgp_cidr_only_cmd, | |
8772 | "show ip bgp cidr-only", | |
8773 | SHOW_STR | |
8774 | IP_STR | |
8775 | BGP_STR | |
8776 | "Display only routes with non-natural netmasks\n") | |
8777 | { | |
8778 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 8779 | bgp_show_type_cidr_only, NULL, 0); |
718e3744 | 8780 | } |
8781 | ||
8782 | DEFUN (show_ip_bgp_flap_cidr_only, | |
8783 | show_ip_bgp_flap_cidr_only_cmd, | |
8784 | "show ip bgp flap-statistics cidr-only", | |
8785 | SHOW_STR | |
8786 | IP_STR | |
8787 | BGP_STR | |
8788 | "Display flap statistics of routes\n" | |
8789 | "Display only routes with non-natural netmasks\n") | |
8790 | { | |
8791 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 8792 | bgp_show_type_flap_cidr_only, NULL, 0); |
718e3744 | 8793 | } |
8794 | ||
8795 | DEFUN (show_ip_bgp_ipv4_cidr_only, | |
8796 | show_ip_bgp_ipv4_cidr_only_cmd, | |
8797 | "show ip bgp ipv4 (unicast|multicast) cidr-only", | |
8798 | SHOW_STR | |
8799 | IP_STR | |
8800 | BGP_STR | |
8801 | "Address family\n" | |
8802 | "Address Family modifier\n" | |
8803 | "Address Family modifier\n" | |
8804 | "Display only routes with non-natural netmasks\n") | |
8805 | { | |
8806 | if (strncmp (argv[0], "m", 1) == 0) | |
8807 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, | |
b05a1c8b | 8808 | bgp_show_type_cidr_only, NULL, 0); |
718e3744 | 8809 | |
8810 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 8811 | bgp_show_type_cidr_only, NULL, 0); |
718e3744 | 8812 | } |
6b0655a2 | 8813 | |
718e3744 | 8814 | DEFUN (show_ip_bgp_community_all, |
8815 | show_ip_bgp_community_all_cmd, | |
8816 | "show ip bgp community", | |
8817 | SHOW_STR | |
8818 | IP_STR | |
8819 | BGP_STR | |
8820 | "Display routes matching the communities\n") | |
8821 | { | |
8822 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 8823 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8824 | } |
8825 | ||
8826 | DEFUN (show_ip_bgp_ipv4_community_all, | |
8827 | show_ip_bgp_ipv4_community_all_cmd, | |
8828 | "show ip bgp ipv4 (unicast|multicast) community", | |
8829 | SHOW_STR | |
8830 | IP_STR | |
8831 | BGP_STR | |
8832 | "Address family\n" | |
8833 | "Address Family modifier\n" | |
8834 | "Address Family modifier\n" | |
8835 | "Display routes matching the communities\n") | |
8836 | { | |
8837 | if (strncmp (argv[0], "m", 1) == 0) | |
8838 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, | |
b05a1c8b | 8839 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8840 | |
8841 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, | |
b05a1c8b | 8842 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8843 | } |
8844 | ||
8845 | #ifdef HAVE_IPV6 | |
8846 | DEFUN (show_bgp_community_all, | |
8847 | show_bgp_community_all_cmd, | |
8848 | "show bgp community", | |
8849 | SHOW_STR | |
8850 | BGP_STR | |
8851 | "Display routes matching the communities\n") | |
8852 | { | |
8853 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, | |
b05a1c8b | 8854 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8855 | } |
8856 | ||
8857 | ALIAS (show_bgp_community_all, | |
8858 | show_bgp_ipv6_community_all_cmd, | |
8859 | "show bgp ipv6 community", | |
8860 | SHOW_STR | |
8861 | BGP_STR | |
8862 | "Address family\n" | |
8863 | "Display routes matching the communities\n") | |
8864 | ||
8865 | /* old command */ | |
8866 | DEFUN (show_ipv6_bgp_community_all, | |
8867 | show_ipv6_bgp_community_all_cmd, | |
8868 | "show ipv6 bgp community", | |
8869 | SHOW_STR | |
8870 | IPV6_STR | |
8871 | BGP_STR | |
8872 | "Display routes matching the communities\n") | |
8873 | { | |
47e9b292 | 8874 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8875 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, |
b05a1c8b | 8876 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8877 | } |
8878 | ||
8879 | /* old command */ | |
8880 | DEFUN (show_ipv6_mbgp_community_all, | |
8881 | show_ipv6_mbgp_community_all_cmd, | |
8882 | "show ipv6 mbgp community", | |
8883 | SHOW_STR | |
8884 | IPV6_STR | |
8885 | MBGP_STR | |
8886 | "Display routes matching the communities\n") | |
8887 | { | |
47e9b292 | 8888 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 8889 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, |
b05a1c8b | 8890 | bgp_show_type_community_all, NULL, 0); |
718e3744 | 8891 | } |
8892 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 8893 | |
94f2b392 | 8894 | static int |
95cbbd2a ML |
8895 | bgp_show_community (struct vty *vty, const char *view_name, int argc, |
8896 | const char **argv, int exact, afi_t afi, safi_t safi) | |
718e3744 | 8897 | { |
8898 | struct community *com; | |
8899 | struct buffer *b; | |
95cbbd2a | 8900 | struct bgp *bgp; |
718e3744 | 8901 | int i; |
8902 | char *str; | |
8903 | int first = 0; | |
8904 | ||
95cbbd2a ML |
8905 | /* BGP structure lookup */ |
8906 | if (view_name) | |
8907 | { | |
8908 | bgp = bgp_lookup_by_name (view_name); | |
8909 | if (bgp == NULL) | |
8910 | { | |
6aeb9e78 | 8911 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
95cbbd2a ML |
8912 | return CMD_WARNING; |
8913 | } | |
8914 | } | |
8915 | else | |
8916 | { | |
8917 | bgp = bgp_get_default (); | |
8918 | if (bgp == NULL) | |
8919 | { | |
8920 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
8921 | return CMD_WARNING; | |
8922 | } | |
8923 | } | |
8924 | ||
718e3744 | 8925 | b = buffer_new (1024); |
8926 | for (i = 0; i < argc; i++) | |
8927 | { | |
8928 | if (first) | |
8929 | buffer_putc (b, ' '); | |
8930 | else | |
8931 | { | |
8932 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) | |
8933 | continue; | |
8934 | first = 1; | |
8935 | } | |
8936 | ||
8937 | buffer_putstr (b, argv[i]); | |
8938 | } | |
8939 | buffer_putc (b, '\0'); | |
8940 | ||
8941 | str = buffer_getstr (b); | |
8942 | buffer_free (b); | |
8943 | ||
8944 | com = community_str2com (str); | |
3b8b1855 | 8945 | XFREE (MTYPE_TMP, str); |
718e3744 | 8946 | if (! com) |
8947 | { | |
8948 | vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE); | |
8949 | return CMD_WARNING; | |
8950 | } | |
8951 | ||
95cbbd2a | 8952 | return bgp_show (vty, bgp, afi, safi, |
5a646650 | 8953 | (exact ? bgp_show_type_community_exact : |
b05a1c8b | 8954 | bgp_show_type_community), com, 0); |
718e3744 | 8955 | } |
8956 | ||
8957 | DEFUN (show_ip_bgp_community, | |
8958 | show_ip_bgp_community_cmd, | |
8959 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
8960 | SHOW_STR | |
8961 | IP_STR | |
8962 | BGP_STR | |
8963 | "Display routes matching the communities\n" | |
8964 | "community number\n" | |
8965 | "Do not send outside local AS (well-known community)\n" | |
8966 | "Do not advertise to any peer (well-known community)\n" | |
8967 | "Do not export to next AS (well-known community)\n") | |
8968 | { | |
95cbbd2a | 8969 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); |
718e3744 | 8970 | } |
8971 | ||
8972 | ALIAS (show_ip_bgp_community, | |
8973 | show_ip_bgp_community2_cmd, | |
8974 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
8975 | SHOW_STR | |
8976 | IP_STR | |
8977 | BGP_STR | |
8978 | "Display routes matching the communities\n" | |
8979 | "community number\n" | |
8980 | "Do not send outside local AS (well-known community)\n" | |
8981 | "Do not advertise to any peer (well-known community)\n" | |
8982 | "Do not export to next AS (well-known community)\n" | |
8983 | "community number\n" | |
8984 | "Do not send outside local AS (well-known community)\n" | |
8985 | "Do not advertise to any peer (well-known community)\n" | |
8986 | "Do not export to next AS (well-known community)\n") | |
8987 | ||
8988 | ALIAS (show_ip_bgp_community, | |
8989 | show_ip_bgp_community3_cmd, | |
8990 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
8991 | SHOW_STR | |
8992 | IP_STR | |
8993 | BGP_STR | |
8994 | "Display routes matching the communities\n" | |
8995 | "community number\n" | |
8996 | "Do not send outside local AS (well-known community)\n" | |
8997 | "Do not advertise to any peer (well-known community)\n" | |
8998 | "Do not export to next AS (well-known community)\n" | |
8999 | "community number\n" | |
9000 | "Do not send outside local AS (well-known community)\n" | |
9001 | "Do not advertise to any peer (well-known community)\n" | |
9002 | "Do not export to next AS (well-known community)\n" | |
9003 | "community number\n" | |
9004 | "Do not send outside local AS (well-known community)\n" | |
9005 | "Do not advertise to any peer (well-known community)\n" | |
9006 | "Do not export to next AS (well-known community)\n") | |
9007 | ||
9008 | ALIAS (show_ip_bgp_community, | |
9009 | show_ip_bgp_community4_cmd, | |
9010 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9011 | SHOW_STR | |
9012 | IP_STR | |
9013 | BGP_STR | |
9014 | "Display routes matching the communities\n" | |
9015 | "community number\n" | |
9016 | "Do not send outside local AS (well-known community)\n" | |
9017 | "Do not advertise to any peer (well-known community)\n" | |
9018 | "Do not export to next AS (well-known community)\n" | |
9019 | "community number\n" | |
9020 | "Do not send outside local AS (well-known community)\n" | |
9021 | "Do not advertise to any peer (well-known community)\n" | |
9022 | "Do not export to next AS (well-known community)\n" | |
9023 | "community number\n" | |
9024 | "Do not send outside local AS (well-known community)\n" | |
9025 | "Do not advertise to any peer (well-known community)\n" | |
9026 | "Do not export to next AS (well-known community)\n" | |
9027 | "community number\n" | |
9028 | "Do not send outside local AS (well-known community)\n" | |
9029 | "Do not advertise to any peer (well-known community)\n" | |
9030 | "Do not export to next AS (well-known community)\n") | |
9031 | ||
9032 | DEFUN (show_ip_bgp_ipv4_community, | |
9033 | show_ip_bgp_ipv4_community_cmd, | |
9034 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", | |
9035 | SHOW_STR | |
9036 | IP_STR | |
9037 | BGP_STR | |
9038 | "Address family\n" | |
9039 | "Address Family modifier\n" | |
9040 | "Address Family modifier\n" | |
9041 | "Display routes matching the communities\n" | |
9042 | "community number\n" | |
9043 | "Do not send outside local AS (well-known community)\n" | |
9044 | "Do not advertise to any peer (well-known community)\n" | |
9045 | "Do not export to next AS (well-known community)\n") | |
9046 | { | |
9047 | if (strncmp (argv[0], "m", 1) == 0) | |
95cbbd2a | 9048 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST); |
718e3744 | 9049 | |
95cbbd2a | 9050 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); |
718e3744 | 9051 | } |
9052 | ||
9053 | ALIAS (show_ip_bgp_ipv4_community, | |
9054 | show_ip_bgp_ipv4_community2_cmd, | |
9055 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9056 | SHOW_STR | |
9057 | IP_STR | |
9058 | BGP_STR | |
9059 | "Address family\n" | |
9060 | "Address Family modifier\n" | |
9061 | "Address Family modifier\n" | |
9062 | "Display routes matching the communities\n" | |
9063 | "community number\n" | |
9064 | "Do not send outside local AS (well-known community)\n" | |
9065 | "Do not advertise to any peer (well-known community)\n" | |
9066 | "Do not export to next AS (well-known community)\n" | |
9067 | "community number\n" | |
9068 | "Do not send outside local AS (well-known community)\n" | |
9069 | "Do not advertise to any peer (well-known community)\n" | |
9070 | "Do not export to next AS (well-known community)\n") | |
9071 | ||
9072 | ALIAS (show_ip_bgp_ipv4_community, | |
9073 | show_ip_bgp_ipv4_community3_cmd, | |
9074 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9075 | SHOW_STR | |
9076 | IP_STR | |
9077 | BGP_STR | |
9078 | "Address family\n" | |
9079 | "Address Family modifier\n" | |
9080 | "Address Family modifier\n" | |
9081 | "Display routes matching the communities\n" | |
9082 | "community number\n" | |
9083 | "Do not send outside local AS (well-known community)\n" | |
9084 | "Do not advertise to any peer (well-known community)\n" | |
9085 | "Do not export to next AS (well-known community)\n" | |
9086 | "community number\n" | |
9087 | "Do not send outside local AS (well-known community)\n" | |
9088 | "Do not advertise to any peer (well-known community)\n" | |
9089 | "Do not export to next AS (well-known community)\n" | |
9090 | "community number\n" | |
9091 | "Do not send outside local AS (well-known community)\n" | |
9092 | "Do not advertise to any peer (well-known community)\n" | |
9093 | "Do not export to next AS (well-known community)\n") | |
9094 | ||
9095 | ALIAS (show_ip_bgp_ipv4_community, | |
9096 | show_ip_bgp_ipv4_community4_cmd, | |
9097 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9098 | SHOW_STR | |
9099 | IP_STR | |
9100 | BGP_STR | |
9101 | "Address family\n" | |
9102 | "Address Family modifier\n" | |
9103 | "Address Family modifier\n" | |
9104 | "Display routes matching the communities\n" | |
9105 | "community number\n" | |
9106 | "Do not send outside local AS (well-known community)\n" | |
9107 | "Do not advertise to any peer (well-known community)\n" | |
9108 | "Do not export to next AS (well-known community)\n" | |
9109 | "community number\n" | |
9110 | "Do not send outside local AS (well-known community)\n" | |
9111 | "Do not advertise to any peer (well-known community)\n" | |
9112 | "Do not export to next AS (well-known community)\n" | |
9113 | "community number\n" | |
9114 | "Do not send outside local AS (well-known community)\n" | |
9115 | "Do not advertise to any peer (well-known community)\n" | |
9116 | "Do not export to next AS (well-known community)\n" | |
9117 | "community number\n" | |
9118 | "Do not send outside local AS (well-known community)\n" | |
9119 | "Do not advertise to any peer (well-known community)\n" | |
9120 | "Do not export to next AS (well-known community)\n") | |
9121 | ||
95cbbd2a ML |
9122 | DEFUN (show_bgp_view_afi_safi_community_all, |
9123 | show_bgp_view_afi_safi_community_all_cmd, | |
9124 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 9125 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community", |
95cbbd2a | 9126 | #else |
6aeb9e78 | 9127 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community", |
95cbbd2a ML |
9128 | #endif |
9129 | SHOW_STR | |
9130 | BGP_STR | |
6aeb9e78 DS |
9131 | "BGP view\nBGP VRF\n" |
9132 | "View/VRF name\n" | |
95cbbd2a ML |
9133 | "Address family\n" |
9134 | #ifdef HAVE_IPV6 | |
9135 | "Address family\n" | |
9136 | #endif | |
9137 | "Address Family modifier\n" | |
9138 | "Address Family modifier\n" | |
2b00515a | 9139 | "Display routes matching the communities\n") |
95cbbd2a ML |
9140 | { |
9141 | int afi; | |
9142 | int safi; | |
9143 | struct bgp *bgp; | |
9144 | ||
9145 | /* BGP structure lookup. */ | |
6aeb9e78 | 9146 | bgp = bgp_lookup_by_name (argv[1]); |
95cbbd2a ML |
9147 | if (bgp == NULL) |
9148 | { | |
6aeb9e78 | 9149 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
95cbbd2a ML |
9150 | return CMD_WARNING; |
9151 | } | |
9152 | ||
9153 | #ifdef HAVE_IPV6 | |
6aeb9e78 DS |
9154 | afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
9155 | safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; | |
95cbbd2a ML |
9156 | #else |
9157 | afi = AFI_IP; | |
6aeb9e78 | 9158 | safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
95cbbd2a | 9159 | #endif |
b05a1c8b | 9160 | return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0); |
95cbbd2a ML |
9161 | } |
9162 | ||
9163 | DEFUN (show_bgp_view_afi_safi_community, | |
9164 | show_bgp_view_afi_safi_community_cmd, | |
9165 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 9166 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a | 9167 | #else |
6aeb9e78 | 9168 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
9169 | #endif |
9170 | SHOW_STR | |
9171 | BGP_STR | |
6aeb9e78 DS |
9172 | "BGP view\nBGP VRF\n" |
9173 | "View/VRF name\n" | |
95cbbd2a ML |
9174 | "Address family\n" |
9175 | #ifdef HAVE_IPV6 | |
9176 | "Address family\n" | |
9177 | #endif | |
9178 | "Address family modifier\n" | |
9179 | "Address family modifier\n" | |
9180 | "Display routes matching the communities\n" | |
9181 | "community number\n" | |
9182 | "Do not send outside local AS (well-known community)\n" | |
9183 | "Do not advertise to any peer (well-known community)\n" | |
9184 | "Do not export to next AS (well-known community)\n") | |
9185 | { | |
9186 | int afi; | |
9187 | int safi; | |
9188 | ||
9189 | #ifdef HAVE_IPV6 | |
6aeb9e78 DS |
9190 | afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
9191 | safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; | |
9192 | return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi); | |
95cbbd2a ML |
9193 | #else |
9194 | afi = AFI_IP; | |
6aeb9e78 DS |
9195 | safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
9196 | return bgp_show_community (vty, argv[1], argc-3, &argv[3], 0, afi, safi); | |
95cbbd2a ML |
9197 | #endif |
9198 | } | |
9199 | ||
9200 | ALIAS (show_bgp_view_afi_safi_community, | |
9201 | show_bgp_view_afi_safi_community2_cmd, | |
9202 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 9203 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a | 9204 | #else |
6aeb9e78 | 9205 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
9206 | #endif |
9207 | SHOW_STR | |
9208 | BGP_STR | |
6aeb9e78 DS |
9209 | "BGP view\nBGP VRF\n" |
9210 | "View/VRF name\n" | |
95cbbd2a ML |
9211 | "Address family\n" |
9212 | #ifdef HAVE_IPV6 | |
9213 | "Address family\n" | |
9214 | #endif | |
9215 | "Address family modifier\n" | |
9216 | "Address family modifier\n" | |
9217 | "Display routes matching the communities\n" | |
9218 | "community number\n" | |
9219 | "Do not send outside local AS (well-known community)\n" | |
9220 | "Do not advertise to any peer (well-known community)\n" | |
9221 | "Do not export to next AS (well-known community)\n" | |
9222 | "community number\n" | |
9223 | "Do not send outside local AS (well-known community)\n" | |
9224 | "Do not advertise to any peer (well-known community)\n" | |
9225 | "Do not export to next AS (well-known community)\n") | |
9226 | ||
9227 | ALIAS (show_bgp_view_afi_safi_community, | |
9228 | show_bgp_view_afi_safi_community3_cmd, | |
9229 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 9230 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a | 9231 | #else |
6aeb9e78 | 9232 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
9233 | #endif |
9234 | SHOW_STR | |
9235 | BGP_STR | |
6aeb9e78 DS |
9236 | "BGP view\nBGP VRF\n" |
9237 | "View/VRF name\n" | |
95cbbd2a ML |
9238 | "Address family\n" |
9239 | #ifdef HAVE_IPV6 | |
9240 | "Address family\n" | |
9241 | #endif | |
9242 | "Address family modifier\n" | |
9243 | "Address family modifier\n" | |
9244 | "Display routes matching the communities\n" | |
9245 | "community number\n" | |
9246 | "Do not send outside local AS (well-known community)\n" | |
9247 | "Do not advertise to any peer (well-known community)\n" | |
9248 | "Do not export to next AS (well-known community)\n" | |
9249 | "community number\n" | |
9250 | "Do not send outside local AS (well-known community)\n" | |
9251 | "Do not advertise to any peer (well-known community)\n" | |
9252 | "Do not export to next AS (well-known community)\n" | |
9253 | "community number\n" | |
9254 | "Do not send outside local AS (well-known community)\n" | |
9255 | "Do not advertise to any peer (well-known community)\n" | |
9256 | "Do not export to next AS (well-known community)\n") | |
9257 | ||
9258 | ALIAS (show_bgp_view_afi_safi_community, | |
9259 | show_bgp_view_afi_safi_community4_cmd, | |
9260 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 9261 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a | 9262 | #else |
6aeb9e78 | 9263 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
95cbbd2a ML |
9264 | #endif |
9265 | SHOW_STR | |
9266 | BGP_STR | |
6aeb9e78 DS |
9267 | "BGP view\nBGP VRF\n" |
9268 | "View/VRF name\n" | |
95cbbd2a ML |
9269 | "Address family\n" |
9270 | #ifdef HAVE_IPV6 | |
9271 | "Address family\n" | |
9272 | #endif | |
9273 | "Address family modifier\n" | |
9274 | "Address family modifier\n" | |
9275 | "Display routes matching the communities\n" | |
9276 | "community number\n" | |
9277 | "Do not send outside local AS (well-known community)\n" | |
9278 | "Do not advertise to any peer (well-known community)\n" | |
9279 | "Do not export to next AS (well-known community)\n" | |
9280 | "community number\n" | |
9281 | "Do not send outside local AS (well-known community)\n" | |
9282 | "Do not advertise to any peer (well-known community)\n" | |
9283 | "Do not export to next AS (well-known community)\n" | |
9284 | "community number\n" | |
9285 | "Do not send outside local AS (well-known community)\n" | |
9286 | "Do not advertise to any peer (well-known community)\n" | |
9287 | "Do not export to next AS (well-known community)\n" | |
9288 | "community number\n" | |
9289 | "Do not send outside local AS (well-known community)\n" | |
9290 | "Do not advertise to any peer (well-known community)\n" | |
9291 | "Do not export to next AS (well-known community)\n") | |
9292 | ||
718e3744 | 9293 | DEFUN (show_ip_bgp_community_exact, |
9294 | show_ip_bgp_community_exact_cmd, | |
9295 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9296 | SHOW_STR | |
9297 | IP_STR | |
9298 | BGP_STR | |
9299 | "Display routes matching the communities\n" | |
9300 | "community number\n" | |
9301 | "Do not send outside local AS (well-known community)\n" | |
9302 | "Do not advertise to any peer (well-known community)\n" | |
9303 | "Do not export to next AS (well-known community)\n" | |
9304 | "Exact match of the communities") | |
9305 | { | |
95cbbd2a | 9306 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); |
718e3744 | 9307 | } |
9308 | ||
9309 | ALIAS (show_ip_bgp_community_exact, | |
9310 | show_ip_bgp_community2_exact_cmd, | |
9311 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9312 | SHOW_STR | |
9313 | IP_STR | |
9314 | BGP_STR | |
9315 | "Display routes matching the communities\n" | |
9316 | "community number\n" | |
9317 | "Do not send outside local AS (well-known community)\n" | |
9318 | "Do not advertise to any peer (well-known community)\n" | |
9319 | "Do not export to next AS (well-known community)\n" | |
9320 | "community number\n" | |
9321 | "Do not send outside local AS (well-known community)\n" | |
9322 | "Do not advertise to any peer (well-known community)\n" | |
9323 | "Do not export to next AS (well-known community)\n" | |
9324 | "Exact match of the communities") | |
9325 | ||
9326 | ALIAS (show_ip_bgp_community_exact, | |
9327 | show_ip_bgp_community3_exact_cmd, | |
9328 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9329 | SHOW_STR | |
9330 | IP_STR | |
9331 | BGP_STR | |
9332 | "Display routes matching the communities\n" | |
9333 | "community number\n" | |
9334 | "Do not send outside local AS (well-known community)\n" | |
9335 | "Do not advertise to any peer (well-known community)\n" | |
9336 | "Do not export to next AS (well-known community)\n" | |
9337 | "community number\n" | |
9338 | "Do not send outside local AS (well-known community)\n" | |
9339 | "Do not advertise to any peer (well-known community)\n" | |
9340 | "Do not export to next AS (well-known community)\n" | |
9341 | "community number\n" | |
9342 | "Do not send outside local AS (well-known community)\n" | |
9343 | "Do not advertise to any peer (well-known community)\n" | |
9344 | "Do not export to next AS (well-known community)\n" | |
9345 | "Exact match of the communities") | |
9346 | ||
9347 | ALIAS (show_ip_bgp_community_exact, | |
9348 | show_ip_bgp_community4_exact_cmd, | |
9349 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9350 | SHOW_STR | |
9351 | IP_STR | |
9352 | BGP_STR | |
9353 | "Display routes matching the communities\n" | |
9354 | "community number\n" | |
9355 | "Do not send outside local AS (well-known community)\n" | |
9356 | "Do not advertise to any peer (well-known community)\n" | |
9357 | "Do not export to next AS (well-known community)\n" | |
9358 | "community number\n" | |
9359 | "Do not send outside local AS (well-known community)\n" | |
9360 | "Do not advertise to any peer (well-known community)\n" | |
9361 | "Do not export to next AS (well-known community)\n" | |
9362 | "community number\n" | |
9363 | "Do not send outside local AS (well-known community)\n" | |
9364 | "Do not advertise to any peer (well-known community)\n" | |
9365 | "Do not export to next AS (well-known community)\n" | |
9366 | "community number\n" | |
9367 | "Do not send outside local AS (well-known community)\n" | |
9368 | "Do not advertise to any peer (well-known community)\n" | |
9369 | "Do not export to next AS (well-known community)\n" | |
9370 | "Exact match of the communities") | |
9371 | ||
9372 | DEFUN (show_ip_bgp_ipv4_community_exact, | |
9373 | show_ip_bgp_ipv4_community_exact_cmd, | |
9374 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9375 | SHOW_STR | |
9376 | IP_STR | |
9377 | BGP_STR | |
9378 | "Address family\n" | |
9379 | "Address Family modifier\n" | |
9380 | "Address Family modifier\n" | |
9381 | "Display routes matching the communities\n" | |
9382 | "community number\n" | |
9383 | "Do not send outside local AS (well-known community)\n" | |
9384 | "Do not advertise to any peer (well-known community)\n" | |
9385 | "Do not export to next AS (well-known community)\n" | |
9386 | "Exact match of the communities") | |
9387 | { | |
9388 | if (strncmp (argv[0], "m", 1) == 0) | |
95cbbd2a | 9389 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST); |
718e3744 | 9390 | |
95cbbd2a | 9391 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); |
718e3744 | 9392 | } |
9393 | ||
9394 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
9395 | show_ip_bgp_ipv4_community2_exact_cmd, | |
9396 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9397 | SHOW_STR | |
9398 | IP_STR | |
9399 | BGP_STR | |
9400 | "Address family\n" | |
9401 | "Address Family modifier\n" | |
9402 | "Address Family modifier\n" | |
9403 | "Display routes matching the communities\n" | |
9404 | "community number\n" | |
9405 | "Do not send outside local AS (well-known community)\n" | |
9406 | "Do not advertise to any peer (well-known community)\n" | |
9407 | "Do not export to next AS (well-known community)\n" | |
9408 | "community number\n" | |
9409 | "Do not send outside local AS (well-known community)\n" | |
9410 | "Do not advertise to any peer (well-known community)\n" | |
9411 | "Do not export to next AS (well-known community)\n" | |
9412 | "Exact match of the communities") | |
9413 | ||
9414 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
9415 | show_ip_bgp_ipv4_community3_exact_cmd, | |
9416 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9417 | SHOW_STR | |
9418 | IP_STR | |
9419 | BGP_STR | |
9420 | "Address family\n" | |
9421 | "Address Family modifier\n" | |
9422 | "Address Family modifier\n" | |
9423 | "Display routes matching the communities\n" | |
9424 | "community number\n" | |
9425 | "Do not send outside local AS (well-known community)\n" | |
9426 | "Do not advertise to any peer (well-known community)\n" | |
9427 | "Do not export to next AS (well-known community)\n" | |
9428 | "community number\n" | |
9429 | "Do not send outside local AS (well-known community)\n" | |
9430 | "Do not advertise to any peer (well-known community)\n" | |
9431 | "Do not export to next AS (well-known community)\n" | |
9432 | "community number\n" | |
9433 | "Do not send outside local AS (well-known community)\n" | |
9434 | "Do not advertise to any peer (well-known community)\n" | |
9435 | "Do not export to next AS (well-known community)\n" | |
9436 | "Exact match of the communities") | |
9437 | ||
9438 | ALIAS (show_ip_bgp_ipv4_community_exact, | |
9439 | show_ip_bgp_ipv4_community4_exact_cmd, | |
9440 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9441 | SHOW_STR | |
9442 | IP_STR | |
9443 | BGP_STR | |
9444 | "Address family\n" | |
9445 | "Address Family modifier\n" | |
9446 | "Address Family modifier\n" | |
9447 | "Display routes matching the communities\n" | |
9448 | "community number\n" | |
9449 | "Do not send outside local AS (well-known community)\n" | |
9450 | "Do not advertise to any peer (well-known community)\n" | |
9451 | "Do not export to next AS (well-known community)\n" | |
9452 | "community number\n" | |
9453 | "Do not send outside local AS (well-known community)\n" | |
9454 | "Do not advertise to any peer (well-known community)\n" | |
9455 | "Do not export to next AS (well-known community)\n" | |
9456 | "community number\n" | |
9457 | "Do not send outside local AS (well-known community)\n" | |
9458 | "Do not advertise to any peer (well-known community)\n" | |
9459 | "Do not export to next AS (well-known community)\n" | |
9460 | "community number\n" | |
9461 | "Do not send outside local AS (well-known community)\n" | |
9462 | "Do not advertise to any peer (well-known community)\n" | |
9463 | "Do not export to next AS (well-known community)\n" | |
9464 | "Exact match of the communities") | |
9465 | ||
9466 | #ifdef HAVE_IPV6 | |
9467 | DEFUN (show_bgp_community, | |
9468 | show_bgp_community_cmd, | |
9469 | "show bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
9470 | SHOW_STR | |
9471 | BGP_STR | |
9472 | "Display routes matching the communities\n" | |
9473 | "community number\n" | |
9474 | "Do not send outside local AS (well-known community)\n" | |
9475 | "Do not advertise to any peer (well-known community)\n" | |
9476 | "Do not export to next AS (well-known community)\n") | |
9477 | { | |
95cbbd2a | 9478 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 9479 | } |
9480 | ||
9481 | ALIAS (show_bgp_community, | |
9482 | show_bgp_ipv6_community_cmd, | |
9483 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)", | |
9484 | SHOW_STR | |
9485 | BGP_STR | |
9486 | "Address family\n" | |
9487 | "Display routes matching the communities\n" | |
9488 | "community number\n" | |
9489 | "Do not send outside local AS (well-known community)\n" | |
9490 | "Do not advertise to any peer (well-known community)\n" | |
9491 | "Do not export to next AS (well-known community)\n") | |
9492 | ||
9493 | ALIAS (show_bgp_community, | |
9494 | show_bgp_community2_cmd, | |
9495 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9496 | SHOW_STR | |
9497 | BGP_STR | |
9498 | "Display routes matching the communities\n" | |
9499 | "community number\n" | |
9500 | "Do not send outside local AS (well-known community)\n" | |
9501 | "Do not advertise to any peer (well-known community)\n" | |
9502 | "Do not export to next AS (well-known community)\n" | |
9503 | "community number\n" | |
9504 | "Do not send outside local AS (well-known community)\n" | |
9505 | "Do not advertise to any peer (well-known community)\n" | |
9506 | "Do not export to next AS (well-known community)\n") | |
9507 | ||
9508 | ALIAS (show_bgp_community, | |
9509 | show_bgp_ipv6_community2_cmd, | |
9510 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9511 | SHOW_STR | |
9512 | BGP_STR | |
9513 | "Address family\n" | |
9514 | "Display routes matching the communities\n" | |
9515 | "community number\n" | |
9516 | "Do not send outside local AS (well-known community)\n" | |
9517 | "Do not advertise to any peer (well-known community)\n" | |
9518 | "Do not export to next AS (well-known community)\n" | |
9519 | "community number\n" | |
9520 | "Do not send outside local AS (well-known community)\n" | |
9521 | "Do not advertise to any peer (well-known community)\n" | |
9522 | "Do not export to next AS (well-known community)\n") | |
9523 | ||
9524 | ALIAS (show_bgp_community, | |
9525 | show_bgp_community3_cmd, | |
9526 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9527 | SHOW_STR | |
9528 | BGP_STR | |
9529 | "Display routes matching the communities\n" | |
9530 | "community number\n" | |
9531 | "Do not send outside local AS (well-known community)\n" | |
9532 | "Do not advertise to any peer (well-known community)\n" | |
9533 | "Do not export to next AS (well-known community)\n" | |
9534 | "community number\n" | |
9535 | "Do not send outside local AS (well-known community)\n" | |
9536 | "Do not advertise to any peer (well-known community)\n" | |
9537 | "Do not export to next AS (well-known community)\n" | |
9538 | "community number\n" | |
9539 | "Do not send outside local AS (well-known community)\n" | |
9540 | "Do not advertise to any peer (well-known community)\n" | |
9541 | "Do not export to next AS (well-known community)\n") | |
9542 | ||
9543 | ALIAS (show_bgp_community, | |
9544 | show_bgp_ipv6_community3_cmd, | |
9545 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9546 | SHOW_STR | |
9547 | BGP_STR | |
9548 | "Address family\n" | |
9549 | "Display routes matching the communities\n" | |
9550 | "community number\n" | |
9551 | "Do not send outside local AS (well-known community)\n" | |
9552 | "Do not advertise to any peer (well-known community)\n" | |
9553 | "Do not export to next AS (well-known community)\n" | |
9554 | "community number\n" | |
9555 | "Do not send outside local AS (well-known community)\n" | |
9556 | "Do not advertise to any peer (well-known community)\n" | |
9557 | "Do not export to next AS (well-known community)\n" | |
9558 | "community number\n" | |
9559 | "Do not send outside local AS (well-known community)\n" | |
9560 | "Do not advertise to any peer (well-known community)\n" | |
9561 | "Do not export to next AS (well-known community)\n") | |
9562 | ||
9563 | ALIAS (show_bgp_community, | |
9564 | show_bgp_community4_cmd, | |
9565 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9566 | SHOW_STR | |
9567 | BGP_STR | |
9568 | "Display routes matching the communities\n" | |
9569 | "community number\n" | |
9570 | "Do not send outside local AS (well-known community)\n" | |
9571 | "Do not advertise to any peer (well-known community)\n" | |
9572 | "Do not export to next AS (well-known community)\n" | |
9573 | "community number\n" | |
9574 | "Do not send outside local AS (well-known community)\n" | |
9575 | "Do not advertise to any peer (well-known community)\n" | |
9576 | "Do not export to next AS (well-known community)\n" | |
9577 | "community number\n" | |
9578 | "Do not send outside local AS (well-known community)\n" | |
9579 | "Do not advertise to any peer (well-known community)\n" | |
9580 | "Do not export to next AS (well-known community)\n" | |
9581 | "community number\n" | |
9582 | "Do not send outside local AS (well-known community)\n" | |
9583 | "Do not advertise to any peer (well-known community)\n" | |
9584 | "Do not export to next AS (well-known community)\n") | |
9585 | ||
9586 | ALIAS (show_bgp_community, | |
9587 | show_bgp_ipv6_community4_cmd, | |
9588 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9589 | SHOW_STR | |
9590 | BGP_STR | |
9591 | "Address family\n" | |
9592 | "Display routes matching the communities\n" | |
9593 | "community number\n" | |
9594 | "Do not send outside local AS (well-known community)\n" | |
9595 | "Do not advertise to any peer (well-known community)\n" | |
9596 | "Do not export to next AS (well-known community)\n" | |
9597 | "community number\n" | |
9598 | "Do not send outside local AS (well-known community)\n" | |
9599 | "Do not advertise to any peer (well-known community)\n" | |
9600 | "Do not export to next AS (well-known community)\n" | |
9601 | "community number\n" | |
9602 | "Do not send outside local AS (well-known community)\n" | |
9603 | "Do not advertise to any peer (well-known community)\n" | |
9604 | "Do not export to next AS (well-known community)\n" | |
9605 | "community number\n" | |
9606 | "Do not send outside local AS (well-known community)\n" | |
9607 | "Do not advertise to any peer (well-known community)\n" | |
9608 | "Do not export to next AS (well-known community)\n") | |
9609 | ||
9610 | /* old command */ | |
9611 | DEFUN (show_ipv6_bgp_community, | |
9612 | show_ipv6_bgp_community_cmd, | |
9613 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)", | |
9614 | SHOW_STR | |
9615 | IPV6_STR | |
9616 | BGP_STR | |
9617 | "Display routes matching the communities\n" | |
9618 | "community number\n" | |
9619 | "Do not send outside local AS (well-known community)\n" | |
9620 | "Do not advertise to any peer (well-known community)\n" | |
9621 | "Do not export to next AS (well-known community)\n") | |
9622 | { | |
47e9b292 | 9623 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 9624 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
718e3744 | 9625 | } |
9626 | ||
9627 | /* old command */ | |
9628 | ALIAS (show_ipv6_bgp_community, | |
9629 | show_ipv6_bgp_community2_cmd, | |
9630 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9631 | SHOW_STR | |
9632 | IPV6_STR | |
9633 | BGP_STR | |
9634 | "Display routes matching the communities\n" | |
9635 | "community number\n" | |
9636 | "Do not send outside local AS (well-known community)\n" | |
9637 | "Do not advertise to any peer (well-known community)\n" | |
9638 | "Do not export to next AS (well-known community)\n" | |
9639 | "community number\n" | |
9640 | "Do not send outside local AS (well-known community)\n" | |
9641 | "Do not advertise to any peer (well-known community)\n" | |
9642 | "Do not export to next AS (well-known community)\n") | |
9643 | ||
9644 | /* old command */ | |
9645 | ALIAS (show_ipv6_bgp_community, | |
9646 | show_ipv6_bgp_community3_cmd, | |
9647 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9648 | SHOW_STR | |
9649 | IPV6_STR | |
9650 | BGP_STR | |
9651 | "Display routes matching the communities\n" | |
9652 | "community number\n" | |
9653 | "Do not send outside local AS (well-known community)\n" | |
9654 | "Do not advertise to any peer (well-known community)\n" | |
9655 | "Do not export to next AS (well-known community)\n" | |
9656 | "community number\n" | |
9657 | "Do not send outside local AS (well-known community)\n" | |
9658 | "Do not advertise to any peer (well-known community)\n" | |
9659 | "Do not export to next AS (well-known community)\n" | |
9660 | "community number\n" | |
9661 | "Do not send outside local AS (well-known community)\n" | |
9662 | "Do not advertise to any peer (well-known community)\n" | |
9663 | "Do not export to next AS (well-known community)\n") | |
9664 | ||
9665 | /* old command */ | |
9666 | ALIAS (show_ipv6_bgp_community, | |
9667 | show_ipv6_bgp_community4_cmd, | |
9668 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9669 | SHOW_STR | |
9670 | IPV6_STR | |
9671 | BGP_STR | |
9672 | "Display routes matching the communities\n" | |
9673 | "community number\n" | |
9674 | "Do not send outside local AS (well-known community)\n" | |
9675 | "Do not advertise to any peer (well-known community)\n" | |
9676 | "Do not export to next AS (well-known community)\n" | |
9677 | "community number\n" | |
9678 | "Do not send outside local AS (well-known community)\n" | |
9679 | "Do not advertise to any peer (well-known community)\n" | |
9680 | "Do not export to next AS (well-known community)\n" | |
9681 | "community number\n" | |
9682 | "Do not send outside local AS (well-known community)\n" | |
9683 | "Do not advertise to any peer (well-known community)\n" | |
9684 | "Do not export to next AS (well-known community)\n" | |
9685 | "community number\n" | |
9686 | "Do not send outside local AS (well-known community)\n" | |
9687 | "Do not advertise to any peer (well-known community)\n" | |
9688 | "Do not export to next AS (well-known community)\n") | |
9689 | ||
9690 | DEFUN (show_bgp_community_exact, | |
9691 | show_bgp_community_exact_cmd, | |
9692 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9693 | SHOW_STR | |
9694 | BGP_STR | |
9695 | "Display routes matching the communities\n" | |
9696 | "community number\n" | |
9697 | "Do not send outside local AS (well-known community)\n" | |
9698 | "Do not advertise to any peer (well-known community)\n" | |
9699 | "Do not export to next AS (well-known community)\n" | |
9700 | "Exact match of the communities") | |
9701 | { | |
95cbbd2a | 9702 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 9703 | } |
9704 | ||
9705 | ALIAS (show_bgp_community_exact, | |
9706 | show_bgp_ipv6_community_exact_cmd, | |
9707 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9708 | SHOW_STR | |
9709 | BGP_STR | |
9710 | "Address family\n" | |
9711 | "Display routes matching the communities\n" | |
9712 | "community number\n" | |
9713 | "Do not send outside local AS (well-known community)\n" | |
9714 | "Do not advertise to any peer (well-known community)\n" | |
9715 | "Do not export to next AS (well-known community)\n" | |
9716 | "Exact match of the communities") | |
9717 | ||
9718 | ALIAS (show_bgp_community_exact, | |
9719 | show_bgp_community2_exact_cmd, | |
9720 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9721 | SHOW_STR | |
9722 | BGP_STR | |
9723 | "Display routes matching the communities\n" | |
9724 | "community number\n" | |
9725 | "Do not send outside local AS (well-known community)\n" | |
9726 | "Do not advertise to any peer (well-known community)\n" | |
9727 | "Do not export to next AS (well-known community)\n" | |
9728 | "community number\n" | |
9729 | "Do not send outside local AS (well-known community)\n" | |
9730 | "Do not advertise to any peer (well-known community)\n" | |
9731 | "Do not export to next AS (well-known community)\n" | |
9732 | "Exact match of the communities") | |
9733 | ||
9734 | ALIAS (show_bgp_community_exact, | |
9735 | show_bgp_ipv6_community2_exact_cmd, | |
9736 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9737 | SHOW_STR | |
9738 | BGP_STR | |
9739 | "Address family\n" | |
9740 | "Display routes matching the communities\n" | |
9741 | "community number\n" | |
9742 | "Do not send outside local AS (well-known community)\n" | |
9743 | "Do not advertise to any peer (well-known community)\n" | |
9744 | "Do not export to next AS (well-known community)\n" | |
9745 | "community number\n" | |
9746 | "Do not send outside local AS (well-known community)\n" | |
9747 | "Do not advertise to any peer (well-known community)\n" | |
9748 | "Do not export to next AS (well-known community)\n" | |
9749 | "Exact match of the communities") | |
9750 | ||
9751 | ALIAS (show_bgp_community_exact, | |
9752 | show_bgp_community3_exact_cmd, | |
9753 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9754 | SHOW_STR | |
9755 | BGP_STR | |
9756 | "Display routes matching the communities\n" | |
9757 | "community number\n" | |
9758 | "Do not send outside local AS (well-known community)\n" | |
9759 | "Do not advertise to any peer (well-known community)\n" | |
9760 | "Do not export to next AS (well-known community)\n" | |
9761 | "community number\n" | |
9762 | "Do not send outside local AS (well-known community)\n" | |
9763 | "Do not advertise to any peer (well-known community)\n" | |
9764 | "Do not export to next AS (well-known community)\n" | |
9765 | "community number\n" | |
9766 | "Do not send outside local AS (well-known community)\n" | |
9767 | "Do not advertise to any peer (well-known community)\n" | |
9768 | "Do not export to next AS (well-known community)\n" | |
9769 | "Exact match of the communities") | |
9770 | ||
9771 | ALIAS (show_bgp_community_exact, | |
9772 | show_bgp_ipv6_community3_exact_cmd, | |
9773 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9774 | SHOW_STR | |
9775 | BGP_STR | |
9776 | "Address family\n" | |
9777 | "Display routes matching the communities\n" | |
9778 | "community number\n" | |
9779 | "Do not send outside local AS (well-known community)\n" | |
9780 | "Do not advertise to any peer (well-known community)\n" | |
9781 | "Do not export to next AS (well-known community)\n" | |
9782 | "community number\n" | |
9783 | "Do not send outside local AS (well-known community)\n" | |
9784 | "Do not advertise to any peer (well-known community)\n" | |
9785 | "Do not export to next AS (well-known community)\n" | |
9786 | "community number\n" | |
9787 | "Do not send outside local AS (well-known community)\n" | |
9788 | "Do not advertise to any peer (well-known community)\n" | |
9789 | "Do not export to next AS (well-known community)\n" | |
9790 | "Exact match of the communities") | |
9791 | ||
9792 | ALIAS (show_bgp_community_exact, | |
9793 | show_bgp_community4_exact_cmd, | |
9794 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9795 | SHOW_STR | |
9796 | BGP_STR | |
9797 | "Display routes matching the communities\n" | |
9798 | "community number\n" | |
9799 | "Do not send outside local AS (well-known community)\n" | |
9800 | "Do not advertise to any peer (well-known community)\n" | |
9801 | "Do not export to next AS (well-known community)\n" | |
9802 | "community number\n" | |
9803 | "Do not send outside local AS (well-known community)\n" | |
9804 | "Do not advertise to any peer (well-known community)\n" | |
9805 | "Do not export to next AS (well-known community)\n" | |
9806 | "community number\n" | |
9807 | "Do not send outside local AS (well-known community)\n" | |
9808 | "Do not advertise to any peer (well-known community)\n" | |
9809 | "Do not export to next AS (well-known community)\n" | |
9810 | "community number\n" | |
9811 | "Do not send outside local AS (well-known community)\n" | |
9812 | "Do not advertise to any peer (well-known community)\n" | |
9813 | "Do not export to next AS (well-known community)\n" | |
9814 | "Exact match of the communities") | |
9815 | ||
9816 | ALIAS (show_bgp_community_exact, | |
9817 | show_bgp_ipv6_community4_exact_cmd, | |
9818 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9819 | SHOW_STR | |
9820 | BGP_STR | |
9821 | "Address family\n" | |
9822 | "Display routes matching the communities\n" | |
9823 | "community number\n" | |
9824 | "Do not send outside local AS (well-known community)\n" | |
9825 | "Do not advertise to any peer (well-known community)\n" | |
9826 | "Do not export to next AS (well-known community)\n" | |
9827 | "community number\n" | |
9828 | "Do not send outside local AS (well-known community)\n" | |
9829 | "Do not advertise to any peer (well-known community)\n" | |
9830 | "Do not export to next AS (well-known community)\n" | |
9831 | "community number\n" | |
9832 | "Do not send outside local AS (well-known community)\n" | |
9833 | "Do not advertise to any peer (well-known community)\n" | |
9834 | "Do not export to next AS (well-known community)\n" | |
9835 | "community number\n" | |
9836 | "Do not send outside local AS (well-known community)\n" | |
9837 | "Do not advertise to any peer (well-known community)\n" | |
9838 | "Do not export to next AS (well-known community)\n" | |
9839 | "Exact match of the communities") | |
9840 | ||
9841 | /* old command */ | |
9842 | DEFUN (show_ipv6_bgp_community_exact, | |
9843 | show_ipv6_bgp_community_exact_cmd, | |
9844 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9845 | SHOW_STR | |
9846 | IPV6_STR | |
9847 | BGP_STR | |
9848 | "Display routes matching the communities\n" | |
9849 | "community number\n" | |
9850 | "Do not send outside local AS (well-known community)\n" | |
9851 | "Do not advertise to any peer (well-known community)\n" | |
9852 | "Do not export to next AS (well-known community)\n" | |
9853 | "Exact match of the communities") | |
9854 | { | |
47e9b292 | 9855 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 9856 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
718e3744 | 9857 | } |
9858 | ||
9859 | /* old command */ | |
9860 | ALIAS (show_ipv6_bgp_community_exact, | |
9861 | show_ipv6_bgp_community2_exact_cmd, | |
9862 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9863 | SHOW_STR | |
9864 | IPV6_STR | |
9865 | BGP_STR | |
9866 | "Display routes matching the communities\n" | |
9867 | "community number\n" | |
9868 | "Do not send outside local AS (well-known community)\n" | |
9869 | "Do not advertise to any peer (well-known community)\n" | |
9870 | "Do not export to next AS (well-known community)\n" | |
9871 | "community number\n" | |
9872 | "Do not send outside local AS (well-known community)\n" | |
9873 | "Do not advertise to any peer (well-known community)\n" | |
9874 | "Do not export to next AS (well-known community)\n" | |
9875 | "Exact match of the communities") | |
9876 | ||
9877 | /* old command */ | |
9878 | ALIAS (show_ipv6_bgp_community_exact, | |
9879 | show_ipv6_bgp_community3_exact_cmd, | |
9880 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9881 | SHOW_STR | |
9882 | IPV6_STR | |
9883 | BGP_STR | |
9884 | "Display routes matching the communities\n" | |
9885 | "community number\n" | |
9886 | "Do not send outside local AS (well-known community)\n" | |
9887 | "Do not advertise to any peer (well-known community)\n" | |
9888 | "Do not export to next AS (well-known community)\n" | |
9889 | "community number\n" | |
9890 | "Do not send outside local AS (well-known community)\n" | |
9891 | "Do not advertise to any peer (well-known community)\n" | |
9892 | "Do not export to next AS (well-known community)\n" | |
9893 | "community number\n" | |
9894 | "Do not send outside local AS (well-known community)\n" | |
9895 | "Do not advertise to any peer (well-known community)\n" | |
9896 | "Do not export to next AS (well-known community)\n" | |
9897 | "Exact match of the communities") | |
9898 | ||
9899 | /* old command */ | |
9900 | ALIAS (show_ipv6_bgp_community_exact, | |
9901 | show_ipv6_bgp_community4_exact_cmd, | |
9902 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
9903 | SHOW_STR | |
9904 | IPV6_STR | |
9905 | BGP_STR | |
9906 | "Display routes matching the communities\n" | |
9907 | "community number\n" | |
9908 | "Do not send outside local AS (well-known community)\n" | |
9909 | "Do not advertise to any peer (well-known community)\n" | |
9910 | "Do not export to next AS (well-known community)\n" | |
9911 | "community number\n" | |
9912 | "Do not send outside local AS (well-known community)\n" | |
9913 | "Do not advertise to any peer (well-known community)\n" | |
9914 | "Do not export to next AS (well-known community)\n" | |
9915 | "community number\n" | |
9916 | "Do not send outside local AS (well-known community)\n" | |
9917 | "Do not advertise to any peer (well-known community)\n" | |
9918 | "Do not export to next AS (well-known community)\n" | |
9919 | "community number\n" | |
9920 | "Do not send outside local AS (well-known community)\n" | |
9921 | "Do not advertise to any peer (well-known community)\n" | |
9922 | "Do not export to next AS (well-known community)\n" | |
9923 | "Exact match of the communities") | |
9924 | ||
9925 | /* old command */ | |
9926 | DEFUN (show_ipv6_mbgp_community, | |
9927 | show_ipv6_mbgp_community_cmd, | |
9928 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)", | |
9929 | SHOW_STR | |
9930 | IPV6_STR | |
9931 | MBGP_STR | |
9932 | "Display routes matching the communities\n" | |
9933 | "community number\n" | |
9934 | "Do not send outside local AS (well-known community)\n" | |
9935 | "Do not advertise to any peer (well-known community)\n" | |
9936 | "Do not export to next AS (well-known community)\n") | |
9937 | { | |
47e9b292 | 9938 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 9939 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 9940 | } |
9941 | ||
9942 | /* old command */ | |
9943 | ALIAS (show_ipv6_mbgp_community, | |
9944 | show_ipv6_mbgp_community2_cmd, | |
9945 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9946 | SHOW_STR | |
9947 | IPV6_STR | |
9948 | MBGP_STR | |
9949 | "Display routes matching the communities\n" | |
9950 | "community number\n" | |
9951 | "Do not send outside local AS (well-known community)\n" | |
9952 | "Do not advertise to any peer (well-known community)\n" | |
9953 | "Do not export to next AS (well-known community)\n" | |
9954 | "community number\n" | |
9955 | "Do not send outside local AS (well-known community)\n" | |
9956 | "Do not advertise to any peer (well-known community)\n" | |
9957 | "Do not export to next AS (well-known community)\n") | |
9958 | ||
9959 | /* old command */ | |
9960 | ALIAS (show_ipv6_mbgp_community, | |
9961 | show_ipv6_mbgp_community3_cmd, | |
9962 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9963 | SHOW_STR | |
9964 | IPV6_STR | |
9965 | MBGP_STR | |
9966 | "Display routes matching the communities\n" | |
9967 | "community number\n" | |
9968 | "Do not send outside local AS (well-known community)\n" | |
9969 | "Do not advertise to any peer (well-known community)\n" | |
9970 | "Do not export to next AS (well-known community)\n" | |
9971 | "community number\n" | |
9972 | "Do not send outside local AS (well-known community)\n" | |
9973 | "Do not advertise to any peer (well-known community)\n" | |
9974 | "Do not export to next AS (well-known community)\n" | |
9975 | "community number\n" | |
9976 | "Do not send outside local AS (well-known community)\n" | |
9977 | "Do not advertise to any peer (well-known community)\n" | |
9978 | "Do not export to next AS (well-known community)\n") | |
9979 | ||
9980 | /* old command */ | |
9981 | ALIAS (show_ipv6_mbgp_community, | |
9982 | show_ipv6_mbgp_community4_cmd, | |
9983 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", | |
9984 | SHOW_STR | |
9985 | IPV6_STR | |
9986 | MBGP_STR | |
9987 | "Display routes matching the communities\n" | |
9988 | "community number\n" | |
9989 | "Do not send outside local AS (well-known community)\n" | |
9990 | "Do not advertise to any peer (well-known community)\n" | |
9991 | "Do not export to next AS (well-known community)\n" | |
9992 | "community number\n" | |
9993 | "Do not send outside local AS (well-known community)\n" | |
9994 | "Do not advertise to any peer (well-known community)\n" | |
9995 | "Do not export to next AS (well-known community)\n" | |
9996 | "community number\n" | |
9997 | "Do not send outside local AS (well-known community)\n" | |
9998 | "Do not advertise to any peer (well-known community)\n" | |
9999 | "Do not export to next AS (well-known community)\n" | |
10000 | "community number\n" | |
10001 | "Do not send outside local AS (well-known community)\n" | |
10002 | "Do not advertise to any peer (well-known community)\n" | |
10003 | "Do not export to next AS (well-known community)\n") | |
10004 | ||
10005 | /* old command */ | |
10006 | DEFUN (show_ipv6_mbgp_community_exact, | |
10007 | show_ipv6_mbgp_community_exact_cmd, | |
10008 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10009 | SHOW_STR | |
10010 | IPV6_STR | |
10011 | MBGP_STR | |
10012 | "Display routes matching the communities\n" | |
10013 | "community number\n" | |
10014 | "Do not send outside local AS (well-known community)\n" | |
10015 | "Do not advertise to any peer (well-known community)\n" | |
10016 | "Do not export to next AS (well-known community)\n" | |
10017 | "Exact match of the communities") | |
10018 | { | |
47e9b292 | 10019 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
95cbbd2a | 10020 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST); |
718e3744 | 10021 | } |
10022 | ||
10023 | /* old command */ | |
10024 | ALIAS (show_ipv6_mbgp_community_exact, | |
10025 | show_ipv6_mbgp_community2_exact_cmd, | |
10026 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10027 | SHOW_STR | |
10028 | IPV6_STR | |
10029 | MBGP_STR | |
10030 | "Display routes matching the communities\n" | |
10031 | "community number\n" | |
10032 | "Do not send outside local AS (well-known community)\n" | |
10033 | "Do not advertise to any peer (well-known community)\n" | |
10034 | "Do not export to next AS (well-known community)\n" | |
10035 | "community number\n" | |
10036 | "Do not send outside local AS (well-known community)\n" | |
10037 | "Do not advertise to any peer (well-known community)\n" | |
10038 | "Do not export to next AS (well-known community)\n" | |
10039 | "Exact match of the communities") | |
10040 | ||
10041 | /* old command */ | |
10042 | ALIAS (show_ipv6_mbgp_community_exact, | |
10043 | show_ipv6_mbgp_community3_exact_cmd, | |
10044 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10045 | SHOW_STR | |
10046 | IPV6_STR | |
10047 | MBGP_STR | |
10048 | "Display routes matching the communities\n" | |
10049 | "community number\n" | |
10050 | "Do not send outside local AS (well-known community)\n" | |
10051 | "Do not advertise to any peer (well-known community)\n" | |
10052 | "Do not export to next AS (well-known community)\n" | |
10053 | "community number\n" | |
10054 | "Do not send outside local AS (well-known community)\n" | |
10055 | "Do not advertise to any peer (well-known community)\n" | |
10056 | "Do not export to next AS (well-known community)\n" | |
10057 | "community number\n" | |
10058 | "Do not send outside local AS (well-known community)\n" | |
10059 | "Do not advertise to any peer (well-known community)\n" | |
10060 | "Do not export to next AS (well-known community)\n" | |
10061 | "Exact match of the communities") | |
10062 | ||
10063 | /* old command */ | |
10064 | ALIAS (show_ipv6_mbgp_community_exact, | |
10065 | show_ipv6_mbgp_community4_exact_cmd, | |
10066 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", | |
10067 | SHOW_STR | |
10068 | IPV6_STR | |
10069 | MBGP_STR | |
10070 | "Display routes matching the communities\n" | |
10071 | "community number\n" | |
10072 | "Do not send outside local AS (well-known community)\n" | |
10073 | "Do not advertise to any peer (well-known community)\n" | |
10074 | "Do not export to next AS (well-known community)\n" | |
10075 | "community number\n" | |
10076 | "Do not send outside local AS (well-known community)\n" | |
10077 | "Do not advertise to any peer (well-known community)\n" | |
10078 | "Do not export to next AS (well-known community)\n" | |
10079 | "community number\n" | |
10080 | "Do not send outside local AS (well-known community)\n" | |
10081 | "Do not advertise to any peer (well-known community)\n" | |
10082 | "Do not export to next AS (well-known community)\n" | |
10083 | "community number\n" | |
10084 | "Do not send outside local AS (well-known community)\n" | |
10085 | "Do not advertise to any peer (well-known community)\n" | |
10086 | "Do not export to next AS (well-known community)\n" | |
10087 | "Exact match of the communities") | |
10088 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 10089 | |
94f2b392 | 10090 | static int |
fd79ac91 | 10091 | bgp_show_community_list (struct vty *vty, const char *com, int exact, |
4c9641ba | 10092 | afi_t afi, safi_t safi) |
718e3744 | 10093 | { |
10094 | struct community_list *list; | |
10095 | ||
fee6e4e4 | 10096 | list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER); |
718e3744 | 10097 | if (list == NULL) |
10098 | { | |
10099 | vty_out (vty, "%% %s is not a valid community-list name%s", com, | |
10100 | VTY_NEWLINE); | |
10101 | return CMD_WARNING; | |
10102 | } | |
10103 | ||
5a646650 | 10104 | return bgp_show (vty, NULL, afi, safi, |
10105 | (exact ? bgp_show_type_community_list_exact : | |
b05a1c8b | 10106 | bgp_show_type_community_list), list, 0); |
718e3744 | 10107 | } |
10108 | ||
10109 | DEFUN (show_ip_bgp_community_list, | |
10110 | show_ip_bgp_community_list_cmd, | |
fee6e4e4 | 10111 | "show ip bgp community-list (<1-500>|WORD)", |
718e3744 | 10112 | SHOW_STR |
10113 | IP_STR | |
10114 | BGP_STR | |
10115 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10116 | "community-list number\n" |
718e3744 | 10117 | "community-list name\n") |
10118 | { | |
10119 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST); | |
10120 | } | |
10121 | ||
10122 | DEFUN (show_ip_bgp_ipv4_community_list, | |
10123 | show_ip_bgp_ipv4_community_list_cmd, | |
fee6e4e4 | 10124 | "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)", |
718e3744 | 10125 | SHOW_STR |
10126 | IP_STR | |
10127 | BGP_STR | |
10128 | "Address family\n" | |
10129 | "Address Family modifier\n" | |
10130 | "Address Family modifier\n" | |
10131 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10132 | "community-list number\n" |
718e3744 | 10133 | "community-list name\n") |
10134 | { | |
10135 | if (strncmp (argv[0], "m", 1) == 0) | |
10136 | return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST); | |
10137 | ||
10138 | return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST); | |
10139 | } | |
10140 | ||
10141 | DEFUN (show_ip_bgp_community_list_exact, | |
10142 | show_ip_bgp_community_list_exact_cmd, | |
fee6e4e4 | 10143 | "show ip bgp community-list (<1-500>|WORD) exact-match", |
718e3744 | 10144 | SHOW_STR |
10145 | IP_STR | |
10146 | BGP_STR | |
10147 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10148 | "community-list number\n" |
718e3744 | 10149 | "community-list name\n" |
10150 | "Exact match of the communities\n") | |
10151 | { | |
10152 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST); | |
10153 | } | |
10154 | ||
10155 | DEFUN (show_ip_bgp_ipv4_community_list_exact, | |
10156 | show_ip_bgp_ipv4_community_list_exact_cmd, | |
fee6e4e4 | 10157 | "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match", |
718e3744 | 10158 | SHOW_STR |
10159 | IP_STR | |
10160 | BGP_STR | |
10161 | "Address family\n" | |
10162 | "Address Family modifier\n" | |
10163 | "Address Family modifier\n" | |
10164 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10165 | "community-list number\n" |
718e3744 | 10166 | "community-list name\n" |
10167 | "Exact match of the communities\n") | |
10168 | { | |
10169 | if (strncmp (argv[0], "m", 1) == 0) | |
10170 | return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST); | |
10171 | ||
10172 | return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST); | |
10173 | } | |
10174 | ||
10175 | #ifdef HAVE_IPV6 | |
10176 | DEFUN (show_bgp_community_list, | |
10177 | show_bgp_community_list_cmd, | |
fee6e4e4 | 10178 | "show bgp community-list (<1-500>|WORD)", |
718e3744 | 10179 | SHOW_STR |
10180 | BGP_STR | |
10181 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10182 | "community-list number\n" |
718e3744 | 10183 | "community-list name\n") |
10184 | { | |
10185 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST); | |
10186 | } | |
10187 | ||
10188 | ALIAS (show_bgp_community_list, | |
10189 | show_bgp_ipv6_community_list_cmd, | |
fee6e4e4 | 10190 | "show bgp ipv6 community-list (<1-500>|WORD)", |
718e3744 | 10191 | SHOW_STR |
10192 | BGP_STR | |
10193 | "Address family\n" | |
10194 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10195 | "community-list number\n" |
e8e1946e | 10196 | "community-list name\n") |
718e3744 | 10197 | |
10198 | /* old command */ | |
10199 | DEFUN (show_ipv6_bgp_community_list, | |
10200 | show_ipv6_bgp_community_list_cmd, | |
10201 | "show ipv6 bgp community-list WORD", | |
10202 | SHOW_STR | |
10203 | IPV6_STR | |
10204 | BGP_STR | |
10205 | "Display routes matching the community-list\n" | |
10206 | "community-list name\n") | |
10207 | { | |
47e9b292 | 10208 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10209 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST); |
10210 | } | |
10211 | ||
10212 | /* old command */ | |
10213 | DEFUN (show_ipv6_mbgp_community_list, | |
10214 | show_ipv6_mbgp_community_list_cmd, | |
10215 | "show ipv6 mbgp community-list WORD", | |
10216 | SHOW_STR | |
10217 | IPV6_STR | |
10218 | MBGP_STR | |
10219 | "Display routes matching the community-list\n" | |
10220 | "community-list name\n") | |
10221 | { | |
47e9b292 | 10222 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10223 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST); |
10224 | } | |
10225 | ||
10226 | DEFUN (show_bgp_community_list_exact, | |
10227 | show_bgp_community_list_exact_cmd, | |
fee6e4e4 | 10228 | "show bgp community-list (<1-500>|WORD) exact-match", |
718e3744 | 10229 | SHOW_STR |
10230 | BGP_STR | |
10231 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10232 | "community-list number\n" |
718e3744 | 10233 | "community-list name\n" |
10234 | "Exact match of the communities\n") | |
10235 | { | |
10236 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST); | |
10237 | } | |
10238 | ||
10239 | ALIAS (show_bgp_community_list_exact, | |
10240 | show_bgp_ipv6_community_list_exact_cmd, | |
fee6e4e4 | 10241 | "show bgp ipv6 community-list (<1-500>|WORD) exact-match", |
718e3744 | 10242 | SHOW_STR |
10243 | BGP_STR | |
10244 | "Address family\n" | |
10245 | "Display routes matching the community-list\n" | |
fee6e4e4 | 10246 | "community-list number\n" |
718e3744 | 10247 | "community-list name\n" |
10248 | "Exact match of the communities\n") | |
10249 | ||
10250 | /* old command */ | |
10251 | DEFUN (show_ipv6_bgp_community_list_exact, | |
10252 | show_ipv6_bgp_community_list_exact_cmd, | |
10253 | "show ipv6 bgp community-list WORD exact-match", | |
10254 | SHOW_STR | |
10255 | IPV6_STR | |
10256 | BGP_STR | |
10257 | "Display routes matching the community-list\n" | |
10258 | "community-list name\n" | |
10259 | "Exact match of the communities\n") | |
10260 | { | |
47e9b292 | 10261 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10262 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST); |
10263 | } | |
10264 | ||
10265 | /* old command */ | |
10266 | DEFUN (show_ipv6_mbgp_community_list_exact, | |
10267 | show_ipv6_mbgp_community_list_exact_cmd, | |
10268 | "show ipv6 mbgp community-list WORD exact-match", | |
10269 | SHOW_STR | |
10270 | IPV6_STR | |
10271 | MBGP_STR | |
10272 | "Display routes matching the community-list\n" | |
10273 | "community-list name\n" | |
10274 | "Exact match of the communities\n") | |
10275 | { | |
47e9b292 | 10276 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10277 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST); |
10278 | } | |
10279 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 10280 | |
94f2b392 | 10281 | static int |
fd79ac91 | 10282 | bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi, |
718e3744 | 10283 | safi_t safi, enum bgp_show_type type) |
10284 | { | |
10285 | int ret; | |
10286 | struct prefix *p; | |
10287 | ||
10288 | p = prefix_new(); | |
10289 | ||
10290 | ret = str2prefix (prefix, p); | |
10291 | if (! ret) | |
10292 | { | |
10293 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); | |
10294 | return CMD_WARNING; | |
10295 | } | |
10296 | ||
b05a1c8b | 10297 | ret = bgp_show (vty, NULL, afi, safi, type, p, 0); |
5a646650 | 10298 | prefix_free(p); |
10299 | return ret; | |
718e3744 | 10300 | } |
10301 | ||
10302 | DEFUN (show_ip_bgp_prefix_longer, | |
10303 | show_ip_bgp_prefix_longer_cmd, | |
10304 | "show ip bgp A.B.C.D/M longer-prefixes", | |
10305 | SHOW_STR | |
10306 | IP_STR | |
10307 | BGP_STR | |
10308 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
10309 | "Display route and more specific routes\n") | |
10310 | { | |
10311 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
10312 | bgp_show_type_prefix_longer); | |
10313 | } | |
10314 | ||
10315 | DEFUN (show_ip_bgp_flap_prefix_longer, | |
10316 | show_ip_bgp_flap_prefix_longer_cmd, | |
10317 | "show ip bgp flap-statistics A.B.C.D/M longer-prefixes", | |
10318 | SHOW_STR | |
10319 | IP_STR | |
10320 | BGP_STR | |
10321 | "Display flap statistics of routes\n" | |
10322 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
10323 | "Display route and more specific routes\n") | |
10324 | { | |
10325 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
10326 | bgp_show_type_flap_prefix_longer); | |
10327 | } | |
10328 | ||
10329 | DEFUN (show_ip_bgp_ipv4_prefix_longer, | |
10330 | show_ip_bgp_ipv4_prefix_longer_cmd, | |
10331 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes", | |
10332 | SHOW_STR | |
10333 | IP_STR | |
10334 | BGP_STR | |
10335 | "Address family\n" | |
10336 | "Address Family modifier\n" | |
10337 | "Address Family modifier\n" | |
10338 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
10339 | "Display route and more specific routes\n") | |
10340 | { | |
10341 | if (strncmp (argv[0], "m", 1) == 0) | |
10342 | return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST, | |
10343 | bgp_show_type_prefix_longer); | |
10344 | ||
10345 | return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST, | |
10346 | bgp_show_type_prefix_longer); | |
10347 | } | |
10348 | ||
10349 | DEFUN (show_ip_bgp_flap_address, | |
10350 | show_ip_bgp_flap_address_cmd, | |
10351 | "show ip bgp flap-statistics A.B.C.D", | |
10352 | SHOW_STR | |
10353 | IP_STR | |
10354 | BGP_STR | |
10355 | "Display flap statistics of routes\n" | |
10356 | "Network in the BGP routing table to display\n") | |
10357 | { | |
10358 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
10359 | bgp_show_type_flap_address); | |
10360 | } | |
10361 | ||
10362 | DEFUN (show_ip_bgp_flap_prefix, | |
10363 | show_ip_bgp_flap_prefix_cmd, | |
10364 | "show ip bgp flap-statistics A.B.C.D/M", | |
10365 | SHOW_STR | |
10366 | IP_STR | |
10367 | BGP_STR | |
10368 | "Display flap statistics of routes\n" | |
10369 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
10370 | { | |
10371 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, | |
10372 | bgp_show_type_flap_prefix); | |
10373 | } | |
10374 | #ifdef HAVE_IPV6 | |
10375 | DEFUN (show_bgp_prefix_longer, | |
10376 | show_bgp_prefix_longer_cmd, | |
10377 | "show bgp X:X::X:X/M longer-prefixes", | |
10378 | SHOW_STR | |
10379 | BGP_STR | |
10380 | "IPv6 prefix <network>/<length>\n" | |
10381 | "Display route and more specific routes\n") | |
10382 | { | |
10383 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST, | |
10384 | bgp_show_type_prefix_longer); | |
10385 | } | |
10386 | ||
10387 | ALIAS (show_bgp_prefix_longer, | |
10388 | show_bgp_ipv6_prefix_longer_cmd, | |
10389 | "show bgp ipv6 X:X::X:X/M longer-prefixes", | |
10390 | SHOW_STR | |
10391 | BGP_STR | |
10392 | "Address family\n" | |
10393 | "IPv6 prefix <network>/<length>\n" | |
10394 | "Display route and more specific routes\n") | |
10395 | ||
10396 | /* old command */ | |
10397 | DEFUN (show_ipv6_bgp_prefix_longer, | |
10398 | show_ipv6_bgp_prefix_longer_cmd, | |
10399 | "show ipv6 bgp X:X::X:X/M longer-prefixes", | |
10400 | SHOW_STR | |
10401 | IPV6_STR | |
10402 | BGP_STR | |
10403 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" | |
10404 | "Display route and more specific routes\n") | |
10405 | { | |
47e9b292 | 10406 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10407 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
10408 | bgp_show_type_prefix_longer); | |
10409 | } | |
10410 | ||
10411 | /* old command */ | |
10412 | DEFUN (show_ipv6_mbgp_prefix_longer, | |
10413 | show_ipv6_mbgp_prefix_longer_cmd, | |
10414 | "show ipv6 mbgp X:X::X:X/M longer-prefixes", | |
10415 | SHOW_STR | |
10416 | IPV6_STR | |
10417 | MBGP_STR | |
10418 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" | |
10419 | "Display route and more specific routes\n") | |
10420 | { | |
47e9b292 | 10421 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
718e3744 | 10422 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
10423 | bgp_show_type_prefix_longer); | |
10424 | } | |
10425 | #endif /* HAVE_IPV6 */ | |
bb46e94f | 10426 | |
94f2b392 | 10427 | static struct peer * |
fd79ac91 | 10428 | peer_lookup_in_view (struct vty *vty, const char *view_name, |
856ca177 | 10429 | const char *ip_str, u_char use_json) |
bb46e94f | 10430 | { |
10431 | int ret; | |
10432 | struct bgp *bgp; | |
10433 | struct peer *peer; | |
10434 | union sockunion su; | |
10435 | ||
10436 | /* BGP structure lookup. */ | |
10437 | if (view_name) | |
10438 | { | |
10439 | bgp = bgp_lookup_by_name (view_name); | |
10440 | if (! bgp) | |
10441 | { | |
856ca177 MS |
10442 | if (use_json) |
10443 | { | |
10444 | json_object *json_no = NULL; | |
10445 | json_no = json_object_new_object(); | |
10446 | json_object_string_add(json_no, "warning", "Can't find BGP view"); | |
10447 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
10448 | json_object_free(json_no); | |
10449 | } | |
10450 | else | |
6aeb9e78 | 10451 | vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
bb46e94f | 10452 | return NULL; |
10453 | } | |
10454 | } | |
5228ad27 | 10455 | else |
bb46e94f | 10456 | { |
10457 | bgp = bgp_get_default (); | |
10458 | if (! bgp) | |
10459 | { | |
856ca177 MS |
10460 | if (use_json) |
10461 | { | |
10462 | json_object *json_no = NULL; | |
10463 | json_no = json_object_new_object(); | |
10464 | json_object_string_add(json_no, "warning", "No BGP process configured"); | |
10465 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
10466 | json_object_free(json_no); | |
10467 | } | |
10468 | else | |
10469 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
bb46e94f | 10470 | return NULL; |
10471 | } | |
10472 | } | |
10473 | ||
10474 | /* Get peer sockunion. */ | |
10475 | ret = str2sockunion (ip_str, &su); | |
10476 | if (ret < 0) | |
10477 | { | |
a80beece DS |
10478 | peer = peer_lookup_by_conf_if (bgp, ip_str); |
10479 | if (!peer) | |
10480 | { | |
04b6bdc0 DW |
10481 | peer = peer_lookup_by_hostname(bgp, ip_str); |
10482 | ||
10483 | if (!peer) | |
856ca177 | 10484 | { |
04b6bdc0 DW |
10485 | if (use_json) |
10486 | { | |
10487 | json_object *json_no = NULL; | |
10488 | json_no = json_object_new_object(); | |
10489 | json_object_string_add(json_no, "malformedAddressOrName", ip_str); | |
10490 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
10491 | json_object_free(json_no); | |
10492 | } | |
10493 | else | |
10494 | vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE); | |
10495 | return NULL; | |
856ca177 | 10496 | } |
a80beece DS |
10497 | } |
10498 | return peer; | |
bb46e94f | 10499 | } |
10500 | ||
10501 | /* Peer structure lookup. */ | |
10502 | peer = peer_lookup (bgp, &su); | |
10503 | if (! peer) | |
10504 | { | |
856ca177 MS |
10505 | if (use_json) |
10506 | { | |
10507 | json_object *json_no = NULL; | |
10508 | json_no = json_object_new_object(); | |
10509 | json_object_string_add(json_no, "warning","No such neighbor"); | |
10510 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
10511 | json_object_free(json_no); | |
10512 | } | |
10513 | else | |
10514 | vty_out (vty, "No such neighbor%s", VTY_NEWLINE); | |
bb46e94f | 10515 | return NULL; |
10516 | } | |
10517 | ||
10518 | return peer; | |
10519 | } | |
6b0655a2 | 10520 | |
2815e61f PJ |
10521 | enum bgp_stats |
10522 | { | |
10523 | BGP_STATS_MAXBITLEN = 0, | |
10524 | BGP_STATS_RIB, | |
10525 | BGP_STATS_PREFIXES, | |
10526 | BGP_STATS_TOTPLEN, | |
10527 | BGP_STATS_UNAGGREGATEABLE, | |
10528 | BGP_STATS_MAX_AGGREGATEABLE, | |
10529 | BGP_STATS_AGGREGATES, | |
10530 | BGP_STATS_SPACE, | |
10531 | BGP_STATS_ASPATH_COUNT, | |
10532 | BGP_STATS_ASPATH_MAXHOPS, | |
10533 | BGP_STATS_ASPATH_TOTHOPS, | |
10534 | BGP_STATS_ASPATH_MAXSIZE, | |
10535 | BGP_STATS_ASPATH_TOTSIZE, | |
10536 | BGP_STATS_ASN_HIGHEST, | |
10537 | BGP_STATS_MAX, | |
10538 | }; | |
10539 | ||
10540 | static const char *table_stats_strs[] = | |
10541 | { | |
10542 | [BGP_STATS_PREFIXES] = "Total Prefixes", | |
10543 | [BGP_STATS_TOTPLEN] = "Average prefix length", | |
10544 | [BGP_STATS_RIB] = "Total Advertisements", | |
10545 | [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes", | |
10546 | [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes", | |
10547 | [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements", | |
10548 | [BGP_STATS_SPACE] = "Address space advertised", | |
10549 | [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths", | |
10550 | [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)", | |
10551 | [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)", | |
10552 | [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)", | |
10553 | [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)", | |
10554 | [BGP_STATS_ASN_HIGHEST] = "Highest public ASN", | |
10555 | [BGP_STATS_MAX] = NULL, | |
10556 | }; | |
10557 | ||
10558 | struct bgp_table_stats | |
10559 | { | |
10560 | struct bgp_table *table; | |
10561 | unsigned long long counts[BGP_STATS_MAX]; | |
10562 | }; | |
10563 | ||
10564 | #if 0 | |
10565 | #define TALLY_SIGFIG 100000 | |
10566 | static unsigned long | |
10567 | ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval) | |
10568 | { | |
10569 | unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG); | |
10570 | unsigned long res = (newtot * TALLY_SIGFIG) / count; | |
10571 | unsigned long ret = newtot / count; | |
10572 | ||
10573 | if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2)) | |
10574 | return ret + 1; | |
10575 | else | |
10576 | return ret; | |
10577 | } | |
10578 | #endif | |
10579 | ||
10580 | static int | |
10581 | bgp_table_stats_walker (struct thread *t) | |
10582 | { | |
10583 | struct bgp_node *rn; | |
10584 | struct bgp_node *top; | |
10585 | struct bgp_table_stats *ts = THREAD_ARG (t); | |
10586 | unsigned int space = 0; | |
10587 | ||
53d9f67a PJ |
10588 | if (!(top = bgp_table_top (ts->table))) |
10589 | return 0; | |
2815e61f PJ |
10590 | |
10591 | switch (top->p.family) | |
10592 | { | |
10593 | case AF_INET: | |
10594 | space = IPV4_MAX_BITLEN; | |
10595 | break; | |
10596 | case AF_INET6: | |
10597 | space = IPV6_MAX_BITLEN; | |
10598 | break; | |
10599 | } | |
10600 | ||
10601 | ts->counts[BGP_STATS_MAXBITLEN] = space; | |
10602 | ||
10603 | for (rn = top; rn; rn = bgp_route_next (rn)) | |
10604 | { | |
10605 | struct bgp_info *ri; | |
67174041 | 10606 | struct bgp_node *prn = bgp_node_parent_nolock (rn); |
2815e61f PJ |
10607 | unsigned int rinum = 0; |
10608 | ||
10609 | if (rn == top) | |
10610 | continue; | |
10611 | ||
10612 | if (!rn->info) | |
10613 | continue; | |
10614 | ||
10615 | ts->counts[BGP_STATS_PREFIXES]++; | |
10616 | ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen; | |
10617 | ||
10618 | #if 0 | |
10619 | ts->counts[BGP_STATS_AVGPLEN] | |
10620 | = ravg_tally (ts->counts[BGP_STATS_PREFIXES], | |
10621 | ts->counts[BGP_STATS_AVGPLEN], | |
10622 | rn->p.prefixlen); | |
10623 | #endif | |
10624 | ||
10625 | /* check if the prefix is included by any other announcements */ | |
10626 | while (prn && !prn->info) | |
67174041 | 10627 | prn = bgp_node_parent_nolock (prn); |
2815e61f PJ |
10628 | |
10629 | if (prn == NULL || prn == top) | |
8383a9bd PJ |
10630 | { |
10631 | ts->counts[BGP_STATS_UNAGGREGATEABLE]++; | |
10632 | /* announced address space */ | |
10633 | if (space) | |
10634 | ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen); | |
10635 | } | |
2815e61f PJ |
10636 | else if (prn->info) |
10637 | ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++; | |
10638 | ||
2815e61f PJ |
10639 | for (ri = rn->info; ri; ri = ri->next) |
10640 | { | |
10641 | rinum++; | |
10642 | ts->counts[BGP_STATS_RIB]++; | |
10643 | ||
10644 | if (ri->attr && | |
10645 | (CHECK_FLAG (ri->attr->flag, | |
10646 | ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))) | |
10647 | ts->counts[BGP_STATS_AGGREGATES]++; | |
10648 | ||
10649 | /* as-path stats */ | |
10650 | if (ri->attr && ri->attr->aspath) | |
10651 | { | |
10652 | unsigned int hops = aspath_count_hops (ri->attr->aspath); | |
10653 | unsigned int size = aspath_size (ri->attr->aspath); | |
10654 | as_t highest = aspath_highest (ri->attr->aspath); | |
10655 | ||
10656 | ts->counts[BGP_STATS_ASPATH_COUNT]++; | |
10657 | ||
10658 | if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS]) | |
10659 | ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops; | |
10660 | ||
10661 | if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE]) | |
10662 | ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size; | |
10663 | ||
10664 | ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops; | |
10665 | ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size; | |
10666 | #if 0 | |
10667 | ts->counts[BGP_STATS_ASPATH_AVGHOPS] | |
10668 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], | |
10669 | ts->counts[BGP_STATS_ASPATH_AVGHOPS], | |
10670 | hops); | |
10671 | ts->counts[BGP_STATS_ASPATH_AVGSIZE] | |
10672 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], | |
10673 | ts->counts[BGP_STATS_ASPATH_AVGSIZE], | |
10674 | size); | |
10675 | #endif | |
10676 | if (highest > ts->counts[BGP_STATS_ASN_HIGHEST]) | |
10677 | ts->counts[BGP_STATS_ASN_HIGHEST] = highest; | |
10678 | } | |
10679 | } | |
10680 | } | |
10681 | return 0; | |
10682 | } | |
10683 | ||
10684 | static int | |
10685 | bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi) | |
10686 | { | |
10687 | struct bgp_table_stats ts; | |
10688 | unsigned int i; | |
10689 | ||
10690 | if (!bgp->rib[afi][safi]) | |
10691 | { | |
06da0daf DS |
10692 | vty_out (vty, "%% No RIB exist's for the AFI(%d)/SAFI(%d)%s", |
10693 | afi, safi, VTY_NEWLINE); | |
2815e61f PJ |
10694 | return CMD_WARNING; |
10695 | } | |
10696 | ||
10697 | memset (&ts, 0, sizeof (ts)); | |
10698 | ts.table = bgp->rib[afi][safi]; | |
87d4a781 | 10699 | thread_execute (bm->master, bgp_table_stats_walker, &ts, 0); |
bb46e94f | 10700 | |
2815e61f PJ |
10701 | vty_out (vty, "BGP %s RIB statistics%s%s", |
10702 | afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE); | |
10703 | ||
10704 | for (i = 0; i < BGP_STATS_MAX; i++) | |
10705 | { | |
10706 | if (!table_stats_strs[i]) | |
10707 | continue; | |
10708 | ||
10709 | switch (i) | |
10710 | { | |
10711 | #if 0 | |
10712 | case BGP_STATS_ASPATH_AVGHOPS: | |
10713 | case BGP_STATS_ASPATH_AVGSIZE: | |
10714 | case BGP_STATS_AVGPLEN: | |
10715 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
10716 | vty_out (vty, "%12.2f", | |
10717 | (float)ts.counts[i] / (float)TALLY_SIGFIG); | |
10718 | break; | |
10719 | #endif | |
10720 | case BGP_STATS_ASPATH_TOTHOPS: | |
10721 | case BGP_STATS_ASPATH_TOTSIZE: | |
10722 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
10723 | vty_out (vty, "%12.2f", | |
10724 | ts.counts[i] ? | |
10725 | (float)ts.counts[i] / | |
10726 | (float)ts.counts[BGP_STATS_ASPATH_COUNT] | |
10727 | : 0); | |
10728 | break; | |
10729 | case BGP_STATS_TOTPLEN: | |
10730 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
10731 | vty_out (vty, "%12.2f", | |
10732 | ts.counts[i] ? | |
10733 | (float)ts.counts[i] / | |
10734 | (float)ts.counts[BGP_STATS_PREFIXES] | |
10735 | : 0); | |
10736 | break; | |
10737 | case BGP_STATS_SPACE: | |
10738 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
10739 | vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE); | |
10740 | if (ts.counts[BGP_STATS_MAXBITLEN] < 9) | |
10741 | break; | |
30a2231a | 10742 | vty_out (vty, "%30s: ", "%% announced "); |
2815e61f PJ |
10743 | vty_out (vty, "%12.2f%s", |
10744 | 100 * (float)ts.counts[BGP_STATS_SPACE] / | |
56395af7 | 10745 | (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]), |
2815e61f PJ |
10746 | VTY_NEWLINE); |
10747 | vty_out (vty, "%30s: ", "/8 equivalent "); | |
10748 | vty_out (vty, "%12.2f%s", | |
10749 | (float)ts.counts[BGP_STATS_SPACE] / | |
10750 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)), | |
10751 | VTY_NEWLINE); | |
10752 | if (ts.counts[BGP_STATS_MAXBITLEN] < 25) | |
10753 | break; | |
10754 | vty_out (vty, "%30s: ", "/24 equivalent "); | |
10755 | vty_out (vty, "%12.2f", | |
10756 | (float)ts.counts[BGP_STATS_SPACE] / | |
10757 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24))); | |
10758 | break; | |
10759 | default: | |
10760 | vty_out (vty, "%-30s: ", table_stats_strs[i]); | |
10761 | vty_out (vty, "%12llu", ts.counts[i]); | |
10762 | } | |
10763 | ||
10764 | vty_out (vty, "%s", VTY_NEWLINE); | |
10765 | } | |
10766 | return CMD_SUCCESS; | |
10767 | } | |
10768 | ||
10769 | static int | |
10770 | bgp_table_stats_vty (struct vty *vty, const char *name, | |
10771 | const char *afi_str, const char *safi_str) | |
10772 | { | |
10773 | struct bgp *bgp; | |
10774 | afi_t afi; | |
10775 | safi_t safi; | |
10776 | ||
10777 | if (name) | |
10778 | bgp = bgp_lookup_by_name (name); | |
10779 | else | |
10780 | bgp = bgp_get_default (); | |
10781 | ||
10782 | if (!bgp) | |
10783 | { | |
10784 | vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE); | |
10785 | return CMD_WARNING; | |
10786 | } | |
10787 | if (strncmp (afi_str, "ipv", 3) == 0) | |
10788 | { | |
10789 | if (strncmp (afi_str, "ipv4", 4) == 0) | |
10790 | afi = AFI_IP; | |
10791 | else if (strncmp (afi_str, "ipv6", 4) == 0) | |
10792 | afi = AFI_IP6; | |
10793 | else | |
10794 | { | |
10795 | vty_out (vty, "%% Invalid address family %s%s", | |
10796 | afi_str, VTY_NEWLINE); | |
10797 | return CMD_WARNING; | |
10798 | } | |
10799 | if (strncmp (safi_str, "m", 1) == 0) | |
10800 | safi = SAFI_MULTICAST; | |
10801 | else if (strncmp (safi_str, "u", 1) == 0) | |
10802 | safi = SAFI_UNICAST; | |
42e6d745 | 10803 | else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0) |
06da0daf | 10804 | safi = SAFI_MPLS_VPN; |
2815e61f PJ |
10805 | else |
10806 | { | |
10807 | vty_out (vty, "%% Invalid subsequent address family %s%s", | |
10808 | safi_str, VTY_NEWLINE); | |
10809 | return CMD_WARNING; | |
10810 | } | |
10811 | } | |
10812 | else | |
10813 | { | |
10814 | vty_out (vty, "%% Invalid address family %s%s", | |
10815 | afi_str, VTY_NEWLINE); | |
10816 | return CMD_WARNING; | |
10817 | } | |
10818 | ||
2815e61f PJ |
10819 | return bgp_table_stats (vty, bgp, afi, safi); |
10820 | } | |
10821 | ||
10822 | DEFUN (show_bgp_statistics, | |
10823 | show_bgp_statistics_cmd, | |
10824 | "show bgp (ipv4|ipv6) (unicast|multicast) statistics", | |
10825 | SHOW_STR | |
10826 | BGP_STR | |
10827 | "Address family\n" | |
10828 | "Address family\n" | |
10829 | "Address Family modifier\n" | |
10830 | "Address Family modifier\n" | |
10831 | "BGP RIB advertisement statistics\n") | |
10832 | { | |
10833 | return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); | |
10834 | } | |
10835 | ||
10836 | ALIAS (show_bgp_statistics, | |
10837 | show_bgp_statistics_vpnv4_cmd, | |
10838 | "show bgp (ipv4) (vpnv4) statistics", | |
10839 | SHOW_STR | |
10840 | BGP_STR | |
10841 | "Address family\n" | |
10842 | "Address Family modifier\n" | |
10843 | "BGP RIB advertisement statistics\n") | |
10844 | ||
10845 | DEFUN (show_bgp_statistics_view, | |
10846 | show_bgp_statistics_view_cmd, | |
6aeb9e78 | 10847 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) statistics", |
2815e61f PJ |
10848 | SHOW_STR |
10849 | BGP_STR | |
6aeb9e78 | 10850 | "BGP view\nBGP VRF\n" |
2815e61f PJ |
10851 | "Address family\n" |
10852 | "Address family\n" | |
10853 | "Address Family modifier\n" | |
10854 | "Address Family modifier\n" | |
10855 | "BGP RIB advertisement statistics\n") | |
10856 | { | |
6aeb9e78 | 10857 | return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]); |
2815e61f PJ |
10858 | } |
10859 | ||
10860 | ALIAS (show_bgp_statistics_view, | |
10861 | show_bgp_statistics_view_vpnv4_cmd, | |
6aeb9e78 | 10862 | "show bgp (view|vrf) WORD (ipv4) (vpnv4) statistics", |
2815e61f PJ |
10863 | SHOW_STR |
10864 | BGP_STR | |
6aeb9e78 | 10865 | "BGP view\nBGP VRF\n" |
2815e61f PJ |
10866 | "Address family\n" |
10867 | "Address Family modifier\n" | |
10868 | "BGP RIB advertisement statistics\n") | |
6b0655a2 | 10869 | |
ff7924f6 PJ |
10870 | enum bgp_pcounts |
10871 | { | |
10872 | PCOUNT_ADJ_IN = 0, | |
10873 | PCOUNT_DAMPED, | |
10874 | PCOUNT_REMOVED, | |
10875 | PCOUNT_HISTORY, | |
10876 | PCOUNT_STALE, | |
10877 | PCOUNT_VALID, | |
10878 | PCOUNT_ALL, | |
10879 | PCOUNT_COUNTED, | |
10880 | PCOUNT_PFCNT, /* the figure we display to users */ | |
10881 | PCOUNT_MAX, | |
10882 | }; | |
10883 | ||
10884 | static const char *pcount_strs[] = | |
10885 | { | |
10886 | [PCOUNT_ADJ_IN] = "Adj-in", | |
10887 | [PCOUNT_DAMPED] = "Damped", | |
10888 | [PCOUNT_REMOVED] = "Removed", | |
10889 | [PCOUNT_HISTORY] = "History", | |
10890 | [PCOUNT_STALE] = "Stale", | |
10891 | [PCOUNT_VALID] = "Valid", | |
10892 | [PCOUNT_ALL] = "All RIB", | |
10893 | [PCOUNT_COUNTED] = "PfxCt counted", | |
10894 | [PCOUNT_PFCNT] = "Useable", | |
10895 | [PCOUNT_MAX] = NULL, | |
10896 | }; | |
10897 | ||
2815e61f PJ |
10898 | struct peer_pcounts |
10899 | { | |
10900 | unsigned int count[PCOUNT_MAX]; | |
10901 | const struct peer *peer; | |
10902 | const struct bgp_table *table; | |
10903 | }; | |
10904 | ||
ff7924f6 | 10905 | static int |
2815e61f | 10906 | bgp_peer_count_walker (struct thread *t) |
ff7924f6 PJ |
10907 | { |
10908 | struct bgp_node *rn; | |
2815e61f PJ |
10909 | struct peer_pcounts *pc = THREAD_ARG (t); |
10910 | const struct peer *peer = pc->peer; | |
ff7924f6 | 10911 | |
2815e61f | 10912 | for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn)) |
ff7924f6 PJ |
10913 | { |
10914 | struct bgp_adj_in *ain; | |
2815e61f | 10915 | struct bgp_info *ri; |
ff7924f6 PJ |
10916 | |
10917 | for (ain = rn->adj_in; ain; ain = ain->next) | |
10918 | if (ain->peer == peer) | |
2815e61f | 10919 | pc->count[PCOUNT_ADJ_IN]++; |
ff7924f6 | 10920 | |
ff7924f6 PJ |
10921 | for (ri = rn->info; ri; ri = ri->next) |
10922 | { | |
10923 | char buf[SU_ADDRSTRLEN]; | |
10924 | ||
10925 | if (ri->peer != peer) | |
10926 | continue; | |
10927 | ||
2815e61f | 10928 | pc->count[PCOUNT_ALL]++; |
ff7924f6 PJ |
10929 | |
10930 | if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)) | |
2815e61f | 10931 | pc->count[PCOUNT_DAMPED]++; |
ff7924f6 | 10932 | if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
2815e61f | 10933 | pc->count[PCOUNT_HISTORY]++; |
ff7924f6 | 10934 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)) |
2815e61f | 10935 | pc->count[PCOUNT_REMOVED]++; |
ff7924f6 | 10936 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
2815e61f | 10937 | pc->count[PCOUNT_STALE]++; |
ff7924f6 | 10938 | if (CHECK_FLAG (ri->flags, BGP_INFO_VALID)) |
2815e61f | 10939 | pc->count[PCOUNT_VALID]++; |
1a392d46 | 10940 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
2815e61f | 10941 | pc->count[PCOUNT_PFCNT]++; |
ff7924f6 PJ |
10942 | |
10943 | if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) | |
10944 | { | |
2815e61f | 10945 | pc->count[PCOUNT_COUNTED]++; |
1a392d46 | 10946 | if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
16286195 | 10947 | zlog_warn ("%s [pcount] %s/%d is counted but flags 0x%x", |
ff7924f6 PJ |
10948 | peer->host, |
10949 | inet_ntop(rn->p.family, &rn->p.u.prefix, | |
10950 | buf, SU_ADDRSTRLEN), | |
10951 | rn->p.prefixlen, | |
10952 | ri->flags); | |
10953 | } | |
10954 | else | |
10955 | { | |
1a392d46 | 10956 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
16286195 | 10957 | zlog_warn ("%s [pcount] %s/%d not counted but flags 0x%x", |
ff7924f6 PJ |
10958 | peer->host, |
10959 | inet_ntop(rn->p.family, &rn->p.u.prefix, | |
10960 | buf, SU_ADDRSTRLEN), | |
10961 | rn->p.prefixlen, | |
10962 | ri->flags); | |
10963 | } | |
10964 | } | |
10965 | } | |
2815e61f PJ |
10966 | return 0; |
10967 | } | |
ff7924f6 | 10968 | |
2815e61f | 10969 | static int |
856ca177 | 10970 | bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_char use_json) |
2815e61f PJ |
10971 | { |
10972 | struct peer_pcounts pcounts = { .peer = peer }; | |
10973 | unsigned int i; | |
856ca177 MS |
10974 | json_object *json = NULL; |
10975 | json_object *json_loop = NULL; | |
10976 | ||
10977 | if (use_json) | |
10978 | { | |
10979 | json = json_object_new_object(); | |
10980 | json_loop = json_object_new_object(); | |
10981 | } | |
2815e61f PJ |
10982 | |
10983 | if (!peer || !peer->bgp || !peer->afc[afi][safi] | |
10984 | || !peer->bgp->rib[afi][safi]) | |
10985 | { | |
856ca177 MS |
10986 | if (use_json) |
10987 | { | |
10988 | json_object_string_add(json, "warning", "No such neighbor or address family"); | |
10989 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
10990 | json_object_free(json); | |
10991 | } | |
10992 | else | |
10993 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
10994 | ||
2815e61f PJ |
10995 | return CMD_WARNING; |
10996 | } | |
10997 | ||
10998 | memset (&pcounts, 0, sizeof(pcounts)); | |
10999 | pcounts.peer = peer; | |
11000 | pcounts.table = peer->bgp->rib[afi][safi]; | |
11001 | ||
11002 | /* in-place call via thread subsystem so as to record execution time | |
856ca177 MS |
11003 | * * stats for the thread-walk (i.e. ensure this can't be blamed on |
11004 | * * on just vty_read()). | |
11005 | * */ | |
87d4a781 | 11006 | thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0); |
6410e93a | 11007 | |
856ca177 MS |
11008 | if (use_json) |
11009 | { | |
11010 | json_object_string_add(json, "prefixCountsFor", peer->host); | |
11011 | json_object_string_add(json, "multiProtocol", afi_safi_print (afi, safi)); | |
11012 | json_object_int_add(json, "pfxCounter", peer->pcount[afi][safi]); | |
11013 | ||
11014 | for (i = 0; i < PCOUNT_MAX; i++) | |
11015 | json_object_int_add(json_loop, pcount_strs[i], pcounts.count[i]); | |
ff7924f6 | 11016 | |
856ca177 | 11017 | json_object_object_add(json, "ribTableWalkCounters", json_loop); |
ff7924f6 | 11018 | |
856ca177 MS |
11019 | if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) |
11020 | { | |
11021 | json_object_string_add(json, "pfxctDriftFor", peer->host); | |
11022 | json_object_string_add(json, "recommended", "Please report this bug, with the above command output"); | |
11023 | } | |
11024 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
11025 | json_object_free(json); | |
11026 | } | |
11027 | else | |
ff7924f6 | 11028 | { |
04b6bdc0 DW |
11029 | |
11030 | if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME)) | |
11031 | { | |
11032 | vty_out (vty, "Prefix counts for %s/%s, %s%s", | |
11033 | peer->hostname, peer->host, afi_safi_print (afi, safi), | |
11034 | VTY_NEWLINE); | |
11035 | } | |
11036 | else | |
11037 | { | |
11038 | vty_out (vty, "Prefix counts for %s, %s%s", | |
11039 | peer->host, afi_safi_print (afi, safi), VTY_NEWLINE); | |
11040 | } | |
11041 | ||
856ca177 MS |
11042 | vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE); |
11043 | vty_out (vty, "%sCounts from RIB table walk:%s%s", | |
11044 | VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); | |
11045 | ||
11046 | for (i = 0; i < PCOUNT_MAX; i++) | |
11047 | vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts.count[i], VTY_NEWLINE); | |
11048 | ||
11049 | if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) | |
11050 | { | |
11051 | vty_out (vty, "%s [pcount] PfxCt drift!%s", | |
11052 | peer->host, VTY_NEWLINE); | |
11053 | vty_out (vty, "Please report this bug, with the above command output%s", | |
11054 | VTY_NEWLINE); | |
11055 | } | |
ff7924f6 PJ |
11056 | } |
11057 | ||
11058 | return CMD_SUCCESS; | |
11059 | } | |
11060 | ||
11061 | DEFUN (show_ip_bgp_neighbor_prefix_counts, | |
11062 | show_ip_bgp_neighbor_prefix_counts_cmd, | |
856ca177 | 11063 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
11064 | SHOW_STR |
11065 | IP_STR | |
11066 | BGP_STR | |
11067 | "Detailed information on TCP and BGP neighbor connections\n" | |
11068 | "Neighbor to display information about\n" | |
11069 | "Neighbor to display information about\n" | |
a80beece | 11070 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11071 | "Display detailed prefix count information\n" |
11072 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
11073 | { |
11074 | struct peer *peer; | |
db7c8528 | 11075 | u_char uj = use_json(argc, argv); |
ff7924f6 | 11076 | |
db7c8528 | 11077 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
ff7924f6 PJ |
11078 | if (! peer) |
11079 | return CMD_WARNING; | |
11080 | ||
db7c8528 | 11081 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); |
ff7924f6 PJ |
11082 | } |
11083 | ||
11084 | DEFUN (show_bgp_ipv6_neighbor_prefix_counts, | |
11085 | show_bgp_ipv6_neighbor_prefix_counts_cmd, | |
856ca177 | 11086 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
11087 | SHOW_STR |
11088 | BGP_STR | |
11089 | "Address family\n" | |
11090 | "Detailed information on TCP and BGP neighbor connections\n" | |
11091 | "Neighbor to display information about\n" | |
11092 | "Neighbor to display information about\n" | |
a80beece | 11093 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11094 | "Display detailed prefix count information\n" |
11095 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
11096 | { |
11097 | struct peer *peer; | |
db7c8528 | 11098 | u_char uj = use_json(argc, argv); |
856ca177 | 11099 | |
db7c8528 | 11100 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
ff7924f6 PJ |
11101 | if (! peer) |
11102 | return CMD_WARNING; | |
11103 | ||
db7c8528 | 11104 | return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj); |
ff7924f6 PJ |
11105 | } |
11106 | ||
11107 | DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, | |
11108 | show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, | |
856ca177 | 11109 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
11110 | SHOW_STR |
11111 | IP_STR | |
11112 | BGP_STR | |
11113 | "Address family\n" | |
11114 | "Address Family modifier\n" | |
11115 | "Address Family modifier\n" | |
11116 | "Detailed information on TCP and BGP neighbor connections\n" | |
11117 | "Neighbor to display information about\n" | |
11118 | "Neighbor to display information about\n" | |
a80beece | 11119 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11120 | "Display detailed prefix count information\n" |
11121 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
11122 | { |
11123 | struct peer *peer; | |
db7c8528 | 11124 | u_char uj = use_json(argc, argv); |
ff7924f6 | 11125 | |
db7c8528 | 11126 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
ff7924f6 PJ |
11127 | if (! peer) |
11128 | return CMD_WARNING; | |
11129 | ||
11130 | if (strncmp (argv[0], "m", 1) == 0) | |
db7c8528 | 11131 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj); |
ff7924f6 | 11132 | |
db7c8528 | 11133 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); |
ff7924f6 PJ |
11134 | } |
11135 | ||
11136 | DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, | |
11137 | show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd, | |
856ca177 | 11138 | "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X|WORD) prefix-counts {json}", |
ff7924f6 PJ |
11139 | SHOW_STR |
11140 | IP_STR | |
11141 | BGP_STR | |
11142 | "Address family\n" | |
11143 | "Address Family modifier\n" | |
11144 | "Address Family modifier\n" | |
11145 | "Detailed information on TCP and BGP neighbor connections\n" | |
11146 | "Neighbor to display information about\n" | |
11147 | "Neighbor to display information about\n" | |
a80beece | 11148 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11149 | "Display detailed prefix count information\n" |
11150 | "JavaScript Object Notation\n") | |
ff7924f6 PJ |
11151 | { |
11152 | struct peer *peer; | |
db7c8528 | 11153 | u_char uj = use_json(argc, argv); |
856ca177 | 11154 | |
db7c8528 | 11155 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
ff7924f6 PJ |
11156 | if (! peer) |
11157 | return CMD_WARNING; | |
11158 | ||
db7c8528 | 11159 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN, uj); |
ff7924f6 PJ |
11160 | } |
11161 | ||
94f2b392 | 11162 | static void |
718e3744 | 11163 | show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, |
856ca177 | 11164 | int in, const char *rmap_name, u_char use_json, json_object *json) |
718e3744 | 11165 | { |
11166 | struct bgp_table *table; | |
11167 | struct bgp_adj_in *ain; | |
11168 | struct bgp_adj_out *adj; | |
11169 | unsigned long output_count; | |
0b16f239 | 11170 | unsigned long filtered_count; |
718e3744 | 11171 | struct bgp_node *rn; |
11172 | int header1 = 1; | |
11173 | struct bgp *bgp; | |
11174 | int header2 = 1; | |
0b16f239 DS |
11175 | struct attr attr; |
11176 | struct attr_extra extra; | |
11177 | int ret; | |
840fced9 | 11178 | struct update_subgroup *subgrp; |
856ca177 MS |
11179 | json_object *json_scode = NULL; |
11180 | json_object *json_ocode = NULL; | |
11181 | json_object *json_ar = NULL; | |
adbac85e | 11182 | struct peer_af *paf; |
856ca177 MS |
11183 | |
11184 | if (use_json) | |
11185 | { | |
11186 | json_scode = json_object_new_object(); | |
11187 | json_ocode = json_object_new_object(); | |
11188 | json_ar = json_object_new_object(); | |
11189 | ||
11190 | json_object_string_add(json_scode, "suppressed", "s"); | |
11191 | json_object_string_add(json_scode, "damped", "d"); | |
11192 | json_object_string_add(json_scode, "history", "h"); | |
11193 | json_object_string_add(json_scode, "valid", "*"); | |
11194 | json_object_string_add(json_scode, "best", ">"); | |
11195 | json_object_string_add(json_scode, "multipath", "="); | |
11196 | json_object_string_add(json_scode, "internal", "i"); | |
11197 | json_object_string_add(json_scode, "ribFailure", "r"); | |
11198 | json_object_string_add(json_scode, "stale", "S"); | |
11199 | json_object_string_add(json_scode, "removed", "R"); | |
11200 | ||
11201 | json_object_string_add(json_ocode, "igp", "i"); | |
11202 | json_object_string_add(json_ocode, "egp", "e"); | |
11203 | json_object_string_add(json_ocode, "incomplete", "?"); | |
11204 | } | |
718e3744 | 11205 | |
bb46e94f | 11206 | bgp = peer->bgp; |
718e3744 | 11207 | |
11208 | if (! bgp) | |
856ca177 MS |
11209 | { |
11210 | if (use_json) | |
11211 | { | |
11212 | json_object_string_add(json, "alert", "no BGP"); | |
11213 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
11214 | json_object_free(json); | |
11215 | } | |
11216 | else | |
11217 | vty_out (vty, "%% No bgp%s", VTY_NEWLINE); | |
11218 | return; | |
11219 | } | |
718e3744 | 11220 | |
11221 | table = bgp->rib[afi][safi]; | |
11222 | ||
0b16f239 | 11223 | output_count = filtered_count = 0; |
840fced9 | 11224 | subgrp = peer_subgroup(peer, afi, safi); |
47fc97cc | 11225 | |
840fced9 | 11226 | if (!in && subgrp && CHECK_FLAG (subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)) |
718e3744 | 11227 | { |
856ca177 MS |
11228 | if (use_json) |
11229 | { | |
11230 | json_object_int_add(json, "bgpTableVersion", table->version); | |
11231 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
11232 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
11233 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
11234 | json_object_string_add(json, "bgpOriginatingDefaultNetwork", "0.0.0.0"); | |
11235 | } | |
11236 | else | |
11237 | { | |
11238 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
11239 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
11240 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
718e3744 | 11241 | |
856ca177 MS |
11242 | vty_out (vty, "Originating default network 0.0.0.0%s%s", |
11243 | VTY_NEWLINE, VTY_NEWLINE); | |
11244 | } | |
718e3744 | 11245 | header1 = 0; |
11246 | } | |
11247 | ||
0b16f239 | 11248 | attr.extra = &extra; |
718e3744 | 11249 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
856ca177 MS |
11250 | { |
11251 | if (in) | |
11252 | { | |
11253 | for (ain = rn->adj_in; ain; ain = ain->next) | |
11254 | { | |
11255 | if (ain->peer == peer) | |
11256 | { | |
11257 | if (header1) | |
11258 | { | |
11259 | if (use_json) | |
11260 | { | |
11261 | json_object_int_add(json, "bgpTableVersion", 0); | |
11262 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
11263 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
11264 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
11265 | } | |
11266 | else | |
11267 | { | |
11268 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
11269 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
11270 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
11271 | } | |
11272 | header1 = 0; | |
11273 | } | |
11274 | if (header2) | |
11275 | { | |
11276 | if (!use_json) | |
11277 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
11278 | header2 = 0; | |
11279 | } | |
11280 | if (ain->attr) | |
11281 | { | |
11282 | bgp_attr_dup(&attr, ain->attr); | |
11283 | if (bgp_input_modifier(peer, &rn->p, &attr, afi, safi, rmap_name) != RMAP_DENY) | |
11284 | { | |
11285 | route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar); | |
11286 | output_count++; | |
11287 | } | |
11288 | else | |
11289 | filtered_count++; | |
11290 | } | |
11291 | } | |
11292 | } | |
11293 | } | |
11294 | else | |
11295 | { | |
adbac85e DW |
11296 | for (adj = rn->adj_out; adj; adj = adj->next) |
11297 | SUBGRP_FOREACH_PEER(adj->subgroup, paf) | |
11298 | if (paf->peer == peer) | |
856ca177 | 11299 | { |
adbac85e | 11300 | if (header1) |
856ca177 | 11301 | { |
adbac85e DW |
11302 | if (use_json) |
11303 | { | |
11304 | json_object_int_add(json, "bgpTableVersion", table->version); | |
11305 | json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id)); | |
11306 | json_object_object_add(json, "bgpStatusCodes", json_scode); | |
11307 | json_object_object_add(json, "bgpOriginCodes", json_ocode); | |
11308 | } | |
11309 | else | |
11310 | { | |
11311 | vty_out (vty, "BGP table version is %" PRIu64 ", local router ID is %s%s", table->version, | |
11312 | inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
11313 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
11314 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); | |
11315 | } | |
11316 | header1 = 0; | |
856ca177 | 11317 | } |
adbac85e DW |
11318 | |
11319 | if (header2) | |
856ca177 | 11320 | { |
adbac85e DW |
11321 | if (!use_json) |
11322 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); | |
11323 | header2 = 0; | |
856ca177 | 11324 | } |
adbac85e DW |
11325 | |
11326 | if (adj->attr) | |
856ca177 | 11327 | { |
adbac85e DW |
11328 | bgp_attr_dup(&attr, adj->attr); |
11329 | ret = bgp_output_modifier(peer, &rn->p, &attr, afi, safi, rmap_name); | |
11330 | if (ret != RMAP_DENY) | |
11331 | { | |
11332 | route_vty_out_tmp (vty, &rn->p, &attr, safi, use_json, json_ar); | |
11333 | output_count++; | |
11334 | } | |
11335 | else | |
11336 | filtered_count++; | |
856ca177 | 11337 | } |
856ca177 | 11338 | } |
856ca177 MS |
11339 | } |
11340 | } | |
11341 | if (use_json) | |
11342 | json_object_object_add(json, "advertisedRoutes", json_ar); | |
47fc97cc | 11343 | |
718e3744 | 11344 | if (output_count != 0) |
856ca177 MS |
11345 | { |
11346 | if (use_json) | |
11347 | json_object_int_add(json, "totalPrefixCounter", output_count); | |
11348 | else | |
11349 | vty_out (vty, "%sTotal number of prefixes %ld%s", | |
11350 | VTY_NEWLINE, output_count, VTY_NEWLINE); | |
11351 | } | |
11352 | if (use_json) | |
11353 | { | |
11354 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
11355 | json_object_free(json); | |
11356 | } | |
11357 | ||
718e3744 | 11358 | } |
11359 | ||
94f2b392 | 11360 | static int |
47fc97cc | 11361 | peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, |
856ca177 MS |
11362 | int in, const char *rmap_name, u_char use_json) |
11363 | { | |
11364 | json_object *json = NULL; | |
11365 | ||
11366 | if (use_json) | |
11367 | json = json_object_new_object(); | |
11368 | ||
11369 | if (!peer || !peer->afc[afi][safi]) | |
718e3744 | 11370 | { |
856ca177 MS |
11371 | if (use_json) |
11372 | { | |
11373 | json_object_string_add(json, "warning", "No such neighbor or address family"); | |
11374 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
11375 | json_object_free(json); | |
11376 | } | |
11377 | else | |
11378 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
11379 | ||
718e3744 | 11380 | return CMD_WARNING; |
11381 | } | |
11382 | ||
856ca177 | 11383 | if (in && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)) |
718e3744 | 11384 | { |
856ca177 MS |
11385 | if (use_json) |
11386 | { | |
11387 | json_object_string_add(json, "warning", "Inbound soft reconfiguration not enabled"); | |
11388 | vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); | |
11389 | json_object_free(json); | |
11390 | } | |
11391 | else | |
11392 | vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", VTY_NEWLINE); | |
11393 | ||
718e3744 | 11394 | return CMD_WARNING; |
11395 | } | |
11396 | ||
856ca177 | 11397 | show_adj_route (vty, peer, afi, safi, in, rmap_name, use_json, json); |
718e3744 | 11398 | |
11399 | return CMD_SUCCESS; | |
11400 | } | |
11401 | ||
2a71e9ce TP |
11402 | DEFUN (show_ip_bgp_view_neighbor_advertised_route, |
11403 | show_ip_bgp_view_neighbor_advertised_route_cmd, | |
6aeb9e78 | 11404 | "show ip bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11405 | SHOW_STR |
11406 | IP_STR | |
11407 | BGP_STR | |
6aeb9e78 DS |
11408 | "BGP view\nBGP VRF\n" |
11409 | "View/VRF name\n" | |
718e3744 | 11410 | "Detailed information on TCP and BGP neighbor connections\n" |
11411 | "Neighbor to display information about\n" | |
11412 | "Neighbor to display information about\n" | |
856ca177 MS |
11413 | "Display the routes advertised to a BGP neighbor\n" |
11414 | "JavaScript Object Notation\n") | |
718e3744 | 11415 | { |
bb46e94f | 11416 | struct peer *peer; |
db7c8528 | 11417 | u_char uj = use_json(argc, argv); |
856ca177 | 11418 | |
6aeb9e78 DS |
11419 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
11420 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
2a71e9ce | 11421 | else |
6aeb9e78 | 11422 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
2a71e9ce | 11423 | |
bb46e94f | 11424 | if (! peer) |
11425 | return CMD_WARNING; | |
0b16f239 | 11426 | |
db7c8528 | 11427 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, NULL, uj); |
718e3744 | 11428 | } |
11429 | ||
0b16f239 | 11430 | DEFUN (show_ip_bgp_neighbor_advertised_route, |
2a71e9ce | 11431 | show_ip_bgp_neighbor_advertised_route_cmd, |
856ca177 | 11432 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
2a71e9ce TP |
11433 | SHOW_STR |
11434 | IP_STR | |
11435 | BGP_STR | |
11436 | "Detailed information on TCP and BGP neighbor connections\n" | |
11437 | "Neighbor to display information about\n" | |
11438 | "Neighbor to display information about\n" | |
a80beece | 11439 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11440 | "Display the routes advertised to a BGP neighbor\n" |
11441 | "JavaScript Object Notation\n") | |
2a71e9ce | 11442 | |
0b16f239 DS |
11443 | { |
11444 | struct peer *peer; | |
ffd0c037 | 11445 | const char *rmap_name = NULL; |
db7c8528 | 11446 | u_char uj = use_json(argc, argv); |
0b16f239 | 11447 | |
db7c8528 | 11448 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
0b16f239 DS |
11449 | |
11450 | if (! peer) | |
11451 | return CMD_WARNING; | |
11452 | ||
856ca177 MS |
11453 | if ((argc == 2 && argv[1] && strcmp(argv[1], "json") != 0) |
11454 | || (argc == 3)) | |
0b16f239 DS |
11455 | rmap_name = argv[1]; |
11456 | ||
db7c8528 | 11457 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj); |
0b16f239 DS |
11458 | } |
11459 | ||
11460 | ALIAS (show_ip_bgp_neighbor_advertised_route, | |
11461 | show_ip_bgp_neighbor_advertised_route_rmap_cmd, | |
856ca177 | 11462 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", |
0b16f239 DS |
11463 | SHOW_STR |
11464 | IP_STR | |
11465 | BGP_STR | |
11466 | "Detailed information on TCP and BGP neighbor connections\n" | |
11467 | "Neighbor to display information about\n" | |
11468 | "Neighbor to display information about\n" | |
11469 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11470 | "Display the routes advertised to a BGP neighbor\n" |
11471 | "JavaScript Object Notation\n") | |
0b16f239 | 11472 | |
718e3744 | 11473 | DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, |
11474 | show_ip_bgp_ipv4_neighbor_advertised_route_cmd, | |
856ca177 | 11475 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11476 | SHOW_STR |
11477 | IP_STR | |
11478 | BGP_STR | |
11479 | "Address family\n" | |
11480 | "Address Family modifier\n" | |
11481 | "Address Family modifier\n" | |
11482 | "Detailed information on TCP and BGP neighbor connections\n" | |
11483 | "Neighbor to display information about\n" | |
11484 | "Neighbor to display information about\n" | |
a80beece | 11485 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11486 | "Display the routes advertised to a BGP neighbor\n" |
11487 | "JavaScript Object Notation\n") | |
718e3744 | 11488 | { |
bb46e94f | 11489 | struct peer *peer; |
ffd0c037 | 11490 | const char *rmap_name = NULL; |
db7c8528 | 11491 | u_char uj = use_json(argc, argv); |
856ca177 | 11492 | |
db7c8528 | 11493 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 11494 | if (! peer) |
11495 | return CMD_WARNING; | |
11496 | ||
856ca177 | 11497 | if ((argc == 4) || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
0b16f239 DS |
11498 | rmap_name = argv[2]; |
11499 | ||
718e3744 | 11500 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 11501 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0, rmap_name, uj); |
856ca177 | 11502 | else |
db7c8528 | 11503 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0, rmap_name, uj); |
718e3744 | 11504 | } |
11505 | ||
0b16f239 DS |
11506 | ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route, |
11507 | show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd, | |
856ca177 | 11508 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes route-map WORD {json}", |
0b16f239 DS |
11509 | SHOW_STR |
11510 | IP_STR | |
11511 | BGP_STR | |
11512 | "Address family\n" | |
11513 | "Address Family modifier\n" | |
11514 | "Address Family modifier\n" | |
11515 | "Detailed information on TCP and BGP neighbor connections\n" | |
11516 | "Neighbor to display information about\n" | |
11517 | "Neighbor to display information about\n" | |
11518 | "Neighbor on bgp configured interface\n" | |
11519 | "Display the routes advertised to a BGP neighbor\n" | |
856ca177 MS |
11520 | "Route-map to control what is displayed\n" |
11521 | "JavaScript Object Notation\n") | |
0b16f239 | 11522 | |
718e3744 | 11523 | #ifdef HAVE_IPV6 |
bb46e94f | 11524 | DEFUN (show_bgp_view_neighbor_advertised_route, |
11525 | show_bgp_view_neighbor_advertised_route_cmd, | |
6aeb9e78 | 11526 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11527 | SHOW_STR |
11528 | BGP_STR | |
6aeb9e78 DS |
11529 | "BGP view\nBGP VRF\n" |
11530 | "View/VRF name\n" | |
718e3744 | 11531 | "Detailed information on TCP and BGP neighbor connections\n" |
11532 | "Neighbor to display information about\n" | |
11533 | "Neighbor to display information about\n" | |
a80beece | 11534 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11535 | "Display the routes advertised to a BGP neighbor\n" |
11536 | "JavaScript Object Notation\n") | |
718e3744 | 11537 | { |
bb46e94f | 11538 | struct peer *peer; |
db7c8528 | 11539 | u_char uj = use_json(argc, argv); |
856ca177 | 11540 | |
6aeb9e78 DS |
11541 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
11542 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 11543 | else |
6aeb9e78 | 11544 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 11545 | |
11546 | if (! peer) | |
0b16f239 | 11547 | return CMD_WARNING; |
bb46e94f | 11548 | |
db7c8528 | 11549 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, NULL, uj); |
47fc97cc DS |
11550 | } |
11551 | ||
0b16f239 DS |
11552 | ALIAS (show_bgp_view_neighbor_advertised_route, |
11553 | show_bgp_view_ipv6_neighbor_advertised_route_cmd, | |
6aeb9e78 | 11554 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
0b16f239 DS |
11555 | SHOW_STR |
11556 | BGP_STR | |
6aeb9e78 DS |
11557 | "BGP view\nBGP VRF\n" |
11558 | "View/VRF name\n" | |
0b16f239 DS |
11559 | "Address family\n" |
11560 | "Detailed information on TCP and BGP neighbor connections\n" | |
11561 | "Neighbor to display information about\n" | |
11562 | "Neighbor to display information about\n" | |
11563 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11564 | "Display the routes advertised to a BGP neighbor\n" |
11565 | "JavaScript Object Notation\n") | |
0b16f239 | 11566 | |
0b16f239 DS |
11567 | DEFUN (show_bgp_neighbor_advertised_route, |
11568 | show_bgp_neighbor_advertised_route_cmd, | |
856ca177 | 11569 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
bb46e94f | 11570 | SHOW_STR |
11571 | BGP_STR | |
bb46e94f | 11572 | "Detailed information on TCP and BGP neighbor connections\n" |
11573 | "Neighbor to display information about\n" | |
11574 | "Neighbor to display information about\n" | |
a80beece | 11575 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11576 | "Display the routes advertised to a BGP neighbor\n" |
11577 | "JavaScript Object Notation\n") | |
0b16f239 | 11578 | |
bb46e94f | 11579 | { |
11580 | struct peer *peer; | |
ffd0c037 | 11581 | const char *rmap_name = NULL; |
db7c8528 | 11582 | u_char uj = use_json(argc, argv); |
bb46e94f | 11583 | |
db7c8528 | 11584 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
856ca177 MS |
11585 | |
11586 | if (!peer) | |
bb46e94f | 11587 | return CMD_WARNING; |
11588 | ||
856ca177 | 11589 | if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)) |
0b16f239 DS |
11590 | rmap_name = argv[1]; |
11591 | ||
db7c8528 | 11592 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0, rmap_name, uj); |
718e3744 | 11593 | } |
11594 | ||
0b16f239 DS |
11595 | ALIAS (show_bgp_neighbor_advertised_route, |
11596 | show_bgp_ipv6_neighbor_advertised_route_cmd, | |
856ca177 | 11597 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11598 | SHOW_STR |
11599 | BGP_STR | |
11600 | "Address family\n" | |
11601 | "Detailed information on TCP and BGP neighbor connections\n" | |
11602 | "Neighbor to display information about\n" | |
11603 | "Neighbor to display information about\n" | |
a80beece | 11604 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11605 | "Display the routes advertised to a BGP neighbor\n" |
11606 | "JavaScript Object Notation\n") | |
718e3744 | 11607 | |
11608 | /* old command */ | |
0b16f239 | 11609 | ALIAS (show_bgp_neighbor_advertised_route, |
718e3744 | 11610 | ipv6_bgp_neighbor_advertised_route_cmd, |
856ca177 | 11611 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11612 | SHOW_STR |
11613 | IPV6_STR | |
11614 | BGP_STR | |
11615 | "Detailed information on TCP and BGP neighbor connections\n" | |
11616 | "Neighbor to display information about\n" | |
11617 | "Neighbor to display information about\n" | |
a80beece | 11618 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11619 | "Display the routes advertised to a BGP neighbor\n" |
11620 | "JavaScript Object Notation\n") | |
bb46e94f | 11621 | |
718e3744 | 11622 | /* old command */ |
11623 | DEFUN (ipv6_mbgp_neighbor_advertised_route, | |
11624 | ipv6_mbgp_neighbor_advertised_route_cmd, | |
856ca177 | 11625 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}", |
718e3744 | 11626 | SHOW_STR |
11627 | IPV6_STR | |
11628 | MBGP_STR | |
11629 | "Detailed information on TCP and BGP neighbor connections\n" | |
11630 | "Neighbor to display information about\n" | |
11631 | "Neighbor to display information about\n" | |
a80beece DS |
11632 | "Neighbor on bgp configured interface\n" |
11633 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11634 | "Display the routes advertised to a BGP neighbor\n" |
11635 | "JavaScript Object Notation\n") | |
718e3744 | 11636 | { |
bb46e94f | 11637 | struct peer *peer; |
db7c8528 | 11638 | u_char uj = use_json(argc, argv); |
856ca177 | 11639 | |
db7c8528 | 11640 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 11641 | if (! peer) |
856ca177 | 11642 | return CMD_WARNING; |
bb46e94f | 11643 | |
47e9b292 | 11644 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 11645 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0, NULL, uj); |
718e3744 | 11646 | } |
11647 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 11648 | |
0b16f239 DS |
11649 | DEFUN (show_bgp_view_neighbor_received_routes, |
11650 | show_bgp_view_neighbor_received_routes_cmd, | |
6aeb9e78 | 11651 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
0b16f239 DS |
11652 | SHOW_STR |
11653 | BGP_STR | |
6aeb9e78 DS |
11654 | "BGP view\nBGP VRF\n" |
11655 | "View/VRF name\n" | |
0b16f239 DS |
11656 | "Detailed information on TCP and BGP neighbor connections\n" |
11657 | "Neighbor to display information about\n" | |
11658 | "Neighbor to display information about\n" | |
11659 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11660 | "Display the received routes from neighbor\n" |
11661 | "JavaScript Object Notation\n") | |
0b16f239 DS |
11662 | { |
11663 | struct peer *peer; | |
db7c8528 | 11664 | u_char uj = use_json(argc, argv); |
856ca177 | 11665 | |
db7c8528 | 11666 | if (uj) |
856ca177 | 11667 | { |
6aeb9e78 DS |
11668 | if (argc == 4) |
11669 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
856ca177 | 11670 | else |
6aeb9e78 | 11671 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
856ca177 | 11672 | } |
0b16f239 | 11673 | else |
856ca177 | 11674 | { |
6aeb9e78 DS |
11675 | if (argc == 3) |
11676 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
856ca177 | 11677 | else |
6aeb9e78 | 11678 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
856ca177 | 11679 | } |
0b16f239 DS |
11680 | |
11681 | if (! peer) | |
11682 | return CMD_WARNING; | |
11683 | ||
db7c8528 | 11684 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1, NULL, uj); |
0b16f239 DS |
11685 | } |
11686 | ||
2a71e9ce TP |
11687 | DEFUN (show_ip_bgp_view_neighbor_received_routes, |
11688 | show_ip_bgp_view_neighbor_received_routes_cmd, | |
6aeb9e78 | 11689 | "show ip bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 11690 | SHOW_STR |
11691 | IP_STR | |
11692 | BGP_STR | |
6aeb9e78 DS |
11693 | "BGP view\nBGP VRF\n" |
11694 | "View/VRF name\n" | |
718e3744 | 11695 | "Detailed information on TCP and BGP neighbor connections\n" |
11696 | "Neighbor to display information about\n" | |
11697 | "Neighbor to display information about\n" | |
a80beece | 11698 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11699 | "Display the received routes from neighbor\n" |
11700 | "JavaScript Object Notation\n") | |
718e3744 | 11701 | { |
bb46e94f | 11702 | struct peer *peer; |
db7c8528 | 11703 | u_char uj = use_json(argc, argv); |
856ca177 | 11704 | |
6aeb9e78 DS |
11705 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
11706 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
2a71e9ce | 11707 | else |
6aeb9e78 | 11708 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
2a71e9ce | 11709 | |
bb46e94f | 11710 | if (! peer) |
11711 | return CMD_WARNING; | |
11712 | ||
db7c8528 | 11713 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, NULL, uj); |
718e3744 | 11714 | } |
11715 | ||
0b16f239 DS |
11716 | ALIAS (show_bgp_view_neighbor_received_routes, |
11717 | show_bgp_view_ipv6_neighbor_received_routes_cmd, | |
6aeb9e78 | 11718 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
0b16f239 DS |
11719 | SHOW_STR |
11720 | BGP_STR | |
6aeb9e78 DS |
11721 | "BGP view\nBGP VRF\n" |
11722 | "View/VRF name\n" | |
0b16f239 DS |
11723 | "Address family\n" |
11724 | "Detailed information on TCP and BGP neighbor connections\n" | |
11725 | "Neighbor to display information about\n" | |
11726 | "Neighbor to display information about\n" | |
11727 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11728 | "Display the received routes from neighbor\n" |
11729 | "JavaScript Object Notation\n") | |
0b16f239 DS |
11730 | |
11731 | DEFUN (show_ip_bgp_neighbor_received_routes, | |
2a71e9ce | 11732 | show_ip_bgp_neighbor_received_routes_cmd, |
856ca177 | 11733 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
2a71e9ce TP |
11734 | SHOW_STR |
11735 | IP_STR | |
11736 | BGP_STR | |
11737 | "Detailed information on TCP and BGP neighbor connections\n" | |
11738 | "Neighbor to display information about\n" | |
11739 | "Neighbor to display information about\n" | |
a80beece | 11740 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11741 | "Display the received routes from neighbor\n" |
11742 | "JavaScript Object Notation\n") | |
2a71e9ce | 11743 | |
0b16f239 DS |
11744 | { |
11745 | struct peer *peer; | |
ffd0c037 | 11746 | const char *rmap_name = NULL; |
db7c8528 | 11747 | u_char uj = use_json(argc, argv); |
0b16f239 | 11748 | |
db7c8528 | 11749 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
0b16f239 DS |
11750 | |
11751 | if (! peer) | |
11752 | return CMD_WARNING; | |
11753 | ||
856ca177 | 11754 | if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0)) |
0b16f239 DS |
11755 | rmap_name = argv[1]; |
11756 | ||
db7c8528 | 11757 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj); |
0b16f239 DS |
11758 | } |
11759 | ||
11760 | ALIAS (show_ip_bgp_neighbor_received_routes, | |
11761 | show_ip_bgp_neighbor_received_routes_rmap_cmd, | |
856ca177 | 11762 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", |
0b16f239 DS |
11763 | SHOW_STR |
11764 | IP_STR | |
11765 | BGP_STR | |
11766 | "Detailed information on TCP and BGP neighbor connections\n" | |
11767 | "Neighbor to display information about\n" | |
11768 | "Neighbor to display information about\n" | |
11769 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11770 | "Display the received routes from neighbor\n" |
11771 | "JavaScript Object Notation\n") | |
0b16f239 | 11772 | |
718e3744 | 11773 | DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, |
11774 | show_ip_bgp_ipv4_neighbor_received_routes_cmd, | |
856ca177 | 11775 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 11776 | SHOW_STR |
11777 | IP_STR | |
11778 | BGP_STR | |
11779 | "Address family\n" | |
11780 | "Address Family modifier\n" | |
11781 | "Address Family modifier\n" | |
11782 | "Detailed information on TCP and BGP neighbor connections\n" | |
11783 | "Neighbor to display information about\n" | |
11784 | "Neighbor to display information about\n" | |
a80beece | 11785 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
11786 | "Display the received routes from neighbor\n" |
11787 | "JavaScript Object Notation\n") | |
718e3744 | 11788 | { |
bb46e94f | 11789 | struct peer *peer; |
ffd0c037 | 11790 | const char *rmap_name = NULL; |
db7c8528 | 11791 | u_char uj = use_json(argc, argv); |
bb46e94f | 11792 | |
db7c8528 | 11793 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 11794 | if (! peer) |
11795 | return CMD_WARNING; | |
0b16f239 | 11796 | |
856ca177 | 11797 | if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) |
0b16f239 DS |
11798 | rmap_name = argv[2]; |
11799 | ||
718e3744 | 11800 | if (strncmp (argv[0], "m", 1) == 0) |
db7c8528 | 11801 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1, rmap_name, uj); |
856ca177 | 11802 | else |
db7c8528 | 11803 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1, rmap_name, uj); |
718e3744 | 11804 | } |
11805 | ||
0b16f239 DS |
11806 | ALIAS (show_ip_bgp_ipv4_neighbor_received_routes, |
11807 | show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd, | |
856ca177 | 11808 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received-routes route-map WORD {json}", |
0b16f239 DS |
11809 | SHOW_STR |
11810 | IP_STR | |
11811 | BGP_STR | |
11812 | "Address family\n" | |
11813 | "Address Family modifier\n" | |
11814 | "Address Family modifier\n" | |
11815 | "Detailed information on TCP and BGP neighbor connections\n" | |
11816 | "Neighbor to display information about\n" | |
11817 | "Neighbor to display information about\n" | |
11818 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
11819 | "Display the received routes from neighbor\n" |
11820 | "JavaScript Object Notation\n") | |
0b16f239 | 11821 | |
95cbbd2a ML |
11822 | DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes, |
11823 | show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd, | |
11824 | #ifdef HAVE_IPV6 | |
6aeb9e78 | 11825 | "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", |
95cbbd2a | 11826 | #else |
6aeb9e78 | 11827 | "show bgp (view|vrf) WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}", |
95cbbd2a ML |
11828 | #endif |
11829 | SHOW_STR | |
11830 | BGP_STR | |
6aeb9e78 DS |
11831 | "BGP view\nBGP VRF\n" |
11832 | "View/VRF name\n" | |
95cbbd2a ML |
11833 | "Address family\n" |
11834 | #ifdef HAVE_IPV6 | |
11835 | "Address family\n" | |
11836 | #endif | |
11837 | "Address family modifier\n" | |
11838 | "Address family modifier\n" | |
11839 | "Detailed information on TCP and BGP neighbor connections\n" | |
11840 | "Neighbor to display information about\n" | |
11841 | "Neighbor to display information about\n" | |
a80beece | 11842 | "Neighbor on bgp configured interface\n" |
95cbbd2a | 11843 | "Display the advertised routes to neighbor\n" |
856ca177 MS |
11844 | "Display the received routes from neighbor\n" |
11845 | "JavaScript Object Notation\n") | |
95cbbd2a ML |
11846 | { |
11847 | int afi; | |
11848 | int safi; | |
11849 | int in; | |
11850 | struct peer *peer; | |
db7c8528 | 11851 | u_char uj = use_json(argc, argv); |
856ca177 | 11852 | |
6aeb9e78 | 11853 | peer = peer_lookup_in_view (vty, argv[1], argv[4], uj); |
95cbbd2a ML |
11854 | |
11855 | if (! peer) | |
11856 | return CMD_WARNING; | |
11857 | ||
6aeb9e78 DS |
11858 | afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
11859 | safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; | |
11860 | in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0; | |
95cbbd2a | 11861 | |
db7c8528 | 11862 | return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj); |
95cbbd2a ML |
11863 | } |
11864 | ||
718e3744 | 11865 | DEFUN (show_ip_bgp_neighbor_received_prefix_filter, |
11866 | show_ip_bgp_neighbor_received_prefix_filter_cmd, | |
856ca177 | 11867 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 11868 | SHOW_STR |
11869 | IP_STR | |
11870 | BGP_STR | |
11871 | "Detailed information on TCP and BGP neighbor connections\n" | |
11872 | "Neighbor to display information about\n" | |
11873 | "Neighbor to display information about\n" | |
a80beece | 11874 | "Neighbor on bgp configured interface\n" |
718e3744 | 11875 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
11876 | "Display the prefixlist filter\n" |
11877 | "JavaScript Object Notation\n") | |
718e3744 | 11878 | { |
11879 | char name[BUFSIZ]; | |
c63b83fe | 11880 | union sockunion su; |
718e3744 | 11881 | struct peer *peer; |
c63b83fe | 11882 | int count, ret; |
db7c8528 | 11883 | u_char uj = use_json(argc, argv); |
718e3744 | 11884 | |
c63b83fe JBD |
11885 | ret = str2sockunion (argv[0], &su); |
11886 | if (ret < 0) | |
11887 | { | |
a80beece | 11888 | peer = peer_lookup_by_conf_if (NULL, argv[0]); |
856ca177 | 11889 | if (! peer) |
a80beece | 11890 | { |
db7c8528 | 11891 | if (uj) |
856ca177 MS |
11892 | { |
11893 | json_object *json_no = NULL; | |
11894 | json_object *json_sub = NULL; | |
11895 | json_no = json_object_new_object(); | |
11896 | json_sub = json_object_new_object(); | |
11897 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
11898 | json_object_string_add(json_sub, "warningCause", argv[0]); | |
11899 | json_object_object_add(json_no, "detail", json_sub); | |
11900 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11901 | json_object_free(json_no); | |
11902 | } | |
11903 | else | |
11904 | vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE); | |
a80beece DS |
11905 | return CMD_WARNING; |
11906 | } | |
11907 | } | |
11908 | else | |
11909 | { | |
11910 | peer = peer_lookup (NULL, &su); | |
11911 | if (! peer) | |
856ca177 | 11912 | { |
db7c8528 | 11913 | if (uj) |
856ca177 MS |
11914 | { |
11915 | json_object *json_no = NULL; | |
11916 | json_no = json_object_new_object(); | |
11917 | json_object_string_add(json_no, "warning", "Peer not found"); | |
11918 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11919 | json_object_free(json_no); | |
11920 | } | |
11921 | else | |
11922 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
11923 | return CMD_WARNING; | |
11924 | } | |
c63b83fe | 11925 | } |
718e3744 | 11926 | |
11927 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); | |
db7c8528 | 11928 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); |
718e3744 | 11929 | if (count) |
11930 | { | |
db7c8528 | 11931 | if (!uj) |
856ca177 | 11932 | vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); |
db7c8528 | 11933 | prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); |
856ca177 MS |
11934 | } |
11935 | else | |
11936 | { | |
db7c8528 | 11937 | if (uj) |
856ca177 MS |
11938 | { |
11939 | json_object *json_no = NULL; | |
11940 | json_no = json_object_new_object(); | |
11941 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
11942 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11943 | json_object_free(json_no); | |
11944 | } | |
11945 | else | |
11946 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
718e3744 | 11947 | } |
11948 | ||
11949 | return CMD_SUCCESS; | |
11950 | } | |
11951 | ||
11952 | DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, | |
11953 | show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd, | |
856ca177 | 11954 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 11955 | SHOW_STR |
11956 | IP_STR | |
11957 | BGP_STR | |
11958 | "Address family\n" | |
11959 | "Address Family modifier\n" | |
11960 | "Address Family modifier\n" | |
11961 | "Detailed information on TCP and BGP neighbor connections\n" | |
11962 | "Neighbor to display information about\n" | |
11963 | "Neighbor to display information about\n" | |
a80beece | 11964 | "Neighbor on bgp configured interface\n" |
718e3744 | 11965 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
11966 | "Display the prefixlist filter\n" |
11967 | "JavaScript Object Notation\n") | |
718e3744 | 11968 | { |
11969 | char name[BUFSIZ]; | |
c63b83fe | 11970 | union sockunion su; |
718e3744 | 11971 | struct peer *peer; |
c63b83fe | 11972 | int count, ret; |
db7c8528 | 11973 | u_char uj = use_json(argc, argv); |
718e3744 | 11974 | |
c63b83fe JBD |
11975 | ret = str2sockunion (argv[1], &su); |
11976 | if (ret < 0) | |
11977 | { | |
a80beece | 11978 | peer = peer_lookup_by_conf_if (NULL, argv[1]); |
856ca177 | 11979 | if (! peer) |
a80beece | 11980 | { |
db7c8528 | 11981 | if (uj) |
856ca177 MS |
11982 | { |
11983 | json_object *json_no = NULL; | |
11984 | json_object *json_sub = NULL; | |
11985 | json_no = json_object_new_object(); | |
11986 | json_sub = json_object_new_object(); | |
11987 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
11988 | json_object_string_add(json_sub, "warningCause", argv[1]); | |
11989 | json_object_object_add(json_no, "detail", json_sub); | |
11990 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
11991 | json_object_free(json_no); | |
11992 | } | |
11993 | else | |
11994 | vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE); | |
a80beece DS |
11995 | return CMD_WARNING; |
11996 | } | |
11997 | } | |
11998 | else | |
11999 | { | |
12000 | peer = peer_lookup (NULL, &su); | |
12001 | if (! peer) | |
856ca177 | 12002 | { |
db7c8528 | 12003 | if (uj) |
856ca177 MS |
12004 | { |
12005 | json_object *json_no = NULL; | |
12006 | json_no = json_object_new_object(); | |
12007 | json_object_string_add(json_no, "warning", "Peer not found"); | |
12008 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12009 | json_object_free(json_no); | |
12010 | } | |
12011 | else | |
12012 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
12013 | return CMD_WARNING; | |
12014 | } | |
c63b83fe | 12015 | } |
718e3744 | 12016 | |
12017 | if (strncmp (argv[0], "m", 1) == 0) | |
12018 | { | |
12019 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST); | |
db7c8528 | 12020 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); |
718e3744 | 12021 | if (count) |
856ca177 | 12022 | { |
db7c8528 | 12023 | if (!uj) |
856ca177 | 12024 | vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE); |
db7c8528 | 12025 | prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); |
856ca177 MS |
12026 | } |
12027 | else | |
12028 | { | |
db7c8528 | 12029 | if (uj) |
856ca177 MS |
12030 | { |
12031 | json_object *json_no = NULL; | |
12032 | json_no = json_object_new_object(); | |
12033 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
12034 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12035 | json_object_free(json_no); | |
12036 | } | |
12037 | else | |
12038 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
12039 | } | |
718e3744 | 12040 | } |
12041 | else | |
12042 | { | |
12043 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); | |
db7c8528 | 12044 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name, uj); |
718e3744 | 12045 | if (count) |
856ca177 | 12046 | { |
db7c8528 | 12047 | if (!uj) |
856ca177 | 12048 | vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); |
db7c8528 | 12049 | prefix_bgp_show_prefix_list (vty, AFI_IP, name, uj); |
856ca177 MS |
12050 | } |
12051 | else | |
12052 | { | |
db7c8528 | 12053 | if (uj) |
856ca177 MS |
12054 | { |
12055 | json_object *json_no = NULL; | |
12056 | json_no = json_object_new_object(); | |
12057 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
12058 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12059 | json_object_free(json_no); | |
12060 | } | |
12061 | else | |
12062 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
12063 | } | |
718e3744 | 12064 | } |
12065 | ||
12066 | return CMD_SUCCESS; | |
12067 | } | |
718e3744 | 12068 | #ifdef HAVE_IPV6 |
bb46e94f | 12069 | ALIAS (show_bgp_view_neighbor_received_routes, |
718e3744 | 12070 | show_bgp_neighbor_received_routes_cmd, |
856ca177 | 12071 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 12072 | SHOW_STR |
12073 | BGP_STR | |
12074 | "Detailed information on TCP and BGP neighbor connections\n" | |
12075 | "Neighbor to display information about\n" | |
12076 | "Neighbor to display information about\n" | |
a80beece | 12077 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12078 | "Display the received routes from neighbor\n" |
12079 | "JavaScript Object Notation\n") | |
718e3744 | 12080 | |
bb46e94f | 12081 | ALIAS (show_bgp_view_neighbor_received_routes, |
718e3744 | 12082 | show_bgp_ipv6_neighbor_received_routes_cmd, |
856ca177 | 12083 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
0b16f239 DS |
12084 | SHOW_STR |
12085 | BGP_STR | |
12086 | "Address family\n" | |
12087 | "Detailed information on TCP and BGP neighbor connections\n" | |
12088 | "Neighbor to display information about\n" | |
12089 | "Neighbor to display information about\n" | |
12090 | "Neighbor on bgp configured interface\n" | |
856ca177 MS |
12091 | "Display the received routes from neighbor\n" |
12092 | "JavaScript Object Notation\n") | |
0b16f239 | 12093 | |
718e3744 | 12094 | DEFUN (show_bgp_neighbor_received_prefix_filter, |
12095 | show_bgp_neighbor_received_prefix_filter_cmd, | |
856ca177 | 12096 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 12097 | SHOW_STR |
12098 | BGP_STR | |
12099 | "Detailed information on TCP and BGP neighbor connections\n" | |
12100 | "Neighbor to display information about\n" | |
12101 | "Neighbor to display information about\n" | |
a80beece | 12102 | "Neighbor on bgp configured interface\n" |
718e3744 | 12103 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12104 | "Display the prefixlist filter\n" |
12105 | "JavaScript Object Notation\n") | |
718e3744 | 12106 | { |
12107 | char name[BUFSIZ]; | |
c63b83fe | 12108 | union sockunion su; |
718e3744 | 12109 | struct peer *peer; |
c63b83fe | 12110 | int count, ret; |
db7c8528 | 12111 | u_char uj = use_json(argc, argv); |
718e3744 | 12112 | |
c63b83fe JBD |
12113 | ret = str2sockunion (argv[0], &su); |
12114 | if (ret < 0) | |
12115 | { | |
a80beece | 12116 | peer = peer_lookup_by_conf_if (NULL, argv[0]); |
856ca177 | 12117 | if (! peer) |
a80beece | 12118 | { |
db7c8528 | 12119 | if (uj) |
856ca177 MS |
12120 | { |
12121 | json_object *json_no = NULL; | |
12122 | json_object *json_sub = NULL; | |
12123 | json_no = json_object_new_object(); | |
12124 | json_sub = json_object_new_object(); | |
12125 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
12126 | json_object_string_add(json_sub, "warningCause", argv[0]); | |
12127 | json_object_object_add(json_no, "detail", json_sub); | |
12128 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12129 | json_object_free(json_no); | |
12130 | } | |
12131 | else | |
12132 | vty_out (vty, "%% Malformed address or name: %s%s", argv[0], VTY_NEWLINE); | |
a80beece DS |
12133 | return CMD_WARNING; |
12134 | } | |
12135 | } | |
12136 | else | |
12137 | { | |
12138 | peer = peer_lookup (NULL, &su); | |
12139 | if (! peer) | |
856ca177 | 12140 | { |
db7c8528 | 12141 | if (uj) |
856ca177 MS |
12142 | { |
12143 | json_object *json_no = NULL; | |
12144 | json_no = json_object_new_object(); | |
12145 | json_object_string_add(json_no, "warning", "No Peer"); | |
12146 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12147 | json_object_free(json_no); | |
12148 | } | |
12149 | else | |
12150 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
12151 | return CMD_WARNING; | |
12152 | } | |
c63b83fe | 12153 | } |
718e3744 | 12154 | |
12155 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); | |
db7c8528 | 12156 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj); |
718e3744 | 12157 | if (count) |
12158 | { | |
db7c8528 | 12159 | if (!uj) |
856ca177 | 12160 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
db7c8528 | 12161 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj); |
856ca177 MS |
12162 | } |
12163 | else | |
12164 | { | |
db7c8528 | 12165 | if (uj) |
856ca177 MS |
12166 | { |
12167 | json_object *json_no = NULL; | |
12168 | json_no = json_object_new_object(); | |
12169 | json_object_boolean_true_add(json_no, "noFuntionalOutput"); | |
12170 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12171 | json_object_free(json_no); | |
12172 | } | |
12173 | else | |
12174 | vty_out (vty, "No functional output%s", VTY_NEWLINE); | |
718e3744 | 12175 | } |
12176 | ||
12177 | return CMD_SUCCESS; | |
12178 | } | |
12179 | ||
12180 | ALIAS (show_bgp_neighbor_received_prefix_filter, | |
12181 | show_bgp_ipv6_neighbor_received_prefix_filter_cmd, | |
856ca177 | 12182 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
718e3744 | 12183 | SHOW_STR |
12184 | BGP_STR | |
12185 | "Address family\n" | |
12186 | "Detailed information on TCP and BGP neighbor connections\n" | |
12187 | "Neighbor to display information about\n" | |
12188 | "Neighbor to display information about\n" | |
a80beece | 12189 | "Neighbor on bgp configured interface\n" |
718e3744 | 12190 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12191 | "Display the prefixlist filter\n" |
12192 | "JavaScript Object Notation\n") | |
718e3744 | 12193 | |
12194 | /* old command */ | |
bb46e94f | 12195 | ALIAS (show_bgp_view_neighbor_received_routes, |
718e3744 | 12196 | ipv6_bgp_neighbor_received_routes_cmd, |
856ca177 | 12197 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 12198 | SHOW_STR |
12199 | IPV6_STR | |
12200 | BGP_STR | |
12201 | "Detailed information on TCP and BGP neighbor connections\n" | |
12202 | "Neighbor to display information about\n" | |
12203 | "Neighbor to display information about\n" | |
a80beece | 12204 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12205 | "Display the received routes from neighbor\n" |
12206 | "JavaScript Object Notation\n") | |
718e3744 | 12207 | |
12208 | /* old command */ | |
12209 | DEFUN (ipv6_mbgp_neighbor_received_routes, | |
12210 | ipv6_mbgp_neighbor_received_routes_cmd, | |
856ca177 | 12211 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}", |
718e3744 | 12212 | SHOW_STR |
12213 | IPV6_STR | |
12214 | MBGP_STR | |
12215 | "Detailed information on TCP and BGP neighbor connections\n" | |
12216 | "Neighbor to display information about\n" | |
12217 | "Neighbor to display information about\n" | |
a80beece | 12218 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12219 | "Display the received routes from neighbor\n" |
12220 | "JavaScript Object Notation\n") | |
718e3744 | 12221 | { |
bb46e94f | 12222 | struct peer *peer; |
db7c8528 | 12223 | u_char uj = use_json(argc, argv); |
bb46e94f | 12224 | |
db7c8528 | 12225 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12226 | if (! peer) |
12227 | return CMD_WARNING; | |
12228 | ||
47e9b292 | 12229 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
db7c8528 | 12230 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1, NULL, uj); |
bb46e94f | 12231 | } |
12232 | ||
12233 | DEFUN (show_bgp_view_neighbor_received_prefix_filter, | |
12234 | show_bgp_view_neighbor_received_prefix_filter_cmd, | |
6aeb9e78 | 12235 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
bb46e94f | 12236 | SHOW_STR |
12237 | BGP_STR | |
6aeb9e78 DS |
12238 | "BGP view\nBGP VRF\n" |
12239 | "View/VRF name\n" | |
bb46e94f | 12240 | "Detailed information on TCP and BGP neighbor connections\n" |
12241 | "Neighbor to display information about\n" | |
12242 | "Neighbor to display information about\n" | |
a80beece | 12243 | "Neighbor on bgp configured interface\n" |
bb46e94f | 12244 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12245 | "Display the prefixlist filter\n" |
12246 | "JavaScript Object Notation\n") | |
bb46e94f | 12247 | { |
12248 | char name[BUFSIZ]; | |
c63b83fe | 12249 | union sockunion su; |
bb46e94f | 12250 | struct peer *peer; |
12251 | struct bgp *bgp; | |
c63b83fe | 12252 | int count, ret; |
db7c8528 | 12253 | u_char uj = use_json(argc, argv); |
bb46e94f | 12254 | |
12255 | /* BGP structure lookup. */ | |
6aeb9e78 | 12256 | bgp = bgp_lookup_by_name (argv[1]); |
bb46e94f | 12257 | if (bgp == NULL) |
856ca177 | 12258 | { |
db7c8528 | 12259 | if (uj) |
856ca177 MS |
12260 | { |
12261 | json_object *json_no = NULL; | |
12262 | json_no = json_object_new_object(); | |
12263 | json_object_string_add(json_no, "warning", "Can't find BGP view"); | |
12264 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12265 | json_object_free(json_no); | |
12266 | } | |
12267 | else | |
6aeb9e78 | 12268 | vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE); |
856ca177 MS |
12269 | return CMD_WARNING; |
12270 | } | |
12271 | ||
6aeb9e78 | 12272 | ret = str2sockunion (argv[2], &su); |
c63b83fe JBD |
12273 | if (ret < 0) |
12274 | { | |
6aeb9e78 | 12275 | peer = peer_lookup_by_conf_if (bgp, argv[2]); |
856ca177 | 12276 | if (! peer) |
a80beece | 12277 | { |
db7c8528 | 12278 | if (uj) |
856ca177 MS |
12279 | { |
12280 | json_object *json_no = NULL; | |
12281 | json_object *json_sub = NULL; | |
12282 | json_no = json_object_new_object(); | |
12283 | json_sub = json_object_new_object(); | |
12284 | json_object_string_add(json_no, "warning", "Malformed address or name"); | |
6aeb9e78 | 12285 | json_object_string_add(json_sub, "warningCause", argv[2]); |
856ca177 MS |
12286 | json_object_object_add(json_no, "detail", json_sub); |
12287 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12288 | json_object_free(json_no); | |
12289 | } | |
12290 | else | |
6aeb9e78 | 12291 | vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE); |
a80beece DS |
12292 | return CMD_WARNING; |
12293 | } | |
12294 | } | |
12295 | else | |
12296 | { | |
12297 | peer = peer_lookup (bgp, &su); | |
12298 | if (! peer) | |
856ca177 | 12299 | { |
db7c8528 | 12300 | if (uj) |
856ca177 MS |
12301 | { |
12302 | json_object *json_no = NULL; | |
12303 | json_no = json_object_new_object(); | |
12304 | json_object_boolean_true_add(json_no, "noPeer"); | |
12305 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12306 | json_object_free(json_no); | |
12307 | } | |
12308 | else | |
12309 | vty_out (vty, "No peer%s", VTY_NEWLINE); | |
12310 | return CMD_WARNING; | |
12311 | } | |
12312 | ||
c63b83fe | 12313 | } |
bb46e94f | 12314 | |
12315 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); | |
db7c8528 | 12316 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name, uj); |
bb46e94f | 12317 | if (count) |
12318 | { | |
db7c8528 | 12319 | if (!uj) |
856ca177 | 12320 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
db7c8528 | 12321 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name, uj); |
bb46e94f | 12322 | } |
12323 | ||
12324 | return CMD_SUCCESS; | |
718e3744 | 12325 | } |
bb46e94f | 12326 | ALIAS (show_bgp_view_neighbor_received_prefix_filter, |
12327 | show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd, | |
6aeb9e78 | 12328 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}", |
bb46e94f | 12329 | SHOW_STR |
12330 | BGP_STR | |
6aeb9e78 DS |
12331 | "BGP view\nBGP VRF\n" |
12332 | "View/VRF name\n" | |
bb46e94f | 12333 | "Address family\n" |
12334 | "Detailed information on TCP and BGP neighbor connections\n" | |
12335 | "Neighbor to display information about\n" | |
12336 | "Neighbor to display information about\n" | |
a80beece | 12337 | "Neighbor on bgp configured interface\n" |
bb46e94f | 12338 | "Display information received from a BGP neighbor\n" |
856ca177 MS |
12339 | "Display the prefixlist filter\n" |
12340 | "JavaScript Object NOtation\n") | |
718e3744 | 12341 | #endif /* HAVE_IPV6 */ |
6b0655a2 | 12342 | |
94f2b392 | 12343 | static int |
bb46e94f | 12344 | bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi, |
856ca177 | 12345 | safi_t safi, enum bgp_show_type type, u_char use_json) |
718e3744 | 12346 | { |
718e3744 | 12347 | if (! peer || ! peer->afc[afi][safi]) |
12348 | { | |
856ca177 MS |
12349 | if (use_json) |
12350 | { | |
12351 | json_object *json_no = NULL; | |
12352 | json_no = json_object_new_object(); | |
12353 | json_object_string_add(json_no, "warning", "No such neighbor or address family"); | |
12354 | vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); | |
12355 | json_object_free(json_no); | |
12356 | } | |
12357 | else | |
12358 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
718e3744 | 12359 | return CMD_WARNING; |
12360 | } | |
47fc97cc | 12361 | |
856ca177 | 12362 | return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su, use_json); |
718e3744 | 12363 | } |
12364 | ||
12365 | DEFUN (show_ip_bgp_neighbor_routes, | |
12366 | show_ip_bgp_neighbor_routes_cmd, | |
856ca177 | 12367 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 12368 | SHOW_STR |
12369 | IP_STR | |
12370 | BGP_STR | |
12371 | "Detailed information on TCP and BGP neighbor connections\n" | |
12372 | "Neighbor to display information about\n" | |
12373 | "Neighbor to display information about\n" | |
a80beece | 12374 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12375 | "Display routes learned from neighbor\n" |
12376 | "JavaScript Object Notation\n") | |
718e3744 | 12377 | { |
bb46e94f | 12378 | struct peer *peer; |
db7c8528 | 12379 | u_char uj = use_json(argc, argv); |
856ca177 | 12380 | |
db7c8528 | 12381 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12382 | if (! peer) |
12383 | return CMD_WARNING; | |
12384 | ||
12385 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 12386 | bgp_show_type_neighbor, uj); |
718e3744 | 12387 | } |
12388 | ||
12389 | DEFUN (show_ip_bgp_neighbor_flap, | |
12390 | show_ip_bgp_neighbor_flap_cmd, | |
856ca177 | 12391 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
718e3744 | 12392 | SHOW_STR |
12393 | IP_STR | |
12394 | BGP_STR | |
12395 | "Detailed information on TCP and BGP neighbor connections\n" | |
12396 | "Neighbor to display information about\n" | |
12397 | "Neighbor to display information about\n" | |
a80beece | 12398 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12399 | "Display flap statistics of the routes learned from neighbor\n" |
12400 | "JavaScript Object Notation\n") | |
718e3744 | 12401 | { |
bb46e94f | 12402 | struct peer *peer; |
db7c8528 | 12403 | u_char uj = use_json(argc, argv); |
856ca177 | 12404 | |
db7c8528 | 12405 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12406 | if (! peer) |
12407 | return CMD_WARNING; | |
12408 | ||
12409 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 12410 | bgp_show_type_flap_neighbor, uj); |
718e3744 | 12411 | } |
12412 | ||
12413 | DEFUN (show_ip_bgp_neighbor_damp, | |
12414 | show_ip_bgp_neighbor_damp_cmd, | |
856ca177 | 12415 | "show ip bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
718e3744 | 12416 | SHOW_STR |
12417 | IP_STR | |
12418 | BGP_STR | |
12419 | "Detailed information on TCP and BGP neighbor connections\n" | |
12420 | "Neighbor to display information about\n" | |
12421 | "Neighbor to display information about\n" | |
a80beece | 12422 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12423 | "Display the dampened routes received from neighbor\n" |
12424 | "JavaScript Object Notation\n") | |
718e3744 | 12425 | { |
bb46e94f | 12426 | struct peer *peer; |
db7c8528 | 12427 | u_char uj = use_json(argc, argv); |
856ca177 | 12428 | |
db7c8528 | 12429 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12430 | if (! peer) |
12431 | return CMD_WARNING; | |
12432 | ||
12433 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, | |
db7c8528 | 12434 | bgp_show_type_damp_neighbor, uj); |
718e3744 | 12435 | } |
12436 | ||
12437 | DEFUN (show_ip_bgp_ipv4_neighbor_routes, | |
12438 | show_ip_bgp_ipv4_neighbor_routes_cmd, | |
856ca177 | 12439 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 12440 | SHOW_STR |
12441 | IP_STR | |
12442 | BGP_STR | |
12443 | "Address family\n" | |
12444 | "Address Family modifier\n" | |
12445 | "Address Family modifier\n" | |
12446 | "Detailed information on TCP and BGP neighbor connections\n" | |
12447 | "Neighbor to display information about\n" | |
12448 | "Neighbor to display information about\n" | |
a80beece | 12449 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12450 | "Display routes learned from neighbor\n" |
12451 | "JavaScript Object Notation\n") | |
718e3744 | 12452 | { |
bb46e94f | 12453 | struct peer *peer; |
db7c8528 | 12454 | u_char uj = use_json(argc, argv); |
bb46e94f | 12455 | |
db7c8528 | 12456 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12457 | if (! peer) |
12458 | return CMD_WARNING; | |
12459 | ||
718e3744 | 12460 | if (strncmp (argv[0], "m", 1) == 0) |
bb46e94f | 12461 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST, |
db7c8528 | 12462 | bgp_show_type_neighbor, uj); |
718e3744 | 12463 | |
bb46e94f | 12464 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, |
db7c8528 | 12465 | bgp_show_type_neighbor, uj); |
718e3744 | 12466 | } |
bb46e94f | 12467 | |
2a3d5731 DW |
12468 | #ifdef HAVE_IPV6 |
12469 | DEFUN (show_bgp_view_neighbor_routes, | |
12470 | show_bgp_view_neighbor_routes_cmd, | |
6aeb9e78 | 12471 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
fee0f4c6 | 12472 | SHOW_STR |
fee0f4c6 | 12473 | BGP_STR |
6aeb9e78 DS |
12474 | "BGP view\nBGP VRF\n" |
12475 | "View/VRF name\n" | |
2a3d5731 DW |
12476 | "Detailed information on TCP and BGP neighbor connections\n" |
12477 | "Neighbor to display information about\n" | |
12478 | "Neighbor to display information about\n" | |
12479 | "Neighbor on bgp configured interface\n" | |
12480 | "Display routes learned from neighbor\n" | |
12481 | "JavaScript Object Notation\n") | |
fee0f4c6 | 12482 | { |
fee0f4c6 | 12483 | struct peer *peer; |
db7c8528 | 12484 | u_char uj = use_json(argc, argv); |
fee0f4c6 | 12485 | |
6aeb9e78 DS |
12486 | if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0) |
12487 | || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) | |
12488 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
2a3d5731 | 12489 | else |
6aeb9e78 | 12490 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
2a3d5731 | 12491 | |
fee0f4c6 | 12492 | if (! peer) |
12493 | return CMD_WARNING; | |
12494 | ||
2a3d5731 | 12495 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
db7c8528 | 12496 | bgp_show_type_neighbor, uj); |
fee0f4c6 | 12497 | } |
12498 | ||
2a3d5731 DW |
12499 | ALIAS (show_bgp_view_neighbor_routes, |
12500 | show_bgp_view_ipv6_neighbor_routes_cmd, | |
6aeb9e78 | 12501 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
fee0f4c6 | 12502 | SHOW_STR |
fee0f4c6 | 12503 | BGP_STR |
6aeb9e78 DS |
12504 | "BGP view\nBGP VRF\n" |
12505 | "View/VRF name\n" | |
2a3d5731 DW |
12506 | "Address family\n" |
12507 | "Detailed information on TCP and BGP neighbor connections\n" | |
12508 | "Neighbor to display information about\n" | |
12509 | "Neighbor to display information about\n" | |
12510 | "Neighbor on bgp configured interface\n" | |
12511 | "Display routes learned from neighbor\n" | |
12512 | "JavaScript Object Notation\n") | |
fee0f4c6 | 12513 | |
2a3d5731 DW |
12514 | DEFUN (show_bgp_view_neighbor_damp, |
12515 | show_bgp_view_neighbor_damp_cmd, | |
6aeb9e78 | 12516 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
fee0f4c6 | 12517 | SHOW_STR |
fee0f4c6 | 12518 | BGP_STR |
6aeb9e78 DS |
12519 | "BGP view\nBGP VRF\n" |
12520 | "View/VRF name\n" | |
2a3d5731 DW |
12521 | "Detailed information on TCP and BGP neighbor connections\n" |
12522 | "Neighbor to display information about\n" | |
12523 | "Neighbor to display information about\n" | |
12524 | "Neighbor on bgp configured interface\n" | |
12525 | "Display the dampened routes received from neighbor\n" | |
12526 | "JavaScript Object Notation\n") | |
bb46e94f | 12527 | { |
12528 | struct peer *peer; | |
db7c8528 | 12529 | u_char uj = use_json(argc, argv); |
856ca177 | 12530 | |
6aeb9e78 DS |
12531 | if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0) |
12532 | || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) | |
12533 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 12534 | else |
6aeb9e78 | 12535 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12536 | |
12537 | if (! peer) | |
12538 | return CMD_WARNING; | |
12539 | ||
12540 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, | |
db7c8528 | 12541 | bgp_show_type_damp_neighbor, uj); |
bb46e94f | 12542 | } |
12543 | ||
12544 | ALIAS (show_bgp_view_neighbor_damp, | |
12545 | show_bgp_view_ipv6_neighbor_damp_cmd, | |
6aeb9e78 | 12546 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
bb46e94f | 12547 | SHOW_STR |
12548 | BGP_STR | |
6aeb9e78 DS |
12549 | "BGP view\nBGP VRF\n" |
12550 | "View/VRF name\n" | |
bb46e94f | 12551 | "Address family\n" |
12552 | "Detailed information on TCP and BGP neighbor connections\n" | |
12553 | "Neighbor to display information about\n" | |
12554 | "Neighbor to display information about\n" | |
a80beece | 12555 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12556 | "Display the dampened routes received from neighbor\n" |
12557 | "JavaScript Object Notation\n") | |
bb46e94f | 12558 | |
12559 | DEFUN (show_bgp_view_neighbor_flap, | |
12560 | show_bgp_view_neighbor_flap_cmd, | |
6aeb9e78 | 12561 | "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 12562 | SHOW_STR |
12563 | BGP_STR | |
6aeb9e78 DS |
12564 | "BGP view\nBGP VRF\n" |
12565 | "View/VRF name\n" | |
bb46e94f | 12566 | "Detailed information on TCP and BGP neighbor connections\n" |
12567 | "Neighbor to display information about\n" | |
12568 | "Neighbor to display information about\n" | |
a80beece | 12569 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12570 | "Display flap statistics of the routes learned from neighbor\n" |
12571 | "JavaScript Object Notation\n") | |
bb46e94f | 12572 | { |
12573 | struct peer *peer; | |
db7c8528 | 12574 | u_char uj = use_json(argc, argv); |
856ca177 | 12575 | |
6aeb9e78 DS |
12576 | if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0) |
12577 | || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0)) | |
12578 | peer = peer_lookup_in_view (vty, argv[1], argv[2], uj); | |
bb46e94f | 12579 | else |
6aeb9e78 | 12580 | peer = peer_lookup_in_view (vty, NULL, argv[1], uj); |
bb46e94f | 12581 | |
12582 | if (! peer) | |
12583 | return CMD_WARNING; | |
12584 | ||
12585 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, | |
db7c8528 | 12586 | bgp_show_type_flap_neighbor, uj); |
bb46e94f | 12587 | } |
12588 | ||
12589 | ALIAS (show_bgp_view_neighbor_flap, | |
12590 | show_bgp_view_ipv6_neighbor_flap_cmd, | |
6aeb9e78 | 12591 | "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 12592 | SHOW_STR |
12593 | BGP_STR | |
6aeb9e78 DS |
12594 | "BGP view\nBGP VRF\n" |
12595 | "View/VRF name\n" | |
bb46e94f | 12596 | "Address family\n" |
12597 | "Detailed information on TCP and BGP neighbor connections\n" | |
12598 | "Neighbor to display information about\n" | |
12599 | "Neighbor to display information about\n" | |
a80beece | 12600 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12601 | "Display flap statistics of the routes learned from neighbor\n" |
12602 | "JavaScript Object Notation\n") | |
bb46e94f | 12603 | |
12604 | ALIAS (show_bgp_view_neighbor_routes, | |
12605 | show_bgp_neighbor_routes_cmd, | |
856ca177 | 12606 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
bb46e94f | 12607 | SHOW_STR |
12608 | BGP_STR | |
12609 | "Detailed information on TCP and BGP neighbor connections\n" | |
12610 | "Neighbor to display information about\n" | |
12611 | "Neighbor to display information about\n" | |
a80beece | 12612 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12613 | "Display routes learned from neighbor\n" |
12614 | "JavaScript Object Notation\n") | |
bb46e94f | 12615 | |
12616 | ||
12617 | ALIAS (show_bgp_view_neighbor_routes, | |
718e3744 | 12618 | show_bgp_ipv6_neighbor_routes_cmd, |
856ca177 | 12619 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 12620 | SHOW_STR |
12621 | BGP_STR | |
12622 | "Address family\n" | |
12623 | "Detailed information on TCP and BGP neighbor connections\n" | |
12624 | "Neighbor to display information about\n" | |
12625 | "Neighbor to display information about\n" | |
a80beece | 12626 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12627 | "Display routes learned from neighbor\n" |
12628 | "JavaScript Object Notation\n") | |
718e3744 | 12629 | |
12630 | /* old command */ | |
bb46e94f | 12631 | ALIAS (show_bgp_view_neighbor_routes, |
718e3744 | 12632 | ipv6_bgp_neighbor_routes_cmd, |
856ca177 | 12633 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 12634 | SHOW_STR |
12635 | IPV6_STR | |
12636 | BGP_STR | |
12637 | "Detailed information on TCP and BGP neighbor connections\n" | |
12638 | "Neighbor to display information about\n" | |
12639 | "Neighbor to display information about\n" | |
a80beece | 12640 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12641 | "Display routes learned from neighbor\n" |
12642 | "JavaScript Object Notation\n") | |
718e3744 | 12643 | |
12644 | /* old command */ | |
12645 | DEFUN (ipv6_mbgp_neighbor_routes, | |
12646 | ipv6_mbgp_neighbor_routes_cmd, | |
856ca177 | 12647 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}", |
718e3744 | 12648 | SHOW_STR |
12649 | IPV6_STR | |
12650 | MBGP_STR | |
12651 | "Detailed information on TCP and BGP neighbor connections\n" | |
12652 | "Neighbor to display information about\n" | |
12653 | "Neighbor to display information about\n" | |
a80beece | 12654 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12655 | "Display routes learned from neighbor\n" |
12656 | "JavaScript Object Notation\n") | |
718e3744 | 12657 | { |
bb46e94f | 12658 | struct peer *peer; |
db7c8528 | 12659 | u_char uj = use_json(argc, argv); |
bb46e94f | 12660 | |
db7c8528 | 12661 | peer = peer_lookup_in_view (vty, NULL, argv[0], uj); |
bb46e94f | 12662 | if (! peer) |
12663 | return CMD_WARNING; | |
12664 | ||
47e9b292 | 12665 | bgp_show_ipv6_bgp_deprecate_warning(vty); |
bb46e94f | 12666 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST, |
db7c8528 | 12667 | bgp_show_type_neighbor, uj); |
718e3744 | 12668 | } |
bb46e94f | 12669 | |
12670 | ALIAS (show_bgp_view_neighbor_flap, | |
12671 | show_bgp_neighbor_flap_cmd, | |
856ca177 | 12672 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 12673 | SHOW_STR |
12674 | BGP_STR | |
12675 | "Detailed information on TCP and BGP neighbor connections\n" | |
12676 | "Neighbor to display information about\n" | |
12677 | "Neighbor to display information about\n" | |
a80beece | 12678 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12679 | "Display flap statistics of the routes learned from neighbor\n" |
12680 | "JavaScript Object Notation\n") | |
bb46e94f | 12681 | |
12682 | ALIAS (show_bgp_view_neighbor_flap, | |
12683 | show_bgp_ipv6_neighbor_flap_cmd, | |
856ca177 | 12684 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}", |
bb46e94f | 12685 | SHOW_STR |
12686 | BGP_STR | |
12687 | "Address family\n" | |
12688 | "Detailed information on TCP and BGP neighbor connections\n" | |
12689 | "Neighbor to display information about\n" | |
12690 | "Neighbor to display information about\n" | |
a80beece | 12691 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12692 | "Display flap statistics of the routes learned from neighbor\n" |
12693 | "JavaScript Object Notation\n") | |
bb46e94f | 12694 | |
12695 | ALIAS (show_bgp_view_neighbor_damp, | |
12696 | show_bgp_neighbor_damp_cmd, | |
856ca177 | 12697 | "show bgp neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
bb46e94f | 12698 | SHOW_STR |
12699 | BGP_STR | |
12700 | "Detailed information on TCP and BGP neighbor connections\n" | |
12701 | "Neighbor to display information about\n" | |
12702 | "Neighbor to display information about\n" | |
a80beece | 12703 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12704 | "Display the dampened routes received from neighbor\n" |
12705 | "JavaScript Object Notation\n") | |
bb46e94f | 12706 | |
12707 | ALIAS (show_bgp_view_neighbor_damp, | |
12708 | show_bgp_ipv6_neighbor_damp_cmd, | |
856ca177 | 12709 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}", |
bb46e94f | 12710 | SHOW_STR |
12711 | BGP_STR | |
12712 | "Address family\n" | |
12713 | "Detailed information on TCP and BGP neighbor connections\n" | |
12714 | "Neighbor to display information about\n" | |
12715 | "Neighbor to display information about\n" | |
a80beece | 12716 | "Neighbor on bgp configured interface\n" |
856ca177 MS |
12717 | "Display the dampened routes received from neighbor\n" |
12718 | "JavaScript Object Notation\n") | |
fee0f4c6 | 12719 | |
718e3744 | 12720 | #endif /* HAVE_IPV6 */ |
6b0655a2 | 12721 | |
718e3744 | 12722 | struct bgp_table *bgp_distance_table; |
12723 | ||
12724 | struct bgp_distance | |
12725 | { | |
12726 | /* Distance value for the IP source prefix. */ | |
12727 | u_char distance; | |
12728 | ||
12729 | /* Name of the access-list to be matched. */ | |
12730 | char *access_list; | |
12731 | }; | |
12732 | ||
94f2b392 | 12733 | static struct bgp_distance * |
66e5cd87 | 12734 | bgp_distance_new (void) |
718e3744 | 12735 | { |
393deb9b | 12736 | return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance)); |
718e3744 | 12737 | } |
12738 | ||
94f2b392 | 12739 | static void |
718e3744 | 12740 | bgp_distance_free (struct bgp_distance *bdistance) |
12741 | { | |
12742 | XFREE (MTYPE_BGP_DISTANCE, bdistance); | |
12743 | } | |
12744 | ||
94f2b392 | 12745 | static int |
fd79ac91 | 12746 | bgp_distance_set (struct vty *vty, const char *distance_str, |
12747 | const char *ip_str, const char *access_list_str) | |
718e3744 | 12748 | { |
12749 | int ret; | |
12750 | struct prefix_ipv4 p; | |
12751 | u_char distance; | |
12752 | struct bgp_node *rn; | |
12753 | struct bgp_distance *bdistance; | |
12754 | ||
12755 | ret = str2prefix_ipv4 (ip_str, &p); | |
12756 | if (ret == 0) | |
12757 | { | |
12758 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
12759 | return CMD_WARNING; | |
12760 | } | |
12761 | ||
12762 | distance = atoi (distance_str); | |
12763 | ||
12764 | /* Get BGP distance node. */ | |
12765 | rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p); | |
12766 | if (rn->info) | |
12767 | { | |
12768 | bdistance = rn->info; | |
12769 | bgp_unlock_node (rn); | |
12770 | } | |
12771 | else | |
12772 | { | |
12773 | bdistance = bgp_distance_new (); | |
12774 | rn->info = bdistance; | |
12775 | } | |
12776 | ||
12777 | /* Set distance value. */ | |
12778 | bdistance->distance = distance; | |
12779 | ||
12780 | /* Reset access-list configuration. */ | |
12781 | if (bdistance->access_list) | |
12782 | { | |
6e919709 | 12783 | XFREE(MTYPE_AS_LIST, bdistance->access_list); |
718e3744 | 12784 | bdistance->access_list = NULL; |
12785 | } | |
12786 | if (access_list_str) | |
6e919709 | 12787 | bdistance->access_list = XSTRDUP(MTYPE_AS_LIST, access_list_str); |
718e3744 | 12788 | |
12789 | return CMD_SUCCESS; | |
12790 | } | |
12791 | ||
94f2b392 | 12792 | static int |
fd79ac91 | 12793 | bgp_distance_unset (struct vty *vty, const char *distance_str, |
12794 | const char *ip_str, const char *access_list_str) | |
718e3744 | 12795 | { |
12796 | int ret; | |
12797 | struct prefix_ipv4 p; | |
718e3744 | 12798 | struct bgp_node *rn; |
12799 | struct bgp_distance *bdistance; | |
12800 | ||
12801 | ret = str2prefix_ipv4 (ip_str, &p); | |
12802 | if (ret == 0) | |
12803 | { | |
12804 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); | |
12805 | return CMD_WARNING; | |
12806 | } | |
12807 | ||
718e3744 | 12808 | rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p); |
12809 | if (! rn) | |
12810 | { | |
12811 | vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE); | |
12812 | return CMD_WARNING; | |
12813 | } | |
12814 | ||
12815 | bdistance = rn->info; | |
12816 | ||
12817 | if (bdistance->access_list) | |
6e919709 | 12818 | XFREE(MTYPE_AS_LIST, bdistance->access_list); |
718e3744 | 12819 | bgp_distance_free (bdistance); |
12820 | ||
12821 | rn->info = NULL; | |
12822 | bgp_unlock_node (rn); | |
12823 | bgp_unlock_node (rn); | |
12824 | ||
12825 | return CMD_SUCCESS; | |
12826 | } | |
12827 | ||
718e3744 | 12828 | /* Apply BGP information to distance method. */ |
12829 | u_char | |
12830 | bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp) | |
12831 | { | |
12832 | struct bgp_node *rn; | |
12833 | struct prefix_ipv4 q; | |
12834 | struct peer *peer; | |
12835 | struct bgp_distance *bdistance; | |
12836 | struct access_list *alist; | |
12837 | struct bgp_static *bgp_static; | |
12838 | ||
12839 | if (! bgp) | |
12840 | return 0; | |
12841 | ||
12842 | if (p->family != AF_INET) | |
12843 | return 0; | |
12844 | ||
12845 | peer = rinfo->peer; | |
12846 | ||
12847 | if (peer->su.sa.sa_family != AF_INET) | |
12848 | return 0; | |
12849 | ||
12850 | memset (&q, 0, sizeof (struct prefix_ipv4)); | |
12851 | q.family = AF_INET; | |
12852 | q.prefix = peer->su.sin.sin_addr; | |
12853 | q.prefixlen = IPV4_MAX_BITLEN; | |
12854 | ||
12855 | /* Check source address. */ | |
12856 | rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q); | |
12857 | if (rn) | |
12858 | { | |
12859 | bdistance = rn->info; | |
12860 | bgp_unlock_node (rn); | |
12861 | ||
12862 | if (bdistance->access_list) | |
12863 | { | |
12864 | alist = access_list_lookup (AFI_IP, bdistance->access_list); | |
12865 | if (alist && access_list_apply (alist, p) == FILTER_PERMIT) | |
12866 | return bdistance->distance; | |
12867 | } | |
12868 | else | |
12869 | return bdistance->distance; | |
12870 | } | |
12871 | ||
12872 | /* Backdoor check. */ | |
12873 | rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p); | |
12874 | if (rn) | |
12875 | { | |
12876 | bgp_static = rn->info; | |
12877 | bgp_unlock_node (rn); | |
12878 | ||
12879 | if (bgp_static->backdoor) | |
12880 | { | |
12881 | if (bgp->distance_local) | |
12882 | return bgp->distance_local; | |
12883 | else | |
12884 | return ZEBRA_IBGP_DISTANCE_DEFAULT; | |
12885 | } | |
12886 | } | |
12887 | ||
6d85b15b | 12888 | if (peer->sort == BGP_PEER_EBGP) |
718e3744 | 12889 | { |
12890 | if (bgp->distance_ebgp) | |
12891 | return bgp->distance_ebgp; | |
12892 | return ZEBRA_EBGP_DISTANCE_DEFAULT; | |
12893 | } | |
12894 | else | |
12895 | { | |
12896 | if (bgp->distance_ibgp) | |
12897 | return bgp->distance_ibgp; | |
12898 | return ZEBRA_IBGP_DISTANCE_DEFAULT; | |
12899 | } | |
12900 | } | |
12901 | ||
12902 | DEFUN (bgp_distance, | |
12903 | bgp_distance_cmd, | |
12904 | "distance bgp <1-255> <1-255> <1-255>", | |
12905 | "Define an administrative distance\n" | |
12906 | "BGP distance\n" | |
12907 | "Distance for routes external to the AS\n" | |
12908 | "Distance for routes internal to the AS\n" | |
12909 | "Distance for local routes\n") | |
12910 | { | |
12911 | struct bgp *bgp; | |
12912 | ||
12913 | bgp = vty->index; | |
12914 | ||
12915 | bgp->distance_ebgp = atoi (argv[0]); | |
12916 | bgp->distance_ibgp = atoi (argv[1]); | |
12917 | bgp->distance_local = atoi (argv[2]); | |
12918 | return CMD_SUCCESS; | |
12919 | } | |
12920 | ||
12921 | DEFUN (no_bgp_distance, | |
12922 | no_bgp_distance_cmd, | |
12923 | "no distance bgp <1-255> <1-255> <1-255>", | |
12924 | NO_STR | |
12925 | "Define an administrative distance\n" | |
12926 | "BGP distance\n" | |
12927 | "Distance for routes external to the AS\n" | |
12928 | "Distance for routes internal to the AS\n" | |
12929 | "Distance for local routes\n") | |
12930 | { | |
12931 | struct bgp *bgp; | |
12932 | ||
12933 | bgp = vty->index; | |
12934 | ||
12935 | bgp->distance_ebgp= 0; | |
12936 | bgp->distance_ibgp = 0; | |
12937 | bgp->distance_local = 0; | |
12938 | return CMD_SUCCESS; | |
12939 | } | |
12940 | ||
12941 | ALIAS (no_bgp_distance, | |
12942 | no_bgp_distance2_cmd, | |
12943 | "no distance bgp", | |
12944 | NO_STR | |
12945 | "Define an administrative distance\n" | |
12946 | "BGP distance\n") | |
12947 | ||
12948 | DEFUN (bgp_distance_source, | |
12949 | bgp_distance_source_cmd, | |
12950 | "distance <1-255> A.B.C.D/M", | |
12951 | "Define an administrative distance\n" | |
12952 | "Administrative distance\n" | |
12953 | "IP source prefix\n") | |
12954 | { | |
12955 | bgp_distance_set (vty, argv[0], argv[1], NULL); | |
12956 | return CMD_SUCCESS; | |
12957 | } | |
12958 | ||
12959 | DEFUN (no_bgp_distance_source, | |
12960 | no_bgp_distance_source_cmd, | |
12961 | "no distance <1-255> A.B.C.D/M", | |
12962 | NO_STR | |
12963 | "Define an administrative distance\n" | |
12964 | "Administrative distance\n" | |
12965 | "IP source prefix\n") | |
12966 | { | |
12967 | bgp_distance_unset (vty, argv[0], argv[1], NULL); | |
12968 | return CMD_SUCCESS; | |
12969 | } | |
12970 | ||
12971 | DEFUN (bgp_distance_source_access_list, | |
12972 | bgp_distance_source_access_list_cmd, | |
12973 | "distance <1-255> A.B.C.D/M WORD", | |
12974 | "Define an administrative distance\n" | |
12975 | "Administrative distance\n" | |
12976 | "IP source prefix\n" | |
12977 | "Access list name\n") | |
12978 | { | |
12979 | bgp_distance_set (vty, argv[0], argv[1], argv[2]); | |
12980 | return CMD_SUCCESS; | |
12981 | } | |
12982 | ||
12983 | DEFUN (no_bgp_distance_source_access_list, | |
12984 | no_bgp_distance_source_access_list_cmd, | |
12985 | "no distance <1-255> A.B.C.D/M WORD", | |
12986 | NO_STR | |
12987 | "Define an administrative distance\n" | |
12988 | "Administrative distance\n" | |
12989 | "IP source prefix\n" | |
12990 | "Access list name\n") | |
12991 | { | |
12992 | bgp_distance_unset (vty, argv[0], argv[1], argv[2]); | |
12993 | return CMD_SUCCESS; | |
12994 | } | |
6b0655a2 | 12995 | |
718e3744 | 12996 | DEFUN (bgp_damp_set, |
12997 | bgp_damp_set_cmd, | |
12998 | "bgp dampening <1-45> <1-20000> <1-20000> <1-255>", | |
12999 | "BGP Specific commands\n" | |
13000 | "Enable route-flap dampening\n" | |
13001 | "Half-life time for the penalty\n" | |
13002 | "Value to start reusing a route\n" | |
13003 | "Value to start suppressing a route\n" | |
13004 | "Maximum duration to suppress a stable route\n") | |
13005 | { | |
13006 | struct bgp *bgp; | |
13007 | int half = DEFAULT_HALF_LIFE * 60; | |
13008 | int reuse = DEFAULT_REUSE; | |
13009 | int suppress = DEFAULT_SUPPRESS; | |
13010 | int max = 4 * half; | |
13011 | ||
13012 | if (argc == 4) | |
13013 | { | |
13014 | half = atoi (argv[0]) * 60; | |
13015 | reuse = atoi (argv[1]); | |
13016 | suppress = atoi (argv[2]); | |
13017 | max = atoi (argv[3]) * 60; | |
13018 | } | |
13019 | else if (argc == 1) | |
13020 | { | |
13021 | half = atoi (argv[0]) * 60; | |
13022 | max = 4 * half; | |
13023 | } | |
13024 | ||
13025 | bgp = vty->index; | |
13026 | return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty), | |
13027 | half, reuse, suppress, max); | |
13028 | } | |
13029 | ||
13030 | ALIAS (bgp_damp_set, | |
13031 | bgp_damp_set2_cmd, | |
13032 | "bgp dampening <1-45>", | |
13033 | "BGP Specific commands\n" | |
13034 | "Enable route-flap dampening\n" | |
13035 | "Half-life time for the penalty\n") | |
13036 | ||
13037 | ALIAS (bgp_damp_set, | |
13038 | bgp_damp_set3_cmd, | |
13039 | "bgp dampening", | |
13040 | "BGP Specific commands\n" | |
13041 | "Enable route-flap dampening\n") | |
13042 | ||
13043 | DEFUN (bgp_damp_unset, | |
13044 | bgp_damp_unset_cmd, | |
13045 | "no bgp dampening", | |
13046 | NO_STR | |
13047 | "BGP Specific commands\n" | |
13048 | "Enable route-flap dampening\n") | |
13049 | { | |
13050 | struct bgp *bgp; | |
13051 | ||
13052 | bgp = vty->index; | |
13053 | return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty)); | |
13054 | } | |
13055 | ||
13056 | ALIAS (bgp_damp_unset, | |
13057 | bgp_damp_unset2_cmd, | |
13058 | "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>", | |
13059 | NO_STR | |
13060 | "BGP Specific commands\n" | |
13061 | "Enable route-flap dampening\n" | |
13062 | "Half-life time for the penalty\n" | |
13063 | "Value to start reusing a route\n" | |
13064 | "Value to start suppressing a route\n" | |
13065 | "Maximum duration to suppress a stable route\n") | |
13066 | ||
813d4307 DW |
13067 | ALIAS (bgp_damp_unset, |
13068 | bgp_damp_unset3_cmd, | |
13069 | "no bgp dampening <1-45>", | |
13070 | NO_STR | |
13071 | "BGP Specific commands\n" | |
13072 | "Enable route-flap dampening\n" | |
13073 | "Half-life time for the penalty\n") | |
13074 | ||
718e3744 | 13075 | DEFUN (show_ip_bgp_dampened_paths, |
13076 | show_ip_bgp_dampened_paths_cmd, | |
13077 | "show ip bgp dampened-paths", | |
13078 | SHOW_STR | |
13079 | IP_STR | |
13080 | BGP_STR | |
13081 | "Display paths suppressed due to dampening\n") | |
13082 | { | |
5a646650 | 13083 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths, |
b05a1c8b | 13084 | NULL, 0); |
718e3744 | 13085 | } |
13086 | ||
13087 | DEFUN (show_ip_bgp_flap_statistics, | |
13088 | show_ip_bgp_flap_statistics_cmd, | |
13089 | "show ip bgp flap-statistics", | |
13090 | SHOW_STR | |
13091 | IP_STR | |
13092 | BGP_STR | |
13093 | "Display flap statistics of routes\n") | |
13094 | { | |
5a646650 | 13095 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
b05a1c8b | 13096 | bgp_show_type_flap_statistics, NULL, 0); |
718e3744 | 13097 | } |
6b0655a2 | 13098 | |
718e3744 | 13099 | /* Display specified route of BGP table. */ |
94f2b392 | 13100 | static int |
fd79ac91 | 13101 | bgp_clear_damp_route (struct vty *vty, const char *view_name, |
13102 | const char *ip_str, afi_t afi, safi_t safi, | |
13103 | struct prefix_rd *prd, int prefix_check) | |
718e3744 | 13104 | { |
13105 | int ret; | |
13106 | struct prefix match; | |
13107 | struct bgp_node *rn; | |
13108 | struct bgp_node *rm; | |
13109 | struct bgp_info *ri; | |
13110 | struct bgp_info *ri_temp; | |
13111 | struct bgp *bgp; | |
13112 | struct bgp_table *table; | |
13113 | ||
13114 | /* BGP structure lookup. */ | |
13115 | if (view_name) | |
13116 | { | |
13117 | bgp = bgp_lookup_by_name (view_name); | |
13118 | if (bgp == NULL) | |
13119 | { | |
6aeb9e78 | 13120 | vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE); |
718e3744 | 13121 | return CMD_WARNING; |
13122 | } | |
13123 | } | |
13124 | else | |
13125 | { | |
13126 | bgp = bgp_get_default (); | |
13127 | if (bgp == NULL) | |
13128 | { | |
13129 | vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE); | |
13130 | return CMD_WARNING; | |
13131 | } | |
13132 | } | |
13133 | ||
13134 | /* Check IP address argument. */ | |
13135 | ret = str2prefix (ip_str, &match); | |
13136 | if (! ret) | |
13137 | { | |
13138 | vty_out (vty, "%% address is malformed%s", VTY_NEWLINE); | |
13139 | return CMD_WARNING; | |
13140 | } | |
13141 | ||
13142 | match.family = afi2family (afi); | |
13143 | ||
13144 | if (safi == SAFI_MPLS_VPN) | |
13145 | { | |
13146 | for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn)) | |
13147 | { | |
13148 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
13149 | continue; | |
13150 | ||
13151 | if ((table = rn->info) != NULL) | |
13152 | if ((rm = bgp_node_match (table, &match)) != NULL) | |
6c88b44d CC |
13153 | { |
13154 | if (! prefix_check || rm->p.prefixlen == match.prefixlen) | |
13155 | { | |
13156 | ri = rm->info; | |
13157 | while (ri) | |
13158 | { | |
13159 | if (ri->extra && ri->extra->damp_info) | |
13160 | { | |
13161 | ri_temp = ri->next; | |
13162 | bgp_damp_info_free (ri->extra->damp_info, 1); | |
13163 | ri = ri_temp; | |
13164 | } | |
13165 | else | |
13166 | ri = ri->next; | |
13167 | } | |
13168 | } | |
13169 | ||
13170 | bgp_unlock_node (rm); | |
13171 | } | |
718e3744 | 13172 | } |
13173 | } | |
13174 | else | |
13175 | { | |
13176 | if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL) | |
6c88b44d CC |
13177 | { |
13178 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) | |
13179 | { | |
13180 | ri = rn->info; | |
13181 | while (ri) | |
13182 | { | |
13183 | if (ri->extra && ri->extra->damp_info) | |
13184 | { | |
13185 | ri_temp = ri->next; | |
13186 | bgp_damp_info_free (ri->extra->damp_info, 1); | |
13187 | ri = ri_temp; | |
13188 | } | |
13189 | else | |
13190 | ri = ri->next; | |
13191 | } | |
13192 | } | |
13193 | ||
13194 | bgp_unlock_node (rn); | |
13195 | } | |
718e3744 | 13196 | } |
13197 | ||
13198 | return CMD_SUCCESS; | |
13199 | } | |
13200 | ||
13201 | DEFUN (clear_ip_bgp_dampening, | |
13202 | clear_ip_bgp_dampening_cmd, | |
13203 | "clear ip bgp dampening", | |
13204 | CLEAR_STR | |
13205 | IP_STR | |
13206 | BGP_STR | |
13207 | "Clear route flap dampening information\n") | |
13208 | { | |
13209 | bgp_damp_info_clean (); | |
13210 | return CMD_SUCCESS; | |
13211 | } | |
13212 | ||
13213 | DEFUN (clear_ip_bgp_dampening_prefix, | |
13214 | clear_ip_bgp_dampening_prefix_cmd, | |
13215 | "clear ip bgp dampening A.B.C.D/M", | |
13216 | CLEAR_STR | |
13217 | IP_STR | |
13218 | BGP_STR | |
13219 | "Clear route flap dampening information\n" | |
13220 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") | |
13221 | { | |
13222 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, | |
13223 | SAFI_UNICAST, NULL, 1); | |
13224 | } | |
13225 | ||
13226 | DEFUN (clear_ip_bgp_dampening_address, | |
13227 | clear_ip_bgp_dampening_address_cmd, | |
13228 | "clear ip bgp dampening A.B.C.D", | |
13229 | CLEAR_STR | |
13230 | IP_STR | |
13231 | BGP_STR | |
13232 | "Clear route flap dampening information\n" | |
13233 | "Network to clear damping information\n") | |
13234 | { | |
13235 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, | |
13236 | SAFI_UNICAST, NULL, 0); | |
13237 | } | |
13238 | ||
13239 | DEFUN (clear_ip_bgp_dampening_address_mask, | |
13240 | clear_ip_bgp_dampening_address_mask_cmd, | |
13241 | "clear ip bgp dampening A.B.C.D A.B.C.D", | |
13242 | CLEAR_STR | |
13243 | IP_STR | |
13244 | BGP_STR | |
13245 | "Clear route flap dampening information\n" | |
13246 | "Network to clear damping information\n" | |
13247 | "Network mask\n") | |
13248 | { | |
13249 | int ret; | |
13250 | char prefix_str[BUFSIZ]; | |
13251 | ||
13252 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); | |
13253 | if (! ret) | |
13254 | { | |
13255 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); | |
13256 | return CMD_WARNING; | |
13257 | } | |
13258 | ||
13259 | return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP, | |
13260 | SAFI_UNICAST, NULL, 0); | |
13261 | } | |
6b0655a2 | 13262 | |
94f2b392 | 13263 | static int |
718e3744 | 13264 | bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp, |
13265 | afi_t afi, safi_t safi, int *write) | |
13266 | { | |
13267 | struct bgp_node *prn; | |
13268 | struct bgp_node *rn; | |
13269 | struct bgp_table *table; | |
13270 | struct prefix *p; | |
13271 | struct prefix_rd *prd; | |
13272 | struct bgp_static *bgp_static; | |
13273 | u_int32_t label; | |
13274 | char buf[SU_ADDRSTRLEN]; | |
13275 | char rdbuf[RD_ADDRSTRLEN]; | |
13276 | ||
13277 | /* Network configuration. */ | |
13278 | for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn)) | |
13279 | if ((table = prn->info) != NULL) | |
13280 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
13281 | if ((bgp_static = rn->info) != NULL) | |
13282 | { | |
13283 | p = &rn->p; | |
13284 | prd = (struct prefix_rd *) &prn->p; | |
13285 | ||
13286 | /* "address-family" display. */ | |
13287 | bgp_config_write_family_header (vty, afi, safi, write); | |
13288 | ||
13289 | /* "network" configuration display. */ | |
13290 | prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN); | |
13291 | label = decode_label (bgp_static->tag); | |
13292 | ||
0b960b4d | 13293 | vty_out (vty, " network %s/%d rd %s tag %d", |
718e3744 | 13294 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
13295 | p->prefixlen, | |
13296 | rdbuf, label); | |
13297 | vty_out (vty, "%s", VTY_NEWLINE); | |
13298 | } | |
13299 | return 0; | |
13300 | } | |
13301 | ||
13302 | /* Configuration of static route announcement and aggregate | |
13303 | information. */ | |
13304 | int | |
13305 | bgp_config_write_network (struct vty *vty, struct bgp *bgp, | |
13306 | afi_t afi, safi_t safi, int *write) | |
13307 | { | |
13308 | struct bgp_node *rn; | |
13309 | struct prefix *p; | |
13310 | struct bgp_static *bgp_static; | |
13311 | struct bgp_aggregate *bgp_aggregate; | |
13312 | char buf[SU_ADDRSTRLEN]; | |
13313 | ||
13314 | if (afi == AFI_IP && safi == SAFI_MPLS_VPN) | |
13315 | return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write); | |
13316 | ||
13317 | /* Network configuration. */ | |
13318 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) | |
13319 | if ((bgp_static = rn->info) != NULL) | |
13320 | { | |
13321 | p = &rn->p; | |
13322 | ||
13323 | /* "address-family" display. */ | |
13324 | bgp_config_write_family_header (vty, afi, safi, write); | |
13325 | ||
13326 | /* "network" configuration display. */ | |
13327 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) | |
13328 | { | |
13329 | u_int32_t destination; | |
13330 | struct in_addr netmask; | |
13331 | ||
13332 | destination = ntohl (p->u.prefix4.s_addr); | |
13333 | masklen2ip (p->prefixlen, &netmask); | |
0b960b4d | 13334 | vty_out (vty, " network %s", |
718e3744 | 13335 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN)); |
13336 | ||
13337 | if ((IN_CLASSC (destination) && p->prefixlen == 24) | |
13338 | || (IN_CLASSB (destination) && p->prefixlen == 16) | |
13339 | || (IN_CLASSA (destination) && p->prefixlen == 8) | |
13340 | || p->u.prefix4.s_addr == 0) | |
13341 | { | |
13342 | /* Natural mask is not display. */ | |
13343 | } | |
13344 | else | |
13345 | vty_out (vty, " mask %s", inet_ntoa (netmask)); | |
13346 | } | |
13347 | else | |
13348 | { | |
0b960b4d | 13349 | vty_out (vty, " network %s/%d", |
718e3744 | 13350 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
13351 | p->prefixlen); | |
13352 | } | |
13353 | ||
13354 | if (bgp_static->rmap.name) | |
13355 | vty_out (vty, " route-map %s", bgp_static->rmap.name); | |
41367172 PJ |
13356 | else |
13357 | { | |
13358 | if (bgp_static->backdoor) | |
13359 | vty_out (vty, " backdoor"); | |
41367172 | 13360 | } |
718e3744 | 13361 | |
13362 | vty_out (vty, "%s", VTY_NEWLINE); | |
13363 | } | |
13364 | ||
13365 | /* Aggregate-address configuration. */ | |
13366 | for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn)) | |
13367 | if ((bgp_aggregate = rn->info) != NULL) | |
13368 | { | |
13369 | p = &rn->p; | |
13370 | ||
13371 | /* "address-family" display. */ | |
13372 | bgp_config_write_family_header (vty, afi, safi, write); | |
13373 | ||
13374 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) | |
13375 | { | |
13376 | struct in_addr netmask; | |
13377 | ||
13378 | masklen2ip (p->prefixlen, &netmask); | |
0b960b4d | 13379 | vty_out (vty, " aggregate-address %s %s", |
718e3744 | 13380 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
13381 | inet_ntoa (netmask)); | |
13382 | } | |
13383 | else | |
13384 | { | |
0b960b4d | 13385 | vty_out (vty, " aggregate-address %s/%d", |
718e3744 | 13386 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
13387 | p->prefixlen); | |
13388 | } | |
13389 | ||
13390 | if (bgp_aggregate->as_set) | |
13391 | vty_out (vty, " as-set"); | |
13392 | ||
13393 | if (bgp_aggregate->summary_only) | |
13394 | vty_out (vty, " summary-only"); | |
13395 | ||
13396 | vty_out (vty, "%s", VTY_NEWLINE); | |
13397 | } | |
13398 | ||
13399 | return 0; | |
13400 | } | |
13401 | ||
13402 | int | |
13403 | bgp_config_write_distance (struct vty *vty, struct bgp *bgp) | |
13404 | { | |
13405 | struct bgp_node *rn; | |
13406 | struct bgp_distance *bdistance; | |
13407 | ||
13408 | /* Distance configuration. */ | |
13409 | if (bgp->distance_ebgp | |
13410 | && bgp->distance_ibgp | |
13411 | && bgp->distance_local | |
13412 | && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT | |
13413 | || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT | |
13414 | || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT)) | |
13415 | vty_out (vty, " distance bgp %d %d %d%s", | |
13416 | bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local, | |
13417 | VTY_NEWLINE); | |
13418 | ||
13419 | for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn)) | |
13420 | if ((bdistance = rn->info) != NULL) | |
13421 | { | |
13422 | vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance, | |
13423 | inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, | |
13424 | bdistance->access_list ? bdistance->access_list : "", | |
13425 | VTY_NEWLINE); | |
13426 | } | |
13427 | ||
13428 | return 0; | |
13429 | } | |
13430 | ||
13431 | /* Allocate routing table structure and install commands. */ | |
13432 | void | |
66e5cd87 | 13433 | bgp_route_init (void) |
718e3744 | 13434 | { |
13435 | /* Init BGP distance table. */ | |
64e580a7 | 13436 | bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST); |
718e3744 | 13437 | |
13438 | /* IPv4 BGP commands. */ | |
73ac8160 | 13439 | install_element (BGP_NODE, &bgp_table_map_cmd); |
718e3744 | 13440 | install_element (BGP_NODE, &bgp_network_cmd); |
13441 | install_element (BGP_NODE, &bgp_network_mask_cmd); | |
13442 | install_element (BGP_NODE, &bgp_network_mask_natural_cmd); | |
13443 | install_element (BGP_NODE, &bgp_network_route_map_cmd); | |
13444 | install_element (BGP_NODE, &bgp_network_mask_route_map_cmd); | |
13445 | install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd); | |
13446 | install_element (BGP_NODE, &bgp_network_backdoor_cmd); | |
13447 | install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd); | |
13448 | install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd); | |
73ac8160 | 13449 | install_element (BGP_NODE, &no_bgp_table_map_cmd); |
718e3744 | 13450 | install_element (BGP_NODE, &no_bgp_network_cmd); |
13451 | install_element (BGP_NODE, &no_bgp_network_mask_cmd); | |
13452 | install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd); | |
13453 | install_element (BGP_NODE, &no_bgp_network_route_map_cmd); | |
13454 | install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd); | |
13455 | install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
13456 | install_element (BGP_NODE, &no_bgp_network_backdoor_cmd); | |
13457 | install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd); | |
13458 | install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd); | |
13459 | ||
13460 | install_element (BGP_NODE, &aggregate_address_cmd); | |
13461 | install_element (BGP_NODE, &aggregate_address_mask_cmd); | |
13462 | install_element (BGP_NODE, &aggregate_address_summary_only_cmd); | |
13463 | install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd); | |
13464 | install_element (BGP_NODE, &aggregate_address_as_set_cmd); | |
13465 | install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd); | |
13466 | install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd); | |
13467 | install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
13468 | install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd); | |
13469 | install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
13470 | install_element (BGP_NODE, &no_aggregate_address_cmd); | |
13471 | install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd); | |
13472 | install_element (BGP_NODE, &no_aggregate_address_as_set_cmd); | |
13473 | install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd); | |
13474 | install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd); | |
13475 | install_element (BGP_NODE, &no_aggregate_address_mask_cmd); | |
13476 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
13477 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd); | |
13478 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
13479 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
13480 | ||
13481 | /* IPv4 unicast configuration. */ | |
73ac8160 | 13482 | install_element (BGP_IPV4_NODE, &bgp_table_map_cmd); |
718e3744 | 13483 | install_element (BGP_IPV4_NODE, &bgp_network_cmd); |
13484 | install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd); | |
13485 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd); | |
13486 | install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd); | |
13487 | install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd); | |
13488 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd); | |
73ac8160 | 13489 | install_element (BGP_IPV4_NODE, &no_bgp_table_map_cmd); |
c8f3fe30 | 13490 | install_element (BGP_IPV4_NODE, &no_bgp_network_cmd); |
718e3744 | 13491 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd); |
13492 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd); | |
13493 | install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd); | |
13494 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd); | |
13495 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
c8f3fe30 | 13496 | |
718e3744 | 13497 | install_element (BGP_IPV4_NODE, &aggregate_address_cmd); |
13498 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd); | |
13499 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd); | |
13500 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd); | |
13501 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd); | |
13502 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd); | |
13503 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd); | |
13504 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
13505 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd); | |
13506 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
13507 | install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd); | |
13508 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd); | |
13509 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd); | |
13510 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd); | |
13511 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd); | |
13512 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd); | |
13513 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
13514 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd); | |
13515 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
13516 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
13517 | ||
13518 | /* IPv4 multicast configuration. */ | |
73ac8160 | 13519 | install_element (BGP_IPV4M_NODE, &bgp_table_map_cmd); |
718e3744 | 13520 | install_element (BGP_IPV4M_NODE, &bgp_network_cmd); |
13521 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd); | |
13522 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd); | |
13523 | install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd); | |
13524 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd); | |
13525 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd); | |
73ac8160 | 13526 | install_element (BGP_IPV4M_NODE, &no_bgp_table_map_cmd); |
718e3744 | 13527 | install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd); |
13528 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd); | |
13529 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd); | |
13530 | install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd); | |
13531 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd); | |
13532 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd); | |
13533 | install_element (BGP_IPV4M_NODE, &aggregate_address_cmd); | |
13534 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd); | |
13535 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd); | |
13536 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd); | |
13537 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd); | |
13538 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd); | |
13539 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd); | |
13540 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd); | |
13541 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd); | |
13542 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd); | |
13543 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd); | |
13544 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd); | |
13545 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd); | |
13546 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd); | |
13547 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd); | |
13548 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd); | |
13549 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd); | |
13550 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd); | |
13551 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd); | |
13552 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd); | |
13553 | ||
13554 | install_element (VIEW_NODE, &show_ip_bgp_cmd); | |
13555 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd); | |
95cbbd2a | 13556 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd); |
718e3744 | 13557 | install_element (VIEW_NODE, &show_ip_bgp_route_cmd); |
4092b06c DS |
13558 | install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd); |
13559 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); | |
718e3744 | 13560 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); |
95cbbd2a | 13561 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); |
718e3744 | 13562 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd); |
13563 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); | |
13564 | install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); | |
13565 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); | |
4092b06c DS |
13566 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd); |
13567 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd); | |
95cbbd2a | 13568 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
4092b06c | 13569 | install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd); |
718e3744 | 13570 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
13571 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); | |
13572 | install_element (VIEW_NODE, &show_ip_bgp_view_cmd); | |
13573 | install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd); | |
13574 | install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd); | |
13575 | install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); | |
13576 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); | |
13577 | install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd); | |
13578 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd); | |
13579 | install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd); | |
13580 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd); | |
13581 | install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd); | |
13582 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd); | |
13583 | install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd); | |
13584 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd); | |
13585 | install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd); | |
13586 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd); | |
13587 | install_element (VIEW_NODE, &show_ip_bgp_community_cmd); | |
13588 | install_element (VIEW_NODE, &show_ip_bgp_community2_cmd); | |
13589 | install_element (VIEW_NODE, &show_ip_bgp_community3_cmd); | |
13590 | install_element (VIEW_NODE, &show_ip_bgp_community4_cmd); | |
13591 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd); | |
13592 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd); | |
13593 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd); | |
13594 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd); | |
95cbbd2a ML |
13595 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
13596 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd); | |
13597 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd); | |
13598 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd); | |
13599 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd); | |
718e3744 | 13600 | install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd); |
13601 | install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd); | |
13602 | install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd); | |
13603 | install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd); | |
13604 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd); | |
13605 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); | |
13606 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); | |
13607 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); | |
13608 | install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd); | |
13609 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd); | |
13610 | install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd); | |
13611 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd); | |
13612 | install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd); | |
13613 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd); | |
13614 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd); | |
0b16f239 | 13615 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd); |
718e3744 | 13616 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd); |
0b16f239 | 13617 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd); |
718e3744 | 13618 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd); |
0b16f239 | 13619 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd); |
718e3744 | 13620 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd); |
0b16f239 | 13621 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd); |
95cbbd2a | 13622 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd); |
718e3744 | 13623 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd); |
13624 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd); | |
13625 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); | |
13626 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd); | |
13627 | install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd); | |
13628 | install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd); | |
13629 | install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd); | |
13630 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd); | |
13631 | install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd); | |
13632 | install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd); | |
13633 | install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd); | |
13634 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd); | |
13635 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd); | |
13636 | install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd); | |
13637 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd); | |
13638 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd); | |
2a71e9ce TP |
13639 | install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd); |
13640 | install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd); | |
62687ff1 PJ |
13641 | |
13642 | /* Restricted node: VIEW_NODE - (set of dangerous commands) */ | |
13643 | install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd); | |
4092b06c DS |
13644 | install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd); |
13645 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); | |
62687ff1 | 13646 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd); |
95cbbd2a | 13647 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd); |
62687ff1 PJ |
13648 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); |
13649 | install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd); | |
13650 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd); | |
4092b06c DS |
13651 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd); |
13652 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd); | |
95cbbd2a | 13653 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
4092b06c | 13654 | install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd); |
62687ff1 PJ |
13655 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
13656 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); | |
13657 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd); | |
13658 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd); | |
13659 | install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd); | |
13660 | install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd); | |
13661 | install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd); | |
13662 | install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd); | |
13663 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd); | |
13664 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd); | |
13665 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd); | |
13666 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd); | |
95cbbd2a ML |
13667 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
13668 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd); | |
13669 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd); | |
13670 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd); | |
13671 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd); | |
62687ff1 PJ |
13672 | install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd); |
13673 | install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd); | |
13674 | install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd); | |
13675 | install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd); | |
13676 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd); | |
13677 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); | |
13678 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); | |
13679 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); | |
718e3744 | 13680 | |
13681 | install_element (ENABLE_NODE, &show_ip_bgp_cmd); | |
13682 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd); | |
95cbbd2a | 13683 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd); |
718e3744 | 13684 | install_element (ENABLE_NODE, &show_ip_bgp_route_cmd); |
4092b06c DS |
13685 | install_element (ENABLE_NODE, &show_ip_bgp_route_pathtype_cmd); |
13686 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd); | |
718e3744 | 13687 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd); |
95cbbd2a | 13688 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd); |
718e3744 | 13689 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd); |
13690 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); | |
13691 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd); | |
13692 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd); | |
4092b06c DS |
13693 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd); |
13694 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd); | |
95cbbd2a | 13695 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
4092b06c | 13696 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_pathtype_cmd); |
718e3744 | 13697 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
13698 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); | |
13699 | install_element (ENABLE_NODE, &show_ip_bgp_view_cmd); | |
13700 | install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd); | |
13701 | install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd); | |
13702 | install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd); | |
13703 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd); | |
13704 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd); | |
13705 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd); | |
13706 | install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd); | |
13707 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd); | |
13708 | install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd); | |
13709 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd); | |
13710 | install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd); | |
13711 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd); | |
13712 | install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd); | |
13713 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd); | |
13714 | install_element (ENABLE_NODE, &show_ip_bgp_community_cmd); | |
13715 | install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd); | |
13716 | install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd); | |
13717 | install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd); | |
13718 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd); | |
13719 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd); | |
13720 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd); | |
13721 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd); | |
95cbbd2a ML |
13722 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
13723 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd); | |
13724 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd); | |
13725 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd); | |
13726 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd); | |
718e3744 | 13727 | install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd); |
13728 | install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd); | |
13729 | install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd); | |
13730 | install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd); | |
13731 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd); | |
13732 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); | |
13733 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); | |
13734 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); | |
13735 | install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd); | |
13736 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd); | |
13737 | install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd); | |
13738 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd); | |
13739 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd); | |
13740 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd); | |
13741 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd); | |
0b16f239 | 13742 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_rmap_cmd); |
718e3744 | 13743 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd); |
0b16f239 | 13744 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_rmap_cmd); |
718e3744 | 13745 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd); |
0b16f239 | 13746 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_rmap_cmd); |
718e3744 | 13747 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd); |
0b16f239 | 13748 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_rmap_cmd); |
95cbbd2a | 13749 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd); |
718e3744 | 13750 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd); |
13751 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd); | |
13752 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); | |
13753 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd); | |
13754 | install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd); | |
13755 | install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd); | |
13756 | install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd); | |
13757 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd); | |
13758 | install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd); | |
13759 | install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd); | |
13760 | install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd); | |
13761 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd); | |
13762 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd); | |
13763 | install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd); | |
13764 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd); | |
13765 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd); | |
2a71e9ce TP |
13766 | install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd); |
13767 | install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd); | |
718e3744 | 13768 | |
13769 | /* BGP dampening clear commands */ | |
13770 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd); | |
13771 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd); | |
13772 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd); | |
13773 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd); | |
13774 | ||
ff7924f6 PJ |
13775 | /* prefix count */ |
13776 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); | |
13777 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); | |
13778 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); | |
718e3744 | 13779 | #ifdef HAVE_IPV6 |
ff7924f6 PJ |
13780 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); |
13781 | ||
718e3744 | 13782 | /* New config IPv6 BGP commands. */ |
73ac8160 | 13783 | install_element (BGP_IPV6_NODE, &bgp_table_map_cmd); |
718e3744 | 13784 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd); |
13785 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd); | |
73ac8160 | 13786 | install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd); |
718e3744 | 13787 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd); |
13788 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd); | |
13789 | ||
13790 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd); | |
13791 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd); | |
13792 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd); | |
13793 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd); | |
73bfe0bd B |
13794 | |
13795 | install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd); | |
13796 | install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd); | |
718e3744 | 13797 | |
13798 | /* Old config IPv6 BGP commands. */ | |
13799 | install_element (BGP_NODE, &old_ipv6_bgp_network_cmd); | |
13800 | install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd); | |
13801 | ||
13802 | install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd); | |
13803 | install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd); | |
13804 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd); | |
13805 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd); | |
13806 | ||
13807 | install_element (VIEW_NODE, &show_bgp_cmd); | |
13808 | install_element (VIEW_NODE, &show_bgp_ipv6_cmd); | |
95cbbd2a | 13809 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd); |
718e3744 | 13810 | install_element (VIEW_NODE, &show_bgp_route_cmd); |
13811 | install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd); | |
95cbbd2a | 13812 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd); |
4092b06c DS |
13813 | install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd); |
13814 | install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd); | |
13815 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd); | |
718e3744 | 13816 | install_element (VIEW_NODE, &show_bgp_prefix_cmd); |
13817 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd); | |
95cbbd2a | 13818 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
4092b06c DS |
13819 | install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd); |
13820 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd); | |
13821 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd); | |
718e3744 | 13822 | install_element (VIEW_NODE, &show_bgp_regexp_cmd); |
13823 | install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd); | |
13824 | install_element (VIEW_NODE, &show_bgp_prefix_list_cmd); | |
13825 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd); | |
13826 | install_element (VIEW_NODE, &show_bgp_filter_list_cmd); | |
13827 | install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd); | |
13828 | install_element (VIEW_NODE, &show_bgp_route_map_cmd); | |
13829 | install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd); | |
13830 | install_element (VIEW_NODE, &show_bgp_community_all_cmd); | |
13831 | install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd); | |
13832 | install_element (VIEW_NODE, &show_bgp_community_cmd); | |
13833 | install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd); | |
13834 | install_element (VIEW_NODE, &show_bgp_community2_cmd); | |
13835 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd); | |
13836 | install_element (VIEW_NODE, &show_bgp_community3_cmd); | |
13837 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd); | |
13838 | install_element (VIEW_NODE, &show_bgp_community4_cmd); | |
13839 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd); | |
13840 | install_element (VIEW_NODE, &show_bgp_community_exact_cmd); | |
13841 | install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd); | |
13842 | install_element (VIEW_NODE, &show_bgp_community2_exact_cmd); | |
13843 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd); | |
13844 | install_element (VIEW_NODE, &show_bgp_community3_exact_cmd); | |
13845 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd); | |
13846 | install_element (VIEW_NODE, &show_bgp_community4_exact_cmd); | |
13847 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd); | |
13848 | install_element (VIEW_NODE, &show_bgp_community_list_cmd); | |
13849 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd); | |
13850 | install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd); | |
13851 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd); | |
13852 | install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd); | |
13853 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd); | |
13854 | install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd); | |
13855 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd); | |
13856 | install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd); | |
13857 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd); | |
13858 | install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd); | |
13859 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd); | |
13860 | install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd); | |
13861 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd); | |
bb46e94f | 13862 | install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd); |
13863 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd); | |
13864 | install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd); | |
13865 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd); | |
13866 | install_element (VIEW_NODE, &show_bgp_view_cmd); | |
13867 | install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd); | |
13868 | install_element (VIEW_NODE, &show_bgp_view_route_cmd); | |
13869 | install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd); | |
13870 | install_element (VIEW_NODE, &show_bgp_view_prefix_cmd); | |
13871 | install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd); | |
13872 | install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd); | |
13873 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd); | |
13874 | install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd); | |
13875 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd); | |
13876 | install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd); | |
13877 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd); | |
13878 | install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); | |
13879 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); | |
13880 | install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd); | |
13881 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd); | |
13882 | install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd); | |
13883 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd); | |
62687ff1 PJ |
13884 | |
13885 | /* Restricted: | |
13886 | * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev) | |
13887 | */ | |
13888 | install_element (RESTRICTED_NODE, &show_bgp_route_cmd); | |
13889 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd); | |
95cbbd2a | 13890 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd); |
4092b06c DS |
13891 | install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd); |
13892 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd); | |
13893 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd); | |
62687ff1 PJ |
13894 | install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd); |
13895 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd); | |
95cbbd2a | 13896 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
4092b06c DS |
13897 | install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd); |
13898 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd); | |
13899 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd); | |
62687ff1 PJ |
13900 | install_element (RESTRICTED_NODE, &show_bgp_community_cmd); |
13901 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd); | |
13902 | install_element (RESTRICTED_NODE, &show_bgp_community2_cmd); | |
13903 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd); | |
13904 | install_element (RESTRICTED_NODE, &show_bgp_community3_cmd); | |
13905 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd); | |
13906 | install_element (RESTRICTED_NODE, &show_bgp_community4_cmd); | |
13907 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd); | |
13908 | install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd); | |
13909 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd); | |
13910 | install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd); | |
13911 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd); | |
13912 | install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd); | |
13913 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd); | |
13914 | install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd); | |
13915 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd); | |
62687ff1 PJ |
13916 | install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd); |
13917 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd); | |
13918 | install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd); | |
13919 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd); | |
13920 | install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); | |
13921 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); | |
718e3744 | 13922 | |
13923 | install_element (ENABLE_NODE, &show_bgp_cmd); | |
13924 | install_element (ENABLE_NODE, &show_bgp_ipv6_cmd); | |
95cbbd2a | 13925 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd); |
718e3744 | 13926 | install_element (ENABLE_NODE, &show_bgp_route_cmd); |
13927 | install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd); | |
95cbbd2a | 13928 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd); |
4092b06c DS |
13929 | install_element (ENABLE_NODE, &show_bgp_route_pathtype_cmd); |
13930 | install_element (ENABLE_NODE, &show_bgp_ipv6_route_pathtype_cmd); | |
13931 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd); | |
718e3744 | 13932 | install_element (ENABLE_NODE, &show_bgp_prefix_cmd); |
4092b06c DS |
13933 | install_element (ENABLE_NODE, &show_bgp_prefix_pathtype_cmd); |
13934 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_pathtype_cmd); | |
13935 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd); | |
718e3744 | 13936 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd); |
95cbbd2a | 13937 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
718e3744 | 13938 | install_element (ENABLE_NODE, &show_bgp_regexp_cmd); |
13939 | install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd); | |
13940 | install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd); | |
13941 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd); | |
13942 | install_element (ENABLE_NODE, &show_bgp_filter_list_cmd); | |
13943 | install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd); | |
13944 | install_element (ENABLE_NODE, &show_bgp_route_map_cmd); | |
13945 | install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd); | |
13946 | install_element (ENABLE_NODE, &show_bgp_community_all_cmd); | |
13947 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd); | |
13948 | install_element (ENABLE_NODE, &show_bgp_community_cmd); | |
13949 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd); | |
13950 | install_element (ENABLE_NODE, &show_bgp_community2_cmd); | |
13951 | install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd); | |
13952 | install_element (ENABLE_NODE, &show_bgp_community3_cmd); | |
13953 | install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd); | |
13954 | install_element (ENABLE_NODE, &show_bgp_community4_cmd); | |
13955 | install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd); | |
13956 | install_element (ENABLE_NODE, &show_bgp_community_exact_cmd); | |
13957 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd); | |
13958 | install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd); | |
13959 | install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd); | |
13960 | install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd); | |
13961 | install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd); | |
13962 | install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd); | |
13963 | install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd); | |
13964 | install_element (ENABLE_NODE, &show_bgp_community_list_cmd); | |
13965 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd); | |
13966 | install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd); | |
13967 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd); | |
13968 | install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd); | |
13969 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd); | |
13970 | install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd); | |
13971 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd); | |
13972 | install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd); | |
13973 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd); | |
13974 | install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd); | |
13975 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd); | |
13976 | install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd); | |
13977 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd); | |
bb46e94f | 13978 | install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd); |
13979 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd); | |
13980 | install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd); | |
13981 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd); | |
13982 | install_element (ENABLE_NODE, &show_bgp_view_cmd); | |
13983 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd); | |
13984 | install_element (ENABLE_NODE, &show_bgp_view_route_cmd); | |
13985 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd); | |
13986 | install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd); | |
13987 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd); | |
13988 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd); | |
13989 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd); | |
13990 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd); | |
13991 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd); | |
13992 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd); | |
13993 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd); | |
13994 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); | |
13995 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); | |
13996 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd); | |
13997 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd); | |
13998 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd); | |
13999 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd); | |
2815e61f PJ |
14000 | |
14001 | /* Statistics */ | |
14002 | install_element (ENABLE_NODE, &show_bgp_statistics_cmd); | |
14003 | install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd); | |
14004 | install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd); | |
14005 | install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd); | |
14006 | ||
718e3744 | 14007 | /* old command */ |
14008 | install_element (VIEW_NODE, &show_ipv6_bgp_cmd); | |
14009 | install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd); | |
14010 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd); | |
14011 | install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd); | |
14012 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd); | |
14013 | install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd); | |
14014 | install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd); | |
14015 | install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd); | |
14016 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd); | |
14017 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd); | |
14018 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd); | |
14019 | install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd); | |
14020 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd); | |
14021 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd); | |
14022 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd); | |
14023 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd); | |
14024 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd); | |
14025 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd); | |
14026 | install_element (VIEW_NODE, &show_ipv6_mbgp_cmd); | |
14027 | install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd); | |
14028 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd); | |
14029 | install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd); | |
14030 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd); | |
14031 | install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd); | |
14032 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd); | |
14033 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd); | |
14034 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd); | |
14035 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd); | |
14036 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd); | |
14037 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd); | |
14038 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd); | |
14039 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd); | |
14040 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd); | |
14041 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd); | |
14042 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd); | |
14043 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd); | |
bb46e94f | 14044 | |
718e3744 | 14045 | /* old command */ |
14046 | install_element (ENABLE_NODE, &show_ipv6_bgp_cmd); | |
14047 | install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd); | |
14048 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd); | |
14049 | install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd); | |
14050 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd); | |
14051 | install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd); | |
14052 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd); | |
14053 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd); | |
14054 | install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd); | |
14055 | install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd); | |
14056 | install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd); | |
14057 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd); | |
14058 | install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd); | |
14059 | install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd); | |
14060 | install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd); | |
14061 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd); | |
14062 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd); | |
14063 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd); | |
14064 | install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd); | |
14065 | install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd); | |
14066 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd); | |
14067 | install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd); | |
14068 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd); | |
14069 | install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd); | |
14070 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd); | |
14071 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd); | |
14072 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd); | |
14073 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd); | |
14074 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd); | |
14075 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd); | |
14076 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd); | |
14077 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd); | |
14078 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd); | |
14079 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd); | |
14080 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd); | |
14081 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd); | |
14082 | ||
14083 | /* old command */ | |
14084 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd); | |
14085 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd); | |
14086 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd); | |
14087 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd); | |
14088 | ||
14089 | /* old command */ | |
14090 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd); | |
14091 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd); | |
14092 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd); | |
14093 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd); | |
14094 | ||
14095 | /* old command */ | |
14096 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd); | |
14097 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd); | |
14098 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd); | |
14099 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd); | |
14100 | #endif /* HAVE_IPV6 */ | |
14101 | ||
14102 | install_element (BGP_NODE, &bgp_distance_cmd); | |
14103 | install_element (BGP_NODE, &no_bgp_distance_cmd); | |
14104 | install_element (BGP_NODE, &no_bgp_distance2_cmd); | |
14105 | install_element (BGP_NODE, &bgp_distance_source_cmd); | |
14106 | install_element (BGP_NODE, &no_bgp_distance_source_cmd); | |
14107 | install_element (BGP_NODE, &bgp_distance_source_access_list_cmd); | |
14108 | install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd); | |
14109 | ||
14110 | install_element (BGP_NODE, &bgp_damp_set_cmd); | |
14111 | install_element (BGP_NODE, &bgp_damp_set2_cmd); | |
14112 | install_element (BGP_NODE, &bgp_damp_set3_cmd); | |
14113 | install_element (BGP_NODE, &bgp_damp_unset_cmd); | |
14114 | install_element (BGP_NODE, &bgp_damp_unset2_cmd); | |
813d4307 | 14115 | install_element (BGP_NODE, &bgp_damp_unset3_cmd); |
718e3744 | 14116 | install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd); |
14117 | install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd); | |
14118 | install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd); | |
14119 | install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd); | |
14120 | install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd); | |
813d4307 | 14121 | install_element (BGP_IPV4_NODE, &bgp_damp_unset3_cmd); |
718e3744 | 14122 | } |
228da428 CC |
14123 | |
14124 | void | |
14125 | bgp_route_finish (void) | |
14126 | { | |
14127 | bgp_table_unlock (bgp_distance_table); | |
14128 | bgp_distance_table = NULL; | |
14129 | } |