paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* MPLS-VPN |
| 2 | Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org> |
| 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 "command.h" |
| 24 | #include "prefix.h" |
| 25 | #include "log.h" |
| 26 | #include "memory.h" |
| 27 | #include "stream.h" |
Donald Sharp | 0490729 | 2016-01-07 10:03:01 -0500 | [diff] [blame] | 28 | #include "filter.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 29 | |
| 30 | #include "bgpd/bgpd.h" |
| 31 | #include "bgpd/bgp_table.h" |
| 32 | #include "bgpd/bgp_route.h" |
| 33 | #include "bgpd/bgp_attr.h" |
| 34 | #include "bgpd/bgp_mplsvpn.h" |
| 35 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 36 | static u_int16_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | decode_rd_type (u_char *pnt) |
| 38 | { |
| 39 | u_int16_t v; |
| 40 | |
| 41 | v = ((u_int16_t) *pnt++ << 8); |
| 42 | v |= (u_int16_t) *pnt; |
| 43 | return v; |
| 44 | } |
| 45 | |
| 46 | u_int32_t |
| 47 | decode_label (u_char *pnt) |
| 48 | { |
| 49 | u_int32_t l; |
| 50 | |
| 51 | l = ((u_int32_t) *pnt++ << 12); |
| 52 | l |= (u_int32_t) *pnt++ << 4; |
| 53 | l |= (u_int32_t) ((*pnt & 0xf0) >> 4); |
| 54 | return l; |
| 55 | } |
| 56 | |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 57 | /* type == RD_TYPE_AS */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 58 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | decode_rd_as (u_char *pnt, struct rd_as *rd_as) |
| 60 | { |
| 61 | rd_as->as = (u_int16_t) *pnt++ << 8; |
| 62 | rd_as->as |= (u_int16_t) *pnt++; |
| 63 | |
| 64 | rd_as->val = ((u_int32_t) *pnt++ << 24); |
| 65 | rd_as->val |= ((u_int32_t) *pnt++ << 16); |
| 66 | rd_as->val |= ((u_int32_t) *pnt++ << 8); |
| 67 | rd_as->val |= (u_int32_t) *pnt; |
| 68 | } |
| 69 | |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 70 | /* type == RD_TYPE_AS4 */ |
| 71 | static void |
| 72 | decode_rd_as4 (u_char *pnt, struct rd_as *rd_as) |
| 73 | { |
| 74 | rd_as->as = (u_int32_t) *pnt++ << 24; |
| 75 | rd_as->as |= (u_int32_t) *pnt++ << 16; |
| 76 | rd_as->as |= (u_int32_t) *pnt++ << 8; |
| 77 | rd_as->as |= (u_int32_t) *pnt++; |
| 78 | |
| 79 | rd_as->val = ((u_int16_t) *pnt++ << 8); |
| 80 | rd_as->val |= (u_int16_t) *pnt; |
| 81 | } |
| 82 | |
| 83 | /* type == RD_TYPE_IP */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 84 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 85 | decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip) |
| 86 | { |
| 87 | memcpy (&rd_ip->ip, pnt, 4); |
| 88 | pnt += 4; |
| 89 | |
| 90 | rd_ip->val = ((u_int16_t) *pnt++ << 8); |
| 91 | rd_ip->val |= (u_int16_t) *pnt; |
| 92 | } |
| 93 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 94 | int |
Lou Berger | 9da04bc | 2016-01-12 13:41:55 -0500 | [diff] [blame] | 95 | bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr, |
| 96 | struct bgp_nlri *packet) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 97 | { |
| 98 | u_char *pnt; |
| 99 | u_char *lim; |
| 100 | struct prefix p; |
Lou Berger | 9da04bc | 2016-01-12 13:41:55 -0500 | [diff] [blame] | 101 | int psize = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | int prefixlen; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | u_int16_t type; |
| 104 | struct rd_as rd_as; |
| 105 | struct rd_ip rd_ip; |
| 106 | struct prefix_rd prd; |
| 107 | u_char *tagpnt; |
| 108 | |
| 109 | /* Check peer status. */ |
| 110 | if (peer->status != Established) |
| 111 | return 0; |
| 112 | |
| 113 | /* Make prefix_rd */ |
| 114 | prd.family = AF_UNSPEC; |
| 115 | prd.prefixlen = 64; |
| 116 | |
| 117 | pnt = packet->nlri; |
| 118 | lim = pnt + packet->length; |
| 119 | |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 120 | #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | for (; pnt < lim; pnt += psize) |
| 122 | { |
| 123 | /* Clear prefix structure. */ |
| 124 | memset (&p, 0, sizeof (struct prefix)); |
| 125 | |
| 126 | /* Fetch prefix length. */ |
| 127 | prefixlen = *pnt++; |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 128 | p.family = afi2family (packet->afi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 129 | psize = PSIZE (prefixlen); |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 130 | |
| 131 | /* sanity check against packet data */ |
| 132 | if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim) |
| 133 | { |
| 134 | zlog_err ("prefix length (%d) is less than 88" |
| 135 | " or larger than received (%u)", |
| 136 | prefixlen, (uint)(lim-pnt)); |
| 137 | return -1; |
| 138 | } |
| 139 | |
| 140 | /* sanity check against storage for the IP address portion */ |
| 141 | if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u)) |
| 142 | { |
| 143 | zlog_err ("prefix length (%d) exceeds prefix storage (%zu)", |
| 144 | prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u)); |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | /* Sanity check against max bitlen of the address family */ |
| 149 | if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p)) |
| 150 | { |
| 151 | zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)", |
| 152 | prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, |
| 153 | p.family, prefix_blen (&p)); |
| 154 | return -1; |
| 155 | |
| 156 | } |
| 157 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | /* Copyr label to prefix. */ |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 159 | tagpnt = pnt; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | |
| 161 | /* Copy routing distinguisher to rd. */ |
| 162 | memcpy (&prd.val, pnt + 3, 8); |
| 163 | |
| 164 | /* Decode RD type. */ |
| 165 | type = decode_rd_type (pnt + 3); |
| 166 | |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 167 | switch (type) |
| 168 | { |
| 169 | case RD_TYPE_AS: |
| 170 | decode_rd_as (pnt + 5, &rd_as); |
| 171 | break; |
| 172 | |
| 173 | case RD_TYPE_AS4: |
| 174 | decode_rd_as4 (pnt + 5, &rd_as); |
| 175 | break; |
| 176 | |
| 177 | case RD_TYPE_IP: |
| 178 | decode_rd_ip (pnt + 5, &rd_ip); |
| 179 | break; |
| 180 | |
Lou Berger | 050defe | 2016-01-12 13:41:59 -0500 | [diff] [blame] | 181 | default: |
| 182 | zlog_err ("Unknown RD type %d", type); |
| 183 | break; /* just report */ |
| 184 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 186 | p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8; |
| 187 | memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES, |
| 188 | psize - VPN_PREFIXLEN_MIN_BYTES); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 189 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 190 | if (attr) |
Lou Berger | 9da04bc | 2016-01-12 13:41:55 -0500 | [diff] [blame] | 191 | bgp_update (peer, &p, attr, packet->afi, SAFI_MPLS_VPN, |
| 192 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | else |
Lou Berger | 9da04bc | 2016-01-12 13:41:55 -0500 | [diff] [blame] | 194 | bgp_withdraw (peer, &p, attr, packet->afi, SAFI_MPLS_VPN, |
| 195 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 196 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 197 | /* Packet length consistency check. */ |
| 198 | if (pnt != lim) |
| 199 | return -1; |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 200 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | return 0; |
Donald Sharp | a3bc7e9 | 2016-01-27 16:54:45 +0000 | [diff] [blame] | 202 | #undef VPN_PREFIXLEN_MIN_BYTES |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 206 | str2prefix_rd (const char *str, struct prefix_rd *prd) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | { |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 208 | int ret; /* ret of called functions */ |
| 209 | int lret; /* local ret, of this func */ |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 210 | char *p; |
| 211 | char *p2; |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 212 | struct stream *s = NULL; |
| 213 | char *half = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | struct in_addr addr; |
| 215 | |
| 216 | s = stream_new (8); |
| 217 | |
| 218 | prd->family = AF_UNSPEC; |
| 219 | prd->prefixlen = 64; |
| 220 | |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 221 | lret = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 222 | p = strchr (str, ':'); |
| 223 | if (! p) |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 224 | goto out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 225 | |
| 226 | if (! all_digit (p + 1)) |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 227 | goto out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | |
| 229 | half = XMALLOC (MTYPE_TMP, (p - str) + 1); |
| 230 | memcpy (half, str, (p - str)); |
| 231 | half[p - str] = '\0'; |
| 232 | |
| 233 | p2 = strchr (str, '.'); |
| 234 | |
| 235 | if (! p2) |
| 236 | { |
| 237 | if (! all_digit (half)) |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 238 | goto out; |
| 239 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | stream_putw (s, RD_TYPE_AS); |
| 241 | stream_putw (s, atoi (half)); |
| 242 | stream_putl (s, atol (p + 1)); |
| 243 | } |
| 244 | else |
| 245 | { |
| 246 | ret = inet_aton (half, &addr); |
| 247 | if (! ret) |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 248 | goto out; |
| 249 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | stream_putw (s, RD_TYPE_IP); |
| 251 | stream_put_in_addr (s, &addr); |
| 252 | stream_putw (s, atol (p + 1)); |
| 253 | } |
| 254 | memcpy (prd->val, s->data, 8); |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 255 | lret = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 257 | out: |
| 258 | if (s) |
| 259 | stream_free (s); |
| 260 | if (half) |
| 261 | XFREE(MTYPE_TMP, half); |
| 262 | return lret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 266 | str2tag (const char *str, u_char *tag) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | { |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 268 | unsigned long l; |
| 269 | char *endptr; |
| 270 | u_int32_t t; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 271 | |
Ulrich Weber | 664711c | 2011-12-21 02:24:11 +0400 | [diff] [blame] | 272 | if (*str == '-') |
| 273 | return 0; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 274 | |
Ulrich Weber | 664711c | 2011-12-21 02:24:11 +0400 | [diff] [blame] | 275 | errno = 0; |
| 276 | l = strtoul (str, &endptr, 10); |
| 277 | |
| 278 | if (*endptr != '\0' || errno || l > UINT32_MAX) |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 279 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 280 | |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 281 | t = (u_int32_t) l; |
| 282 | |
| 283 | tag[0] = (u_char)(t >> 12); |
| 284 | tag[1] = (u_char)(t >> 4); |
| 285 | tag[2] = (u_char)(t << 4); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 286 | |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | char * |
| 291 | prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size) |
| 292 | { |
| 293 | u_char *pnt; |
| 294 | u_int16_t type; |
| 295 | struct rd_as rd_as; |
| 296 | struct rd_ip rd_ip; |
| 297 | |
| 298 | if (size < RD_ADDRSTRLEN) |
| 299 | return NULL; |
| 300 | |
| 301 | pnt = prd->val; |
| 302 | |
| 303 | type = decode_rd_type (pnt); |
| 304 | |
| 305 | if (type == RD_TYPE_AS) |
| 306 | { |
| 307 | decode_rd_as (pnt + 2, &rd_as); |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 308 | snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 309 | return buf; |
| 310 | } |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 311 | else if (type == RD_TYPE_AS4) |
| 312 | { |
| 313 | decode_rd_as4 (pnt + 2, &rd_as); |
| 314 | snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val); |
| 315 | return buf; |
| 316 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 317 | else if (type == RD_TYPE_IP) |
| 318 | { |
| 319 | decode_rd_ip (pnt + 2, &rd_ip); |
| 320 | snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); |
| 321 | return buf; |
| 322 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | /* For testing purpose, static route of MPLS-VPN. */ |
| 327 | DEFUN (vpnv4_network, |
| 328 | vpnv4_network_cmd, |
| 329 | "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD", |
| 330 | "Specify a network to announce via BGP\n" |
| 331 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 332 | "Specify Route Distinguisher\n" |
| 333 | "VPN Route Distinguisher\n" |
| 334 | "BGP tag\n" |
| 335 | "tag value\n") |
| 336 | { |
Lou Berger | a76d9ca | 2016-01-12 13:41:53 -0500 | [diff] [blame] | 337 | return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], NULL); |
| 338 | } |
| 339 | |
| 340 | DEFUN (vpnv4_network_route_map, |
| 341 | vpnv4_network_route_map_cmd, |
| 342 | "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD", |
| 343 | "Specify a network to announce via BGP\n" |
| 344 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 345 | "Specify Route Distinguisher\n" |
| 346 | "VPN Route Distinguisher\n" |
| 347 | "BGP tag\n" |
| 348 | "tag value\n" |
| 349 | "route map\n" |
| 350 | "route map name\n") |
| 351 | { |
| 352 | return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], argv[3]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /* For testing purpose, static route of MPLS-VPN. */ |
| 356 | DEFUN (no_vpnv4_network, |
| 357 | no_vpnv4_network_cmd, |
| 358 | "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD", |
| 359 | NO_STR |
| 360 | "Specify a network to announce via BGP\n" |
| 361 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 362 | "Specify Route Distinguisher\n" |
| 363 | "VPN Route Distinguisher\n" |
| 364 | "BGP tag\n" |
| 365 | "tag value\n") |
| 366 | { |
Lou Berger | a76d9ca | 2016-01-12 13:41:53 -0500 | [diff] [blame] | 367 | return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | } |
| 369 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 370 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 371 | show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd) |
| 372 | { |
| 373 | struct bgp *bgp; |
| 374 | struct bgp_table *table; |
| 375 | struct bgp_node *rn; |
| 376 | struct bgp_node *rm; |
| 377 | struct attr *attr; |
| 378 | int rd_header; |
| 379 | int header = 1; |
| 380 | char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s"; |
| 381 | |
| 382 | bgp = bgp_get_default (); |
| 383 | if (bgp == NULL) |
| 384 | { |
| 385 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 386 | return CMD_WARNING; |
| 387 | } |
| 388 | |
| 389 | for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; |
| 390 | rn = bgp_route_next (rn)) |
| 391 | { |
| 392 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) |
| 393 | continue; |
| 394 | |
| 395 | if ((table = rn->info) != NULL) |
| 396 | { |
| 397 | rd_header = 1; |
| 398 | |
| 399 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) |
| 400 | if ((attr = rm->info) != NULL) |
| 401 | { |
| 402 | if (header) |
| 403 | { |
| 404 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", |
| 405 | inet_ntoa (bgp->router_id), VTY_NEWLINE); |
| 406 | vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", |
| 407 | VTY_NEWLINE); |
| 408 | vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", |
| 409 | VTY_NEWLINE, VTY_NEWLINE); |
| 410 | vty_out (vty, v4_header, VTY_NEWLINE); |
| 411 | header = 0; |
| 412 | } |
| 413 | |
| 414 | if (rd_header) |
| 415 | { |
| 416 | u_int16_t type; |
| 417 | struct rd_as rd_as; |
| 418 | struct rd_ip rd_ip; |
| 419 | u_char *pnt; |
| 420 | |
| 421 | pnt = rn->p.u.val; |
| 422 | |
| 423 | /* Decode RD type. */ |
| 424 | type = decode_rd_type (pnt); |
| 425 | /* Decode RD value. */ |
| 426 | if (type == RD_TYPE_AS) |
| 427 | decode_rd_as (pnt + 2, &rd_as); |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 428 | else if (type == RD_TYPE_AS4) |
| 429 | decode_rd_as4 (pnt + 2, &rd_as); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | else if (type == RD_TYPE_IP) |
| 431 | decode_rd_ip (pnt + 2, &rd_ip); |
| 432 | |
| 433 | vty_out (vty, "Route Distinguisher: "); |
| 434 | |
| 435 | if (type == RD_TYPE_AS) |
Denis Ovsienko | aea339f | 2009-04-30 17:16:22 +0400 | [diff] [blame] | 436 | vty_out (vty, "%u:%d", rd_as.as, rd_as.val); |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 437 | else if (type == RD_TYPE_AS4) |
| 438 | vty_out (vty, "%u:%d", rd_as.as, rd_as.val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | else if (type == RD_TYPE_IP) |
| 440 | vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); |
| 441 | |
| 442 | vty_out (vty, "%s", VTY_NEWLINE); |
| 443 | rd_header = 0; |
| 444 | } |
| 445 | route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | return CMD_SUCCESS; |
| 450 | } |
| 451 | |
| 452 | enum bgp_show_type |
| 453 | { |
| 454 | bgp_show_type_normal, |
| 455 | bgp_show_type_regexp, |
| 456 | bgp_show_type_prefix_list, |
| 457 | bgp_show_type_filter_list, |
| 458 | bgp_show_type_neighbor, |
| 459 | bgp_show_type_cidr_only, |
| 460 | bgp_show_type_prefix_longer, |
| 461 | bgp_show_type_community_all, |
| 462 | bgp_show_type_community, |
| 463 | bgp_show_type_community_exact, |
| 464 | bgp_show_type_community_list, |
| 465 | bgp_show_type_community_list_exact |
| 466 | }; |
| 467 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 468 | static int |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 469 | bgp_show_mpls_vpn( |
| 470 | struct vty *vty, |
| 471 | afi_t afi, |
| 472 | struct prefix_rd *prd, |
| 473 | enum bgp_show_type type, |
| 474 | void *output_arg, |
| 475 | int tags) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 476 | { |
| 477 | struct bgp *bgp; |
| 478 | struct bgp_table *table; |
| 479 | struct bgp_node *rn; |
| 480 | struct bgp_node *rm; |
| 481 | struct bgp_info *ri; |
| 482 | int rd_header; |
| 483 | int header = 1; |
| 484 | char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s"; |
| 485 | char v4_header_tag[] = " Network Next Hop In tag/Out tag%s"; |
| 486 | |
Lou Berger | bf1ae6c | 2016-01-12 13:42:08 -0500 | [diff] [blame] | 487 | unsigned long output_count = 0; |
| 488 | unsigned long total_count = 0; |
| 489 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 490 | bgp = bgp_get_default (); |
| 491 | if (bgp == NULL) |
| 492 | { |
| 493 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); |
| 494 | return CMD_WARNING; |
| 495 | } |
| 496 | |
Lou Berger | 9da04bc | 2016-01-12 13:41:55 -0500 | [diff] [blame] | 497 | if ((afi != AFI_IP) && (afi != AFI_IP6)) |
| 498 | { |
| 499 | vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE); |
| 500 | return CMD_WARNING; |
| 501 | } |
| 502 | |
| 503 | for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 504 | { |
| 505 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) |
| 506 | continue; |
| 507 | |
| 508 | if ((table = rn->info) != NULL) |
| 509 | { |
| 510 | rd_header = 1; |
| 511 | |
| 512 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) |
| 513 | for (ri = rm->info; ri; ri = ri->next) |
| 514 | { |
Lou Berger | bf1ae6c | 2016-01-12 13:42:08 -0500 | [diff] [blame] | 515 | total_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | if (type == bgp_show_type_neighbor) |
| 517 | { |
| 518 | union sockunion *su = output_arg; |
| 519 | |
| 520 | if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su)) |
| 521 | continue; |
| 522 | } |
| 523 | if (header) |
| 524 | { |
| 525 | if (tags) |
| 526 | vty_out (vty, v4_header_tag, VTY_NEWLINE); |
| 527 | else |
| 528 | { |
| 529 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", |
| 530 | inet_ntoa (bgp->router_id), VTY_NEWLINE); |
| 531 | vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", |
| 532 | VTY_NEWLINE); |
| 533 | vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", |
| 534 | VTY_NEWLINE, VTY_NEWLINE); |
| 535 | vty_out (vty, v4_header, VTY_NEWLINE); |
| 536 | } |
| 537 | header = 0; |
| 538 | } |
| 539 | |
| 540 | if (rd_header) |
| 541 | { |
| 542 | u_int16_t type; |
| 543 | struct rd_as rd_as; |
| 544 | struct rd_ip rd_ip; |
| 545 | u_char *pnt; |
| 546 | |
| 547 | pnt = rn->p.u.val; |
| 548 | |
| 549 | /* Decode RD type. */ |
| 550 | type = decode_rd_type (pnt); |
| 551 | /* Decode RD value. */ |
| 552 | if (type == RD_TYPE_AS) |
| 553 | decode_rd_as (pnt + 2, &rd_as); |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 554 | else if (type == RD_TYPE_AS4) |
| 555 | decode_rd_as4 (pnt + 2, &rd_as); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 556 | else if (type == RD_TYPE_IP) |
| 557 | decode_rd_ip (pnt + 2, &rd_ip); |
| 558 | |
| 559 | vty_out (vty, "Route Distinguisher: "); |
| 560 | |
| 561 | if (type == RD_TYPE_AS) |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 562 | vty_out (vty, "as2 %u:%d", rd_as.as, rd_as.val); |
| 563 | else if (type == RD_TYPE_AS4) |
| 564 | vty_out (vty, "as4 %u:%d", rd_as.as, rd_as.val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | else if (type == RD_TYPE_IP) |
Lou Berger | a03bd16 | 2016-01-12 13:41:54 -0500 | [diff] [blame] | 566 | vty_out (vty, "ip %s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 567 | |
| 568 | vty_out (vty, "%s", VTY_NEWLINE); |
| 569 | rd_header = 0; |
| 570 | } |
| 571 | if (tags) |
| 572 | route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN); |
| 573 | else |
| 574 | route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN); |
Lou Berger | bf1ae6c | 2016-01-12 13:42:08 -0500 | [diff] [blame] | 575 | output_count++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | } |
Lou Berger | bf1ae6c | 2016-01-12 13:42:08 -0500 | [diff] [blame] | 579 | |
| 580 | if (output_count == 0) |
| 581 | { |
| 582 | vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE); |
| 583 | } |
| 584 | else |
| 585 | vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s", |
| 586 | VTY_NEWLINE, output_count, total_count, VTY_NEWLINE); |
| 587 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 588 | return CMD_SUCCESS; |
| 589 | } |
| 590 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 591 | DEFUN (show_bgp_ipv4_vpn, |
| 592 | show_bgp_ipv4_vpn_cmd, |
| 593 | "show bgp ipv4 vpn", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 594 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 595 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 596 | "Address Family\n" |
| 597 | "Display VPN NLRI specific information\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | { |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 599 | return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 602 | DEFUN (show_bgp_ipv6_vpn, |
| 603 | show_bgp_ipv6_vpn_cmd, |
| 604 | "show bgp ipv6 vpn", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 605 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 606 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 607 | "Address Family\n" |
| 608 | "Display VPN NLRI specific information\n") |
| 609 | { |
| 610 | return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0); |
| 611 | } |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 612 | |
| 613 | DEFUN (show_bgp_ipv4_vpn_rd, |
| 614 | show_bgp_ipv4_vpn_rd_cmd, |
| 615 | "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn", |
| 616 | SHOW_STR |
| 617 | BGP_STR |
| 618 | "Address Family\n" |
| 619 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 620 | "Display information for a route distinguisher\n" |
| 621 | "VPN Route Distinguisher\n") |
| 622 | { |
| 623 | int ret; |
| 624 | struct prefix_rd prd; |
| 625 | |
| 626 | ret = str2prefix_rd (argv[0], &prd); |
| 627 | if (! ret) |
| 628 | { |
| 629 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 630 | return CMD_WARNING; |
| 631 | } |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 632 | return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 635 | DEFUN (show_bgp_ipv6_vpn_rd, |
| 636 | show_bgp_ipv6_vpn_rd_cmd, |
| 637 | "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 638 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 639 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 640 | "Address Family\n" |
| 641 | "Display VPN NLRI specific information\n" |
| 642 | "Display information for a route distinguisher\n" |
| 643 | "VPN Route Distinguisher\n") |
| 644 | { |
| 645 | int ret; |
| 646 | struct prefix_rd prd; |
| 647 | |
| 648 | ret = str2prefix_rd (argv[0], &prd); |
| 649 | if (! ret) |
| 650 | { |
| 651 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 652 | return CMD_WARNING; |
| 653 | } |
| 654 | return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | DEFUN (show_bgp_ipv4_vpn_tags, |
| 659 | show_bgp_ipv4_vpn_tags_cmd, |
| 660 | "show bgp ipv4 vpn tags", |
| 661 | SHOW_STR |
| 662 | BGP_STR |
| 663 | "Address Family\n" |
| 664 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | "Display BGP tags for prefixes\n") |
| 666 | { |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 667 | return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1); |
| 668 | } |
| 669 | DEFUN (show_bgp_ipv6_vpn_tags, |
| 670 | show_bgp_ipv6_vpn_tags_cmd, |
| 671 | "show bgp ipv6 vpn tags", |
| 672 | SHOW_STR |
| 673 | BGP_STR |
| 674 | "Address Family\n" |
| 675 | "Display VPN NLRI specific information\n" |
| 676 | "Display BGP tags for prefixes\n") |
| 677 | { |
| 678 | return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 681 | DEFUN (show_bgp_ipv4_vpn_rd_tags, |
| 682 | show_bgp_ipv4_vpn_rd_tags_cmd, |
| 683 | "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn tags", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 686 | "Address Family\n" |
| 687 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | "Display information for a route distinguisher\n" |
| 689 | "VPN Route Distinguisher\n" |
| 690 | "Display BGP tags for prefixes\n") |
| 691 | { |
| 692 | int ret; |
| 693 | struct prefix_rd prd; |
| 694 | |
| 695 | ret = str2prefix_rd (argv[0], &prd); |
| 696 | if (! ret) |
| 697 | { |
| 698 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 699 | return CMD_WARNING; |
| 700 | } |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 701 | return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1); |
| 702 | } |
| 703 | DEFUN (show_bgp_ipv6_vpn_rd_tags, |
| 704 | show_bgp_ipv6_vpn_rd_tags_cmd, |
| 705 | "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn tags", |
| 706 | SHOW_STR |
| 707 | BGP_STR |
| 708 | "Address Family\n" |
| 709 | "Display VPN NLRI specific information\n" |
| 710 | "Display information for a route distinguisher\n" |
| 711 | "VPN Route Distinguisher\n" |
| 712 | "Display BGP tags for prefixes\n") |
| 713 | { |
| 714 | int ret; |
| 715 | struct prefix_rd prd; |
| 716 | |
| 717 | ret = str2prefix_rd (argv[0], &prd); |
| 718 | if (! ret) |
| 719 | { |
| 720 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 721 | return CMD_WARNING; |
| 722 | } |
| 723 | return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 726 | DEFUN (show_bgp_ipv4_vpn_neighbor_routes, |
| 727 | show_bgp_ipv4_vpn_neighbor_routes_cmd, |
| 728 | "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) routes", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 729 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 730 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 731 | "Address Family\n" |
| 732 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 733 | "Detailed information on TCP and BGP neighbor connections\n" |
| 734 | "Neighbor to display information about\n" |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 735 | "Neighbor to display information about\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 736 | "Display routes learned from neighbor\n") |
| 737 | { |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 738 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 739 | struct peer *peer; |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 740 | int ret; |
| 741 | |
| 742 | ret = str2sockunion (argv[0], &su); |
| 743 | if (ret < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 744 | { |
| 745 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 746 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 749 | peer = peer_lookup (NULL, &su); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 750 | if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) |
| 751 | { |
| 752 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 753 | return CMD_WARNING; |
| 754 | } |
| 755 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 756 | return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 759 | DEFUN (show_bgp_ipv6_vpn_neighbor_routes, |
| 760 | show_bgp_ipv6_vpn_neighbor_routes_cmd, |
| 761 | "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) routes", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 762 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 763 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 764 | "Address Family\n" |
| 765 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 766 | "Detailed information on TCP and BGP neighbor connections\n" |
| 767 | "Neighbor to display information about\n" |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 768 | "Neighbor to display information about\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 769 | "Display routes learned from neighbor\n") |
| 770 | { |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 771 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 772 | struct peer *peer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 773 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 774 | int ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 775 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 776 | ret = str2sockunion (argv[0], &su); |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 777 | if (ret < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 778 | { |
| 779 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 780 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Jorge Boncompte [DTI2] | c63b83f | 2012-04-10 16:57:24 +0200 | [diff] [blame] | 783 | peer = peer_lookup (NULL, &su); |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 784 | if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN]) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 785 | { |
| 786 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 787 | return CMD_WARNING; |
| 788 | } |
| 789 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 790 | return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 793 | DEFUN (show_bgp_ipv4_vpn_neighbor_advertised_routes, |
| 794 | show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd, |
| 795 | "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 796 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 797 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 798 | "Address Family\n" |
| 799 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 800 | "Detailed information on TCP and BGP neighbor connections\n" |
| 801 | "Neighbor to display information about\n" |
| 802 | "Display the routes advertised to a BGP neighbor\n") |
| 803 | { |
| 804 | int ret; |
| 805 | struct peer *peer; |
| 806 | union sockunion su; |
| 807 | |
| 808 | ret = str2sockunion (argv[0], &su); |
| 809 | if (ret < 0) |
| 810 | { |
| 811 | vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE); |
| 812 | return CMD_WARNING; |
| 813 | } |
| 814 | peer = peer_lookup (NULL, &su); |
| 815 | if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) |
| 816 | { |
| 817 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 818 | return CMD_WARNING; |
| 819 | } |
| 820 | |
| 821 | return show_adj_route_vpn (vty, peer, NULL); |
| 822 | } |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 823 | DEFUN (show_bgp_ipv6_vpn_neighbor_advertised_routes, |
| 824 | show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd, |
| 825 | "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 826 | SHOW_STR |
| 827 | BGP_STR |
| 828 | "Address Family\n" |
| 829 | "Display VPN NLRI specific information\n" |
| 830 | "Detailed information on TCP and BGP neighbor connections\n" |
| 831 | "Neighbor to display information about\n" |
| 832 | "Display the routes advertised to a BGP neighbor\n") |
| 833 | { |
| 834 | int ret; |
| 835 | struct peer *peer; |
| 836 | union sockunion su; |
| 837 | |
| 838 | ret = str2sockunion (argv[0], &su); |
| 839 | if (ret < 0) |
| 840 | { |
| 841 | vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE); |
| 842 | return CMD_WARNING; |
| 843 | } |
| 844 | peer = peer_lookup (NULL, &su); |
| 845 | if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN]) |
| 846 | { |
| 847 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 848 | return CMD_WARNING; |
| 849 | } |
| 850 | |
| 851 | return show_adj_route_vpn (vty, peer, NULL); |
| 852 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 853 | |
| 854 | DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes, |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 855 | show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd, |
| 856 | "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 857 | SHOW_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 858 | BGP_STR |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 859 | "Address Family\n" |
| 860 | "Display VPN NLRI specific information\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 861 | "Display information for a route distinguisher\n" |
| 862 | "VPN Route Distinguisher\n" |
| 863 | "Detailed information on TCP and BGP neighbor connections\n" |
| 864 | "Neighbor to display information about\n" |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 865 | "Neighbor to display information about\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 866 | "Display the routes advertised to a BGP neighbor\n") |
| 867 | { |
| 868 | int ret; |
| 869 | struct peer *peer; |
| 870 | struct prefix_rd prd; |
| 871 | union sockunion su; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | ret = str2sockunion (argv[1], &su); |
| 873 | if (ret < 0) |
| 874 | { |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 875 | vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 876 | return CMD_WARNING; |
| 877 | } |
| 878 | peer = peer_lookup (NULL, &su); |
| 879 | if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) |
| 880 | { |
| 881 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 882 | return CMD_WARNING; |
| 883 | } |
| 884 | |
| 885 | ret = str2prefix_rd (argv[0], &prd); |
| 886 | if (! ret) |
| 887 | { |
| 888 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 889 | return CMD_WARNING; |
| 890 | } |
| 891 | |
| 892 | return show_adj_route_vpn (vty, peer, &prd); |
| 893 | } |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 894 | DEFUN (show_ip_bgp_vpnv6_rd_neighbor_advertised_routes, |
| 895 | show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd, |
| 896 | "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes", |
| 897 | SHOW_STR |
| 898 | BGP_STR |
| 899 | "Address Family\n" |
| 900 | "Display VPN NLRI specific information\n" |
| 901 | "Display information for a route distinguisher\n" |
| 902 | "VPN Route Distinguisher\n" |
| 903 | "Detailed information on TCP and BGP neighbor connections\n" |
| 904 | "Neighbor to display information about\n" |
| 905 | "Neighbor to display information about\n" |
| 906 | "Display the routes advertised to a BGP neighbor\n") |
| 907 | { |
| 908 | int ret; |
| 909 | struct peer *peer; |
| 910 | struct prefix_rd prd; |
| 911 | union sockunion su; |
| 912 | ret = str2sockunion (argv[1], &su); |
| 913 | if (ret < 0) |
| 914 | { |
| 915 | vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE); |
| 916 | return CMD_WARNING; |
| 917 | } |
| 918 | peer = peer_lookup (NULL, &su); |
| 919 | if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN]) |
| 920 | { |
| 921 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 922 | return CMD_WARNING; |
| 923 | } |
| 924 | |
| 925 | ret = str2prefix_rd (argv[0], &prd); |
| 926 | if (! ret) |
| 927 | { |
| 928 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 929 | return CMD_WARNING; |
| 930 | } |
| 931 | |
| 932 | return show_adj_route_vpn (vty, peer, &prd); |
| 933 | } |
| 934 | |
| 935 | DEFUN (show_bgp_ipv4_vpn_rd_neighbor_routes, |
| 936 | show_bgp_ipv4_vpn_rd_neighbor_routes_cmd, |
| 937 | "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes", |
| 938 | SHOW_STR |
| 939 | BGP_STR |
| 940 | "Address Family\n" |
| 941 | "Address Family modifier\n" |
| 942 | "Display information for a route distinguisher\n" |
| 943 | "VPN Route Distinguisher\n" |
| 944 | "Detailed information on TCP and BGP neighbor connections\n" |
| 945 | "Neighbor to display information about\n" |
| 946 | "Display routes learned from neighbor\n") |
| 947 | { |
| 948 | int ret; |
| 949 | union sockunion *su; |
| 950 | struct peer *peer; |
| 951 | struct prefix_rd prd; |
| 952 | |
| 953 | ret = str2prefix_rd (argv[0], &prd); |
| 954 | if (! ret) |
| 955 | { |
| 956 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 957 | return CMD_WARNING; |
| 958 | } |
| 959 | |
| 960 | su = sockunion_str2su (argv[1]); |
| 961 | if (su == NULL) |
| 962 | { |
| 963 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); |
| 964 | return CMD_WARNING; |
| 965 | } |
| 966 | |
| 967 | peer = peer_lookup (NULL, su); |
| 968 | if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN]) |
| 969 | { |
| 970 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 971 | return CMD_WARNING; |
| 972 | } |
| 973 | |
| 974 | return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0); |
| 975 | } |
| 976 | DEFUN (show_bgp_ipv6_vpn_rd_neighbor_routes, |
| 977 | show_bgp_ipv6_vpn_rd_neighbor_routes_cmd, |
| 978 | "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes", |
| 979 | SHOW_STR |
| 980 | BGP_STR |
| 981 | "Address Family\n" |
| 982 | "Address Family modifier\n" |
| 983 | "Display information for a route distinguisher\n" |
| 984 | "VPN Route Distinguisher\n" |
| 985 | "Detailed information on TCP and BGP neighbor connections\n" |
| 986 | "Neighbor to display information about\n" |
| 987 | "Display routes learned from neighbor\n") |
| 988 | { |
| 989 | int ret; |
| 990 | union sockunion *su; |
| 991 | struct peer *peer; |
| 992 | struct prefix_rd prd; |
| 993 | |
| 994 | ret = str2prefix_rd (argv[0], &prd); |
| 995 | if (! ret) |
| 996 | { |
| 997 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); |
| 998 | return CMD_WARNING; |
| 999 | } |
| 1000 | |
| 1001 | su = sockunion_str2su (argv[1]); |
| 1002 | if (su == NULL) |
| 1003 | { |
| 1004 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); |
| 1005 | return CMD_WARNING; |
| 1006 | } |
| 1007 | |
| 1008 | peer = peer_lookup (NULL, su); |
| 1009 | if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN]) |
| 1010 | { |
| 1011 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); |
| 1012 | return CMD_WARNING; |
| 1013 | } |
| 1014 | |
| 1015 | return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0); |
| 1016 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1017 | |
| 1018 | void |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1019 | bgp_mplsvpn_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1020 | { |
| 1021 | install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd); |
Lou Berger | a76d9ca | 2016-01-12 13:41:53 -0500 | [diff] [blame] | 1022 | install_element (BGP_VPNV4_NODE, &vpnv4_network_route_map_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1023 | install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd); |
| 1024 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 1025 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_cmd); |
| 1026 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd); |
| 1027 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_tags_cmd); |
| 1028 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd); |
| 1029 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd); |
| 1030 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd); |
| 1031 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd); |
| 1032 | install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1033 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 1034 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd); |
| 1035 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd); |
| 1036 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_tags_cmd); |
| 1037 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd); |
| 1038 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd); |
| 1039 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd); |
| 1040 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd); |
| 1041 | install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1042 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 1043 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_cmd); |
| 1044 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_cmd); |
| 1045 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_tags_cmd); |
| 1046 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd); |
| 1047 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd); |
| 1048 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd); |
| 1049 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd); |
| 1050 | install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd); |
| 1051 | |
Lou Berger | 35c3686 | 2016-01-12 13:42:06 -0500 | [diff] [blame] | 1052 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_cmd); |
| 1053 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_cmd); |
| 1054 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_tags_cmd); |
| 1055 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd); |
| 1056 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd); |
| 1057 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd); |
| 1058 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd); |
| 1059 | install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1060 | } |