paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 23 | #include "prefix.h" |
| 24 | #include "linklist.h" |
| 25 | #include "memory.h" |
| 26 | #include "command.h" |
| 27 | #include "stream.h" |
| 28 | #include "filter.h" |
| 29 | #include "str.h" |
| 30 | #include "log.h" |
| 31 | #include "routemap.h" |
| 32 | #include "buffer.h" |
| 33 | #include "sockunion.h" |
| 34 | #include "plist.h" |
| 35 | #include "thread.h" |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 36 | #include "workqueue.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | |
| 38 | #include "bgpd/bgpd.h" |
| 39 | #include "bgpd/bgp_table.h" |
| 40 | #include "bgpd/bgp_route.h" |
| 41 | #include "bgpd/bgp_attr.h" |
| 42 | #include "bgpd/bgp_debug.h" |
| 43 | #include "bgpd/bgp_aspath.h" |
| 44 | #include "bgpd/bgp_regex.h" |
| 45 | #include "bgpd/bgp_community.h" |
| 46 | #include "bgpd/bgp_ecommunity.h" |
| 47 | #include "bgpd/bgp_clist.h" |
| 48 | #include "bgpd/bgp_packet.h" |
| 49 | #include "bgpd/bgp_filter.h" |
| 50 | #include "bgpd/bgp_fsm.h" |
| 51 | #include "bgpd/bgp_mplsvpn.h" |
| 52 | #include "bgpd/bgp_nexthop.h" |
| 53 | #include "bgpd/bgp_damp.h" |
| 54 | #include "bgpd/bgp_advertise.h" |
| 55 | #include "bgpd/bgp_zebra.h" |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 56 | #include "bgpd/bgp_vty.h" |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 57 | #include "bgpd/bgp_mpath.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 58 | |
| 59 | /* Extern from bgp_dump.c */ |
Stephen Hemminger | dde7258 | 2009-05-08 15:19:07 -0700 | [diff] [blame] | 60 | extern const char *bgp_origin_str[]; |
| 61 | extern const char *bgp_origin_long_str[]; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 62 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 63 | static struct bgp_node * |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 64 | bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | struct prefix_rd *prd) |
| 66 | { |
| 67 | struct bgp_node *rn; |
| 68 | struct bgp_node *prn = NULL; |
Paul Jakma | da5b30f | 2006-05-08 14:37:17 +0000 | [diff] [blame] | 69 | |
| 70 | assert (table); |
| 71 | if (!table) |
| 72 | return NULL; |
| 73 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 74 | if (safi == SAFI_MPLS_VPN) |
| 75 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 76 | prn = bgp_node_get (table, (struct prefix *) prd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 77 | |
| 78 | if (prn->info == NULL) |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 79 | prn->info = bgp_table_init (afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 80 | else |
| 81 | bgp_unlock_node (prn); |
| 82 | table = prn->info; |
| 83 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | |
| 85 | rn = bgp_node_get (table, p); |
| 86 | |
| 87 | if (safi == SAFI_MPLS_VPN) |
| 88 | rn->prn = prn; |
| 89 | |
| 90 | return rn; |
| 91 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 92 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 93 | /* Allocate bgp_info_extra */ |
| 94 | static struct bgp_info_extra * |
| 95 | bgp_info_extra_new (void) |
| 96 | { |
| 97 | struct bgp_info_extra *new; |
| 98 | new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra)); |
| 99 | return new; |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | bgp_info_extra_free (struct bgp_info_extra **extra) |
| 104 | { |
| 105 | if (extra && *extra) |
| 106 | { |
| 107 | if ((*extra)->damp_info) |
| 108 | bgp_damp_info_free ((*extra)->damp_info, 0); |
| 109 | |
| 110 | (*extra)->damp_info = NULL; |
| 111 | |
| 112 | XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra); |
| 113 | |
| 114 | *extra = NULL; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* Get bgp_info extra information for the given bgp_info, lazy allocated |
| 119 | * if required. |
| 120 | */ |
| 121 | struct bgp_info_extra * |
| 122 | bgp_info_extra_get (struct bgp_info *ri) |
| 123 | { |
| 124 | if (!ri->extra) |
| 125 | ri->extra = bgp_info_extra_new(); |
| 126 | return ri->extra; |
| 127 | } |
| 128 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 129 | /* Allocate new bgp info structure. */ |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 130 | static struct bgp_info * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 131 | bgp_info_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 132 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 133 | return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* Free bgp route information. */ |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 137 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | bgp_info_free (struct bgp_info *binfo) |
| 139 | { |
| 140 | if (binfo->attr) |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 141 | bgp_attr_unintern (&binfo->attr); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 142 | |
| 143 | bgp_info_extra_free (&binfo->extra); |
Josh Bailey | de8d5df | 2011-07-20 20:46:01 -0700 | [diff] [blame] | 144 | bgp_info_mpath_free (&binfo->mpath); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 146 | peer_unlock (binfo->peer); /* bgp_info peer reference */ |
| 147 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | XFREE (MTYPE_BGP_ROUTE, binfo); |
| 149 | } |
| 150 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 151 | struct bgp_info * |
| 152 | bgp_info_lock (struct bgp_info *binfo) |
| 153 | { |
| 154 | binfo->lock++; |
| 155 | return binfo; |
| 156 | } |
| 157 | |
| 158 | struct bgp_info * |
| 159 | bgp_info_unlock (struct bgp_info *binfo) |
| 160 | { |
| 161 | assert (binfo && binfo->lock > 0); |
| 162 | binfo->lock--; |
| 163 | |
| 164 | if (binfo->lock == 0) |
| 165 | { |
| 166 | #if 0 |
| 167 | zlog_debug ("%s: unlocked and freeing", __func__); |
| 168 | zlog_backtrace (LOG_DEBUG); |
| 169 | #endif |
| 170 | bgp_info_free (binfo); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | #if 0 |
| 175 | if (binfo->lock == 1) |
| 176 | { |
| 177 | zlog_debug ("%s: unlocked to 1", __func__); |
| 178 | zlog_backtrace (LOG_DEBUG); |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | return binfo; |
| 183 | } |
| 184 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | void |
| 186 | bgp_info_add (struct bgp_node *rn, struct bgp_info *ri) |
| 187 | { |
| 188 | struct bgp_info *top; |
| 189 | |
| 190 | top = rn->info; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 191 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 192 | ri->next = rn->info; |
| 193 | ri->prev = NULL; |
| 194 | if (top) |
| 195 | top->prev = ri; |
| 196 | rn->info = ri; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 197 | |
| 198 | bgp_info_lock (ri); |
| 199 | bgp_lock_node (rn); |
| 200 | peer_lock (ri->peer); /* bgp_info peer reference */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | } |
| 202 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 203 | /* Do the actual removal of info from RIB, for use by bgp_process |
| 204 | completion callback *only* */ |
| 205 | static void |
| 206 | bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | { |
| 208 | if (ri->next) |
| 209 | ri->next->prev = ri->prev; |
| 210 | if (ri->prev) |
| 211 | ri->prev->next = ri->next; |
| 212 | else |
| 213 | rn->info = ri->next; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 214 | |
Josh Bailey | de8d5df | 2011-07-20 20:46:01 -0700 | [diff] [blame] | 215 | bgp_info_mpath_dequeue (ri); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 216 | bgp_info_unlock (ri); |
| 217 | bgp_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | } |
| 219 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 220 | void |
| 221 | bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri) |
| 222 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 223 | bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED); |
| 224 | /* set of previous already took care of pcount */ |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 225 | UNSET_FLAG (ri->flags, BGP_INFO_VALID); |
| 226 | } |
| 227 | |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 228 | /* undo the effects of a previous call to bgp_info_delete; typically |
| 229 | called when a route is deleted and then quickly re-added before the |
| 230 | deletion has been processed */ |
| 231 | static void |
| 232 | bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri) |
| 233 | { |
| 234 | bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED); |
| 235 | /* unset of previous already took care of pcount */ |
| 236 | SET_FLAG (ri->flags, BGP_INFO_VALID); |
| 237 | } |
| 238 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 239 | /* Adjust pcount as required */ |
| 240 | static void |
| 241 | bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri) |
| 242 | { |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 243 | struct bgp_table *table; |
| 244 | |
| 245 | assert (rn && bgp_node_table (rn)); |
Paul Jakma | 6f58544 | 2006-10-22 19:13:07 +0000 | [diff] [blame] | 246 | assert (ri && ri->peer && ri->peer->bgp); |
| 247 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 248 | table = bgp_node_table (rn); |
| 249 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 250 | /* Ignore 'pcount' for RS-client tables */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 251 | if (table->type != BGP_TABLE_MAIN |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 252 | || ri->peer == ri->peer->bgp->peer_self) |
| 253 | return; |
| 254 | |
| 255 | if (BGP_INFO_HOLDDOWN (ri) |
| 256 | && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
| 257 | { |
| 258 | |
| 259 | UNSET_FLAG (ri->flags, BGP_INFO_COUNTED); |
| 260 | |
| 261 | /* slight hack, but more robust against errors. */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 262 | if (ri->peer->pcount[table->afi][table->safi]) |
| 263 | ri->peer->pcount[table->afi][table->safi]--; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 264 | else |
| 265 | { |
| 266 | zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s", |
| 267 | __func__, ri->peer->host); |
| 268 | zlog_backtrace (LOG_WARNING); |
| 269 | zlog_warn ("%s: Please report to Quagga bugzilla", __func__); |
| 270 | } |
| 271 | } |
| 272 | else if (!BGP_INFO_HOLDDOWN (ri) |
| 273 | && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
| 274 | { |
| 275 | SET_FLAG (ri->flags, BGP_INFO_COUNTED); |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 276 | ri->peer->pcount[table->afi][table->safi]++; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /* Set/unset bgp_info flags, adjusting any other state as needed. |
| 282 | * This is here primarily to keep prefix-count in check. |
| 283 | */ |
| 284 | void |
| 285 | bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) |
| 286 | { |
| 287 | SET_FLAG (ri->flags, flag); |
| 288 | |
| 289 | /* early bath if we know it's not a flag that changes useability state */ |
| 290 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE)) |
| 291 | return; |
| 292 | |
| 293 | bgp_pcount_adjust (rn, ri); |
| 294 | } |
| 295 | |
| 296 | void |
| 297 | bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) |
| 298 | { |
| 299 | UNSET_FLAG (ri->flags, flag); |
| 300 | |
| 301 | /* early bath if we know it's not a flag that changes useability state */ |
| 302 | if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE)) |
| 303 | return; |
| 304 | |
| 305 | bgp_pcount_adjust (rn, ri); |
| 306 | } |
| 307 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 308 | /* Get MED value. If MED value is missing and "bgp bestpath |
| 309 | missing-as-worst" is specified, treat it as the worst value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 310 | static u_int32_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 311 | bgp_med_value (struct attr *attr, struct bgp *bgp) |
| 312 | { |
| 313 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
| 314 | return attr->med; |
| 315 | else |
| 316 | { |
| 317 | if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST)) |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 318 | return BGP_MED_MAX; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | else |
| 320 | return 0; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /* Compare two bgp route entity. br is preferable then return 1. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 325 | static int |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 326 | bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist, |
| 327 | int *paths_eq) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 328 | { |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 329 | struct attr *newattr, *existattr; |
| 330 | struct attr_extra *newattre, *existattre; |
| 331 | bgp_peer_sort_t new_sort; |
| 332 | bgp_peer_sort_t exist_sort; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 333 | u_int32_t new_pref; |
| 334 | u_int32_t exist_pref; |
| 335 | u_int32_t new_med; |
| 336 | u_int32_t exist_med; |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 337 | u_int32_t new_weight; |
| 338 | u_int32_t exist_weight; |
| 339 | uint32_t newm, existm; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 340 | struct in_addr new_id; |
| 341 | struct in_addr exist_id; |
| 342 | int new_cluster; |
| 343 | int exist_cluster; |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 344 | int internal_as_route; |
| 345 | int confed_as_route; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 346 | int ret; |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 347 | |
| 348 | *paths_eq = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 349 | |
| 350 | /* 0. Null check. */ |
| 351 | if (new == NULL) |
| 352 | return 0; |
| 353 | if (exist == NULL) |
| 354 | return 1; |
| 355 | |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 356 | newattr = new->attr; |
| 357 | existattr = exist->attr; |
| 358 | newattre = newattr->extra; |
| 359 | existattre = existattr->extra; |
| 360 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 361 | /* 1. Weight check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 362 | new_weight = exist_weight = 0; |
| 363 | |
| 364 | if (newattre) |
| 365 | new_weight = newattre->weight; |
| 366 | if (existattre) |
| 367 | exist_weight = existattre->weight; |
| 368 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 369 | if (new_weight > exist_weight) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 370 | return 1; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 371 | if (new_weight < exist_weight) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | return 0; |
| 373 | |
| 374 | /* 2. Local preference check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 375 | new_pref = exist_pref = bgp->default_local_pref; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 377 | if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
| 378 | new_pref = newattr->local_pref; |
| 379 | if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
| 380 | exist_pref = existattr->local_pref; |
| 381 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 382 | if (new_pref > exist_pref) |
| 383 | return 1; |
| 384 | if (new_pref < exist_pref) |
| 385 | return 0; |
| 386 | |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 387 | /* 3. Local route check. We prefer: |
| 388 | * - BGP_ROUTE_STATIC |
| 389 | * - BGP_ROUTE_AGGREGATE |
| 390 | * - BGP_ROUTE_REDISTRIBUTE |
| 391 | */ |
| 392 | if (! (new->sub_type == BGP_ROUTE_NORMAL)) |
| 393 | return 1; |
| 394 | if (! (exist->sub_type == BGP_ROUTE_NORMAL)) |
| 395 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | |
| 397 | /* 4. AS path length check. */ |
| 398 | if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE)) |
| 399 | { |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 400 | int exist_hops = aspath_count_hops (existattr->aspath); |
| 401 | int exist_confeds = aspath_count_confeds (existattr->aspath); |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 402 | |
hasso | 6811845 | 2005-04-08 15:40:36 +0000 | [diff] [blame] | 403 | if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED)) |
| 404 | { |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 405 | int aspath_hops; |
| 406 | |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 407 | aspath_hops = aspath_count_hops (newattr->aspath); |
| 408 | aspath_hops += aspath_count_confeds (newattr->aspath); |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 409 | |
| 410 | if ( aspath_hops < (exist_hops + exist_confeds)) |
hasso | 6811845 | 2005-04-08 15:40:36 +0000 | [diff] [blame] | 411 | return 1; |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 412 | if ( aspath_hops > (exist_hops + exist_confeds)) |
hasso | 6811845 | 2005-04-08 15:40:36 +0000 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | else |
| 416 | { |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 417 | int newhops = aspath_count_hops (newattr->aspath); |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 418 | |
| 419 | if (newhops < exist_hops) |
hasso | 6811845 | 2005-04-08 15:40:36 +0000 | [diff] [blame] | 420 | return 1; |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 421 | if (newhops > exist_hops) |
hasso | 6811845 | 2005-04-08 15:40:36 +0000 | [diff] [blame] | 422 | return 0; |
| 423 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* 5. Origin check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 427 | if (newattr->origin < existattr->origin) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 428 | return 1; |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 429 | if (newattr->origin > existattr->origin) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | return 0; |
| 431 | |
| 432 | /* 6. MED check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 433 | internal_as_route = (aspath_count_hops (newattr->aspath) == 0 |
| 434 | && aspath_count_hops (existattr->aspath) == 0); |
| 435 | confed_as_route = (aspath_count_confeds (newattr->aspath) > 0 |
| 436 | && aspath_count_confeds (existattr->aspath) > 0 |
| 437 | && aspath_count_hops (newattr->aspath) == 0 |
| 438 | && aspath_count_hops (existattr->aspath) == 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | |
| 440 | if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED) |
| 441 | || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED) |
| 442 | && confed_as_route) |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 443 | || aspath_cmp_left (newattr->aspath, existattr->aspath) |
| 444 | || aspath_cmp_left_confed (newattr->aspath, existattr->aspath) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 445 | || internal_as_route) |
| 446 | { |
| 447 | new_med = bgp_med_value (new->attr, bgp); |
| 448 | exist_med = bgp_med_value (exist->attr, bgp); |
| 449 | |
| 450 | if (new_med < exist_med) |
| 451 | return 1; |
| 452 | if (new_med > exist_med) |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | /* 7. Peer type check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 457 | new_sort = new->peer->sort; |
| 458 | exist_sort = exist->peer->sort; |
| 459 | |
| 460 | if (new_sort == BGP_PEER_EBGP |
| 461 | && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 462 | return 1; |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 463 | if (exist_sort == BGP_PEER_EBGP |
| 464 | && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 465 | return 0; |
| 466 | |
| 467 | /* 8. IGP metric check. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 468 | newm = existm = 0; |
| 469 | |
| 470 | if (new->extra) |
| 471 | newm = new->extra->igpmetric; |
| 472 | if (exist->extra) |
| 473 | existm = exist->extra->igpmetric; |
| 474 | |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 475 | if (newm < existm) |
| 476 | ret = 1; |
| 477 | if (newm > existm) |
| 478 | ret = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | |
| 480 | /* 9. Maximum path check. */ |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 481 | if (newm == existm) |
| 482 | { |
Pradosh Mohapatra | 2fdd455 | 2013-09-07 07:02:36 +0000 | [diff] [blame] | 483 | if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) |
| 484 | { |
| 485 | |
| 486 | /* |
| 487 | * For the two paths, all comparison steps till IGP metric |
| 488 | * have succeeded - including AS_PATH hop count. Since 'bgp |
| 489 | * bestpath as-path multipath-relax' knob is on, we don't need |
| 490 | * an exact match of AS_PATH. Thus, mark the paths are equal. |
| 491 | * That will trigger both these paths to get into the multipath |
| 492 | * array. |
| 493 | */ |
| 494 | *paths_eq = 1; |
| 495 | } |
| 496 | else if (new->peer->sort == BGP_PEER_IBGP) |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 497 | { |
| 498 | if (aspath_cmp (new->attr->aspath, exist->attr->aspath)) |
| 499 | *paths_eq = 1; |
| 500 | } |
| 501 | else if (new->peer->as == exist->peer->as) |
| 502 | *paths_eq = 1; |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | /* |
| 507 | * TODO: If unequal cost ibgp multipath is enabled we can |
| 508 | * mark the paths as equal here instead of returning |
| 509 | */ |
| 510 | return ret; |
| 511 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | |
| 513 | /* 10. If both paths are external, prefer the path that was received |
| 514 | first (the oldest one). This step minimizes route-flap, since a |
| 515 | newer path won't displace an older one, even if it was the |
| 516 | preferred route based on the additional decision criteria below. */ |
| 517 | if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID) |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 518 | && new_sort == BGP_PEER_EBGP |
| 519 | && exist_sort == BGP_PEER_EBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 520 | { |
| 521 | if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED)) |
| 522 | return 1; |
| 523 | if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED)) |
| 524 | return 0; |
| 525 | } |
| 526 | |
vivek | bd4b7f1 | 2014-09-30 15:54:45 -0700 | [diff] [blame^] | 527 | /* 11. Router-ID comparision. */ |
| 528 | /* If one of the paths is "stale", the corresponding peer router-id will |
| 529 | * be 0 and would always win over the other path. If originator id is |
| 530 | * used for the comparision, it will decide which path is better. |
| 531 | */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 532 | if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
| 533 | new_id.s_addr = newattre->originator_id.s_addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 534 | else |
| 535 | new_id.s_addr = new->peer->remote_id.s_addr; |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 536 | if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
| 537 | exist_id.s_addr = existattre->originator_id.s_addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | else |
| 539 | exist_id.s_addr = exist->peer->remote_id.s_addr; |
| 540 | |
| 541 | if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr)) |
| 542 | return 1; |
| 543 | if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr)) |
| 544 | return 0; |
| 545 | |
| 546 | /* 12. Cluster length comparision. */ |
Jorge Boncompte [DTI2] | 8ff5631 | 2012-05-07 16:52:56 +0000 | [diff] [blame] | 547 | new_cluster = exist_cluster = 0; |
| 548 | |
| 549 | if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) |
| 550 | new_cluster = newattre->cluster->length; |
| 551 | if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) |
| 552 | exist_cluster = existattre->cluster->length; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | |
| 554 | if (new_cluster < exist_cluster) |
| 555 | return 1; |
| 556 | if (new_cluster > exist_cluster) |
| 557 | return 0; |
| 558 | |
| 559 | /* 13. Neighbor address comparision. */ |
vivek | bd4b7f1 | 2014-09-30 15:54:45 -0700 | [diff] [blame^] | 560 | /* Do this only if neither path is "stale" as stale paths do not have |
| 561 | * valid peer information (as the connection may or may not be up). |
| 562 | */ |
| 563 | if (CHECK_FLAG (exist->flags, BGP_INFO_STALE)) |
| 564 | return 1; |
| 565 | if (CHECK_FLAG (new->flags, BGP_INFO_STALE)) |
| 566 | return 0; |
| 567 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 568 | ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote); |
| 569 | |
| 570 | if (ret == 1) |
| 571 | return 0; |
| 572 | if (ret == -1) |
| 573 | return 1; |
| 574 | |
| 575 | return 1; |
| 576 | } |
| 577 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 578 | static enum filter_type |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 579 | bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
| 580 | afi_t afi, safi_t safi) |
| 581 | { |
| 582 | struct bgp_filter *filter; |
| 583 | |
| 584 | filter = &peer->filter[afi][safi]; |
| 585 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 586 | #define FILTER_EXIST_WARN(F,f,filter) \ |
| 587 | if (BGP_DEBUG (update, UPDATE_IN) \ |
| 588 | && !(F ## _IN (filter))) \ |
| 589 | plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \ |
| 590 | peer->host, #f, F ## _IN_NAME(filter)); |
| 591 | |
| 592 | if (DISTRIBUTE_IN_NAME (filter)) { |
| 593 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); |
| 594 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 595 | if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY) |
| 596 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 597 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 599 | if (PREFIX_LIST_IN_NAME (filter)) { |
| 600 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); |
| 601 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY) |
| 603 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 604 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 605 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 606 | if (FILTER_LIST_IN_NAME (filter)) { |
| 607 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); |
| 608 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 609 | if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY) |
| 610 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 611 | } |
| 612 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 613 | return FILTER_PERMIT; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 614 | #undef FILTER_EXIST_WARN |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 615 | } |
| 616 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 617 | static enum filter_type |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 618 | bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr, |
| 619 | afi_t afi, safi_t safi) |
| 620 | { |
| 621 | struct bgp_filter *filter; |
| 622 | |
| 623 | filter = &peer->filter[afi][safi]; |
| 624 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 625 | #define FILTER_EXIST_WARN(F,f,filter) \ |
| 626 | if (BGP_DEBUG (update, UPDATE_OUT) \ |
| 627 | && !(F ## _OUT (filter))) \ |
| 628 | plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \ |
| 629 | peer->host, #f, F ## _OUT_NAME(filter)); |
| 630 | |
| 631 | if (DISTRIBUTE_OUT_NAME (filter)) { |
| 632 | FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter); |
| 633 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY) |
| 635 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 636 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 637 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 638 | if (PREFIX_LIST_OUT_NAME (filter)) { |
| 639 | FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter); |
| 640 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 641 | if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY) |
| 642 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 643 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 644 | |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 645 | if (FILTER_LIST_OUT_NAME (filter)) { |
| 646 | FILTER_EXIST_WARN(FILTER_LIST, as, filter); |
| 647 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY) |
| 649 | return FILTER_DENY; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 650 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 651 | |
| 652 | return FILTER_PERMIT; |
Paul Jakma | 650f76c | 2009-06-25 18:06:31 +0100 | [diff] [blame] | 653 | #undef FILTER_EXIST_WARN |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* If community attribute includes no_export then return 1. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 657 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 658 | bgp_community_filter (struct peer *peer, struct attr *attr) |
| 659 | { |
| 660 | if (attr->community) |
| 661 | { |
| 662 | /* NO_ADVERTISE check. */ |
| 663 | if (community_include (attr->community, COMMUNITY_NO_ADVERTISE)) |
| 664 | return 1; |
| 665 | |
| 666 | /* NO_EXPORT check. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 667 | if (peer->sort == BGP_PEER_EBGP && |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | community_include (attr->community, COMMUNITY_NO_EXPORT)) |
| 669 | return 1; |
| 670 | |
| 671 | /* NO_EXPORT_SUBCONFED check. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 672 | if (peer->sort == BGP_PEER_EBGP |
| 673 | || peer->sort == BGP_PEER_CONFED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 674 | if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED)) |
| 675 | return 1; |
| 676 | } |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* Route reflection loop check. */ |
| 681 | static int |
| 682 | bgp_cluster_filter (struct peer *peer, struct attr *attr) |
| 683 | { |
| 684 | struct in_addr cluster_id; |
| 685 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 686 | if (attr->extra && attr->extra->cluster) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | { |
| 688 | if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID) |
| 689 | cluster_id = peer->bgp->cluster_id; |
| 690 | else |
| 691 | cluster_id = peer->bgp->router_id; |
| 692 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 693 | if (cluster_loop_check (attr->extra->cluster, cluster_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 694 | return 1; |
| 695 | } |
| 696 | return 0; |
| 697 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 698 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 699 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 700 | bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr, |
| 701 | afi_t afi, safi_t safi) |
| 702 | { |
| 703 | struct bgp_filter *filter; |
| 704 | struct bgp_info info; |
| 705 | route_map_result_t ret; |
| 706 | |
| 707 | filter = &peer->filter[afi][safi]; |
| 708 | |
| 709 | /* Apply default weight value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 710 | if (peer->weight) |
| 711 | (bgp_attr_extra_get (attr))->weight = peer->weight; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 712 | |
| 713 | /* Route map apply. */ |
| 714 | if (ROUTE_MAP_IN_NAME (filter)) |
| 715 | { |
| 716 | /* Duplicate current value to new strucutre for modification. */ |
| 717 | info.peer = peer; |
| 718 | info.attr = attr; |
| 719 | |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 720 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN); |
| 721 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 722 | /* Apply BGP route map to the attribute. */ |
| 723 | ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info); |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 724 | |
| 725 | peer->rmap_type = 0; |
| 726 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 727 | if (ret == RMAP_DENYMATCH) |
David Lamparter | c460e57 | 2014-06-04 00:54:58 +0200 | [diff] [blame] | 728 | /* caller has multiple error paths with bgp_attr_flush() */ |
| 729 | return RMAP_DENY; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 730 | } |
| 731 | return RMAP_PERMIT; |
| 732 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 733 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 734 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 735 | bgp_export_modifier (struct peer *rsclient, struct peer *peer, |
| 736 | struct prefix *p, struct attr *attr, afi_t afi, safi_t safi) |
| 737 | { |
| 738 | struct bgp_filter *filter; |
| 739 | struct bgp_info info; |
| 740 | route_map_result_t ret; |
| 741 | |
| 742 | filter = &peer->filter[afi][safi]; |
| 743 | |
| 744 | /* Route map apply. */ |
| 745 | if (ROUTE_MAP_EXPORT_NAME (filter)) |
| 746 | { |
| 747 | /* Duplicate current value to new strucutre for modification. */ |
| 748 | info.peer = rsclient; |
| 749 | info.attr = attr; |
| 750 | |
| 751 | SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT); |
| 752 | |
| 753 | /* Apply BGP route map to the attribute. */ |
| 754 | ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info); |
| 755 | |
| 756 | rsclient->rmap_type = 0; |
| 757 | |
| 758 | if (ret == RMAP_DENYMATCH) |
| 759 | { |
| 760 | /* Free newly generated AS path and community by route-map. */ |
| 761 | bgp_attr_flush (attr); |
| 762 | return RMAP_DENY; |
| 763 | } |
| 764 | } |
| 765 | return RMAP_PERMIT; |
| 766 | } |
| 767 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 768 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 769 | bgp_import_modifier (struct peer *rsclient, struct peer *peer, |
| 770 | struct prefix *p, struct attr *attr, afi_t afi, safi_t safi) |
| 771 | { |
| 772 | struct bgp_filter *filter; |
| 773 | struct bgp_info info; |
| 774 | route_map_result_t ret; |
| 775 | |
| 776 | filter = &rsclient->filter[afi][safi]; |
| 777 | |
| 778 | /* Apply default weight value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 779 | if (peer->weight) |
| 780 | (bgp_attr_extra_get (attr))->weight = peer->weight; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 781 | |
| 782 | /* Route map apply. */ |
| 783 | if (ROUTE_MAP_IMPORT_NAME (filter)) |
| 784 | { |
| 785 | /* Duplicate current value to new strucutre for modification. */ |
| 786 | info.peer = peer; |
| 787 | info.attr = attr; |
| 788 | |
| 789 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT); |
| 790 | |
| 791 | /* Apply BGP route map to the attribute. */ |
| 792 | ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info); |
| 793 | |
| 794 | peer->rmap_type = 0; |
| 795 | |
| 796 | if (ret == RMAP_DENYMATCH) |
| 797 | { |
| 798 | /* Free newly generated AS path and community by route-map. */ |
| 799 | bgp_attr_flush (attr); |
| 800 | return RMAP_DENY; |
| 801 | } |
| 802 | } |
| 803 | return RMAP_PERMIT; |
| 804 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 805 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 806 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 807 | bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p, |
| 808 | struct attr *attr, afi_t afi, safi_t safi) |
| 809 | { |
| 810 | int ret; |
| 811 | char buf[SU_ADDRSTRLEN]; |
| 812 | struct bgp_filter *filter; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | struct peer *from; |
| 814 | struct bgp *bgp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 815 | int transparent; |
| 816 | int reflect; |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 817 | struct attr *riattr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 818 | |
| 819 | from = ri->peer; |
| 820 | filter = &peer->filter[afi][safi]; |
| 821 | bgp = peer->bgp; |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 822 | riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 823 | |
Paul Jakma | 750e814 | 2008-07-22 21:11:48 +0000 | [diff] [blame] | 824 | if (DISABLE_BGP_ANNOUNCE) |
| 825 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 826 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 827 | /* Do not send announces to RS-clients from the 'normal' bgp_table. */ |
| 828 | if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 829 | return 0; |
| 830 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 831 | /* Do not send back route to sender. */ |
| 832 | if (from == peer) |
| 833 | return 0; |
| 834 | |
| 835 | /* Aggregate-address suppress check. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 836 | if (ri->extra && ri->extra->suppress) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | if (! UNSUPPRESS_MAP_NAME (filter)) |
| 838 | return 0; |
| 839 | |
| 840 | /* Default route check. */ |
| 841 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE)) |
| 842 | { |
| 843 | if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) |
| 844 | return 0; |
| 845 | #ifdef HAVE_IPV6 |
| 846 | else if (p->family == AF_INET6 && p->prefixlen == 0) |
| 847 | return 0; |
| 848 | #endif /* HAVE_IPV6 */ |
| 849 | } |
| 850 | |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 851 | /* Transparency check. */ |
| 852 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) |
| 853 | && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 854 | transparent = 1; |
| 855 | else |
| 856 | transparent = 0; |
| 857 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 858 | /* If community is not disabled check the no-export and local. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 859 | if (! transparent && bgp_community_filter (peer, riattr)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 860 | return 0; |
| 861 | |
| 862 | /* If the attribute has originator-id and it is same as remote |
| 863 | peer's id. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 864 | if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 865 | { |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 866 | if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | { |
| 868 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 869 | zlog (peer->log, LOG_DEBUG, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | "%s [Update:SEND] %s/%d originator-id is same as remote router-id", |
| 871 | peer->host, |
| 872 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 873 | p->prefixlen); |
| 874 | return 0; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /* ORF prefix-list filter check */ |
| 879 | if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) |
| 880 | && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) |
| 881 | || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV))) |
| 882 | if (peer->orf_plist[afi][safi]) |
| 883 | { |
| 884 | if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY) |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | /* Output filter check. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 889 | if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 890 | { |
| 891 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 892 | zlog (peer->log, LOG_DEBUG, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 893 | "%s [Update:SEND] %s/%d is filtered", |
| 894 | peer->host, |
| 895 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 896 | p->prefixlen); |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | #ifdef BGP_SEND_ASPATH_CHECK |
| 901 | /* AS path loop check. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 902 | if (aspath_loop_check (riattr->aspath, peer->as)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 903 | { |
| 904 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 905 | zlog (peer->log, LOG_DEBUG, |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 906 | "%s [Update:SEND] suppress announcement to peer AS %u is AS path.", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 907 | peer->host, peer->as); |
| 908 | return 0; |
| 909 | } |
| 910 | #endif /* BGP_SEND_ASPATH_CHECK */ |
| 911 | |
| 912 | /* If we're a CONFED we need to loop check the CONFED ID too */ |
| 913 | if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) |
| 914 | { |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 915 | if (aspath_loop_check(riattr->aspath, bgp->confed_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 916 | { |
| 917 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 918 | zlog (peer->log, LOG_DEBUG, |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 919 | "%s [Update:SEND] suppress announcement to peer AS %u is AS path.", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 920 | peer->host, |
| 921 | bgp->confed_id); |
| 922 | return 0; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /* Route-Reflect check. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 927 | if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 928 | reflect = 1; |
| 929 | else |
| 930 | reflect = 0; |
| 931 | |
| 932 | /* IBGP reflection check. */ |
| 933 | if (reflect) |
| 934 | { |
| 935 | /* A route from a Client peer. */ |
| 936 | if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
| 937 | { |
| 938 | /* Reflect to all the Non-Client peers and also to the |
| 939 | Client peers other than the originator. Originator check |
| 940 | is already done. So there is noting to do. */ |
| 941 | /* no bgp client-to-client reflection check. */ |
| 942 | if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT)) |
| 943 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
| 944 | return 0; |
| 945 | } |
| 946 | else |
| 947 | { |
| 948 | /* A route from a Non-client peer. Reflect to all other |
| 949 | clients. */ |
| 950 | if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
| 951 | return 0; |
| 952 | } |
| 953 | } |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 954 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | /* For modify attribute, copy it to temporary structure. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 956 | bgp_attr_dup (attr, riattr); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 957 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 958 | /* If local-preference is not set. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 959 | if ((peer->sort == BGP_PEER_IBGP |
| 960 | || peer->sort == BGP_PEER_CONFED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 961 | && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))) |
| 962 | { |
| 963 | attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF); |
| 964 | attr->local_pref = bgp->default_local_pref; |
| 965 | } |
| 966 | |
Pradosh Mohapatra | 689bb66 | 2013-09-07 07:13:37 +0000 | [diff] [blame] | 967 | /* If originator-id is not set and the route is to be reflected, |
| 968 | set the originator id */ |
| 969 | if (peer && from && peer->sort == BGP_PEER_IBGP && |
| 970 | from->sort == BGP_PEER_IBGP && |
| 971 | (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))) |
| 972 | { |
| 973 | attr->extra = bgp_attr_extra_get(attr); |
| 974 | IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id)); |
| 975 | SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID); |
| 976 | } |
| 977 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | /* Remove MED if its an EBGP peer - will get overwritten by route-maps */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 979 | if (peer->sort == BGP_PEER_EBGP |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 980 | && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
| 981 | { |
| 982 | if (ri->peer != bgp->peer_self && ! transparent |
| 983 | && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED)) |
| 984 | attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)); |
| 985 | } |
| 986 | |
| 987 | /* next-hop-set */ |
Timo Teräs | 9e7a53c | 2014-04-24 10:22:37 +0300 | [diff] [blame] | 988 | if (transparent |
| 989 | || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 990 | || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED) |
| 991 | && ((p->family == AF_INET && attr->nexthop.s_addr) |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 992 | #ifdef HAVE_IPV6 |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 993 | || (p->family == AF_INET6 && |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 994 | ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global)) |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 995 | #endif /* HAVE_IPV6 */ |
| 996 | ))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 997 | { |
| 998 | /* NEXT-HOP Unchanged. */ |
| 999 | } |
| 1000 | else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) |
| 1001 | || (p->family == AF_INET && attr->nexthop.s_addr == 0) |
| 1002 | #ifdef HAVE_IPV6 |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1003 | || (p->family == AF_INET6 && |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1004 | IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1005 | #endif /* HAVE_IPV6 */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 1006 | || (peer->sort == BGP_PEER_EBGP |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1007 | && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0)) |
| 1008 | { |
| 1009 | /* Set IPv4 nexthop. */ |
| 1010 | if (p->family == AF_INET) |
| 1011 | { |
| 1012 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1013 | memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4, |
| 1014 | IPV4_MAX_BYTELEN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1015 | else |
| 1016 | memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN); |
| 1017 | } |
| 1018 | #ifdef HAVE_IPV6 |
| 1019 | /* Set IPv6 nexthop. */ |
| 1020 | if (p->family == AF_INET6) |
| 1021 | { |
| 1022 | /* IPv6 global nexthop must be included. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1023 | memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1024 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1025 | attr->extra->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1026 | } |
| 1027 | #endif /* HAVE_IPV6 */ |
| 1028 | } |
| 1029 | |
| 1030 | #ifdef HAVE_IPV6 |
| 1031 | if (p->family == AF_INET6) |
| 1032 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1033 | /* Left nexthop_local unchanged if so configured. */ |
| 1034 | if ( CHECK_FLAG (peer->af_flags[afi][safi], |
| 1035 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) ) |
| 1036 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1037 | if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) ) |
| 1038 | attr->extra->mp_nexthop_len=32; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1039 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1040 | attr->extra->mp_nexthop_len=16; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* Default nexthop_local treatment for non-RS-Clients */ |
| 1044 | else |
| 1045 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1046 | /* Link-local address should not be transit to different peer. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1047 | attr->extra->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1048 | |
| 1049 | /* Set link-local address for shared network peer. */ |
| 1050 | if (peer->shared_network |
| 1051 | && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local)) |
| 1052 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1053 | memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1054 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1055 | attr->extra->mp_nexthop_len = 32; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /* If bgpd act as BGP-4+ route-reflector, do not send link-local |
| 1059 | address.*/ |
| 1060 | if (reflect) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1061 | attr->extra->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1062 | |
| 1063 | /* If BGP-4+ link-local nexthop is not link-local nexthop. */ |
| 1064 | if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local)) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1065 | attr->extra->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1066 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1067 | |
| 1068 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1069 | #endif /* HAVE_IPV6 */ |
| 1070 | |
| 1071 | /* If this is EBGP peer and remove-private-AS is set. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 1072 | if (peer->sort == BGP_PEER_EBGP |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1073 | && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS) |
| 1074 | && aspath_private_as_check (attr->aspath)) |
| 1075 | attr->aspath = aspath_empty_get (); |
| 1076 | |
| 1077 | /* Route map & unsuppress-map apply. */ |
| 1078 | if (ROUTE_MAP_OUT_NAME (filter) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1079 | || (ri->extra && ri->extra->suppress) ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1080 | { |
Paul Jakma | 7c7fa1b | 2006-02-18 10:52:09 +0000 | [diff] [blame] | 1081 | struct bgp_info info; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1082 | struct attr dummy_attr; |
| 1083 | struct attr_extra dummy_extra; |
| 1084 | |
| 1085 | dummy_attr.extra = &dummy_extra; |
| 1086 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1087 | info.peer = peer; |
| 1088 | info.attr = attr; |
| 1089 | |
| 1090 | /* The route reflector is not allowed to modify the attributes |
| 1091 | of the reflected IBGP routes. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 1092 | if (from->sort == BGP_PEER_IBGP |
| 1093 | && peer->sort == BGP_PEER_IBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1094 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1095 | bgp_attr_dup (&dummy_attr, attr); |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1096 | info.attr = &dummy_attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1097 | } |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 1098 | |
| 1099 | SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); |
| 1100 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1101 | if (ri->extra && ri->extra->suppress) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1102 | ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info); |
| 1103 | else |
| 1104 | ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info); |
| 1105 | |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 1106 | peer->rmap_type = 0; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1107 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1108 | if (ret == RMAP_DENYMATCH) |
| 1109 | { |
| 1110 | bgp_attr_flush (attr); |
| 1111 | return 0; |
| 1112 | } |
| 1113 | } |
| 1114 | return 1; |
| 1115 | } |
| 1116 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1117 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1118 | bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient, |
| 1119 | struct prefix *p, struct attr *attr, afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1120 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1121 | int ret; |
| 1122 | char buf[SU_ADDRSTRLEN]; |
| 1123 | struct bgp_filter *filter; |
| 1124 | struct bgp_info info; |
| 1125 | struct peer *from; |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1126 | struct attr *riattr; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1127 | |
| 1128 | from = ri->peer; |
| 1129 | filter = &rsclient->filter[afi][safi]; |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1130 | riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1131 | |
Paul Jakma | 750e814 | 2008-07-22 21:11:48 +0000 | [diff] [blame] | 1132 | if (DISABLE_BGP_ANNOUNCE) |
| 1133 | return 0; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1134 | |
| 1135 | /* Do not send back route to sender. */ |
| 1136 | if (from == rsclient) |
| 1137 | return 0; |
| 1138 | |
| 1139 | /* Aggregate-address suppress check. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1140 | if (ri->extra && ri->extra->suppress) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1141 | if (! UNSUPPRESS_MAP_NAME (filter)) |
| 1142 | return 0; |
| 1143 | |
| 1144 | /* Default route check. */ |
| 1145 | if (CHECK_FLAG (rsclient->af_sflags[afi][safi], |
| 1146 | PEER_STATUS_DEFAULT_ORIGINATE)) |
| 1147 | { |
| 1148 | if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) |
| 1149 | return 0; |
| 1150 | #ifdef HAVE_IPV6 |
| 1151 | else if (p->family == AF_INET6 && p->prefixlen == 0) |
| 1152 | return 0; |
| 1153 | #endif /* HAVE_IPV6 */ |
| 1154 | } |
| 1155 | |
| 1156 | /* If the attribute has originator-id and it is same as remote |
| 1157 | peer's id. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1158 | if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1159 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1160 | if (IPV4_ADDR_SAME (&rsclient->remote_id, |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1161 | &riattr->extra->originator_id)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1162 | { |
| 1163 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1164 | zlog (rsclient->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1165 | "%s [Update:SEND] %s/%d originator-id is same as remote router-id", |
| 1166 | rsclient->host, |
| 1167 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 1168 | p->prefixlen); |
| 1169 | return 0; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | /* ORF prefix-list filter check */ |
| 1174 | if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) |
| 1175 | && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) |
| 1176 | || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV))) |
| 1177 | if (rsclient->orf_plist[afi][safi]) |
| 1178 | { |
| 1179 | if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY) |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | /* Output filter check. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1184 | if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1185 | { |
| 1186 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1187 | zlog (rsclient->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1188 | "%s [Update:SEND] %s/%d is filtered", |
| 1189 | rsclient->host, |
| 1190 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 1191 | p->prefixlen); |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | #ifdef BGP_SEND_ASPATH_CHECK |
| 1196 | /* AS path loop check. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1197 | if (aspath_loop_check (riattr->aspath, rsclient->as)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1198 | { |
| 1199 | if (BGP_DEBUG (filter, FILTER)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1200 | zlog (rsclient->log, LOG_DEBUG, |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 1201 | "%s [Update:SEND] suppress announcement to peer AS %u is AS path.", |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1202 | rsclient->host, rsclient->as); |
| 1203 | return 0; |
| 1204 | } |
| 1205 | #endif /* BGP_SEND_ASPATH_CHECK */ |
| 1206 | |
| 1207 | /* For modify attribute, copy it to temporary structure. */ |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1208 | bgp_attr_dup (attr, riattr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1209 | |
| 1210 | /* next-hop-set */ |
| 1211 | if ((p->family == AF_INET && attr->nexthop.s_addr == 0) |
| 1212 | #ifdef HAVE_IPV6 |
| 1213 | || (p->family == AF_INET6 && |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1214 | IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1215 | #endif /* HAVE_IPV6 */ |
| 1216 | ) |
| 1217 | { |
| 1218 | /* Set IPv4 nexthop. */ |
| 1219 | if (p->family == AF_INET) |
| 1220 | { |
| 1221 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1222 | memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1223 | IPV4_MAX_BYTELEN); |
| 1224 | else |
| 1225 | memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN); |
| 1226 | } |
| 1227 | #ifdef HAVE_IPV6 |
| 1228 | /* Set IPv6 nexthop. */ |
| 1229 | if (p->family == AF_INET6) |
| 1230 | { |
| 1231 | /* IPv6 global nexthop must be included. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1232 | memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1233 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1234 | attr->extra->mp_nexthop_len = 16; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1235 | } |
| 1236 | #endif /* HAVE_IPV6 */ |
| 1237 | } |
| 1238 | |
| 1239 | #ifdef HAVE_IPV6 |
| 1240 | if (p->family == AF_INET6) |
| 1241 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1242 | struct attr_extra *attre = attr->extra; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1243 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1244 | /* Left nexthop_local unchanged if so configured. */ |
| 1245 | if ( CHECK_FLAG (rsclient->af_flags[afi][safi], |
| 1246 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) ) |
| 1247 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1248 | if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) ) |
| 1249 | attre->mp_nexthop_len=32; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1250 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1251 | attre->mp_nexthop_len=16; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | /* Default nexthop_local treatment for RS-Clients */ |
| 1255 | else |
| 1256 | { |
| 1257 | /* Announcer and RS-Client are both in the same network */ |
| 1258 | if (rsclient->shared_network && from->shared_network && |
| 1259 | (rsclient->ifindex == from->ifindex)) |
| 1260 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1261 | if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) ) |
| 1262 | attre->mp_nexthop_len=32; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1263 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1264 | attre->mp_nexthop_len=16; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /* Set link-local address for shared network peer. */ |
| 1268 | else if (rsclient->shared_network |
| 1269 | && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local)) |
| 1270 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1271 | memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1272 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1273 | attre->mp_nexthop_len = 32; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1277 | attre->mp_nexthop_len = 16; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | } |
| 1281 | #endif /* HAVE_IPV6 */ |
| 1282 | |
| 1283 | |
| 1284 | /* If this is EBGP peer and remove-private-AS is set. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 1285 | if (rsclient->sort == BGP_PEER_EBGP |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1286 | && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS) |
| 1287 | && aspath_private_as_check (attr->aspath)) |
| 1288 | attr->aspath = aspath_empty_get (); |
| 1289 | |
| 1290 | /* Route map & unsuppress-map apply. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1291 | if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) ) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1292 | { |
| 1293 | info.peer = rsclient; |
| 1294 | info.attr = attr; |
| 1295 | |
| 1296 | SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT); |
| 1297 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1298 | if (ri->extra && ri->extra->suppress) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1299 | ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info); |
| 1300 | else |
| 1301 | ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info); |
| 1302 | |
| 1303 | rsclient->rmap_type = 0; |
| 1304 | |
| 1305 | if (ret == RMAP_DENYMATCH) |
| 1306 | { |
| 1307 | bgp_attr_flush (attr); |
| 1308 | return 0; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | return 1; |
| 1313 | } |
| 1314 | |
| 1315 | struct bgp_info_pair |
| 1316 | { |
| 1317 | struct bgp_info *old; |
| 1318 | struct bgp_info *new; |
| 1319 | }; |
| 1320 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1321 | static void |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1322 | bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, |
| 1323 | struct bgp_maxpaths_cfg *mpath_cfg, |
| 1324 | struct bgp_info_pair *result) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1325 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1326 | struct bgp_info *new_select; |
| 1327 | struct bgp_info *old_select; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1328 | struct bgp_info *ri; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1329 | struct bgp_info *ri1; |
| 1330 | struct bgp_info *ri2; |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1331 | struct bgp_info *nextri = NULL; |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1332 | int paths_eq, do_mpath; |
| 1333 | struct list mp_list; |
| 1334 | |
| 1335 | bgp_mp_list_init (&mp_list); |
| 1336 | do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS || |
| 1337 | mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS); |
| 1338 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1339 | /* bgp deterministic-med */ |
| 1340 | new_select = NULL; |
| 1341 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) |
| 1342 | for (ri1 = rn->info; ri1; ri1 = ri1->next) |
| 1343 | { |
| 1344 | if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK)) |
| 1345 | continue; |
| 1346 | if (BGP_INFO_HOLDDOWN (ri1)) |
| 1347 | continue; |
| 1348 | |
| 1349 | new_select = ri1; |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1350 | if (do_mpath) |
| 1351 | bgp_mp_list_add (&mp_list, ri1); |
| 1352 | old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1353 | if (ri1->next) |
| 1354 | for (ri2 = ri1->next; ri2; ri2 = ri2->next) |
| 1355 | { |
| 1356 | if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK)) |
| 1357 | continue; |
| 1358 | if (BGP_INFO_HOLDDOWN (ri2)) |
| 1359 | continue; |
| 1360 | |
| 1361 | if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath) |
| 1362 | || aspath_cmp_left_confed (ri1->attr->aspath, |
| 1363 | ri2->attr->aspath)) |
| 1364 | { |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1365 | if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED)) |
| 1366 | old_select = ri2; |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1367 | if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1368 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1369 | bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1370 | new_select = ri2; |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1371 | if (do_mpath && !paths_eq) |
| 1372 | { |
| 1373 | bgp_mp_list_clear (&mp_list); |
| 1374 | bgp_mp_list_add (&mp_list, ri2); |
| 1375 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1378 | if (do_mpath && paths_eq) |
| 1379 | bgp_mp_list_add (&mp_list, ri2); |
| 1380 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1381 | bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1382 | } |
| 1383 | } |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1384 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK); |
| 1385 | bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED); |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1386 | |
| 1387 | bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg); |
| 1388 | bgp_mp_list_clear (&mp_list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | /* Check old selected route and new selected route. */ |
| 1392 | old_select = NULL; |
| 1393 | new_select = NULL; |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1394 | for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1395 | { |
| 1396 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) |
| 1397 | old_select = ri; |
| 1398 | |
| 1399 | if (BGP_INFO_HOLDDOWN (ri)) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1400 | { |
| 1401 | /* reap REMOVED routes, if needs be |
| 1402 | * selected route must stay for a while longer though |
| 1403 | */ |
| 1404 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) |
| 1405 | && (ri != old_select)) |
| 1406 | bgp_info_reap (rn, ri); |
| 1407 | |
| 1408 | continue; |
| 1409 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1410 | |
| 1411 | if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED) |
| 1412 | && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED))) |
| 1413 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1414 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1415 | continue; |
| 1416 | } |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1417 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK); |
| 1418 | bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1419 | |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1420 | if (bgp_info_cmp (bgp, ri, new_select, &paths_eq)) |
| 1421 | { |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1422 | if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) |
| 1423 | bgp_mp_dmed_deselect (new_select); |
| 1424 | |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1425 | new_select = ri; |
| 1426 | |
| 1427 | if (do_mpath && !paths_eq) |
| 1428 | { |
| 1429 | bgp_mp_list_clear (&mp_list); |
| 1430 | bgp_mp_list_add (&mp_list, ri); |
| 1431 | } |
| 1432 | } |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1433 | else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) |
| 1434 | bgp_mp_dmed_deselect (ri); |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1435 | |
| 1436 | if (do_mpath && paths_eq) |
| 1437 | bgp_mp_list_add (&mp_list, ri); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1438 | } |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1439 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1440 | |
Josh Bailey | 6918e74 | 2011-07-20 20:48:20 -0700 | [diff] [blame] | 1441 | if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)) |
| 1442 | bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg); |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1443 | |
Josh Bailey | 0b597ef | 2011-07-20 20:49:11 -0700 | [diff] [blame] | 1444 | bgp_info_mpath_aggregate_update (new_select, old_select); |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1445 | bgp_mp_list_clear (&mp_list); |
| 1446 | |
| 1447 | result->old = old_select; |
| 1448 | result->new = new_select; |
| 1449 | |
| 1450 | return; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1453 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1454 | bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected, |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1455 | struct bgp_node *rn, afi_t afi, safi_t safi) |
| 1456 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1457 | struct prefix *p; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1458 | struct attr attr; |
| 1459 | struct attr_extra extra; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1460 | |
| 1461 | p = &rn->p; |
| 1462 | |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1463 | /* Announce route to Established peer. */ |
| 1464 | if (peer->status != Established) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1465 | return 0; |
| 1466 | |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1467 | /* Address family configuration check. */ |
| 1468 | if (! peer->afc_nego[afi][safi]) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1469 | return 0; |
| 1470 | |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1471 | /* First update is deferred until ORF or ROUTE-REFRESH is received */ |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1472 | if (CHECK_FLAG (peer->af_sflags[afi][safi], |
| 1473 | PEER_STATUS_ORF_WAIT_REFRESH)) |
| 1474 | return 0; |
| 1475 | |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1476 | /* It's initialized in bgp_announce_[check|check_rsclient]() */ |
| 1477 | attr.extra = &extra; |
| 1478 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 1479 | switch (bgp_node_table (rn)->type) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1480 | { |
| 1481 | case BGP_TABLE_MAIN: |
| 1482 | /* Announcement to peer->conf. If the route is filtered, |
| 1483 | withdraw it. */ |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1484 | if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi)) |
| 1485 | bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1486 | else |
| 1487 | bgp_adj_out_unset (rn, peer, p, afi, safi); |
| 1488 | break; |
| 1489 | case BGP_TABLE_RSCLIENT: |
| 1490 | /* Announcement to peer->conf. If the route is filtered, |
| 1491 | withdraw it. */ |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1492 | if (selected && |
| 1493 | bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi)) |
| 1494 | bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected); |
| 1495 | else |
| 1496 | bgp_adj_out_unset (rn, peer, p, afi, safi); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1497 | break; |
| 1498 | } |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1499 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1500 | return 0; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1501 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1502 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1503 | struct bgp_process_queue |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1504 | { |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1505 | struct bgp *bgp; |
| 1506 | struct bgp_node *rn; |
| 1507 | afi_t afi; |
| 1508 | safi_t safi; |
| 1509 | }; |
| 1510 | |
| 1511 | static wq_item_status |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1512 | bgp_process_rsclient (struct work_queue *wq, void *data) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1513 | { |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1514 | struct bgp_process_queue *pq = data; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1515 | struct bgp *bgp = pq->bgp; |
| 1516 | struct bgp_node *rn = pq->rn; |
| 1517 | afi_t afi = pq->afi; |
| 1518 | safi_t safi = pq->safi; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1519 | struct bgp_info *new_select; |
| 1520 | struct bgp_info *old_select; |
| 1521 | struct bgp_info_pair old_and_new; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1522 | struct listnode *node, *nnode; |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 1523 | struct peer *rsclient = bgp_node_table (rn)->owner; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1524 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1525 | /* Best path selection. */ |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1526 | bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1527 | new_select = old_and_new.new; |
| 1528 | old_select = old_and_new.old; |
| 1529 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1530 | if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP)) |
| 1531 | { |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1532 | if (rsclient->group) |
| 1533 | for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient)) |
| 1534 | { |
| 1535 | /* Nothing to do. */ |
| 1536 | if (old_select && old_select == new_select) |
| 1537 | if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED)) |
| 1538 | continue; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1539 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1540 | if (old_select) |
| 1541 | bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED); |
| 1542 | if (new_select) |
| 1543 | { |
| 1544 | bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED); |
| 1545 | bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED); |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1546 | UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG); |
| 1547 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1548 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1549 | bgp_process_announce_selected (rsclient, new_select, rn, |
| 1550 | afi, safi); |
| 1551 | } |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1552 | } |
| 1553 | else |
| 1554 | { |
hasso | b739579 | 2005-08-26 12:58:38 +0000 | [diff] [blame] | 1555 | if (old_select) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1556 | bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED); |
hasso | b739579 | 2005-08-26 12:58:38 +0000 | [diff] [blame] | 1557 | if (new_select) |
| 1558 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1559 | bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED); |
| 1560 | bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED); |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1561 | UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG); |
hasso | b739579 | 2005-08-26 12:58:38 +0000 | [diff] [blame] | 1562 | } |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1563 | bgp_process_announce_selected (rsclient, new_select, rn, afi, safi); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1564 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1565 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1566 | if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED)) |
| 1567 | bgp_info_reap (rn, old_select); |
| 1568 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1569 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
| 1570 | return WQ_SUCCESS; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1573 | static wq_item_status |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1574 | bgp_process_main (struct work_queue *wq, void *data) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1575 | { |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1576 | struct bgp_process_queue *pq = data; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1577 | struct bgp *bgp = pq->bgp; |
| 1578 | struct bgp_node *rn = pq->rn; |
| 1579 | afi_t afi = pq->afi; |
| 1580 | safi_t safi = pq->safi; |
| 1581 | struct prefix *p = &rn->p; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1582 | struct bgp_info *new_select; |
| 1583 | struct bgp_info *old_select; |
| 1584 | struct bgp_info_pair old_and_new; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1585 | struct listnode *node, *nnode; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1586 | struct peer *peer; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1587 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1588 | /* Best path selection. */ |
Josh Bailey | 96450fa | 2011-07-20 20:45:12 -0700 | [diff] [blame] | 1589 | bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1590 | old_select = old_and_new.old; |
| 1591 | new_select = old_and_new.new; |
| 1592 | |
| 1593 | /* Nothing to do. */ |
| 1594 | if (old_select && old_select == new_select) |
| 1595 | { |
| 1596 | if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED)) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1597 | { |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1598 | if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) || |
| 1599 | CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG)) |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 1600 | bgp_zebra_announce (p, old_select, bgp, safi); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1601 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1602 | UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1603 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
| 1604 | return WQ_SUCCESS; |
| 1605 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1606 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1607 | |
hasso | 338b342 | 2005-02-23 14:27:24 +0000 | [diff] [blame] | 1608 | if (old_select) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1609 | bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED); |
hasso | 338b342 | 2005-02-23 14:27:24 +0000 | [diff] [blame] | 1610 | if (new_select) |
| 1611 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1612 | bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED); |
| 1613 | bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED); |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1614 | UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG); |
hasso | 338b342 | 2005-02-23 14:27:24 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1618 | /* Check each BGP peer. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1619 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1620 | { |
Paul Jakma | 9eda90c | 2007-08-30 13:36:17 +0000 | [diff] [blame] | 1621 | bgp_process_announce_selected (peer, new_select, rn, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /* FIB update. */ |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 1625 | if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name && |
| 1626 | ! bgp_option_check (BGP_OPT_NO_FIB))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1627 | { |
| 1628 | if (new_select |
| 1629 | && new_select->type == ZEBRA_ROUTE_BGP |
| 1630 | && new_select->sub_type == BGP_ROUTE_NORMAL) |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 1631 | bgp_zebra_announce (p, new_select, bgp, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1632 | else |
| 1633 | { |
| 1634 | /* Withdraw the route from the kernel. */ |
| 1635 | if (old_select |
| 1636 | && old_select->type == ZEBRA_ROUTE_BGP |
| 1637 | && old_select->sub_type == BGP_ROUTE_NORMAL) |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 1638 | bgp_zebra_withdraw (p, old_select, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1639 | } |
| 1640 | } |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1641 | |
| 1642 | /* Reap old select bgp_info, it it has been removed */ |
| 1643 | if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED)) |
| 1644 | bgp_info_reap (rn, old_select); |
| 1645 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1646 | UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
| 1647 | return WQ_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1650 | static void |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1651 | bgp_processq_del (struct work_queue *wq, void *data) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1652 | { |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1653 | struct bgp_process_queue *pq = data; |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 1654 | struct bgp_table *table = bgp_node_table (pq->rn); |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 1655 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1656 | bgp_unlock (pq->bgp); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1657 | bgp_unlock_node (pq->rn); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1658 | bgp_table_unlock (table); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1659 | XFREE (MTYPE_BGP_PROCESS_QUEUE, pq); |
| 1660 | } |
| 1661 | |
| 1662 | static void |
| 1663 | bgp_process_queue_init (void) |
| 1664 | { |
| 1665 | bm->process_main_queue |
| 1666 | = work_queue_new (bm->master, "process_main_queue"); |
| 1667 | bm->process_rsclient_queue |
| 1668 | = work_queue_new (bm->master, "process_rsclient_queue"); |
| 1669 | |
| 1670 | if ( !(bm->process_main_queue && bm->process_rsclient_queue) ) |
| 1671 | { |
| 1672 | zlog_err ("%s: Failed to allocate work queue", __func__); |
| 1673 | exit (1); |
| 1674 | } |
| 1675 | |
| 1676 | bm->process_main_queue->spec.workfunc = &bgp_process_main; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1677 | bm->process_main_queue->spec.del_item_data = &bgp_processq_del; |
Paul Jakma | 838bbde | 2010-01-08 14:05:32 +0000 | [diff] [blame] | 1678 | bm->process_main_queue->spec.max_retries = 0; |
| 1679 | bm->process_main_queue->spec.hold = 50; |
| 1680 | |
Paul Jakma | 838bbde | 2010-01-08 14:05:32 +0000 | [diff] [blame] | 1681 | bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient; |
David Lamparter | d43f8b3 | 2015-03-03 08:54:54 +0100 | [diff] [blame] | 1682 | bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del; |
| 1683 | bm->process_rsclient_queue->spec.max_retries = 0; |
| 1684 | bm->process_rsclient_queue->spec.hold = 50; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1688 | bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) |
| 1689 | { |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1690 | struct bgp_process_queue *pqnode; |
| 1691 | |
| 1692 | /* already scheduled for processing? */ |
| 1693 | if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED)) |
| 1694 | return; |
| 1695 | |
| 1696 | if ( (bm->process_main_queue == NULL) || |
| 1697 | (bm->process_rsclient_queue == NULL) ) |
| 1698 | bgp_process_queue_init (); |
| 1699 | |
| 1700 | pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, |
| 1701 | sizeof (struct bgp_process_queue)); |
| 1702 | if (!pqnode) |
| 1703 | return; |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1704 | |
| 1705 | /* all unlocked in bgp_processq_del */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 1706 | bgp_table_lock (bgp_node_table (rn)); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1707 | pqnode->rn = bgp_lock_node (rn); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1708 | pqnode->bgp = bgp; |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1709 | bgp_lock (bgp); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1710 | pqnode->afi = afi; |
| 1711 | pqnode->safi = safi; |
| 1712 | |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 1713 | switch (bgp_node_table (rn)->type) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1714 | { |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1715 | case BGP_TABLE_MAIN: |
| 1716 | work_queue_add (bm->process_main_queue, pqnode); |
| 1717 | break; |
| 1718 | case BGP_TABLE_RSCLIENT: |
| 1719 | work_queue_add (bm->process_rsclient_queue, pqnode); |
| 1720 | break; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1721 | } |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1722 | |
Stephen Hemminger | 07ff4dc | 2013-01-04 22:29:20 +0000 | [diff] [blame] | 1723 | SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 1724 | return; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1725 | } |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 1726 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1727 | static int |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 1728 | bgp_maximum_prefix_restart_timer (struct thread *thread) |
| 1729 | { |
| 1730 | struct peer *peer; |
| 1731 | |
| 1732 | peer = THREAD_ARG (thread); |
| 1733 | peer->t_pmax_restart = NULL; |
| 1734 | |
| 1735 | if (BGP_DEBUG (events, EVENTS)) |
| 1736 | zlog_debug ("%s Maximum-prefix restart timer expired, restore peering", |
| 1737 | peer->host); |
| 1738 | |
| 1739 | peer_clear (peer); |
| 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1744 | int |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 1745 | bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, |
| 1746 | safi_t safi, int always) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1747 | { |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1748 | if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) |
| 1749 | return 0; |
| 1750 | |
| 1751 | if (peer->pcount[afi][safi] > peer->pmax[afi][safi]) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1752 | { |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1753 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT) |
| 1754 | && ! always) |
| 1755 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1756 | |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1757 | zlog (peer->log, LOG_INFO, |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 1758 | "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, " |
| 1759 | "limit %ld", afi_safi_print (afi, safi), peer->host, |
| 1760 | peer->pcount[afi][safi], peer->pmax[afi][safi]); |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1761 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1762 | |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1763 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)) |
| 1764 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1765 | |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1766 | { |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 1767 | u_int8_t ndata[7]; |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1768 | |
| 1769 | if (safi == SAFI_MPLS_VPN) |
Denis Ovsienko | 42e6d74 | 2011-07-14 12:36:19 +0400 | [diff] [blame] | 1770 | safi = SAFI_MPLS_LABELED_VPN; |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 1771 | |
| 1772 | ndata[0] = (afi >> 8); |
| 1773 | ndata[1] = afi; |
| 1774 | ndata[2] = safi; |
| 1775 | ndata[3] = (peer->pmax[afi][safi] >> 24); |
| 1776 | ndata[4] = (peer->pmax[afi][safi] >> 16); |
| 1777 | ndata[5] = (peer->pmax[afi][safi] >> 8); |
| 1778 | ndata[6] = (peer->pmax[afi][safi]); |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1779 | |
| 1780 | SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); |
| 1781 | bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE, |
| 1782 | BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7); |
| 1783 | } |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 1784 | |
| 1785 | /* restart timer start */ |
| 1786 | if (peer->pmax_restart[afi][safi]) |
| 1787 | { |
| 1788 | peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60; |
| 1789 | |
| 1790 | if (BGP_DEBUG (events, EVENTS)) |
| 1791 | zlog_debug ("%s Maximum-prefix restart timer started for %d secs", |
| 1792 | peer->host, peer->v_pmax_restart); |
| 1793 | |
| 1794 | BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer, |
| 1795 | peer->v_pmax_restart); |
| 1796 | } |
| 1797 | |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1798 | return 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1799 | } |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1800 | else |
| 1801 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); |
| 1802 | |
| 1803 | if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) |
| 1804 | { |
| 1805 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD) |
| 1806 | && ! always) |
| 1807 | return 0; |
| 1808 | |
| 1809 | zlog (peer->log, LOG_INFO, |
hasso | 0a486e5 | 2005-02-01 20:57:17 +0000 | [diff] [blame] | 1810 | "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld", |
| 1811 | afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi], |
| 1812 | peer->pmax[afi][safi]); |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 1813 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); |
| 1814 | } |
| 1815 | else |
| 1816 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1817 | return 0; |
| 1818 | } |
| 1819 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1820 | /* Unconditionally remove the route from the RIB, without taking |
| 1821 | * damping into consideration (eg, because the session went down) |
| 1822 | */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1823 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1824 | bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
| 1825 | afi_t afi, safi_t safi) |
| 1826 | { |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 1827 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
| 1828 | |
| 1829 | if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
| 1830 | bgp_info_delete (rn, ri); /* keep historical info */ |
| 1831 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1832 | bgp_process (peer->bgp, rn, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1835 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1836 | bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer, |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1837 | afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1838 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1839 | int status = BGP_DAMP_NONE; |
| 1840 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1841 | /* apply dampening, if result is suppressed, we'll be retaining |
| 1842 | * the bgp_info in the RIB for historical reference. |
| 1843 | */ |
| 1844 | if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 1845 | && peer->sort == BGP_PEER_EBGP) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 1846 | if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0)) |
| 1847 | == BGP_DAMP_SUPPRESSED) |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 1848 | { |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 1849 | bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi); |
| 1850 | return; |
| 1851 | } |
| 1852 | |
| 1853 | bgp_rib_remove (rn, ri, peer, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1856 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1857 | bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi, |
| 1858 | struct attr *attr, struct peer *peer, struct prefix *p, int type, |
| 1859 | int sub_type, struct prefix_rd *prd, u_char *tag) |
| 1860 | { |
| 1861 | struct bgp_node *rn; |
| 1862 | struct bgp *bgp; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1863 | struct attr new_attr; |
| 1864 | struct attr_extra new_extra; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1865 | struct attr *attr_new; |
| 1866 | struct attr *attr_new2; |
| 1867 | struct bgp_info *ri; |
| 1868 | struct bgp_info *new; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1869 | const char *reason; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1870 | char buf[SU_ADDRSTRLEN]; |
| 1871 | |
| 1872 | /* Do not insert announces from a rsclient into its own 'bgp_table'. */ |
| 1873 | if (peer == rsclient) |
| 1874 | return; |
| 1875 | |
| 1876 | bgp = peer->bgp; |
| 1877 | rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd); |
| 1878 | |
| 1879 | /* Check previously received route. */ |
| 1880 | for (ri = rn->info; ri; ri = ri->next) |
| 1881 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type) |
| 1882 | break; |
| 1883 | |
| 1884 | /* AS path loop check. */ |
Milan Kocian | 000e157 | 2013-10-18 07:59:38 +0000 | [diff] [blame] | 1885 | if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi]) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1886 | { |
| 1887 | reason = "as-path contains our own AS;"; |
| 1888 | goto filtered; |
| 1889 | } |
| 1890 | |
| 1891 | /* Route reflector originator ID check. */ |
| 1892 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1893 | && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1894 | { |
| 1895 | reason = "originator is us;"; |
| 1896 | goto filtered; |
| 1897 | } |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1898 | |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1899 | new_attr.extra = &new_extra; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1900 | bgp_attr_dup (&new_attr, attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1901 | |
| 1902 | /* Apply export policy. */ |
| 1903 | if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) && |
| 1904 | bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY) |
| 1905 | { |
| 1906 | reason = "export-policy;"; |
| 1907 | goto filtered; |
| 1908 | } |
| 1909 | |
| 1910 | attr_new2 = bgp_attr_intern (&new_attr); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1911 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1912 | /* Apply import policy. */ |
| 1913 | if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY) |
| 1914 | { |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 1915 | bgp_attr_unintern (&attr_new2); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1916 | |
| 1917 | reason = "import-policy;"; |
| 1918 | goto filtered; |
| 1919 | } |
| 1920 | |
| 1921 | attr_new = bgp_attr_intern (&new_attr); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 1922 | bgp_attr_unintern (&attr_new2); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1923 | |
| 1924 | /* IPv4 unicast next hop check. */ |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 1925 | if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1926 | { |
Denis Ovsienko | 733cd9e | 2011-12-17 19:39:30 +0400 | [diff] [blame] | 1927 | /* Next hop must not be 0.0.0.0 nor Class D/E address. */ |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1928 | if (new_attr.nexthop.s_addr == 0 |
Denis Ovsienko | 733cd9e | 2011-12-17 19:39:30 +0400 | [diff] [blame] | 1929 | || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1930 | { |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 1931 | bgp_attr_unintern (&attr_new); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1932 | |
| 1933 | reason = "martian next-hop;"; |
| 1934 | goto filtered; |
| 1935 | } |
| 1936 | } |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 1937 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1938 | /* If the update is implicit withdraw. */ |
| 1939 | if (ri) |
| 1940 | { |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 1941 | ri->uptime = bgp_clock (); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1942 | |
| 1943 | /* Same attribute comes in. */ |
Paul Jakma | 16d2e24 | 2007-04-10 19:32:10 +0000 | [diff] [blame] | 1944 | if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED) |
| 1945 | && attrhash_cmp (ri->attr, attr_new)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1946 | { |
| 1947 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1948 | bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1949 | |
| 1950 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1951 | zlog (peer->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1952 | "%s rcvd %s/%d for RS-client %s...duplicate ignored", |
| 1953 | peer->host, |
| 1954 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 1955 | p->prefixlen, rsclient->host); |
| 1956 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1957 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 1958 | bgp_attr_unintern (&attr_new); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1959 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1960 | return; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
Paul Jakma | 16d2e24 | 2007-04-10 19:32:10 +0000 | [diff] [blame] | 1963 | /* Withdraw/Announce before we fully processed the withdraw */ |
| 1964 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
| 1965 | bgp_info_restore (rn, ri); |
| 1966 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1967 | /* Received Logging. */ |
| 1968 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1969 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s", |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1970 | peer->host, |
| 1971 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 1972 | p->prefixlen, rsclient->host); |
| 1973 | |
| 1974 | /* The attribute is changed. */ |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1975 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1976 | |
| 1977 | /* Update to new attribute. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 1978 | bgp_attr_unintern (&ri->attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1979 | ri->attr = attr_new; |
| 1980 | |
| 1981 | /* Update MPLS tag. */ |
| 1982 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1983 | memcpy ((bgp_info_extra_get (ri))->tag, tag, 3); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1984 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 1985 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1986 | |
| 1987 | /* Process change. */ |
| 1988 | bgp_process (bgp, rn, afi, safi); |
| 1989 | bgp_unlock_node (rn); |
| 1990 | |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | /* Received Logging. */ |
| 1995 | if (BGP_DEBUG (update, UPDATE_IN)) |
| 1996 | { |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 1997 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s", |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 1998 | peer->host, |
| 1999 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2000 | p->prefixlen, rsclient->host); |
| 2001 | } |
| 2002 | |
| 2003 | /* Make new BGP info. */ |
| 2004 | new = bgp_info_new (); |
| 2005 | new->type = type; |
| 2006 | new->sub_type = sub_type; |
| 2007 | new->peer = peer; |
| 2008 | new->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 2009 | new->uptime = bgp_clock (); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2010 | |
| 2011 | /* Update MPLS tag. */ |
| 2012 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2013 | memcpy ((bgp_info_extra_get (new))->tag, tag, 3); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2014 | |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2015 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2016 | |
| 2017 | /* Register new BGP information. */ |
| 2018 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2019 | |
| 2020 | /* route_node_get lock */ |
| 2021 | bgp_unlock_node (rn); |
| 2022 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2023 | /* Process change. */ |
| 2024 | bgp_process (bgp, rn, afi, safi); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2025 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2026 | return; |
| 2027 | |
| 2028 | filtered: |
| 2029 | |
| 2030 | /* This BGP update is filtered. Log the reason then update BGP entry. */ |
| 2031 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2032 | zlog (peer->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2033 | "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s", |
| 2034 | peer->host, |
| 2035 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2036 | p->prefixlen, rsclient->host, reason); |
| 2037 | |
| 2038 | if (ri) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 2039 | bgp_rib_remove (rn, ri, peer, afi, safi); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2040 | |
| 2041 | bgp_unlock_node (rn); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2042 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2043 | return; |
| 2044 | } |
| 2045 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2046 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2047 | bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi, |
| 2048 | struct peer *peer, struct prefix *p, int type, int sub_type, |
| 2049 | struct prefix_rd *prd, u_char *tag) |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2050 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2051 | struct bgp_node *rn; |
| 2052 | struct bgp_info *ri; |
| 2053 | char buf[SU_ADDRSTRLEN]; |
| 2054 | |
| 2055 | if (rsclient == peer) |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2056 | return; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2057 | |
| 2058 | rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd); |
| 2059 | |
| 2060 | /* Lookup withdrawn route. */ |
| 2061 | for (ri = rn->info; ri; ri = ri->next) |
| 2062 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type) |
| 2063 | break; |
| 2064 | |
| 2065 | /* Withdraw specified route from routing table. */ |
| 2066 | if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 2067 | bgp_rib_withdraw (rn, ri, peer, afi, safi); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2068 | else if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2069 | zlog (peer->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2070 | "%s Can't find the route %s/%d", peer->host, |
| 2071 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2072 | p->prefixlen); |
| 2073 | |
| 2074 | /* Unlock bgp_node_get() lock. */ |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2075 | bgp_unlock_node (rn); |
| 2076 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2077 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2078 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2079 | bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2080 | afi_t afi, safi_t safi, int type, int sub_type, |
| 2081 | struct prefix_rd *prd, u_char *tag, int soft_reconfig) |
| 2082 | { |
| 2083 | int ret; |
| 2084 | int aspath_loop_count = 0; |
| 2085 | struct bgp_node *rn; |
| 2086 | struct bgp *bgp; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2087 | struct attr new_attr; |
| 2088 | struct attr_extra new_extra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2089 | struct attr *attr_new; |
| 2090 | struct bgp_info *ri; |
| 2091 | struct bgp_info *new; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2092 | const char *reason; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2093 | char buf[SU_ADDRSTRLEN]; |
| 2094 | |
| 2095 | bgp = peer->bgp; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2096 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2097 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2098 | /* When peer's soft reconfiguration enabled. Record input packet in |
| 2099 | Adj-RIBs-In. */ |
Jorge Boncompte [DTI2] | 343aa82 | 2012-05-07 16:53:08 +0000 | [diff] [blame] | 2100 | if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) |
| 2101 | && peer != bgp->peer_self) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2102 | bgp_adj_in_set (rn, peer, attr); |
| 2103 | |
| 2104 | /* Check previously received route. */ |
| 2105 | for (ri = rn->info; ri; ri = ri->next) |
| 2106 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type) |
| 2107 | break; |
| 2108 | |
| 2109 | /* AS path local-as loop check. */ |
| 2110 | if (peer->change_local_as) |
| 2111 | { |
| 2112 | if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)) |
| 2113 | aspath_loop_count = 1; |
| 2114 | |
| 2115 | if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count) |
| 2116 | { |
| 2117 | reason = "as-path contains our own AS;"; |
| 2118 | goto filtered; |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | /* AS path loop check. */ |
| 2123 | if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi] |
| 2124 | || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) |
| 2125 | && aspath_loop_check(attr->aspath, bgp->confed_id) |
| 2126 | > peer->allowas_in[afi][safi])) |
| 2127 | { |
| 2128 | reason = "as-path contains our own AS;"; |
| 2129 | goto filtered; |
| 2130 | } |
| 2131 | |
| 2132 | /* Route reflector originator ID check. */ |
| 2133 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2134 | && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2135 | { |
| 2136 | reason = "originator is us;"; |
| 2137 | goto filtered; |
| 2138 | } |
| 2139 | |
| 2140 | /* Route reflector cluster ID check. */ |
| 2141 | if (bgp_cluster_filter (peer, attr)) |
| 2142 | { |
| 2143 | reason = "reflected from the same cluster;"; |
| 2144 | goto filtered; |
| 2145 | } |
| 2146 | |
| 2147 | /* Apply incoming filter. */ |
| 2148 | if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY) |
| 2149 | { |
| 2150 | reason = "filter;"; |
| 2151 | goto filtered; |
| 2152 | } |
| 2153 | |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2154 | new_attr.extra = &new_extra; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2155 | bgp_attr_dup (&new_attr, attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2156 | |
David Lamparter | c460e57 | 2014-06-04 00:54:58 +0200 | [diff] [blame] | 2157 | /* Apply incoming route-map. |
| 2158 | * NB: new_attr may now contain newly allocated values from route-map "set" |
| 2159 | * commands, so we need bgp_attr_flush in the error paths, until we intern |
| 2160 | * the attr (which takes over the memory references) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2161 | if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY) |
| 2162 | { |
| 2163 | reason = "route-map;"; |
David Lamparter | c460e57 | 2014-06-04 00:54:58 +0200 | [diff] [blame] | 2164 | bgp_attr_flush (&new_attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2165 | goto filtered; |
| 2166 | } |
| 2167 | |
| 2168 | /* IPv4 unicast next hop check. */ |
| 2169 | if (afi == AFI_IP && safi == SAFI_UNICAST) |
| 2170 | { |
| 2171 | /* If the peer is EBGP and nexthop is not on connected route, |
| 2172 | discard it. */ |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2173 | if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1 |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 2174 | && ! bgp_nexthop_onlink (afi, &new_attr) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 2175 | && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2176 | { |
| 2177 | reason = "non-connected next-hop;"; |
David Lamparter | c460e57 | 2014-06-04 00:54:58 +0200 | [diff] [blame] | 2178 | bgp_attr_flush (&new_attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2179 | goto filtered; |
| 2180 | } |
| 2181 | |
Denis Ovsienko | 733cd9e | 2011-12-17 19:39:30 +0400 | [diff] [blame] | 2182 | /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2183 | must not be my own address. */ |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 2184 | if (new_attr.nexthop.s_addr == 0 |
| 2185 | || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)) |
| 2186 | || bgp_nexthop_self (&new_attr)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2187 | { |
| 2188 | reason = "martian next-hop;"; |
David Lamparter | c460e57 | 2014-06-04 00:54:58 +0200 | [diff] [blame] | 2189 | bgp_attr_flush (&new_attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2190 | goto filtered; |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | attr_new = bgp_attr_intern (&new_attr); |
| 2195 | |
| 2196 | /* If the update is implicit withdraw. */ |
| 2197 | if (ri) |
| 2198 | { |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 2199 | ri->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2200 | |
| 2201 | /* Same attribute comes in. */ |
Paul Jakma | 16d2e24 | 2007-04-10 19:32:10 +0000 | [diff] [blame] | 2202 | if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) |
| 2203 | && attrhash_cmp (ri->attr, attr_new)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2204 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2205 | bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2206 | |
| 2207 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2208 | && peer->sort == BGP_PEER_EBGP |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2209 | && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
| 2210 | { |
| 2211 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2212 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2213 | peer->host, |
| 2214 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2215 | p->prefixlen); |
| 2216 | |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 2217 | if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED) |
| 2218 | { |
| 2219 | bgp_aggregate_increment (bgp, p, ri, afi, safi); |
| 2220 | bgp_process (bgp, rn, afi, safi); |
| 2221 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2222 | } |
Paul Jakma | 16d2e24 | 2007-04-10 19:32:10 +0000 | [diff] [blame] | 2223 | else /* Duplicate - odd */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2224 | { |
| 2225 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2226 | zlog (peer->log, LOG_DEBUG, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2227 | "%s rcvd %s/%d...duplicate ignored", |
| 2228 | peer->host, |
| 2229 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2230 | p->prefixlen); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 2231 | |
| 2232 | /* graceful restart STALE flag unset. */ |
| 2233 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
| 2234 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2235 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 2236 | bgp_process (bgp, rn, afi, safi); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 2237 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 2241 | bgp_attr_unintern (&attr_new); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2242 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2243 | return 0; |
| 2244 | } |
| 2245 | |
Paul Jakma | 16d2e24 | 2007-04-10 19:32:10 +0000 | [diff] [blame] | 2246 | /* Withdraw/Announce before we fully processed the withdraw */ |
| 2247 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
| 2248 | { |
| 2249 | if (BGP_DEBUG (update, UPDATE_IN)) |
| 2250 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing", |
| 2251 | peer->host, |
| 2252 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2253 | p->prefixlen); |
| 2254 | bgp_info_restore (rn, ri); |
| 2255 | } |
| 2256 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2257 | /* Received Logging. */ |
| 2258 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2259 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2260 | peer->host, |
| 2261 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2262 | p->prefixlen); |
| 2263 | |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 2264 | /* graceful restart STALE flag unset. */ |
| 2265 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2266 | bgp_info_unset_flag (rn, ri, BGP_INFO_STALE); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 2267 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2268 | /* The attribute is changed. */ |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2269 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 2270 | |
| 2271 | /* implicit withdraw, decrement aggregate and pcount here. |
| 2272 | * only if update is accepted, they'll increment below. |
| 2273 | */ |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 2274 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
| 2275 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2276 | /* Update bgp route dampening information. */ |
| 2277 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2278 | && peer->sort == BGP_PEER_EBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2279 | { |
| 2280 | /* This is implicit withdraw so we should update dampening |
| 2281 | information. */ |
| 2282 | if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
| 2283 | bgp_damp_withdraw (ri, rn, afi, safi, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2286 | /* Update to new attribute. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 2287 | bgp_attr_unintern (&ri->attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2288 | ri->attr = attr_new; |
| 2289 | |
| 2290 | /* Update MPLS tag. */ |
| 2291 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2292 | memcpy ((bgp_info_extra_get (ri))->tag, tag, 3); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2293 | |
| 2294 | /* Update bgp route dampening information. */ |
| 2295 | if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2296 | && peer->sort == BGP_PEER_EBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2297 | { |
| 2298 | /* Now we do normal update dampening. */ |
| 2299 | ret = bgp_damp_update (ri, rn, afi, safi); |
| 2300 | if (ret == BGP_DAMP_SUPPRESSED) |
| 2301 | { |
| 2302 | bgp_unlock_node (rn); |
| 2303 | return 0; |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | /* Nexthop reachability check. */ |
| 2308 | if ((afi == AFI_IP || afi == AFI_IP6) |
| 2309 | && safi == SAFI_UNICAST |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2310 | && (peer->sort == BGP_PEER_IBGP |
| 2311 | || peer->sort == BGP_PEER_CONFED |
| 2312 | || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 2313 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2314 | { |
| 2315 | if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL)) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2316 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2317 | else |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2318 | bgp_info_unset_flag (rn, ri, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2319 | } |
| 2320 | else |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2321 | bgp_info_set_flag (rn, ri, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2322 | |
| 2323 | /* Process change. */ |
| 2324 | bgp_aggregate_increment (bgp, p, ri, afi, safi); |
| 2325 | |
| 2326 | bgp_process (bgp, rn, afi, safi); |
| 2327 | bgp_unlock_node (rn); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2328 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2329 | return 0; |
| 2330 | } |
| 2331 | |
| 2332 | /* Received Logging. */ |
| 2333 | if (BGP_DEBUG (update, UPDATE_IN)) |
| 2334 | { |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2335 | zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2336 | peer->host, |
| 2337 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2338 | p->prefixlen); |
| 2339 | } |
| 2340 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2341 | /* Make new BGP info. */ |
| 2342 | new = bgp_info_new (); |
| 2343 | new->type = type; |
| 2344 | new->sub_type = sub_type; |
| 2345 | new->peer = peer; |
| 2346 | new->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 2347 | new->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2348 | |
| 2349 | /* Update MPLS tag. */ |
| 2350 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2351 | memcpy ((bgp_info_extra_get (new))->tag, tag, 3); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2352 | |
| 2353 | /* Nexthop reachability check. */ |
| 2354 | if ((afi == AFI_IP || afi == AFI_IP6) |
| 2355 | && safi == SAFI_UNICAST |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 2356 | && (peer->sort == BGP_PEER_IBGP |
| 2357 | || peer->sort == BGP_PEER_CONFED |
| 2358 | || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 2359 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2360 | { |
| 2361 | if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL)) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2362 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2363 | else |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2364 | bgp_info_unset_flag (rn, new, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2365 | } |
| 2366 | else |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2367 | bgp_info_set_flag (rn, new, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2368 | |
paul | 902212c | 2006-02-05 17:51:19 +0000 | [diff] [blame] | 2369 | /* Increment prefix */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2370 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
| 2371 | |
| 2372 | /* Register new BGP information. */ |
| 2373 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2374 | |
| 2375 | /* route_node_get lock */ |
| 2376 | bgp_unlock_node (rn); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2377 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2378 | /* If maximum prefix count is configured and current prefix |
| 2379 | count exeed it. */ |
hasso | e0701b7 | 2004-05-20 09:19:34 +0000 | [diff] [blame] | 2380 | if (bgp_maximum_prefix_overflow (peer, afi, safi, 0)) |
| 2381 | return -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2382 | |
| 2383 | /* Process change. */ |
| 2384 | bgp_process (bgp, rn, afi, safi); |
| 2385 | |
| 2386 | return 0; |
| 2387 | |
| 2388 | /* This BGP update is filtered. Log the reason then update BGP |
| 2389 | entry. */ |
| 2390 | filtered: |
| 2391 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2392 | zlog (peer->log, LOG_DEBUG, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2393 | "%s rcvd UPDATE about %s/%d -- DENIED due to: %s", |
| 2394 | peer->host, |
| 2395 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2396 | p->prefixlen, reason); |
| 2397 | |
| 2398 | if (ri) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 2399 | bgp_rib_remove (rn, ri, peer, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2400 | |
| 2401 | bgp_unlock_node (rn); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2402 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2403 | return 0; |
| 2404 | } |
| 2405 | |
| 2406 | int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2407 | bgp_update (struct peer *peer, struct prefix *p, struct attr *attr, |
| 2408 | afi_t afi, safi_t safi, int type, int sub_type, |
| 2409 | struct prefix_rd *prd, u_char *tag, int soft_reconfig) |
| 2410 | { |
| 2411 | struct peer *rsclient; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2412 | struct listnode *node, *nnode; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2413 | struct bgp *bgp; |
| 2414 | int ret; |
| 2415 | |
| 2416 | ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag, |
| 2417 | soft_reconfig); |
| 2418 | |
| 2419 | bgp = peer->bgp; |
| 2420 | |
| 2421 | /* Process the update for each RS-client. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2422 | for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2423 | { |
| 2424 | if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 2425 | bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type, |
| 2426 | sub_type, prd, tag); |
| 2427 | } |
| 2428 | |
| 2429 | return ret; |
| 2430 | } |
| 2431 | |
| 2432 | int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2433 | bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr, |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2434 | afi_t afi, safi_t safi, int type, int sub_type, |
| 2435 | struct prefix_rd *prd, u_char *tag) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2436 | { |
| 2437 | struct bgp *bgp; |
| 2438 | char buf[SU_ADDRSTRLEN]; |
| 2439 | struct bgp_node *rn; |
| 2440 | struct bgp_info *ri; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2441 | struct peer *rsclient; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2442 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2443 | |
| 2444 | bgp = peer->bgp; |
| 2445 | |
David Lamparter | 4584c23 | 2015-04-13 09:50:00 +0200 | [diff] [blame] | 2446 | /* Lookup node. */ |
| 2447 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
| 2448 | |
| 2449 | /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all |
| 2450 | * routes that are filtered. This tanks out Quagga RS pretty badly due to |
| 2451 | * the iteration over all RS clients. |
| 2452 | * Since we need to remove the entry from adj_in anyway, do that first and |
| 2453 | * if there was no entry, we don't need to do anything more. */ |
| 2454 | if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) |
| 2455 | && peer != bgp->peer_self) |
| 2456 | if (!bgp_adj_in_unset (rn, peer)) |
| 2457 | { |
| 2458 | if (BGP_DEBUG (update, UPDATE_IN)) |
| 2459 | zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d " |
| 2460 | "not in adj-in", peer->host, |
| 2461 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2462 | p->prefixlen); |
| 2463 | bgp_unlock_node (rn); |
| 2464 | return 0; |
| 2465 | } |
| 2466 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2467 | /* Process the withdraw for each RS-client. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2468 | for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2469 | { |
| 2470 | if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 2471 | bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag); |
| 2472 | } |
| 2473 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2474 | /* Logging. */ |
| 2475 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2476 | zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2477 | peer->host, |
| 2478 | inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2479 | p->prefixlen); |
| 2480 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2481 | /* Lookup withdrawn route. */ |
| 2482 | for (ri = rn->info; ri; ri = ri->next) |
| 2483 | if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type) |
| 2484 | break; |
| 2485 | |
| 2486 | /* Withdraw specified route from routing table. */ |
| 2487 | if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 2488 | bgp_rib_withdraw (rn, ri, peer, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2489 | else if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 2490 | zlog (peer->log, LOG_DEBUG, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2491 | "%s Can't find the route %s/%d", peer->host, |
| 2492 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 2493 | p->prefixlen); |
| 2494 | |
| 2495 | /* Unlock bgp_node_get() lock. */ |
| 2496 | bgp_unlock_node (rn); |
| 2497 | |
| 2498 | return 0; |
| 2499 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 2500 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2501 | void |
| 2502 | bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw) |
| 2503 | { |
| 2504 | struct bgp *bgp; |
Jorge Boncompte [DTI2] | e16a413 | 2012-05-07 16:52:57 +0000 | [diff] [blame] | 2505 | struct attr attr; |
Jorge Boncompte [DTI2] | 577ac57 | 2012-05-07 16:53:06 +0000 | [diff] [blame] | 2506 | struct aspath *aspath; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2507 | struct prefix p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2508 | struct peer *from; |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2509 | struct bgp_node *rn; |
| 2510 | struct bgp_info *ri; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2511 | int ret = RMAP_DENYMATCH; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2512 | |
Paul Jakma | b249702 | 2007-06-14 11:17:58 +0000 | [diff] [blame] | 2513 | if (!(afi == AFI_IP || afi == AFI_IP6)) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2514 | return; |
| 2515 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2516 | bgp = peer->bgp; |
| 2517 | from = bgp->peer_self; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2518 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2519 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); |
| 2520 | aspath = attr.aspath; |
| 2521 | attr.local_pref = bgp->default_local_pref; |
| 2522 | memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN); |
| 2523 | |
| 2524 | if (afi == AFI_IP) |
| 2525 | str2prefix ("0.0.0.0/0", &p); |
| 2526 | #ifdef HAVE_IPV6 |
| 2527 | else if (afi == AFI_IP6) |
| 2528 | { |
Jorge Boncompte [DTI2] | 6182d65 | 2012-05-07 16:53:02 +0000 | [diff] [blame] | 2529 | struct attr_extra *ae = attr.extra; |
| 2530 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2531 | str2prefix ("::/0", &p); |
| 2532 | |
| 2533 | /* IPv6 global nexthop must be included. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2534 | memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2535 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2536 | ae->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2537 | |
| 2538 | /* If the peer is on shared nextwork and we have link-local |
| 2539 | nexthop set it. */ |
| 2540 | if (peer->shared_network |
| 2541 | && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local)) |
| 2542 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2543 | memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2544 | IPV6_MAX_BYTELEN); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2545 | ae->mp_nexthop_len = 32; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | #endif /* HAVE_IPV6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2549 | |
| 2550 | if (peer->default_rmap[afi][safi].name) |
| 2551 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2552 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT); |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2553 | for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) |
| 2554 | { |
| 2555 | for (ri = rn->info; ri; ri = ri->next) |
| 2556 | { |
| 2557 | struct attr dummy_attr; |
| 2558 | struct attr_extra dummy_extra; |
| 2559 | struct bgp_info info; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2560 | |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2561 | /* Provide dummy so the route-map can't modify the attributes */ |
| 2562 | dummy_attr.extra = &dummy_extra; |
| 2563 | bgp_attr_dup(&dummy_attr, ri->attr); |
| 2564 | info.peer = ri->peer; |
| 2565 | info.attr = &dummy_attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2566 | |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2567 | ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p, |
| 2568 | RMAP_BGP, &info); |
| 2569 | |
| 2570 | /* The route map might have set attributes. If we don't flush them |
| 2571 | * here, they will be leaked. */ |
| 2572 | bgp_attr_flush(&dummy_attr); |
| 2573 | if (ret != RMAP_DENYMATCH) |
| 2574 | break; |
| 2575 | } |
| 2576 | if (ret != RMAP_DENYMATCH) |
| 2577 | break; |
| 2578 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2579 | bgp->peer_self->rmap_type = 0; |
| 2580 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2581 | if (ret == RMAP_DENYMATCH) |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2582 | withdraw = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | if (withdraw) |
| 2586 | { |
| 2587 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE)) |
| 2588 | bgp_default_withdraw_send (peer, afi, safi); |
| 2589 | UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE); |
| 2590 | } |
| 2591 | else |
| 2592 | { |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 2593 | if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE)) |
| 2594 | { |
| 2595 | SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE); |
| 2596 | bgp_default_update_send (peer, &attr, afi, safi, from); |
| 2597 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2598 | } |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2599 | |
| 2600 | bgp_attr_extra_free (&attr); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 2601 | aspath_unintern (&aspath); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2602 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 2603 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2604 | static void |
| 2605 | bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2606 | struct bgp_table *table, int rsclient) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2607 | { |
| 2608 | struct bgp_node *rn; |
| 2609 | struct bgp_info *ri; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2610 | struct attr attr; |
| 2611 | struct attr_extra extra; |
| 2612 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2613 | if (! table) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2614 | table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2615 | |
| 2616 | if (safi != SAFI_MPLS_VPN |
| 2617 | && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) |
| 2618 | bgp_default_originate (peer, afi, safi, 0); |
| 2619 | |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 2620 | /* It's initialized in bgp_announce_[check|check_rsclient]() */ |
| 2621 | attr.extra = &extra; |
| 2622 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2623 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn)) |
| 2624 | for (ri = rn->info; ri; ri = ri->next) |
| 2625 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer) |
| 2626 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2627 | if ( (rsclient) ? |
| 2628 | (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi)) |
| 2629 | : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2630 | bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri); |
| 2631 | else |
| 2632 | bgp_adj_out_unset (rn, peer, &rn->p, afi, safi); |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | void |
| 2637 | bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi) |
| 2638 | { |
| 2639 | struct bgp_node *rn; |
| 2640 | struct bgp_table *table; |
| 2641 | |
| 2642 | if (peer->status != Established) |
| 2643 | return; |
| 2644 | |
| 2645 | if (! peer->afc_nego[afi][safi]) |
| 2646 | return; |
| 2647 | |
| 2648 | /* First update is deferred until ORF or ROUTE-REFRESH is received */ |
| 2649 | if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH)) |
| 2650 | return; |
| 2651 | |
| 2652 | if (safi != SAFI_MPLS_VPN) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2653 | bgp_announce_table (peer, afi, safi, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2654 | else |
| 2655 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; |
| 2656 | rn = bgp_route_next(rn)) |
| 2657 | if ((table = (rn->info)) != NULL) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2658 | bgp_announce_table (peer, afi, safi, table, 0); |
| 2659 | |
| 2660 | if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 2661 | bgp_announce_table (peer, afi, safi, NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | void |
| 2665 | bgp_announce_route_all (struct peer *peer) |
| 2666 | { |
| 2667 | afi_t afi; |
| 2668 | safi_t safi; |
| 2669 | |
| 2670 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 2671 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 2672 | bgp_announce_route (peer, afi, safi); |
| 2673 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 2674 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2675 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2676 | bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi, |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2677 | safi_t safi, struct bgp_table *table, struct prefix_rd *prd) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2678 | { |
| 2679 | struct bgp_node *rn; |
| 2680 | struct bgp_adj_in *ain; |
| 2681 | |
| 2682 | if (! table) |
| 2683 | table = rsclient->bgp->rib[afi][safi]; |
| 2684 | |
| 2685 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 2686 | for (ain = rn->adj_in; ain; ain = ain->next) |
| 2687 | { |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2688 | struct bgp_info *ri = rn->info; |
Christian Franke | d53d8fd | 2013-01-28 07:14:43 +0100 | [diff] [blame] | 2689 | u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL; |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2690 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2691 | bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer, |
Christian Franke | d53d8fd | 2013-01-28 07:14:43 +0100 | [diff] [blame] | 2692 | &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | void |
| 2697 | bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi) |
| 2698 | { |
| 2699 | struct bgp_table *table; |
| 2700 | struct bgp_node *rn; |
| 2701 | |
| 2702 | if (safi != SAFI_MPLS_VPN) |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2703 | bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2704 | |
| 2705 | else |
| 2706 | for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn; |
| 2707 | rn = bgp_route_next (rn)) |
| 2708 | if ((table = rn->info) != NULL) |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2709 | { |
| 2710 | struct prefix_rd prd; |
| 2711 | prd.family = AF_UNSPEC; |
| 2712 | prd.prefixlen = 64; |
| 2713 | memcpy(&prd.val, rn->p.u.val, 8); |
| 2714 | |
| 2715 | bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd); |
| 2716 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2717 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 2718 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2719 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2720 | bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi, |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2721 | struct bgp_table *table, struct prefix_rd *prd) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2722 | { |
| 2723 | int ret; |
| 2724 | struct bgp_node *rn; |
| 2725 | struct bgp_adj_in *ain; |
| 2726 | |
| 2727 | if (! table) |
| 2728 | table = peer->bgp->rib[afi][safi]; |
| 2729 | |
| 2730 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 2731 | for (ain = rn->adj_in; ain; ain = ain->next) |
| 2732 | { |
| 2733 | if (ain->peer == peer) |
| 2734 | { |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2735 | struct bgp_info *ri = rn->info; |
Christian Franke | d53d8fd | 2013-01-28 07:14:43 +0100 | [diff] [blame] | 2736 | u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL; |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2737 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2738 | ret = bgp_update (peer, &rn->p, ain->attr, afi, safi, |
| 2739 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, |
Christian Franke | d53d8fd | 2013-01-28 07:14:43 +0100 | [diff] [blame] | 2740 | prd, tag, 1); |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2741 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2742 | if (ret < 0) |
| 2743 | { |
| 2744 | bgp_unlock_node (rn); |
| 2745 | return; |
| 2746 | } |
| 2747 | continue; |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | void |
| 2753 | bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi) |
| 2754 | { |
| 2755 | struct bgp_node *rn; |
| 2756 | struct bgp_table *table; |
| 2757 | |
| 2758 | if (peer->status != Established) |
| 2759 | return; |
| 2760 | |
| 2761 | if (safi != SAFI_MPLS_VPN) |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2762 | bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2763 | else |
| 2764 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; |
| 2765 | rn = bgp_route_next (rn)) |
| 2766 | if ((table = rn->info) != NULL) |
Jorge Boncompte [DTI2] | 8692c50 | 2012-05-07 15:17:34 +0000 | [diff] [blame] | 2767 | { |
| 2768 | struct prefix_rd prd; |
| 2769 | prd.family = AF_UNSPEC; |
| 2770 | prd.prefixlen = 64; |
| 2771 | memcpy(&prd.val, rn->p.u.val, 8); |
| 2772 | |
| 2773 | bgp_soft_reconfig_table (peer, afi, safi, table, &prd); |
| 2774 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2775 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 2776 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2777 | |
| 2778 | struct bgp_clear_node_queue |
| 2779 | { |
| 2780 | struct bgp_node *rn; |
| 2781 | enum bgp_clear_route_type purpose; |
| 2782 | }; |
| 2783 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2784 | static wq_item_status |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 2785 | bgp_clear_route_node (struct work_queue *wq, void *data) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2786 | { |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2787 | struct bgp_clear_node_queue *cnq = data; |
| 2788 | struct bgp_node *rn = cnq->rn; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2789 | struct peer *peer = wq->spec.data; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2790 | struct bgp_info *ri; |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 2791 | afi_t afi = bgp_node_table (rn)->afi; |
| 2792 | safi_t safi = bgp_node_table (rn)->safi; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2793 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2794 | assert (rn && peer); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2795 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2796 | for (ri = rn->info; ri; ri = ri->next) |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2797 | if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2798 | { |
| 2799 | /* graceful restart STALE flag set. */ |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2800 | if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT) |
| 2801 | && peer->nsf[afi][safi] |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2802 | && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE) |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 2803 | && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
| 2804 | bgp_info_set_flag (rn, ri, BGP_INFO_STALE); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2805 | else |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2806 | bgp_rib_remove (rn, ri, peer, afi, safi); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2807 | break; |
| 2808 | } |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2809 | return WQ_SUCCESS; |
| 2810 | } |
| 2811 | |
| 2812 | static void |
paul | 0fb58d5 | 2005-11-14 14:31:49 +0000 | [diff] [blame] | 2813 | bgp_clear_node_queue_del (struct work_queue *wq, void *data) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2814 | { |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2815 | struct bgp_clear_node_queue *cnq = data; |
| 2816 | struct bgp_node *rn = cnq->rn; |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 2817 | struct bgp_table *table = bgp_node_table (rn); |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2818 | |
| 2819 | bgp_unlock_node (rn); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2820 | bgp_table_unlock (table); |
| 2821 | XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | static void |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2825 | bgp_clear_node_complete (struct work_queue *wq) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2826 | { |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2827 | struct peer *peer = wq->spec.data; |
| 2828 | |
Paul Jakma | 3e0c78e | 2006-03-06 18:06:53 +0000 | [diff] [blame] | 2829 | /* Tickle FSM to start moving again */ |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 2830 | BGP_EVENT_ADD (peer, Clearing_Completed); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2831 | |
| 2832 | peer_unlock (peer); /* bgp_clear_route */ |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | static void |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2836 | bgp_clear_node_queue_init (struct peer *peer) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2837 | { |
Paul Jakma | a294365 | 2009-07-21 14:02:04 +0100 | [diff] [blame] | 2838 | char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")]; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2839 | |
Paul Jakma | a294365 | 2009-07-21 14:02:04 +0100 | [diff] [blame] | 2840 | snprintf (wname, sizeof(wname), "clear %s", peer->host); |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2841 | #undef CLEAR_QUEUE_NAME_LEN |
| 2842 | |
| 2843 | if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL) |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2844 | { |
| 2845 | zlog_err ("%s: Failed to allocate work queue", __func__); |
| 2846 | exit (1); |
| 2847 | } |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2848 | peer->clear_node_queue->spec.hold = 10; |
| 2849 | peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node; |
| 2850 | peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del; |
| 2851 | peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete; |
| 2852 | peer->clear_node_queue->spec.max_retries = 0; |
| 2853 | |
| 2854 | /* we only 'lock' this peer reference when the queue is actually active */ |
| 2855 | peer->clear_node_queue->spec.data = peer; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2858 | static void |
| 2859 | bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi, |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2860 | struct bgp_table *table, struct peer *rsclient, |
| 2861 | enum bgp_clear_route_type purpose) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2862 | { |
| 2863 | struct bgp_node *rn; |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2864 | |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2865 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2866 | if (! table) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2867 | table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi]; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2868 | |
hasso | 6cf159b | 2005-03-21 10:28:14 +0000 | [diff] [blame] | 2869 | /* If still no table => afi/safi isn't configured at all or smth. */ |
| 2870 | if (! table) |
| 2871 | return; |
Paul Jakma | 65ca75e | 2006-05-04 08:08:15 +0000 | [diff] [blame] | 2872 | |
| 2873 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 2874 | { |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2875 | struct bgp_info *ri; |
| 2876 | struct bgp_adj_in *ain; |
| 2877 | struct bgp_adj_out *aout; |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2878 | |
| 2879 | /* XXX:TODO: This is suboptimal, every non-empty route_node is |
| 2880 | * queued for every clearing peer, regardless of whether it is |
| 2881 | * relevant to the peer at hand. |
| 2882 | * |
| 2883 | * Overview: There are 3 different indices which need to be |
| 2884 | * scrubbed, potentially, when a peer is removed: |
| 2885 | * |
| 2886 | * 1 peer's routes visible via the RIB (ie accepted routes) |
| 2887 | * 2 peer's routes visible by the (optional) peer's adj-in index |
| 2888 | * 3 other routes visible by the peer's adj-out index |
| 2889 | * |
| 2890 | * 3 there is no hurry in scrubbing, once the struct peer is |
| 2891 | * removed from bgp->peer, we could just GC such deleted peer's |
| 2892 | * adj-outs at our leisure. |
| 2893 | * |
| 2894 | * 1 and 2 must be 'scrubbed' in some way, at least made |
| 2895 | * invisible via RIB index before peer session is allowed to be |
| 2896 | * brought back up. So one needs to know when such a 'search' is |
| 2897 | * complete. |
| 2898 | * |
| 2899 | * Ideally: |
| 2900 | * |
| 2901 | * - there'd be a single global queue or a single RIB walker |
| 2902 | * - rather than tracking which route_nodes still need to be |
| 2903 | * examined on a peer basis, we'd track which peers still |
| 2904 | * aren't cleared |
| 2905 | * |
| 2906 | * Given that our per-peer prefix-counts now should be reliable, |
| 2907 | * this may actually be achievable. It doesn't seem to be a huge |
| 2908 | * problem at this time, |
| 2909 | */ |
Jorge Boncompte [DTI2] | 24e50f2 | 2012-05-07 15:17:33 +0000 | [diff] [blame] | 2910 | for (ain = rn->adj_in; ain; ain = ain->next) |
| 2911 | if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT) |
| 2912 | { |
| 2913 | bgp_adj_in_remove (rn, ain); |
| 2914 | bgp_unlock_node (rn); |
| 2915 | break; |
| 2916 | } |
| 2917 | for (aout = rn->adj_out; aout; aout = aout->next) |
| 2918 | if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT) |
| 2919 | { |
| 2920 | bgp_adj_out_remove (rn, aout, peer, afi, safi); |
| 2921 | bgp_unlock_node (rn); |
| 2922 | break; |
| 2923 | } |
| 2924 | |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2925 | for (ri = rn->info; ri; ri = ri->next) |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2926 | if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT) |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2927 | { |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2928 | struct bgp_clear_node_queue *cnq; |
| 2929 | |
| 2930 | /* both unlocked in bgp_clear_node_queue_del */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 2931 | bgp_table_lock (bgp_node_table (rn)); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2932 | bgp_lock_node (rn); |
| 2933 | cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE, |
| 2934 | sizeof (struct bgp_clear_node_queue)); |
| 2935 | cnq->rn = rn; |
| 2936 | cnq->purpose = purpose; |
| 2937 | work_queue_add (peer->clear_node_queue, cnq); |
| 2938 | break; |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2939 | } |
Paul Jakma | 65ca75e | 2006-05-04 08:08:15 +0000 | [diff] [blame] | 2940 | } |
| 2941 | return; |
| 2942 | } |
| 2943 | |
| 2944 | void |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2945 | bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi, |
| 2946 | enum bgp_clear_route_type purpose) |
Paul Jakma | 65ca75e | 2006-05-04 08:08:15 +0000 | [diff] [blame] | 2947 | { |
| 2948 | struct bgp_node *rn; |
| 2949 | struct bgp_table *table; |
| 2950 | struct peer *rsclient; |
| 2951 | struct listnode *node, *nnode; |
hasso | 6cf159b | 2005-03-21 10:28:14 +0000 | [diff] [blame] | 2952 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2953 | if (peer->clear_node_queue == NULL) |
| 2954 | bgp_clear_node_queue_init (peer); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2955 | |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 2956 | /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to |
| 2957 | * Idle until it receives a Clearing_Completed event. This protects |
| 2958 | * against peers which flap faster than we can we clear, which could |
| 2959 | * lead to: |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 2960 | * |
| 2961 | * a) race with routes from the new session being installed before |
| 2962 | * clear_route_node visits the node (to delete the route of that |
| 2963 | * peer) |
| 2964 | * b) resource exhaustion, clear_route_node likely leads to an entry |
| 2965 | * on the process_main queue. Fast-flapping could cause that queue |
| 2966 | * to grow and grow. |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 2967 | */ |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 2968 | if (!peer->clear_node_queue->thread) |
| 2969 | peer_lock (peer); /* bgp_clear_node_complete */ |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2970 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2971 | switch (purpose) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2972 | { |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 2973 | case BGP_CLEAR_ROUTE_NORMAL: |
| 2974 | if (safi != SAFI_MPLS_VPN) |
| 2975 | bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose); |
| 2976 | else |
| 2977 | for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn; |
| 2978 | rn = bgp_route_next (rn)) |
| 2979 | if ((table = rn->info) != NULL) |
| 2980 | bgp_clear_route_table (peer, afi, safi, table, NULL, purpose); |
| 2981 | |
| 2982 | for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient)) |
| 2983 | if (CHECK_FLAG(rsclient->af_flags[afi][safi], |
| 2984 | PEER_FLAG_RSERVER_CLIENT)) |
| 2985 | bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose); |
| 2986 | break; |
| 2987 | |
| 2988 | case BGP_CLEAR_ROUTE_MY_RSCLIENT: |
| 2989 | bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose); |
| 2990 | break; |
| 2991 | |
| 2992 | default: |
| 2993 | assert (0); |
| 2994 | break; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2995 | } |
Paul Jakma | 65ca75e | 2006-05-04 08:08:15 +0000 | [diff] [blame] | 2996 | |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 2997 | /* If no routes were cleared, nothing was added to workqueue, the |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 2998 | * completion function won't be run by workqueue code - call it here. |
| 2999 | * XXX: Actually, this assumption doesn't hold, see |
| 3000 | * bgp_clear_route_table(), we queue all non-empty nodes. |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 3001 | * |
| 3002 | * Additionally, there is a presumption in FSM that clearing is only |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 3003 | * really needed if peer state is Established - peers in |
| 3004 | * pre-Established states shouldn't have any route-update state |
| 3005 | * associated with them (in or out). |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 3006 | * |
Paul Jakma | f2c31ac | 2007-02-22 17:48:42 +0000 | [diff] [blame] | 3007 | * We still can get here in pre-Established though, through |
| 3008 | * peer_delete -> bgp_fsm_change_status, so this is a useful sanity |
| 3009 | * check to ensure the assumption above holds. |
Paul Jakma | ca058a3 | 2006-09-14 02:58:49 +0000 | [diff] [blame] | 3010 | * |
| 3011 | * At some future point, this check could be move to the top of the |
| 3012 | * function, and do a quick early-return when state is |
| 3013 | * pre-Established, avoiding above list and table scans. Once we're |
| 3014 | * sure it is safe.. |
Paul Jakma | 65ca75e | 2006-05-04 08:08:15 +0000 | [diff] [blame] | 3015 | */ |
| 3016 | if (!peer->clear_node_queue->thread) |
| 3017 | bgp_clear_node_complete (peer->clear_node_queue); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | void |
| 3021 | bgp_clear_route_all (struct peer *peer) |
| 3022 | { |
| 3023 | afi_t afi; |
| 3024 | safi_t safi; |
| 3025 | |
| 3026 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 3027 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 3028 | bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | void |
| 3032 | bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi) |
| 3033 | { |
| 3034 | struct bgp_table *table; |
| 3035 | struct bgp_node *rn; |
| 3036 | struct bgp_adj_in *ain; |
| 3037 | |
| 3038 | table = peer->bgp->rib[afi][safi]; |
| 3039 | |
| 3040 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 3041 | for (ain = rn->adj_in; ain ; ain = ain->next) |
| 3042 | if (ain->peer == peer) |
| 3043 | { |
| 3044 | bgp_adj_in_remove (rn, ain); |
| 3045 | bgp_unlock_node (rn); |
| 3046 | break; |
| 3047 | } |
| 3048 | } |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 3049 | |
| 3050 | void |
| 3051 | bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi) |
| 3052 | { |
| 3053 | struct bgp_node *rn; |
| 3054 | struct bgp_info *ri; |
| 3055 | struct bgp_table *table; |
| 3056 | |
| 3057 | table = peer->bgp->rib[afi][safi]; |
| 3058 | |
| 3059 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 3060 | { |
| 3061 | for (ri = rn->info; ri; ri = ri->next) |
| 3062 | if (ri->peer == peer) |
| 3063 | { |
| 3064 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
| 3065 | bgp_rib_remove (rn, ri, peer, afi, safi); |
| 3066 | break; |
| 3067 | } |
| 3068 | } |
| 3069 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 3070 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3071 | /* Delete all kernel routes. */ |
| 3072 | void |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 3073 | bgp_cleanup_routes (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3074 | { |
| 3075 | struct bgp *bgp; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 3076 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3077 | struct bgp_node *rn; |
| 3078 | struct bgp_table *table; |
| 3079 | struct bgp_info *ri; |
| 3080 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 3081 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3082 | { |
| 3083 | table = bgp->rib[AFI_IP][SAFI_UNICAST]; |
| 3084 | |
| 3085 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 3086 | for (ri = rn->info; ri; ri = ri->next) |
| 3087 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) |
| 3088 | && ri->type == ZEBRA_ROUTE_BGP |
| 3089 | && ri->sub_type == BGP_ROUTE_NORMAL) |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 3090 | bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3091 | |
| 3092 | table = bgp->rib[AFI_IP6][SAFI_UNICAST]; |
| 3093 | |
| 3094 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 3095 | for (ri = rn->info; ri; ri = ri->next) |
| 3096 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) |
| 3097 | && ri->type == ZEBRA_ROUTE_BGP |
| 3098 | && ri->sub_type == BGP_ROUTE_NORMAL) |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 3099 | bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | void |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 3104 | bgp_reset (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3105 | { |
| 3106 | vty_reset (); |
| 3107 | bgp_zclient_reset (); |
| 3108 | access_list_reset (); |
| 3109 | prefix_list_reset (); |
| 3110 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 3111 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3112 | /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr |
| 3113 | value. */ |
| 3114 | int |
| 3115 | bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet) |
| 3116 | { |
| 3117 | u_char *pnt; |
| 3118 | u_char *lim; |
| 3119 | struct prefix p; |
| 3120 | int psize; |
| 3121 | int ret; |
| 3122 | |
| 3123 | /* Check peer status. */ |
| 3124 | if (peer->status != Established) |
| 3125 | return 0; |
| 3126 | |
| 3127 | pnt = packet->nlri; |
| 3128 | lim = pnt + packet->length; |
| 3129 | |
| 3130 | for (; pnt < lim; pnt += psize) |
| 3131 | { |
| 3132 | /* Clear prefix structure. */ |
| 3133 | memset (&p, 0, sizeof (struct prefix)); |
| 3134 | |
| 3135 | /* Fetch prefix length. */ |
| 3136 | p.prefixlen = *pnt++; |
| 3137 | p.family = afi2family (packet->afi); |
| 3138 | |
| 3139 | /* Already checked in nlri_sanity_check(). We do double check |
| 3140 | here. */ |
| 3141 | if ((packet->afi == AFI_IP && p.prefixlen > 32) |
| 3142 | || (packet->afi == AFI_IP6 && p.prefixlen > 128)) |
| 3143 | return -1; |
| 3144 | |
| 3145 | /* Packet size overflow check. */ |
| 3146 | psize = PSIZE (p.prefixlen); |
| 3147 | |
| 3148 | /* When packet overflow occur return immediately. */ |
| 3149 | if (pnt + psize > lim) |
| 3150 | return -1; |
| 3151 | |
| 3152 | /* Fetch prefix from NLRI packet. */ |
| 3153 | memcpy (&p.u.prefix, pnt, psize); |
| 3154 | |
| 3155 | /* Check address. */ |
| 3156 | if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST) |
| 3157 | { |
| 3158 | if (IN_CLASSD (ntohl (p.u.prefix4.s_addr))) |
| 3159 | { |
paul | f5ba387 | 2004-07-09 12:11:31 +0000 | [diff] [blame] | 3160 | /* |
| 3161 | * From draft-ietf-idr-bgp4-22, Section 6.3: |
| 3162 | * If a BGP router receives an UPDATE message with a |
| 3163 | * semantically incorrect NLRI field, in which a prefix is |
| 3164 | * semantically incorrect (eg. an unexpected multicast IP |
| 3165 | * address), it should ignore the prefix. |
| 3166 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3167 | zlog (peer->log, LOG_ERR, |
| 3168 | "IPv4 unicast NLRI is multicast address %s", |
| 3169 | inet_ntoa (p.u.prefix4)); |
paul | f5ba387 | 2004-07-09 12:11:31 +0000 | [diff] [blame] | 3170 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3171 | return -1; |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | #ifdef HAVE_IPV6 |
| 3176 | /* Check address. */ |
| 3177 | if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST) |
| 3178 | { |
| 3179 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 3180 | { |
| 3181 | char buf[BUFSIZ]; |
| 3182 | |
| 3183 | zlog (peer->log, LOG_WARNING, |
| 3184 | "IPv6 link-local NLRI received %s ignore this NLRI", |
| 3185 | inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ)); |
| 3186 | |
| 3187 | continue; |
| 3188 | } |
| 3189 | } |
| 3190 | #endif /* HAVE_IPV6 */ |
| 3191 | |
| 3192 | /* Normal process. */ |
| 3193 | if (attr) |
| 3194 | ret = bgp_update (peer, &p, attr, packet->afi, packet->safi, |
| 3195 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0); |
| 3196 | else |
| 3197 | ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi, |
| 3198 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL); |
| 3199 | |
| 3200 | /* Address family configuration mismatch or maximum-prefix count |
| 3201 | overflow. */ |
| 3202 | if (ret < 0) |
| 3203 | return -1; |
| 3204 | } |
| 3205 | |
| 3206 | /* Packet length consistency check. */ |
| 3207 | if (pnt != lim) |
| 3208 | return -1; |
| 3209 | |
| 3210 | return 0; |
| 3211 | } |
| 3212 | |
| 3213 | /* NLRI encode syntax check routine. */ |
| 3214 | int |
| 3215 | bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt, |
| 3216 | bgp_size_t length) |
| 3217 | { |
| 3218 | u_char *end; |
| 3219 | u_char prefixlen; |
| 3220 | int psize; |
| 3221 | |
| 3222 | end = pnt + length; |
| 3223 | |
| 3224 | /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for |
| 3225 | syntactic validity. If the field is syntactically incorrect, |
| 3226 | then the Error Subcode is set to Invalid Network Field. */ |
| 3227 | |
| 3228 | while (pnt < end) |
| 3229 | { |
| 3230 | prefixlen = *pnt++; |
| 3231 | |
| 3232 | /* Prefix length check. */ |
| 3233 | if ((afi == AFI_IP && prefixlen > 32) |
| 3234 | || (afi == AFI_IP6 && prefixlen > 128)) |
| 3235 | { |
| 3236 | plog_err (peer->log, |
| 3237 | "%s [Error] Update packet error (wrong prefix length %d)", |
| 3238 | peer->host, prefixlen); |
| 3239 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, |
| 3240 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); |
| 3241 | return -1; |
| 3242 | } |
| 3243 | |
| 3244 | /* Packet size overflow check. */ |
| 3245 | psize = PSIZE (prefixlen); |
| 3246 | |
| 3247 | if (pnt + psize > end) |
| 3248 | { |
| 3249 | plog_err (peer->log, |
| 3250 | "%s [Error] Update packet error" |
| 3251 | " (prefix data overflow prefix size is %d)", |
| 3252 | peer->host, psize); |
| 3253 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, |
| 3254 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); |
| 3255 | return -1; |
| 3256 | } |
| 3257 | |
| 3258 | pnt += psize; |
| 3259 | } |
| 3260 | |
| 3261 | /* Packet length consistency check. */ |
| 3262 | if (pnt != end) |
| 3263 | { |
| 3264 | plog_err (peer->log, |
| 3265 | "%s [Error] Update packet error" |
| 3266 | " (prefix length mismatch with total length)", |
| 3267 | peer->host); |
| 3268 | bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, |
| 3269 | BGP_NOTIFY_UPDATE_INVAL_NETWORK); |
| 3270 | return -1; |
| 3271 | } |
| 3272 | return 0; |
| 3273 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 3274 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3275 | static struct bgp_static * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 3276 | bgp_static_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3277 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 3278 | return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3281 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3282 | bgp_static_free (struct bgp_static *bgp_static) |
| 3283 | { |
| 3284 | if (bgp_static->rmap.name) |
| 3285 | free (bgp_static->rmap.name); |
| 3286 | XFREE (MTYPE_BGP_STATIC, bgp_static); |
| 3287 | } |
| 3288 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3289 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3290 | bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient, |
| 3291 | struct prefix *p, afi_t afi, safi_t safi) |
| 3292 | { |
| 3293 | struct bgp_node *rn; |
| 3294 | struct bgp_info *ri; |
| 3295 | |
| 3296 | rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL); |
| 3297 | |
| 3298 | /* Check selected route and self inserted route. */ |
| 3299 | for (ri = rn->info; ri; ri = ri->next) |
| 3300 | if (ri->peer == bgp->peer_self |
| 3301 | && ri->type == ZEBRA_ROUTE_BGP |
| 3302 | && ri->sub_type == BGP_ROUTE_STATIC) |
| 3303 | break; |
| 3304 | |
| 3305 | /* Withdraw static BGP route from routing table. */ |
| 3306 | if (ri) |
| 3307 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3308 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 3309 | bgp_process (bgp, rn, afi, safi); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | /* Unlock bgp_node_lookup. */ |
| 3313 | bgp_unlock_node (rn); |
| 3314 | } |
| 3315 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3316 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3317 | bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p, |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3318 | struct bgp_static *bgp_static, |
| 3319 | afi_t afi, safi_t safi) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3320 | { |
| 3321 | struct bgp_node *rn; |
| 3322 | struct bgp_info *ri; |
| 3323 | struct bgp_info *new; |
| 3324 | struct bgp_info info; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3325 | struct attr *attr_new; |
Jorge Boncompte [DTI2] | e16a413 | 2012-05-07 16:52:57 +0000 | [diff] [blame] | 3326 | struct attr attr; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 3327 | struct attr new_attr; |
| 3328 | struct attr_extra new_extra; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3329 | struct bgp *bgp; |
| 3330 | int ret; |
| 3331 | char buf[SU_ADDRSTRLEN]; |
| 3332 | |
| 3333 | bgp = rsclient->bgp; |
| 3334 | |
Paul Jakma | 06e110f | 2006-05-12 23:29:22 +0000 | [diff] [blame] | 3335 | assert (bgp_static); |
| 3336 | if (!bgp_static) |
| 3337 | return; |
| 3338 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3339 | rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL); |
| 3340 | |
| 3341 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); |
Paul Jakma | 06e110f | 2006-05-12 23:29:22 +0000 | [diff] [blame] | 3342 | |
| 3343 | attr.nexthop = bgp_static->igpnexthop; |
| 3344 | attr.med = bgp_static->igpmetric; |
| 3345 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3346 | |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3347 | if (bgp_static->atomic) |
| 3348 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); |
| 3349 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3350 | /* Apply network route-map for export to this rsclient. */ |
| 3351 | if (bgp_static->rmap.name) |
| 3352 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3353 | struct attr attr_tmp = attr; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3354 | info.peer = rsclient; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3355 | info.attr = &attr_tmp; |
| 3356 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3357 | SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT); |
| 3358 | SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK); |
| 3359 | |
| 3360 | ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info); |
| 3361 | |
| 3362 | rsclient->rmap_type = 0; |
| 3363 | |
| 3364 | if (ret == RMAP_DENYMATCH) |
| 3365 | { |
| 3366 | /* Free uninterned attribute. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3367 | bgp_attr_flush (&attr_tmp); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3368 | |
| 3369 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3370 | aspath_unintern (&attr.aspath); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3371 | bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3372 | bgp_attr_extra_free (&attr); |
| 3373 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3374 | return; |
| 3375 | } |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3376 | attr_new = bgp_attr_intern (&attr_tmp); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3377 | } |
| 3378 | else |
| 3379 | attr_new = bgp_attr_intern (&attr); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 3380 | |
| 3381 | new_attr.extra = &new_extra; |
Stephen Hemminger | 7badc26 | 2010-08-05 10:26:31 -0700 | [diff] [blame] | 3382 | bgp_attr_dup(&new_attr, attr_new); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3383 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3384 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); |
| 3385 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3386 | if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) |
| 3387 | == RMAP_DENY) |
| 3388 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3389 | /* This BGP update is filtered. Log the reason then update BGP entry. */ |
| 3390 | if (BGP_DEBUG (update, UPDATE_IN)) |
ajs | d2c1f16 | 2004-12-08 21:10:20 +0000 | [diff] [blame] | 3391 | zlog (rsclient->log, LOG_DEBUG, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3392 | "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy", |
| 3393 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 3394 | p->prefixlen, rsclient->host); |
| 3395 | |
| 3396 | bgp->peer_self->rmap_type = 0; |
| 3397 | |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3398 | bgp_attr_unintern (&attr_new); |
| 3399 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3400 | bgp_attr_extra_free (&attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3401 | |
| 3402 | bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi); |
| 3403 | |
| 3404 | return; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3405 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3406 | |
| 3407 | bgp->peer_self->rmap_type = 0; |
| 3408 | |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3409 | bgp_attr_unintern (&attr_new); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3410 | attr_new = bgp_attr_intern (&new_attr); |
| 3411 | |
| 3412 | for (ri = rn->info; ri; ri = ri->next) |
| 3413 | if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP |
| 3414 | && ri->sub_type == BGP_ROUTE_STATIC) |
| 3415 | break; |
| 3416 | |
| 3417 | if (ri) |
| 3418 | { |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 3419 | if (attrhash_cmp (ri->attr, attr_new) && |
| 3420 | !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3421 | { |
| 3422 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3423 | bgp_attr_unintern (&attr_new); |
| 3424 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3425 | bgp_attr_extra_free (&attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3426 | return; |
| 3427 | } |
| 3428 | else |
| 3429 | { |
| 3430 | /* The attribute is changed. */ |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 3431 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3432 | |
| 3433 | /* Rewrite BGP route information. */ |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 3434 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
| 3435 | bgp_info_restore(rn, ri); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3436 | bgp_attr_unintern (&ri->attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3437 | ri->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 3438 | ri->uptime = bgp_clock (); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3439 | |
| 3440 | /* Process change. */ |
| 3441 | bgp_process (bgp, rn, afi, safi); |
| 3442 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3443 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3444 | bgp_attr_extra_free (&attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3445 | return; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3446 | } |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3447 | } |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3448 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3449 | /* Make new BGP info. */ |
| 3450 | new = bgp_info_new (); |
| 3451 | new->type = ZEBRA_ROUTE_BGP; |
| 3452 | new->sub_type = BGP_ROUTE_STATIC; |
| 3453 | new->peer = bgp->peer_self; |
| 3454 | SET_FLAG (new->flags, BGP_INFO_VALID); |
| 3455 | new->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 3456 | new->uptime = bgp_clock (); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3457 | |
| 3458 | /* Register new BGP information. */ |
| 3459 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 3460 | |
| 3461 | /* route_node_get lock */ |
| 3462 | bgp_unlock_node (rn); |
| 3463 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3464 | /* Process change. */ |
| 3465 | bgp_process (bgp, rn, afi, safi); |
| 3466 | |
| 3467 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3468 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3469 | bgp_attr_extra_free (&attr); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3472 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3473 | bgp_static_update_main (struct bgp *bgp, struct prefix *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3474 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) |
| 3475 | { |
| 3476 | struct bgp_node *rn; |
| 3477 | struct bgp_info *ri; |
| 3478 | struct bgp_info *new; |
| 3479 | struct bgp_info info; |
Jorge Boncompte [DTI2] | e16a413 | 2012-05-07 16:52:57 +0000 | [diff] [blame] | 3480 | struct attr attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3481 | struct attr *attr_new; |
| 3482 | int ret; |
| 3483 | |
Paul Jakma | dd8103a | 2006-05-12 23:27:30 +0000 | [diff] [blame] | 3484 | assert (bgp_static); |
| 3485 | if (!bgp_static) |
| 3486 | return; |
| 3487 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3488 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3489 | |
| 3490 | bgp_attr_default_set (&attr, BGP_ORIGIN_IGP); |
Paul Jakma | dd8103a | 2006-05-12 23:27:30 +0000 | [diff] [blame] | 3491 | |
| 3492 | attr.nexthop = bgp_static->igpnexthop; |
| 3493 | attr.med = bgp_static->igpmetric; |
| 3494 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3495 | |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3496 | if (bgp_static->atomic) |
| 3497 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); |
| 3498 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3499 | /* Apply route-map. */ |
| 3500 | if (bgp_static->rmap.name) |
| 3501 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3502 | struct attr attr_tmp = attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3503 | info.peer = bgp->peer_self; |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 3504 | info.attr = &attr_tmp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3505 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3506 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); |
| 3507 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3508 | ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info); |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 3509 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3510 | bgp->peer_self->rmap_type = 0; |
| 3511 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3512 | if (ret == RMAP_DENYMATCH) |
| 3513 | { |
| 3514 | /* Free uninterned attribute. */ |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 3515 | bgp_attr_flush (&attr_tmp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3516 | |
| 3517 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3518 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3519 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3520 | bgp_static_withdraw (bgp, p, afi, safi); |
| 3521 | return; |
| 3522 | } |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 3523 | attr_new = bgp_attr_intern (&attr_tmp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3524 | } |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 3525 | else |
| 3526 | attr_new = bgp_attr_intern (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3527 | |
| 3528 | for (ri = rn->info; ri; ri = ri->next) |
| 3529 | if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP |
| 3530 | && ri->sub_type == BGP_ROUTE_STATIC) |
| 3531 | break; |
| 3532 | |
| 3533 | if (ri) |
| 3534 | { |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 3535 | if (attrhash_cmp (ri->attr, attr_new) && |
| 3536 | !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3537 | { |
| 3538 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3539 | bgp_attr_unintern (&attr_new); |
| 3540 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3541 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3542 | return; |
| 3543 | } |
| 3544 | else |
| 3545 | { |
| 3546 | /* The attribute is changed. */ |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 3547 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3548 | |
| 3549 | /* Rewrite BGP route information. */ |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 3550 | if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)) |
| 3551 | bgp_info_restore(rn, ri); |
| 3552 | else |
| 3553 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3554 | bgp_attr_unintern (&ri->attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3555 | ri->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 3556 | ri->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3557 | |
| 3558 | /* Process change. */ |
| 3559 | bgp_aggregate_increment (bgp, p, ri, afi, safi); |
| 3560 | bgp_process (bgp, rn, afi, safi); |
| 3561 | bgp_unlock_node (rn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3562 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3563 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3564 | return; |
| 3565 | } |
| 3566 | } |
| 3567 | |
| 3568 | /* Make new BGP info. */ |
| 3569 | new = bgp_info_new (); |
| 3570 | new->type = ZEBRA_ROUTE_BGP; |
| 3571 | new->sub_type = BGP_ROUTE_STATIC; |
| 3572 | new->peer = bgp->peer_self; |
| 3573 | SET_FLAG (new->flags, BGP_INFO_VALID); |
| 3574 | new->attr = attr_new; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 3575 | new->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3576 | |
| 3577 | /* Aggregate address increment. */ |
| 3578 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
| 3579 | |
| 3580 | /* Register new BGP information. */ |
| 3581 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 3582 | |
| 3583 | /* route_node_get lock */ |
| 3584 | bgp_unlock_node (rn); |
| 3585 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3586 | /* Process change. */ |
| 3587 | bgp_process (bgp, rn, afi, safi); |
| 3588 | |
| 3589 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 3590 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3591 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3595 | bgp_static_update (struct bgp *bgp, struct prefix *p, |
| 3596 | struct bgp_static *bgp_static, afi_t afi, safi_t safi) |
| 3597 | { |
| 3598 | struct peer *rsclient; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 3599 | struct listnode *node, *nnode; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3600 | |
| 3601 | bgp_static_update_main (bgp, p, bgp_static, afi, safi); |
| 3602 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 3603 | for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3604 | { |
Paul Jakma | da5b30f | 2006-05-08 14:37:17 +0000 | [diff] [blame] | 3605 | if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 3606 | bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3607 | } |
| 3608 | } |
| 3609 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3610 | static void |
Michael Lambert | 4c9641b | 2010-07-22 13:20:55 -0400 | [diff] [blame] | 3611 | bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi, |
| 3612 | safi_t safi, struct prefix_rd *prd, u_char *tag) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3613 | { |
| 3614 | struct bgp_node *rn; |
| 3615 | struct bgp_info *new; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3616 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3617 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3618 | |
| 3619 | /* Make new BGP info. */ |
| 3620 | new = bgp_info_new (); |
| 3621 | new->type = ZEBRA_ROUTE_BGP; |
| 3622 | new->sub_type = BGP_ROUTE_STATIC; |
| 3623 | new->peer = bgp->peer_self; |
| 3624 | new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP); |
| 3625 | SET_FLAG (new->flags, BGP_INFO_VALID); |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 3626 | new->uptime = bgp_clock (); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 3627 | new->extra = bgp_info_extra_new(); |
| 3628 | memcpy (new->extra->tag, tag, 3); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3629 | |
| 3630 | /* Aggregate address increment. */ |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 3631 | bgp_aggregate_increment (bgp, p, new, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3632 | |
| 3633 | /* Register new BGP information. */ |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 3634 | bgp_info_add (rn, new); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3635 | |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 3636 | /* route_node_get lock */ |
| 3637 | bgp_unlock_node (rn); |
| 3638 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3639 | /* Process change. */ |
| 3640 | bgp_process (bgp, rn, afi, safi); |
| 3641 | } |
| 3642 | |
| 3643 | void |
| 3644 | bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi, |
| 3645 | safi_t safi) |
| 3646 | { |
| 3647 | struct bgp_node *rn; |
| 3648 | struct bgp_info *ri; |
| 3649 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3650 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3651 | |
| 3652 | /* Check selected route and self inserted route. */ |
| 3653 | for (ri = rn->info; ri; ri = ri->next) |
| 3654 | if (ri->peer == bgp->peer_self |
| 3655 | && ri->type == ZEBRA_ROUTE_BGP |
| 3656 | && ri->sub_type == BGP_ROUTE_STATIC) |
| 3657 | break; |
| 3658 | |
| 3659 | /* Withdraw static BGP route from routing table. */ |
| 3660 | if (ri) |
| 3661 | { |
| 3662 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3663 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 3664 | bgp_process (bgp, rn, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | /* Unlock bgp_node_lookup. */ |
| 3668 | bgp_unlock_node (rn); |
| 3669 | } |
| 3670 | |
| 3671 | void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3672 | bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi) |
| 3673 | { |
| 3674 | struct bgp_static *bgp_static; |
| 3675 | struct bgp *bgp; |
| 3676 | struct bgp_node *rn; |
| 3677 | struct prefix *p; |
| 3678 | |
| 3679 | bgp = rsclient->bgp; |
| 3680 | |
| 3681 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) |
| 3682 | if ((bgp_static = rn->info) != NULL) |
| 3683 | { |
| 3684 | p = &rn->p; |
| 3685 | |
| 3686 | bgp_static_update_rsclient (rsclient, p, bgp_static, |
| 3687 | afi, safi); |
| 3688 | } |
| 3689 | } |
| 3690 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3691 | static void |
Michael Lambert | 4c9641b | 2010-07-22 13:20:55 -0400 | [diff] [blame] | 3692 | bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi, |
| 3693 | safi_t safi, struct prefix_rd *prd, u_char *tag) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3694 | { |
| 3695 | struct bgp_node *rn; |
| 3696 | struct bgp_info *ri; |
| 3697 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3698 | rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3699 | |
| 3700 | /* Check selected route and self inserted route. */ |
| 3701 | for (ri = rn->info; ri; ri = ri->next) |
| 3702 | if (ri->peer == bgp->peer_self |
| 3703 | && ri->type == ZEBRA_ROUTE_BGP |
| 3704 | && ri->sub_type == BGP_ROUTE_STATIC) |
| 3705 | break; |
| 3706 | |
| 3707 | /* Withdraw static BGP route from routing table. */ |
| 3708 | if (ri) |
| 3709 | { |
| 3710 | bgp_aggregate_decrement (bgp, p, ri, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3711 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 3712 | bgp_process (bgp, rn, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | /* Unlock bgp_node_lookup. */ |
| 3716 | bgp_unlock_node (rn); |
| 3717 | } |
| 3718 | |
| 3719 | /* Configure static BGP network. When user don't run zebra, static |
| 3720 | route should be installed as valid. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3721 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 3722 | bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 3723 | afi_t afi, safi_t safi, const char *rmap, int backdoor) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3724 | { |
| 3725 | int ret; |
| 3726 | struct prefix p; |
| 3727 | struct bgp_static *bgp_static; |
| 3728 | struct bgp_node *rn; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3729 | u_char need_update = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3730 | |
| 3731 | /* Convert IP prefix string to struct prefix. */ |
| 3732 | ret = str2prefix (ip_str, &p); |
| 3733 | if (! ret) |
| 3734 | { |
| 3735 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); |
| 3736 | return CMD_WARNING; |
| 3737 | } |
| 3738 | #ifdef HAVE_IPV6 |
| 3739 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 3740 | { |
| 3741 | vty_out (vty, "%% Malformed prefix (link-local address)%s", |
| 3742 | VTY_NEWLINE); |
| 3743 | return CMD_WARNING; |
| 3744 | } |
| 3745 | #endif /* HAVE_IPV6 */ |
| 3746 | |
| 3747 | apply_mask (&p); |
| 3748 | |
| 3749 | /* Set BGP static route configuration. */ |
| 3750 | rn = bgp_node_get (bgp->route[afi][safi], &p); |
| 3751 | |
| 3752 | if (rn->info) |
| 3753 | { |
| 3754 | /* Configuration change. */ |
| 3755 | bgp_static = rn->info; |
| 3756 | |
| 3757 | /* Check previous routes are installed into BGP. */ |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 3758 | if (bgp_static->valid && bgp_static->backdoor != backdoor) |
| 3759 | need_update = 1; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3760 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3761 | bgp_static->backdoor = backdoor; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3762 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3763 | if (rmap) |
| 3764 | { |
| 3765 | if (bgp_static->rmap.name) |
| 3766 | free (bgp_static->rmap.name); |
| 3767 | bgp_static->rmap.name = strdup (rmap); |
| 3768 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
| 3769 | } |
| 3770 | else |
| 3771 | { |
| 3772 | if (bgp_static->rmap.name) |
| 3773 | free (bgp_static->rmap.name); |
| 3774 | bgp_static->rmap.name = NULL; |
| 3775 | bgp_static->rmap.map = NULL; |
| 3776 | bgp_static->valid = 0; |
| 3777 | } |
| 3778 | bgp_unlock_node (rn); |
| 3779 | } |
| 3780 | else |
| 3781 | { |
| 3782 | /* New configuration. */ |
| 3783 | bgp_static = bgp_static_new (); |
| 3784 | bgp_static->backdoor = backdoor; |
| 3785 | bgp_static->valid = 0; |
| 3786 | bgp_static->igpmetric = 0; |
| 3787 | bgp_static->igpnexthop.s_addr = 0; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3788 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3789 | if (rmap) |
| 3790 | { |
| 3791 | if (bgp_static->rmap.name) |
| 3792 | free (bgp_static->rmap.name); |
| 3793 | bgp_static->rmap.name = strdup (rmap); |
| 3794 | bgp_static->rmap.map = route_map_lookup_by_name (rmap); |
| 3795 | } |
| 3796 | rn->info = bgp_static; |
| 3797 | } |
| 3798 | |
| 3799 | /* If BGP scan is not enabled, we should install this route here. */ |
| 3800 | if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)) |
| 3801 | { |
| 3802 | bgp_static->valid = 1; |
| 3803 | |
| 3804 | if (need_update) |
| 3805 | bgp_static_withdraw (bgp, &p, afi, safi); |
| 3806 | |
| 3807 | if (! bgp_static->backdoor) |
| 3808 | bgp_static_update (bgp, &p, bgp_static, afi, safi); |
| 3809 | } |
| 3810 | |
| 3811 | return CMD_SUCCESS; |
| 3812 | } |
| 3813 | |
| 3814 | /* Configure static BGP network. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3815 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 3816 | bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str, |
Michael Lambert | 4c9641b | 2010-07-22 13:20:55 -0400 | [diff] [blame] | 3817 | afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3818 | { |
| 3819 | int ret; |
| 3820 | struct prefix p; |
| 3821 | struct bgp_static *bgp_static; |
| 3822 | struct bgp_node *rn; |
| 3823 | |
| 3824 | /* Convert IP prefix string to struct prefix. */ |
| 3825 | ret = str2prefix (ip_str, &p); |
| 3826 | if (! ret) |
| 3827 | { |
| 3828 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); |
| 3829 | return CMD_WARNING; |
| 3830 | } |
| 3831 | #ifdef HAVE_IPV6 |
| 3832 | if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 3833 | { |
| 3834 | vty_out (vty, "%% Malformed prefix (link-local address)%s", |
| 3835 | VTY_NEWLINE); |
| 3836 | return CMD_WARNING; |
| 3837 | } |
| 3838 | #endif /* HAVE_IPV6 */ |
| 3839 | |
| 3840 | apply_mask (&p); |
| 3841 | |
| 3842 | rn = bgp_node_lookup (bgp->route[afi][safi], &p); |
| 3843 | if (! rn) |
| 3844 | { |
| 3845 | vty_out (vty, "%% Can't find specified static route configuration.%s", |
| 3846 | VTY_NEWLINE); |
| 3847 | return CMD_WARNING; |
| 3848 | } |
| 3849 | |
| 3850 | bgp_static = rn->info; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3851 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3852 | /* Update BGP RIB. */ |
| 3853 | if (! bgp_static->backdoor) |
| 3854 | bgp_static_withdraw (bgp, &p, afi, safi); |
| 3855 | |
| 3856 | /* Clear configuration. */ |
| 3857 | bgp_static_free (bgp_static); |
| 3858 | rn->info = NULL; |
| 3859 | bgp_unlock_node (rn); |
| 3860 | bgp_unlock_node (rn); |
| 3861 | |
| 3862 | return CMD_SUCCESS; |
| 3863 | } |
| 3864 | |
| 3865 | /* Called from bgp_delete(). Delete all static routes from the BGP |
| 3866 | instance. */ |
| 3867 | void |
| 3868 | bgp_static_delete (struct bgp *bgp) |
| 3869 | { |
| 3870 | afi_t afi; |
| 3871 | safi_t safi; |
| 3872 | struct bgp_node *rn; |
| 3873 | struct bgp_node *rm; |
| 3874 | struct bgp_table *table; |
| 3875 | struct bgp_static *bgp_static; |
| 3876 | |
| 3877 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 3878 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 3879 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) |
| 3880 | if (rn->info != NULL) |
| 3881 | { |
| 3882 | if (safi == SAFI_MPLS_VPN) |
| 3883 | { |
| 3884 | table = rn->info; |
| 3885 | |
| 3886 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) |
| 3887 | { |
| 3888 | bgp_static = rn->info; |
| 3889 | bgp_static_withdraw_vpnv4 (bgp, &rm->p, |
| 3890 | AFI_IP, SAFI_MPLS_VPN, |
| 3891 | (struct prefix_rd *)&rn->p, |
| 3892 | bgp_static->tag); |
| 3893 | bgp_static_free (bgp_static); |
| 3894 | rn->info = NULL; |
| 3895 | bgp_unlock_node (rn); |
| 3896 | } |
| 3897 | } |
| 3898 | else |
| 3899 | { |
| 3900 | bgp_static = rn->info; |
| 3901 | bgp_static_withdraw (bgp, &rn->p, afi, safi); |
| 3902 | bgp_static_free (bgp_static); |
| 3903 | rn->info = NULL; |
| 3904 | bgp_unlock_node (rn); |
| 3905 | } |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 3910 | bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str, |
| 3911 | const char *tag_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3912 | { |
| 3913 | int ret; |
| 3914 | struct prefix p; |
| 3915 | struct prefix_rd prd; |
| 3916 | struct bgp *bgp; |
| 3917 | struct bgp_node *prn; |
| 3918 | struct bgp_node *rn; |
| 3919 | struct bgp_table *table; |
| 3920 | struct bgp_static *bgp_static; |
| 3921 | u_char tag[3]; |
| 3922 | |
| 3923 | bgp = vty->index; |
| 3924 | |
| 3925 | ret = str2prefix (ip_str, &p); |
| 3926 | if (! ret) |
| 3927 | { |
| 3928 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); |
| 3929 | return CMD_WARNING; |
| 3930 | } |
| 3931 | apply_mask (&p); |
| 3932 | |
| 3933 | ret = str2prefix_rd (rd_str, &prd); |
| 3934 | if (! ret) |
| 3935 | { |
| 3936 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); |
| 3937 | return CMD_WARNING; |
| 3938 | } |
| 3939 | |
| 3940 | ret = str2tag (tag_str, tag); |
| 3941 | if (! ret) |
| 3942 | { |
| 3943 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); |
| 3944 | return CMD_WARNING; |
| 3945 | } |
| 3946 | |
| 3947 | prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], |
| 3948 | (struct prefix *)&prd); |
| 3949 | if (prn->info == NULL) |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 3950 | prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3951 | else |
| 3952 | bgp_unlock_node (prn); |
| 3953 | table = prn->info; |
| 3954 | |
| 3955 | rn = bgp_node_get (table, &p); |
| 3956 | |
| 3957 | if (rn->info) |
| 3958 | { |
| 3959 | vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE); |
| 3960 | bgp_unlock_node (rn); |
| 3961 | } |
| 3962 | else |
| 3963 | { |
| 3964 | /* New configuration. */ |
| 3965 | bgp_static = bgp_static_new (); |
| 3966 | bgp_static->valid = 1; |
| 3967 | memcpy (bgp_static->tag, tag, 3); |
| 3968 | rn->info = bgp_static; |
| 3969 | |
| 3970 | bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); |
| 3971 | } |
| 3972 | |
| 3973 | return CMD_SUCCESS; |
| 3974 | } |
| 3975 | |
| 3976 | /* Configure static BGP network. */ |
| 3977 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 3978 | bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str, |
| 3979 | const char *rd_str, const char *tag_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3980 | { |
| 3981 | int ret; |
| 3982 | struct bgp *bgp; |
| 3983 | struct prefix p; |
| 3984 | struct prefix_rd prd; |
| 3985 | struct bgp_node *prn; |
| 3986 | struct bgp_node *rn; |
| 3987 | struct bgp_table *table; |
| 3988 | struct bgp_static *bgp_static; |
| 3989 | u_char tag[3]; |
| 3990 | |
| 3991 | bgp = vty->index; |
| 3992 | |
| 3993 | /* Convert IP prefix string to struct prefix. */ |
| 3994 | ret = str2prefix (ip_str, &p); |
| 3995 | if (! ret) |
| 3996 | { |
| 3997 | vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE); |
| 3998 | return CMD_WARNING; |
| 3999 | } |
| 4000 | apply_mask (&p); |
| 4001 | |
| 4002 | ret = str2prefix_rd (rd_str, &prd); |
| 4003 | if (! ret) |
| 4004 | { |
| 4005 | vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE); |
| 4006 | return CMD_WARNING; |
| 4007 | } |
| 4008 | |
| 4009 | ret = str2tag (tag_str, tag); |
| 4010 | if (! ret) |
| 4011 | { |
| 4012 | vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE); |
| 4013 | return CMD_WARNING; |
| 4014 | } |
| 4015 | |
| 4016 | prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN], |
| 4017 | (struct prefix *)&prd); |
| 4018 | if (prn->info == NULL) |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 4019 | prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4020 | else |
| 4021 | bgp_unlock_node (prn); |
| 4022 | table = prn->info; |
| 4023 | |
| 4024 | rn = bgp_node_lookup (table, &p); |
| 4025 | |
| 4026 | if (rn) |
| 4027 | { |
| 4028 | bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag); |
| 4029 | |
| 4030 | bgp_static = rn->info; |
| 4031 | bgp_static_free (bgp_static); |
| 4032 | rn->info = NULL; |
| 4033 | bgp_unlock_node (rn); |
| 4034 | bgp_unlock_node (rn); |
| 4035 | } |
| 4036 | else |
| 4037 | vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE); |
| 4038 | |
| 4039 | return CMD_SUCCESS; |
| 4040 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 4041 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4042 | DEFUN (bgp_network, |
| 4043 | bgp_network_cmd, |
| 4044 | "network A.B.C.D/M", |
| 4045 | "Specify a network to announce via BGP\n" |
| 4046 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 4047 | { |
| 4048 | return bgp_static_set (vty, vty->index, argv[0], |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4049 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | DEFUN (bgp_network_route_map, |
| 4053 | bgp_network_route_map_cmd, |
| 4054 | "network A.B.C.D/M route-map WORD", |
| 4055 | "Specify a network to announce via BGP\n" |
| 4056 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4057 | "Route-map to modify the attributes\n" |
| 4058 | "Name of the route map\n") |
| 4059 | { |
| 4060 | return bgp_static_set (vty, vty->index, argv[0], |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4061 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | DEFUN (bgp_network_backdoor, |
| 4065 | bgp_network_backdoor_cmd, |
| 4066 | "network A.B.C.D/M backdoor", |
| 4067 | "Specify a network to announce via BGP\n" |
| 4068 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4069 | "Specify a BGP backdoor route\n") |
| 4070 | { |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4071 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4072 | NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | DEFUN (bgp_network_mask, |
| 4076 | bgp_network_mask_cmd, |
| 4077 | "network A.B.C.D mask A.B.C.D", |
| 4078 | "Specify a network to announce via BGP\n" |
| 4079 | "Network number\n" |
| 4080 | "Network mask\n" |
| 4081 | "Network mask\n") |
| 4082 | { |
| 4083 | int ret; |
| 4084 | char prefix_str[BUFSIZ]; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4085 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4086 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 4087 | if (! ret) |
| 4088 | { |
| 4089 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4090 | return CMD_WARNING; |
| 4091 | } |
| 4092 | |
| 4093 | return bgp_static_set (vty, vty->index, prefix_str, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4094 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | DEFUN (bgp_network_mask_route_map, |
| 4098 | bgp_network_mask_route_map_cmd, |
| 4099 | "network A.B.C.D mask A.B.C.D route-map WORD", |
| 4100 | "Specify a network to announce via BGP\n" |
| 4101 | "Network number\n" |
| 4102 | "Network mask\n" |
| 4103 | "Network mask\n" |
| 4104 | "Route-map to modify the attributes\n" |
| 4105 | "Name of the route map\n") |
| 4106 | { |
| 4107 | int ret; |
| 4108 | char prefix_str[BUFSIZ]; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4109 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4110 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 4111 | if (! ret) |
| 4112 | { |
| 4113 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4114 | return CMD_WARNING; |
| 4115 | } |
| 4116 | |
| 4117 | return bgp_static_set (vty, vty->index, prefix_str, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4118 | AFI_IP, bgp_node_safi (vty), argv[2], 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
| 4121 | DEFUN (bgp_network_mask_backdoor, |
| 4122 | bgp_network_mask_backdoor_cmd, |
| 4123 | "network A.B.C.D mask A.B.C.D backdoor", |
| 4124 | "Specify a network to announce via BGP\n" |
| 4125 | "Network number\n" |
| 4126 | "Network mask\n" |
| 4127 | "Network mask\n" |
| 4128 | "Specify a BGP backdoor route\n") |
| 4129 | { |
| 4130 | int ret; |
| 4131 | char prefix_str[BUFSIZ]; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4132 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4133 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 4134 | if (! ret) |
| 4135 | { |
| 4136 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4137 | return CMD_WARNING; |
| 4138 | } |
| 4139 | |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4140 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4141 | NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | DEFUN (bgp_network_mask_natural, |
| 4145 | bgp_network_mask_natural_cmd, |
| 4146 | "network A.B.C.D", |
| 4147 | "Specify a network to announce via BGP\n" |
| 4148 | "Network number\n") |
| 4149 | { |
| 4150 | int ret; |
| 4151 | char prefix_str[BUFSIZ]; |
| 4152 | |
| 4153 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); |
| 4154 | if (! ret) |
| 4155 | { |
| 4156 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4157 | return CMD_WARNING; |
| 4158 | } |
| 4159 | |
| 4160 | return bgp_static_set (vty, vty->index, prefix_str, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4161 | AFI_IP, bgp_node_safi (vty), NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | DEFUN (bgp_network_mask_natural_route_map, |
| 4165 | bgp_network_mask_natural_route_map_cmd, |
| 4166 | "network A.B.C.D route-map WORD", |
| 4167 | "Specify a network to announce via BGP\n" |
| 4168 | "Network number\n" |
| 4169 | "Route-map to modify the attributes\n" |
| 4170 | "Name of the route map\n") |
| 4171 | { |
| 4172 | int ret; |
| 4173 | char prefix_str[BUFSIZ]; |
| 4174 | |
| 4175 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); |
| 4176 | if (! ret) |
| 4177 | { |
| 4178 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4179 | return CMD_WARNING; |
| 4180 | } |
| 4181 | |
| 4182 | return bgp_static_set (vty, vty->index, prefix_str, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4183 | AFI_IP, bgp_node_safi (vty), argv[1], 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | DEFUN (bgp_network_mask_natural_backdoor, |
| 4187 | bgp_network_mask_natural_backdoor_cmd, |
| 4188 | "network A.B.C.D backdoor", |
| 4189 | "Specify a network to announce via BGP\n" |
| 4190 | "Network number\n" |
| 4191 | "Specify a BGP backdoor route\n") |
| 4192 | { |
| 4193 | int ret; |
| 4194 | char prefix_str[BUFSIZ]; |
| 4195 | |
| 4196 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); |
| 4197 | if (! ret) |
| 4198 | { |
| 4199 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4200 | return CMD_WARNING; |
| 4201 | } |
| 4202 | |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 4203 | return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4204 | NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | DEFUN (no_bgp_network, |
| 4208 | no_bgp_network_cmd, |
| 4209 | "no network A.B.C.D/M", |
| 4210 | NO_STR |
| 4211 | "Specify a network to announce via BGP\n" |
| 4212 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 4213 | { |
| 4214 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP, |
| 4215 | bgp_node_safi (vty)); |
| 4216 | } |
| 4217 | |
| 4218 | ALIAS (no_bgp_network, |
| 4219 | no_bgp_network_route_map_cmd, |
| 4220 | "no network A.B.C.D/M route-map WORD", |
| 4221 | NO_STR |
| 4222 | "Specify a network to announce via BGP\n" |
| 4223 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4224 | "Route-map to modify the attributes\n" |
| 4225 | "Name of the route map\n") |
| 4226 | |
| 4227 | ALIAS (no_bgp_network, |
| 4228 | no_bgp_network_backdoor_cmd, |
| 4229 | "no network A.B.C.D/M backdoor", |
| 4230 | NO_STR |
| 4231 | "Specify a network to announce via BGP\n" |
| 4232 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4233 | "Specify a BGP backdoor route\n") |
| 4234 | |
| 4235 | DEFUN (no_bgp_network_mask, |
| 4236 | no_bgp_network_mask_cmd, |
| 4237 | "no network A.B.C.D mask A.B.C.D", |
| 4238 | NO_STR |
| 4239 | "Specify a network to announce via BGP\n" |
| 4240 | "Network number\n" |
| 4241 | "Network mask\n" |
| 4242 | "Network mask\n") |
| 4243 | { |
| 4244 | int ret; |
| 4245 | char prefix_str[BUFSIZ]; |
| 4246 | |
| 4247 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 4248 | if (! ret) |
| 4249 | { |
| 4250 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4251 | return CMD_WARNING; |
| 4252 | } |
| 4253 | |
| 4254 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, |
| 4255 | bgp_node_safi (vty)); |
| 4256 | } |
| 4257 | |
| 4258 | ALIAS (no_bgp_network_mask, |
| 4259 | no_bgp_network_mask_route_map_cmd, |
| 4260 | "no network A.B.C.D mask A.B.C.D route-map WORD", |
| 4261 | NO_STR |
| 4262 | "Specify a network to announce via BGP\n" |
| 4263 | "Network number\n" |
| 4264 | "Network mask\n" |
| 4265 | "Network mask\n" |
| 4266 | "Route-map to modify the attributes\n" |
| 4267 | "Name of the route map\n") |
| 4268 | |
| 4269 | ALIAS (no_bgp_network_mask, |
| 4270 | no_bgp_network_mask_backdoor_cmd, |
| 4271 | "no network A.B.C.D mask A.B.C.D backdoor", |
| 4272 | NO_STR |
| 4273 | "Specify a network to announce via BGP\n" |
| 4274 | "Network number\n" |
| 4275 | "Network mask\n" |
| 4276 | "Network mask\n" |
| 4277 | "Specify a BGP backdoor route\n") |
| 4278 | |
| 4279 | DEFUN (no_bgp_network_mask_natural, |
| 4280 | no_bgp_network_mask_natural_cmd, |
| 4281 | "no network A.B.C.D", |
| 4282 | NO_STR |
| 4283 | "Specify a network to announce via BGP\n" |
| 4284 | "Network number\n") |
| 4285 | { |
| 4286 | int ret; |
| 4287 | char prefix_str[BUFSIZ]; |
| 4288 | |
| 4289 | ret = netmask_str2prefix_str (argv[0], NULL, prefix_str); |
| 4290 | if (! ret) |
| 4291 | { |
| 4292 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 4293 | return CMD_WARNING; |
| 4294 | } |
| 4295 | |
| 4296 | return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, |
| 4297 | bgp_node_safi (vty)); |
| 4298 | } |
| 4299 | |
| 4300 | ALIAS (no_bgp_network_mask_natural, |
| 4301 | no_bgp_network_mask_natural_route_map_cmd, |
| 4302 | "no network A.B.C.D route-map WORD", |
| 4303 | NO_STR |
| 4304 | "Specify a network to announce via BGP\n" |
| 4305 | "Network number\n" |
| 4306 | "Route-map to modify the attributes\n" |
| 4307 | "Name of the route map\n") |
| 4308 | |
| 4309 | ALIAS (no_bgp_network_mask_natural, |
| 4310 | no_bgp_network_mask_natural_backdoor_cmd, |
| 4311 | "no network A.B.C.D backdoor", |
| 4312 | NO_STR |
| 4313 | "Specify a network to announce via BGP\n" |
| 4314 | "Network number\n" |
| 4315 | "Specify a BGP backdoor route\n") |
| 4316 | |
| 4317 | #ifdef HAVE_IPV6 |
| 4318 | DEFUN (ipv6_bgp_network, |
| 4319 | ipv6_bgp_network_cmd, |
| 4320 | "network X:X::X:X/M", |
| 4321 | "Specify a network to announce via BGP\n" |
| 4322 | "IPv6 prefix <network>/<length>\n") |
| 4323 | { |
G.Balaji | 73bfe0b | 2011-09-23 22:36:20 +0530 | [diff] [blame] | 4324 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty), |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4325 | NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | DEFUN (ipv6_bgp_network_route_map, |
| 4329 | ipv6_bgp_network_route_map_cmd, |
| 4330 | "network X:X::X:X/M route-map WORD", |
| 4331 | "Specify a network to announce via BGP\n" |
| 4332 | "IPv6 prefix <network>/<length>\n" |
| 4333 | "Route-map to modify the attributes\n" |
| 4334 | "Name of the route map\n") |
| 4335 | { |
| 4336 | return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4337 | bgp_node_safi (vty), argv[1], 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | DEFUN (no_ipv6_bgp_network, |
| 4341 | no_ipv6_bgp_network_cmd, |
| 4342 | "no network X:X::X:X/M", |
| 4343 | NO_STR |
| 4344 | "Specify a network to announce via BGP\n" |
| 4345 | "IPv6 prefix <network>/<length>\n") |
| 4346 | { |
G.Balaji | 73bfe0b | 2011-09-23 22:36:20 +0530 | [diff] [blame] | 4347 | return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | ALIAS (no_ipv6_bgp_network, |
| 4351 | no_ipv6_bgp_network_route_map_cmd, |
| 4352 | "no network X:X::X:X/M route-map WORD", |
| 4353 | NO_STR |
| 4354 | "Specify a network to announce via BGP\n" |
| 4355 | "IPv6 prefix <network>/<length>\n" |
| 4356 | "Route-map to modify the attributes\n" |
| 4357 | "Name of the route map\n") |
| 4358 | |
| 4359 | ALIAS (ipv6_bgp_network, |
| 4360 | old_ipv6_bgp_network_cmd, |
| 4361 | "ipv6 bgp network X:X::X:X/M", |
| 4362 | IPV6_STR |
| 4363 | BGP_STR |
| 4364 | "Specify a network to announce via BGP\n" |
| 4365 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 4366 | |
| 4367 | ALIAS (no_ipv6_bgp_network, |
| 4368 | old_no_ipv6_bgp_network_cmd, |
| 4369 | "no ipv6 bgp network X:X::X:X/M", |
| 4370 | NO_STR |
| 4371 | IPV6_STR |
| 4372 | BGP_STR |
| 4373 | "Specify a network to announce via BGP\n" |
| 4374 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 4375 | #endif /* HAVE_IPV6 */ |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4376 | |
| 4377 | /* stubs for removed AS-Pathlimit commands, kept for config compatibility */ |
| 4378 | ALIAS_DEPRECATED (bgp_network, |
| 4379 | bgp_network_ttl_cmd, |
| 4380 | "network A.B.C.D/M pathlimit <0-255>", |
| 4381 | "Specify a network to announce via BGP\n" |
| 4382 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4383 | "AS-Path hopcount limit attribute\n" |
| 4384 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4385 | ALIAS_DEPRECATED (bgp_network_backdoor, |
| 4386 | bgp_network_backdoor_ttl_cmd, |
| 4387 | "network A.B.C.D/M backdoor pathlimit <0-255>", |
| 4388 | "Specify a network to announce via BGP\n" |
| 4389 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4390 | "Specify a BGP backdoor route\n" |
| 4391 | "AS-Path hopcount limit attribute\n" |
| 4392 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4393 | ALIAS_DEPRECATED (bgp_network_mask, |
| 4394 | bgp_network_mask_ttl_cmd, |
| 4395 | "network A.B.C.D mask A.B.C.D pathlimit <0-255>", |
| 4396 | "Specify a network to announce via BGP\n" |
| 4397 | "Network number\n" |
| 4398 | "Network mask\n" |
| 4399 | "Network mask\n" |
| 4400 | "AS-Path hopcount limit attribute\n" |
| 4401 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4402 | ALIAS_DEPRECATED (bgp_network_mask_backdoor, |
| 4403 | bgp_network_mask_backdoor_ttl_cmd, |
| 4404 | "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>", |
| 4405 | "Specify a network to announce via BGP\n" |
| 4406 | "Network number\n" |
| 4407 | "Network mask\n" |
| 4408 | "Network mask\n" |
| 4409 | "Specify a BGP backdoor route\n" |
| 4410 | "AS-Path hopcount limit attribute\n" |
| 4411 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4412 | ALIAS_DEPRECATED (bgp_network_mask_natural, |
| 4413 | bgp_network_mask_natural_ttl_cmd, |
| 4414 | "network A.B.C.D pathlimit <0-255>", |
| 4415 | "Specify a network to announce via BGP\n" |
| 4416 | "Network number\n" |
| 4417 | "AS-Path hopcount limit attribute\n" |
| 4418 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4419 | ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor, |
| 4420 | bgp_network_mask_natural_backdoor_ttl_cmd, |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 4421 | "network A.B.C.D backdoor pathlimit <1-255>", |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4422 | "Specify a network to announce via BGP\n" |
| 4423 | "Network number\n" |
| 4424 | "Specify a BGP backdoor route\n" |
| 4425 | "AS-Path hopcount limit attribute\n" |
| 4426 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4427 | ALIAS_DEPRECATED (no_bgp_network, |
| 4428 | no_bgp_network_ttl_cmd, |
| 4429 | "no network A.B.C.D/M pathlimit <0-255>", |
| 4430 | NO_STR |
| 4431 | "Specify a network to announce via BGP\n" |
| 4432 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4433 | "AS-Path hopcount limit attribute\n" |
| 4434 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4435 | ALIAS_DEPRECATED (no_bgp_network, |
| 4436 | no_bgp_network_backdoor_ttl_cmd, |
| 4437 | "no network A.B.C.D/M backdoor pathlimit <0-255>", |
| 4438 | NO_STR |
| 4439 | "Specify a network to announce via BGP\n" |
| 4440 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 4441 | "Specify a BGP backdoor route\n" |
| 4442 | "AS-Path hopcount limit attribute\n" |
| 4443 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4444 | ALIAS_DEPRECATED (no_bgp_network, |
| 4445 | no_bgp_network_mask_ttl_cmd, |
| 4446 | "no network A.B.C.D mask A.B.C.D pathlimit <0-255>", |
| 4447 | NO_STR |
| 4448 | "Specify a network to announce via BGP\n" |
| 4449 | "Network number\n" |
| 4450 | "Network mask\n" |
| 4451 | "Network mask\n" |
| 4452 | "AS-Path hopcount limit attribute\n" |
| 4453 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4454 | ALIAS_DEPRECATED (no_bgp_network_mask, |
| 4455 | no_bgp_network_mask_backdoor_ttl_cmd, |
| 4456 | "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>", |
| 4457 | NO_STR |
| 4458 | "Specify a network to announce via BGP\n" |
| 4459 | "Network number\n" |
| 4460 | "Network mask\n" |
| 4461 | "Network mask\n" |
| 4462 | "Specify a BGP backdoor route\n" |
| 4463 | "AS-Path hopcount limit attribute\n" |
| 4464 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4465 | ALIAS_DEPRECATED (no_bgp_network_mask_natural, |
| 4466 | no_bgp_network_mask_natural_ttl_cmd, |
| 4467 | "no network A.B.C.D pathlimit <0-255>", |
| 4468 | NO_STR |
| 4469 | "Specify a network to announce via BGP\n" |
| 4470 | "Network number\n" |
| 4471 | "AS-Path hopcount limit attribute\n" |
| 4472 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4473 | ALIAS_DEPRECATED (no_bgp_network_mask_natural, |
| 4474 | no_bgp_network_mask_natural_backdoor_ttl_cmd, |
| 4475 | "no network A.B.C.D backdoor pathlimit <0-255>", |
| 4476 | NO_STR |
| 4477 | "Specify a network to announce via BGP\n" |
| 4478 | "Network number\n" |
| 4479 | "Specify a BGP backdoor route\n" |
| 4480 | "AS-Path hopcount limit attribute\n" |
| 4481 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
Paul Jakma | 3bde17f | 2011-03-23 10:30:30 +0000 | [diff] [blame] | 4482 | #ifdef HAVE_IPV6 |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 4483 | ALIAS_DEPRECATED (ipv6_bgp_network, |
| 4484 | ipv6_bgp_network_ttl_cmd, |
| 4485 | "network X:X::X:X/M pathlimit <0-255>", |
| 4486 | "Specify a network to announce via BGP\n" |
| 4487 | "IPv6 prefix <network>/<length>\n" |
| 4488 | "AS-Path hopcount limit attribute\n" |
| 4489 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
| 4490 | ALIAS_DEPRECATED (no_ipv6_bgp_network, |
| 4491 | no_ipv6_bgp_network_ttl_cmd, |
| 4492 | "no network X:X::X:X/M pathlimit <0-255>", |
| 4493 | NO_STR |
| 4494 | "Specify a network to announce via BGP\n" |
| 4495 | "IPv6 prefix <network>/<length>\n" |
| 4496 | "AS-Path hopcount limit attribute\n" |
| 4497 | "AS-Pathlimit TTL, in number of AS-Path hops\n") |
Paul Jakma | 3bde17f | 2011-03-23 10:30:30 +0000 | [diff] [blame] | 4498 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 4499 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4500 | /* Aggreagete address: |
| 4501 | |
| 4502 | advertise-map Set condition to advertise attribute |
| 4503 | as-set Generate AS set path information |
| 4504 | attribute-map Set attributes of aggregate |
| 4505 | route-map Set parameters of aggregate |
| 4506 | summary-only Filter more specific routes from updates |
| 4507 | suppress-map Conditionally filter more specific routes from updates |
| 4508 | <cr> |
| 4509 | */ |
| 4510 | struct bgp_aggregate |
| 4511 | { |
| 4512 | /* Summary-only flag. */ |
| 4513 | u_char summary_only; |
| 4514 | |
| 4515 | /* AS set generation. */ |
| 4516 | u_char as_set; |
| 4517 | |
| 4518 | /* Route-map for aggregated route. */ |
| 4519 | struct route_map *map; |
| 4520 | |
| 4521 | /* Suppress-count. */ |
| 4522 | unsigned long count; |
| 4523 | |
| 4524 | /* SAFI configuration. */ |
| 4525 | safi_t safi; |
| 4526 | }; |
| 4527 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 4528 | static struct bgp_aggregate * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 4529 | bgp_aggregate_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4530 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 4531 | return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4532 | } |
| 4533 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 4534 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4535 | bgp_aggregate_free (struct bgp_aggregate *aggregate) |
| 4536 | { |
| 4537 | XFREE (MTYPE_BGP_AGGREGATE, aggregate); |
| 4538 | } |
| 4539 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 4540 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4541 | bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew, |
| 4542 | afi_t afi, safi_t safi, struct bgp_info *del, |
| 4543 | struct bgp_aggregate *aggregate) |
| 4544 | { |
| 4545 | struct bgp_table *table; |
| 4546 | struct bgp_node *top; |
| 4547 | struct bgp_node *rn; |
| 4548 | u_char origin; |
| 4549 | struct aspath *aspath = NULL; |
| 4550 | struct aspath *asmerge = NULL; |
| 4551 | struct community *community = NULL; |
| 4552 | struct community *commerge = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4553 | struct bgp_info *ri; |
| 4554 | struct bgp_info *new; |
| 4555 | int first = 1; |
| 4556 | unsigned long match = 0; |
| 4557 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4558 | /* ORIGIN attribute: If at least one route among routes that are |
| 4559 | aggregated has ORIGIN with the value INCOMPLETE, then the |
| 4560 | aggregated route must have the ORIGIN attribute with the value |
| 4561 | INCOMPLETE. Otherwise, if at least one route among routes that |
| 4562 | are aggregated has ORIGIN with the value EGP, then the aggregated |
| 4563 | route must have the origin attribute with the value EGP. In all |
| 4564 | other case the value of the ORIGIN attribute of the aggregated |
| 4565 | route is INTERNAL. */ |
| 4566 | origin = BGP_ORIGIN_IGP; |
| 4567 | |
| 4568 | table = bgp->rib[afi][safi]; |
| 4569 | |
| 4570 | top = bgp_node_get (table, p); |
| 4571 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) |
| 4572 | if (rn->p.prefixlen > p->prefixlen) |
| 4573 | { |
| 4574 | match = 0; |
| 4575 | |
| 4576 | for (ri = rn->info; ri; ri = ri->next) |
| 4577 | { |
| 4578 | if (BGP_INFO_HOLDDOWN (ri)) |
| 4579 | continue; |
| 4580 | |
| 4581 | if (del && ri == del) |
| 4582 | continue; |
| 4583 | |
| 4584 | if (! rinew && first) |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 4585 | first = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4586 | |
| 4587 | #ifdef AGGREGATE_NEXTHOP_CHECK |
| 4588 | if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop) |
| 4589 | || ri->attr->med != med) |
| 4590 | { |
| 4591 | if (aspath) |
| 4592 | aspath_free (aspath); |
| 4593 | if (community) |
| 4594 | community_free (community); |
| 4595 | bgp_unlock_node (rn); |
| 4596 | bgp_unlock_node (top); |
| 4597 | return; |
| 4598 | } |
| 4599 | #endif /* AGGREGATE_NEXTHOP_CHECK */ |
| 4600 | |
| 4601 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
| 4602 | { |
| 4603 | if (aggregate->summary_only) |
| 4604 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4605 | (bgp_info_extra_get (ri))->suppress++; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 4606 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4607 | match++; |
| 4608 | } |
| 4609 | |
| 4610 | aggregate->count++; |
| 4611 | |
| 4612 | if (aggregate->as_set) |
| 4613 | { |
| 4614 | if (origin < ri->attr->origin) |
| 4615 | origin = ri->attr->origin; |
| 4616 | |
| 4617 | if (aspath) |
| 4618 | { |
| 4619 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); |
| 4620 | aspath_free (aspath); |
| 4621 | aspath = asmerge; |
| 4622 | } |
| 4623 | else |
| 4624 | aspath = aspath_dup (ri->attr->aspath); |
| 4625 | |
| 4626 | if (ri->attr->community) |
| 4627 | { |
| 4628 | if (community) |
| 4629 | { |
| 4630 | commerge = community_merge (community, |
| 4631 | ri->attr->community); |
| 4632 | community = community_uniq_sort (commerge); |
| 4633 | community_free (commerge); |
| 4634 | } |
| 4635 | else |
| 4636 | community = community_dup (ri->attr->community); |
| 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | } |
| 4641 | if (match) |
| 4642 | bgp_process (bgp, rn, afi, safi); |
| 4643 | } |
| 4644 | bgp_unlock_node (top); |
| 4645 | |
| 4646 | if (rinew) |
| 4647 | { |
| 4648 | aggregate->count++; |
| 4649 | |
| 4650 | if (aggregate->summary_only) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4651 | (bgp_info_extra_get (rinew))->suppress++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4652 | |
| 4653 | if (aggregate->as_set) |
| 4654 | { |
| 4655 | if (origin < rinew->attr->origin) |
| 4656 | origin = rinew->attr->origin; |
| 4657 | |
| 4658 | if (aspath) |
| 4659 | { |
| 4660 | asmerge = aspath_aggregate (aspath, rinew->attr->aspath); |
| 4661 | aspath_free (aspath); |
| 4662 | aspath = asmerge; |
| 4663 | } |
| 4664 | else |
| 4665 | aspath = aspath_dup (rinew->attr->aspath); |
| 4666 | |
| 4667 | if (rinew->attr->community) |
| 4668 | { |
| 4669 | if (community) |
| 4670 | { |
| 4671 | commerge = community_merge (community, |
| 4672 | rinew->attr->community); |
| 4673 | community = community_uniq_sort (commerge); |
| 4674 | community_free (commerge); |
| 4675 | } |
| 4676 | else |
| 4677 | community = community_dup (rinew->attr->community); |
| 4678 | } |
| 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | if (aggregate->count > 0) |
| 4683 | { |
| 4684 | rn = bgp_node_get (table, p); |
| 4685 | new = bgp_info_new (); |
| 4686 | new->type = ZEBRA_ROUTE_BGP; |
| 4687 | new->sub_type = BGP_ROUTE_AGGREGATE; |
| 4688 | new->peer = bgp->peer_self; |
| 4689 | SET_FLAG (new->flags, BGP_INFO_VALID); |
| 4690 | new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set); |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 4691 | new->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4692 | |
| 4693 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 4694 | bgp_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4695 | bgp_process (bgp, rn, afi, safi); |
| 4696 | } |
| 4697 | else |
| 4698 | { |
| 4699 | if (aspath) |
| 4700 | aspath_free (aspath); |
| 4701 | if (community) |
| 4702 | community_free (community); |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t, |
| 4707 | struct bgp_aggregate *); |
| 4708 | |
| 4709 | void |
| 4710 | bgp_aggregate_increment (struct bgp *bgp, struct prefix *p, |
| 4711 | struct bgp_info *ri, afi_t afi, safi_t safi) |
| 4712 | { |
| 4713 | struct bgp_node *child; |
| 4714 | struct bgp_node *rn; |
| 4715 | struct bgp_aggregate *aggregate; |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4716 | struct bgp_table *table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4717 | |
| 4718 | /* MPLS-VPN aggregation is not yet supported. */ |
| 4719 | if (safi == SAFI_MPLS_VPN) |
| 4720 | return; |
| 4721 | |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4722 | table = bgp->aggregate[afi][safi]; |
| 4723 | |
| 4724 | /* No aggregates configured. */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 4725 | if (bgp_table_top_nolock (table) == NULL) |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4726 | return; |
| 4727 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4728 | if (p->prefixlen == 0) |
| 4729 | return; |
| 4730 | |
| 4731 | if (BGP_INFO_HOLDDOWN (ri)) |
| 4732 | return; |
| 4733 | |
Jorge Boncompte [DTI2] | bb782fb | 2012-06-20 16:34:01 +0200 | [diff] [blame] | 4734 | child = bgp_node_get (table, p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4735 | |
| 4736 | /* Aggregate address configuration check. */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 4737 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4738 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
| 4739 | { |
| 4740 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 4741 | bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4742 | } |
| 4743 | bgp_unlock_node (child); |
| 4744 | } |
| 4745 | |
| 4746 | void |
| 4747 | bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p, |
| 4748 | struct bgp_info *del, afi_t afi, safi_t safi) |
| 4749 | { |
| 4750 | struct bgp_node *child; |
| 4751 | struct bgp_node *rn; |
| 4752 | struct bgp_aggregate *aggregate; |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4753 | struct bgp_table *table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4754 | |
| 4755 | /* MPLS-VPN aggregation is not yet supported. */ |
| 4756 | if (safi == SAFI_MPLS_VPN) |
| 4757 | return; |
| 4758 | |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4759 | table = bgp->aggregate[afi][safi]; |
| 4760 | |
| 4761 | /* No aggregates configured. */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 4762 | if (bgp_table_top_nolock (table) == NULL) |
Jorge Boncompte [DTI2] | f018db8 | 2012-05-07 16:53:10 +0000 | [diff] [blame] | 4763 | return; |
| 4764 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4765 | if (p->prefixlen == 0) |
| 4766 | return; |
| 4767 | |
Jorge Boncompte [DTI2] | bb782fb | 2012-06-20 16:34:01 +0200 | [diff] [blame] | 4768 | child = bgp_node_get (table, p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4769 | |
| 4770 | /* Aggregate address configuration check. */ |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 4771 | for (rn = child; rn; rn = bgp_node_parent_nolock (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4772 | if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen) |
| 4773 | { |
| 4774 | bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate); |
paul | 286e1e7 | 2003-08-08 00:24:31 +0000 | [diff] [blame] | 4775 | bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4776 | } |
| 4777 | bgp_unlock_node (child); |
| 4778 | } |
| 4779 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 4780 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4781 | bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi, |
| 4782 | struct bgp_aggregate *aggregate) |
| 4783 | { |
| 4784 | struct bgp_table *table; |
| 4785 | struct bgp_node *top; |
| 4786 | struct bgp_node *rn; |
| 4787 | struct bgp_info *new; |
| 4788 | struct bgp_info *ri; |
| 4789 | unsigned long match; |
| 4790 | u_char origin = BGP_ORIGIN_IGP; |
| 4791 | struct aspath *aspath = NULL; |
| 4792 | struct aspath *asmerge = NULL; |
| 4793 | struct community *community = NULL; |
| 4794 | struct community *commerge = NULL; |
| 4795 | |
| 4796 | table = bgp->rib[afi][safi]; |
| 4797 | |
| 4798 | /* Sanity check. */ |
| 4799 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) |
| 4800 | return; |
| 4801 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) |
| 4802 | return; |
| 4803 | |
| 4804 | /* If routes exists below this node, generate aggregate routes. */ |
| 4805 | top = bgp_node_get (table, p); |
| 4806 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) |
| 4807 | if (rn->p.prefixlen > p->prefixlen) |
| 4808 | { |
| 4809 | match = 0; |
| 4810 | |
| 4811 | for (ri = rn->info; ri; ri = ri->next) |
| 4812 | { |
| 4813 | if (BGP_INFO_HOLDDOWN (ri)) |
| 4814 | continue; |
| 4815 | |
| 4816 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
| 4817 | { |
| 4818 | /* summary-only aggregate route suppress aggregated |
| 4819 | route announcement. */ |
| 4820 | if (aggregate->summary_only) |
| 4821 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4822 | (bgp_info_extra_get (ri))->suppress++; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 4823 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4824 | match++; |
| 4825 | } |
| 4826 | /* as-set aggregate route generate origin, as path, |
| 4827 | community aggregation. */ |
| 4828 | if (aggregate->as_set) |
| 4829 | { |
| 4830 | if (origin < ri->attr->origin) |
| 4831 | origin = ri->attr->origin; |
| 4832 | |
| 4833 | if (aspath) |
| 4834 | { |
| 4835 | asmerge = aspath_aggregate (aspath, ri->attr->aspath); |
| 4836 | aspath_free (aspath); |
| 4837 | aspath = asmerge; |
| 4838 | } |
| 4839 | else |
| 4840 | aspath = aspath_dup (ri->attr->aspath); |
| 4841 | |
| 4842 | if (ri->attr->community) |
| 4843 | { |
| 4844 | if (community) |
| 4845 | { |
| 4846 | commerge = community_merge (community, |
| 4847 | ri->attr->community); |
| 4848 | community = community_uniq_sort (commerge); |
| 4849 | community_free (commerge); |
| 4850 | } |
| 4851 | else |
| 4852 | community = community_dup (ri->attr->community); |
| 4853 | } |
| 4854 | } |
| 4855 | aggregate->count++; |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | /* If this node is suppressed, process the change. */ |
| 4860 | if (match) |
| 4861 | bgp_process (bgp, rn, afi, safi); |
| 4862 | } |
| 4863 | bgp_unlock_node (top); |
| 4864 | |
| 4865 | /* Add aggregate route to BGP table. */ |
| 4866 | if (aggregate->count) |
| 4867 | { |
| 4868 | rn = bgp_node_get (table, p); |
| 4869 | |
| 4870 | new = bgp_info_new (); |
| 4871 | new->type = ZEBRA_ROUTE_BGP; |
| 4872 | new->sub_type = BGP_ROUTE_AGGREGATE; |
| 4873 | new->peer = bgp->peer_self; |
| 4874 | SET_FLAG (new->flags, BGP_INFO_VALID); |
| 4875 | new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set); |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 4876 | new->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4877 | |
| 4878 | bgp_info_add (rn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 4879 | bgp_unlock_node (rn); |
| 4880 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4881 | /* Process change. */ |
| 4882 | bgp_process (bgp, rn, afi, safi); |
| 4883 | } |
| 4884 | } |
| 4885 | |
| 4886 | void |
| 4887 | bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi, |
| 4888 | safi_t safi, struct bgp_aggregate *aggregate) |
| 4889 | { |
| 4890 | struct bgp_table *table; |
| 4891 | struct bgp_node *top; |
| 4892 | struct bgp_node *rn; |
| 4893 | struct bgp_info *ri; |
| 4894 | unsigned long match; |
| 4895 | |
| 4896 | table = bgp->rib[afi][safi]; |
| 4897 | |
| 4898 | if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN) |
| 4899 | return; |
| 4900 | if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN) |
| 4901 | return; |
| 4902 | |
| 4903 | /* If routes exists below this node, generate aggregate routes. */ |
| 4904 | top = bgp_node_get (table, p); |
| 4905 | for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top)) |
| 4906 | if (rn->p.prefixlen > p->prefixlen) |
| 4907 | { |
| 4908 | match = 0; |
| 4909 | |
| 4910 | for (ri = rn->info; ri; ri = ri->next) |
| 4911 | { |
| 4912 | if (BGP_INFO_HOLDDOWN (ri)) |
| 4913 | continue; |
| 4914 | |
| 4915 | if (ri->sub_type != BGP_ROUTE_AGGREGATE) |
| 4916 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4917 | if (aggregate->summary_only && ri->extra) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4918 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4919 | ri->extra->suppress--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4920 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4921 | if (ri->extra->suppress == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4922 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 4923 | bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4924 | match++; |
| 4925 | } |
| 4926 | } |
| 4927 | aggregate->count--; |
| 4928 | } |
| 4929 | } |
| 4930 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 4931 | /* If this node was suppressed, process the change. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4932 | if (match) |
| 4933 | bgp_process (bgp, rn, afi, safi); |
| 4934 | } |
| 4935 | bgp_unlock_node (top); |
| 4936 | |
| 4937 | /* Delete aggregate route from BGP table. */ |
| 4938 | rn = bgp_node_get (table, p); |
| 4939 | |
| 4940 | for (ri = rn->info; ri; ri = ri->next) |
| 4941 | if (ri->peer == bgp->peer_self |
| 4942 | && ri->type == ZEBRA_ROUTE_BGP |
| 4943 | && ri->sub_type == BGP_ROUTE_AGGREGATE) |
| 4944 | break; |
| 4945 | |
| 4946 | /* Withdraw static BGP route from routing table. */ |
| 4947 | if (ri) |
| 4948 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4949 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 4950 | bgp_process (bgp, rn, afi, safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
| 4953 | /* Unlock bgp_node_lookup. */ |
| 4954 | bgp_unlock_node (rn); |
| 4955 | } |
| 4956 | |
| 4957 | /* Aggregate route attribute. */ |
| 4958 | #define AGGREGATE_SUMMARY_ONLY 1 |
| 4959 | #define AGGREGATE_AS_SET 1 |
| 4960 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 4961 | static int |
Robert Bays | f6269b4 | 2010-08-05 10:26:28 -0700 | [diff] [blame] | 4962 | bgp_aggregate_unset (struct vty *vty, const char *prefix_str, |
| 4963 | afi_t afi, safi_t safi) |
| 4964 | { |
| 4965 | int ret; |
| 4966 | struct prefix p; |
| 4967 | struct bgp_node *rn; |
| 4968 | struct bgp *bgp; |
| 4969 | struct bgp_aggregate *aggregate; |
| 4970 | |
| 4971 | /* Convert string to prefix structure. */ |
| 4972 | ret = str2prefix (prefix_str, &p); |
| 4973 | if (!ret) |
| 4974 | { |
| 4975 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 4976 | return CMD_WARNING; |
| 4977 | } |
| 4978 | apply_mask (&p); |
| 4979 | |
| 4980 | /* Get BGP structure. */ |
| 4981 | bgp = vty->index; |
| 4982 | |
| 4983 | /* Old configuration check. */ |
| 4984 | rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p); |
| 4985 | if (! rn) |
| 4986 | { |
| 4987 | vty_out (vty, "%% There is no aggregate-address configuration.%s", |
| 4988 | VTY_NEWLINE); |
| 4989 | return CMD_WARNING; |
| 4990 | } |
| 4991 | |
| 4992 | aggregate = rn->info; |
| 4993 | if (aggregate->safi & SAFI_UNICAST) |
| 4994 | bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate); |
| 4995 | if (aggregate->safi & SAFI_MULTICAST) |
| 4996 | bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate); |
| 4997 | |
| 4998 | /* Unlock aggregate address configuration. */ |
| 4999 | rn->info = NULL; |
| 5000 | bgp_aggregate_free (aggregate); |
| 5001 | bgp_unlock_node (rn); |
| 5002 | bgp_unlock_node (rn); |
| 5003 | |
| 5004 | return CMD_SUCCESS; |
| 5005 | } |
| 5006 | |
| 5007 | static int |
| 5008 | bgp_aggregate_set (struct vty *vty, const char *prefix_str, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 5009 | afi_t afi, safi_t safi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5010 | u_char summary_only, u_char as_set) |
| 5011 | { |
| 5012 | int ret; |
| 5013 | struct prefix p; |
| 5014 | struct bgp_node *rn; |
| 5015 | struct bgp *bgp; |
| 5016 | struct bgp_aggregate *aggregate; |
| 5017 | |
| 5018 | /* Convert string to prefix structure. */ |
| 5019 | ret = str2prefix (prefix_str, &p); |
| 5020 | if (!ret) |
| 5021 | { |
| 5022 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 5023 | return CMD_WARNING; |
| 5024 | } |
| 5025 | apply_mask (&p); |
| 5026 | |
| 5027 | /* Get BGP structure. */ |
| 5028 | bgp = vty->index; |
| 5029 | |
| 5030 | /* Old configuration check. */ |
| 5031 | rn = bgp_node_get (bgp->aggregate[afi][safi], &p); |
| 5032 | |
| 5033 | if (rn->info) |
| 5034 | { |
| 5035 | vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE); |
Robert Bays | 368473f | 2010-08-05 10:26:29 -0700 | [diff] [blame] | 5036 | /* try to remove the old entry */ |
Robert Bays | f6269b4 | 2010-08-05 10:26:28 -0700 | [diff] [blame] | 5037 | ret = bgp_aggregate_unset (vty, prefix_str, afi, safi); |
| 5038 | if (ret) |
| 5039 | { |
Robert Bays | 368473f | 2010-08-05 10:26:29 -0700 | [diff] [blame] | 5040 | vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE); |
| 5041 | bgp_unlock_node (rn); |
Robert Bays | f6269b4 | 2010-08-05 10:26:28 -0700 | [diff] [blame] | 5042 | return CMD_WARNING; |
| 5043 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | /* Make aggregate address structure. */ |
| 5047 | aggregate = bgp_aggregate_new (); |
| 5048 | aggregate->summary_only = summary_only; |
| 5049 | aggregate->as_set = as_set; |
| 5050 | aggregate->safi = safi; |
| 5051 | rn->info = aggregate; |
| 5052 | |
| 5053 | /* Aggregate address insert into BGP routing table. */ |
| 5054 | if (safi & SAFI_UNICAST) |
| 5055 | bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate); |
| 5056 | if (safi & SAFI_MULTICAST) |
| 5057 | bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate); |
| 5058 | |
| 5059 | return CMD_SUCCESS; |
| 5060 | } |
| 5061 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5062 | DEFUN (aggregate_address, |
| 5063 | aggregate_address_cmd, |
| 5064 | "aggregate-address A.B.C.D/M", |
| 5065 | "Configure BGP aggregate entries\n" |
| 5066 | "Aggregate prefix\n") |
| 5067 | { |
| 5068 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0); |
| 5069 | } |
| 5070 | |
| 5071 | DEFUN (aggregate_address_mask, |
| 5072 | aggregate_address_mask_cmd, |
| 5073 | "aggregate-address A.B.C.D A.B.C.D", |
| 5074 | "Configure BGP aggregate entries\n" |
| 5075 | "Aggregate address\n" |
| 5076 | "Aggregate mask\n") |
| 5077 | { |
| 5078 | int ret; |
| 5079 | char prefix_str[BUFSIZ]; |
| 5080 | |
| 5081 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 5082 | |
| 5083 | if (! ret) |
| 5084 | { |
| 5085 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 5086 | return CMD_WARNING; |
| 5087 | } |
| 5088 | |
| 5089 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), |
| 5090 | 0, 0); |
| 5091 | } |
| 5092 | |
| 5093 | DEFUN (aggregate_address_summary_only, |
| 5094 | aggregate_address_summary_only_cmd, |
| 5095 | "aggregate-address A.B.C.D/M summary-only", |
| 5096 | "Configure BGP aggregate entries\n" |
| 5097 | "Aggregate prefix\n" |
| 5098 | "Filter more specific routes from updates\n") |
| 5099 | { |
| 5100 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), |
| 5101 | AGGREGATE_SUMMARY_ONLY, 0); |
| 5102 | } |
| 5103 | |
| 5104 | DEFUN (aggregate_address_mask_summary_only, |
| 5105 | aggregate_address_mask_summary_only_cmd, |
| 5106 | "aggregate-address A.B.C.D A.B.C.D summary-only", |
| 5107 | "Configure BGP aggregate entries\n" |
| 5108 | "Aggregate address\n" |
| 5109 | "Aggregate mask\n" |
| 5110 | "Filter more specific routes from updates\n") |
| 5111 | { |
| 5112 | int ret; |
| 5113 | char prefix_str[BUFSIZ]; |
| 5114 | |
| 5115 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 5116 | |
| 5117 | if (! ret) |
| 5118 | { |
| 5119 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 5120 | return CMD_WARNING; |
| 5121 | } |
| 5122 | |
| 5123 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), |
| 5124 | AGGREGATE_SUMMARY_ONLY, 0); |
| 5125 | } |
| 5126 | |
| 5127 | DEFUN (aggregate_address_as_set, |
| 5128 | aggregate_address_as_set_cmd, |
| 5129 | "aggregate-address A.B.C.D/M as-set", |
| 5130 | "Configure BGP aggregate entries\n" |
| 5131 | "Aggregate prefix\n" |
| 5132 | "Generate AS set path information\n") |
| 5133 | { |
| 5134 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), |
| 5135 | 0, AGGREGATE_AS_SET); |
| 5136 | } |
| 5137 | |
| 5138 | DEFUN (aggregate_address_mask_as_set, |
| 5139 | aggregate_address_mask_as_set_cmd, |
| 5140 | "aggregate-address A.B.C.D A.B.C.D as-set", |
| 5141 | "Configure BGP aggregate entries\n" |
| 5142 | "Aggregate address\n" |
| 5143 | "Aggregate mask\n" |
| 5144 | "Generate AS set path information\n") |
| 5145 | { |
| 5146 | int ret; |
| 5147 | char prefix_str[BUFSIZ]; |
| 5148 | |
| 5149 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 5150 | |
| 5151 | if (! ret) |
| 5152 | { |
| 5153 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 5154 | return CMD_WARNING; |
| 5155 | } |
| 5156 | |
| 5157 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), |
| 5158 | 0, AGGREGATE_AS_SET); |
| 5159 | } |
| 5160 | |
| 5161 | |
| 5162 | DEFUN (aggregate_address_as_set_summary, |
| 5163 | aggregate_address_as_set_summary_cmd, |
| 5164 | "aggregate-address A.B.C.D/M as-set summary-only", |
| 5165 | "Configure BGP aggregate entries\n" |
| 5166 | "Aggregate prefix\n" |
| 5167 | "Generate AS set path information\n" |
| 5168 | "Filter more specific routes from updates\n") |
| 5169 | { |
| 5170 | return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), |
| 5171 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); |
| 5172 | } |
| 5173 | |
| 5174 | ALIAS (aggregate_address_as_set_summary, |
| 5175 | aggregate_address_summary_as_set_cmd, |
| 5176 | "aggregate-address A.B.C.D/M summary-only as-set", |
| 5177 | "Configure BGP aggregate entries\n" |
| 5178 | "Aggregate prefix\n" |
| 5179 | "Filter more specific routes from updates\n" |
| 5180 | "Generate AS set path information\n") |
| 5181 | |
| 5182 | DEFUN (aggregate_address_mask_as_set_summary, |
| 5183 | aggregate_address_mask_as_set_summary_cmd, |
| 5184 | "aggregate-address A.B.C.D A.B.C.D as-set summary-only", |
| 5185 | "Configure BGP aggregate entries\n" |
| 5186 | "Aggregate address\n" |
| 5187 | "Aggregate mask\n" |
| 5188 | "Generate AS set path information\n" |
| 5189 | "Filter more specific routes from updates\n") |
| 5190 | { |
| 5191 | int ret; |
| 5192 | char prefix_str[BUFSIZ]; |
| 5193 | |
| 5194 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 5195 | |
| 5196 | if (! ret) |
| 5197 | { |
| 5198 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 5199 | return CMD_WARNING; |
| 5200 | } |
| 5201 | |
| 5202 | return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty), |
| 5203 | AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET); |
| 5204 | } |
| 5205 | |
| 5206 | ALIAS (aggregate_address_mask_as_set_summary, |
| 5207 | aggregate_address_mask_summary_as_set_cmd, |
| 5208 | "aggregate-address A.B.C.D A.B.C.D summary-only as-set", |
| 5209 | "Configure BGP aggregate entries\n" |
| 5210 | "Aggregate address\n" |
| 5211 | "Aggregate mask\n" |
| 5212 | "Filter more specific routes from updates\n" |
| 5213 | "Generate AS set path information\n") |
| 5214 | |
| 5215 | DEFUN (no_aggregate_address, |
| 5216 | no_aggregate_address_cmd, |
| 5217 | "no aggregate-address A.B.C.D/M", |
| 5218 | NO_STR |
| 5219 | "Configure BGP aggregate entries\n" |
| 5220 | "Aggregate prefix\n") |
| 5221 | { |
| 5222 | return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty)); |
| 5223 | } |
| 5224 | |
| 5225 | ALIAS (no_aggregate_address, |
| 5226 | no_aggregate_address_summary_only_cmd, |
| 5227 | "no aggregate-address A.B.C.D/M summary-only", |
| 5228 | NO_STR |
| 5229 | "Configure BGP aggregate entries\n" |
| 5230 | "Aggregate prefix\n" |
| 5231 | "Filter more specific routes from updates\n") |
| 5232 | |
| 5233 | ALIAS (no_aggregate_address, |
| 5234 | no_aggregate_address_as_set_cmd, |
| 5235 | "no aggregate-address A.B.C.D/M as-set", |
| 5236 | NO_STR |
| 5237 | "Configure BGP aggregate entries\n" |
| 5238 | "Aggregate prefix\n" |
| 5239 | "Generate AS set path information\n") |
| 5240 | |
| 5241 | ALIAS (no_aggregate_address, |
| 5242 | no_aggregate_address_as_set_summary_cmd, |
| 5243 | "no aggregate-address A.B.C.D/M as-set summary-only", |
| 5244 | NO_STR |
| 5245 | "Configure BGP aggregate entries\n" |
| 5246 | "Aggregate prefix\n" |
| 5247 | "Generate AS set path information\n" |
| 5248 | "Filter more specific routes from updates\n") |
| 5249 | |
| 5250 | ALIAS (no_aggregate_address, |
| 5251 | no_aggregate_address_summary_as_set_cmd, |
| 5252 | "no aggregate-address A.B.C.D/M summary-only as-set", |
| 5253 | NO_STR |
| 5254 | "Configure BGP aggregate entries\n" |
| 5255 | "Aggregate prefix\n" |
| 5256 | "Filter more specific routes from updates\n" |
| 5257 | "Generate AS set path information\n") |
| 5258 | |
| 5259 | DEFUN (no_aggregate_address_mask, |
| 5260 | no_aggregate_address_mask_cmd, |
| 5261 | "no aggregate-address A.B.C.D A.B.C.D", |
| 5262 | NO_STR |
| 5263 | "Configure BGP aggregate entries\n" |
| 5264 | "Aggregate address\n" |
| 5265 | "Aggregate mask\n") |
| 5266 | { |
| 5267 | int ret; |
| 5268 | char prefix_str[BUFSIZ]; |
| 5269 | |
| 5270 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 5271 | |
| 5272 | if (! ret) |
| 5273 | { |
| 5274 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 5275 | return CMD_WARNING; |
| 5276 | } |
| 5277 | |
| 5278 | return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty)); |
| 5279 | } |
| 5280 | |
| 5281 | ALIAS (no_aggregate_address_mask, |
| 5282 | no_aggregate_address_mask_summary_only_cmd, |
| 5283 | "no aggregate-address A.B.C.D A.B.C.D summary-only", |
| 5284 | NO_STR |
| 5285 | "Configure BGP aggregate entries\n" |
| 5286 | "Aggregate address\n" |
| 5287 | "Aggregate mask\n" |
| 5288 | "Filter more specific routes from updates\n") |
| 5289 | |
| 5290 | ALIAS (no_aggregate_address_mask, |
| 5291 | no_aggregate_address_mask_as_set_cmd, |
| 5292 | "no aggregate-address A.B.C.D A.B.C.D as-set", |
| 5293 | NO_STR |
| 5294 | "Configure BGP aggregate entries\n" |
| 5295 | "Aggregate address\n" |
| 5296 | "Aggregate mask\n" |
| 5297 | "Generate AS set path information\n") |
| 5298 | |
| 5299 | ALIAS (no_aggregate_address_mask, |
| 5300 | no_aggregate_address_mask_as_set_summary_cmd, |
| 5301 | "no aggregate-address A.B.C.D A.B.C.D as-set summary-only", |
| 5302 | NO_STR |
| 5303 | "Configure BGP aggregate entries\n" |
| 5304 | "Aggregate address\n" |
| 5305 | "Aggregate mask\n" |
| 5306 | "Generate AS set path information\n" |
| 5307 | "Filter more specific routes from updates\n") |
| 5308 | |
| 5309 | ALIAS (no_aggregate_address_mask, |
| 5310 | no_aggregate_address_mask_summary_as_set_cmd, |
| 5311 | "no aggregate-address A.B.C.D A.B.C.D summary-only as-set", |
| 5312 | NO_STR |
| 5313 | "Configure BGP aggregate entries\n" |
| 5314 | "Aggregate address\n" |
| 5315 | "Aggregate mask\n" |
| 5316 | "Filter more specific routes from updates\n" |
| 5317 | "Generate AS set path information\n") |
| 5318 | |
| 5319 | #ifdef HAVE_IPV6 |
| 5320 | DEFUN (ipv6_aggregate_address, |
| 5321 | ipv6_aggregate_address_cmd, |
| 5322 | "aggregate-address X:X::X:X/M", |
| 5323 | "Configure BGP aggregate entries\n" |
| 5324 | "Aggregate prefix\n") |
| 5325 | { |
| 5326 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0); |
| 5327 | } |
| 5328 | |
| 5329 | DEFUN (ipv6_aggregate_address_summary_only, |
| 5330 | ipv6_aggregate_address_summary_only_cmd, |
| 5331 | "aggregate-address X:X::X:X/M summary-only", |
| 5332 | "Configure BGP aggregate entries\n" |
| 5333 | "Aggregate prefix\n" |
| 5334 | "Filter more specific routes from updates\n") |
| 5335 | { |
| 5336 | return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 5337 | AGGREGATE_SUMMARY_ONLY, 0); |
| 5338 | } |
| 5339 | |
| 5340 | DEFUN (no_ipv6_aggregate_address, |
| 5341 | no_ipv6_aggregate_address_cmd, |
| 5342 | "no aggregate-address X:X::X:X/M", |
| 5343 | NO_STR |
| 5344 | "Configure BGP aggregate entries\n" |
| 5345 | "Aggregate prefix\n") |
| 5346 | { |
| 5347 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); |
| 5348 | } |
| 5349 | |
| 5350 | DEFUN (no_ipv6_aggregate_address_summary_only, |
| 5351 | no_ipv6_aggregate_address_summary_only_cmd, |
| 5352 | "no aggregate-address X:X::X:X/M summary-only", |
| 5353 | NO_STR |
| 5354 | "Configure BGP aggregate entries\n" |
| 5355 | "Aggregate prefix\n" |
| 5356 | "Filter more specific routes from updates\n") |
| 5357 | { |
| 5358 | return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST); |
| 5359 | } |
| 5360 | |
| 5361 | ALIAS (ipv6_aggregate_address, |
| 5362 | old_ipv6_aggregate_address_cmd, |
| 5363 | "ipv6 bgp aggregate-address X:X::X:X/M", |
| 5364 | IPV6_STR |
| 5365 | BGP_STR |
| 5366 | "Configure BGP aggregate entries\n" |
| 5367 | "Aggregate prefix\n") |
| 5368 | |
| 5369 | ALIAS (ipv6_aggregate_address_summary_only, |
| 5370 | old_ipv6_aggregate_address_summary_only_cmd, |
| 5371 | "ipv6 bgp aggregate-address X:X::X:X/M summary-only", |
| 5372 | IPV6_STR |
| 5373 | BGP_STR |
| 5374 | "Configure BGP aggregate entries\n" |
| 5375 | "Aggregate prefix\n" |
| 5376 | "Filter more specific routes from updates\n") |
| 5377 | |
| 5378 | ALIAS (no_ipv6_aggregate_address, |
| 5379 | old_no_ipv6_aggregate_address_cmd, |
| 5380 | "no ipv6 bgp aggregate-address X:X::X:X/M", |
| 5381 | NO_STR |
| 5382 | IPV6_STR |
| 5383 | BGP_STR |
| 5384 | "Configure BGP aggregate entries\n" |
| 5385 | "Aggregate prefix\n") |
| 5386 | |
| 5387 | ALIAS (no_ipv6_aggregate_address_summary_only, |
| 5388 | old_no_ipv6_aggregate_address_summary_only_cmd, |
| 5389 | "no ipv6 bgp aggregate-address X:X::X:X/M summary-only", |
| 5390 | NO_STR |
| 5391 | IPV6_STR |
| 5392 | BGP_STR |
| 5393 | "Configure BGP aggregate entries\n" |
| 5394 | "Aggregate prefix\n" |
| 5395 | "Filter more specific routes from updates\n") |
| 5396 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 5397 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5398 | /* Redistribute route treatment. */ |
| 5399 | void |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 5400 | bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop, |
| 5401 | const struct in6_addr *nexthop6, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5402 | u_int32_t metric, u_char type) |
| 5403 | { |
| 5404 | struct bgp *bgp; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 5405 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5406 | struct bgp_info *new; |
| 5407 | struct bgp_info *bi; |
| 5408 | struct bgp_info info; |
| 5409 | struct bgp_node *bn; |
Jorge Boncompte [DTI2] | e16a413 | 2012-05-07 16:52:57 +0000 | [diff] [blame] | 5410 | struct attr attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5411 | struct attr *new_attr; |
| 5412 | afi_t afi; |
| 5413 | int ret; |
| 5414 | |
| 5415 | /* Make default attribute. */ |
| 5416 | bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE); |
| 5417 | if (nexthop) |
| 5418 | attr.nexthop = *nexthop; |
| 5419 | |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 5420 | #ifdef HAVE_IPV6 |
| 5421 | if (nexthop6) |
| 5422 | { |
| 5423 | struct attr_extra *extra = bgp_attr_extra_get(&attr); |
| 5424 | extra->mp_nexthop_global = *nexthop6; |
| 5425 | extra->mp_nexthop_len = 16; |
| 5426 | } |
| 5427 | #endif |
| 5428 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5429 | attr.med = metric; |
| 5430 | attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); |
| 5431 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 5432 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5433 | { |
| 5434 | afi = family2afi (p->family); |
| 5435 | |
| 5436 | if (bgp->redist[afi][type]) |
| 5437 | { |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 5438 | struct attr attr_new; |
| 5439 | struct attr_extra extra_new; |
| 5440 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5441 | /* Copy attribute for modification. */ |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 5442 | attr_new.extra = &extra_new; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5443 | bgp_attr_dup (&attr_new, &attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5444 | |
| 5445 | if (bgp->redist_metric_flag[afi][type]) |
| 5446 | attr_new.med = bgp->redist_metric[afi][type]; |
| 5447 | |
| 5448 | /* Apply route-map. */ |
| 5449 | if (bgp->rmap[afi][type].map) |
| 5450 | { |
| 5451 | info.peer = bgp->peer_self; |
| 5452 | info.attr = &attr_new; |
| 5453 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 5454 | SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE); |
| 5455 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5456 | ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP, |
| 5457 | &info); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 5458 | |
| 5459 | bgp->peer_self->rmap_type = 0; |
| 5460 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5461 | if (ret == RMAP_DENYMATCH) |
| 5462 | { |
| 5463 | /* Free uninterned attribute. */ |
| 5464 | bgp_attr_flush (&attr_new); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 5465 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5466 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 5467 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5468 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5469 | bgp_redistribute_delete (p, type); |
| 5470 | return; |
| 5471 | } |
| 5472 | } |
| 5473 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5474 | bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], |
| 5475 | afi, SAFI_UNICAST, p, NULL); |
| 5476 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5477 | new_attr = bgp_attr_intern (&attr_new); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 5478 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5479 | for (bi = bn->info; bi; bi = bi->next) |
| 5480 | if (bi->peer == bgp->peer_self |
| 5481 | && bi->sub_type == BGP_ROUTE_REDISTRIBUTE) |
| 5482 | break; |
| 5483 | |
| 5484 | if (bi) |
| 5485 | { |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 5486 | if (attrhash_cmp (bi->attr, new_attr) && |
| 5487 | !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5488 | { |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 5489 | bgp_attr_unintern (&new_attr); |
| 5490 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5491 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5492 | bgp_unlock_node (bn); |
| 5493 | return; |
| 5494 | } |
| 5495 | else |
| 5496 | { |
| 5497 | /* The attribute is changed. */ |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 5498 | bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5499 | |
| 5500 | /* Rewrite BGP route information. */ |
Andrew J. Schorr | 8d45210 | 2006-11-28 19:50:46 +0000 | [diff] [blame] | 5501 | if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) |
| 5502 | bgp_info_restore(bn, bi); |
| 5503 | else |
| 5504 | bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 5505 | bgp_attr_unintern (&bi->attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5506 | bi->attr = new_attr; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 5507 | bi->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5508 | |
| 5509 | /* Process change. */ |
| 5510 | bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST); |
| 5511 | bgp_process (bgp, bn, afi, SAFI_UNICAST); |
| 5512 | bgp_unlock_node (bn); |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 5513 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5514 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5515 | return; |
| 5516 | } |
| 5517 | } |
| 5518 | |
| 5519 | new = bgp_info_new (); |
| 5520 | new->type = type; |
| 5521 | new->sub_type = BGP_ROUTE_REDISTRIBUTE; |
| 5522 | new->peer = bgp->peer_self; |
| 5523 | SET_FLAG (new->flags, BGP_INFO_VALID); |
| 5524 | new->attr = new_attr; |
Stephen Hemminger | 6595788 | 2010-01-15 16:22:10 +0300 | [diff] [blame] | 5525 | new->uptime = bgp_clock (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5526 | |
| 5527 | bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST); |
| 5528 | bgp_info_add (bn, new); |
paul | 200df11 | 2005-06-01 11:17:05 +0000 | [diff] [blame] | 5529 | bgp_unlock_node (bn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5530 | bgp_process (bgp, bn, afi, SAFI_UNICAST); |
| 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | /* Unintern original. */ |
Paul Jakma | f6f434b | 2010-11-23 21:28:03 +0000 | [diff] [blame] | 5535 | aspath_unintern (&attr.aspath); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5536 | bgp_attr_extra_free (&attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | void |
| 5540 | bgp_redistribute_delete (struct prefix *p, u_char type) |
| 5541 | { |
| 5542 | struct bgp *bgp; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 5543 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5544 | afi_t afi; |
| 5545 | struct bgp_node *rn; |
| 5546 | struct bgp_info *ri; |
| 5547 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 5548 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5549 | { |
| 5550 | afi = family2afi (p->family); |
| 5551 | |
| 5552 | if (bgp->redist[afi][type]) |
| 5553 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 5554 | rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5555 | |
| 5556 | for (ri = rn->info; ri; ri = ri->next) |
| 5557 | if (ri->peer == bgp->peer_self |
| 5558 | && ri->type == type) |
| 5559 | break; |
| 5560 | |
| 5561 | if (ri) |
| 5562 | { |
| 5563 | bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5564 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 5565 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5566 | } |
| 5567 | bgp_unlock_node (rn); |
| 5568 | } |
| 5569 | } |
| 5570 | } |
| 5571 | |
| 5572 | /* Withdraw specified route type's route. */ |
| 5573 | void |
| 5574 | bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type) |
| 5575 | { |
| 5576 | struct bgp_node *rn; |
| 5577 | struct bgp_info *ri; |
| 5578 | struct bgp_table *table; |
| 5579 | |
| 5580 | table = bgp->rib[afi][SAFI_UNICAST]; |
| 5581 | |
| 5582 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 5583 | { |
| 5584 | for (ri = rn->info; ri; ri = ri->next) |
| 5585 | if (ri->peer == bgp->peer_self |
| 5586 | && ri->type == type) |
| 5587 | break; |
| 5588 | |
| 5589 | if (ri) |
| 5590 | { |
| 5591 | bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5592 | bgp_info_delete (rn, ri); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 5593 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5594 | } |
| 5595 | } |
| 5596 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 5597 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5598 | /* Static function to display route. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 5599 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5600 | route_vty_out_route (struct prefix *p, struct vty *vty) |
| 5601 | { |
| 5602 | int len; |
| 5603 | u_int32_t destination; |
| 5604 | char buf[BUFSIZ]; |
| 5605 | |
| 5606 | if (p->family == AF_INET) |
| 5607 | { |
| 5608 | len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ)); |
| 5609 | destination = ntohl (p->u.prefix4.s_addr); |
| 5610 | |
| 5611 | if ((IN_CLASSC (destination) && p->prefixlen == 24) |
| 5612 | || (IN_CLASSB (destination) && p->prefixlen == 16) |
| 5613 | || (IN_CLASSA (destination) && p->prefixlen == 8) |
| 5614 | || p->u.prefix4.s_addr == 0) |
| 5615 | { |
| 5616 | /* When mask is natural, mask is not displayed. */ |
| 5617 | } |
| 5618 | else |
| 5619 | len += vty_out (vty, "/%d", p->prefixlen); |
| 5620 | } |
| 5621 | else |
| 5622 | len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), |
| 5623 | p->prefixlen); |
| 5624 | |
| 5625 | len = 17 - len; |
| 5626 | if (len < 1) |
| 5627 | vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " "); |
| 5628 | else |
| 5629 | vty_out (vty, "%*s", len, " "); |
| 5630 | } |
| 5631 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5632 | enum bgp_display_type |
| 5633 | { |
| 5634 | normal_list, |
| 5635 | }; |
| 5636 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5637 | /* Print the short form route status for a bgp_info */ |
| 5638 | static void |
| 5639 | route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5640 | { |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5641 | /* Route status display. */ |
| 5642 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) |
| 5643 | vty_out (vty, "R"); |
| 5644 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 5645 | vty_out (vty, "S"); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5646 | else if (binfo->extra && binfo->extra->suppress) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5647 | vty_out (vty, "s"); |
| 5648 | else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
| 5649 | vty_out (vty, "*"); |
| 5650 | else |
| 5651 | vty_out (vty, " "); |
| 5652 | |
| 5653 | /* Selected */ |
| 5654 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
| 5655 | vty_out (vty, "h"); |
| 5656 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) |
| 5657 | vty_out (vty, "d"); |
| 5658 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) |
| 5659 | vty_out (vty, ">"); |
Boian Bonev | b366b51 | 2013-09-09 16:41:35 +0000 | [diff] [blame] | 5660 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH)) |
| 5661 | vty_out (vty, "="); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5662 | else |
| 5663 | vty_out (vty, " "); |
| 5664 | |
| 5665 | /* Internal route. */ |
| 5666 | if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as)) |
| 5667 | vty_out (vty, "i"); |
| 5668 | else |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5669 | vty_out (vty, " "); |
| 5670 | } |
| 5671 | |
| 5672 | /* called from terminal list command */ |
| 5673 | void |
| 5674 | route_vty_out (struct vty *vty, struct prefix *p, |
| 5675 | struct bgp_info *binfo, int display, safi_t safi) |
| 5676 | { |
| 5677 | struct attr *attr; |
| 5678 | |
| 5679 | /* short status lead text */ |
| 5680 | route_vty_short_status_out (vty, binfo); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5681 | |
| 5682 | /* print prefix and mask */ |
| 5683 | if (! display) |
| 5684 | route_vty_out_route (p, vty); |
| 5685 | else |
| 5686 | vty_out (vty, "%*s", 17, " "); |
| 5687 | |
| 5688 | /* Print attribute */ |
| 5689 | attr = binfo->attr; |
| 5690 | if (attr) |
| 5691 | { |
| 5692 | if (p->family == AF_INET) |
| 5693 | { |
| 5694 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5695 | vty_out (vty, "%-16s", |
| 5696 | inet_ntoa (attr->extra->mp_nexthop_global_in)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5697 | else |
| 5698 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); |
| 5699 | } |
| 5700 | #ifdef HAVE_IPV6 |
| 5701 | else if (p->family == AF_INET6) |
| 5702 | { |
| 5703 | int len; |
| 5704 | char buf[BUFSIZ]; |
| 5705 | |
| 5706 | len = vty_out (vty, "%s", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5707 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
| 5708 | buf, BUFSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5709 | len = 16 - len; |
| 5710 | if (len < 1) |
| 5711 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); |
| 5712 | else |
| 5713 | vty_out (vty, "%*s", len, " "); |
| 5714 | } |
| 5715 | #endif /* HAVE_IPV6 */ |
| 5716 | |
| 5717 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 5718 | vty_out (vty, "%10u", attr->med); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5719 | else |
| 5720 | vty_out (vty, " "); |
| 5721 | |
| 5722 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 5723 | vty_out (vty, "%7u", attr->local_pref); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5724 | else |
| 5725 | vty_out (vty, " "); |
| 5726 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5727 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5728 | |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5729 | /* Print aspath */ |
| 5730 | if (attr->aspath) |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 5731 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5732 | |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5733 | /* Print origin */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5734 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5735 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5736 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | /* called from terminal list command */ |
| 5740 | void |
| 5741 | route_vty_out_tmp (struct vty *vty, struct prefix *p, |
| 5742 | struct attr *attr, safi_t safi) |
| 5743 | { |
| 5744 | /* Route status display. */ |
| 5745 | vty_out (vty, "*"); |
| 5746 | vty_out (vty, ">"); |
| 5747 | vty_out (vty, " "); |
| 5748 | |
| 5749 | /* print prefix and mask */ |
| 5750 | route_vty_out_route (p, vty); |
| 5751 | |
| 5752 | /* Print attribute */ |
| 5753 | if (attr) |
| 5754 | { |
| 5755 | if (p->family == AF_INET) |
| 5756 | { |
| 5757 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5758 | vty_out (vty, "%-16s", |
| 5759 | inet_ntoa (attr->extra->mp_nexthop_global_in)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5760 | else |
| 5761 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); |
| 5762 | } |
| 5763 | #ifdef HAVE_IPV6 |
| 5764 | else if (p->family == AF_INET6) |
| 5765 | { |
| 5766 | int len; |
| 5767 | char buf[BUFSIZ]; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5768 | |
| 5769 | assert (attr->extra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5770 | |
| 5771 | len = vty_out (vty, "%s", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5772 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
| 5773 | buf, BUFSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5774 | len = 16 - len; |
| 5775 | if (len < 1) |
| 5776 | vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " "); |
| 5777 | else |
| 5778 | vty_out (vty, "%*s", len, " "); |
| 5779 | } |
| 5780 | #endif /* HAVE_IPV6 */ |
| 5781 | |
| 5782 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 5783 | vty_out (vty, "%10u", attr->med); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5784 | else |
| 5785 | vty_out (vty, " "); |
| 5786 | |
| 5787 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 5788 | vty_out (vty, "%7u", attr->local_pref); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5789 | else |
| 5790 | vty_out (vty, " "); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5791 | |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 5792 | vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0)); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5793 | |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5794 | /* Print aspath */ |
| 5795 | if (attr->aspath) |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 5796 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5797 | |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5798 | /* Print origin */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5799 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5800 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5801 | |
| 5802 | vty_out (vty, "%s", VTY_NEWLINE); |
| 5803 | } |
| 5804 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 5805 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5806 | route_vty_out_tag (struct vty *vty, struct prefix *p, |
| 5807 | struct bgp_info *binfo, int display, safi_t safi) |
| 5808 | { |
| 5809 | struct attr *attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5810 | u_int32_t label = 0; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5811 | |
| 5812 | if (!binfo->extra) |
| 5813 | return; |
| 5814 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5815 | /* short status lead text */ |
| 5816 | route_vty_short_status_out (vty, binfo); |
| 5817 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5818 | /* print prefix and mask */ |
| 5819 | if (! display) |
| 5820 | route_vty_out_route (p, vty); |
| 5821 | else |
| 5822 | vty_out (vty, "%*s", 17, " "); |
| 5823 | |
| 5824 | /* Print attribute */ |
| 5825 | attr = binfo->attr; |
| 5826 | if (attr) |
| 5827 | { |
| 5828 | if (p->family == AF_INET) |
| 5829 | { |
| 5830 | if (safi == SAFI_MPLS_VPN) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5831 | vty_out (vty, "%-16s", |
| 5832 | inet_ntoa (attr->extra->mp_nexthop_global_in)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5833 | else |
| 5834 | vty_out (vty, "%-16s", inet_ntoa (attr->nexthop)); |
| 5835 | } |
| 5836 | #ifdef HAVE_IPV6 |
| 5837 | else if (p->family == AF_INET6) |
| 5838 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5839 | assert (attr->extra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5840 | char buf[BUFSIZ]; |
| 5841 | char buf1[BUFSIZ]; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5842 | if (attr->extra->mp_nexthop_len == 16) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5843 | vty_out (vty, "%s", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5844 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
| 5845 | buf, BUFSIZ)); |
| 5846 | else if (attr->extra->mp_nexthop_len == 32) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5847 | vty_out (vty, "%s(%s)", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5848 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
| 5849 | buf, BUFSIZ), |
| 5850 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, |
| 5851 | buf1, BUFSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5852 | |
| 5853 | } |
| 5854 | #endif /* HAVE_IPV6 */ |
| 5855 | } |
| 5856 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5857 | label = decode_label (binfo->extra->tag); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5858 | |
| 5859 | vty_out (vty, "notag/%d", label); |
| 5860 | |
| 5861 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | /* dampening route */ |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 5865 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5866 | damp_route_vty_out (struct vty *vty, struct prefix *p, |
| 5867 | struct bgp_info *binfo, int display, safi_t safi) |
| 5868 | { |
| 5869 | struct attr *attr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5870 | int len; |
Chris Caputo | 50aef6f | 2009-06-23 06:06:49 +0000 | [diff] [blame] | 5871 | char timebuf[BGP_UPTIME_LEN]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5872 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5873 | /* short status lead text */ |
| 5874 | route_vty_short_status_out (vty, binfo); |
| 5875 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5876 | /* print prefix and mask */ |
| 5877 | if (! display) |
| 5878 | route_vty_out_route (p, vty); |
| 5879 | else |
| 5880 | vty_out (vty, "%*s", 17, " "); |
| 5881 | |
| 5882 | len = vty_out (vty, "%s", binfo->peer->host); |
| 5883 | len = 17 - len; |
| 5884 | if (len < 1) |
| 5885 | vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " "); |
| 5886 | else |
| 5887 | vty_out (vty, "%*s", len, " "); |
| 5888 | |
Chris Caputo | 50aef6f | 2009-06-23 06:06:49 +0000 | [diff] [blame] | 5889 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5890 | |
| 5891 | /* Print attribute */ |
| 5892 | attr = binfo->attr; |
| 5893 | if (attr) |
| 5894 | { |
| 5895 | /* Print aspath */ |
| 5896 | if (attr->aspath) |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 5897 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5898 | |
| 5899 | /* Print origin */ |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5900 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5901 | } |
| 5902 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5903 | } |
| 5904 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5905 | /* flap route */ |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 5906 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5907 | flap_route_vty_out (struct vty *vty, struct prefix *p, |
| 5908 | struct bgp_info *binfo, int display, safi_t safi) |
| 5909 | { |
| 5910 | struct attr *attr; |
| 5911 | struct bgp_damp_info *bdi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5912 | char timebuf[BGP_UPTIME_LEN]; |
| 5913 | int len; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5914 | |
| 5915 | if (!binfo->extra) |
| 5916 | return; |
| 5917 | |
| 5918 | bdi = binfo->extra->damp_info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5919 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5920 | /* short status lead text */ |
| 5921 | route_vty_short_status_out (vty, binfo); |
| 5922 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5923 | /* print prefix and mask */ |
| 5924 | if (! display) |
| 5925 | route_vty_out_route (p, vty); |
| 5926 | else |
| 5927 | vty_out (vty, "%*s", 17, " "); |
| 5928 | |
| 5929 | len = vty_out (vty, "%s", binfo->peer->host); |
| 5930 | len = 16 - len; |
| 5931 | if (len < 1) |
| 5932 | vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " "); |
| 5933 | else |
| 5934 | vty_out (vty, "%*s", len, " "); |
| 5935 | |
| 5936 | len = vty_out (vty, "%d", bdi->flap); |
| 5937 | len = 5 - len; |
| 5938 | if (len < 1) |
| 5939 | vty_out (vty, " "); |
| 5940 | else |
| 5941 | vty_out (vty, "%*s ", len, " "); |
| 5942 | |
| 5943 | vty_out (vty, "%s ", peer_uptime (bdi->start_time, |
| 5944 | timebuf, BGP_UPTIME_LEN)); |
| 5945 | |
| 5946 | if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED) |
| 5947 | && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
Chris Caputo | 50aef6f | 2009-06-23 06:06:49 +0000 | [diff] [blame] | 5948 | vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5949 | else |
| 5950 | vty_out (vty, "%*s ", 8, " "); |
| 5951 | |
| 5952 | /* Print attribute */ |
| 5953 | attr = binfo->attr; |
| 5954 | if (attr) |
| 5955 | { |
| 5956 | /* Print aspath */ |
| 5957 | if (attr->aspath) |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 5958 | aspath_print_vty (vty, "%s", attr->aspath, " "); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5959 | |
| 5960 | /* Print origin */ |
Paul Jakma | b2518c1 | 2006-05-12 23:48:40 +0000 | [diff] [blame] | 5961 | vty_out (vty, "%s", bgp_origin_str[attr->origin]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5962 | } |
| 5963 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 5966 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5967 | route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p, |
| 5968 | struct bgp_info *binfo, afi_t afi, safi_t safi) |
| 5969 | { |
| 5970 | char buf[INET6_ADDRSTRLEN]; |
| 5971 | char buf1[BUFSIZ]; |
| 5972 | struct attr *attr; |
| 5973 | int sockunion_vty_out (struct vty *, union sockunion *); |
John Kemp | 30b0017 | 2011-03-18 17:52:18 +0300 | [diff] [blame] | 5974 | #ifdef HAVE_CLOCK_MONOTONIC |
| 5975 | time_t tbuf; |
| 5976 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5977 | |
| 5978 | attr = binfo->attr; |
| 5979 | |
| 5980 | if (attr) |
| 5981 | { |
| 5982 | /* Line1 display AS-path, Aggregator */ |
| 5983 | if (attr->aspath) |
| 5984 | { |
| 5985 | vty_out (vty, " "); |
paul | fe69a50 | 2005-09-10 16:55:02 +0000 | [diff] [blame] | 5986 | if (aspath_count_hops (attr->aspath) == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5987 | vty_out (vty, "Local"); |
| 5988 | else |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 5989 | aspath_print_vty (vty, "%s", attr->aspath, ""); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
paul | b40d939 | 2005-08-22 22:34:41 +0000 | [diff] [blame] | 5992 | if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED)) |
| 5993 | vty_out (vty, ", (removed)"); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 5994 | if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE)) |
| 5995 | vty_out (vty, ", (stale)"); |
| 5996 | if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR))) |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 5997 | vty_out (vty, ", (aggregated by %u %s)", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 5998 | attr->extra->aggregator_as, |
| 5999 | inet_ntoa (attr->extra->aggregator_addr)); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 6000 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) |
| 6001 | vty_out (vty, ", (Received from a RR-client)"); |
| 6002 | if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) |
| 6003 | vty_out (vty, ", (Received from a RS-client)"); |
| 6004 | if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
| 6005 | vty_out (vty, ", (history entry)"); |
| 6006 | else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)) |
| 6007 | vty_out (vty, ", (suppressed due to dampening)"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6008 | vty_out (vty, "%s", VTY_NEWLINE); |
| 6009 | |
| 6010 | /* Line2 display Next-hop, Neighbor, Router-id */ |
| 6011 | if (p->family == AF_INET) |
| 6012 | { |
| 6013 | vty_out (vty, " %s", safi == SAFI_MPLS_VPN ? |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6014 | inet_ntoa (attr->extra->mp_nexthop_global_in) : |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6015 | inet_ntoa (attr->nexthop)); |
| 6016 | } |
| 6017 | #ifdef HAVE_IPV6 |
| 6018 | else |
| 6019 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6020 | assert (attr->extra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6021 | vty_out (vty, " %s", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6022 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6023 | buf, INET6_ADDRSTRLEN)); |
| 6024 | } |
| 6025 | #endif /* HAVE_IPV6 */ |
| 6026 | |
| 6027 | if (binfo->peer == bgp->peer_self) |
| 6028 | { |
| 6029 | vty_out (vty, " from %s ", |
| 6030 | p->family == AF_INET ? "0.0.0.0" : "::"); |
| 6031 | vty_out (vty, "(%s)", inet_ntoa(bgp->router_id)); |
| 6032 | } |
| 6033 | else |
| 6034 | { |
| 6035 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID)) |
| 6036 | vty_out (vty, " (inaccessible)"); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6037 | else if (binfo->extra && binfo->extra->igpmetric) |
Jorge Boncompte [DTI2] | ddc943d | 2012-04-13 13:46:07 +0200 | [diff] [blame] | 6038 | vty_out (vty, " (metric %u)", binfo->extra->igpmetric); |
paul | eb82118 | 2004-05-01 08:44:08 +0000 | [diff] [blame] | 6039 | vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6040 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6041 | vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6042 | else |
| 6043 | vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ)); |
| 6044 | } |
| 6045 | vty_out (vty, "%s", VTY_NEWLINE); |
| 6046 | |
| 6047 | #ifdef HAVE_IPV6 |
| 6048 | /* display nexthop local */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6049 | if (attr->extra && attr->extra->mp_nexthop_len == 32) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6050 | { |
| 6051 | vty_out (vty, " (%s)%s", |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6052 | inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6053 | buf, INET6_ADDRSTRLEN), |
| 6054 | VTY_NEWLINE); |
| 6055 | } |
| 6056 | #endif /* HAVE_IPV6 */ |
| 6057 | |
| 6058 | /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */ |
| 6059 | vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]); |
| 6060 | |
| 6061 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 6062 | vty_out (vty, ", metric %u", attr->med); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6063 | |
| 6064 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 6065 | vty_out (vty, ", localpref %u", attr->local_pref); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6066 | else |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 6067 | vty_out (vty, ", localpref %u", bgp->default_local_pref); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6068 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6069 | if (attr->extra && attr->extra->weight != 0) |
Wataru Tanitsu | c099baf | 2010-09-10 09:47:56 -0700 | [diff] [blame] | 6070 | vty_out (vty, ", weight %u", attr->extra->weight); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6071 | |
| 6072 | if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)) |
| 6073 | vty_out (vty, ", valid"); |
| 6074 | |
| 6075 | if (binfo->peer != bgp->peer_self) |
| 6076 | { |
| 6077 | if (binfo->peer->as == binfo->peer->local_as) |
| 6078 | vty_out (vty, ", internal"); |
| 6079 | else |
| 6080 | vty_out (vty, ", %s", |
| 6081 | (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external")); |
| 6082 | } |
| 6083 | else if (binfo->sub_type == BGP_ROUTE_AGGREGATE) |
| 6084 | vty_out (vty, ", aggregated, local"); |
| 6085 | else if (binfo->type != ZEBRA_ROUTE_BGP) |
| 6086 | vty_out (vty, ", sourced"); |
| 6087 | else |
| 6088 | vty_out (vty, ", sourced, local"); |
| 6089 | |
| 6090 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
| 6091 | vty_out (vty, ", atomic-aggregate"); |
| 6092 | |
Josh Bailey | de8d5df | 2011-07-20 20:46:01 -0700 | [diff] [blame] | 6093 | if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) || |
| 6094 | (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) && |
| 6095 | bgp_info_mpath_count (binfo))) |
| 6096 | vty_out (vty, ", multipath"); |
| 6097 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6098 | if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED)) |
| 6099 | vty_out (vty, ", best"); |
| 6100 | |
| 6101 | vty_out (vty, "%s", VTY_NEWLINE); |
| 6102 | |
| 6103 | /* Line 4 display Community */ |
| 6104 | if (attr->community) |
| 6105 | vty_out (vty, " Community: %s%s", attr->community->str, |
| 6106 | VTY_NEWLINE); |
| 6107 | |
| 6108 | /* Line 5 display Extended-community */ |
| 6109 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6110 | vty_out (vty, " Extended Community: %s%s", |
| 6111 | attr->extra->ecommunity->str, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6112 | |
| 6113 | /* Line 6 display Originator, Cluster-id */ |
| 6114 | if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) || |
| 6115 | (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) |
| 6116 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6117 | assert (attr->extra); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6118 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6119 | vty_out (vty, " Originator: %s", |
| 6120 | inet_ntoa (attr->extra->originator_id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6121 | |
| 6122 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) |
| 6123 | { |
| 6124 | int i; |
| 6125 | vty_out (vty, ", Cluster list: "); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6126 | for (i = 0; i < attr->extra->cluster->length / 4; i++) |
| 6127 | vty_out (vty, "%s ", |
| 6128 | inet_ntoa (attr->extra->cluster->list[i])); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6129 | } |
| 6130 | vty_out (vty, "%s", VTY_NEWLINE); |
| 6131 | } |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 6132 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6133 | if (binfo->extra && binfo->extra->damp_info) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6134 | bgp_damp_info_vty (vty, binfo); |
| 6135 | |
| 6136 | /* Line 7 display Uptime */ |
John Kemp | 30b0017 | 2011-03-18 17:52:18 +0300 | [diff] [blame] | 6137 | #ifdef HAVE_CLOCK_MONOTONIC |
| 6138 | tbuf = time(NULL) - (bgp_clock() - binfo->uptime); |
Vladimir L Ivanov | 213b6cd | 2010-10-21 14:59:54 +0400 | [diff] [blame] | 6139 | vty_out (vty, " Last update: %s", ctime(&tbuf)); |
John Kemp | 30b0017 | 2011-03-18 17:52:18 +0300 | [diff] [blame] | 6140 | #else |
| 6141 | vty_out (vty, " Last update: %s", ctime(&binfo->uptime)); |
| 6142 | #endif /* HAVE_CLOCK_MONOTONIC */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6143 | } |
| 6144 | vty_out (vty, "%s", VTY_NEWLINE); |
Boian Bonev | b366b51 | 2013-09-09 16:41:35 +0000 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\ |
| 6148 | "h history, * valid, > best, = multipath,%s"\ |
| 6149 | " i internal, r RIB-failure, S Stale, R Removed%s" |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 6150 | #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6151 | #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s" |
| 6152 | #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s" |
| 6153 | #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s" |
| 6154 | |
| 6155 | enum bgp_show_type |
| 6156 | { |
| 6157 | bgp_show_type_normal, |
| 6158 | bgp_show_type_regexp, |
| 6159 | bgp_show_type_prefix_list, |
| 6160 | bgp_show_type_filter_list, |
| 6161 | bgp_show_type_route_map, |
| 6162 | bgp_show_type_neighbor, |
| 6163 | bgp_show_type_cidr_only, |
| 6164 | bgp_show_type_prefix_longer, |
| 6165 | bgp_show_type_community_all, |
| 6166 | bgp_show_type_community, |
| 6167 | bgp_show_type_community_exact, |
| 6168 | bgp_show_type_community_list, |
| 6169 | bgp_show_type_community_list_exact, |
| 6170 | bgp_show_type_flap_statistics, |
| 6171 | bgp_show_type_flap_address, |
| 6172 | bgp_show_type_flap_prefix, |
| 6173 | bgp_show_type_flap_cidr_only, |
| 6174 | bgp_show_type_flap_regexp, |
| 6175 | bgp_show_type_flap_filter_list, |
| 6176 | bgp_show_type_flap_prefix_list, |
| 6177 | bgp_show_type_flap_prefix_longer, |
| 6178 | bgp_show_type_flap_route_map, |
| 6179 | bgp_show_type_flap_neighbor, |
| 6180 | bgp_show_type_dampend_paths, |
| 6181 | bgp_show_type_damp_neighbor |
| 6182 | }; |
| 6183 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6184 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6185 | bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6186 | enum bgp_show_type type, void *output_arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6187 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6188 | struct bgp_info *ri; |
| 6189 | struct bgp_node *rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6190 | int header = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6191 | int display; |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6192 | unsigned long output_count; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6193 | |
| 6194 | /* This is first entry point, so reset total line. */ |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6195 | output_count = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6196 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6197 | /* Start processing of routes. */ |
| 6198 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 6199 | if (rn->info != NULL) |
| 6200 | { |
| 6201 | display = 0; |
| 6202 | |
| 6203 | for (ri = rn->info; ri; ri = ri->next) |
| 6204 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6205 | if (type == bgp_show_type_flap_statistics |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6206 | || type == bgp_show_type_flap_address |
| 6207 | || type == bgp_show_type_flap_prefix |
| 6208 | || type == bgp_show_type_flap_cidr_only |
| 6209 | || type == bgp_show_type_flap_regexp |
| 6210 | || type == bgp_show_type_flap_filter_list |
| 6211 | || type == bgp_show_type_flap_prefix_list |
| 6212 | || type == bgp_show_type_flap_prefix_longer |
| 6213 | || type == bgp_show_type_flap_route_map |
| 6214 | || type == bgp_show_type_flap_neighbor |
| 6215 | || type == bgp_show_type_dampend_paths |
| 6216 | || type == bgp_show_type_damp_neighbor) |
| 6217 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6218 | if (!(ri->extra && ri->extra->damp_info)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6219 | continue; |
| 6220 | } |
| 6221 | if (type == bgp_show_type_regexp |
| 6222 | || type == bgp_show_type_flap_regexp) |
| 6223 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6224 | regex_t *regex = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6225 | |
| 6226 | if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH) |
| 6227 | continue; |
| 6228 | } |
| 6229 | if (type == bgp_show_type_prefix_list |
| 6230 | || type == bgp_show_type_flap_prefix_list) |
| 6231 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6232 | struct prefix_list *plist = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6233 | |
| 6234 | if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT) |
| 6235 | continue; |
| 6236 | } |
| 6237 | if (type == bgp_show_type_filter_list |
| 6238 | || type == bgp_show_type_flap_filter_list) |
| 6239 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6240 | struct as_list *as_list = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6241 | |
| 6242 | if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT) |
| 6243 | continue; |
| 6244 | } |
| 6245 | if (type == bgp_show_type_route_map |
| 6246 | || type == bgp_show_type_flap_route_map) |
| 6247 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6248 | struct route_map *rmap = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6249 | struct bgp_info binfo; |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 6250 | struct attr dummy_attr; |
| 6251 | struct attr_extra dummy_extra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6252 | int ret; |
| 6253 | |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 6254 | dummy_attr.extra = &dummy_extra; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6255 | bgp_attr_dup (&dummy_attr, ri->attr); |
Jorge Boncompte [DTI2] | 558d1fe | 2012-05-07 16:53:05 +0000 | [diff] [blame] | 6256 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6257 | binfo.peer = ri->peer; |
| 6258 | binfo.attr = &dummy_attr; |
| 6259 | |
| 6260 | ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6261 | if (ret == RMAP_DENYMATCH) |
| 6262 | continue; |
| 6263 | } |
| 6264 | if (type == bgp_show_type_neighbor |
| 6265 | || type == bgp_show_type_flap_neighbor |
| 6266 | || type == bgp_show_type_damp_neighbor) |
| 6267 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6268 | union sockunion *su = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6269 | |
| 6270 | if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su)) |
| 6271 | continue; |
| 6272 | } |
| 6273 | if (type == bgp_show_type_cidr_only |
| 6274 | || type == bgp_show_type_flap_cidr_only) |
| 6275 | { |
| 6276 | u_int32_t destination; |
| 6277 | |
| 6278 | destination = ntohl (rn->p.u.prefix4.s_addr); |
| 6279 | if (IN_CLASSC (destination) && rn->p.prefixlen == 24) |
| 6280 | continue; |
| 6281 | if (IN_CLASSB (destination) && rn->p.prefixlen == 16) |
| 6282 | continue; |
| 6283 | if (IN_CLASSA (destination) && rn->p.prefixlen == 8) |
| 6284 | continue; |
| 6285 | } |
| 6286 | if (type == bgp_show_type_prefix_longer |
| 6287 | || type == bgp_show_type_flap_prefix_longer) |
| 6288 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6289 | struct prefix *p = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6290 | |
| 6291 | if (! prefix_match (p, &rn->p)) |
| 6292 | continue; |
| 6293 | } |
| 6294 | if (type == bgp_show_type_community_all) |
| 6295 | { |
| 6296 | if (! ri->attr->community) |
| 6297 | continue; |
| 6298 | } |
| 6299 | if (type == bgp_show_type_community) |
| 6300 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6301 | struct community *com = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6302 | |
| 6303 | if (! ri->attr->community || |
| 6304 | ! community_match (ri->attr->community, com)) |
| 6305 | continue; |
| 6306 | } |
| 6307 | if (type == bgp_show_type_community_exact) |
| 6308 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6309 | struct community *com = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6310 | |
| 6311 | if (! ri->attr->community || |
| 6312 | ! community_cmp (ri->attr->community, com)) |
| 6313 | continue; |
| 6314 | } |
| 6315 | if (type == bgp_show_type_community_list) |
| 6316 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6317 | struct community_list *list = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6318 | |
| 6319 | if (! community_list_match (ri->attr->community, list)) |
| 6320 | continue; |
| 6321 | } |
| 6322 | if (type == bgp_show_type_community_list_exact) |
| 6323 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6324 | struct community_list *list = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6325 | |
| 6326 | if (! community_list_exact_match (ri->attr->community, list)) |
| 6327 | continue; |
| 6328 | } |
| 6329 | if (type == bgp_show_type_flap_address |
| 6330 | || type == bgp_show_type_flap_prefix) |
| 6331 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6332 | struct prefix *p = output_arg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6333 | |
| 6334 | if (! prefix_match (&rn->p, p)) |
| 6335 | continue; |
| 6336 | |
| 6337 | if (type == bgp_show_type_flap_prefix) |
| 6338 | if (p->prefixlen != rn->p.prefixlen) |
| 6339 | continue; |
| 6340 | } |
| 6341 | if (type == bgp_show_type_dampend_paths |
| 6342 | || type == bgp_show_type_damp_neighbor) |
| 6343 | { |
| 6344 | if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED) |
| 6345 | || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
| 6346 | continue; |
| 6347 | } |
| 6348 | |
| 6349 | if (header) |
| 6350 | { |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 6351 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE); |
| 6352 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
| 6353 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6354 | if (type == bgp_show_type_dampend_paths |
| 6355 | || type == bgp_show_type_damp_neighbor) |
| 6356 | vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE); |
| 6357 | else if (type == bgp_show_type_flap_statistics |
| 6358 | || type == bgp_show_type_flap_address |
| 6359 | || type == bgp_show_type_flap_prefix |
| 6360 | || type == bgp_show_type_flap_cidr_only |
| 6361 | || type == bgp_show_type_flap_regexp |
| 6362 | || type == bgp_show_type_flap_filter_list |
| 6363 | || type == bgp_show_type_flap_prefix_list |
| 6364 | || type == bgp_show_type_flap_prefix_longer |
| 6365 | || type == bgp_show_type_flap_route_map |
| 6366 | || type == bgp_show_type_flap_neighbor) |
| 6367 | vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE); |
| 6368 | else |
| 6369 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6370 | header = 0; |
| 6371 | } |
| 6372 | |
| 6373 | if (type == bgp_show_type_dampend_paths |
| 6374 | || type == bgp_show_type_damp_neighbor) |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6375 | damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6376 | else if (type == bgp_show_type_flap_statistics |
| 6377 | || type == bgp_show_type_flap_address |
| 6378 | || type == bgp_show_type_flap_prefix |
| 6379 | || type == bgp_show_type_flap_cidr_only |
| 6380 | || type == bgp_show_type_flap_regexp |
| 6381 | || type == bgp_show_type_flap_filter_list |
| 6382 | || type == bgp_show_type_flap_prefix_list |
| 6383 | || type == bgp_show_type_flap_prefix_longer |
| 6384 | || type == bgp_show_type_flap_route_map |
| 6385 | || type == bgp_show_type_flap_neighbor) |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6386 | flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6387 | else |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6388 | route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6389 | display++; |
| 6390 | } |
| 6391 | if (display) |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6392 | output_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /* No route is displayed */ |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6396 | if (output_count == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6397 | { |
| 6398 | if (type == bgp_show_type_normal) |
| 6399 | vty_out (vty, "No BGP network exists%s", VTY_NEWLINE); |
| 6400 | } |
| 6401 | else |
| 6402 | vty_out (vty, "%sTotal number of prefixes %ld%s", |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6403 | VTY_NEWLINE, output_count, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6404 | |
| 6405 | return CMD_SUCCESS; |
| 6406 | } |
| 6407 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6408 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6409 | bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6410 | enum bgp_show_type type, void *output_arg) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6411 | { |
| 6412 | struct bgp_table *table; |
| 6413 | |
| 6414 | if (bgp == NULL) { |
| 6415 | bgp = bgp_get_default (); |
| 6416 | } |
| 6417 | |
| 6418 | if (bgp == NULL) |
| 6419 | { |
| 6420 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 6421 | return CMD_WARNING; |
| 6422 | } |
| 6423 | |
| 6424 | |
| 6425 | table = bgp->rib[afi][safi]; |
| 6426 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6427 | return bgp_show_table (vty, table, &bgp->router_id, type, output_arg); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6428 | } |
| 6429 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6430 | /* Header of detailed BGP route information */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 6431 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6432 | route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, |
| 6433 | struct bgp_node *rn, |
| 6434 | struct prefix_rd *prd, afi_t afi, safi_t safi) |
| 6435 | { |
| 6436 | struct bgp_info *ri; |
| 6437 | struct prefix *p; |
| 6438 | struct peer *peer; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 6439 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6440 | char buf1[INET6_ADDRSTRLEN]; |
| 6441 | char buf2[INET6_ADDRSTRLEN]; |
| 6442 | int count = 0; |
| 6443 | int best = 0; |
| 6444 | int suppress = 0; |
| 6445 | int no_export = 0; |
| 6446 | int no_advertise = 0; |
| 6447 | int local_as = 0; |
| 6448 | int first = 0; |
| 6449 | |
| 6450 | p = &rn->p; |
| 6451 | vty_out (vty, "BGP routing table entry for %s%s%s/%d%s", |
| 6452 | (safi == SAFI_MPLS_VPN ? |
| 6453 | prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""), |
| 6454 | safi == SAFI_MPLS_VPN ? ":" : "", |
| 6455 | inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN), |
| 6456 | p->prefixlen, VTY_NEWLINE); |
| 6457 | |
| 6458 | for (ri = rn->info; ri; ri = ri->next) |
| 6459 | { |
| 6460 | count++; |
| 6461 | if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) |
| 6462 | { |
| 6463 | best = count; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 6464 | if (ri->extra && ri->extra->suppress) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6465 | suppress = 1; |
| 6466 | if (ri->attr->community != NULL) |
| 6467 | { |
| 6468 | if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE)) |
| 6469 | no_advertise = 1; |
| 6470 | if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT)) |
| 6471 | no_export = 1; |
| 6472 | if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS)) |
| 6473 | local_as = 1; |
| 6474 | } |
| 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | vty_out (vty, "Paths: (%d available", count); |
| 6479 | if (best) |
| 6480 | { |
| 6481 | vty_out (vty, ", best #%d", best); |
| 6482 | if (safi == SAFI_UNICAST) |
| 6483 | vty_out (vty, ", table Default-IP-Routing-Table"); |
| 6484 | } |
| 6485 | else |
| 6486 | vty_out (vty, ", no best path"); |
| 6487 | if (no_advertise) |
| 6488 | vty_out (vty, ", not advertised to any peer"); |
| 6489 | else if (no_export) |
| 6490 | vty_out (vty, ", not advertised to EBGP peer"); |
| 6491 | else if (local_as) |
| 6492 | vty_out (vty, ", not advertised outside local AS"); |
| 6493 | if (suppress) |
| 6494 | vty_out (vty, ", Advertisements suppressed by an aggregate."); |
| 6495 | vty_out (vty, ")%s", VTY_NEWLINE); |
| 6496 | |
| 6497 | /* advertised peer */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 6498 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6499 | { |
| 6500 | if (bgp_adj_out_lookup (peer, p, afi, safi, rn)) |
| 6501 | { |
| 6502 | if (! first) |
| 6503 | vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE); |
| 6504 | vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN)); |
| 6505 | first = 1; |
| 6506 | } |
| 6507 | } |
| 6508 | if (! first) |
| 6509 | vty_out (vty, " Not advertised to any peer"); |
| 6510 | vty_out (vty, "%s", VTY_NEWLINE); |
| 6511 | } |
| 6512 | |
| 6513 | /* Display specified route of BGP table. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 6514 | static int |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6515 | bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 6516 | struct bgp_table *rib, const char *ip_str, |
| 6517 | afi_t afi, safi_t safi, struct prefix_rd *prd, |
| 6518 | int prefix_check) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6519 | { |
| 6520 | int ret; |
| 6521 | int header; |
| 6522 | int display = 0; |
| 6523 | struct prefix match; |
| 6524 | struct bgp_node *rn; |
| 6525 | struct bgp_node *rm; |
| 6526 | struct bgp_info *ri; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6527 | struct bgp_table *table; |
| 6528 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6529 | /* Check IP address argument. */ |
| 6530 | ret = str2prefix (ip_str, &match); |
| 6531 | if (! ret) |
| 6532 | { |
| 6533 | vty_out (vty, "address is malformed%s", VTY_NEWLINE); |
| 6534 | return CMD_WARNING; |
| 6535 | } |
| 6536 | |
| 6537 | match.family = afi2family (afi); |
| 6538 | |
| 6539 | if (safi == SAFI_MPLS_VPN) |
| 6540 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6541 | for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6542 | { |
| 6543 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) |
| 6544 | continue; |
| 6545 | |
| 6546 | if ((table = rn->info) != NULL) |
| 6547 | { |
| 6548 | header = 1; |
| 6549 | |
| 6550 | if ((rm = bgp_node_match (table, &match)) != NULL) |
| 6551 | { |
| 6552 | if (prefix_check && rm->p.prefixlen != match.prefixlen) |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 6553 | { |
| 6554 | bgp_unlock_node (rm); |
| 6555 | continue; |
| 6556 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6557 | |
| 6558 | for (ri = rm->info; ri; ri = ri->next) |
| 6559 | { |
| 6560 | if (header) |
| 6561 | { |
| 6562 | route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p, |
| 6563 | AFI_IP, SAFI_MPLS_VPN); |
| 6564 | |
| 6565 | header = 0; |
| 6566 | } |
| 6567 | display++; |
| 6568 | route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN); |
| 6569 | } |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 6570 | |
| 6571 | bgp_unlock_node (rm); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | } |
| 6576 | else |
| 6577 | { |
| 6578 | header = 1; |
| 6579 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6580 | if ((rn = bgp_node_match (rib, &match)) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6581 | { |
| 6582 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) |
| 6583 | { |
| 6584 | for (ri = rn->info; ri; ri = ri->next) |
| 6585 | { |
| 6586 | if (header) |
| 6587 | { |
| 6588 | route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi); |
| 6589 | header = 0; |
| 6590 | } |
| 6591 | display++; |
| 6592 | route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi); |
| 6593 | } |
| 6594 | } |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 6595 | |
| 6596 | bgp_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | if (! display) |
| 6601 | { |
| 6602 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); |
| 6603 | return CMD_WARNING; |
| 6604 | } |
| 6605 | |
| 6606 | return CMD_SUCCESS; |
| 6607 | } |
| 6608 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6609 | /* Display specified route of Main RIB */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 6610 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 6611 | bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str, |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 6612 | afi_t afi, safi_t safi, struct prefix_rd *prd, |
| 6613 | int prefix_check) |
| 6614 | { |
| 6615 | struct bgp *bgp; |
| 6616 | |
| 6617 | /* BGP structure lookup. */ |
| 6618 | if (view_name) |
| 6619 | { |
| 6620 | bgp = bgp_lookup_by_name (view_name); |
| 6621 | if (bgp == NULL) |
| 6622 | { |
| 6623 | vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE); |
| 6624 | return CMD_WARNING; |
| 6625 | } |
| 6626 | } |
| 6627 | else |
| 6628 | { |
| 6629 | bgp = bgp_get_default (); |
| 6630 | if (bgp == NULL) |
| 6631 | { |
| 6632 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 6633 | return CMD_WARNING; |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str, |
| 6638 | afi, safi, prd, prefix_check); |
| 6639 | } |
| 6640 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6641 | /* BGP route print out function. */ |
| 6642 | DEFUN (show_ip_bgp, |
| 6643 | show_ip_bgp_cmd, |
| 6644 | "show ip bgp", |
| 6645 | SHOW_STR |
| 6646 | IP_STR |
| 6647 | BGP_STR) |
| 6648 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6649 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | DEFUN (show_ip_bgp_ipv4, |
| 6653 | show_ip_bgp_ipv4_cmd, |
| 6654 | "show ip bgp ipv4 (unicast|multicast)", |
| 6655 | SHOW_STR |
| 6656 | IP_STR |
| 6657 | BGP_STR |
| 6658 | "Address family\n" |
| 6659 | "Address Family modifier\n" |
| 6660 | "Address Family modifier\n") |
| 6661 | { |
| 6662 | if (strncmp (argv[0], "m", 1) == 0) |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6663 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal, |
| 6664 | NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6665 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6666 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6667 | } |
| 6668 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6669 | ALIAS (show_ip_bgp_ipv4, |
| 6670 | show_bgp_ipv4_safi_cmd, |
| 6671 | "show bgp ipv4 (unicast|multicast)", |
| 6672 | SHOW_STR |
| 6673 | BGP_STR |
| 6674 | "Address family\n" |
| 6675 | "Address Family modifier\n" |
| 6676 | "Address Family modifier\n") |
| 6677 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6678 | DEFUN (show_ip_bgp_route, |
| 6679 | show_ip_bgp_route_cmd, |
| 6680 | "show ip bgp A.B.C.D", |
| 6681 | SHOW_STR |
| 6682 | IP_STR |
| 6683 | BGP_STR |
| 6684 | "Network in the BGP routing table to display\n") |
| 6685 | { |
| 6686 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0); |
| 6687 | } |
| 6688 | |
| 6689 | DEFUN (show_ip_bgp_ipv4_route, |
| 6690 | show_ip_bgp_ipv4_route_cmd, |
| 6691 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D", |
| 6692 | SHOW_STR |
| 6693 | IP_STR |
| 6694 | BGP_STR |
| 6695 | "Address family\n" |
| 6696 | "Address Family modifier\n" |
| 6697 | "Address Family modifier\n" |
| 6698 | "Network in the BGP routing table to display\n") |
| 6699 | { |
| 6700 | if (strncmp (argv[0], "m", 1) == 0) |
| 6701 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0); |
| 6702 | |
| 6703 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0); |
| 6704 | } |
| 6705 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6706 | ALIAS (show_ip_bgp_ipv4_route, |
| 6707 | show_bgp_ipv4_safi_route_cmd, |
| 6708 | "show bgp ipv4 (unicast|multicast) A.B.C.D", |
| 6709 | SHOW_STR |
| 6710 | BGP_STR |
| 6711 | "Address family\n" |
| 6712 | "Address Family modifier\n" |
| 6713 | "Address Family modifier\n" |
| 6714 | "Network in the BGP routing table to display\n") |
| 6715 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6716 | DEFUN (show_ip_bgp_vpnv4_all_route, |
| 6717 | show_ip_bgp_vpnv4_all_route_cmd, |
| 6718 | "show ip bgp vpnv4 all A.B.C.D", |
| 6719 | SHOW_STR |
| 6720 | IP_STR |
| 6721 | BGP_STR |
| 6722 | "Display VPNv4 NLRI specific information\n" |
| 6723 | "Display information about all VPNv4 NLRIs\n" |
| 6724 | "Network in the BGP routing table to display\n") |
| 6725 | { |
| 6726 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0); |
| 6727 | } |
| 6728 | |
| 6729 | DEFUN (show_ip_bgp_vpnv4_rd_route, |
| 6730 | show_ip_bgp_vpnv4_rd_route_cmd, |
| 6731 | "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D", |
| 6732 | SHOW_STR |
| 6733 | IP_STR |
| 6734 | BGP_STR |
| 6735 | "Display VPNv4 NLRI specific information\n" |
| 6736 | "Display information for a route distinguisher\n" |
| 6737 | "VPN Route Distinguisher\n" |
| 6738 | "Network in the BGP routing table to display\n") |
| 6739 | { |
| 6740 | int ret; |
| 6741 | struct prefix_rd prd; |
| 6742 | |
| 6743 | ret = str2prefix_rd (argv[0], &prd); |
| 6744 | if (! ret) |
| 6745 | { |
| 6746 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 6747 | return CMD_WARNING; |
| 6748 | } |
| 6749 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0); |
| 6750 | } |
| 6751 | |
| 6752 | DEFUN (show_ip_bgp_prefix, |
| 6753 | show_ip_bgp_prefix_cmd, |
| 6754 | "show ip bgp A.B.C.D/M", |
| 6755 | SHOW_STR |
| 6756 | IP_STR |
| 6757 | BGP_STR |
| 6758 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6759 | { |
| 6760 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1); |
| 6761 | } |
| 6762 | |
| 6763 | DEFUN (show_ip_bgp_ipv4_prefix, |
| 6764 | show_ip_bgp_ipv4_prefix_cmd, |
| 6765 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M", |
| 6766 | SHOW_STR |
| 6767 | IP_STR |
| 6768 | BGP_STR |
| 6769 | "Address family\n" |
| 6770 | "Address Family modifier\n" |
| 6771 | "Address Family modifier\n" |
| 6772 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6773 | { |
| 6774 | if (strncmp (argv[0], "m", 1) == 0) |
| 6775 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1); |
| 6776 | |
| 6777 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1); |
| 6778 | } |
| 6779 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6780 | ALIAS (show_ip_bgp_ipv4_prefix, |
| 6781 | show_bgp_ipv4_safi_prefix_cmd, |
| 6782 | "show bgp ipv4 (unicast|multicast) A.B.C.D/M", |
| 6783 | SHOW_STR |
| 6784 | BGP_STR |
| 6785 | "Address family\n" |
| 6786 | "Address Family modifier\n" |
| 6787 | "Address Family modifier\n" |
| 6788 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6789 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6790 | DEFUN (show_ip_bgp_vpnv4_all_prefix, |
| 6791 | show_ip_bgp_vpnv4_all_prefix_cmd, |
| 6792 | "show ip bgp vpnv4 all A.B.C.D/M", |
| 6793 | SHOW_STR |
| 6794 | IP_STR |
| 6795 | BGP_STR |
| 6796 | "Display VPNv4 NLRI specific information\n" |
| 6797 | "Display information about all VPNv4 NLRIs\n" |
| 6798 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6799 | { |
| 6800 | return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1); |
| 6801 | } |
| 6802 | |
| 6803 | DEFUN (show_ip_bgp_vpnv4_rd_prefix, |
| 6804 | show_ip_bgp_vpnv4_rd_prefix_cmd, |
| 6805 | "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M", |
| 6806 | SHOW_STR |
| 6807 | IP_STR |
| 6808 | BGP_STR |
| 6809 | "Display VPNv4 NLRI specific information\n" |
| 6810 | "Display information for a route distinguisher\n" |
| 6811 | "VPN Route Distinguisher\n" |
| 6812 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6813 | { |
| 6814 | int ret; |
| 6815 | struct prefix_rd prd; |
| 6816 | |
| 6817 | ret = str2prefix_rd (argv[0], &prd); |
| 6818 | if (! ret) |
| 6819 | { |
| 6820 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 6821 | return CMD_WARNING; |
| 6822 | } |
| 6823 | return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1); |
| 6824 | } |
| 6825 | |
| 6826 | DEFUN (show_ip_bgp_view, |
| 6827 | show_ip_bgp_view_cmd, |
| 6828 | "show ip bgp view WORD", |
| 6829 | SHOW_STR |
| 6830 | IP_STR |
| 6831 | BGP_STR |
| 6832 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 6833 | "View name\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6834 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 6835 | struct bgp *bgp; |
| 6836 | |
| 6837 | /* BGP structure lookup. */ |
| 6838 | bgp = bgp_lookup_by_name (argv[0]); |
| 6839 | if (bgp == NULL) |
| 6840 | { |
| 6841 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 6842 | return CMD_WARNING; |
| 6843 | } |
| 6844 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6845 | return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | DEFUN (show_ip_bgp_view_route, |
| 6849 | show_ip_bgp_view_route_cmd, |
| 6850 | "show ip bgp view WORD A.B.C.D", |
| 6851 | SHOW_STR |
| 6852 | IP_STR |
| 6853 | BGP_STR |
| 6854 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 6855 | "View name\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6856 | "Network in the BGP routing table to display\n") |
| 6857 | { |
| 6858 | return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0); |
| 6859 | } |
| 6860 | |
| 6861 | DEFUN (show_ip_bgp_view_prefix, |
| 6862 | show_ip_bgp_view_prefix_cmd, |
| 6863 | "show ip bgp view WORD A.B.C.D/M", |
| 6864 | SHOW_STR |
| 6865 | IP_STR |
| 6866 | BGP_STR |
| 6867 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 6868 | "View name\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6869 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 6870 | { |
| 6871 | return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1); |
| 6872 | } |
| 6873 | |
| 6874 | #ifdef HAVE_IPV6 |
| 6875 | DEFUN (show_bgp, |
| 6876 | show_bgp_cmd, |
| 6877 | "show bgp", |
| 6878 | SHOW_STR |
| 6879 | BGP_STR) |
| 6880 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6881 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
| 6882 | NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6883 | } |
| 6884 | |
| 6885 | ALIAS (show_bgp, |
| 6886 | show_bgp_ipv6_cmd, |
| 6887 | "show bgp ipv6", |
| 6888 | SHOW_STR |
| 6889 | BGP_STR |
| 6890 | "Address family\n") |
| 6891 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6892 | DEFUN (show_bgp_ipv6_safi, |
| 6893 | show_bgp_ipv6_safi_cmd, |
| 6894 | "show bgp ipv6 (unicast|multicast)", |
| 6895 | SHOW_STR |
| 6896 | BGP_STR |
| 6897 | "Address family\n" |
| 6898 | "Address Family modifier\n" |
| 6899 | "Address Family modifier\n") |
| 6900 | { |
| 6901 | if (strncmp (argv[0], "m", 1) == 0) |
| 6902 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal, |
| 6903 | NULL); |
| 6904 | |
| 6905 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL); |
| 6906 | } |
| 6907 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6908 | /* old command */ |
| 6909 | DEFUN (show_ipv6_bgp, |
| 6910 | show_ipv6_bgp_cmd, |
| 6911 | "show ipv6 bgp", |
| 6912 | SHOW_STR |
| 6913 | IP_STR |
| 6914 | BGP_STR) |
| 6915 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 6916 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, |
| 6917 | NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | DEFUN (show_bgp_route, |
| 6921 | show_bgp_route_cmd, |
| 6922 | "show bgp X:X::X:X", |
| 6923 | SHOW_STR |
| 6924 | BGP_STR |
| 6925 | "Network in the BGP routing table to display\n") |
| 6926 | { |
| 6927 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0); |
| 6928 | } |
| 6929 | |
| 6930 | ALIAS (show_bgp_route, |
| 6931 | show_bgp_ipv6_route_cmd, |
| 6932 | "show bgp ipv6 X:X::X:X", |
| 6933 | SHOW_STR |
| 6934 | BGP_STR |
| 6935 | "Address family\n" |
| 6936 | "Network in the BGP routing table to display\n") |
| 6937 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6938 | DEFUN (show_bgp_ipv6_safi_route, |
| 6939 | show_bgp_ipv6_safi_route_cmd, |
| 6940 | "show bgp ipv6 (unicast|multicast) X:X::X:X", |
| 6941 | SHOW_STR |
| 6942 | BGP_STR |
| 6943 | "Address family\n" |
| 6944 | "Address Family modifier\n" |
| 6945 | "Address Family modifier\n" |
| 6946 | "Network in the BGP routing table to display\n") |
| 6947 | { |
| 6948 | if (strncmp (argv[0], "m", 1) == 0) |
| 6949 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0); |
| 6950 | |
| 6951 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0); |
| 6952 | } |
| 6953 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 6954 | /* old command */ |
| 6955 | DEFUN (show_ipv6_bgp_route, |
| 6956 | show_ipv6_bgp_route_cmd, |
| 6957 | "show ipv6 bgp X:X::X:X", |
| 6958 | SHOW_STR |
| 6959 | IP_STR |
| 6960 | BGP_STR |
| 6961 | "Network in the BGP routing table to display\n") |
| 6962 | { |
| 6963 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0); |
| 6964 | } |
| 6965 | |
| 6966 | DEFUN (show_bgp_prefix, |
| 6967 | show_bgp_prefix_cmd, |
| 6968 | "show bgp X:X::X:X/M", |
| 6969 | SHOW_STR |
| 6970 | BGP_STR |
| 6971 | "IPv6 prefix <network>/<length>\n") |
| 6972 | { |
| 6973 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1); |
| 6974 | } |
| 6975 | |
| 6976 | ALIAS (show_bgp_prefix, |
| 6977 | show_bgp_ipv6_prefix_cmd, |
| 6978 | "show bgp ipv6 X:X::X:X/M", |
| 6979 | SHOW_STR |
| 6980 | BGP_STR |
| 6981 | "Address family\n" |
| 6982 | "IPv6 prefix <network>/<length>\n") |
| 6983 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 6984 | DEFUN (show_bgp_ipv6_safi_prefix, |
| 6985 | show_bgp_ipv6_safi_prefix_cmd, |
| 6986 | "show bgp ipv6 (unicast|multicast) X:X::X:X/M", |
| 6987 | SHOW_STR |
| 6988 | BGP_STR |
| 6989 | "Address family\n" |
| 6990 | "Address Family modifier\n" |
| 6991 | "Address Family modifier\n" |
| 6992 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 6993 | { |
| 6994 | if (strncmp (argv[0], "m", 1) == 0) |
| 6995 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1); |
| 6996 | |
| 6997 | return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1); |
| 6998 | } |
| 6999 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7000 | /* old command */ |
| 7001 | DEFUN (show_ipv6_bgp_prefix, |
| 7002 | show_ipv6_bgp_prefix_cmd, |
| 7003 | "show ipv6 bgp X:X::X:X/M", |
| 7004 | SHOW_STR |
| 7005 | IP_STR |
| 7006 | BGP_STR |
| 7007 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 7008 | { |
| 7009 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1); |
| 7010 | } |
| 7011 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 7012 | DEFUN (show_bgp_view, |
| 7013 | show_bgp_view_cmd, |
| 7014 | "show bgp view WORD", |
| 7015 | SHOW_STR |
| 7016 | BGP_STR |
| 7017 | "BGP view\n" |
| 7018 | "View name\n") |
| 7019 | { |
| 7020 | struct bgp *bgp; |
| 7021 | |
| 7022 | /* BGP structure lookup. */ |
| 7023 | bgp = bgp_lookup_by_name (argv[0]); |
| 7024 | if (bgp == NULL) |
| 7025 | { |
| 7026 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 7027 | return CMD_WARNING; |
| 7028 | } |
| 7029 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7030 | return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | ALIAS (show_bgp_view, |
| 7034 | show_bgp_view_ipv6_cmd, |
| 7035 | "show bgp view WORD ipv6", |
| 7036 | SHOW_STR |
| 7037 | BGP_STR |
| 7038 | "BGP view\n" |
| 7039 | "View name\n" |
| 7040 | "Address family\n") |
| 7041 | |
| 7042 | DEFUN (show_bgp_view_route, |
| 7043 | show_bgp_view_route_cmd, |
| 7044 | "show bgp view WORD X:X::X:X", |
| 7045 | SHOW_STR |
| 7046 | BGP_STR |
| 7047 | "BGP view\n" |
| 7048 | "View name\n" |
| 7049 | "Network in the BGP routing table to display\n") |
| 7050 | { |
| 7051 | return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0); |
| 7052 | } |
| 7053 | |
| 7054 | ALIAS (show_bgp_view_route, |
| 7055 | show_bgp_view_ipv6_route_cmd, |
| 7056 | "show bgp view WORD ipv6 X:X::X:X", |
| 7057 | SHOW_STR |
| 7058 | BGP_STR |
| 7059 | "BGP view\n" |
| 7060 | "View name\n" |
| 7061 | "Address family\n" |
| 7062 | "Network in the BGP routing table to display\n") |
| 7063 | |
| 7064 | DEFUN (show_bgp_view_prefix, |
| 7065 | show_bgp_view_prefix_cmd, |
| 7066 | "show bgp view WORD X:X::X:X/M", |
| 7067 | SHOW_STR |
| 7068 | BGP_STR |
| 7069 | "BGP view\n" |
| 7070 | "View name\n" |
| 7071 | "IPv6 prefix <network>/<length>\n") |
| 7072 | { |
| 7073 | return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1); |
| 7074 | } |
| 7075 | |
| 7076 | ALIAS (show_bgp_view_prefix, |
| 7077 | show_bgp_view_ipv6_prefix_cmd, |
| 7078 | "show bgp view WORD ipv6 X:X::X:X/M", |
| 7079 | SHOW_STR |
| 7080 | BGP_STR |
| 7081 | "BGP view\n" |
| 7082 | "View name\n" |
| 7083 | "Address family\n" |
| 7084 | "IPv6 prefix <network>/<length>\n") |
| 7085 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7086 | /* old command */ |
| 7087 | DEFUN (show_ipv6_mbgp, |
| 7088 | show_ipv6_mbgp_cmd, |
| 7089 | "show ipv6 mbgp", |
| 7090 | SHOW_STR |
| 7091 | IP_STR |
| 7092 | MBGP_STR) |
| 7093 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7094 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal, |
| 7095 | NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | /* old command */ |
| 7099 | DEFUN (show_ipv6_mbgp_route, |
| 7100 | show_ipv6_mbgp_route_cmd, |
| 7101 | "show ipv6 mbgp X:X::X:X", |
| 7102 | SHOW_STR |
| 7103 | IP_STR |
| 7104 | MBGP_STR |
| 7105 | "Network in the MBGP routing table to display\n") |
| 7106 | { |
| 7107 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0); |
| 7108 | } |
| 7109 | |
| 7110 | /* old command */ |
| 7111 | DEFUN (show_ipv6_mbgp_prefix, |
| 7112 | show_ipv6_mbgp_prefix_cmd, |
| 7113 | "show ipv6 mbgp X:X::X:X/M", |
| 7114 | SHOW_STR |
| 7115 | IP_STR |
| 7116 | MBGP_STR |
| 7117 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 7118 | { |
| 7119 | return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1); |
| 7120 | } |
| 7121 | #endif |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7122 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7123 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 7124 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 7125 | bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7126 | safi_t safi, enum bgp_show_type type) |
| 7127 | { |
| 7128 | int i; |
| 7129 | struct buffer *b; |
| 7130 | char *regstr; |
| 7131 | int first; |
| 7132 | regex_t *regex; |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7133 | int rc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7134 | |
| 7135 | first = 0; |
| 7136 | b = buffer_new (1024); |
| 7137 | for (i = 0; i < argc; i++) |
| 7138 | { |
| 7139 | if (first) |
| 7140 | buffer_putc (b, ' '); |
| 7141 | else |
| 7142 | { |
| 7143 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) |
| 7144 | continue; |
| 7145 | first = 1; |
| 7146 | } |
| 7147 | |
| 7148 | buffer_putstr (b, argv[i]); |
| 7149 | } |
| 7150 | buffer_putc (b, '\0'); |
| 7151 | |
| 7152 | regstr = buffer_getstr (b); |
| 7153 | buffer_free (b); |
| 7154 | |
| 7155 | regex = bgp_regcomp (regstr); |
ajs | 3b8b185 | 2005-01-29 18:19:13 +0000 | [diff] [blame] | 7156 | XFREE(MTYPE_TMP, regstr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7157 | if (! regex) |
| 7158 | { |
| 7159 | vty_out (vty, "Can't compile regexp %s%s", argv[0], |
| 7160 | VTY_NEWLINE); |
| 7161 | return CMD_WARNING; |
| 7162 | } |
| 7163 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7164 | rc = bgp_show (vty, NULL, afi, safi, type, regex); |
| 7165 | bgp_regex_free (regex); |
| 7166 | return rc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | DEFUN (show_ip_bgp_regexp, |
| 7170 | show_ip_bgp_regexp_cmd, |
| 7171 | "show ip bgp regexp .LINE", |
| 7172 | SHOW_STR |
| 7173 | IP_STR |
| 7174 | BGP_STR |
| 7175 | "Display routes matching the AS path regular expression\n" |
| 7176 | "A regular-expression to match the BGP AS paths\n") |
| 7177 | { |
| 7178 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, |
| 7179 | bgp_show_type_regexp); |
| 7180 | } |
| 7181 | |
| 7182 | DEFUN (show_ip_bgp_flap_regexp, |
| 7183 | show_ip_bgp_flap_regexp_cmd, |
| 7184 | "show ip bgp flap-statistics regexp .LINE", |
| 7185 | SHOW_STR |
| 7186 | IP_STR |
| 7187 | BGP_STR |
| 7188 | "Display flap statistics of routes\n" |
| 7189 | "Display routes matching the AS path regular expression\n" |
| 7190 | "A regular-expression to match the BGP AS paths\n") |
| 7191 | { |
| 7192 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, |
| 7193 | bgp_show_type_flap_regexp); |
| 7194 | } |
| 7195 | |
| 7196 | DEFUN (show_ip_bgp_ipv4_regexp, |
| 7197 | show_ip_bgp_ipv4_regexp_cmd, |
| 7198 | "show ip bgp ipv4 (unicast|multicast) regexp .LINE", |
| 7199 | SHOW_STR |
| 7200 | IP_STR |
| 7201 | BGP_STR |
| 7202 | "Address family\n" |
| 7203 | "Address Family modifier\n" |
| 7204 | "Address Family modifier\n" |
| 7205 | "Display routes matching the AS path regular expression\n" |
| 7206 | "A regular-expression to match the BGP AS paths\n") |
| 7207 | { |
| 7208 | if (strncmp (argv[0], "m", 1) == 0) |
| 7209 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST, |
| 7210 | bgp_show_type_regexp); |
| 7211 | |
| 7212 | return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST, |
| 7213 | bgp_show_type_regexp); |
| 7214 | } |
| 7215 | |
| 7216 | #ifdef HAVE_IPV6 |
| 7217 | DEFUN (show_bgp_regexp, |
| 7218 | show_bgp_regexp_cmd, |
| 7219 | "show bgp regexp .LINE", |
| 7220 | SHOW_STR |
| 7221 | BGP_STR |
| 7222 | "Display routes matching the AS path regular expression\n" |
| 7223 | "A regular-expression to match the BGP AS paths\n") |
| 7224 | { |
| 7225 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, |
| 7226 | bgp_show_type_regexp); |
| 7227 | } |
| 7228 | |
| 7229 | ALIAS (show_bgp_regexp, |
| 7230 | show_bgp_ipv6_regexp_cmd, |
| 7231 | "show bgp ipv6 regexp .LINE", |
| 7232 | SHOW_STR |
| 7233 | BGP_STR |
| 7234 | "Address family\n" |
| 7235 | "Display routes matching the AS path regular expression\n" |
| 7236 | "A regular-expression to match the BGP AS paths\n") |
| 7237 | |
| 7238 | /* old command */ |
| 7239 | DEFUN (show_ipv6_bgp_regexp, |
| 7240 | show_ipv6_bgp_regexp_cmd, |
| 7241 | "show ipv6 bgp regexp .LINE", |
| 7242 | SHOW_STR |
| 7243 | IP_STR |
| 7244 | BGP_STR |
| 7245 | "Display routes matching the AS path regular expression\n" |
| 7246 | "A regular-expression to match the BGP AS paths\n") |
| 7247 | { |
| 7248 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST, |
| 7249 | bgp_show_type_regexp); |
| 7250 | } |
| 7251 | |
| 7252 | /* old command */ |
| 7253 | DEFUN (show_ipv6_mbgp_regexp, |
| 7254 | show_ipv6_mbgp_regexp_cmd, |
| 7255 | "show ipv6 mbgp regexp .LINE", |
| 7256 | SHOW_STR |
| 7257 | IP_STR |
| 7258 | BGP_STR |
| 7259 | "Display routes matching the AS path regular expression\n" |
| 7260 | "A regular-expression to match the MBGP AS paths\n") |
| 7261 | { |
| 7262 | return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST, |
| 7263 | bgp_show_type_regexp); |
| 7264 | } |
| 7265 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7266 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 7267 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 7268 | bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7269 | safi_t safi, enum bgp_show_type type) |
| 7270 | { |
| 7271 | struct prefix_list *plist; |
| 7272 | |
| 7273 | plist = prefix_list_lookup (afi, prefix_list_str); |
| 7274 | if (plist == NULL) |
| 7275 | { |
| 7276 | vty_out (vty, "%% %s is not a valid prefix-list name%s", |
| 7277 | prefix_list_str, VTY_NEWLINE); |
| 7278 | return CMD_WARNING; |
| 7279 | } |
| 7280 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7281 | return bgp_show (vty, NULL, afi, safi, type, plist); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7282 | } |
| 7283 | |
| 7284 | DEFUN (show_ip_bgp_prefix_list, |
| 7285 | show_ip_bgp_prefix_list_cmd, |
| 7286 | "show ip bgp prefix-list WORD", |
| 7287 | SHOW_STR |
| 7288 | IP_STR |
| 7289 | BGP_STR |
| 7290 | "Display routes conforming to the prefix-list\n" |
| 7291 | "IP prefix-list name\n") |
| 7292 | { |
| 7293 | return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7294 | bgp_show_type_prefix_list); |
| 7295 | } |
| 7296 | |
| 7297 | DEFUN (show_ip_bgp_flap_prefix_list, |
| 7298 | show_ip_bgp_flap_prefix_list_cmd, |
| 7299 | "show ip bgp flap-statistics prefix-list WORD", |
| 7300 | SHOW_STR |
| 7301 | IP_STR |
| 7302 | BGP_STR |
| 7303 | "Display flap statistics of routes\n" |
| 7304 | "Display routes conforming to the prefix-list\n" |
| 7305 | "IP prefix-list name\n") |
| 7306 | { |
| 7307 | return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7308 | bgp_show_type_flap_prefix_list); |
| 7309 | } |
| 7310 | |
| 7311 | DEFUN (show_ip_bgp_ipv4_prefix_list, |
| 7312 | show_ip_bgp_ipv4_prefix_list_cmd, |
| 7313 | "show ip bgp ipv4 (unicast|multicast) prefix-list WORD", |
| 7314 | SHOW_STR |
| 7315 | IP_STR |
| 7316 | BGP_STR |
| 7317 | "Address family\n" |
| 7318 | "Address Family modifier\n" |
| 7319 | "Address Family modifier\n" |
| 7320 | "Display routes conforming to the prefix-list\n" |
| 7321 | "IP prefix-list name\n") |
| 7322 | { |
| 7323 | if (strncmp (argv[0], "m", 1) == 0) |
| 7324 | return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST, |
| 7325 | bgp_show_type_prefix_list); |
| 7326 | |
| 7327 | return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST, |
| 7328 | bgp_show_type_prefix_list); |
| 7329 | } |
| 7330 | |
| 7331 | #ifdef HAVE_IPV6 |
| 7332 | DEFUN (show_bgp_prefix_list, |
| 7333 | show_bgp_prefix_list_cmd, |
| 7334 | "show bgp prefix-list WORD", |
| 7335 | SHOW_STR |
| 7336 | BGP_STR |
| 7337 | "Display routes conforming to the prefix-list\n" |
| 7338 | "IPv6 prefix-list name\n") |
| 7339 | { |
| 7340 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 7341 | bgp_show_type_prefix_list); |
| 7342 | } |
| 7343 | |
| 7344 | ALIAS (show_bgp_prefix_list, |
| 7345 | show_bgp_ipv6_prefix_list_cmd, |
| 7346 | "show bgp ipv6 prefix-list WORD", |
| 7347 | SHOW_STR |
| 7348 | BGP_STR |
| 7349 | "Address family\n" |
| 7350 | "Display routes conforming to the prefix-list\n" |
| 7351 | "IPv6 prefix-list name\n") |
| 7352 | |
| 7353 | /* old command */ |
| 7354 | DEFUN (show_ipv6_bgp_prefix_list, |
| 7355 | show_ipv6_bgp_prefix_list_cmd, |
| 7356 | "show ipv6 bgp prefix-list WORD", |
| 7357 | SHOW_STR |
| 7358 | IPV6_STR |
| 7359 | BGP_STR |
| 7360 | "Display routes matching the prefix-list\n" |
| 7361 | "IPv6 prefix-list name\n") |
| 7362 | { |
| 7363 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 7364 | bgp_show_type_prefix_list); |
| 7365 | } |
| 7366 | |
| 7367 | /* old command */ |
| 7368 | DEFUN (show_ipv6_mbgp_prefix_list, |
| 7369 | show_ipv6_mbgp_prefix_list_cmd, |
| 7370 | "show ipv6 mbgp prefix-list WORD", |
| 7371 | SHOW_STR |
| 7372 | IPV6_STR |
| 7373 | MBGP_STR |
| 7374 | "Display routes matching the prefix-list\n" |
| 7375 | "IPv6 prefix-list name\n") |
| 7376 | { |
| 7377 | return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
| 7378 | bgp_show_type_prefix_list); |
| 7379 | } |
| 7380 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7381 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 7382 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 7383 | bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7384 | safi_t safi, enum bgp_show_type type) |
| 7385 | { |
| 7386 | struct as_list *as_list; |
| 7387 | |
| 7388 | as_list = as_list_lookup (filter); |
| 7389 | if (as_list == NULL) |
| 7390 | { |
| 7391 | vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE); |
| 7392 | return CMD_WARNING; |
| 7393 | } |
| 7394 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7395 | return bgp_show (vty, NULL, afi, safi, type, as_list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7396 | } |
| 7397 | |
| 7398 | DEFUN (show_ip_bgp_filter_list, |
| 7399 | show_ip_bgp_filter_list_cmd, |
| 7400 | "show ip bgp filter-list WORD", |
| 7401 | SHOW_STR |
| 7402 | IP_STR |
| 7403 | BGP_STR |
| 7404 | "Display routes conforming to the filter-list\n" |
| 7405 | "Regular expression access list name\n") |
| 7406 | { |
| 7407 | return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7408 | bgp_show_type_filter_list); |
| 7409 | } |
| 7410 | |
| 7411 | DEFUN (show_ip_bgp_flap_filter_list, |
| 7412 | show_ip_bgp_flap_filter_list_cmd, |
| 7413 | "show ip bgp flap-statistics filter-list WORD", |
| 7414 | SHOW_STR |
| 7415 | IP_STR |
| 7416 | BGP_STR |
| 7417 | "Display flap statistics of routes\n" |
| 7418 | "Display routes conforming to the filter-list\n" |
| 7419 | "Regular expression access list name\n") |
| 7420 | { |
| 7421 | return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7422 | bgp_show_type_flap_filter_list); |
| 7423 | } |
| 7424 | |
| 7425 | DEFUN (show_ip_bgp_ipv4_filter_list, |
| 7426 | show_ip_bgp_ipv4_filter_list_cmd, |
| 7427 | "show ip bgp ipv4 (unicast|multicast) filter-list WORD", |
| 7428 | SHOW_STR |
| 7429 | IP_STR |
| 7430 | BGP_STR |
| 7431 | "Address family\n" |
| 7432 | "Address Family modifier\n" |
| 7433 | "Address Family modifier\n" |
| 7434 | "Display routes conforming to the filter-list\n" |
| 7435 | "Regular expression access list name\n") |
| 7436 | { |
| 7437 | if (strncmp (argv[0], "m", 1) == 0) |
| 7438 | return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST, |
| 7439 | bgp_show_type_filter_list); |
| 7440 | |
| 7441 | return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST, |
| 7442 | bgp_show_type_filter_list); |
| 7443 | } |
| 7444 | |
| 7445 | #ifdef HAVE_IPV6 |
| 7446 | DEFUN (show_bgp_filter_list, |
| 7447 | show_bgp_filter_list_cmd, |
| 7448 | "show bgp filter-list WORD", |
| 7449 | SHOW_STR |
| 7450 | BGP_STR |
| 7451 | "Display routes conforming to the filter-list\n" |
| 7452 | "Regular expression access list name\n") |
| 7453 | { |
| 7454 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 7455 | bgp_show_type_filter_list); |
| 7456 | } |
| 7457 | |
| 7458 | ALIAS (show_bgp_filter_list, |
| 7459 | show_bgp_ipv6_filter_list_cmd, |
| 7460 | "show bgp ipv6 filter-list WORD", |
| 7461 | SHOW_STR |
| 7462 | BGP_STR |
| 7463 | "Address family\n" |
| 7464 | "Display routes conforming to the filter-list\n" |
| 7465 | "Regular expression access list name\n") |
| 7466 | |
| 7467 | /* old command */ |
| 7468 | DEFUN (show_ipv6_bgp_filter_list, |
| 7469 | show_ipv6_bgp_filter_list_cmd, |
| 7470 | "show ipv6 bgp filter-list WORD", |
| 7471 | SHOW_STR |
| 7472 | IPV6_STR |
| 7473 | BGP_STR |
| 7474 | "Display routes conforming to the filter-list\n" |
| 7475 | "Regular expression access list name\n") |
| 7476 | { |
| 7477 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 7478 | bgp_show_type_filter_list); |
| 7479 | } |
| 7480 | |
| 7481 | /* old command */ |
| 7482 | DEFUN (show_ipv6_mbgp_filter_list, |
| 7483 | show_ipv6_mbgp_filter_list_cmd, |
| 7484 | "show ipv6 mbgp filter-list WORD", |
| 7485 | SHOW_STR |
| 7486 | IPV6_STR |
| 7487 | MBGP_STR |
| 7488 | "Display routes conforming to the filter-list\n" |
| 7489 | "Regular expression access list name\n") |
| 7490 | { |
| 7491 | return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
| 7492 | bgp_show_type_filter_list); |
| 7493 | } |
| 7494 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7495 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 7496 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 7497 | bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7498 | safi_t safi, enum bgp_show_type type) |
| 7499 | { |
| 7500 | struct route_map *rmap; |
| 7501 | |
| 7502 | rmap = route_map_lookup_by_name (rmap_str); |
| 7503 | if (! rmap) |
| 7504 | { |
| 7505 | vty_out (vty, "%% %s is not a valid route-map name%s", |
| 7506 | rmap_str, VTY_NEWLINE); |
| 7507 | return CMD_WARNING; |
| 7508 | } |
| 7509 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7510 | return bgp_show (vty, NULL, afi, safi, type, rmap); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7511 | } |
| 7512 | |
| 7513 | DEFUN (show_ip_bgp_route_map, |
| 7514 | show_ip_bgp_route_map_cmd, |
| 7515 | "show ip bgp route-map WORD", |
| 7516 | SHOW_STR |
| 7517 | IP_STR |
| 7518 | BGP_STR |
| 7519 | "Display routes matching the route-map\n" |
| 7520 | "A route-map to match on\n") |
| 7521 | { |
| 7522 | return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7523 | bgp_show_type_route_map); |
| 7524 | } |
| 7525 | |
| 7526 | DEFUN (show_ip_bgp_flap_route_map, |
| 7527 | show_ip_bgp_flap_route_map_cmd, |
| 7528 | "show ip bgp flap-statistics route-map WORD", |
| 7529 | SHOW_STR |
| 7530 | IP_STR |
| 7531 | BGP_STR |
| 7532 | "Display flap statistics of routes\n" |
| 7533 | "Display routes matching the route-map\n" |
| 7534 | "A route-map to match on\n") |
| 7535 | { |
| 7536 | return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 7537 | bgp_show_type_flap_route_map); |
| 7538 | } |
| 7539 | |
| 7540 | DEFUN (show_ip_bgp_ipv4_route_map, |
| 7541 | show_ip_bgp_ipv4_route_map_cmd, |
| 7542 | "show ip bgp ipv4 (unicast|multicast) route-map WORD", |
| 7543 | SHOW_STR |
| 7544 | IP_STR |
| 7545 | BGP_STR |
| 7546 | "Address family\n" |
| 7547 | "Address Family modifier\n" |
| 7548 | "Address Family modifier\n" |
| 7549 | "Display routes matching the route-map\n" |
| 7550 | "A route-map to match on\n") |
| 7551 | { |
| 7552 | if (strncmp (argv[0], "m", 1) == 0) |
| 7553 | return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST, |
| 7554 | bgp_show_type_route_map); |
| 7555 | |
| 7556 | return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST, |
| 7557 | bgp_show_type_route_map); |
| 7558 | } |
| 7559 | |
| 7560 | DEFUN (show_bgp_route_map, |
| 7561 | show_bgp_route_map_cmd, |
| 7562 | "show bgp route-map WORD", |
| 7563 | SHOW_STR |
| 7564 | BGP_STR |
| 7565 | "Display routes matching the route-map\n" |
| 7566 | "A route-map to match on\n") |
| 7567 | { |
| 7568 | return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 7569 | bgp_show_type_route_map); |
| 7570 | } |
| 7571 | |
| 7572 | ALIAS (show_bgp_route_map, |
| 7573 | show_bgp_ipv6_route_map_cmd, |
| 7574 | "show bgp ipv6 route-map WORD", |
| 7575 | SHOW_STR |
| 7576 | BGP_STR |
| 7577 | "Address family\n" |
| 7578 | "Display routes matching the route-map\n" |
| 7579 | "A route-map to match on\n") |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7580 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7581 | DEFUN (show_ip_bgp_cidr_only, |
| 7582 | show_ip_bgp_cidr_only_cmd, |
| 7583 | "show ip bgp cidr-only", |
| 7584 | SHOW_STR |
| 7585 | IP_STR |
| 7586 | BGP_STR |
| 7587 | "Display only routes with non-natural netmasks\n") |
| 7588 | { |
| 7589 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7590 | bgp_show_type_cidr_only, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | DEFUN (show_ip_bgp_flap_cidr_only, |
| 7594 | show_ip_bgp_flap_cidr_only_cmd, |
| 7595 | "show ip bgp flap-statistics cidr-only", |
| 7596 | SHOW_STR |
| 7597 | IP_STR |
| 7598 | BGP_STR |
| 7599 | "Display flap statistics of routes\n" |
| 7600 | "Display only routes with non-natural netmasks\n") |
| 7601 | { |
| 7602 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7603 | bgp_show_type_flap_cidr_only, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7604 | } |
| 7605 | |
| 7606 | DEFUN (show_ip_bgp_ipv4_cidr_only, |
| 7607 | show_ip_bgp_ipv4_cidr_only_cmd, |
| 7608 | "show ip bgp ipv4 (unicast|multicast) cidr-only", |
| 7609 | SHOW_STR |
| 7610 | IP_STR |
| 7611 | BGP_STR |
| 7612 | "Address family\n" |
| 7613 | "Address Family modifier\n" |
| 7614 | "Address Family modifier\n" |
| 7615 | "Display only routes with non-natural netmasks\n") |
| 7616 | { |
| 7617 | if (strncmp (argv[0], "m", 1) == 0) |
| 7618 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7619 | bgp_show_type_cidr_only, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7620 | |
| 7621 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7622 | bgp_show_type_cidr_only, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7623 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7624 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7625 | DEFUN (show_ip_bgp_community_all, |
| 7626 | show_ip_bgp_community_all_cmd, |
| 7627 | "show ip bgp community", |
| 7628 | SHOW_STR |
| 7629 | IP_STR |
| 7630 | BGP_STR |
| 7631 | "Display routes matching the communities\n") |
| 7632 | { |
| 7633 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7634 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7635 | } |
| 7636 | |
| 7637 | DEFUN (show_ip_bgp_ipv4_community_all, |
| 7638 | show_ip_bgp_ipv4_community_all_cmd, |
| 7639 | "show ip bgp ipv4 (unicast|multicast) community", |
| 7640 | SHOW_STR |
| 7641 | IP_STR |
| 7642 | BGP_STR |
| 7643 | "Address family\n" |
| 7644 | "Address Family modifier\n" |
| 7645 | "Address Family modifier\n" |
| 7646 | "Display routes matching the communities\n") |
| 7647 | { |
| 7648 | if (strncmp (argv[0], "m", 1) == 0) |
| 7649 | return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7650 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7651 | |
| 7652 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7653 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | #ifdef HAVE_IPV6 |
| 7657 | DEFUN (show_bgp_community_all, |
| 7658 | show_bgp_community_all_cmd, |
| 7659 | "show bgp community", |
| 7660 | SHOW_STR |
| 7661 | BGP_STR |
| 7662 | "Display routes matching the communities\n") |
| 7663 | { |
| 7664 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7665 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | ALIAS (show_bgp_community_all, |
| 7669 | show_bgp_ipv6_community_all_cmd, |
| 7670 | "show bgp ipv6 community", |
| 7671 | SHOW_STR |
| 7672 | BGP_STR |
| 7673 | "Address family\n" |
| 7674 | "Display routes matching the communities\n") |
| 7675 | |
| 7676 | /* old command */ |
| 7677 | DEFUN (show_ipv6_bgp_community_all, |
| 7678 | show_ipv6_bgp_community_all_cmd, |
| 7679 | "show ipv6 bgp community", |
| 7680 | SHOW_STR |
| 7681 | IPV6_STR |
| 7682 | BGP_STR |
| 7683 | "Display routes matching the communities\n") |
| 7684 | { |
| 7685 | return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7686 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7687 | } |
| 7688 | |
| 7689 | /* old command */ |
| 7690 | DEFUN (show_ipv6_mbgp_community_all, |
| 7691 | show_ipv6_mbgp_community_all_cmd, |
| 7692 | "show ipv6 mbgp community", |
| 7693 | SHOW_STR |
| 7694 | IPV6_STR |
| 7695 | MBGP_STR |
| 7696 | "Display routes matching the communities\n") |
| 7697 | { |
| 7698 | return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7699 | bgp_show_type_community_all, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7700 | } |
| 7701 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 7702 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 7703 | static int |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7704 | bgp_show_community (struct vty *vty, const char *view_name, int argc, |
| 7705 | const char **argv, int exact, afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7706 | { |
| 7707 | struct community *com; |
| 7708 | struct buffer *b; |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7709 | struct bgp *bgp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7710 | int i; |
| 7711 | char *str; |
| 7712 | int first = 0; |
| 7713 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7714 | /* BGP structure lookup */ |
| 7715 | if (view_name) |
| 7716 | { |
| 7717 | bgp = bgp_lookup_by_name (view_name); |
| 7718 | if (bgp == NULL) |
| 7719 | { |
| 7720 | vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE); |
| 7721 | return CMD_WARNING; |
| 7722 | } |
| 7723 | } |
| 7724 | else |
| 7725 | { |
| 7726 | bgp = bgp_get_default (); |
| 7727 | if (bgp == NULL) |
| 7728 | { |
| 7729 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 7730 | return CMD_WARNING; |
| 7731 | } |
| 7732 | } |
| 7733 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7734 | b = buffer_new (1024); |
| 7735 | for (i = 0; i < argc; i++) |
| 7736 | { |
| 7737 | if (first) |
| 7738 | buffer_putc (b, ' '); |
| 7739 | else |
| 7740 | { |
| 7741 | if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0)) |
| 7742 | continue; |
| 7743 | first = 1; |
| 7744 | } |
| 7745 | |
| 7746 | buffer_putstr (b, argv[i]); |
| 7747 | } |
| 7748 | buffer_putc (b, '\0'); |
| 7749 | |
| 7750 | str = buffer_getstr (b); |
| 7751 | buffer_free (b); |
| 7752 | |
| 7753 | com = community_str2com (str); |
ajs | 3b8b185 | 2005-01-29 18:19:13 +0000 | [diff] [blame] | 7754 | XFREE (MTYPE_TMP, str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7755 | if (! com) |
| 7756 | { |
| 7757 | vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE); |
| 7758 | return CMD_WARNING; |
| 7759 | } |
| 7760 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7761 | return bgp_show (vty, bgp, afi, safi, |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 7762 | (exact ? bgp_show_type_community_exact : |
| 7763 | bgp_show_type_community), com); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | DEFUN (show_ip_bgp_community, |
| 7767 | show_ip_bgp_community_cmd, |
| 7768 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)", |
| 7769 | SHOW_STR |
| 7770 | IP_STR |
| 7771 | BGP_STR |
| 7772 | "Display routes matching the communities\n" |
| 7773 | "community number\n" |
| 7774 | "Do not send outside local AS (well-known community)\n" |
| 7775 | "Do not advertise to any peer (well-known community)\n" |
| 7776 | "Do not export to next AS (well-known community)\n") |
| 7777 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7778 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
| 7781 | ALIAS (show_ip_bgp_community, |
| 7782 | show_ip_bgp_community2_cmd, |
| 7783 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 7784 | SHOW_STR |
| 7785 | IP_STR |
| 7786 | BGP_STR |
| 7787 | "Display routes matching the communities\n" |
| 7788 | "community number\n" |
| 7789 | "Do not send outside local AS (well-known community)\n" |
| 7790 | "Do not advertise to any peer (well-known community)\n" |
| 7791 | "Do not export to next AS (well-known community)\n" |
| 7792 | "community number\n" |
| 7793 | "Do not send outside local AS (well-known community)\n" |
| 7794 | "Do not advertise to any peer (well-known community)\n" |
| 7795 | "Do not export to next AS (well-known community)\n") |
| 7796 | |
| 7797 | ALIAS (show_ip_bgp_community, |
| 7798 | show_ip_bgp_community3_cmd, |
| 7799 | "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)", |
| 7800 | SHOW_STR |
| 7801 | IP_STR |
| 7802 | BGP_STR |
| 7803 | "Display routes matching the communities\n" |
| 7804 | "community number\n" |
| 7805 | "Do not send outside local AS (well-known community)\n" |
| 7806 | "Do not advertise to any peer (well-known community)\n" |
| 7807 | "Do not export to next AS (well-known community)\n" |
| 7808 | "community number\n" |
| 7809 | "Do not send outside local AS (well-known community)\n" |
| 7810 | "Do not advertise to any peer (well-known community)\n" |
| 7811 | "Do not export to next AS (well-known community)\n" |
| 7812 | "community number\n" |
| 7813 | "Do not send outside local AS (well-known community)\n" |
| 7814 | "Do not advertise to any peer (well-known community)\n" |
| 7815 | "Do not export to next AS (well-known community)\n") |
| 7816 | |
| 7817 | ALIAS (show_ip_bgp_community, |
| 7818 | show_ip_bgp_community4_cmd, |
| 7819 | "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)", |
| 7820 | SHOW_STR |
| 7821 | IP_STR |
| 7822 | BGP_STR |
| 7823 | "Display routes matching the communities\n" |
| 7824 | "community number\n" |
| 7825 | "Do not send outside local AS (well-known community)\n" |
| 7826 | "Do not advertise to any peer (well-known community)\n" |
| 7827 | "Do not export to next AS (well-known community)\n" |
| 7828 | "community number\n" |
| 7829 | "Do not send outside local AS (well-known community)\n" |
| 7830 | "Do not advertise to any peer (well-known community)\n" |
| 7831 | "Do not export to next AS (well-known community)\n" |
| 7832 | "community number\n" |
| 7833 | "Do not send outside local AS (well-known community)\n" |
| 7834 | "Do not advertise to any peer (well-known community)\n" |
| 7835 | "Do not export to next AS (well-known community)\n" |
| 7836 | "community number\n" |
| 7837 | "Do not send outside local AS (well-known community)\n" |
| 7838 | "Do not advertise to any peer (well-known community)\n" |
| 7839 | "Do not export to next AS (well-known community)\n") |
| 7840 | |
| 7841 | DEFUN (show_ip_bgp_ipv4_community, |
| 7842 | show_ip_bgp_ipv4_community_cmd, |
| 7843 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", |
| 7844 | SHOW_STR |
| 7845 | IP_STR |
| 7846 | BGP_STR |
| 7847 | "Address family\n" |
| 7848 | "Address Family modifier\n" |
| 7849 | "Address Family modifier\n" |
| 7850 | "Display routes matching the communities\n" |
| 7851 | "community number\n" |
| 7852 | "Do not send outside local AS (well-known community)\n" |
| 7853 | "Do not advertise to any peer (well-known community)\n" |
| 7854 | "Do not export to next AS (well-known community)\n") |
| 7855 | { |
| 7856 | if (strncmp (argv[0], "m", 1) == 0) |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7857 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7858 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7859 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 7860 | } |
| 7861 | |
| 7862 | ALIAS (show_ip_bgp_ipv4_community, |
| 7863 | show_ip_bgp_ipv4_community2_cmd, |
| 7864 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 7865 | SHOW_STR |
| 7866 | IP_STR |
| 7867 | BGP_STR |
| 7868 | "Address family\n" |
| 7869 | "Address Family modifier\n" |
| 7870 | "Address Family modifier\n" |
| 7871 | "Display routes matching the communities\n" |
| 7872 | "community number\n" |
| 7873 | "Do not send outside local AS (well-known community)\n" |
| 7874 | "Do not advertise to any peer (well-known community)\n" |
| 7875 | "Do not export to next AS (well-known community)\n" |
| 7876 | "community number\n" |
| 7877 | "Do not send outside local AS (well-known community)\n" |
| 7878 | "Do not advertise to any peer (well-known community)\n" |
| 7879 | "Do not export to next AS (well-known community)\n") |
| 7880 | |
| 7881 | ALIAS (show_ip_bgp_ipv4_community, |
| 7882 | show_ip_bgp_ipv4_community3_cmd, |
| 7883 | "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)", |
| 7884 | SHOW_STR |
| 7885 | IP_STR |
| 7886 | BGP_STR |
| 7887 | "Address family\n" |
| 7888 | "Address Family modifier\n" |
| 7889 | "Address Family modifier\n" |
| 7890 | "Display routes matching the communities\n" |
| 7891 | "community number\n" |
| 7892 | "Do not send outside local AS (well-known community)\n" |
| 7893 | "Do not advertise to any peer (well-known community)\n" |
| 7894 | "Do not export to next AS (well-known community)\n" |
| 7895 | "community number\n" |
| 7896 | "Do not send outside local AS (well-known community)\n" |
| 7897 | "Do not advertise to any peer (well-known community)\n" |
| 7898 | "Do not export to next AS (well-known community)\n" |
| 7899 | "community number\n" |
| 7900 | "Do not send outside local AS (well-known community)\n" |
| 7901 | "Do not advertise to any peer (well-known community)\n" |
| 7902 | "Do not export to next AS (well-known community)\n") |
| 7903 | |
| 7904 | ALIAS (show_ip_bgp_ipv4_community, |
| 7905 | show_ip_bgp_ipv4_community4_cmd, |
| 7906 | "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)", |
| 7907 | SHOW_STR |
| 7908 | IP_STR |
| 7909 | BGP_STR |
| 7910 | "Address family\n" |
| 7911 | "Address Family modifier\n" |
| 7912 | "Address Family modifier\n" |
| 7913 | "Display routes matching the communities\n" |
| 7914 | "community number\n" |
| 7915 | "Do not send outside local AS (well-known community)\n" |
| 7916 | "Do not advertise to any peer (well-known community)\n" |
| 7917 | "Do not export to next AS (well-known community)\n" |
| 7918 | "community number\n" |
| 7919 | "Do not send outside local AS (well-known community)\n" |
| 7920 | "Do not advertise to any peer (well-known community)\n" |
| 7921 | "Do not export to next AS (well-known community)\n" |
| 7922 | "community number\n" |
| 7923 | "Do not send outside local AS (well-known community)\n" |
| 7924 | "Do not advertise to any peer (well-known community)\n" |
| 7925 | "Do not export to next AS (well-known community)\n" |
| 7926 | "community number\n" |
| 7927 | "Do not send outside local AS (well-known community)\n" |
| 7928 | "Do not advertise to any peer (well-known community)\n" |
| 7929 | "Do not export to next AS (well-known community)\n") |
| 7930 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7931 | DEFUN (show_bgp_view_afi_safi_community_all, |
| 7932 | show_bgp_view_afi_safi_community_all_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7933 | "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7934 | SHOW_STR |
| 7935 | BGP_STR |
| 7936 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 7937 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7938 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7939 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7940 | "Address Family modifier\n" |
| 7941 | "Address Family modifier\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 7942 | "Display routes matching the communities\n") |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7943 | { |
| 7944 | int afi; |
| 7945 | int safi; |
| 7946 | struct bgp *bgp; |
| 7947 | |
| 7948 | /* BGP structure lookup. */ |
| 7949 | bgp = bgp_lookup_by_name (argv[0]); |
| 7950 | if (bgp == NULL) |
| 7951 | { |
| 7952 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 7953 | return CMD_WARNING; |
| 7954 | } |
| 7955 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7956 | afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
| 7957 | safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7958 | return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL); |
| 7959 | } |
| 7960 | |
| 7961 | DEFUN (show_bgp_view_afi_safi_community, |
| 7962 | show_bgp_view_afi_safi_community_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7963 | "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7964 | SHOW_STR |
| 7965 | BGP_STR |
| 7966 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 7967 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7968 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7969 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7970 | "Address family modifier\n" |
| 7971 | "Address family modifier\n" |
| 7972 | "Display routes matching the communities\n" |
| 7973 | "community number\n" |
| 7974 | "Do not send outside local AS (well-known community)\n" |
| 7975 | "Do not advertise to any peer (well-known community)\n" |
| 7976 | "Do not export to next AS (well-known community)\n") |
| 7977 | { |
| 7978 | int afi; |
| 7979 | int safi; |
| 7980 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7981 | afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
| 7982 | safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 7983 | return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7984 | } |
| 7985 | |
| 7986 | ALIAS (show_bgp_view_afi_safi_community, |
| 7987 | show_bgp_view_afi_safi_community2_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7988 | "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7989 | SHOW_STR |
| 7990 | BGP_STR |
| 7991 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 7992 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7993 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7994 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 7995 | "Address family modifier\n" |
| 7996 | "Address family modifier\n" |
| 7997 | "Display routes matching the communities\n" |
| 7998 | "community number\n" |
| 7999 | "Do not send outside local AS (well-known community)\n" |
| 8000 | "Do not advertise to any peer (well-known community)\n" |
| 8001 | "Do not export to next AS (well-known community)\n" |
| 8002 | "community number\n" |
| 8003 | "Do not send outside local AS (well-known community)\n" |
| 8004 | "Do not advertise to any peer (well-known community)\n" |
| 8005 | "Do not export to next AS (well-known community)\n") |
| 8006 | |
| 8007 | ALIAS (show_bgp_view_afi_safi_community, |
| 8008 | show_bgp_view_afi_safi_community3_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8009 | "show bgp view 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)", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8010 | SHOW_STR |
| 8011 | BGP_STR |
| 8012 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 8013 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8014 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8015 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8016 | "Address family modifier\n" |
| 8017 | "Address family modifier\n" |
| 8018 | "Display routes matching the communities\n" |
| 8019 | "community number\n" |
| 8020 | "Do not send outside local AS (well-known community)\n" |
| 8021 | "Do not advertise to any peer (well-known community)\n" |
| 8022 | "Do not export to next AS (well-known community)\n" |
| 8023 | "community number\n" |
| 8024 | "Do not send outside local AS (well-known community)\n" |
| 8025 | "Do not advertise to any peer (well-known community)\n" |
| 8026 | "Do not export to next AS (well-known community)\n" |
| 8027 | "community number\n" |
| 8028 | "Do not send outside local AS (well-known community)\n" |
| 8029 | "Do not advertise to any peer (well-known community)\n" |
| 8030 | "Do not export to next AS (well-known community)\n") |
| 8031 | |
| 8032 | ALIAS (show_bgp_view_afi_safi_community, |
| 8033 | show_bgp_view_afi_safi_community4_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8034 | "show bgp view 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)", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8035 | SHOW_STR |
| 8036 | BGP_STR |
| 8037 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 8038 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8039 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8040 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8041 | "Address family modifier\n" |
| 8042 | "Address family modifier\n" |
| 8043 | "Display routes matching the communities\n" |
| 8044 | "community number\n" |
| 8045 | "Do not send outside local AS (well-known community)\n" |
| 8046 | "Do not advertise to any peer (well-known community)\n" |
| 8047 | "Do not export to next AS (well-known community)\n" |
| 8048 | "community number\n" |
| 8049 | "Do not send outside local AS (well-known community)\n" |
| 8050 | "Do not advertise to any peer (well-known community)\n" |
| 8051 | "Do not export to next AS (well-known community)\n" |
| 8052 | "community number\n" |
| 8053 | "Do not send outside local AS (well-known community)\n" |
| 8054 | "Do not advertise to any peer (well-known community)\n" |
| 8055 | "Do not export to next AS (well-known community)\n" |
| 8056 | "community number\n" |
| 8057 | "Do not send outside local AS (well-known community)\n" |
| 8058 | "Do not advertise to any peer (well-known community)\n" |
| 8059 | "Do not export to next AS (well-known community)\n") |
| 8060 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8061 | DEFUN (show_ip_bgp_community_exact, |
| 8062 | show_ip_bgp_community_exact_cmd, |
| 8063 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8064 | SHOW_STR |
| 8065 | IP_STR |
| 8066 | BGP_STR |
| 8067 | "Display routes matching the communities\n" |
| 8068 | "community number\n" |
| 8069 | "Do not send outside local AS (well-known community)\n" |
| 8070 | "Do not advertise to any peer (well-known community)\n" |
| 8071 | "Do not export to next AS (well-known community)\n" |
| 8072 | "Exact match of the communities") |
| 8073 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8074 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | ALIAS (show_ip_bgp_community_exact, |
| 8078 | show_ip_bgp_community2_exact_cmd, |
| 8079 | "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8080 | SHOW_STR |
| 8081 | IP_STR |
| 8082 | BGP_STR |
| 8083 | "Display routes matching the communities\n" |
| 8084 | "community number\n" |
| 8085 | "Do not send outside local AS (well-known community)\n" |
| 8086 | "Do not advertise to any peer (well-known community)\n" |
| 8087 | "Do not export to next AS (well-known community)\n" |
| 8088 | "community number\n" |
| 8089 | "Do not send outside local AS (well-known community)\n" |
| 8090 | "Do not advertise to any peer (well-known community)\n" |
| 8091 | "Do not export to next AS (well-known community)\n" |
| 8092 | "Exact match of the communities") |
| 8093 | |
| 8094 | ALIAS (show_ip_bgp_community_exact, |
| 8095 | show_ip_bgp_community3_exact_cmd, |
| 8096 | "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", |
| 8097 | SHOW_STR |
| 8098 | IP_STR |
| 8099 | BGP_STR |
| 8100 | "Display routes matching the communities\n" |
| 8101 | "community number\n" |
| 8102 | "Do not send outside local AS (well-known community)\n" |
| 8103 | "Do not advertise to any peer (well-known community)\n" |
| 8104 | "Do not export to next AS (well-known community)\n" |
| 8105 | "community number\n" |
| 8106 | "Do not send outside local AS (well-known community)\n" |
| 8107 | "Do not advertise to any peer (well-known community)\n" |
| 8108 | "Do not export to next AS (well-known community)\n" |
| 8109 | "community number\n" |
| 8110 | "Do not send outside local AS (well-known community)\n" |
| 8111 | "Do not advertise to any peer (well-known community)\n" |
| 8112 | "Do not export to next AS (well-known community)\n" |
| 8113 | "Exact match of the communities") |
| 8114 | |
| 8115 | ALIAS (show_ip_bgp_community_exact, |
| 8116 | show_ip_bgp_community4_exact_cmd, |
| 8117 | "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", |
| 8118 | SHOW_STR |
| 8119 | IP_STR |
| 8120 | BGP_STR |
| 8121 | "Display routes matching the communities\n" |
| 8122 | "community number\n" |
| 8123 | "Do not send outside local AS (well-known community)\n" |
| 8124 | "Do not advertise to any peer (well-known community)\n" |
| 8125 | "Do not export to next AS (well-known community)\n" |
| 8126 | "community number\n" |
| 8127 | "Do not send outside local AS (well-known community)\n" |
| 8128 | "Do not advertise to any peer (well-known community)\n" |
| 8129 | "Do not export to next AS (well-known community)\n" |
| 8130 | "community number\n" |
| 8131 | "Do not send outside local AS (well-known community)\n" |
| 8132 | "Do not advertise to any peer (well-known community)\n" |
| 8133 | "Do not export to next AS (well-known community)\n" |
| 8134 | "community number\n" |
| 8135 | "Do not send outside local AS (well-known community)\n" |
| 8136 | "Do not advertise to any peer (well-known community)\n" |
| 8137 | "Do not export to next AS (well-known community)\n" |
| 8138 | "Exact match of the communities") |
| 8139 | |
| 8140 | DEFUN (show_ip_bgp_ipv4_community_exact, |
| 8141 | show_ip_bgp_ipv4_community_exact_cmd, |
| 8142 | "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8143 | SHOW_STR |
| 8144 | IP_STR |
| 8145 | BGP_STR |
| 8146 | "Address family\n" |
| 8147 | "Address Family modifier\n" |
| 8148 | "Address Family modifier\n" |
| 8149 | "Display routes matching the communities\n" |
| 8150 | "community number\n" |
| 8151 | "Do not send outside local AS (well-known community)\n" |
| 8152 | "Do not advertise to any peer (well-known community)\n" |
| 8153 | "Do not export to next AS (well-known community)\n" |
| 8154 | "Exact match of the communities") |
| 8155 | { |
| 8156 | if (strncmp (argv[0], "m", 1) == 0) |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8157 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8158 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8159 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8160 | } |
| 8161 | |
| 8162 | ALIAS (show_ip_bgp_ipv4_community_exact, |
| 8163 | show_ip_bgp_ipv4_community2_exact_cmd, |
| 8164 | "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", |
| 8165 | SHOW_STR |
| 8166 | IP_STR |
| 8167 | BGP_STR |
| 8168 | "Address family\n" |
| 8169 | "Address Family modifier\n" |
| 8170 | "Address Family modifier\n" |
| 8171 | "Display routes matching the communities\n" |
| 8172 | "community number\n" |
| 8173 | "Do not send outside local AS (well-known community)\n" |
| 8174 | "Do not advertise to any peer (well-known community)\n" |
| 8175 | "Do not export to next AS (well-known community)\n" |
| 8176 | "community number\n" |
| 8177 | "Do not send outside local AS (well-known community)\n" |
| 8178 | "Do not advertise to any peer (well-known community)\n" |
| 8179 | "Do not export to next AS (well-known community)\n" |
| 8180 | "Exact match of the communities") |
| 8181 | |
| 8182 | ALIAS (show_ip_bgp_ipv4_community_exact, |
| 8183 | show_ip_bgp_ipv4_community3_exact_cmd, |
| 8184 | "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", |
| 8185 | SHOW_STR |
| 8186 | IP_STR |
| 8187 | BGP_STR |
| 8188 | "Address family\n" |
| 8189 | "Address Family modifier\n" |
| 8190 | "Address Family modifier\n" |
| 8191 | "Display routes matching the communities\n" |
| 8192 | "community number\n" |
| 8193 | "Do not send outside local AS (well-known community)\n" |
| 8194 | "Do not advertise to any peer (well-known community)\n" |
| 8195 | "Do not export to next AS (well-known community)\n" |
| 8196 | "community number\n" |
| 8197 | "Do not send outside local AS (well-known community)\n" |
| 8198 | "Do not advertise to any peer (well-known community)\n" |
| 8199 | "Do not export to next AS (well-known community)\n" |
| 8200 | "community number\n" |
| 8201 | "Do not send outside local AS (well-known community)\n" |
| 8202 | "Do not advertise to any peer (well-known community)\n" |
| 8203 | "Do not export to next AS (well-known community)\n" |
| 8204 | "Exact match of the communities") |
| 8205 | |
| 8206 | ALIAS (show_ip_bgp_ipv4_community_exact, |
| 8207 | show_ip_bgp_ipv4_community4_exact_cmd, |
| 8208 | "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", |
| 8209 | SHOW_STR |
| 8210 | IP_STR |
| 8211 | BGP_STR |
| 8212 | "Address family\n" |
| 8213 | "Address Family modifier\n" |
| 8214 | "Address Family modifier\n" |
| 8215 | "Display routes matching the communities\n" |
| 8216 | "community number\n" |
| 8217 | "Do not send outside local AS (well-known community)\n" |
| 8218 | "Do not advertise to any peer (well-known community)\n" |
| 8219 | "Do not export to next AS (well-known community)\n" |
| 8220 | "community number\n" |
| 8221 | "Do not send outside local AS (well-known community)\n" |
| 8222 | "Do not advertise to any peer (well-known community)\n" |
| 8223 | "Do not export to next AS (well-known community)\n" |
| 8224 | "community number\n" |
| 8225 | "Do not send outside local AS (well-known community)\n" |
| 8226 | "Do not advertise to any peer (well-known community)\n" |
| 8227 | "Do not export to next AS (well-known community)\n" |
| 8228 | "community number\n" |
| 8229 | "Do not send outside local AS (well-known community)\n" |
| 8230 | "Do not advertise to any peer (well-known community)\n" |
| 8231 | "Do not export to next AS (well-known community)\n" |
| 8232 | "Exact match of the communities") |
| 8233 | |
| 8234 | #ifdef HAVE_IPV6 |
| 8235 | DEFUN (show_bgp_community, |
| 8236 | show_bgp_community_cmd, |
| 8237 | "show bgp community (AA:NN|local-AS|no-advertise|no-export)", |
| 8238 | SHOW_STR |
| 8239 | BGP_STR |
| 8240 | "Display routes matching the communities\n" |
| 8241 | "community number\n" |
| 8242 | "Do not send outside local AS (well-known community)\n" |
| 8243 | "Do not advertise to any peer (well-known community)\n" |
| 8244 | "Do not export to next AS (well-known community)\n") |
| 8245 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8246 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | ALIAS (show_bgp_community, |
| 8250 | show_bgp_ipv6_community_cmd, |
| 8251 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)", |
| 8252 | SHOW_STR |
| 8253 | BGP_STR |
| 8254 | "Address family\n" |
| 8255 | "Display routes matching the communities\n" |
| 8256 | "community number\n" |
| 8257 | "Do not send outside local AS (well-known community)\n" |
| 8258 | "Do not advertise to any peer (well-known community)\n" |
| 8259 | "Do not export to next AS (well-known community)\n") |
| 8260 | |
| 8261 | ALIAS (show_bgp_community, |
| 8262 | show_bgp_community2_cmd, |
| 8263 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 8264 | SHOW_STR |
| 8265 | BGP_STR |
| 8266 | "Display routes matching the communities\n" |
| 8267 | "community number\n" |
| 8268 | "Do not send outside local AS (well-known community)\n" |
| 8269 | "Do not advertise to any peer (well-known community)\n" |
| 8270 | "Do not export to next AS (well-known community)\n" |
| 8271 | "community number\n" |
| 8272 | "Do not send outside local AS (well-known community)\n" |
| 8273 | "Do not advertise to any peer (well-known community)\n" |
| 8274 | "Do not export to next AS (well-known community)\n") |
| 8275 | |
| 8276 | ALIAS (show_bgp_community, |
| 8277 | show_bgp_ipv6_community2_cmd, |
| 8278 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 8279 | SHOW_STR |
| 8280 | BGP_STR |
| 8281 | "Address family\n" |
| 8282 | "Display routes matching the communities\n" |
| 8283 | "community number\n" |
| 8284 | "Do not send outside local AS (well-known community)\n" |
| 8285 | "Do not advertise to any peer (well-known community)\n" |
| 8286 | "Do not export to next AS (well-known community)\n" |
| 8287 | "community number\n" |
| 8288 | "Do not send outside local AS (well-known community)\n" |
| 8289 | "Do not advertise to any peer (well-known community)\n" |
| 8290 | "Do not export to next AS (well-known community)\n") |
| 8291 | |
| 8292 | ALIAS (show_bgp_community, |
| 8293 | show_bgp_community3_cmd, |
| 8294 | "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)", |
| 8295 | SHOW_STR |
| 8296 | BGP_STR |
| 8297 | "Display routes matching the communities\n" |
| 8298 | "community number\n" |
| 8299 | "Do not send outside local AS (well-known community)\n" |
| 8300 | "Do not advertise to any peer (well-known community)\n" |
| 8301 | "Do not export to next AS (well-known community)\n" |
| 8302 | "community number\n" |
| 8303 | "Do not send outside local AS (well-known community)\n" |
| 8304 | "Do not advertise to any peer (well-known community)\n" |
| 8305 | "Do not export to next AS (well-known community)\n" |
| 8306 | "community number\n" |
| 8307 | "Do not send outside local AS (well-known community)\n" |
| 8308 | "Do not advertise to any peer (well-known community)\n" |
| 8309 | "Do not export to next AS (well-known community)\n") |
| 8310 | |
| 8311 | ALIAS (show_bgp_community, |
| 8312 | show_bgp_ipv6_community3_cmd, |
| 8313 | "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)", |
| 8314 | SHOW_STR |
| 8315 | BGP_STR |
| 8316 | "Address family\n" |
| 8317 | "Display routes matching the communities\n" |
| 8318 | "community number\n" |
| 8319 | "Do not send outside local AS (well-known community)\n" |
| 8320 | "Do not advertise to any peer (well-known community)\n" |
| 8321 | "Do not export to next AS (well-known community)\n" |
| 8322 | "community number\n" |
| 8323 | "Do not send outside local AS (well-known community)\n" |
| 8324 | "Do not advertise to any peer (well-known community)\n" |
| 8325 | "Do not export to next AS (well-known community)\n" |
| 8326 | "community number\n" |
| 8327 | "Do not send outside local AS (well-known community)\n" |
| 8328 | "Do not advertise to any peer (well-known community)\n" |
| 8329 | "Do not export to next AS (well-known community)\n") |
| 8330 | |
| 8331 | ALIAS (show_bgp_community, |
| 8332 | show_bgp_community4_cmd, |
| 8333 | "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)", |
| 8334 | SHOW_STR |
| 8335 | BGP_STR |
| 8336 | "Display routes matching the communities\n" |
| 8337 | "community number\n" |
| 8338 | "Do not send outside local AS (well-known community)\n" |
| 8339 | "Do not advertise to any peer (well-known community)\n" |
| 8340 | "Do not export to next AS (well-known community)\n" |
| 8341 | "community number\n" |
| 8342 | "Do not send outside local AS (well-known community)\n" |
| 8343 | "Do not advertise to any peer (well-known community)\n" |
| 8344 | "Do not export to next AS (well-known community)\n" |
| 8345 | "community number\n" |
| 8346 | "Do not send outside local AS (well-known community)\n" |
| 8347 | "Do not advertise to any peer (well-known community)\n" |
| 8348 | "Do not export to next AS (well-known community)\n" |
| 8349 | "community number\n" |
| 8350 | "Do not send outside local AS (well-known community)\n" |
| 8351 | "Do not advertise to any peer (well-known community)\n" |
| 8352 | "Do not export to next AS (well-known community)\n") |
| 8353 | |
| 8354 | ALIAS (show_bgp_community, |
| 8355 | show_bgp_ipv6_community4_cmd, |
| 8356 | "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)", |
| 8357 | SHOW_STR |
| 8358 | BGP_STR |
| 8359 | "Address family\n" |
| 8360 | "Display routes matching the communities\n" |
| 8361 | "community number\n" |
| 8362 | "Do not send outside local AS (well-known community)\n" |
| 8363 | "Do not advertise to any peer (well-known community)\n" |
| 8364 | "Do not export to next AS (well-known community)\n" |
| 8365 | "community number\n" |
| 8366 | "Do not send outside local AS (well-known community)\n" |
| 8367 | "Do not advertise to any peer (well-known community)\n" |
| 8368 | "Do not export to next AS (well-known community)\n" |
| 8369 | "community number\n" |
| 8370 | "Do not send outside local AS (well-known community)\n" |
| 8371 | "Do not advertise to any peer (well-known community)\n" |
| 8372 | "Do not export to next AS (well-known community)\n" |
| 8373 | "community number\n" |
| 8374 | "Do not send outside local AS (well-known community)\n" |
| 8375 | "Do not advertise to any peer (well-known community)\n" |
| 8376 | "Do not export to next AS (well-known community)\n") |
| 8377 | |
| 8378 | /* old command */ |
| 8379 | DEFUN (show_ipv6_bgp_community, |
| 8380 | show_ipv6_bgp_community_cmd, |
| 8381 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)", |
| 8382 | SHOW_STR |
| 8383 | IPV6_STR |
| 8384 | BGP_STR |
| 8385 | "Display routes matching the communities\n" |
| 8386 | "community number\n" |
| 8387 | "Do not send outside local AS (well-known community)\n" |
| 8388 | "Do not advertise to any peer (well-known community)\n" |
| 8389 | "Do not export to next AS (well-known community)\n") |
| 8390 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8391 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8392 | } |
| 8393 | |
| 8394 | /* old command */ |
| 8395 | ALIAS (show_ipv6_bgp_community, |
| 8396 | show_ipv6_bgp_community2_cmd, |
| 8397 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 8398 | SHOW_STR |
| 8399 | IPV6_STR |
| 8400 | BGP_STR |
| 8401 | "Display routes matching the communities\n" |
| 8402 | "community number\n" |
| 8403 | "Do not send outside local AS (well-known community)\n" |
| 8404 | "Do not advertise to any peer (well-known community)\n" |
| 8405 | "Do not export to next AS (well-known community)\n" |
| 8406 | "community number\n" |
| 8407 | "Do not send outside local AS (well-known community)\n" |
| 8408 | "Do not advertise to any peer (well-known community)\n" |
| 8409 | "Do not export to next AS (well-known community)\n") |
| 8410 | |
| 8411 | /* old command */ |
| 8412 | ALIAS (show_ipv6_bgp_community, |
| 8413 | show_ipv6_bgp_community3_cmd, |
| 8414 | "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)", |
| 8415 | SHOW_STR |
| 8416 | IPV6_STR |
| 8417 | BGP_STR |
| 8418 | "Display routes matching the communities\n" |
| 8419 | "community number\n" |
| 8420 | "Do not send outside local AS (well-known community)\n" |
| 8421 | "Do not advertise to any peer (well-known community)\n" |
| 8422 | "Do not export to next AS (well-known community)\n" |
| 8423 | "community number\n" |
| 8424 | "Do not send outside local AS (well-known community)\n" |
| 8425 | "Do not advertise to any peer (well-known community)\n" |
| 8426 | "Do not export to next AS (well-known community)\n" |
| 8427 | "community number\n" |
| 8428 | "Do not send outside local AS (well-known community)\n" |
| 8429 | "Do not advertise to any peer (well-known community)\n" |
| 8430 | "Do not export to next AS (well-known community)\n") |
| 8431 | |
| 8432 | /* old command */ |
| 8433 | ALIAS (show_ipv6_bgp_community, |
| 8434 | show_ipv6_bgp_community4_cmd, |
| 8435 | "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)", |
| 8436 | SHOW_STR |
| 8437 | IPV6_STR |
| 8438 | BGP_STR |
| 8439 | "Display routes matching the communities\n" |
| 8440 | "community number\n" |
| 8441 | "Do not send outside local AS (well-known community)\n" |
| 8442 | "Do not advertise to any peer (well-known community)\n" |
| 8443 | "Do not export to next AS (well-known community)\n" |
| 8444 | "community number\n" |
| 8445 | "Do not send outside local AS (well-known community)\n" |
| 8446 | "Do not advertise to any peer (well-known community)\n" |
| 8447 | "Do not export to next AS (well-known community)\n" |
| 8448 | "community number\n" |
| 8449 | "Do not send outside local AS (well-known community)\n" |
| 8450 | "Do not advertise to any peer (well-known community)\n" |
| 8451 | "Do not export to next AS (well-known community)\n" |
| 8452 | "community number\n" |
| 8453 | "Do not send outside local AS (well-known community)\n" |
| 8454 | "Do not advertise to any peer (well-known community)\n" |
| 8455 | "Do not export to next AS (well-known community)\n") |
| 8456 | |
| 8457 | DEFUN (show_bgp_community_exact, |
| 8458 | show_bgp_community_exact_cmd, |
| 8459 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8460 | SHOW_STR |
| 8461 | BGP_STR |
| 8462 | "Display routes matching the communities\n" |
| 8463 | "community number\n" |
| 8464 | "Do not send outside local AS (well-known community)\n" |
| 8465 | "Do not advertise to any peer (well-known community)\n" |
| 8466 | "Do not export to next AS (well-known community)\n" |
| 8467 | "Exact match of the communities") |
| 8468 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8469 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8470 | } |
| 8471 | |
| 8472 | ALIAS (show_bgp_community_exact, |
| 8473 | show_bgp_ipv6_community_exact_cmd, |
| 8474 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8475 | SHOW_STR |
| 8476 | BGP_STR |
| 8477 | "Address family\n" |
| 8478 | "Display routes matching the communities\n" |
| 8479 | "community number\n" |
| 8480 | "Do not send outside local AS (well-known community)\n" |
| 8481 | "Do not advertise to any peer (well-known community)\n" |
| 8482 | "Do not export to next AS (well-known community)\n" |
| 8483 | "Exact match of the communities") |
| 8484 | |
| 8485 | ALIAS (show_bgp_community_exact, |
| 8486 | show_bgp_community2_exact_cmd, |
| 8487 | "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8488 | SHOW_STR |
| 8489 | BGP_STR |
| 8490 | "Display routes matching the communities\n" |
| 8491 | "community number\n" |
| 8492 | "Do not send outside local AS (well-known community)\n" |
| 8493 | "Do not advertise to any peer (well-known community)\n" |
| 8494 | "Do not export to next AS (well-known community)\n" |
| 8495 | "community number\n" |
| 8496 | "Do not send outside local AS (well-known community)\n" |
| 8497 | "Do not advertise to any peer (well-known community)\n" |
| 8498 | "Do not export to next AS (well-known community)\n" |
| 8499 | "Exact match of the communities") |
| 8500 | |
| 8501 | ALIAS (show_bgp_community_exact, |
| 8502 | show_bgp_ipv6_community2_exact_cmd, |
| 8503 | "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8504 | SHOW_STR |
| 8505 | BGP_STR |
| 8506 | "Address family\n" |
| 8507 | "Display routes matching the communities\n" |
| 8508 | "community number\n" |
| 8509 | "Do not send outside local AS (well-known community)\n" |
| 8510 | "Do not advertise to any peer (well-known community)\n" |
| 8511 | "Do not export to next AS (well-known community)\n" |
| 8512 | "community number\n" |
| 8513 | "Do not send outside local AS (well-known community)\n" |
| 8514 | "Do not advertise to any peer (well-known community)\n" |
| 8515 | "Do not export to next AS (well-known community)\n" |
| 8516 | "Exact match of the communities") |
| 8517 | |
| 8518 | ALIAS (show_bgp_community_exact, |
| 8519 | show_bgp_community3_exact_cmd, |
| 8520 | "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", |
| 8521 | SHOW_STR |
| 8522 | BGP_STR |
| 8523 | "Display routes matching the communities\n" |
| 8524 | "community number\n" |
| 8525 | "Do not send outside local AS (well-known community)\n" |
| 8526 | "Do not advertise to any peer (well-known community)\n" |
| 8527 | "Do not export to next AS (well-known community)\n" |
| 8528 | "community number\n" |
| 8529 | "Do not send outside local AS (well-known community)\n" |
| 8530 | "Do not advertise to any peer (well-known community)\n" |
| 8531 | "Do not export to next AS (well-known community)\n" |
| 8532 | "community number\n" |
| 8533 | "Do not send outside local AS (well-known community)\n" |
| 8534 | "Do not advertise to any peer (well-known community)\n" |
| 8535 | "Do not export to next AS (well-known community)\n" |
| 8536 | "Exact match of the communities") |
| 8537 | |
| 8538 | ALIAS (show_bgp_community_exact, |
| 8539 | show_bgp_ipv6_community3_exact_cmd, |
| 8540 | "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", |
| 8541 | SHOW_STR |
| 8542 | BGP_STR |
| 8543 | "Address family\n" |
| 8544 | "Display routes matching the communities\n" |
| 8545 | "community number\n" |
| 8546 | "Do not send outside local AS (well-known community)\n" |
| 8547 | "Do not advertise to any peer (well-known community)\n" |
| 8548 | "Do not export to next AS (well-known community)\n" |
| 8549 | "community number\n" |
| 8550 | "Do not send outside local AS (well-known community)\n" |
| 8551 | "Do not advertise to any peer (well-known community)\n" |
| 8552 | "Do not export to next AS (well-known community)\n" |
| 8553 | "community number\n" |
| 8554 | "Do not send outside local AS (well-known community)\n" |
| 8555 | "Do not advertise to any peer (well-known community)\n" |
| 8556 | "Do not export to next AS (well-known community)\n" |
| 8557 | "Exact match of the communities") |
| 8558 | |
| 8559 | ALIAS (show_bgp_community_exact, |
| 8560 | show_bgp_community4_exact_cmd, |
| 8561 | "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", |
| 8562 | SHOW_STR |
| 8563 | BGP_STR |
| 8564 | "Display routes matching the communities\n" |
| 8565 | "community number\n" |
| 8566 | "Do not send outside local AS (well-known community)\n" |
| 8567 | "Do not advertise to any peer (well-known community)\n" |
| 8568 | "Do not export to next AS (well-known community)\n" |
| 8569 | "community number\n" |
| 8570 | "Do not send outside local AS (well-known community)\n" |
| 8571 | "Do not advertise to any peer (well-known community)\n" |
| 8572 | "Do not export to next AS (well-known community)\n" |
| 8573 | "community number\n" |
| 8574 | "Do not send outside local AS (well-known community)\n" |
| 8575 | "Do not advertise to any peer (well-known community)\n" |
| 8576 | "Do not export to next AS (well-known community)\n" |
| 8577 | "community number\n" |
| 8578 | "Do not send outside local AS (well-known community)\n" |
| 8579 | "Do not advertise to any peer (well-known community)\n" |
| 8580 | "Do not export to next AS (well-known community)\n" |
| 8581 | "Exact match of the communities") |
| 8582 | |
| 8583 | ALIAS (show_bgp_community_exact, |
| 8584 | show_bgp_ipv6_community4_exact_cmd, |
| 8585 | "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", |
| 8586 | SHOW_STR |
| 8587 | BGP_STR |
| 8588 | "Address family\n" |
| 8589 | "Display routes matching the communities\n" |
| 8590 | "community number\n" |
| 8591 | "Do not send outside local AS (well-known community)\n" |
| 8592 | "Do not advertise to any peer (well-known community)\n" |
| 8593 | "Do not export to next AS (well-known community)\n" |
| 8594 | "community number\n" |
| 8595 | "Do not send outside local AS (well-known community)\n" |
| 8596 | "Do not advertise to any peer (well-known community)\n" |
| 8597 | "Do not export to next AS (well-known community)\n" |
| 8598 | "community number\n" |
| 8599 | "Do not send outside local AS (well-known community)\n" |
| 8600 | "Do not advertise to any peer (well-known community)\n" |
| 8601 | "Do not export to next AS (well-known community)\n" |
| 8602 | "community number\n" |
| 8603 | "Do not send outside local AS (well-known community)\n" |
| 8604 | "Do not advertise to any peer (well-known community)\n" |
| 8605 | "Do not export to next AS (well-known community)\n" |
| 8606 | "Exact match of the communities") |
| 8607 | |
| 8608 | /* old command */ |
| 8609 | DEFUN (show_ipv6_bgp_community_exact, |
| 8610 | show_ipv6_bgp_community_exact_cmd, |
| 8611 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8612 | SHOW_STR |
| 8613 | IPV6_STR |
| 8614 | BGP_STR |
| 8615 | "Display routes matching the communities\n" |
| 8616 | "community number\n" |
| 8617 | "Do not send outside local AS (well-known community)\n" |
| 8618 | "Do not advertise to any peer (well-known community)\n" |
| 8619 | "Do not export to next AS (well-known community)\n" |
| 8620 | "Exact match of the communities") |
| 8621 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8622 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8623 | } |
| 8624 | |
| 8625 | /* old command */ |
| 8626 | ALIAS (show_ipv6_bgp_community_exact, |
| 8627 | show_ipv6_bgp_community2_exact_cmd, |
| 8628 | "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8629 | SHOW_STR |
| 8630 | IPV6_STR |
| 8631 | BGP_STR |
| 8632 | "Display routes matching the communities\n" |
| 8633 | "community number\n" |
| 8634 | "Do not send outside local AS (well-known community)\n" |
| 8635 | "Do not advertise to any peer (well-known community)\n" |
| 8636 | "Do not export to next AS (well-known community)\n" |
| 8637 | "community number\n" |
| 8638 | "Do not send outside local AS (well-known community)\n" |
| 8639 | "Do not advertise to any peer (well-known community)\n" |
| 8640 | "Do not export to next AS (well-known community)\n" |
| 8641 | "Exact match of the communities") |
| 8642 | |
| 8643 | /* old command */ |
| 8644 | ALIAS (show_ipv6_bgp_community_exact, |
| 8645 | show_ipv6_bgp_community3_exact_cmd, |
| 8646 | "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", |
| 8647 | SHOW_STR |
| 8648 | IPV6_STR |
| 8649 | BGP_STR |
| 8650 | "Display routes matching the communities\n" |
| 8651 | "community number\n" |
| 8652 | "Do not send outside local AS (well-known community)\n" |
| 8653 | "Do not advertise to any peer (well-known community)\n" |
| 8654 | "Do not export to next AS (well-known community)\n" |
| 8655 | "community number\n" |
| 8656 | "Do not send outside local AS (well-known community)\n" |
| 8657 | "Do not advertise to any peer (well-known community)\n" |
| 8658 | "Do not export to next AS (well-known community)\n" |
| 8659 | "community number\n" |
| 8660 | "Do not send outside local AS (well-known community)\n" |
| 8661 | "Do not advertise to any peer (well-known community)\n" |
| 8662 | "Do not export to next AS (well-known community)\n" |
| 8663 | "Exact match of the communities") |
| 8664 | |
| 8665 | /* old command */ |
| 8666 | ALIAS (show_ipv6_bgp_community_exact, |
| 8667 | show_ipv6_bgp_community4_exact_cmd, |
| 8668 | "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", |
| 8669 | SHOW_STR |
| 8670 | IPV6_STR |
| 8671 | BGP_STR |
| 8672 | "Display routes matching the communities\n" |
| 8673 | "community number\n" |
| 8674 | "Do not send outside local AS (well-known community)\n" |
| 8675 | "Do not advertise to any peer (well-known community)\n" |
| 8676 | "Do not export to next AS (well-known community)\n" |
| 8677 | "community number\n" |
| 8678 | "Do not send outside local AS (well-known community)\n" |
| 8679 | "Do not advertise to any peer (well-known community)\n" |
| 8680 | "Do not export to next AS (well-known community)\n" |
| 8681 | "community number\n" |
| 8682 | "Do not send outside local AS (well-known community)\n" |
| 8683 | "Do not advertise to any peer (well-known community)\n" |
| 8684 | "Do not export to next AS (well-known community)\n" |
| 8685 | "community number\n" |
| 8686 | "Do not send outside local AS (well-known community)\n" |
| 8687 | "Do not advertise to any peer (well-known community)\n" |
| 8688 | "Do not export to next AS (well-known community)\n" |
| 8689 | "Exact match of the communities") |
| 8690 | |
| 8691 | /* old command */ |
| 8692 | DEFUN (show_ipv6_mbgp_community, |
| 8693 | show_ipv6_mbgp_community_cmd, |
| 8694 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)", |
| 8695 | SHOW_STR |
| 8696 | IPV6_STR |
| 8697 | MBGP_STR |
| 8698 | "Display routes matching the communities\n" |
| 8699 | "community number\n" |
| 8700 | "Do not send outside local AS (well-known community)\n" |
| 8701 | "Do not advertise to any peer (well-known community)\n" |
| 8702 | "Do not export to next AS (well-known community)\n") |
| 8703 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8704 | return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8705 | } |
| 8706 | |
| 8707 | /* old command */ |
| 8708 | ALIAS (show_ipv6_mbgp_community, |
| 8709 | show_ipv6_mbgp_community2_cmd, |
| 8710 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)", |
| 8711 | SHOW_STR |
| 8712 | IPV6_STR |
| 8713 | MBGP_STR |
| 8714 | "Display routes matching the communities\n" |
| 8715 | "community number\n" |
| 8716 | "Do not send outside local AS (well-known community)\n" |
| 8717 | "Do not advertise to any peer (well-known community)\n" |
| 8718 | "Do not export to next AS (well-known community)\n" |
| 8719 | "community number\n" |
| 8720 | "Do not send outside local AS (well-known community)\n" |
| 8721 | "Do not advertise to any peer (well-known community)\n" |
| 8722 | "Do not export to next AS (well-known community)\n") |
| 8723 | |
| 8724 | /* old command */ |
| 8725 | ALIAS (show_ipv6_mbgp_community, |
| 8726 | show_ipv6_mbgp_community3_cmd, |
| 8727 | "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)", |
| 8728 | SHOW_STR |
| 8729 | IPV6_STR |
| 8730 | MBGP_STR |
| 8731 | "Display routes matching the communities\n" |
| 8732 | "community number\n" |
| 8733 | "Do not send outside local AS (well-known community)\n" |
| 8734 | "Do not advertise to any peer (well-known community)\n" |
| 8735 | "Do not export to next AS (well-known community)\n" |
| 8736 | "community number\n" |
| 8737 | "Do not send outside local AS (well-known community)\n" |
| 8738 | "Do not advertise to any peer (well-known community)\n" |
| 8739 | "Do not export to next AS (well-known community)\n" |
| 8740 | "community number\n" |
| 8741 | "Do not send outside local AS (well-known community)\n" |
| 8742 | "Do not advertise to any peer (well-known community)\n" |
| 8743 | "Do not export to next AS (well-known community)\n") |
| 8744 | |
| 8745 | /* old command */ |
| 8746 | ALIAS (show_ipv6_mbgp_community, |
| 8747 | show_ipv6_mbgp_community4_cmd, |
| 8748 | "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)", |
| 8749 | SHOW_STR |
| 8750 | IPV6_STR |
| 8751 | MBGP_STR |
| 8752 | "Display routes matching the communities\n" |
| 8753 | "community number\n" |
| 8754 | "Do not send outside local AS (well-known community)\n" |
| 8755 | "Do not advertise to any peer (well-known community)\n" |
| 8756 | "Do not export to next AS (well-known community)\n" |
| 8757 | "community number\n" |
| 8758 | "Do not send outside local AS (well-known community)\n" |
| 8759 | "Do not advertise to any peer (well-known community)\n" |
| 8760 | "Do not export to next AS (well-known community)\n" |
| 8761 | "community number\n" |
| 8762 | "Do not send outside local AS (well-known community)\n" |
| 8763 | "Do not advertise to any peer (well-known community)\n" |
| 8764 | "Do not export to next AS (well-known community)\n" |
| 8765 | "community number\n" |
| 8766 | "Do not send outside local AS (well-known community)\n" |
| 8767 | "Do not advertise to any peer (well-known community)\n" |
| 8768 | "Do not export to next AS (well-known community)\n") |
| 8769 | |
| 8770 | /* old command */ |
| 8771 | DEFUN (show_ipv6_mbgp_community_exact, |
| 8772 | show_ipv6_mbgp_community_exact_cmd, |
| 8773 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8774 | SHOW_STR |
| 8775 | IPV6_STR |
| 8776 | MBGP_STR |
| 8777 | "Display routes matching the communities\n" |
| 8778 | "community number\n" |
| 8779 | "Do not send outside local AS (well-known community)\n" |
| 8780 | "Do not advertise to any peer (well-known community)\n" |
| 8781 | "Do not export to next AS (well-known community)\n" |
| 8782 | "Exact match of the communities") |
| 8783 | { |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 8784 | return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8785 | } |
| 8786 | |
| 8787 | /* old command */ |
| 8788 | ALIAS (show_ipv6_mbgp_community_exact, |
| 8789 | show_ipv6_mbgp_community2_exact_cmd, |
| 8790 | "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match", |
| 8791 | SHOW_STR |
| 8792 | IPV6_STR |
| 8793 | MBGP_STR |
| 8794 | "Display routes matching the communities\n" |
| 8795 | "community number\n" |
| 8796 | "Do not send outside local AS (well-known community)\n" |
| 8797 | "Do not advertise to any peer (well-known community)\n" |
| 8798 | "Do not export to next AS (well-known community)\n" |
| 8799 | "community number\n" |
| 8800 | "Do not send outside local AS (well-known community)\n" |
| 8801 | "Do not advertise to any peer (well-known community)\n" |
| 8802 | "Do not export to next AS (well-known community)\n" |
| 8803 | "Exact match of the communities") |
| 8804 | |
| 8805 | /* old command */ |
| 8806 | ALIAS (show_ipv6_mbgp_community_exact, |
| 8807 | show_ipv6_mbgp_community3_exact_cmd, |
| 8808 | "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", |
| 8809 | SHOW_STR |
| 8810 | IPV6_STR |
| 8811 | MBGP_STR |
| 8812 | "Display routes matching the communities\n" |
| 8813 | "community number\n" |
| 8814 | "Do not send outside local AS (well-known community)\n" |
| 8815 | "Do not advertise to any peer (well-known community)\n" |
| 8816 | "Do not export to next AS (well-known community)\n" |
| 8817 | "community number\n" |
| 8818 | "Do not send outside local AS (well-known community)\n" |
| 8819 | "Do not advertise to any peer (well-known community)\n" |
| 8820 | "Do not export to next AS (well-known community)\n" |
| 8821 | "community number\n" |
| 8822 | "Do not send outside local AS (well-known community)\n" |
| 8823 | "Do not advertise to any peer (well-known community)\n" |
| 8824 | "Do not export to next AS (well-known community)\n" |
| 8825 | "Exact match of the communities") |
| 8826 | |
| 8827 | /* old command */ |
| 8828 | ALIAS (show_ipv6_mbgp_community_exact, |
| 8829 | show_ipv6_mbgp_community4_exact_cmd, |
| 8830 | "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", |
| 8831 | SHOW_STR |
| 8832 | IPV6_STR |
| 8833 | MBGP_STR |
| 8834 | "Display routes matching the communities\n" |
| 8835 | "community number\n" |
| 8836 | "Do not send outside local AS (well-known community)\n" |
| 8837 | "Do not advertise to any peer (well-known community)\n" |
| 8838 | "Do not export to next AS (well-known community)\n" |
| 8839 | "community number\n" |
| 8840 | "Do not send outside local AS (well-known community)\n" |
| 8841 | "Do not advertise to any peer (well-known community)\n" |
| 8842 | "Do not export to next AS (well-known community)\n" |
| 8843 | "community number\n" |
| 8844 | "Do not send outside local AS (well-known community)\n" |
| 8845 | "Do not advertise to any peer (well-known community)\n" |
| 8846 | "Do not export to next AS (well-known community)\n" |
| 8847 | "community number\n" |
| 8848 | "Do not send outside local AS (well-known community)\n" |
| 8849 | "Do not advertise to any peer (well-known community)\n" |
| 8850 | "Do not export to next AS (well-known community)\n" |
| 8851 | "Exact match of the communities") |
| 8852 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 8853 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 8854 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 8855 | bgp_show_community_list (struct vty *vty, const char *com, int exact, |
Michael Lambert | 4c9641b | 2010-07-22 13:20:55 -0400 | [diff] [blame] | 8856 | afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8857 | { |
| 8858 | struct community_list *list; |
| 8859 | |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8860 | list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8861 | if (list == NULL) |
| 8862 | { |
| 8863 | vty_out (vty, "%% %s is not a valid community-list name%s", com, |
| 8864 | VTY_NEWLINE); |
| 8865 | return CMD_WARNING; |
| 8866 | } |
| 8867 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 8868 | return bgp_show (vty, NULL, afi, safi, |
| 8869 | (exact ? bgp_show_type_community_list_exact : |
| 8870 | bgp_show_type_community_list), list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8871 | } |
| 8872 | |
| 8873 | DEFUN (show_ip_bgp_community_list, |
| 8874 | show_ip_bgp_community_list_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8875 | "show ip bgp community-list (<1-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8876 | SHOW_STR |
| 8877 | IP_STR |
| 8878 | BGP_STR |
| 8879 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8880 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8881 | "community-list name\n") |
| 8882 | { |
| 8883 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST); |
| 8884 | } |
| 8885 | |
| 8886 | DEFUN (show_ip_bgp_ipv4_community_list, |
| 8887 | show_ip_bgp_ipv4_community_list_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8888 | "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8889 | SHOW_STR |
| 8890 | IP_STR |
| 8891 | BGP_STR |
| 8892 | "Address family\n" |
| 8893 | "Address Family modifier\n" |
| 8894 | "Address Family modifier\n" |
| 8895 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8896 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8897 | "community-list name\n") |
| 8898 | { |
| 8899 | if (strncmp (argv[0], "m", 1) == 0) |
| 8900 | return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST); |
| 8901 | |
| 8902 | return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST); |
| 8903 | } |
| 8904 | |
| 8905 | DEFUN (show_ip_bgp_community_list_exact, |
| 8906 | show_ip_bgp_community_list_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8907 | "show ip bgp community-list (<1-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8908 | SHOW_STR |
| 8909 | IP_STR |
| 8910 | BGP_STR |
| 8911 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8912 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8913 | "community-list name\n" |
| 8914 | "Exact match of the communities\n") |
| 8915 | { |
| 8916 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST); |
| 8917 | } |
| 8918 | |
| 8919 | DEFUN (show_ip_bgp_ipv4_community_list_exact, |
| 8920 | show_ip_bgp_ipv4_community_list_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8921 | "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8922 | SHOW_STR |
| 8923 | IP_STR |
| 8924 | BGP_STR |
| 8925 | "Address family\n" |
| 8926 | "Address Family modifier\n" |
| 8927 | "Address Family modifier\n" |
| 8928 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8929 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8930 | "community-list name\n" |
| 8931 | "Exact match of the communities\n") |
| 8932 | { |
| 8933 | if (strncmp (argv[0], "m", 1) == 0) |
| 8934 | return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST); |
| 8935 | |
| 8936 | return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST); |
| 8937 | } |
| 8938 | |
| 8939 | #ifdef HAVE_IPV6 |
| 8940 | DEFUN (show_bgp_community_list, |
| 8941 | show_bgp_community_list_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8942 | "show bgp community-list (<1-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8943 | SHOW_STR |
| 8944 | BGP_STR |
| 8945 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8946 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8947 | "community-list name\n") |
| 8948 | { |
| 8949 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST); |
| 8950 | } |
| 8951 | |
| 8952 | ALIAS (show_bgp_community_list, |
| 8953 | show_bgp_ipv6_community_list_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8954 | "show bgp ipv6 community-list (<1-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8955 | SHOW_STR |
| 8956 | BGP_STR |
| 8957 | "Address family\n" |
| 8958 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8959 | "community-list number\n" |
paul | e8e1946 | 2006-01-19 20:16:55 +0000 | [diff] [blame] | 8960 | "community-list name\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8961 | |
| 8962 | /* old command */ |
| 8963 | DEFUN (show_ipv6_bgp_community_list, |
| 8964 | show_ipv6_bgp_community_list_cmd, |
| 8965 | "show ipv6 bgp community-list WORD", |
| 8966 | SHOW_STR |
| 8967 | IPV6_STR |
| 8968 | BGP_STR |
| 8969 | "Display routes matching the community-list\n" |
| 8970 | "community-list name\n") |
| 8971 | { |
| 8972 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST); |
| 8973 | } |
| 8974 | |
| 8975 | /* old command */ |
| 8976 | DEFUN (show_ipv6_mbgp_community_list, |
| 8977 | show_ipv6_mbgp_community_list_cmd, |
| 8978 | "show ipv6 mbgp community-list WORD", |
| 8979 | SHOW_STR |
| 8980 | IPV6_STR |
| 8981 | MBGP_STR |
| 8982 | "Display routes matching the community-list\n" |
| 8983 | "community-list name\n") |
| 8984 | { |
| 8985 | return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST); |
| 8986 | } |
| 8987 | |
| 8988 | DEFUN (show_bgp_community_list_exact, |
| 8989 | show_bgp_community_list_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8990 | "show bgp community-list (<1-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8991 | SHOW_STR |
| 8992 | BGP_STR |
| 8993 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 8994 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 8995 | "community-list name\n" |
| 8996 | "Exact match of the communities\n") |
| 8997 | { |
| 8998 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST); |
| 8999 | } |
| 9000 | |
| 9001 | ALIAS (show_bgp_community_list_exact, |
| 9002 | show_bgp_ipv6_community_list_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 9003 | "show bgp ipv6 community-list (<1-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9004 | SHOW_STR |
| 9005 | BGP_STR |
| 9006 | "Address family\n" |
| 9007 | "Display routes matching the community-list\n" |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 9008 | "community-list number\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9009 | "community-list name\n" |
| 9010 | "Exact match of the communities\n") |
| 9011 | |
| 9012 | /* old command */ |
| 9013 | DEFUN (show_ipv6_bgp_community_list_exact, |
| 9014 | show_ipv6_bgp_community_list_exact_cmd, |
| 9015 | "show ipv6 bgp community-list WORD exact-match", |
| 9016 | SHOW_STR |
| 9017 | IPV6_STR |
| 9018 | BGP_STR |
| 9019 | "Display routes matching the community-list\n" |
| 9020 | "community-list name\n" |
| 9021 | "Exact match of the communities\n") |
| 9022 | { |
| 9023 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST); |
| 9024 | } |
| 9025 | |
| 9026 | /* old command */ |
| 9027 | DEFUN (show_ipv6_mbgp_community_list_exact, |
| 9028 | show_ipv6_mbgp_community_list_exact_cmd, |
| 9029 | "show ipv6 mbgp community-list WORD exact-match", |
| 9030 | SHOW_STR |
| 9031 | IPV6_STR |
| 9032 | MBGP_STR |
| 9033 | "Display routes matching the community-list\n" |
| 9034 | "community-list name\n" |
| 9035 | "Exact match of the communities\n") |
| 9036 | { |
| 9037 | return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST); |
| 9038 | } |
| 9039 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 9040 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 9041 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 9042 | bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9043 | safi_t safi, enum bgp_show_type type) |
| 9044 | { |
| 9045 | int ret; |
| 9046 | struct prefix *p; |
| 9047 | |
| 9048 | p = prefix_new(); |
| 9049 | |
| 9050 | ret = str2prefix (prefix, p); |
| 9051 | if (! ret) |
| 9052 | { |
| 9053 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); |
| 9054 | return CMD_WARNING; |
| 9055 | } |
| 9056 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 9057 | ret = bgp_show (vty, NULL, afi, safi, type, p); |
| 9058 | prefix_free(p); |
| 9059 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9060 | } |
| 9061 | |
| 9062 | DEFUN (show_ip_bgp_prefix_longer, |
| 9063 | show_ip_bgp_prefix_longer_cmd, |
| 9064 | "show ip bgp A.B.C.D/M longer-prefixes", |
| 9065 | SHOW_STR |
| 9066 | IP_STR |
| 9067 | BGP_STR |
| 9068 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 9069 | "Display route and more specific routes\n") |
| 9070 | { |
| 9071 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 9072 | bgp_show_type_prefix_longer); |
| 9073 | } |
| 9074 | |
| 9075 | DEFUN (show_ip_bgp_flap_prefix_longer, |
| 9076 | show_ip_bgp_flap_prefix_longer_cmd, |
| 9077 | "show ip bgp flap-statistics A.B.C.D/M longer-prefixes", |
| 9078 | SHOW_STR |
| 9079 | IP_STR |
| 9080 | BGP_STR |
| 9081 | "Display flap statistics of routes\n" |
| 9082 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 9083 | "Display route and more specific routes\n") |
| 9084 | { |
| 9085 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 9086 | bgp_show_type_flap_prefix_longer); |
| 9087 | } |
| 9088 | |
| 9089 | DEFUN (show_ip_bgp_ipv4_prefix_longer, |
| 9090 | show_ip_bgp_ipv4_prefix_longer_cmd, |
| 9091 | "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes", |
| 9092 | SHOW_STR |
| 9093 | IP_STR |
| 9094 | BGP_STR |
| 9095 | "Address family\n" |
| 9096 | "Address Family modifier\n" |
| 9097 | "Address Family modifier\n" |
| 9098 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 9099 | "Display route and more specific routes\n") |
| 9100 | { |
| 9101 | if (strncmp (argv[0], "m", 1) == 0) |
| 9102 | return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST, |
| 9103 | bgp_show_type_prefix_longer); |
| 9104 | |
| 9105 | return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST, |
| 9106 | bgp_show_type_prefix_longer); |
| 9107 | } |
| 9108 | |
| 9109 | DEFUN (show_ip_bgp_flap_address, |
| 9110 | show_ip_bgp_flap_address_cmd, |
| 9111 | "show ip bgp flap-statistics A.B.C.D", |
| 9112 | SHOW_STR |
| 9113 | IP_STR |
| 9114 | BGP_STR |
| 9115 | "Display flap statistics of routes\n" |
| 9116 | "Network in the BGP routing table to display\n") |
| 9117 | { |
| 9118 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 9119 | bgp_show_type_flap_address); |
| 9120 | } |
| 9121 | |
| 9122 | DEFUN (show_ip_bgp_flap_prefix, |
| 9123 | show_ip_bgp_flap_prefix_cmd, |
| 9124 | "show ip bgp flap-statistics A.B.C.D/M", |
| 9125 | SHOW_STR |
| 9126 | IP_STR |
| 9127 | BGP_STR |
| 9128 | "Display flap statistics of routes\n" |
| 9129 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 9130 | { |
| 9131 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST, |
| 9132 | bgp_show_type_flap_prefix); |
| 9133 | } |
| 9134 | #ifdef HAVE_IPV6 |
| 9135 | DEFUN (show_bgp_prefix_longer, |
| 9136 | show_bgp_prefix_longer_cmd, |
| 9137 | "show bgp X:X::X:X/M longer-prefixes", |
| 9138 | SHOW_STR |
| 9139 | BGP_STR |
| 9140 | "IPv6 prefix <network>/<length>\n" |
| 9141 | "Display route and more specific routes\n") |
| 9142 | { |
| 9143 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 9144 | bgp_show_type_prefix_longer); |
| 9145 | } |
| 9146 | |
| 9147 | ALIAS (show_bgp_prefix_longer, |
| 9148 | show_bgp_ipv6_prefix_longer_cmd, |
| 9149 | "show bgp ipv6 X:X::X:X/M longer-prefixes", |
| 9150 | SHOW_STR |
| 9151 | BGP_STR |
| 9152 | "Address family\n" |
| 9153 | "IPv6 prefix <network>/<length>\n" |
| 9154 | "Display route and more specific routes\n") |
| 9155 | |
| 9156 | /* old command */ |
| 9157 | DEFUN (show_ipv6_bgp_prefix_longer, |
| 9158 | show_ipv6_bgp_prefix_longer_cmd, |
| 9159 | "show ipv6 bgp X:X::X:X/M longer-prefixes", |
| 9160 | SHOW_STR |
| 9161 | IPV6_STR |
| 9162 | BGP_STR |
| 9163 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
| 9164 | "Display route and more specific routes\n") |
| 9165 | { |
| 9166 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST, |
| 9167 | bgp_show_type_prefix_longer); |
| 9168 | } |
| 9169 | |
| 9170 | /* old command */ |
| 9171 | DEFUN (show_ipv6_mbgp_prefix_longer, |
| 9172 | show_ipv6_mbgp_prefix_longer_cmd, |
| 9173 | "show ipv6 mbgp X:X::X:X/M longer-prefixes", |
| 9174 | SHOW_STR |
| 9175 | IPV6_STR |
| 9176 | MBGP_STR |
| 9177 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n" |
| 9178 | "Display route and more specific routes\n") |
| 9179 | { |
| 9180 | return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST, |
| 9181 | bgp_show_type_prefix_longer); |
| 9182 | } |
| 9183 | #endif /* HAVE_IPV6 */ |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9184 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 9185 | static struct peer * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 9186 | peer_lookup_in_view (struct vty *vty, const char *view_name, |
| 9187 | const char *ip_str) |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9188 | { |
| 9189 | int ret; |
| 9190 | struct bgp *bgp; |
| 9191 | struct peer *peer; |
| 9192 | union sockunion su; |
| 9193 | |
| 9194 | /* BGP structure lookup. */ |
| 9195 | if (view_name) |
| 9196 | { |
| 9197 | bgp = bgp_lookup_by_name (view_name); |
| 9198 | if (! bgp) |
| 9199 | { |
| 9200 | vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE); |
| 9201 | return NULL; |
| 9202 | } |
| 9203 | } |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 9204 | else |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9205 | { |
| 9206 | bgp = bgp_get_default (); |
| 9207 | if (! bgp) |
| 9208 | { |
| 9209 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 9210 | return NULL; |
| 9211 | } |
| 9212 | } |
| 9213 | |
| 9214 | /* Get peer sockunion. */ |
| 9215 | ret = str2sockunion (ip_str, &su); |
| 9216 | if (ret < 0) |
| 9217 | { |
| 9218 | vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE); |
| 9219 | return NULL; |
| 9220 | } |
| 9221 | |
| 9222 | /* Peer structure lookup. */ |
| 9223 | peer = peer_lookup (bgp, &su); |
| 9224 | if (! peer) |
| 9225 | { |
| 9226 | vty_out (vty, "No such neighbor%s", VTY_NEWLINE); |
| 9227 | return NULL; |
| 9228 | } |
| 9229 | |
| 9230 | return peer; |
| 9231 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 9232 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9233 | enum bgp_stats |
| 9234 | { |
| 9235 | BGP_STATS_MAXBITLEN = 0, |
| 9236 | BGP_STATS_RIB, |
| 9237 | BGP_STATS_PREFIXES, |
| 9238 | BGP_STATS_TOTPLEN, |
| 9239 | BGP_STATS_UNAGGREGATEABLE, |
| 9240 | BGP_STATS_MAX_AGGREGATEABLE, |
| 9241 | BGP_STATS_AGGREGATES, |
| 9242 | BGP_STATS_SPACE, |
| 9243 | BGP_STATS_ASPATH_COUNT, |
| 9244 | BGP_STATS_ASPATH_MAXHOPS, |
| 9245 | BGP_STATS_ASPATH_TOTHOPS, |
| 9246 | BGP_STATS_ASPATH_MAXSIZE, |
| 9247 | BGP_STATS_ASPATH_TOTSIZE, |
| 9248 | BGP_STATS_ASN_HIGHEST, |
| 9249 | BGP_STATS_MAX, |
| 9250 | }; |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9251 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9252 | static const char *table_stats_strs[] = |
| 9253 | { |
| 9254 | [BGP_STATS_PREFIXES] = "Total Prefixes", |
| 9255 | [BGP_STATS_TOTPLEN] = "Average prefix length", |
| 9256 | [BGP_STATS_RIB] = "Total Advertisements", |
| 9257 | [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes", |
| 9258 | [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes", |
| 9259 | [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements", |
| 9260 | [BGP_STATS_SPACE] = "Address space advertised", |
| 9261 | [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths", |
| 9262 | [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)", |
| 9263 | [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)", |
| 9264 | [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)", |
| 9265 | [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)", |
| 9266 | [BGP_STATS_ASN_HIGHEST] = "Highest public ASN", |
| 9267 | [BGP_STATS_MAX] = NULL, |
| 9268 | }; |
| 9269 | |
| 9270 | struct bgp_table_stats |
| 9271 | { |
| 9272 | struct bgp_table *table; |
| 9273 | unsigned long long counts[BGP_STATS_MAX]; |
| 9274 | }; |
| 9275 | |
| 9276 | #if 0 |
| 9277 | #define TALLY_SIGFIG 100000 |
| 9278 | static unsigned long |
| 9279 | ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval) |
| 9280 | { |
| 9281 | unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG); |
| 9282 | unsigned long res = (newtot * TALLY_SIGFIG) / count; |
| 9283 | unsigned long ret = newtot / count; |
| 9284 | |
| 9285 | if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2)) |
| 9286 | return ret + 1; |
| 9287 | else |
| 9288 | return ret; |
| 9289 | } |
| 9290 | #endif |
| 9291 | |
| 9292 | static int |
| 9293 | bgp_table_stats_walker (struct thread *t) |
| 9294 | { |
| 9295 | struct bgp_node *rn; |
| 9296 | struct bgp_node *top; |
| 9297 | struct bgp_table_stats *ts = THREAD_ARG (t); |
| 9298 | unsigned int space = 0; |
| 9299 | |
Paul Jakma | 53d9f67 | 2006-10-15 23:41:16 +0000 | [diff] [blame] | 9300 | if (!(top = bgp_table_top (ts->table))) |
| 9301 | return 0; |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9302 | |
| 9303 | switch (top->p.family) |
| 9304 | { |
| 9305 | case AF_INET: |
| 9306 | space = IPV4_MAX_BITLEN; |
| 9307 | break; |
| 9308 | case AF_INET6: |
| 9309 | space = IPV6_MAX_BITLEN; |
| 9310 | break; |
| 9311 | } |
| 9312 | |
| 9313 | ts->counts[BGP_STATS_MAXBITLEN] = space; |
| 9314 | |
| 9315 | for (rn = top; rn; rn = bgp_route_next (rn)) |
| 9316 | { |
| 9317 | struct bgp_info *ri; |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 9318 | struct bgp_node *prn = bgp_node_parent_nolock (rn); |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9319 | unsigned int rinum = 0; |
| 9320 | |
| 9321 | if (rn == top) |
| 9322 | continue; |
| 9323 | |
| 9324 | if (!rn->info) |
| 9325 | continue; |
| 9326 | |
| 9327 | ts->counts[BGP_STATS_PREFIXES]++; |
| 9328 | ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen; |
| 9329 | |
| 9330 | #if 0 |
| 9331 | ts->counts[BGP_STATS_AVGPLEN] |
| 9332 | = ravg_tally (ts->counts[BGP_STATS_PREFIXES], |
| 9333 | ts->counts[BGP_STATS_AVGPLEN], |
| 9334 | rn->p.prefixlen); |
| 9335 | #endif |
| 9336 | |
| 9337 | /* check if the prefix is included by any other announcements */ |
| 9338 | while (prn && !prn->info) |
Avneesh Sachdev | 6717404 | 2012-08-17 08:19:49 -0700 | [diff] [blame] | 9339 | prn = bgp_node_parent_nolock (prn); |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9340 | |
| 9341 | if (prn == NULL || prn == top) |
Paul Jakma | 8383a9b | 2006-09-14 03:06:54 +0000 | [diff] [blame] | 9342 | { |
| 9343 | ts->counts[BGP_STATS_UNAGGREGATEABLE]++; |
| 9344 | /* announced address space */ |
| 9345 | if (space) |
| 9346 | ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen); |
| 9347 | } |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9348 | else if (prn->info) |
| 9349 | ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++; |
| 9350 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9351 | for (ri = rn->info; ri; ri = ri->next) |
| 9352 | { |
| 9353 | rinum++; |
| 9354 | ts->counts[BGP_STATS_RIB]++; |
| 9355 | |
| 9356 | if (ri->attr && |
| 9357 | (CHECK_FLAG (ri->attr->flag, |
| 9358 | ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))) |
| 9359 | ts->counts[BGP_STATS_AGGREGATES]++; |
| 9360 | |
| 9361 | /* as-path stats */ |
| 9362 | if (ri->attr && ri->attr->aspath) |
| 9363 | { |
| 9364 | unsigned int hops = aspath_count_hops (ri->attr->aspath); |
| 9365 | unsigned int size = aspath_size (ri->attr->aspath); |
| 9366 | as_t highest = aspath_highest (ri->attr->aspath); |
| 9367 | |
| 9368 | ts->counts[BGP_STATS_ASPATH_COUNT]++; |
| 9369 | |
| 9370 | if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS]) |
| 9371 | ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops; |
| 9372 | |
| 9373 | if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE]) |
| 9374 | ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size; |
| 9375 | |
| 9376 | ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops; |
| 9377 | ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size; |
| 9378 | #if 0 |
| 9379 | ts->counts[BGP_STATS_ASPATH_AVGHOPS] |
| 9380 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], |
| 9381 | ts->counts[BGP_STATS_ASPATH_AVGHOPS], |
| 9382 | hops); |
| 9383 | ts->counts[BGP_STATS_ASPATH_AVGSIZE] |
| 9384 | = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT], |
| 9385 | ts->counts[BGP_STATS_ASPATH_AVGSIZE], |
| 9386 | size); |
| 9387 | #endif |
| 9388 | if (highest > ts->counts[BGP_STATS_ASN_HIGHEST]) |
| 9389 | ts->counts[BGP_STATS_ASN_HIGHEST] = highest; |
| 9390 | } |
| 9391 | } |
| 9392 | } |
| 9393 | return 0; |
| 9394 | } |
| 9395 | |
| 9396 | static int |
| 9397 | bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi) |
| 9398 | { |
| 9399 | struct bgp_table_stats ts; |
| 9400 | unsigned int i; |
| 9401 | |
| 9402 | if (!bgp->rib[afi][safi]) |
| 9403 | { |
| 9404 | vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE); |
| 9405 | return CMD_WARNING; |
| 9406 | } |
| 9407 | |
| 9408 | memset (&ts, 0, sizeof (ts)); |
| 9409 | ts.table = bgp->rib[afi][safi]; |
| 9410 | thread_execute (bm->master, bgp_table_stats_walker, &ts, 0); |
| 9411 | |
| 9412 | vty_out (vty, "BGP %s RIB statistics%s%s", |
| 9413 | afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE); |
| 9414 | |
| 9415 | for (i = 0; i < BGP_STATS_MAX; i++) |
| 9416 | { |
| 9417 | if (!table_stats_strs[i]) |
| 9418 | continue; |
| 9419 | |
| 9420 | switch (i) |
| 9421 | { |
| 9422 | #if 0 |
| 9423 | case BGP_STATS_ASPATH_AVGHOPS: |
| 9424 | case BGP_STATS_ASPATH_AVGSIZE: |
| 9425 | case BGP_STATS_AVGPLEN: |
| 9426 | vty_out (vty, "%-30s: ", table_stats_strs[i]); |
| 9427 | vty_out (vty, "%12.2f", |
| 9428 | (float)ts.counts[i] / (float)TALLY_SIGFIG); |
| 9429 | break; |
| 9430 | #endif |
| 9431 | case BGP_STATS_ASPATH_TOTHOPS: |
| 9432 | case BGP_STATS_ASPATH_TOTSIZE: |
| 9433 | vty_out (vty, "%-30s: ", table_stats_strs[i]); |
| 9434 | vty_out (vty, "%12.2f", |
| 9435 | ts.counts[i] ? |
| 9436 | (float)ts.counts[i] / |
| 9437 | (float)ts.counts[BGP_STATS_ASPATH_COUNT] |
| 9438 | : 0); |
| 9439 | break; |
| 9440 | case BGP_STATS_TOTPLEN: |
| 9441 | vty_out (vty, "%-30s: ", table_stats_strs[i]); |
| 9442 | vty_out (vty, "%12.2f", |
| 9443 | ts.counts[i] ? |
| 9444 | (float)ts.counts[i] / |
| 9445 | (float)ts.counts[BGP_STATS_PREFIXES] |
| 9446 | : 0); |
| 9447 | break; |
| 9448 | case BGP_STATS_SPACE: |
| 9449 | vty_out (vty, "%-30s: ", table_stats_strs[i]); |
| 9450 | vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE); |
| 9451 | if (ts.counts[BGP_STATS_MAXBITLEN] < 9) |
| 9452 | break; |
Paul Jakma | 30a2231 | 2008-08-15 14:05:22 +0100 | [diff] [blame] | 9453 | vty_out (vty, "%30s: ", "%% announced "); |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9454 | vty_out (vty, "%12.2f%s", |
| 9455 | 100 * (float)ts.counts[BGP_STATS_SPACE] / |
Paul Jakma | 56395af | 2006-10-27 16:58:20 +0000 | [diff] [blame] | 9456 | (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]), |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9457 | VTY_NEWLINE); |
| 9458 | vty_out (vty, "%30s: ", "/8 equivalent "); |
| 9459 | vty_out (vty, "%12.2f%s", |
| 9460 | (float)ts.counts[BGP_STATS_SPACE] / |
| 9461 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)), |
| 9462 | VTY_NEWLINE); |
| 9463 | if (ts.counts[BGP_STATS_MAXBITLEN] < 25) |
| 9464 | break; |
| 9465 | vty_out (vty, "%30s: ", "/24 equivalent "); |
| 9466 | vty_out (vty, "%12.2f", |
| 9467 | (float)ts.counts[BGP_STATS_SPACE] / |
| 9468 | (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24))); |
| 9469 | break; |
| 9470 | default: |
| 9471 | vty_out (vty, "%-30s: ", table_stats_strs[i]); |
| 9472 | vty_out (vty, "%12llu", ts.counts[i]); |
| 9473 | } |
| 9474 | |
| 9475 | vty_out (vty, "%s", VTY_NEWLINE); |
| 9476 | } |
| 9477 | return CMD_SUCCESS; |
| 9478 | } |
| 9479 | |
| 9480 | static int |
| 9481 | bgp_table_stats_vty (struct vty *vty, const char *name, |
| 9482 | const char *afi_str, const char *safi_str) |
| 9483 | { |
| 9484 | struct bgp *bgp; |
| 9485 | afi_t afi; |
| 9486 | safi_t safi; |
| 9487 | |
| 9488 | if (name) |
| 9489 | bgp = bgp_lookup_by_name (name); |
| 9490 | else |
| 9491 | bgp = bgp_get_default (); |
| 9492 | |
| 9493 | if (!bgp) |
| 9494 | { |
| 9495 | vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE); |
| 9496 | return CMD_WARNING; |
| 9497 | } |
| 9498 | if (strncmp (afi_str, "ipv", 3) == 0) |
| 9499 | { |
| 9500 | if (strncmp (afi_str, "ipv4", 4) == 0) |
| 9501 | afi = AFI_IP; |
| 9502 | else if (strncmp (afi_str, "ipv6", 4) == 0) |
| 9503 | afi = AFI_IP6; |
| 9504 | else |
| 9505 | { |
| 9506 | vty_out (vty, "%% Invalid address family %s%s", |
| 9507 | afi_str, VTY_NEWLINE); |
| 9508 | return CMD_WARNING; |
| 9509 | } |
| 9510 | if (strncmp (safi_str, "m", 1) == 0) |
| 9511 | safi = SAFI_MULTICAST; |
| 9512 | else if (strncmp (safi_str, "u", 1) == 0) |
| 9513 | safi = SAFI_UNICAST; |
Denis Ovsienko | 42e6d74 | 2011-07-14 12:36:19 +0400 | [diff] [blame] | 9514 | else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0) |
| 9515 | safi = SAFI_MPLS_LABELED_VPN; |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9516 | else |
| 9517 | { |
| 9518 | vty_out (vty, "%% Invalid subsequent address family %s%s", |
| 9519 | safi_str, VTY_NEWLINE); |
| 9520 | return CMD_WARNING; |
| 9521 | } |
| 9522 | } |
| 9523 | else |
| 9524 | { |
| 9525 | vty_out (vty, "%% Invalid address family %s%s", |
| 9526 | afi_str, VTY_NEWLINE); |
| 9527 | return CMD_WARNING; |
| 9528 | } |
| 9529 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9530 | return bgp_table_stats (vty, bgp, afi, safi); |
| 9531 | } |
| 9532 | |
| 9533 | DEFUN (show_bgp_statistics, |
| 9534 | show_bgp_statistics_cmd, |
| 9535 | "show bgp (ipv4|ipv6) (unicast|multicast) statistics", |
| 9536 | SHOW_STR |
| 9537 | BGP_STR |
| 9538 | "Address family\n" |
| 9539 | "Address family\n" |
| 9540 | "Address Family modifier\n" |
| 9541 | "Address Family modifier\n" |
| 9542 | "BGP RIB advertisement statistics\n") |
| 9543 | { |
| 9544 | return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); |
| 9545 | } |
| 9546 | |
| 9547 | ALIAS (show_bgp_statistics, |
| 9548 | show_bgp_statistics_vpnv4_cmd, |
| 9549 | "show bgp (ipv4) (vpnv4) statistics", |
| 9550 | SHOW_STR |
| 9551 | BGP_STR |
| 9552 | "Address family\n" |
| 9553 | "Address Family modifier\n" |
| 9554 | "BGP RIB advertisement statistics\n") |
| 9555 | |
| 9556 | DEFUN (show_bgp_statistics_view, |
| 9557 | show_bgp_statistics_view_cmd, |
| 9558 | "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics", |
| 9559 | SHOW_STR |
| 9560 | BGP_STR |
| 9561 | "BGP view\n" |
| 9562 | "Address family\n" |
| 9563 | "Address family\n" |
| 9564 | "Address Family modifier\n" |
| 9565 | "Address Family modifier\n" |
| 9566 | "BGP RIB advertisement statistics\n") |
| 9567 | { |
| 9568 | return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]); |
| 9569 | } |
| 9570 | |
| 9571 | ALIAS (show_bgp_statistics_view, |
| 9572 | show_bgp_statistics_view_vpnv4_cmd, |
| 9573 | "show bgp view WORD (ipv4) (vpnv4) statistics", |
| 9574 | SHOW_STR |
| 9575 | BGP_STR |
| 9576 | "BGP view\n" |
| 9577 | "Address family\n" |
| 9578 | "Address Family modifier\n" |
| 9579 | "BGP RIB advertisement statistics\n") |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 9580 | |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9581 | enum bgp_pcounts |
| 9582 | { |
| 9583 | PCOUNT_ADJ_IN = 0, |
| 9584 | PCOUNT_DAMPED, |
| 9585 | PCOUNT_REMOVED, |
| 9586 | PCOUNT_HISTORY, |
| 9587 | PCOUNT_STALE, |
| 9588 | PCOUNT_VALID, |
| 9589 | PCOUNT_ALL, |
| 9590 | PCOUNT_COUNTED, |
| 9591 | PCOUNT_PFCNT, /* the figure we display to users */ |
| 9592 | PCOUNT_MAX, |
| 9593 | }; |
| 9594 | |
| 9595 | static const char *pcount_strs[] = |
| 9596 | { |
| 9597 | [PCOUNT_ADJ_IN] = "Adj-in", |
| 9598 | [PCOUNT_DAMPED] = "Damped", |
| 9599 | [PCOUNT_REMOVED] = "Removed", |
| 9600 | [PCOUNT_HISTORY] = "History", |
| 9601 | [PCOUNT_STALE] = "Stale", |
| 9602 | [PCOUNT_VALID] = "Valid", |
| 9603 | [PCOUNT_ALL] = "All RIB", |
| 9604 | [PCOUNT_COUNTED] = "PfxCt counted", |
| 9605 | [PCOUNT_PFCNT] = "Useable", |
| 9606 | [PCOUNT_MAX] = NULL, |
| 9607 | }; |
| 9608 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9609 | struct peer_pcounts |
| 9610 | { |
| 9611 | unsigned int count[PCOUNT_MAX]; |
| 9612 | const struct peer *peer; |
| 9613 | const struct bgp_table *table; |
| 9614 | }; |
| 9615 | |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9616 | static int |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9617 | bgp_peer_count_walker (struct thread *t) |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9618 | { |
| 9619 | struct bgp_node *rn; |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9620 | struct peer_pcounts *pc = THREAD_ARG (t); |
| 9621 | const struct peer *peer = pc->peer; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9622 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9623 | for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn)) |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9624 | { |
| 9625 | struct bgp_adj_in *ain; |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9626 | struct bgp_info *ri; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9627 | |
| 9628 | for (ain = rn->adj_in; ain; ain = ain->next) |
| 9629 | if (ain->peer == peer) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9630 | pc->count[PCOUNT_ADJ_IN]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9631 | |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9632 | for (ri = rn->info; ri; ri = ri->next) |
| 9633 | { |
| 9634 | char buf[SU_ADDRSTRLEN]; |
| 9635 | |
| 9636 | if (ri->peer != peer) |
| 9637 | continue; |
| 9638 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9639 | pc->count[PCOUNT_ALL]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9640 | |
| 9641 | if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9642 | pc->count[PCOUNT_DAMPED]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9643 | if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9644 | pc->count[PCOUNT_HISTORY]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9645 | if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9646 | pc->count[PCOUNT_REMOVED]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9647 | if (CHECK_FLAG (ri->flags, BGP_INFO_STALE)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9648 | pc->count[PCOUNT_STALE]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9649 | if (CHECK_FLAG (ri->flags, BGP_INFO_VALID)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9650 | pc->count[PCOUNT_VALID]++; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 9651 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9652 | pc->count[PCOUNT_PFCNT]++; |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9653 | |
| 9654 | if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)) |
| 9655 | { |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9656 | pc->count[PCOUNT_COUNTED]++; |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 9657 | if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9658 | plog_warn (peer->log, |
| 9659 | "%s [pcount] %s/%d is counted but flags 0x%x", |
| 9660 | peer->host, |
| 9661 | inet_ntop(rn->p.family, &rn->p.u.prefix, |
| 9662 | buf, SU_ADDRSTRLEN), |
| 9663 | rn->p.prefixlen, |
| 9664 | ri->flags); |
| 9665 | } |
| 9666 | else |
| 9667 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 9668 | if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE)) |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9669 | plog_warn (peer->log, |
| 9670 | "%s [pcount] %s/%d not counted but flags 0x%x", |
| 9671 | peer->host, |
| 9672 | inet_ntop(rn->p.family, &rn->p.u.prefix, |
| 9673 | buf, SU_ADDRSTRLEN), |
| 9674 | rn->p.prefixlen, |
| 9675 | ri->flags); |
| 9676 | } |
| 9677 | } |
| 9678 | } |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9679 | return 0; |
| 9680 | } |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9681 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9682 | static int |
| 9683 | bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi) |
| 9684 | { |
| 9685 | struct peer_pcounts pcounts = { .peer = peer }; |
| 9686 | unsigned int i; |
| 9687 | |
| 9688 | if (!peer || !peer->bgp || !peer->afc[afi][safi] |
| 9689 | || !peer->bgp->rib[afi][safi]) |
| 9690 | { |
| 9691 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 9692 | return CMD_WARNING; |
| 9693 | } |
| 9694 | |
| 9695 | memset (&pcounts, 0, sizeof(pcounts)); |
| 9696 | pcounts.peer = peer; |
| 9697 | pcounts.table = peer->bgp->rib[afi][safi]; |
| 9698 | |
| 9699 | /* in-place call via thread subsystem so as to record execution time |
| 9700 | * stats for the thread-walk (i.e. ensure this can't be blamed on |
| 9701 | * on just vty_read()). |
| 9702 | */ |
| 9703 | thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0); |
| 9704 | |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9705 | vty_out (vty, "Prefix counts for %s, %s%s", |
| 9706 | peer->host, afi_safi_print (afi, safi), VTY_NEWLINE); |
| 9707 | vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE); |
| 9708 | vty_out (vty, "%sCounts from RIB table walk:%s%s", |
| 9709 | VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); |
| 9710 | |
| 9711 | for (i = 0; i < PCOUNT_MAX; i++) |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9712 | vty_out (vty, "%20s: %-10d%s", |
| 9713 | pcount_strs[i], pcounts.count[i], VTY_NEWLINE); |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9714 | |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 9715 | if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 9716 | { |
| 9717 | vty_out (vty, "%s [pcount] PfxCt drift!%s", |
| 9718 | peer->host, VTY_NEWLINE); |
| 9719 | vty_out (vty, "Please report this bug, with the above command output%s", |
| 9720 | VTY_NEWLINE); |
| 9721 | } |
| 9722 | |
| 9723 | return CMD_SUCCESS; |
| 9724 | } |
| 9725 | |
| 9726 | DEFUN (show_ip_bgp_neighbor_prefix_counts, |
| 9727 | show_ip_bgp_neighbor_prefix_counts_cmd, |
| 9728 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts", |
| 9729 | SHOW_STR |
| 9730 | IP_STR |
| 9731 | BGP_STR |
| 9732 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9733 | "Neighbor to display information about\n" |
| 9734 | "Neighbor to display information about\n" |
| 9735 | "Display detailed prefix count information\n") |
| 9736 | { |
| 9737 | struct peer *peer; |
| 9738 | |
| 9739 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 9740 | if (! peer) |
| 9741 | return CMD_WARNING; |
| 9742 | |
| 9743 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST); |
| 9744 | } |
| 9745 | |
| 9746 | DEFUN (show_bgp_ipv6_neighbor_prefix_counts, |
| 9747 | show_bgp_ipv6_neighbor_prefix_counts_cmd, |
| 9748 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts", |
| 9749 | SHOW_STR |
| 9750 | BGP_STR |
| 9751 | "Address family\n" |
| 9752 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9753 | "Neighbor to display information about\n" |
| 9754 | "Neighbor to display information about\n" |
| 9755 | "Display detailed prefix count information\n") |
| 9756 | { |
| 9757 | struct peer *peer; |
| 9758 | |
| 9759 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 9760 | if (! peer) |
| 9761 | return CMD_WARNING; |
| 9762 | |
| 9763 | return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST); |
| 9764 | } |
| 9765 | |
| 9766 | DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, |
| 9767 | show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, |
| 9768 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts", |
| 9769 | SHOW_STR |
| 9770 | IP_STR |
| 9771 | BGP_STR |
| 9772 | "Address family\n" |
| 9773 | "Address Family modifier\n" |
| 9774 | "Address Family modifier\n" |
| 9775 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9776 | "Neighbor to display information about\n" |
| 9777 | "Neighbor to display information about\n" |
| 9778 | "Display detailed prefix count information\n") |
| 9779 | { |
| 9780 | struct peer *peer; |
| 9781 | |
| 9782 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 9783 | if (! peer) |
| 9784 | return CMD_WARNING; |
| 9785 | |
| 9786 | if (strncmp (argv[0], "m", 1) == 0) |
| 9787 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST); |
| 9788 | |
| 9789 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST); |
| 9790 | } |
| 9791 | |
| 9792 | DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts, |
| 9793 | show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd, |
| 9794 | "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts", |
| 9795 | SHOW_STR |
| 9796 | IP_STR |
| 9797 | BGP_STR |
| 9798 | "Address family\n" |
| 9799 | "Address Family modifier\n" |
| 9800 | "Address Family modifier\n" |
| 9801 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9802 | "Neighbor to display information about\n" |
| 9803 | "Neighbor to display information about\n" |
| 9804 | "Display detailed prefix count information\n") |
| 9805 | { |
| 9806 | struct peer *peer; |
| 9807 | |
| 9808 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 9809 | if (! peer) |
| 9810 | return CMD_WARNING; |
| 9811 | |
| 9812 | return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN); |
| 9813 | } |
| 9814 | |
| 9815 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 9816 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9817 | show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, |
| 9818 | int in) |
| 9819 | { |
| 9820 | struct bgp_table *table; |
| 9821 | struct bgp_adj_in *ain; |
| 9822 | struct bgp_adj_out *adj; |
| 9823 | unsigned long output_count; |
| 9824 | struct bgp_node *rn; |
| 9825 | int header1 = 1; |
| 9826 | struct bgp *bgp; |
| 9827 | int header2 = 1; |
| 9828 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9829 | bgp = peer->bgp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9830 | |
| 9831 | if (! bgp) |
| 9832 | return; |
| 9833 | |
| 9834 | table = bgp->rib[afi][safi]; |
| 9835 | |
| 9836 | output_count = 0; |
| 9837 | |
| 9838 | if (! in && CHECK_FLAG (peer->af_sflags[afi][safi], |
| 9839 | PEER_STATUS_DEFAULT_ORIGINATE)) |
| 9840 | { |
| 9841 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 9842 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
| 9843 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9844 | |
| 9845 | vty_out (vty, "Originating default network 0.0.0.0%s%s", |
| 9846 | VTY_NEWLINE, VTY_NEWLINE); |
| 9847 | header1 = 0; |
| 9848 | } |
| 9849 | |
| 9850 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 9851 | if (in) |
| 9852 | { |
| 9853 | for (ain = rn->adj_in; ain; ain = ain->next) |
| 9854 | if (ain->peer == peer) |
| 9855 | { |
| 9856 | if (header1) |
| 9857 | { |
| 9858 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 9859 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
| 9860 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9861 | header1 = 0; |
| 9862 | } |
| 9863 | if (header2) |
| 9864 | { |
| 9865 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); |
| 9866 | header2 = 0; |
| 9867 | } |
| 9868 | if (ain->attr) |
| 9869 | { |
| 9870 | route_vty_out_tmp (vty, &rn->p, ain->attr, safi); |
| 9871 | output_count++; |
| 9872 | } |
| 9873 | } |
| 9874 | } |
| 9875 | else |
| 9876 | { |
| 9877 | for (adj = rn->adj_out; adj; adj = adj->next) |
| 9878 | if (adj->peer == peer) |
| 9879 | { |
| 9880 | if (header1) |
| 9881 | { |
| 9882 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); |
hasso | 93406d8 | 2005-02-02 14:40:33 +0000 | [diff] [blame] | 9883 | vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
| 9884 | vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9885 | header1 = 0; |
| 9886 | } |
| 9887 | if (header2) |
| 9888 | { |
| 9889 | vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE); |
| 9890 | header2 = 0; |
| 9891 | } |
| 9892 | if (adj->attr) |
| 9893 | { |
| 9894 | route_vty_out_tmp (vty, &rn->p, adj->attr, safi); |
| 9895 | output_count++; |
| 9896 | } |
| 9897 | } |
| 9898 | } |
| 9899 | |
| 9900 | if (output_count != 0) |
| 9901 | vty_out (vty, "%sTotal number of prefixes %ld%s", |
| 9902 | VTY_NEWLINE, output_count, VTY_NEWLINE); |
| 9903 | } |
| 9904 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 9905 | static int |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9906 | peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in) |
| 9907 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9908 | if (! peer || ! peer->afc[afi][safi]) |
| 9909 | { |
| 9910 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 9911 | return CMD_WARNING; |
| 9912 | } |
| 9913 | |
| 9914 | if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)) |
| 9915 | { |
| 9916 | vty_out (vty, "%% Inbound soft reconfiguration not enabled%s", |
| 9917 | VTY_NEWLINE); |
| 9918 | return CMD_WARNING; |
| 9919 | } |
| 9920 | |
| 9921 | show_adj_route (vty, peer, afi, safi, in); |
| 9922 | |
| 9923 | return CMD_SUCCESS; |
| 9924 | } |
| 9925 | |
Tomasz Pala | 2a71e9c | 2009-06-24 21:36:50 +0100 | [diff] [blame] | 9926 | DEFUN (show_ip_bgp_view_neighbor_advertised_route, |
| 9927 | show_ip_bgp_view_neighbor_advertised_route_cmd, |
| 9928 | "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 9929 | SHOW_STR |
| 9930 | IP_STR |
| 9931 | BGP_STR |
| 9932 | "BGP view\n" |
| 9933 | "View name\n" |
| 9934 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9935 | "Neighbor to display information about\n" |
| 9936 | "Neighbor to display information about\n" |
| 9937 | "Display the routes advertised to a BGP neighbor\n") |
| 9938 | { |
| 9939 | struct peer *peer; |
| 9940 | |
| 9941 | if (argc == 2) |
| 9942 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 9943 | else |
| 9944 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 9945 | |
| 9946 | if (! peer) |
| 9947 | return CMD_WARNING; |
| 9948 | |
| 9949 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0); |
| 9950 | } |
| 9951 | |
| 9952 | ALIAS (show_ip_bgp_view_neighbor_advertised_route, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9953 | show_ip_bgp_neighbor_advertised_route_cmd, |
| 9954 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 9955 | SHOW_STR |
| 9956 | IP_STR |
| 9957 | BGP_STR |
| 9958 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9959 | "Neighbor to display information about\n" |
| 9960 | "Neighbor to display information about\n" |
| 9961 | "Display the routes advertised to a BGP neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9962 | |
| 9963 | DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route, |
| 9964 | show_ip_bgp_ipv4_neighbor_advertised_route_cmd, |
| 9965 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 9966 | SHOW_STR |
| 9967 | IP_STR |
| 9968 | BGP_STR |
| 9969 | "Address family\n" |
| 9970 | "Address Family modifier\n" |
| 9971 | "Address Family modifier\n" |
| 9972 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9973 | "Neighbor to display information about\n" |
| 9974 | "Neighbor to display information about\n" |
| 9975 | "Display the routes advertised to a BGP neighbor\n") |
| 9976 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9977 | struct peer *peer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9978 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9979 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 9980 | if (! peer) |
| 9981 | return CMD_WARNING; |
| 9982 | |
| 9983 | if (strncmp (argv[0], "m", 1) == 0) |
| 9984 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0); |
| 9985 | |
| 9986 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | #ifdef HAVE_IPV6 |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 9990 | DEFUN (show_bgp_view_neighbor_advertised_route, |
| 9991 | show_bgp_view_neighbor_advertised_route_cmd, |
| 9992 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 9993 | SHOW_STR |
| 9994 | BGP_STR |
| 9995 | "BGP view\n" |
| 9996 | "View name\n" |
| 9997 | "Detailed information on TCP and BGP neighbor connections\n" |
| 9998 | "Neighbor to display information about\n" |
| 9999 | "Neighbor to display information about\n" |
| 10000 | "Display the routes advertised to a BGP neighbor\n") |
| 10001 | { |
| 10002 | struct peer *peer; |
| 10003 | |
| 10004 | if (argc == 2) |
| 10005 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10006 | else |
| 10007 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10008 | |
| 10009 | if (! peer) |
| 10010 | return CMD_WARNING; |
| 10011 | |
| 10012 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0); |
| 10013 | } |
| 10014 | |
| 10015 | ALIAS (show_bgp_view_neighbor_advertised_route, |
| 10016 | show_bgp_view_ipv6_neighbor_advertised_route_cmd, |
| 10017 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 10018 | SHOW_STR |
| 10019 | BGP_STR |
| 10020 | "BGP view\n" |
| 10021 | "View name\n" |
| 10022 | "Address family\n" |
| 10023 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10024 | "Neighbor to display information about\n" |
| 10025 | "Neighbor to display information about\n" |
| 10026 | "Display the routes advertised to a BGP neighbor\n") |
| 10027 | |
| 10028 | DEFUN (show_bgp_view_neighbor_received_routes, |
| 10029 | show_bgp_view_neighbor_received_routes_cmd, |
| 10030 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10031 | SHOW_STR |
| 10032 | BGP_STR |
| 10033 | "BGP view\n" |
| 10034 | "View name\n" |
| 10035 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10036 | "Neighbor to display information about\n" |
| 10037 | "Neighbor to display information about\n" |
| 10038 | "Display the received routes from neighbor\n") |
| 10039 | { |
| 10040 | struct peer *peer; |
| 10041 | |
| 10042 | if (argc == 2) |
| 10043 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10044 | else |
| 10045 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10046 | |
| 10047 | if (! peer) |
| 10048 | return CMD_WARNING; |
| 10049 | |
| 10050 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1); |
| 10051 | } |
| 10052 | |
| 10053 | ALIAS (show_bgp_view_neighbor_received_routes, |
| 10054 | show_bgp_view_ipv6_neighbor_received_routes_cmd, |
| 10055 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10056 | SHOW_STR |
| 10057 | BGP_STR |
| 10058 | "BGP view\n" |
| 10059 | "View name\n" |
| 10060 | "Address family\n" |
| 10061 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10062 | "Neighbor to display information about\n" |
| 10063 | "Neighbor to display information about\n" |
| 10064 | "Display the received routes from neighbor\n") |
| 10065 | |
| 10066 | ALIAS (show_bgp_view_neighbor_advertised_route, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10067 | show_bgp_neighbor_advertised_route_cmd, |
| 10068 | "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 10069 | SHOW_STR |
| 10070 | BGP_STR |
| 10071 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10072 | "Neighbor to display information about\n" |
| 10073 | "Neighbor to display information about\n" |
| 10074 | "Display the routes advertised to a BGP neighbor\n") |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10075 | |
| 10076 | ALIAS (show_bgp_view_neighbor_advertised_route, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10077 | show_bgp_ipv6_neighbor_advertised_route_cmd, |
| 10078 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 10079 | SHOW_STR |
| 10080 | BGP_STR |
| 10081 | "Address family\n" |
| 10082 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10083 | "Neighbor to display information about\n" |
| 10084 | "Neighbor to display information about\n" |
| 10085 | "Display the routes advertised to a BGP neighbor\n") |
| 10086 | |
| 10087 | /* old command */ |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10088 | ALIAS (show_bgp_view_neighbor_advertised_route, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10089 | ipv6_bgp_neighbor_advertised_route_cmd, |
| 10090 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 10091 | SHOW_STR |
| 10092 | IPV6_STR |
| 10093 | BGP_STR |
| 10094 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10095 | "Neighbor to display information about\n" |
| 10096 | "Neighbor to display information about\n" |
| 10097 | "Display the routes advertised to a BGP neighbor\n") |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10098 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10099 | /* old command */ |
| 10100 | DEFUN (ipv6_mbgp_neighbor_advertised_route, |
| 10101 | ipv6_mbgp_neighbor_advertised_route_cmd, |
| 10102 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 10103 | SHOW_STR |
| 10104 | IPV6_STR |
| 10105 | MBGP_STR |
| 10106 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10107 | "Neighbor to display information about\n" |
| 10108 | "Neighbor to display information about\n" |
| 10109 | "Display the routes advertised to a BGP neighbor\n") |
| 10110 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10111 | struct peer *peer; |
| 10112 | |
| 10113 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10114 | if (! peer) |
| 10115 | return CMD_WARNING; |
| 10116 | |
| 10117 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10118 | } |
| 10119 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 10120 | |
Tomasz Pala | 2a71e9c | 2009-06-24 21:36:50 +0100 | [diff] [blame] | 10121 | DEFUN (show_ip_bgp_view_neighbor_received_routes, |
| 10122 | show_ip_bgp_view_neighbor_received_routes_cmd, |
| 10123 | "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10124 | SHOW_STR |
| 10125 | IP_STR |
| 10126 | BGP_STR |
| 10127 | "BGP view\n" |
| 10128 | "View name\n" |
| 10129 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10130 | "Neighbor to display information about\n" |
| 10131 | "Neighbor to display information about\n" |
| 10132 | "Display the received routes from neighbor\n") |
| 10133 | { |
| 10134 | struct peer *peer; |
| 10135 | |
| 10136 | if (argc == 2) |
| 10137 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10138 | else |
| 10139 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10140 | |
| 10141 | if (! peer) |
| 10142 | return CMD_WARNING; |
| 10143 | |
| 10144 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1); |
| 10145 | } |
| 10146 | |
| 10147 | ALIAS (show_ip_bgp_view_neighbor_received_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10148 | show_ip_bgp_neighbor_received_routes_cmd, |
| 10149 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10150 | SHOW_STR |
| 10151 | IP_STR |
| 10152 | BGP_STR |
| 10153 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10154 | "Neighbor to display information about\n" |
| 10155 | "Neighbor to display information about\n" |
| 10156 | "Display the received routes from neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10157 | |
| 10158 | DEFUN (show_ip_bgp_ipv4_neighbor_received_routes, |
| 10159 | show_ip_bgp_ipv4_neighbor_received_routes_cmd, |
| 10160 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10161 | SHOW_STR |
| 10162 | IP_STR |
| 10163 | BGP_STR |
| 10164 | "Address family\n" |
| 10165 | "Address Family modifier\n" |
| 10166 | "Address Family modifier\n" |
| 10167 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10168 | "Neighbor to display information about\n" |
| 10169 | "Neighbor to display information about\n" |
| 10170 | "Display the received routes from neighbor\n") |
| 10171 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10172 | struct peer *peer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10173 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10174 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 10175 | if (! peer) |
| 10176 | return CMD_WARNING; |
| 10177 | |
| 10178 | if (strncmp (argv[0], "m", 1) == 0) |
| 10179 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1); |
| 10180 | |
| 10181 | return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10182 | } |
| 10183 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10184 | DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes, |
| 10185 | show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd, |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10186 | "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)", |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10187 | SHOW_STR |
| 10188 | BGP_STR |
| 10189 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10190 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10191 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10192 | "Address family\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10193 | "Address family modifier\n" |
| 10194 | "Address family modifier\n" |
| 10195 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10196 | "Neighbor to display information about\n" |
| 10197 | "Neighbor to display information about\n" |
| 10198 | "Display the advertised routes to neighbor\n" |
| 10199 | "Display the received routes from neighbor\n") |
| 10200 | { |
| 10201 | int afi; |
| 10202 | int safi; |
| 10203 | int in; |
| 10204 | struct peer *peer; |
| 10205 | |
David Lamparter | 94bad67 | 2015-03-03 08:52:22 +0100 | [diff] [blame] | 10206 | peer = peer_lookup_in_view (vty, argv[0], argv[3]); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10207 | |
| 10208 | if (! peer) |
| 10209 | return CMD_WARNING; |
| 10210 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10211 | afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP; |
| 10212 | safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10213 | in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0; |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10214 | |
| 10215 | return peer_adj_routes (vty, peer, afi, safi, in); |
| 10216 | } |
| 10217 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10218 | DEFUN (show_ip_bgp_neighbor_received_prefix_filter, |
| 10219 | show_ip_bgp_neighbor_received_prefix_filter_cmd, |
| 10220 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10221 | SHOW_STR |
| 10222 | IP_STR |
| 10223 | BGP_STR |
| 10224 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10225 | "Neighbor to display information about\n" |
| 10226 | "Neighbor to display information about\n" |
| 10227 | "Display information received from a BGP neighbor\n" |
| 10228 | "Display the prefixlist filter\n") |
| 10229 | { |
| 10230 | char name[BUFSIZ]; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10231 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10232 | struct peer *peer; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10233 | int count, ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10234 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10235 | ret = str2sockunion (argv[0], &su); |
| 10236 | if (ret < 0) |
| 10237 | { |
| 10238 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); |
| 10239 | return CMD_WARNING; |
| 10240 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10241 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10242 | peer = peer_lookup (NULL, &su); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10243 | if (! peer) |
| 10244 | return CMD_WARNING; |
| 10245 | |
| 10246 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); |
| 10247 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name); |
| 10248 | if (count) |
| 10249 | { |
| 10250 | vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); |
| 10251 | prefix_bgp_show_prefix_list (vty, AFI_IP, name); |
| 10252 | } |
| 10253 | |
| 10254 | return CMD_SUCCESS; |
| 10255 | } |
| 10256 | |
| 10257 | DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter, |
| 10258 | show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd, |
| 10259 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10260 | SHOW_STR |
| 10261 | IP_STR |
| 10262 | BGP_STR |
| 10263 | "Address family\n" |
| 10264 | "Address Family modifier\n" |
| 10265 | "Address Family modifier\n" |
| 10266 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10267 | "Neighbor to display information about\n" |
| 10268 | "Neighbor to display information about\n" |
| 10269 | "Display information received from a BGP neighbor\n" |
| 10270 | "Display the prefixlist filter\n") |
| 10271 | { |
| 10272 | char name[BUFSIZ]; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10273 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10274 | struct peer *peer; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10275 | int count, ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10276 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10277 | ret = str2sockunion (argv[1], &su); |
| 10278 | if (ret < 0) |
| 10279 | { |
| 10280 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); |
| 10281 | return CMD_WARNING; |
| 10282 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10283 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10284 | peer = peer_lookup (NULL, &su); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10285 | if (! peer) |
| 10286 | return CMD_WARNING; |
| 10287 | |
| 10288 | if (strncmp (argv[0], "m", 1) == 0) |
| 10289 | { |
| 10290 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST); |
| 10291 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name); |
| 10292 | if (count) |
| 10293 | { |
| 10294 | vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE); |
| 10295 | prefix_bgp_show_prefix_list (vty, AFI_IP, name); |
| 10296 | } |
| 10297 | } |
| 10298 | else |
| 10299 | { |
| 10300 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST); |
| 10301 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name); |
| 10302 | if (count) |
| 10303 | { |
| 10304 | vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE); |
| 10305 | prefix_bgp_show_prefix_list (vty, AFI_IP, name); |
| 10306 | } |
| 10307 | } |
| 10308 | |
| 10309 | return CMD_SUCCESS; |
| 10310 | } |
| 10311 | |
| 10312 | |
| 10313 | #ifdef HAVE_IPV6 |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10314 | ALIAS (show_bgp_view_neighbor_received_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10315 | show_bgp_neighbor_received_routes_cmd, |
| 10316 | "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10317 | SHOW_STR |
| 10318 | BGP_STR |
| 10319 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10320 | "Neighbor to display information about\n" |
| 10321 | "Neighbor to display information about\n" |
| 10322 | "Display the received routes from neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10323 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10324 | ALIAS (show_bgp_view_neighbor_received_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10325 | show_bgp_ipv6_neighbor_received_routes_cmd, |
| 10326 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10327 | SHOW_STR |
| 10328 | BGP_STR |
| 10329 | "Address family\n" |
| 10330 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10331 | "Neighbor to display information about\n" |
| 10332 | "Neighbor to display information about\n" |
| 10333 | "Display the received routes from neighbor\n") |
| 10334 | |
| 10335 | DEFUN (show_bgp_neighbor_received_prefix_filter, |
| 10336 | show_bgp_neighbor_received_prefix_filter_cmd, |
| 10337 | "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10338 | SHOW_STR |
| 10339 | BGP_STR |
| 10340 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10341 | "Neighbor to display information about\n" |
| 10342 | "Neighbor to display information about\n" |
| 10343 | "Display information received from a BGP neighbor\n" |
| 10344 | "Display the prefixlist filter\n") |
| 10345 | { |
| 10346 | char name[BUFSIZ]; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10347 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10348 | struct peer *peer; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10349 | int count, ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10350 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10351 | ret = str2sockunion (argv[0], &su); |
| 10352 | if (ret < 0) |
| 10353 | { |
| 10354 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); |
| 10355 | return CMD_WARNING; |
| 10356 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10357 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10358 | peer = peer_lookup (NULL, &su); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10359 | if (! peer) |
| 10360 | return CMD_WARNING; |
| 10361 | |
| 10362 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); |
| 10363 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name); |
| 10364 | if (count) |
| 10365 | { |
| 10366 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
| 10367 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name); |
| 10368 | } |
| 10369 | |
| 10370 | return CMD_SUCCESS; |
| 10371 | } |
| 10372 | |
| 10373 | ALIAS (show_bgp_neighbor_received_prefix_filter, |
| 10374 | show_bgp_ipv6_neighbor_received_prefix_filter_cmd, |
| 10375 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10376 | SHOW_STR |
| 10377 | BGP_STR |
| 10378 | "Address family\n" |
| 10379 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10380 | "Neighbor to display information about\n" |
| 10381 | "Neighbor to display information about\n" |
| 10382 | "Display information received from a BGP neighbor\n" |
| 10383 | "Display the prefixlist filter\n") |
| 10384 | |
| 10385 | /* old command */ |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10386 | ALIAS (show_bgp_view_neighbor_received_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10387 | ipv6_bgp_neighbor_received_routes_cmd, |
| 10388 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10389 | SHOW_STR |
| 10390 | IPV6_STR |
| 10391 | BGP_STR |
| 10392 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10393 | "Neighbor to display information about\n" |
| 10394 | "Neighbor to display information about\n" |
| 10395 | "Display the received routes from neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10396 | |
| 10397 | /* old command */ |
| 10398 | DEFUN (ipv6_mbgp_neighbor_received_routes, |
| 10399 | ipv6_mbgp_neighbor_received_routes_cmd, |
| 10400 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes", |
| 10401 | SHOW_STR |
| 10402 | IPV6_STR |
| 10403 | MBGP_STR |
| 10404 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10405 | "Neighbor to display information about\n" |
| 10406 | "Neighbor to display information about\n" |
| 10407 | "Display the received routes from neighbor\n") |
| 10408 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10409 | struct peer *peer; |
| 10410 | |
| 10411 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10412 | if (! peer) |
| 10413 | return CMD_WARNING; |
| 10414 | |
| 10415 | return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10416 | } |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10417 | |
| 10418 | DEFUN (show_bgp_view_neighbor_received_prefix_filter, |
| 10419 | show_bgp_view_neighbor_received_prefix_filter_cmd, |
| 10420 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10421 | SHOW_STR |
| 10422 | BGP_STR |
| 10423 | "BGP view\n" |
| 10424 | "View name\n" |
| 10425 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10426 | "Neighbor to display information about\n" |
| 10427 | "Neighbor to display information about\n" |
| 10428 | "Display information received from a BGP neighbor\n" |
| 10429 | "Display the prefixlist filter\n") |
| 10430 | { |
| 10431 | char name[BUFSIZ]; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10432 | union sockunion su; |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10433 | struct peer *peer; |
| 10434 | struct bgp *bgp; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10435 | int count, ret; |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10436 | |
| 10437 | /* BGP structure lookup. */ |
| 10438 | bgp = bgp_lookup_by_name (argv[0]); |
| 10439 | if (bgp == NULL) |
| 10440 | { |
| 10441 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 10442 | return CMD_WARNING; |
| 10443 | } |
| 10444 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10445 | ret = str2sockunion (argv[1], &su); |
| 10446 | if (ret < 0) |
| 10447 | { |
| 10448 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); |
| 10449 | return CMD_WARNING; |
| 10450 | } |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10451 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 10452 | peer = peer_lookup (bgp, &su); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10453 | if (! peer) |
| 10454 | return CMD_WARNING; |
| 10455 | |
| 10456 | sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST); |
| 10457 | count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name); |
| 10458 | if (count) |
| 10459 | { |
| 10460 | vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE); |
| 10461 | prefix_bgp_show_prefix_list (vty, AFI_IP6, name); |
| 10462 | } |
| 10463 | |
| 10464 | return CMD_SUCCESS; |
| 10465 | } |
| 10466 | |
| 10467 | ALIAS (show_bgp_view_neighbor_received_prefix_filter, |
| 10468 | show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd, |
| 10469 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter", |
| 10470 | SHOW_STR |
| 10471 | BGP_STR |
| 10472 | "BGP view\n" |
| 10473 | "View name\n" |
| 10474 | "Address family\n" |
| 10475 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10476 | "Neighbor to display information about\n" |
| 10477 | "Neighbor to display information about\n" |
| 10478 | "Display information received from a BGP neighbor\n" |
| 10479 | "Display the prefixlist filter\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10480 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 10481 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 10482 | static int |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10483 | bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10484 | safi_t safi, enum bgp_show_type type) |
| 10485 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10486 | if (! peer || ! peer->afc[afi][safi]) |
| 10487 | { |
| 10488 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10489 | return CMD_WARNING; |
| 10490 | } |
| 10491 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 10492 | return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10493 | } |
| 10494 | |
| 10495 | DEFUN (show_ip_bgp_neighbor_routes, |
| 10496 | show_ip_bgp_neighbor_routes_cmd, |
| 10497 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes", |
| 10498 | SHOW_STR |
| 10499 | IP_STR |
| 10500 | BGP_STR |
| 10501 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10502 | "Neighbor to display information about\n" |
| 10503 | "Neighbor to display information about\n" |
| 10504 | "Display routes learned from neighbor\n") |
| 10505 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10506 | struct peer *peer; |
| 10507 | |
| 10508 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10509 | if (! peer) |
| 10510 | return CMD_WARNING; |
| 10511 | |
| 10512 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10513 | bgp_show_type_neighbor); |
| 10514 | } |
| 10515 | |
| 10516 | DEFUN (show_ip_bgp_neighbor_flap, |
| 10517 | show_ip_bgp_neighbor_flap_cmd, |
| 10518 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics", |
| 10519 | SHOW_STR |
| 10520 | IP_STR |
| 10521 | BGP_STR |
| 10522 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10523 | "Neighbor to display information about\n" |
| 10524 | "Neighbor to display information about\n" |
| 10525 | "Display flap statistics of the routes learned from neighbor\n") |
| 10526 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10527 | struct peer *peer; |
| 10528 | |
| 10529 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10530 | if (! peer) |
| 10531 | return CMD_WARNING; |
| 10532 | |
| 10533 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10534 | bgp_show_type_flap_neighbor); |
| 10535 | } |
| 10536 | |
| 10537 | DEFUN (show_ip_bgp_neighbor_damp, |
| 10538 | show_ip_bgp_neighbor_damp_cmd, |
| 10539 | "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes", |
| 10540 | SHOW_STR |
| 10541 | IP_STR |
| 10542 | BGP_STR |
| 10543 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10544 | "Neighbor to display information about\n" |
| 10545 | "Neighbor to display information about\n" |
| 10546 | "Display the dampened routes received from neighbor\n") |
| 10547 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10548 | struct peer *peer; |
| 10549 | |
| 10550 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10551 | if (! peer) |
| 10552 | return CMD_WARNING; |
| 10553 | |
| 10554 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10555 | bgp_show_type_damp_neighbor); |
| 10556 | } |
| 10557 | |
| 10558 | DEFUN (show_ip_bgp_ipv4_neighbor_routes, |
| 10559 | show_ip_bgp_ipv4_neighbor_routes_cmd, |
| 10560 | "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes", |
| 10561 | SHOW_STR |
| 10562 | IP_STR |
| 10563 | BGP_STR |
| 10564 | "Address family\n" |
| 10565 | "Address Family modifier\n" |
| 10566 | "Address Family modifier\n" |
| 10567 | "Detailed information on TCP and BGP neighbor connections\n" |
| 10568 | "Neighbor to display information about\n" |
| 10569 | "Neighbor to display information about\n" |
| 10570 | "Display routes learned from neighbor\n") |
| 10571 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10572 | struct peer *peer; |
| 10573 | |
| 10574 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 10575 | if (! peer) |
| 10576 | return CMD_WARNING; |
| 10577 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10578 | if (strncmp (argv[0], "m", 1) == 0) |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10579 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10580 | bgp_show_type_neighbor); |
| 10581 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10582 | return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 10583 | bgp_show_type_neighbor); |
| 10584 | } |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 10585 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10586 | DEFUN (show_ip_bgp_view_rsclient, |
| 10587 | show_ip_bgp_view_rsclient_cmd, |
| 10588 | "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)", |
| 10589 | SHOW_STR |
| 10590 | IP_STR |
| 10591 | BGP_STR |
| 10592 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10593 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10594 | "Information about Route Server Client\n" |
| 10595 | NEIGHBOR_ADDR_STR) |
| 10596 | { |
| 10597 | struct bgp_table *table; |
| 10598 | struct peer *peer; |
| 10599 | |
| 10600 | if (argc == 2) |
| 10601 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10602 | else |
| 10603 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10604 | |
| 10605 | if (! peer) |
| 10606 | return CMD_WARNING; |
| 10607 | |
| 10608 | if (! peer->afc[AFI_IP][SAFI_UNICAST]) |
| 10609 | { |
| 10610 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10611 | VTY_NEWLINE); |
| 10612 | return CMD_WARNING; |
| 10613 | } |
| 10614 | |
| 10615 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST], |
| 10616 | PEER_FLAG_RSERVER_CLIENT)) |
| 10617 | { |
| 10618 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10619 | VTY_NEWLINE); |
| 10620 | return CMD_WARNING; |
| 10621 | } |
| 10622 | |
| 10623 | table = peer->rib[AFI_IP][SAFI_UNICAST]; |
| 10624 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 10625 | return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10626 | } |
| 10627 | |
| 10628 | ALIAS (show_ip_bgp_view_rsclient, |
| 10629 | show_ip_bgp_rsclient_cmd, |
| 10630 | "show ip bgp rsclient (A.B.C.D|X:X::X:X)", |
| 10631 | SHOW_STR |
| 10632 | IP_STR |
| 10633 | BGP_STR |
| 10634 | "Information about Route Server Client\n" |
| 10635 | NEIGHBOR_ADDR_STR) |
| 10636 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10637 | DEFUN (show_bgp_view_ipv4_safi_rsclient, |
| 10638 | show_bgp_view_ipv4_safi_rsclient_cmd, |
| 10639 | "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)", |
| 10640 | SHOW_STR |
| 10641 | BGP_STR |
| 10642 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10643 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10644 | "Address family\n" |
| 10645 | "Address Family modifier\n" |
| 10646 | "Address Family modifier\n" |
| 10647 | "Information about Route Server Client\n" |
| 10648 | NEIGHBOR_ADDR_STR) |
| 10649 | { |
| 10650 | struct bgp_table *table; |
| 10651 | struct peer *peer; |
| 10652 | safi_t safi; |
| 10653 | |
| 10654 | if (argc == 3) { |
| 10655 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 10656 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10657 | } else { |
| 10658 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 10659 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10660 | } |
| 10661 | |
| 10662 | if (! peer) |
| 10663 | return CMD_WARNING; |
| 10664 | |
| 10665 | if (! peer->afc[AFI_IP][safi]) |
| 10666 | { |
| 10667 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10668 | VTY_NEWLINE); |
| 10669 | return CMD_WARNING; |
| 10670 | } |
| 10671 | |
| 10672 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi], |
| 10673 | PEER_FLAG_RSERVER_CLIENT)) |
| 10674 | { |
| 10675 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10676 | VTY_NEWLINE); |
| 10677 | return CMD_WARNING; |
| 10678 | } |
| 10679 | |
| 10680 | table = peer->rib[AFI_IP][safi]; |
| 10681 | |
| 10682 | return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL); |
| 10683 | } |
| 10684 | |
| 10685 | ALIAS (show_bgp_view_ipv4_safi_rsclient, |
| 10686 | show_bgp_ipv4_safi_rsclient_cmd, |
| 10687 | "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)", |
| 10688 | SHOW_STR |
| 10689 | BGP_STR |
| 10690 | "Address family\n" |
| 10691 | "Address Family modifier\n" |
| 10692 | "Address Family modifier\n" |
| 10693 | "Information about Route Server Client\n" |
| 10694 | NEIGHBOR_ADDR_STR) |
| 10695 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10696 | DEFUN (show_ip_bgp_view_rsclient_route, |
| 10697 | show_ip_bgp_view_rsclient_route_cmd, |
Michael Lambert | a8bf6f5 | 2008-09-24 17:23:11 +0100 | [diff] [blame] | 10698 | "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D", |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10699 | SHOW_STR |
| 10700 | IP_STR |
| 10701 | BGP_STR |
| 10702 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10703 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10704 | "Information about Route Server Client\n" |
| 10705 | NEIGHBOR_ADDR_STR |
| 10706 | "Network in the BGP routing table to display\n") |
| 10707 | { |
| 10708 | struct bgp *bgp; |
| 10709 | struct peer *peer; |
| 10710 | |
| 10711 | /* BGP structure lookup. */ |
| 10712 | if (argc == 3) |
| 10713 | { |
| 10714 | bgp = bgp_lookup_by_name (argv[0]); |
| 10715 | if (bgp == NULL) |
| 10716 | { |
| 10717 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 10718 | return CMD_WARNING; |
| 10719 | } |
| 10720 | } |
| 10721 | else |
| 10722 | { |
| 10723 | bgp = bgp_get_default (); |
| 10724 | if (bgp == NULL) |
| 10725 | { |
| 10726 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 10727 | return CMD_WARNING; |
| 10728 | } |
| 10729 | } |
| 10730 | |
| 10731 | if (argc == 3) |
| 10732 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10733 | else |
| 10734 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10735 | |
| 10736 | if (! peer) |
| 10737 | return CMD_WARNING; |
| 10738 | |
| 10739 | if (! peer->afc[AFI_IP][SAFI_UNICAST]) |
| 10740 | { |
| 10741 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10742 | VTY_NEWLINE); |
| 10743 | return CMD_WARNING; |
| 10744 | } |
| 10745 | |
| 10746 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST], |
| 10747 | PEER_FLAG_RSERVER_CLIENT)) |
| 10748 | { |
| 10749 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10750 | VTY_NEWLINE); |
| 10751 | return CMD_WARNING; |
| 10752 | } |
| 10753 | |
| 10754 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST], |
| 10755 | (argc == 3) ? argv[2] : argv[1], |
| 10756 | AFI_IP, SAFI_UNICAST, NULL, 0); |
| 10757 | } |
| 10758 | |
| 10759 | ALIAS (show_ip_bgp_view_rsclient_route, |
| 10760 | show_ip_bgp_rsclient_route_cmd, |
| 10761 | "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D", |
| 10762 | SHOW_STR |
| 10763 | IP_STR |
| 10764 | BGP_STR |
| 10765 | "Information about Route Server Client\n" |
| 10766 | NEIGHBOR_ADDR_STR |
| 10767 | "Network in the BGP routing table to display\n") |
| 10768 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10769 | DEFUN (show_bgp_view_ipv4_safi_rsclient_route, |
| 10770 | show_bgp_view_ipv4_safi_rsclient_route_cmd, |
| 10771 | "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D", |
| 10772 | SHOW_STR |
| 10773 | BGP_STR |
| 10774 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10775 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10776 | "Address family\n" |
| 10777 | "Address Family modifier\n" |
| 10778 | "Address Family modifier\n" |
| 10779 | "Information about Route Server Client\n" |
| 10780 | NEIGHBOR_ADDR_STR |
| 10781 | "Network in the BGP routing table to display\n") |
| 10782 | { |
| 10783 | struct bgp *bgp; |
| 10784 | struct peer *peer; |
| 10785 | safi_t safi; |
| 10786 | |
| 10787 | /* BGP structure lookup. */ |
| 10788 | if (argc == 4) |
| 10789 | { |
| 10790 | bgp = bgp_lookup_by_name (argv[0]); |
| 10791 | if (bgp == NULL) |
| 10792 | { |
| 10793 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 10794 | return CMD_WARNING; |
| 10795 | } |
| 10796 | } |
| 10797 | else |
| 10798 | { |
| 10799 | bgp = bgp_get_default (); |
| 10800 | if (bgp == NULL) |
| 10801 | { |
| 10802 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 10803 | return CMD_WARNING; |
| 10804 | } |
| 10805 | } |
| 10806 | |
| 10807 | if (argc == 4) { |
| 10808 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 10809 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10810 | } else { |
| 10811 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 10812 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10813 | } |
| 10814 | |
| 10815 | if (! peer) |
| 10816 | return CMD_WARNING; |
| 10817 | |
| 10818 | if (! peer->afc[AFI_IP][safi]) |
| 10819 | { |
| 10820 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10821 | VTY_NEWLINE); |
| 10822 | return CMD_WARNING; |
| 10823 | } |
| 10824 | |
| 10825 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi], |
| 10826 | PEER_FLAG_RSERVER_CLIENT)) |
| 10827 | { |
| 10828 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10829 | VTY_NEWLINE); |
| 10830 | return CMD_WARNING; |
| 10831 | } |
| 10832 | |
| 10833 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi], |
| 10834 | (argc == 4) ? argv[3] : argv[2], |
| 10835 | AFI_IP, safi, NULL, 0); |
| 10836 | } |
| 10837 | |
| 10838 | ALIAS (show_bgp_view_ipv4_safi_rsclient_route, |
| 10839 | show_bgp_ipv4_safi_rsclient_route_cmd, |
| 10840 | "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D", |
| 10841 | SHOW_STR |
| 10842 | BGP_STR |
| 10843 | "Address family\n" |
| 10844 | "Address Family modifier\n" |
| 10845 | "Address Family modifier\n" |
| 10846 | "Information about Route Server Client\n" |
| 10847 | NEIGHBOR_ADDR_STR |
| 10848 | "Network in the BGP routing table to display\n") |
| 10849 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10850 | DEFUN (show_ip_bgp_view_rsclient_prefix, |
| 10851 | show_ip_bgp_view_rsclient_prefix_cmd, |
| 10852 | "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M", |
| 10853 | SHOW_STR |
| 10854 | IP_STR |
| 10855 | BGP_STR |
| 10856 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10857 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 10858 | "Information about Route Server Client\n" |
| 10859 | NEIGHBOR_ADDR_STR |
| 10860 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 10861 | { |
| 10862 | struct bgp *bgp; |
| 10863 | struct peer *peer; |
| 10864 | |
| 10865 | /* BGP structure lookup. */ |
| 10866 | if (argc == 3) |
| 10867 | { |
| 10868 | bgp = bgp_lookup_by_name (argv[0]); |
| 10869 | if (bgp == NULL) |
| 10870 | { |
| 10871 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 10872 | return CMD_WARNING; |
| 10873 | } |
| 10874 | } |
| 10875 | else |
| 10876 | { |
| 10877 | bgp = bgp_get_default (); |
| 10878 | if (bgp == NULL) |
| 10879 | { |
| 10880 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 10881 | return CMD_WARNING; |
| 10882 | } |
| 10883 | } |
| 10884 | |
| 10885 | if (argc == 3) |
| 10886 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 10887 | else |
| 10888 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 10889 | |
| 10890 | if (! peer) |
| 10891 | return CMD_WARNING; |
| 10892 | |
| 10893 | if (! peer->afc[AFI_IP][SAFI_UNICAST]) |
| 10894 | { |
| 10895 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10896 | VTY_NEWLINE); |
| 10897 | return CMD_WARNING; |
| 10898 | } |
| 10899 | |
| 10900 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST], |
| 10901 | PEER_FLAG_RSERVER_CLIENT)) |
| 10902 | { |
| 10903 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10904 | VTY_NEWLINE); |
| 10905 | return CMD_WARNING; |
| 10906 | } |
| 10907 | |
| 10908 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST], |
| 10909 | (argc == 3) ? argv[2] : argv[1], |
| 10910 | AFI_IP, SAFI_UNICAST, NULL, 1); |
| 10911 | } |
| 10912 | |
| 10913 | ALIAS (show_ip_bgp_view_rsclient_prefix, |
| 10914 | show_ip_bgp_rsclient_prefix_cmd, |
| 10915 | "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M", |
| 10916 | SHOW_STR |
| 10917 | IP_STR |
| 10918 | BGP_STR |
| 10919 | "Information about Route Server Client\n" |
| 10920 | NEIGHBOR_ADDR_STR |
| 10921 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 10922 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10923 | DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix, |
| 10924 | show_bgp_view_ipv4_safi_rsclient_prefix_cmd, |
| 10925 | "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M", |
| 10926 | SHOW_STR |
| 10927 | BGP_STR |
| 10928 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 10929 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 10930 | "Address family\n" |
| 10931 | "Address Family modifier\n" |
| 10932 | "Address Family modifier\n" |
| 10933 | "Information about Route Server Client\n" |
| 10934 | NEIGHBOR_ADDR_STR |
| 10935 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 10936 | { |
| 10937 | struct bgp *bgp; |
| 10938 | struct peer *peer; |
| 10939 | safi_t safi; |
| 10940 | |
| 10941 | /* BGP structure lookup. */ |
| 10942 | if (argc == 4) |
| 10943 | { |
| 10944 | bgp = bgp_lookup_by_name (argv[0]); |
| 10945 | if (bgp == NULL) |
| 10946 | { |
| 10947 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 10948 | return CMD_WARNING; |
| 10949 | } |
| 10950 | } |
| 10951 | else |
| 10952 | { |
| 10953 | bgp = bgp_get_default (); |
| 10954 | if (bgp == NULL) |
| 10955 | { |
| 10956 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 10957 | return CMD_WARNING; |
| 10958 | } |
| 10959 | } |
| 10960 | |
| 10961 | if (argc == 4) { |
| 10962 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 10963 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10964 | } else { |
| 10965 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 10966 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 10967 | } |
| 10968 | |
| 10969 | if (! peer) |
| 10970 | return CMD_WARNING; |
| 10971 | |
| 10972 | if (! peer->afc[AFI_IP][safi]) |
| 10973 | { |
| 10974 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 10975 | VTY_NEWLINE); |
| 10976 | return CMD_WARNING; |
| 10977 | } |
| 10978 | |
| 10979 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi], |
| 10980 | PEER_FLAG_RSERVER_CLIENT)) |
| 10981 | { |
| 10982 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 10983 | VTY_NEWLINE); |
| 10984 | return CMD_WARNING; |
| 10985 | } |
| 10986 | |
| 10987 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi], |
| 10988 | (argc == 4) ? argv[3] : argv[2], |
| 10989 | AFI_IP, safi, NULL, 1); |
| 10990 | } |
| 10991 | |
| 10992 | ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix, |
| 10993 | show_bgp_ipv4_safi_rsclient_prefix_cmd, |
| 10994 | "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M", |
| 10995 | SHOW_STR |
| 10996 | BGP_STR |
| 10997 | "Address family\n" |
| 10998 | "Address Family modifier\n" |
| 10999 | "Address Family modifier\n" |
| 11000 | "Information about Route Server Client\n" |
| 11001 | NEIGHBOR_ADDR_STR |
| 11002 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11003 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11004 | #ifdef HAVE_IPV6 |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11005 | DEFUN (show_bgp_view_neighbor_routes, |
| 11006 | show_bgp_view_neighbor_routes_cmd, |
| 11007 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes", |
| 11008 | SHOW_STR |
| 11009 | BGP_STR |
| 11010 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11011 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11012 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11013 | "Neighbor to display information about\n" |
| 11014 | "Neighbor to display information about\n" |
| 11015 | "Display routes learned from neighbor\n") |
| 11016 | { |
| 11017 | struct peer *peer; |
| 11018 | |
| 11019 | if (argc == 2) |
| 11020 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11021 | else |
| 11022 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11023 | |
| 11024 | if (! peer) |
| 11025 | return CMD_WARNING; |
| 11026 | |
| 11027 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
| 11028 | bgp_show_type_neighbor); |
| 11029 | } |
| 11030 | |
| 11031 | ALIAS (show_bgp_view_neighbor_routes, |
| 11032 | show_bgp_view_ipv6_neighbor_routes_cmd, |
| 11033 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes", |
| 11034 | SHOW_STR |
| 11035 | BGP_STR |
| 11036 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11037 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11038 | "Address family\n" |
| 11039 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11040 | "Neighbor to display information about\n" |
| 11041 | "Neighbor to display information about\n" |
| 11042 | "Display routes learned from neighbor\n") |
| 11043 | |
| 11044 | DEFUN (show_bgp_view_neighbor_damp, |
| 11045 | show_bgp_view_neighbor_damp_cmd, |
| 11046 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes", |
| 11047 | SHOW_STR |
| 11048 | BGP_STR |
| 11049 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11050 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11051 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11052 | "Neighbor to display information about\n" |
| 11053 | "Neighbor to display information about\n" |
| 11054 | "Display the dampened routes received from neighbor\n") |
| 11055 | { |
| 11056 | struct peer *peer; |
| 11057 | |
| 11058 | if (argc == 2) |
| 11059 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11060 | else |
| 11061 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11062 | |
| 11063 | if (! peer) |
| 11064 | return CMD_WARNING; |
| 11065 | |
| 11066 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
| 11067 | bgp_show_type_damp_neighbor); |
| 11068 | } |
| 11069 | |
| 11070 | ALIAS (show_bgp_view_neighbor_damp, |
| 11071 | show_bgp_view_ipv6_neighbor_damp_cmd, |
| 11072 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes", |
| 11073 | SHOW_STR |
| 11074 | BGP_STR |
| 11075 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11076 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11077 | "Address family\n" |
| 11078 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11079 | "Neighbor to display information about\n" |
| 11080 | "Neighbor to display information about\n" |
| 11081 | "Display the dampened routes received from neighbor\n") |
| 11082 | |
| 11083 | DEFUN (show_bgp_view_neighbor_flap, |
| 11084 | show_bgp_view_neighbor_flap_cmd, |
| 11085 | "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics", |
| 11086 | SHOW_STR |
| 11087 | BGP_STR |
| 11088 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11089 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11090 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11091 | "Neighbor to display information about\n" |
| 11092 | "Neighbor to display information about\n" |
| 11093 | "Display flap statistics of the routes learned from neighbor\n") |
| 11094 | { |
| 11095 | struct peer *peer; |
| 11096 | |
| 11097 | if (argc == 2) |
| 11098 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11099 | else |
| 11100 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11101 | |
| 11102 | if (! peer) |
| 11103 | return CMD_WARNING; |
| 11104 | |
| 11105 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST, |
| 11106 | bgp_show_type_flap_neighbor); |
| 11107 | } |
| 11108 | |
| 11109 | ALIAS (show_bgp_view_neighbor_flap, |
| 11110 | show_bgp_view_ipv6_neighbor_flap_cmd, |
| 11111 | "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics", |
| 11112 | SHOW_STR |
| 11113 | BGP_STR |
| 11114 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11115 | "View name\n" |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11116 | "Address family\n" |
| 11117 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11118 | "Neighbor to display information about\n" |
| 11119 | "Neighbor to display information about\n" |
| 11120 | "Display flap statistics of the routes learned from neighbor\n") |
| 11121 | |
| 11122 | ALIAS (show_bgp_view_neighbor_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11123 | show_bgp_neighbor_routes_cmd, |
| 11124 | "show bgp neighbors (A.B.C.D|X:X::X:X) routes", |
| 11125 | SHOW_STR |
| 11126 | BGP_STR |
| 11127 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11128 | "Neighbor to display information about\n" |
| 11129 | "Neighbor to display information about\n" |
| 11130 | "Display routes learned from neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11131 | |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11132 | |
| 11133 | ALIAS (show_bgp_view_neighbor_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11134 | show_bgp_ipv6_neighbor_routes_cmd, |
| 11135 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes", |
| 11136 | SHOW_STR |
| 11137 | BGP_STR |
| 11138 | "Address family\n" |
| 11139 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11140 | "Neighbor to display information about\n" |
| 11141 | "Neighbor to display information about\n" |
| 11142 | "Display routes learned from neighbor\n") |
| 11143 | |
| 11144 | /* old command */ |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11145 | ALIAS (show_bgp_view_neighbor_routes, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11146 | ipv6_bgp_neighbor_routes_cmd, |
| 11147 | "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes", |
| 11148 | SHOW_STR |
| 11149 | IPV6_STR |
| 11150 | BGP_STR |
| 11151 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11152 | "Neighbor to display information about\n" |
| 11153 | "Neighbor to display information about\n" |
| 11154 | "Display routes learned from neighbor\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11155 | |
| 11156 | /* old command */ |
| 11157 | DEFUN (ipv6_mbgp_neighbor_routes, |
| 11158 | ipv6_mbgp_neighbor_routes_cmd, |
| 11159 | "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes", |
| 11160 | SHOW_STR |
| 11161 | IPV6_STR |
| 11162 | MBGP_STR |
| 11163 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11164 | "Neighbor to display information about\n" |
| 11165 | "Neighbor to display information about\n" |
| 11166 | "Display routes learned from neighbor\n") |
| 11167 | { |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11168 | struct peer *peer; |
| 11169 | |
| 11170 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11171 | if (! peer) |
| 11172 | return CMD_WARNING; |
| 11173 | |
| 11174 | return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11175 | bgp_show_type_neighbor); |
| 11176 | } |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 11177 | |
| 11178 | ALIAS (show_bgp_view_neighbor_flap, |
| 11179 | show_bgp_neighbor_flap_cmd, |
| 11180 | "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics", |
| 11181 | SHOW_STR |
| 11182 | BGP_STR |
| 11183 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11184 | "Neighbor to display information about\n" |
| 11185 | "Neighbor to display information about\n" |
| 11186 | "Display flap statistics of the routes learned from neighbor\n") |
| 11187 | |
| 11188 | ALIAS (show_bgp_view_neighbor_flap, |
| 11189 | show_bgp_ipv6_neighbor_flap_cmd, |
| 11190 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics", |
| 11191 | SHOW_STR |
| 11192 | BGP_STR |
| 11193 | "Address family\n" |
| 11194 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11195 | "Neighbor to display information about\n" |
| 11196 | "Neighbor to display information about\n" |
| 11197 | "Display flap statistics of the routes learned from neighbor\n") |
| 11198 | |
| 11199 | ALIAS (show_bgp_view_neighbor_damp, |
| 11200 | show_bgp_neighbor_damp_cmd, |
| 11201 | "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes", |
| 11202 | SHOW_STR |
| 11203 | BGP_STR |
| 11204 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11205 | "Neighbor to display information about\n" |
| 11206 | "Neighbor to display information about\n" |
| 11207 | "Display the dampened routes received from neighbor\n") |
| 11208 | |
| 11209 | ALIAS (show_bgp_view_neighbor_damp, |
| 11210 | show_bgp_ipv6_neighbor_damp_cmd, |
| 11211 | "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes", |
| 11212 | SHOW_STR |
| 11213 | BGP_STR |
| 11214 | "Address family\n" |
| 11215 | "Detailed information on TCP and BGP neighbor connections\n" |
| 11216 | "Neighbor to display information about\n" |
| 11217 | "Neighbor to display information about\n" |
paul | c001ae6 | 2003-11-03 12:37:43 +0000 | [diff] [blame] | 11218 | "Display the dampened routes received from neighbor\n") |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11219 | |
| 11220 | DEFUN (show_bgp_view_rsclient, |
| 11221 | show_bgp_view_rsclient_cmd, |
| 11222 | "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)", |
| 11223 | SHOW_STR |
| 11224 | BGP_STR |
| 11225 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11226 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11227 | "Information about Route Server Client\n" |
| 11228 | NEIGHBOR_ADDR_STR) |
| 11229 | { |
| 11230 | struct bgp_table *table; |
| 11231 | struct peer *peer; |
| 11232 | |
| 11233 | if (argc == 2) |
| 11234 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11235 | else |
| 11236 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11237 | |
| 11238 | if (! peer) |
| 11239 | return CMD_WARNING; |
| 11240 | |
| 11241 | if (! peer->afc[AFI_IP6][SAFI_UNICAST]) |
| 11242 | { |
| 11243 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11244 | VTY_NEWLINE); |
| 11245 | return CMD_WARNING; |
| 11246 | } |
| 11247 | |
| 11248 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST], |
| 11249 | PEER_FLAG_RSERVER_CLIENT)) |
| 11250 | { |
| 11251 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11252 | VTY_NEWLINE); |
| 11253 | return CMD_WARNING; |
| 11254 | } |
| 11255 | |
| 11256 | table = peer->rib[AFI_IP6][SAFI_UNICAST]; |
| 11257 | |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 11258 | return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11259 | } |
| 11260 | |
| 11261 | ALIAS (show_bgp_view_rsclient, |
| 11262 | show_bgp_rsclient_cmd, |
| 11263 | "show bgp rsclient (A.B.C.D|X:X::X:X)", |
| 11264 | SHOW_STR |
| 11265 | BGP_STR |
| 11266 | "Information about Route Server Client\n" |
| 11267 | NEIGHBOR_ADDR_STR) |
| 11268 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11269 | DEFUN (show_bgp_view_ipv6_safi_rsclient, |
| 11270 | show_bgp_view_ipv6_safi_rsclient_cmd, |
| 11271 | "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)", |
| 11272 | SHOW_STR |
| 11273 | BGP_STR |
| 11274 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11275 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11276 | "Address family\n" |
| 11277 | "Address Family modifier\n" |
| 11278 | "Address Family modifier\n" |
| 11279 | "Information about Route Server Client\n" |
| 11280 | NEIGHBOR_ADDR_STR) |
| 11281 | { |
| 11282 | struct bgp_table *table; |
| 11283 | struct peer *peer; |
| 11284 | safi_t safi; |
| 11285 | |
| 11286 | if (argc == 3) { |
| 11287 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 11288 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11289 | } else { |
| 11290 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 11291 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11292 | } |
| 11293 | |
| 11294 | if (! peer) |
| 11295 | return CMD_WARNING; |
| 11296 | |
| 11297 | if (! peer->afc[AFI_IP6][safi]) |
| 11298 | { |
| 11299 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11300 | VTY_NEWLINE); |
| 11301 | return CMD_WARNING; |
| 11302 | } |
| 11303 | |
| 11304 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi], |
| 11305 | PEER_FLAG_RSERVER_CLIENT)) |
| 11306 | { |
| 11307 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11308 | VTY_NEWLINE); |
| 11309 | return CMD_WARNING; |
| 11310 | } |
| 11311 | |
| 11312 | table = peer->rib[AFI_IP6][safi]; |
| 11313 | |
| 11314 | return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL); |
| 11315 | } |
| 11316 | |
| 11317 | ALIAS (show_bgp_view_ipv6_safi_rsclient, |
| 11318 | show_bgp_ipv6_safi_rsclient_cmd, |
| 11319 | "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)", |
| 11320 | SHOW_STR |
| 11321 | BGP_STR |
| 11322 | "Address family\n" |
| 11323 | "Address Family modifier\n" |
| 11324 | "Address Family modifier\n" |
| 11325 | "Information about Route Server Client\n" |
| 11326 | NEIGHBOR_ADDR_STR) |
| 11327 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11328 | DEFUN (show_bgp_view_rsclient_route, |
| 11329 | show_bgp_view_rsclient_route_cmd, |
| 11330 | "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X", |
| 11331 | SHOW_STR |
| 11332 | BGP_STR |
| 11333 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11334 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11335 | "Information about Route Server Client\n" |
| 11336 | NEIGHBOR_ADDR_STR |
| 11337 | "Network in the BGP routing table to display\n") |
| 11338 | { |
| 11339 | struct bgp *bgp; |
| 11340 | struct peer *peer; |
| 11341 | |
| 11342 | /* BGP structure lookup. */ |
| 11343 | if (argc == 3) |
| 11344 | { |
| 11345 | bgp = bgp_lookup_by_name (argv[0]); |
| 11346 | if (bgp == NULL) |
| 11347 | { |
| 11348 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 11349 | return CMD_WARNING; |
| 11350 | } |
| 11351 | } |
| 11352 | else |
| 11353 | { |
| 11354 | bgp = bgp_get_default (); |
| 11355 | if (bgp == NULL) |
| 11356 | { |
| 11357 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 11358 | return CMD_WARNING; |
| 11359 | } |
| 11360 | } |
| 11361 | |
| 11362 | if (argc == 3) |
| 11363 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11364 | else |
| 11365 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11366 | |
| 11367 | if (! peer) |
| 11368 | return CMD_WARNING; |
| 11369 | |
| 11370 | if (! peer->afc[AFI_IP6][SAFI_UNICAST]) |
| 11371 | { |
| 11372 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11373 | VTY_NEWLINE); |
| 11374 | return CMD_WARNING; |
| 11375 | } |
| 11376 | |
| 11377 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST], |
| 11378 | PEER_FLAG_RSERVER_CLIENT)) |
| 11379 | { |
| 11380 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11381 | VTY_NEWLINE); |
| 11382 | return CMD_WARNING; |
| 11383 | } |
| 11384 | |
| 11385 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST], |
| 11386 | (argc == 3) ? argv[2] : argv[1], |
| 11387 | AFI_IP6, SAFI_UNICAST, NULL, 0); |
| 11388 | } |
| 11389 | |
| 11390 | ALIAS (show_bgp_view_rsclient_route, |
| 11391 | show_bgp_rsclient_route_cmd, |
| 11392 | "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X", |
| 11393 | SHOW_STR |
| 11394 | BGP_STR |
| 11395 | "Information about Route Server Client\n" |
| 11396 | NEIGHBOR_ADDR_STR |
| 11397 | "Network in the BGP routing table to display\n") |
| 11398 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11399 | DEFUN (show_bgp_view_ipv6_safi_rsclient_route, |
| 11400 | show_bgp_view_ipv6_safi_rsclient_route_cmd, |
| 11401 | "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X", |
| 11402 | SHOW_STR |
| 11403 | BGP_STR |
| 11404 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11405 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11406 | "Address family\n" |
| 11407 | "Address Family modifier\n" |
| 11408 | "Address Family modifier\n" |
| 11409 | "Information about Route Server Client\n" |
| 11410 | NEIGHBOR_ADDR_STR |
| 11411 | "Network in the BGP routing table to display\n") |
| 11412 | { |
| 11413 | struct bgp *bgp; |
| 11414 | struct peer *peer; |
| 11415 | safi_t safi; |
| 11416 | |
| 11417 | /* BGP structure lookup. */ |
| 11418 | if (argc == 4) |
| 11419 | { |
| 11420 | bgp = bgp_lookup_by_name (argv[0]); |
| 11421 | if (bgp == NULL) |
| 11422 | { |
| 11423 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 11424 | return CMD_WARNING; |
| 11425 | } |
| 11426 | } |
| 11427 | else |
| 11428 | { |
| 11429 | bgp = bgp_get_default (); |
| 11430 | if (bgp == NULL) |
| 11431 | { |
| 11432 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 11433 | return CMD_WARNING; |
| 11434 | } |
| 11435 | } |
| 11436 | |
| 11437 | if (argc == 4) { |
| 11438 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 11439 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11440 | } else { |
| 11441 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 11442 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11443 | } |
| 11444 | |
| 11445 | if (! peer) |
| 11446 | return CMD_WARNING; |
| 11447 | |
| 11448 | if (! peer->afc[AFI_IP6][safi]) |
| 11449 | { |
| 11450 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11451 | VTY_NEWLINE); |
| 11452 | return CMD_WARNING; |
| 11453 | } |
| 11454 | |
| 11455 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi], |
| 11456 | PEER_FLAG_RSERVER_CLIENT)) |
| 11457 | { |
| 11458 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11459 | VTY_NEWLINE); |
| 11460 | return CMD_WARNING; |
| 11461 | } |
| 11462 | |
| 11463 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi], |
| 11464 | (argc == 4) ? argv[3] : argv[2], |
| 11465 | AFI_IP6, safi, NULL, 0); |
| 11466 | } |
| 11467 | |
| 11468 | ALIAS (show_bgp_view_ipv6_safi_rsclient_route, |
| 11469 | show_bgp_ipv6_safi_rsclient_route_cmd, |
| 11470 | "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X", |
| 11471 | SHOW_STR |
| 11472 | BGP_STR |
| 11473 | "Address family\n" |
| 11474 | "Address Family modifier\n" |
| 11475 | "Address Family modifier\n" |
| 11476 | "Information about Route Server Client\n" |
| 11477 | NEIGHBOR_ADDR_STR |
| 11478 | "Network in the BGP routing table to display\n") |
| 11479 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11480 | DEFUN (show_bgp_view_rsclient_prefix, |
| 11481 | show_bgp_view_rsclient_prefix_cmd, |
| 11482 | "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M", |
| 11483 | SHOW_STR |
| 11484 | BGP_STR |
| 11485 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11486 | "View name\n" |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 11487 | "Information about Route Server Client\n" |
| 11488 | NEIGHBOR_ADDR_STR |
| 11489 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 11490 | { |
| 11491 | struct bgp *bgp; |
| 11492 | struct peer *peer; |
| 11493 | |
| 11494 | /* BGP structure lookup. */ |
| 11495 | if (argc == 3) |
| 11496 | { |
| 11497 | bgp = bgp_lookup_by_name (argv[0]); |
| 11498 | if (bgp == NULL) |
| 11499 | { |
| 11500 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 11501 | return CMD_WARNING; |
| 11502 | } |
| 11503 | } |
| 11504 | else |
| 11505 | { |
| 11506 | bgp = bgp_get_default (); |
| 11507 | if (bgp == NULL) |
| 11508 | { |
| 11509 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 11510 | return CMD_WARNING; |
| 11511 | } |
| 11512 | } |
| 11513 | |
| 11514 | if (argc == 3) |
| 11515 | peer = peer_lookup_in_view (vty, argv[0], argv[1]); |
| 11516 | else |
| 11517 | peer = peer_lookup_in_view (vty, NULL, argv[0]); |
| 11518 | |
| 11519 | if (! peer) |
| 11520 | return CMD_WARNING; |
| 11521 | |
| 11522 | if (! peer->afc[AFI_IP6][SAFI_UNICAST]) |
| 11523 | { |
| 11524 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11525 | VTY_NEWLINE); |
| 11526 | return CMD_WARNING; |
| 11527 | } |
| 11528 | |
| 11529 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST], |
| 11530 | PEER_FLAG_RSERVER_CLIENT)) |
| 11531 | { |
| 11532 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11533 | VTY_NEWLINE); |
| 11534 | return CMD_WARNING; |
| 11535 | } |
| 11536 | |
| 11537 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST], |
| 11538 | (argc == 3) ? argv[2] : argv[1], |
| 11539 | AFI_IP6, SAFI_UNICAST, NULL, 1); |
| 11540 | } |
| 11541 | |
| 11542 | ALIAS (show_bgp_view_rsclient_prefix, |
| 11543 | show_bgp_rsclient_prefix_cmd, |
| 11544 | "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M", |
| 11545 | SHOW_STR |
| 11546 | BGP_STR |
| 11547 | "Information about Route Server Client\n" |
| 11548 | NEIGHBOR_ADDR_STR |
| 11549 | "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 11550 | |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11551 | DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix, |
| 11552 | show_bgp_view_ipv6_safi_rsclient_prefix_cmd, |
| 11553 | "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M", |
| 11554 | SHOW_STR |
| 11555 | BGP_STR |
| 11556 | "BGP view\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 11557 | "View name\n" |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 11558 | "Address family\n" |
| 11559 | "Address Family modifier\n" |
| 11560 | "Address Family modifier\n" |
| 11561 | "Information about Route Server Client\n" |
| 11562 | NEIGHBOR_ADDR_STR |
| 11563 | "IP prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 11564 | { |
| 11565 | struct bgp *bgp; |
| 11566 | struct peer *peer; |
| 11567 | safi_t safi; |
| 11568 | |
| 11569 | /* BGP structure lookup. */ |
| 11570 | if (argc == 4) |
| 11571 | { |
| 11572 | bgp = bgp_lookup_by_name (argv[0]); |
| 11573 | if (bgp == NULL) |
| 11574 | { |
| 11575 | vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE); |
| 11576 | return CMD_WARNING; |
| 11577 | } |
| 11578 | } |
| 11579 | else |
| 11580 | { |
| 11581 | bgp = bgp_get_default (); |
| 11582 | if (bgp == NULL) |
| 11583 | { |
| 11584 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 11585 | return CMD_WARNING; |
| 11586 | } |
| 11587 | } |
| 11588 | |
| 11589 | if (argc == 4) { |
| 11590 | peer = peer_lookup_in_view (vty, argv[0], argv[2]); |
| 11591 | safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11592 | } else { |
| 11593 | peer = peer_lookup_in_view (vty, NULL, argv[1]); |
| 11594 | safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST; |
| 11595 | } |
| 11596 | |
| 11597 | if (! peer) |
| 11598 | return CMD_WARNING; |
| 11599 | |
| 11600 | if (! peer->afc[AFI_IP6][safi]) |
| 11601 | { |
| 11602 | vty_out (vty, "%% Activate the neighbor for the address family first%s", |
| 11603 | VTY_NEWLINE); |
| 11604 | return CMD_WARNING; |
| 11605 | } |
| 11606 | |
| 11607 | if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi], |
| 11608 | PEER_FLAG_RSERVER_CLIENT)) |
| 11609 | { |
| 11610 | vty_out (vty, "%% Neighbor is not a Route-Server client%s", |
| 11611 | VTY_NEWLINE); |
| 11612 | return CMD_WARNING; |
| 11613 | } |
| 11614 | |
| 11615 | return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi], |
| 11616 | (argc == 4) ? argv[3] : argv[2], |
| 11617 | AFI_IP6, safi, NULL, 1); |
| 11618 | } |
| 11619 | |
| 11620 | ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix, |
| 11621 | show_bgp_ipv6_safi_rsclient_prefix_cmd, |
| 11622 | "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M", |
| 11623 | SHOW_STR |
| 11624 | BGP_STR |
| 11625 | "Address family\n" |
| 11626 | "Address Family modifier\n" |
| 11627 | "Address Family modifier\n" |
| 11628 | "Information about Route Server Client\n" |
| 11629 | NEIGHBOR_ADDR_STR |
| 11630 | "IP prefix <network>/<length>, e.g., 3ffe::/16\n") |
| 11631 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11632 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 11633 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11634 | struct bgp_table *bgp_distance_table; |
| 11635 | |
| 11636 | struct bgp_distance |
| 11637 | { |
| 11638 | /* Distance value for the IP source prefix. */ |
| 11639 | u_char distance; |
| 11640 | |
| 11641 | /* Name of the access-list to be matched. */ |
| 11642 | char *access_list; |
| 11643 | }; |
| 11644 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 11645 | static struct bgp_distance * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 11646 | bgp_distance_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11647 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 11648 | return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11649 | } |
| 11650 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 11651 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11652 | bgp_distance_free (struct bgp_distance *bdistance) |
| 11653 | { |
| 11654 | XFREE (MTYPE_BGP_DISTANCE, bdistance); |
| 11655 | } |
| 11656 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 11657 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 11658 | bgp_distance_set (struct vty *vty, const char *distance_str, |
| 11659 | const char *ip_str, const char *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11660 | { |
| 11661 | int ret; |
| 11662 | struct prefix_ipv4 p; |
| 11663 | u_char distance; |
| 11664 | struct bgp_node *rn; |
| 11665 | struct bgp_distance *bdistance; |
| 11666 | |
| 11667 | ret = str2prefix_ipv4 (ip_str, &p); |
| 11668 | if (ret == 0) |
| 11669 | { |
| 11670 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 11671 | return CMD_WARNING; |
| 11672 | } |
| 11673 | |
| 11674 | distance = atoi (distance_str); |
| 11675 | |
| 11676 | /* Get BGP distance node. */ |
| 11677 | rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p); |
| 11678 | if (rn->info) |
| 11679 | { |
| 11680 | bdistance = rn->info; |
| 11681 | bgp_unlock_node (rn); |
| 11682 | } |
| 11683 | else |
| 11684 | { |
| 11685 | bdistance = bgp_distance_new (); |
| 11686 | rn->info = bdistance; |
| 11687 | } |
| 11688 | |
| 11689 | /* Set distance value. */ |
| 11690 | bdistance->distance = distance; |
| 11691 | |
| 11692 | /* Reset access-list configuration. */ |
| 11693 | if (bdistance->access_list) |
| 11694 | { |
| 11695 | free (bdistance->access_list); |
| 11696 | bdistance->access_list = NULL; |
| 11697 | } |
| 11698 | if (access_list_str) |
| 11699 | bdistance->access_list = strdup (access_list_str); |
| 11700 | |
| 11701 | return CMD_SUCCESS; |
| 11702 | } |
| 11703 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 11704 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 11705 | bgp_distance_unset (struct vty *vty, const char *distance_str, |
| 11706 | const char *ip_str, const char *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11707 | { |
| 11708 | int ret; |
| 11709 | struct prefix_ipv4 p; |
| 11710 | u_char distance; |
| 11711 | struct bgp_node *rn; |
| 11712 | struct bgp_distance *bdistance; |
| 11713 | |
| 11714 | ret = str2prefix_ipv4 (ip_str, &p); |
| 11715 | if (ret == 0) |
| 11716 | { |
| 11717 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 11718 | return CMD_WARNING; |
| 11719 | } |
| 11720 | |
| 11721 | distance = atoi (distance_str); |
| 11722 | |
| 11723 | rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p); |
| 11724 | if (! rn) |
| 11725 | { |
| 11726 | vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE); |
| 11727 | return CMD_WARNING; |
| 11728 | } |
| 11729 | |
| 11730 | bdistance = rn->info; |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 11731 | |
| 11732 | if (bdistance->distance != distance) |
| 11733 | { |
| 11734 | vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE); |
| 11735 | return CMD_WARNING; |
| 11736 | } |
| 11737 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11738 | if (bdistance->access_list) |
| 11739 | free (bdistance->access_list); |
| 11740 | bgp_distance_free (bdistance); |
| 11741 | |
| 11742 | rn->info = NULL; |
| 11743 | bgp_unlock_node (rn); |
| 11744 | bgp_unlock_node (rn); |
| 11745 | |
| 11746 | return CMD_SUCCESS; |
| 11747 | } |
| 11748 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11749 | /* Apply BGP information to distance method. */ |
| 11750 | u_char |
| 11751 | bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp) |
| 11752 | { |
| 11753 | struct bgp_node *rn; |
| 11754 | struct prefix_ipv4 q; |
| 11755 | struct peer *peer; |
| 11756 | struct bgp_distance *bdistance; |
| 11757 | struct access_list *alist; |
| 11758 | struct bgp_static *bgp_static; |
| 11759 | |
| 11760 | if (! bgp) |
| 11761 | return 0; |
| 11762 | |
| 11763 | if (p->family != AF_INET) |
| 11764 | return 0; |
| 11765 | |
| 11766 | peer = rinfo->peer; |
| 11767 | |
| 11768 | if (peer->su.sa.sa_family != AF_INET) |
| 11769 | return 0; |
| 11770 | |
| 11771 | memset (&q, 0, sizeof (struct prefix_ipv4)); |
| 11772 | q.family = AF_INET; |
| 11773 | q.prefix = peer->su.sin.sin_addr; |
| 11774 | q.prefixlen = IPV4_MAX_BITLEN; |
| 11775 | |
| 11776 | /* Check source address. */ |
| 11777 | rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q); |
| 11778 | if (rn) |
| 11779 | { |
| 11780 | bdistance = rn->info; |
| 11781 | bgp_unlock_node (rn); |
| 11782 | |
| 11783 | if (bdistance->access_list) |
| 11784 | { |
| 11785 | alist = access_list_lookup (AFI_IP, bdistance->access_list); |
| 11786 | if (alist && access_list_apply (alist, p) == FILTER_PERMIT) |
| 11787 | return bdistance->distance; |
| 11788 | } |
| 11789 | else |
| 11790 | return bdistance->distance; |
| 11791 | } |
| 11792 | |
| 11793 | /* Backdoor check. */ |
| 11794 | rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p); |
| 11795 | if (rn) |
| 11796 | { |
| 11797 | bgp_static = rn->info; |
| 11798 | bgp_unlock_node (rn); |
| 11799 | |
| 11800 | if (bgp_static->backdoor) |
| 11801 | { |
| 11802 | if (bgp->distance_local) |
| 11803 | return bgp->distance_local; |
| 11804 | else |
| 11805 | return ZEBRA_IBGP_DISTANCE_DEFAULT; |
| 11806 | } |
| 11807 | } |
| 11808 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 11809 | if (peer->sort == BGP_PEER_EBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11810 | { |
| 11811 | if (bgp->distance_ebgp) |
| 11812 | return bgp->distance_ebgp; |
| 11813 | return ZEBRA_EBGP_DISTANCE_DEFAULT; |
| 11814 | } |
| 11815 | else |
| 11816 | { |
| 11817 | if (bgp->distance_ibgp) |
| 11818 | return bgp->distance_ibgp; |
| 11819 | return ZEBRA_IBGP_DISTANCE_DEFAULT; |
| 11820 | } |
| 11821 | } |
| 11822 | |
| 11823 | DEFUN (bgp_distance, |
| 11824 | bgp_distance_cmd, |
| 11825 | "distance bgp <1-255> <1-255> <1-255>", |
| 11826 | "Define an administrative distance\n" |
| 11827 | "BGP distance\n" |
| 11828 | "Distance for routes external to the AS\n" |
| 11829 | "Distance for routes internal to the AS\n" |
| 11830 | "Distance for local routes\n") |
| 11831 | { |
| 11832 | struct bgp *bgp; |
| 11833 | |
| 11834 | bgp = vty->index; |
| 11835 | |
| 11836 | bgp->distance_ebgp = atoi (argv[0]); |
| 11837 | bgp->distance_ibgp = atoi (argv[1]); |
| 11838 | bgp->distance_local = atoi (argv[2]); |
| 11839 | return CMD_SUCCESS; |
| 11840 | } |
| 11841 | |
| 11842 | DEFUN (no_bgp_distance, |
| 11843 | no_bgp_distance_cmd, |
| 11844 | "no distance bgp <1-255> <1-255> <1-255>", |
| 11845 | NO_STR |
| 11846 | "Define an administrative distance\n" |
| 11847 | "BGP distance\n" |
| 11848 | "Distance for routes external to the AS\n" |
| 11849 | "Distance for routes internal to the AS\n" |
| 11850 | "Distance for local routes\n") |
| 11851 | { |
| 11852 | struct bgp *bgp; |
| 11853 | |
| 11854 | bgp = vty->index; |
| 11855 | |
| 11856 | bgp->distance_ebgp= 0; |
| 11857 | bgp->distance_ibgp = 0; |
| 11858 | bgp->distance_local = 0; |
| 11859 | return CMD_SUCCESS; |
| 11860 | } |
| 11861 | |
| 11862 | ALIAS (no_bgp_distance, |
| 11863 | no_bgp_distance2_cmd, |
| 11864 | "no distance bgp", |
| 11865 | NO_STR |
| 11866 | "Define an administrative distance\n" |
| 11867 | "BGP distance\n") |
| 11868 | |
| 11869 | DEFUN (bgp_distance_source, |
| 11870 | bgp_distance_source_cmd, |
| 11871 | "distance <1-255> A.B.C.D/M", |
| 11872 | "Define an administrative distance\n" |
| 11873 | "Administrative distance\n" |
| 11874 | "IP source prefix\n") |
| 11875 | { |
| 11876 | bgp_distance_set (vty, argv[0], argv[1], NULL); |
| 11877 | return CMD_SUCCESS; |
| 11878 | } |
| 11879 | |
| 11880 | DEFUN (no_bgp_distance_source, |
| 11881 | no_bgp_distance_source_cmd, |
| 11882 | "no distance <1-255> A.B.C.D/M", |
| 11883 | NO_STR |
| 11884 | "Define an administrative distance\n" |
| 11885 | "Administrative distance\n" |
| 11886 | "IP source prefix\n") |
| 11887 | { |
| 11888 | bgp_distance_unset (vty, argv[0], argv[1], NULL); |
| 11889 | return CMD_SUCCESS; |
| 11890 | } |
| 11891 | |
| 11892 | DEFUN (bgp_distance_source_access_list, |
| 11893 | bgp_distance_source_access_list_cmd, |
| 11894 | "distance <1-255> A.B.C.D/M WORD", |
| 11895 | "Define an administrative distance\n" |
| 11896 | "Administrative distance\n" |
| 11897 | "IP source prefix\n" |
| 11898 | "Access list name\n") |
| 11899 | { |
| 11900 | bgp_distance_set (vty, argv[0], argv[1], argv[2]); |
| 11901 | return CMD_SUCCESS; |
| 11902 | } |
| 11903 | |
| 11904 | DEFUN (no_bgp_distance_source_access_list, |
| 11905 | no_bgp_distance_source_access_list_cmd, |
| 11906 | "no distance <1-255> A.B.C.D/M WORD", |
| 11907 | NO_STR |
| 11908 | "Define an administrative distance\n" |
| 11909 | "Administrative distance\n" |
| 11910 | "IP source prefix\n" |
| 11911 | "Access list name\n") |
| 11912 | { |
| 11913 | bgp_distance_unset (vty, argv[0], argv[1], argv[2]); |
| 11914 | return CMD_SUCCESS; |
| 11915 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 11916 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11917 | DEFUN (bgp_damp_set, |
| 11918 | bgp_damp_set_cmd, |
| 11919 | "bgp dampening <1-45> <1-20000> <1-20000> <1-255>", |
| 11920 | "BGP Specific commands\n" |
| 11921 | "Enable route-flap dampening\n" |
| 11922 | "Half-life time for the penalty\n" |
| 11923 | "Value to start reusing a route\n" |
| 11924 | "Value to start suppressing a route\n" |
| 11925 | "Maximum duration to suppress a stable route\n") |
| 11926 | { |
| 11927 | struct bgp *bgp; |
| 11928 | int half = DEFAULT_HALF_LIFE * 60; |
| 11929 | int reuse = DEFAULT_REUSE; |
| 11930 | int suppress = DEFAULT_SUPPRESS; |
| 11931 | int max = 4 * half; |
| 11932 | |
| 11933 | if (argc == 4) |
| 11934 | { |
| 11935 | half = atoi (argv[0]) * 60; |
| 11936 | reuse = atoi (argv[1]); |
| 11937 | suppress = atoi (argv[2]); |
| 11938 | max = atoi (argv[3]) * 60; |
| 11939 | } |
| 11940 | else if (argc == 1) |
| 11941 | { |
| 11942 | half = atoi (argv[0]) * 60; |
| 11943 | max = 4 * half; |
| 11944 | } |
| 11945 | |
| 11946 | bgp = vty->index; |
Balaji | aa7dbb1 | 2015-03-16 16:55:26 +0000 | [diff] [blame] | 11947 | |
| 11948 | if (suppress < reuse) |
| 11949 | { |
| 11950 | vty_out (vty, "Suppress value cannot be less than reuse value %s", |
| 11951 | VTY_NEWLINE); |
| 11952 | return 0; |
| 11953 | } |
| 11954 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 11955 | return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty), |
| 11956 | half, reuse, suppress, max); |
| 11957 | } |
| 11958 | |
| 11959 | ALIAS (bgp_damp_set, |
| 11960 | bgp_damp_set2_cmd, |
| 11961 | "bgp dampening <1-45>", |
| 11962 | "BGP Specific commands\n" |
| 11963 | "Enable route-flap dampening\n" |
| 11964 | "Half-life time for the penalty\n") |
| 11965 | |
| 11966 | ALIAS (bgp_damp_set, |
| 11967 | bgp_damp_set3_cmd, |
| 11968 | "bgp dampening", |
| 11969 | "BGP Specific commands\n" |
| 11970 | "Enable route-flap dampening\n") |
| 11971 | |
| 11972 | DEFUN (bgp_damp_unset, |
| 11973 | bgp_damp_unset_cmd, |
| 11974 | "no bgp dampening", |
| 11975 | NO_STR |
| 11976 | "BGP Specific commands\n" |
| 11977 | "Enable route-flap dampening\n") |
| 11978 | { |
| 11979 | struct bgp *bgp; |
| 11980 | |
| 11981 | bgp = vty->index; |
| 11982 | return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty)); |
| 11983 | } |
| 11984 | |
| 11985 | ALIAS (bgp_damp_unset, |
| 11986 | bgp_damp_unset2_cmd, |
| 11987 | "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>", |
| 11988 | NO_STR |
| 11989 | "BGP Specific commands\n" |
| 11990 | "Enable route-flap dampening\n" |
| 11991 | "Half-life time for the penalty\n" |
| 11992 | "Value to start reusing a route\n" |
| 11993 | "Value to start suppressing a route\n" |
| 11994 | "Maximum duration to suppress a stable route\n") |
| 11995 | |
| 11996 | DEFUN (show_ip_bgp_dampened_paths, |
| 11997 | show_ip_bgp_dampened_paths_cmd, |
| 11998 | "show ip bgp dampened-paths", |
| 11999 | SHOW_STR |
| 12000 | IP_STR |
| 12001 | BGP_STR |
| 12002 | "Display paths suppressed due to dampening\n") |
| 12003 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 12004 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths, |
| 12005 | NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12006 | } |
| 12007 | |
| 12008 | DEFUN (show_ip_bgp_flap_statistics, |
| 12009 | show_ip_bgp_flap_statistics_cmd, |
| 12010 | "show ip bgp flap-statistics", |
| 12011 | SHOW_STR |
| 12012 | IP_STR |
| 12013 | BGP_STR |
| 12014 | "Display flap statistics of routes\n") |
| 12015 | { |
ajs | 5a64665 | 2004-11-05 01:25:55 +0000 | [diff] [blame] | 12016 | return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, |
| 12017 | bgp_show_type_flap_statistics, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12018 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 12019 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12020 | /* Display specified route of BGP table. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 12021 | static int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 12022 | bgp_clear_damp_route (struct vty *vty, const char *view_name, |
| 12023 | const char *ip_str, afi_t afi, safi_t safi, |
| 12024 | struct prefix_rd *prd, int prefix_check) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12025 | { |
| 12026 | int ret; |
| 12027 | struct prefix match; |
| 12028 | struct bgp_node *rn; |
| 12029 | struct bgp_node *rm; |
| 12030 | struct bgp_info *ri; |
| 12031 | struct bgp_info *ri_temp; |
| 12032 | struct bgp *bgp; |
| 12033 | struct bgp_table *table; |
| 12034 | |
| 12035 | /* BGP structure lookup. */ |
| 12036 | if (view_name) |
| 12037 | { |
| 12038 | bgp = bgp_lookup_by_name (view_name); |
| 12039 | if (bgp == NULL) |
| 12040 | { |
| 12041 | vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE); |
| 12042 | return CMD_WARNING; |
| 12043 | } |
| 12044 | } |
| 12045 | else |
| 12046 | { |
| 12047 | bgp = bgp_get_default (); |
| 12048 | if (bgp == NULL) |
| 12049 | { |
| 12050 | vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE); |
| 12051 | return CMD_WARNING; |
| 12052 | } |
| 12053 | } |
| 12054 | |
| 12055 | /* Check IP address argument. */ |
| 12056 | ret = str2prefix (ip_str, &match); |
| 12057 | if (! ret) |
| 12058 | { |
| 12059 | vty_out (vty, "%% address is malformed%s", VTY_NEWLINE); |
| 12060 | return CMD_WARNING; |
| 12061 | } |
| 12062 | |
| 12063 | match.family = afi2family (afi); |
| 12064 | |
| 12065 | if (safi == SAFI_MPLS_VPN) |
| 12066 | { |
| 12067 | for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn)) |
| 12068 | { |
| 12069 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) |
| 12070 | continue; |
| 12071 | |
| 12072 | if ((table = rn->info) != NULL) |
| 12073 | if ((rm = bgp_node_match (table, &match)) != NULL) |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 12074 | { |
| 12075 | if (! prefix_check || rm->p.prefixlen == match.prefixlen) |
| 12076 | { |
| 12077 | ri = rm->info; |
| 12078 | while (ri) |
| 12079 | { |
| 12080 | if (ri->extra && ri->extra->damp_info) |
| 12081 | { |
| 12082 | ri_temp = ri->next; |
| 12083 | bgp_damp_info_free (ri->extra->damp_info, 1); |
| 12084 | ri = ri_temp; |
| 12085 | } |
| 12086 | else |
| 12087 | ri = ri->next; |
| 12088 | } |
| 12089 | } |
| 12090 | |
| 12091 | bgp_unlock_node (rm); |
| 12092 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12093 | } |
| 12094 | } |
| 12095 | else |
| 12096 | { |
| 12097 | if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL) |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 12098 | { |
| 12099 | if (! prefix_check || rn->p.prefixlen == match.prefixlen) |
| 12100 | { |
| 12101 | ri = rn->info; |
| 12102 | while (ri) |
| 12103 | { |
| 12104 | if (ri->extra && ri->extra->damp_info) |
| 12105 | { |
| 12106 | ri_temp = ri->next; |
| 12107 | bgp_damp_info_free (ri->extra->damp_info, 1); |
| 12108 | ri = ri_temp; |
| 12109 | } |
| 12110 | else |
| 12111 | ri = ri->next; |
| 12112 | } |
| 12113 | } |
| 12114 | |
| 12115 | bgp_unlock_node (rn); |
| 12116 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12117 | } |
| 12118 | |
| 12119 | return CMD_SUCCESS; |
| 12120 | } |
| 12121 | |
| 12122 | DEFUN (clear_ip_bgp_dampening, |
| 12123 | clear_ip_bgp_dampening_cmd, |
| 12124 | "clear ip bgp dampening", |
| 12125 | CLEAR_STR |
| 12126 | IP_STR |
| 12127 | BGP_STR |
| 12128 | "Clear route flap dampening information\n") |
| 12129 | { |
| 12130 | bgp_damp_info_clean (); |
| 12131 | return CMD_SUCCESS; |
| 12132 | } |
| 12133 | |
| 12134 | DEFUN (clear_ip_bgp_dampening_prefix, |
| 12135 | clear_ip_bgp_dampening_prefix_cmd, |
| 12136 | "clear ip bgp dampening A.B.C.D/M", |
| 12137 | CLEAR_STR |
| 12138 | IP_STR |
| 12139 | BGP_STR |
| 12140 | "Clear route flap dampening information\n" |
| 12141 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 12142 | { |
| 12143 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, |
| 12144 | SAFI_UNICAST, NULL, 1); |
| 12145 | } |
| 12146 | |
| 12147 | DEFUN (clear_ip_bgp_dampening_address, |
| 12148 | clear_ip_bgp_dampening_address_cmd, |
| 12149 | "clear ip bgp dampening A.B.C.D", |
| 12150 | CLEAR_STR |
| 12151 | IP_STR |
| 12152 | BGP_STR |
| 12153 | "Clear route flap dampening information\n" |
| 12154 | "Network to clear damping information\n") |
| 12155 | { |
| 12156 | return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP, |
| 12157 | SAFI_UNICAST, NULL, 0); |
| 12158 | } |
| 12159 | |
| 12160 | DEFUN (clear_ip_bgp_dampening_address_mask, |
| 12161 | clear_ip_bgp_dampening_address_mask_cmd, |
| 12162 | "clear ip bgp dampening A.B.C.D A.B.C.D", |
| 12163 | CLEAR_STR |
| 12164 | IP_STR |
| 12165 | BGP_STR |
| 12166 | "Clear route flap dampening information\n" |
| 12167 | "Network to clear damping information\n" |
| 12168 | "Network mask\n") |
| 12169 | { |
| 12170 | int ret; |
| 12171 | char prefix_str[BUFSIZ]; |
| 12172 | |
| 12173 | ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str); |
| 12174 | if (! ret) |
| 12175 | { |
| 12176 | vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE); |
| 12177 | return CMD_WARNING; |
| 12178 | } |
| 12179 | |
| 12180 | return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP, |
| 12181 | SAFI_UNICAST, NULL, 0); |
| 12182 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 12183 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 12184 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12185 | bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp, |
| 12186 | afi_t afi, safi_t safi, int *write) |
| 12187 | { |
| 12188 | struct bgp_node *prn; |
| 12189 | struct bgp_node *rn; |
| 12190 | struct bgp_table *table; |
| 12191 | struct prefix *p; |
| 12192 | struct prefix_rd *prd; |
| 12193 | struct bgp_static *bgp_static; |
| 12194 | u_int32_t label; |
| 12195 | char buf[SU_ADDRSTRLEN]; |
| 12196 | char rdbuf[RD_ADDRSTRLEN]; |
| 12197 | |
| 12198 | /* Network configuration. */ |
| 12199 | for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn)) |
| 12200 | if ((table = prn->info) != NULL) |
| 12201 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 12202 | if ((bgp_static = rn->info) != NULL) |
| 12203 | { |
| 12204 | p = &rn->p; |
| 12205 | prd = (struct prefix_rd *) &prn->p; |
| 12206 | |
| 12207 | /* "address-family" display. */ |
| 12208 | bgp_config_write_family_header (vty, afi, safi, write); |
| 12209 | |
| 12210 | /* "network" configuration display. */ |
| 12211 | prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN); |
| 12212 | label = decode_label (bgp_static->tag); |
| 12213 | |
| 12214 | vty_out (vty, " network %s/%d rd %s tag %d", |
| 12215 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 12216 | p->prefixlen, |
| 12217 | rdbuf, label); |
| 12218 | vty_out (vty, "%s", VTY_NEWLINE); |
| 12219 | } |
| 12220 | return 0; |
| 12221 | } |
| 12222 | |
| 12223 | /* Configuration of static route announcement and aggregate |
| 12224 | information. */ |
| 12225 | int |
| 12226 | bgp_config_write_network (struct vty *vty, struct bgp *bgp, |
| 12227 | afi_t afi, safi_t safi, int *write) |
| 12228 | { |
| 12229 | struct bgp_node *rn; |
| 12230 | struct prefix *p; |
| 12231 | struct bgp_static *bgp_static; |
| 12232 | struct bgp_aggregate *bgp_aggregate; |
| 12233 | char buf[SU_ADDRSTRLEN]; |
| 12234 | |
| 12235 | if (afi == AFI_IP && safi == SAFI_MPLS_VPN) |
| 12236 | return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write); |
| 12237 | |
| 12238 | /* Network configuration. */ |
| 12239 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) |
| 12240 | if ((bgp_static = rn->info) != NULL) |
| 12241 | { |
| 12242 | p = &rn->p; |
| 12243 | |
| 12244 | /* "address-family" display. */ |
| 12245 | bgp_config_write_family_header (vty, afi, safi, write); |
| 12246 | |
| 12247 | /* "network" configuration display. */ |
| 12248 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) |
| 12249 | { |
| 12250 | u_int32_t destination; |
| 12251 | struct in_addr netmask; |
| 12252 | |
| 12253 | destination = ntohl (p->u.prefix4.s_addr); |
| 12254 | masklen2ip (p->prefixlen, &netmask); |
| 12255 | vty_out (vty, " network %s", |
| 12256 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN)); |
| 12257 | |
| 12258 | if ((IN_CLASSC (destination) && p->prefixlen == 24) |
| 12259 | || (IN_CLASSB (destination) && p->prefixlen == 16) |
| 12260 | || (IN_CLASSA (destination) && p->prefixlen == 8) |
| 12261 | || p->u.prefix4.s_addr == 0) |
| 12262 | { |
| 12263 | /* Natural mask is not display. */ |
| 12264 | } |
| 12265 | else |
| 12266 | vty_out (vty, " mask %s", inet_ntoa (netmask)); |
| 12267 | } |
| 12268 | else |
| 12269 | { |
| 12270 | vty_out (vty, " network %s/%d", |
| 12271 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 12272 | p->prefixlen); |
| 12273 | } |
| 12274 | |
| 12275 | if (bgp_static->rmap.name) |
| 12276 | vty_out (vty, " route-map %s", bgp_static->rmap.name); |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 12277 | else |
| 12278 | { |
| 12279 | if (bgp_static->backdoor) |
| 12280 | vty_out (vty, " backdoor"); |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 12281 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12282 | |
| 12283 | vty_out (vty, "%s", VTY_NEWLINE); |
| 12284 | } |
| 12285 | |
| 12286 | /* Aggregate-address configuration. */ |
| 12287 | for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn)) |
| 12288 | if ((bgp_aggregate = rn->info) != NULL) |
| 12289 | { |
| 12290 | p = &rn->p; |
| 12291 | |
| 12292 | /* "address-family" display. */ |
| 12293 | bgp_config_write_family_header (vty, afi, safi, write); |
| 12294 | |
| 12295 | if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) |
| 12296 | { |
| 12297 | struct in_addr netmask; |
| 12298 | |
| 12299 | masklen2ip (p->prefixlen, &netmask); |
| 12300 | vty_out (vty, " aggregate-address %s %s", |
| 12301 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 12302 | inet_ntoa (netmask)); |
| 12303 | } |
| 12304 | else |
| 12305 | { |
| 12306 | vty_out (vty, " aggregate-address %s/%d", |
| 12307 | inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), |
| 12308 | p->prefixlen); |
| 12309 | } |
| 12310 | |
| 12311 | if (bgp_aggregate->as_set) |
| 12312 | vty_out (vty, " as-set"); |
| 12313 | |
| 12314 | if (bgp_aggregate->summary_only) |
| 12315 | vty_out (vty, " summary-only"); |
| 12316 | |
| 12317 | vty_out (vty, "%s", VTY_NEWLINE); |
| 12318 | } |
| 12319 | |
| 12320 | return 0; |
| 12321 | } |
| 12322 | |
| 12323 | int |
| 12324 | bgp_config_write_distance (struct vty *vty, struct bgp *bgp) |
| 12325 | { |
| 12326 | struct bgp_node *rn; |
| 12327 | struct bgp_distance *bdistance; |
| 12328 | |
| 12329 | /* Distance configuration. */ |
| 12330 | if (bgp->distance_ebgp |
| 12331 | && bgp->distance_ibgp |
| 12332 | && bgp->distance_local |
| 12333 | && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT |
| 12334 | || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT |
| 12335 | || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT)) |
| 12336 | vty_out (vty, " distance bgp %d %d %d%s", |
| 12337 | bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local, |
| 12338 | VTY_NEWLINE); |
| 12339 | |
| 12340 | for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn)) |
| 12341 | if ((bdistance = rn->info) != NULL) |
| 12342 | { |
| 12343 | vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance, |
| 12344 | inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, |
| 12345 | bdistance->access_list ? bdistance->access_list : "", |
| 12346 | VTY_NEWLINE); |
| 12347 | } |
| 12348 | |
| 12349 | return 0; |
| 12350 | } |
| 12351 | |
| 12352 | /* Allocate routing table structure and install commands. */ |
| 12353 | void |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 12354 | bgp_route_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12355 | { |
| 12356 | /* Init BGP distance table. */ |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 12357 | bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12358 | |
| 12359 | /* IPv4 BGP commands. */ |
| 12360 | install_element (BGP_NODE, &bgp_network_cmd); |
| 12361 | install_element (BGP_NODE, &bgp_network_mask_cmd); |
| 12362 | install_element (BGP_NODE, &bgp_network_mask_natural_cmd); |
| 12363 | install_element (BGP_NODE, &bgp_network_route_map_cmd); |
| 12364 | install_element (BGP_NODE, &bgp_network_mask_route_map_cmd); |
| 12365 | install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd); |
| 12366 | install_element (BGP_NODE, &bgp_network_backdoor_cmd); |
| 12367 | install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd); |
| 12368 | install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd); |
| 12369 | install_element (BGP_NODE, &no_bgp_network_cmd); |
| 12370 | install_element (BGP_NODE, &no_bgp_network_mask_cmd); |
| 12371 | install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd); |
| 12372 | install_element (BGP_NODE, &no_bgp_network_route_map_cmd); |
| 12373 | install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd); |
| 12374 | install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd); |
| 12375 | install_element (BGP_NODE, &no_bgp_network_backdoor_cmd); |
| 12376 | install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd); |
| 12377 | install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd); |
| 12378 | |
| 12379 | install_element (BGP_NODE, &aggregate_address_cmd); |
| 12380 | install_element (BGP_NODE, &aggregate_address_mask_cmd); |
| 12381 | install_element (BGP_NODE, &aggregate_address_summary_only_cmd); |
| 12382 | install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd); |
| 12383 | install_element (BGP_NODE, &aggregate_address_as_set_cmd); |
| 12384 | install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd); |
| 12385 | install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd); |
| 12386 | install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd); |
| 12387 | install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd); |
| 12388 | install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd); |
| 12389 | install_element (BGP_NODE, &no_aggregate_address_cmd); |
| 12390 | install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd); |
| 12391 | install_element (BGP_NODE, &no_aggregate_address_as_set_cmd); |
| 12392 | install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd); |
| 12393 | install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd); |
| 12394 | install_element (BGP_NODE, &no_aggregate_address_mask_cmd); |
| 12395 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd); |
| 12396 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd); |
| 12397 | install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd); |
| 12398 | install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd); |
| 12399 | |
| 12400 | /* IPv4 unicast configuration. */ |
| 12401 | install_element (BGP_IPV4_NODE, &bgp_network_cmd); |
| 12402 | install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd); |
| 12403 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd); |
| 12404 | install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd); |
| 12405 | install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd); |
| 12406 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd); |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 12407 | install_element (BGP_IPV4_NODE, &no_bgp_network_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12408 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd); |
| 12409 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd); |
| 12410 | install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd); |
| 12411 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd); |
| 12412 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd); |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 12413 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12414 | install_element (BGP_IPV4_NODE, &aggregate_address_cmd); |
| 12415 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd); |
| 12416 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd); |
| 12417 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd); |
| 12418 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd); |
| 12419 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd); |
| 12420 | install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd); |
| 12421 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd); |
| 12422 | install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd); |
| 12423 | install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd); |
| 12424 | install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd); |
| 12425 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd); |
| 12426 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd); |
| 12427 | install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd); |
| 12428 | install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd); |
| 12429 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd); |
| 12430 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd); |
| 12431 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd); |
| 12432 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd); |
| 12433 | install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd); |
| 12434 | |
| 12435 | /* IPv4 multicast configuration. */ |
| 12436 | install_element (BGP_IPV4M_NODE, &bgp_network_cmd); |
| 12437 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd); |
| 12438 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd); |
| 12439 | install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd); |
| 12440 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd); |
| 12441 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd); |
| 12442 | install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd); |
| 12443 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd); |
| 12444 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd); |
| 12445 | install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd); |
| 12446 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd); |
| 12447 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd); |
| 12448 | install_element (BGP_IPV4M_NODE, &aggregate_address_cmd); |
| 12449 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd); |
| 12450 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd); |
| 12451 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd); |
| 12452 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd); |
| 12453 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd); |
| 12454 | install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd); |
| 12455 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd); |
| 12456 | install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd); |
| 12457 | install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd); |
| 12458 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd); |
| 12459 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd); |
| 12460 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd); |
| 12461 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd); |
| 12462 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd); |
| 12463 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd); |
| 12464 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd); |
| 12465 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd); |
| 12466 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd); |
| 12467 | install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd); |
| 12468 | |
| 12469 | install_element (VIEW_NODE, &show_ip_bgp_cmd); |
| 12470 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12471 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12472 | install_element (VIEW_NODE, &show_ip_bgp_route_cmd); |
| 12473 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12474 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12475 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd); |
| 12476 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); |
| 12477 | install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd); |
| 12478 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12479 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12480 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
| 12481 | install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); |
| 12482 | install_element (VIEW_NODE, &show_ip_bgp_view_cmd); |
| 12483 | install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd); |
| 12484 | install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd); |
| 12485 | install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); |
| 12486 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd); |
| 12487 | install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd); |
| 12488 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd); |
| 12489 | install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd); |
| 12490 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd); |
| 12491 | install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd); |
| 12492 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd); |
| 12493 | install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd); |
| 12494 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd); |
| 12495 | install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd); |
| 12496 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd); |
| 12497 | install_element (VIEW_NODE, &show_ip_bgp_community_cmd); |
| 12498 | install_element (VIEW_NODE, &show_ip_bgp_community2_cmd); |
| 12499 | install_element (VIEW_NODE, &show_ip_bgp_community3_cmd); |
| 12500 | install_element (VIEW_NODE, &show_ip_bgp_community4_cmd); |
| 12501 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd); |
| 12502 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd); |
| 12503 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd); |
| 12504 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12505 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
| 12506 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd); |
| 12507 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd); |
| 12508 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd); |
| 12509 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12510 | install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd); |
| 12511 | install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd); |
| 12512 | install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd); |
| 12513 | install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd); |
| 12514 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd); |
| 12515 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); |
| 12516 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); |
| 12517 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); |
| 12518 | install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd); |
| 12519 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd); |
| 12520 | install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd); |
| 12521 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd); |
| 12522 | install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd); |
| 12523 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd); |
| 12524 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd); |
| 12525 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd); |
| 12526 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd); |
| 12527 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12528 | install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12529 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd); |
| 12530 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd); |
| 12531 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); |
| 12532 | install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd); |
| 12533 | install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd); |
| 12534 | install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd); |
| 12535 | install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd); |
| 12536 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd); |
| 12537 | install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd); |
| 12538 | install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd); |
| 12539 | install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd); |
| 12540 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd); |
| 12541 | install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd); |
| 12542 | install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd); |
| 12543 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd); |
| 12544 | install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12545 | install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12546 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12547 | install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12548 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12549 | install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12550 | install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd); |
Tomasz Pala | 2a71e9c | 2009-06-24 21:36:50 +0100 | [diff] [blame] | 12551 | install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd); |
| 12552 | install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12553 | install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12554 | install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12555 | install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12556 | install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12557 | install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12558 | install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12559 | |
| 12560 | /* Restricted node: VIEW_NODE - (set of dangerous commands) */ |
| 12561 | install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd); |
| 12562 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12563 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12564 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); |
| 12565 | install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd); |
| 12566 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12567 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12568 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
| 12569 | install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); |
| 12570 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd); |
| 12571 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd); |
| 12572 | install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd); |
| 12573 | install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd); |
| 12574 | install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd); |
| 12575 | install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd); |
| 12576 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd); |
| 12577 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd); |
| 12578 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd); |
| 12579 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12580 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
| 12581 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd); |
| 12582 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd); |
| 12583 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd); |
| 12584 | install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12585 | install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd); |
| 12586 | install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd); |
| 12587 | install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd); |
| 12588 | install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd); |
| 12589 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd); |
| 12590 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); |
| 12591 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); |
| 12592 | install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); |
| 12593 | install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12594 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12595 | install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12596 | install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12597 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12598 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12599 | install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12600 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12601 | |
| 12602 | install_element (ENABLE_NODE, &show_ip_bgp_cmd); |
| 12603 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12604 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12605 | install_element (ENABLE_NODE, &show_ip_bgp_route_cmd); |
| 12606 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12607 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12608 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd); |
| 12609 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd); |
| 12610 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd); |
| 12611 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12612 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12613 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd); |
| 12614 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd); |
| 12615 | install_element (ENABLE_NODE, &show_ip_bgp_view_cmd); |
| 12616 | install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd); |
| 12617 | install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd); |
| 12618 | install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd); |
| 12619 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd); |
| 12620 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd); |
| 12621 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd); |
| 12622 | install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd); |
| 12623 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd); |
| 12624 | install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd); |
| 12625 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd); |
| 12626 | install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd); |
| 12627 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd); |
| 12628 | install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd); |
| 12629 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd); |
| 12630 | install_element (ENABLE_NODE, &show_ip_bgp_community_cmd); |
| 12631 | install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd); |
| 12632 | install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd); |
| 12633 | install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd); |
| 12634 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd); |
| 12635 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd); |
| 12636 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd); |
| 12637 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12638 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd); |
| 12639 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd); |
| 12640 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd); |
| 12641 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd); |
| 12642 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12643 | install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd); |
| 12644 | install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd); |
| 12645 | install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd); |
| 12646 | install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd); |
| 12647 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd); |
| 12648 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd); |
| 12649 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd); |
| 12650 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd); |
| 12651 | install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd); |
| 12652 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd); |
| 12653 | install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd); |
| 12654 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd); |
| 12655 | install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd); |
| 12656 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd); |
| 12657 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd); |
| 12658 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd); |
| 12659 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd); |
| 12660 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12661 | install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12662 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd); |
| 12663 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd); |
| 12664 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); |
| 12665 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd); |
| 12666 | install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd); |
| 12667 | install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd); |
| 12668 | install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd); |
| 12669 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd); |
| 12670 | install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd); |
| 12671 | install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd); |
| 12672 | install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd); |
| 12673 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd); |
| 12674 | install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd); |
| 12675 | install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd); |
| 12676 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd); |
| 12677 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12678 | install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12679 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12680 | install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12681 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12682 | install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12683 | install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd); |
Tomasz Pala | 2a71e9c | 2009-06-24 21:36:50 +0100 | [diff] [blame] | 12684 | install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd); |
| 12685 | install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12686 | install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12687 | install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12688 | install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12689 | install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12690 | install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12691 | install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12692 | |
| 12693 | /* BGP dampening clear commands */ |
| 12694 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd); |
| 12695 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd); |
| 12696 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd); |
| 12697 | install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd); |
| 12698 | |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 12699 | /* prefix count */ |
| 12700 | install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); |
| 12701 | install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); |
| 12702 | install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12703 | #ifdef HAVE_IPV6 |
Paul Jakma | ff7924f | 2006-09-04 01:10:36 +0000 | [diff] [blame] | 12704 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); |
| 12705 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12706 | /* New config IPv6 BGP commands. */ |
| 12707 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd); |
| 12708 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd); |
| 12709 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd); |
| 12710 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd); |
| 12711 | |
| 12712 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd); |
| 12713 | install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd); |
| 12714 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd); |
| 12715 | install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd); |
| 12716 | |
G.Balaji | 73bfe0b | 2011-09-23 22:36:20 +0530 | [diff] [blame] | 12717 | install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd); |
| 12718 | install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd); |
| 12719 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12720 | /* Old config IPv6 BGP commands. */ |
| 12721 | install_element (BGP_NODE, &old_ipv6_bgp_network_cmd); |
| 12722 | install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd); |
| 12723 | |
| 12724 | install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd); |
| 12725 | install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd); |
| 12726 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd); |
| 12727 | install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd); |
| 12728 | |
| 12729 | install_element (VIEW_NODE, &show_bgp_cmd); |
| 12730 | install_element (VIEW_NODE, &show_bgp_ipv6_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12731 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12732 | install_element (VIEW_NODE, &show_bgp_route_cmd); |
| 12733 | install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12734 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12735 | install_element (VIEW_NODE, &show_bgp_prefix_cmd); |
| 12736 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12737 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12738 | install_element (VIEW_NODE, &show_bgp_regexp_cmd); |
| 12739 | install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd); |
| 12740 | install_element (VIEW_NODE, &show_bgp_prefix_list_cmd); |
| 12741 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd); |
| 12742 | install_element (VIEW_NODE, &show_bgp_filter_list_cmd); |
| 12743 | install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd); |
| 12744 | install_element (VIEW_NODE, &show_bgp_route_map_cmd); |
| 12745 | install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd); |
| 12746 | install_element (VIEW_NODE, &show_bgp_community_all_cmd); |
| 12747 | install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd); |
| 12748 | install_element (VIEW_NODE, &show_bgp_community_cmd); |
| 12749 | install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd); |
| 12750 | install_element (VIEW_NODE, &show_bgp_community2_cmd); |
| 12751 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd); |
| 12752 | install_element (VIEW_NODE, &show_bgp_community3_cmd); |
| 12753 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd); |
| 12754 | install_element (VIEW_NODE, &show_bgp_community4_cmd); |
| 12755 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd); |
| 12756 | install_element (VIEW_NODE, &show_bgp_community_exact_cmd); |
| 12757 | install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd); |
| 12758 | install_element (VIEW_NODE, &show_bgp_community2_exact_cmd); |
| 12759 | install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd); |
| 12760 | install_element (VIEW_NODE, &show_bgp_community3_exact_cmd); |
| 12761 | install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd); |
| 12762 | install_element (VIEW_NODE, &show_bgp_community4_exact_cmd); |
| 12763 | install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd); |
| 12764 | install_element (VIEW_NODE, &show_bgp_community_list_cmd); |
| 12765 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd); |
| 12766 | install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd); |
| 12767 | install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd); |
| 12768 | install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd); |
| 12769 | install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd); |
| 12770 | install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd); |
| 12771 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd); |
| 12772 | install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd); |
| 12773 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd); |
| 12774 | install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd); |
| 12775 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd); |
| 12776 | install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd); |
| 12777 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 12778 | install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd); |
| 12779 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd); |
| 12780 | install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd); |
| 12781 | install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12782 | install_element (VIEW_NODE, &show_bgp_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12783 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12784 | install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12785 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12786 | install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12787 | install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 12788 | install_element (VIEW_NODE, &show_bgp_view_cmd); |
| 12789 | install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd); |
| 12790 | install_element (VIEW_NODE, &show_bgp_view_route_cmd); |
| 12791 | install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd); |
| 12792 | install_element (VIEW_NODE, &show_bgp_view_prefix_cmd); |
| 12793 | install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd); |
| 12794 | install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd); |
| 12795 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd); |
| 12796 | install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd); |
| 12797 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd); |
| 12798 | install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd); |
| 12799 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd); |
| 12800 | install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); |
| 12801 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); |
| 12802 | install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd); |
| 12803 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd); |
| 12804 | install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd); |
| 12805 | install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12806 | install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12807 | install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12808 | install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12809 | install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12810 | install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12811 | install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12812 | |
| 12813 | /* Restricted: |
| 12814 | * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev) |
| 12815 | */ |
| 12816 | install_element (RESTRICTED_NODE, &show_bgp_route_cmd); |
| 12817 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12818 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12819 | install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd); |
| 12820 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12821 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12822 | install_element (RESTRICTED_NODE, &show_bgp_community_cmd); |
| 12823 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd); |
| 12824 | install_element (RESTRICTED_NODE, &show_bgp_community2_cmd); |
| 12825 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd); |
| 12826 | install_element (RESTRICTED_NODE, &show_bgp_community3_cmd); |
| 12827 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd); |
| 12828 | install_element (RESTRICTED_NODE, &show_bgp_community4_cmd); |
| 12829 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd); |
| 12830 | install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd); |
| 12831 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd); |
| 12832 | install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd); |
| 12833 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd); |
| 12834 | install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd); |
| 12835 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd); |
| 12836 | install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd); |
| 12837 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd); |
| 12838 | install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12839 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12840 | install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12841 | install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12842 | install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd); |
| 12843 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd); |
| 12844 | install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd); |
| 12845 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd); |
| 12846 | install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); |
| 12847 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); |
| 12848 | install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12849 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 12850 | install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12851 | install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12852 | |
| 12853 | install_element (ENABLE_NODE, &show_bgp_cmd); |
| 12854 | install_element (ENABLE_NODE, &show_bgp_ipv6_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12855 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12856 | install_element (ENABLE_NODE, &show_bgp_route_cmd); |
| 12857 | install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12858 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12859 | install_element (ENABLE_NODE, &show_bgp_prefix_cmd); |
| 12860 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12861 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12862 | install_element (ENABLE_NODE, &show_bgp_regexp_cmd); |
| 12863 | install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd); |
| 12864 | install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd); |
| 12865 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd); |
| 12866 | install_element (ENABLE_NODE, &show_bgp_filter_list_cmd); |
| 12867 | install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd); |
| 12868 | install_element (ENABLE_NODE, &show_bgp_route_map_cmd); |
| 12869 | install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd); |
| 12870 | install_element (ENABLE_NODE, &show_bgp_community_all_cmd); |
| 12871 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd); |
| 12872 | install_element (ENABLE_NODE, &show_bgp_community_cmd); |
| 12873 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd); |
| 12874 | install_element (ENABLE_NODE, &show_bgp_community2_cmd); |
| 12875 | install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd); |
| 12876 | install_element (ENABLE_NODE, &show_bgp_community3_cmd); |
| 12877 | install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd); |
| 12878 | install_element (ENABLE_NODE, &show_bgp_community4_cmd); |
| 12879 | install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd); |
| 12880 | install_element (ENABLE_NODE, &show_bgp_community_exact_cmd); |
| 12881 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd); |
| 12882 | install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd); |
| 12883 | install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd); |
| 12884 | install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd); |
| 12885 | install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd); |
| 12886 | install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd); |
| 12887 | install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd); |
| 12888 | install_element (ENABLE_NODE, &show_bgp_community_list_cmd); |
| 12889 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd); |
| 12890 | install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd); |
| 12891 | install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd); |
| 12892 | install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd); |
| 12893 | install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd); |
| 12894 | install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd); |
| 12895 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd); |
| 12896 | install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd); |
| 12897 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd); |
| 12898 | install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd); |
| 12899 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd); |
| 12900 | install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd); |
| 12901 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 12902 | install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd); |
| 12903 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd); |
| 12904 | install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd); |
| 12905 | install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12906 | install_element (ENABLE_NODE, &show_bgp_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12907 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12908 | install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12909 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12910 | install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12911 | install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 12912 | install_element (ENABLE_NODE, &show_bgp_view_cmd); |
| 12913 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd); |
| 12914 | install_element (ENABLE_NODE, &show_bgp_view_route_cmd); |
| 12915 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd); |
| 12916 | install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd); |
| 12917 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd); |
| 12918 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd); |
| 12919 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd); |
| 12920 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd); |
| 12921 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd); |
| 12922 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd); |
| 12923 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd); |
| 12924 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd); |
| 12925 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd); |
| 12926 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd); |
| 12927 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd); |
| 12928 | install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd); |
| 12929 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12930 | install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12931 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12932 | install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12933 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd); |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 12934 | install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd); |
Michael Lambert | 95cbbd2 | 2010-07-23 14:43:04 -0400 | [diff] [blame] | 12935 | install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd); |
Paul Jakma | 2815e61 | 2006-09-14 02:56:07 +0000 | [diff] [blame] | 12936 | |
| 12937 | /* Statistics */ |
| 12938 | install_element (ENABLE_NODE, &show_bgp_statistics_cmd); |
| 12939 | install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd); |
| 12940 | install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd); |
| 12941 | install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd); |
| 12942 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12943 | /* old command */ |
| 12944 | install_element (VIEW_NODE, &show_ipv6_bgp_cmd); |
| 12945 | install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd); |
| 12946 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd); |
| 12947 | install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd); |
| 12948 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd); |
| 12949 | install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd); |
| 12950 | install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd); |
| 12951 | install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd); |
| 12952 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd); |
| 12953 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd); |
| 12954 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd); |
| 12955 | install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd); |
| 12956 | install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd); |
| 12957 | install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd); |
| 12958 | install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd); |
| 12959 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd); |
| 12960 | install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd); |
| 12961 | install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd); |
| 12962 | install_element (VIEW_NODE, &show_ipv6_mbgp_cmd); |
| 12963 | install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd); |
| 12964 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd); |
| 12965 | install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd); |
| 12966 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd); |
| 12967 | install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd); |
| 12968 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd); |
| 12969 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd); |
| 12970 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd); |
| 12971 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd); |
| 12972 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd); |
| 12973 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd); |
| 12974 | install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd); |
| 12975 | install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd); |
| 12976 | install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd); |
| 12977 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd); |
| 12978 | install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd); |
| 12979 | install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd); |
paul | bb46e94 | 2003-10-24 19:02:03 +0000 | [diff] [blame] | 12980 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 12981 | /* old command */ |
| 12982 | install_element (ENABLE_NODE, &show_ipv6_bgp_cmd); |
| 12983 | install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd); |
| 12984 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd); |
| 12985 | install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd); |
| 12986 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd); |
| 12987 | install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd); |
| 12988 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd); |
| 12989 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd); |
| 12990 | install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd); |
| 12991 | install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd); |
| 12992 | install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd); |
| 12993 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd); |
| 12994 | install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd); |
| 12995 | install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd); |
| 12996 | install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd); |
| 12997 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd); |
| 12998 | install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd); |
| 12999 | install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd); |
| 13000 | install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd); |
| 13001 | install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd); |
| 13002 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd); |
| 13003 | install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd); |
| 13004 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd); |
| 13005 | install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd); |
| 13006 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd); |
| 13007 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd); |
| 13008 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd); |
| 13009 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd); |
| 13010 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd); |
| 13011 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd); |
| 13012 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd); |
| 13013 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd); |
| 13014 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd); |
| 13015 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd); |
| 13016 | install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd); |
| 13017 | install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd); |
| 13018 | |
| 13019 | /* old command */ |
| 13020 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd); |
| 13021 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd); |
| 13022 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd); |
| 13023 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd); |
| 13024 | |
| 13025 | /* old command */ |
| 13026 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd); |
| 13027 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd); |
| 13028 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd); |
| 13029 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd); |
| 13030 | |
| 13031 | /* old command */ |
| 13032 | install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd); |
| 13033 | install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd); |
| 13034 | install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd); |
| 13035 | install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd); |
| 13036 | #endif /* HAVE_IPV6 */ |
| 13037 | |
| 13038 | install_element (BGP_NODE, &bgp_distance_cmd); |
| 13039 | install_element (BGP_NODE, &no_bgp_distance_cmd); |
| 13040 | install_element (BGP_NODE, &no_bgp_distance2_cmd); |
| 13041 | install_element (BGP_NODE, &bgp_distance_source_cmd); |
| 13042 | install_element (BGP_NODE, &no_bgp_distance_source_cmd); |
| 13043 | install_element (BGP_NODE, &bgp_distance_source_access_list_cmd); |
| 13044 | install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd); |
| 13045 | |
| 13046 | install_element (BGP_NODE, &bgp_damp_set_cmd); |
| 13047 | install_element (BGP_NODE, &bgp_damp_set2_cmd); |
| 13048 | install_element (BGP_NODE, &bgp_damp_set3_cmd); |
| 13049 | install_element (BGP_NODE, &bgp_damp_unset_cmd); |
| 13050 | install_element (BGP_NODE, &bgp_damp_unset2_cmd); |
| 13051 | install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd); |
| 13052 | install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd); |
| 13053 | install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd); |
| 13054 | install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd); |
| 13055 | install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd); |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 13056 | |
| 13057 | /* Deprecated AS-Pathlimit commands */ |
| 13058 | install_element (BGP_NODE, &bgp_network_ttl_cmd); |
| 13059 | install_element (BGP_NODE, &bgp_network_mask_ttl_cmd); |
| 13060 | install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd); |
| 13061 | install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd); |
| 13062 | install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd); |
| 13063 | install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); |
| 13064 | |
| 13065 | install_element (BGP_NODE, &no_bgp_network_ttl_cmd); |
| 13066 | install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd); |
| 13067 | install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd); |
| 13068 | install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd); |
| 13069 | install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd); |
| 13070 | install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); |
| 13071 | |
| 13072 | install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd); |
| 13073 | install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd); |
| 13074 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd); |
| 13075 | install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd); |
| 13076 | install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd); |
| 13077 | install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); |
| 13078 | |
| 13079 | install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd); |
| 13080 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd); |
| 13081 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd); |
| 13082 | install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd); |
| 13083 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd); |
| 13084 | install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); |
| 13085 | |
| 13086 | install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd); |
| 13087 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd); |
| 13088 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd); |
| 13089 | install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd); |
| 13090 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd); |
| 13091 | install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); |
| 13092 | |
| 13093 | install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd); |
| 13094 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd); |
| 13095 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd); |
| 13096 | install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd); |
| 13097 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd); |
| 13098 | install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); |
Paul Jakma | 3bde17f | 2011-03-23 10:30:30 +0000 | [diff] [blame] | 13099 | |
| 13100 | #ifdef HAVE_IPV6 |
Paul Jakma | c8f3fe3 | 2010-12-05 20:28:02 +0000 | [diff] [blame] | 13101 | install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd); |
| 13102 | install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd); |
Paul Jakma | 3bde17f | 2011-03-23 10:30:30 +0000 | [diff] [blame] | 13103 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 13104 | } |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 13105 | |
| 13106 | void |
| 13107 | bgp_route_finish (void) |
| 13108 | { |
| 13109 | bgp_table_unlock (bgp_distance_table); |
| 13110 | bgp_distance_table = NULL; |
| 13111 | } |