blob: b5b50bb5fa39ea1812476088736ddef6638e7b94 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP open message handling
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "linklist.h"
24#include "prefix.h"
25#include "stream.h"
26#include "thread.h"
27#include "log.h"
28#include "command.h"
Paul Jakma6d582722007-08-06 15:21:45 +000029#include "memory.h"
paul718e3742002-12-13 20:15:29 +000030
31#include "bgpd/bgpd.h"
32#include "bgpd/bgp_attr.h"
33#include "bgpd/bgp_debug.h"
34#include "bgpd/bgp_fsm.h"
35#include "bgpd/bgp_packet.h"
36#include "bgpd/bgp_open.h"
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000037#include "bgpd/bgp_aspath.h"
hasso538621f2004-05-21 09:31:30 +000038#include "bgpd/bgp_vty.h"
39
paul718e3742002-12-13 20:15:29 +000040/* BGP-4 Multiprotocol Extentions lead us to the complex world. We can
41 negotiate remote peer supports extentions or not. But if
42 remote-peer doesn't supports negotiation process itself. We would
43 like to do manual configuration.
44
45 So there is many configurable point. First of all we want set each
46 peer whether we send capability negotiation to the peer or not.
47 Next, if we send capability to the peer we want to set my capabilty
48 inforation at each peer. */
49
50void
51bgp_capability_vty_out (struct vty *vty, struct peer *peer)
52{
paul5228ad22004-06-04 17:58:18 +000053 char *pnt;
54 char *end;
Paul Jakma6d582722007-08-06 15:21:45 +000055 struct capability_mp_data mpc;
56 struct capability_header *hdr;
paul718e3742002-12-13 20:15:29 +000057
58 pnt = peer->notify.data;
59 end = pnt + peer->notify.length;
Paul Jakma6d582722007-08-06 15:21:45 +000060
paul718e3742002-12-13 20:15:29 +000061 while (pnt < end)
62 {
Paul Jakma6d582722007-08-06 15:21:45 +000063 if (pnt + sizeof (struct capability_mp_data) + 2 > end)
paul718e3742002-12-13 20:15:29 +000064 return;
Paul Jakma6d582722007-08-06 15:21:45 +000065
66 hdr = (struct capability_header *)pnt;
67 if (pnt + hdr->length + 2 > end)
paul718e3742002-12-13 20:15:29 +000068 return;
69
Paul Jakma6d582722007-08-06 15:21:45 +000070 memcpy (&mpc, pnt + 2, sizeof(struct capability_mp_data));
71
72 if (hdr->code == CAPABILITY_CODE_MP)
paul718e3742002-12-13 20:15:29 +000073 {
74 vty_out (vty, " Capability error for: Multi protocol ");
75
Paul Jakma6d582722007-08-06 15:21:45 +000076 switch (ntohs (mpc.afi))
paul718e3742002-12-13 20:15:29 +000077 {
78 case AFI_IP:
79 vty_out (vty, "AFI IPv4, ");
80 break;
81 case AFI_IP6:
82 vty_out (vty, "AFI IPv6, ");
83 break;
84 default:
Paul Jakma6d582722007-08-06 15:21:45 +000085 vty_out (vty, "AFI Unknown %d, ", ntohs (mpc.afi));
paul718e3742002-12-13 20:15:29 +000086 break;
87 }
Paul Jakma6d582722007-08-06 15:21:45 +000088 switch (mpc.safi)
paul718e3742002-12-13 20:15:29 +000089 {
90 case SAFI_UNICAST:
91 vty_out (vty, "SAFI Unicast");
92 break;
93 case SAFI_MULTICAST:
94 vty_out (vty, "SAFI Multicast");
95 break;
Denis Ovsienko42e6d742011-07-14 12:36:19 +040096 case SAFI_MPLS_LABELED_VPN:
97 vty_out (vty, "SAFI MPLS-labeled VPN");
paul718e3742002-12-13 20:15:29 +000098 break;
99 default:
Paul Jakma6d582722007-08-06 15:21:45 +0000100 vty_out (vty, "SAFI Unknown %d ", mpc.safi);
paul718e3742002-12-13 20:15:29 +0000101 break;
102 }
103 vty_out (vty, "%s", VTY_NEWLINE);
104 }
Paul Jakma6d582722007-08-06 15:21:45 +0000105 else if (hdr->code >= 128)
paul718e3742002-12-13 20:15:29 +0000106 vty_out (vty, " Capability error: vendor specific capability code %d",
Paul Jakma6d582722007-08-06 15:21:45 +0000107 hdr->code);
paul718e3742002-12-13 20:15:29 +0000108 else
109 vty_out (vty, " Capability error: unknown capability code %d",
Paul Jakma6d582722007-08-06 15:21:45 +0000110 hdr->code);
paul718e3742002-12-13 20:15:29 +0000111
Paul Jakma6d582722007-08-06 15:21:45 +0000112 pnt += hdr->length + 2;
paul718e3742002-12-13 20:15:29 +0000113 }
114}
115
Paul Jakma6d582722007-08-06 15:21:45 +0000116static void
117bgp_capability_mp_data (struct stream *s, struct capability_mp_data *mpc)
118{
119 mpc->afi = stream_getw (s);
120 mpc->reserved = stream_getc (s);
121 mpc->safi = stream_getc (s);
122}
123
124int
125bgp_afi_safi_valid_indices (afi_t afi, safi_t *safi)
126{
Paul Jakma6d582722007-08-06 15:21:45 +0000127 switch (afi)
128 {
129 case AFI_IP:
130#ifdef HAVE_IPV6
131 case AFI_IP6:
132#endif
133 switch (*safi)
134 {
Denis Ovsienko42e6d742011-07-14 12:36:19 +0400135 /* BGP MPLS-labeled VPN SAFI isn't contigious with others, remap */
136 case SAFI_MPLS_LABELED_VPN:
Paul Jakma6d582722007-08-06 15:21:45 +0000137 *safi = SAFI_MPLS_VPN;
138 case SAFI_UNICAST:
139 case SAFI_MULTICAST:
140 case SAFI_MPLS_VPN:
141 return 1;
142 }
143 }
144 zlog_debug ("unknown afi/safi (%u/%u)", afi, *safi);
145
146 return 0;
147}
148
paul718e3742002-12-13 20:15:29 +0000149/* Set negotiated capability value. */
paul94f2b392005-06-28 12:44:16 +0000150static int
Paul Jakma6d582722007-08-06 15:21:45 +0000151bgp_capability_mp (struct peer *peer, struct capability_header *hdr)
paul718e3742002-12-13 20:15:29 +0000152{
Paul Jakma6d582722007-08-06 15:21:45 +0000153 struct capability_mp_data mpc;
154 struct stream *s = BGP_INPUT (peer);
155
156 bgp_capability_mp_data (s, &mpc);
157
158 if (BGP_DEBUG (normal, NORMAL))
159 zlog_debug ("%s OPEN has MP_EXT CAP for afi/safi: %u/%u",
160 peer->host, mpc.afi, mpc.safi);
161
162 if (!bgp_afi_safi_valid_indices (mpc.afi, &mpc.safi))
163 return -1;
164
165 /* Now safi remapped, and afi/safi are valid array indices */
166 peer->afc_recv[mpc.afi][mpc.safi] = 1;
167
168 if (peer->afc[mpc.afi][mpc.safi])
Paul Jakmae08286b2007-09-18 12:11:26 +0000169 peer->afc_nego[mpc.afi][mpc.safi] = 1;
Paul Jakma6d582722007-08-06 15:21:45 +0000170 else
171 return -1;
paul718e3742002-12-13 20:15:29 +0000172
173 return 0;
174}
175
paul94f2b392005-06-28 12:44:16 +0000176static void
paul718e3742002-12-13 20:15:29 +0000177bgp_capability_orf_not_support (struct peer *peer, afi_t afi, safi_t safi,
178 u_char type, u_char mode)
179{
180 if (BGP_DEBUG (normal, NORMAL))
ajs8325cd72004-12-08 20:47:40 +0000181 zlog_debug ("%s Addr-family %d/%d has ORF type/mode %d/%d not supported",
paul718e3742002-12-13 20:15:29 +0000182 peer->host, afi, safi, type, mode);
183}
184
Stephen Hemminger8f5abac2009-05-15 10:16:34 -0700185static const struct message orf_type_str[] =
paul718e3742002-12-13 20:15:29 +0000186{
Paul Jakma6d582722007-08-06 15:21:45 +0000187 { ORF_TYPE_PREFIX, "Prefixlist" },
188 { ORF_TYPE_PREFIX_OLD, "Prefixlist (old)" },
189};
Stephen Hemminger8f5abac2009-05-15 10:16:34 -0700190static const int orf_type_str_max
191 = sizeof(orf_type_str)/sizeof(orf_type_str[0]);
Paul Jakma6d582722007-08-06 15:21:45 +0000192
Stephen Hemminger8f5abac2009-05-15 10:16:34 -0700193static const struct message orf_mode_str[] =
Paul Jakma6d582722007-08-06 15:21:45 +0000194{
195 { ORF_MODE_RECEIVE, "Receive" },
196 { ORF_MODE_SEND, "Send" },
197 { ORF_MODE_BOTH, "Both" },
198};
Stephen Hemminger8f5abac2009-05-15 10:16:34 -0700199static const int orf_mode_str_max
200 = sizeof(orf_mode_str)/sizeof(orf_mode_str[0]);
Paul Jakma6d582722007-08-06 15:21:45 +0000201
202static int
203bgp_capability_orf_entry (struct peer *peer, struct capability_header *hdr)
204{
205 struct stream *s = BGP_INPUT (peer);
206 struct capability_orf_entry entry;
207 afi_t afi;
208 safi_t safi;
paul718e3742002-12-13 20:15:29 +0000209 u_char type;
210 u_char mode;
211 u_int16_t sm_cap = 0; /* capability send-mode receive */
212 u_int16_t rm_cap = 0; /* capability receive-mode receive */
213 int i;
214
Paul Jakma6d582722007-08-06 15:21:45 +0000215 /* ORF Entry header */
216 bgp_capability_mp_data (s, &entry.mpc);
217 entry.num = stream_getc (s);
218 afi = entry.mpc.afi;
219 safi = entry.mpc.safi;
220
paul718e3742002-12-13 20:15:29 +0000221 if (BGP_DEBUG (normal, NORMAL))
Paul Jakma6d582722007-08-06 15:21:45 +0000222 zlog_debug ("%s ORF Cap entry for afi/safi: %u/%u",
223 peer->host, entry.mpc.afi, entry.mpc.safi);
paul718e3742002-12-13 20:15:29 +0000224
225 /* Check AFI and SAFI. */
Paul Jakma6d582722007-08-06 15:21:45 +0000226 if (!bgp_afi_safi_valid_indices (entry.mpc.afi, &safi))
paul718e3742002-12-13 20:15:29 +0000227 {
Paul Jakma6d582722007-08-06 15:21:45 +0000228 zlog_info ("%s Addr-family %d/%d not supported."
229 " Ignoring the ORF capability",
230 peer->host, entry.mpc.afi, entry.mpc.safi);
231 return 0;
232 }
233
234 /* validate number field */
235 if (sizeof (struct capability_orf_entry) + (entry.num * 2) > hdr->length)
236 {
237 zlog_info ("%s ORF Capability entry length error,"
238 " Cap length %u, num %u",
239 peer->host, hdr->length, entry.num);
240 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
paul718e3742002-12-13 20:15:29 +0000241 return -1;
242 }
243
Paul Jakma6d582722007-08-06 15:21:45 +0000244 for (i = 0 ; i < entry.num ; i++)
paul718e3742002-12-13 20:15:29 +0000245 {
Paul Jakma6d582722007-08-06 15:21:45 +0000246 type = stream_getc(s);
247 mode = stream_getc(s);
248
paul718e3742002-12-13 20:15:29 +0000249 /* ORF Mode error check */
Paul Jakma6d582722007-08-06 15:21:45 +0000250 switch (mode)
251 {
252 case ORF_MODE_BOTH:
253 case ORF_MODE_SEND:
254 case ORF_MODE_RECEIVE:
255 break;
256 default:
257 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
258 continue;
paul718e3742002-12-13 20:15:29 +0000259 }
Paul Jakma6d582722007-08-06 15:21:45 +0000260 /* ORF Type and afi/safi error checks */
261 /* capcode versus type */
262 switch (hdr->code)
263 {
264 case CAPABILITY_CODE_ORF:
265 switch (type)
266 {
267 case ORF_TYPE_PREFIX:
268 break;
269 default:
270 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
271 continue;
272 }
273 break;
274 case CAPABILITY_CODE_ORF_OLD:
275 switch (type)
276 {
277 case ORF_TYPE_PREFIX_OLD:
278 break;
279 default:
280 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
281 continue;
282 }
283 break;
284 default:
285 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
286 continue;
287 }
288
289 /* AFI vs SAFI */
290 if (!((afi == AFI_IP && safi == SAFI_UNICAST)
291 || (afi == AFI_IP && safi == SAFI_MULTICAST)
292 || (afi == AFI_IP6 && safi == SAFI_UNICAST)))
293 {
294 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
295 continue;
296 }
297
298 if (BGP_DEBUG (normal, NORMAL))
299 zlog_debug ("%s OPEN has %s ORF capability"
300 " as %s for afi/safi: %d/%d",
301 peer->host, LOOKUP (orf_type_str, type),
302 LOOKUP (orf_mode_str, mode),
303 entry.mpc.afi, safi);
paul718e3742002-12-13 20:15:29 +0000304
Paul Jakma6d582722007-08-06 15:21:45 +0000305 if (hdr->code == CAPABILITY_CODE_ORF)
paul718e3742002-12-13 20:15:29 +0000306 {
Paul Jakma6d582722007-08-06 15:21:45 +0000307 sm_cap = PEER_CAP_ORF_PREFIX_SM_RCV;
308 rm_cap = PEER_CAP_ORF_PREFIX_RM_RCV;
paul718e3742002-12-13 20:15:29 +0000309 }
Paul Jakma6d582722007-08-06 15:21:45 +0000310 else if (hdr->code == CAPABILITY_CODE_ORF_OLD)
paul718e3742002-12-13 20:15:29 +0000311 {
Paul Jakma6d582722007-08-06 15:21:45 +0000312 sm_cap = PEER_CAP_ORF_PREFIX_SM_OLD_RCV;
313 rm_cap = PEER_CAP_ORF_PREFIX_RM_OLD_RCV;
paul718e3742002-12-13 20:15:29 +0000314 }
315 else
316 {
317 bgp_capability_orf_not_support (peer, afi, safi, type, mode);
318 continue;
319 }
320
321 switch (mode)
322 {
323 case ORF_MODE_BOTH:
324 SET_FLAG (peer->af_cap[afi][safi], sm_cap);
325 SET_FLAG (peer->af_cap[afi][safi], rm_cap);
326 break;
327 case ORF_MODE_SEND:
328 SET_FLAG (peer->af_cap[afi][safi], sm_cap);
329 break;
330 case ORF_MODE_RECEIVE:
331 SET_FLAG (peer->af_cap[afi][safi], rm_cap);
332 break;
333 }
334 }
335 return 0;
336}
337
paul94f2b392005-06-28 12:44:16 +0000338static int
Paul Jakma6d582722007-08-06 15:21:45 +0000339bgp_capability_orf (struct peer *peer, struct capability_header *hdr)
340{
341 struct stream *s = BGP_INPUT (peer);
342 size_t end = stream_get_getp (s) + hdr->length;
343
344 assert (stream_get_getp(s) + sizeof(struct capability_orf_entry) <= end);
345
346 /* We must have at least one ORF entry, as the caller has already done
347 * minimum length validation for the capability code - for ORF there must
348 * at least one ORF entry (header and unknown number of pairs of bytes).
349 */
350 do
351 {
352 if (bgp_capability_orf_entry (peer, hdr) == -1)
353 return -1;
354 }
355 while (stream_get_getp(s) + sizeof(struct capability_orf_entry) < end);
356
357 return 0;
358}
359
360static int
361bgp_capability_restart (struct peer *peer, struct capability_header *caphdr)
362{
363 struct stream *s = BGP_INPUT (peer);
364 u_int16_t restart_flag_time;
365 int restart_bit = 0;
366 size_t end = stream_get_getp (s) + caphdr->length;
367
368 SET_FLAG (peer->cap, PEER_CAP_RESTART_RCV);
369 restart_flag_time = stream_getw(s);
370 if (CHECK_FLAG (restart_flag_time, RESTART_R_BIT))
371 restart_bit = 1;
372 UNSET_FLAG (restart_flag_time, 0xF000);
373 peer->v_gr_restart = restart_flag_time;
374
375 if (BGP_DEBUG (normal, NORMAL))
376 {
377 zlog_debug ("%s OPEN has Graceful Restart capability", peer->host);
378 zlog_debug ("%s Peer has%srestarted. Restart Time : %d",
379 peer->host, restart_bit ? " " : " not ",
380 peer->v_gr_restart);
381 }
382
Peter Pentchev21cc7692011-09-12 16:30:31 +0400383 while (stream_get_getp (s) + 4 <= end)
Paul Jakma6d582722007-08-06 15:21:45 +0000384 {
385 afi_t afi = stream_getw (s);
386 safi_t safi = stream_getc (s);
387 u_char flag = stream_getc (s);
388
389 if (!bgp_afi_safi_valid_indices (afi, &safi))
390 {
391 if (BGP_DEBUG (normal, NORMAL))
392 zlog_debug ("%s Addr-family %d/%d(afi/safi) not supported."
393 " Ignore the Graceful Restart capability",
394 peer->host, afi, safi);
395 }
396 else if (!peer->afc[afi][safi])
397 {
398 if (BGP_DEBUG (normal, NORMAL))
399 zlog_debug ("%s Addr-family %d/%d(afi/safi) not enabled."
400 " Ignore the Graceful Restart capability",
401 peer->host, afi, safi);
402 }
403 else
404 {
405 if (BGP_DEBUG (normal, NORMAL))
406 zlog_debug ("%s Address family %s is%spreserved", peer->host,
407 afi_safi_print (afi, safi),
408 CHECK_FLAG (peer->af_cap[afi][safi],
409 PEER_CAP_RESTART_AF_PRESERVE_RCV)
410 ? " " : " not ");
411
412 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV);
413 if (CHECK_FLAG (flag, RESTART_F_BIT))
414 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV);
415
416 }
417 }
418 return 0;
419}
420
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000421static as_t
422bgp_capability_as4 (struct peer *peer, struct capability_header *hdr)
423{
Paul Jakma58617392012-01-09 20:59:26 +0000424 SET_FLAG (peer->cap, PEER_CAP_AS4_RCV);
425
426 if (hdr->length != CAPABILITY_CODE_AS4_LEN)
427 {
428 zlog_err ("%s AS4 capability has incorrect data length %d",
429 peer->host, hdr->length);
430 return 0;
431 }
432
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000433 as_t as4 = stream_getl (BGP_INPUT(peer));
434
435 if (BGP_DEBUG (as4, AS4))
436 zlog_debug ("%s [AS4] about to set cap PEER_CAP_AS4_RCV, got as4 %u",
437 peer->host, as4);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000438 return as4;
439}
440
Stephen Hemmingerfc52f952009-05-15 09:48:55 -0700441static const struct message capcode_str[] =
Paul Jakma6d582722007-08-06 15:21:45 +0000442{
Paul Jakma6d582722007-08-06 15:21:45 +0000443 { CAPABILITY_CODE_MP, "MultiProtocol Extensions" },
444 { CAPABILITY_CODE_REFRESH, "Route Refresh" },
445 { CAPABILITY_CODE_ORF, "Cooperative Route Filtering" },
446 { CAPABILITY_CODE_RESTART, "Graceful Restart" },
447 { CAPABILITY_CODE_AS4, "4-octet AS number" },
448 { CAPABILITY_CODE_DYNAMIC, "Dynamic" },
449 { CAPABILITY_CODE_REFRESH_OLD, "Route Refresh (Old)" },
450 { CAPABILITY_CODE_ORF_OLD, "ORF (Old)" },
451};
Stephen Hemmingerfc52f952009-05-15 09:48:55 -0700452static const int capcode_str_max = sizeof(capcode_str)/sizeof(capcode_str[0]);
Paul Jakma6d582722007-08-06 15:21:45 +0000453
454/* Minimum sizes for length field of each cap (so not inc. the header) */
Stephen Hemmingerfc52f952009-05-15 09:48:55 -0700455static const size_t cap_minsizes[] =
Paul Jakma6d582722007-08-06 15:21:45 +0000456{
457 [CAPABILITY_CODE_MP] = sizeof (struct capability_mp_data),
458 [CAPABILITY_CODE_REFRESH] = CAPABILITY_CODE_REFRESH_LEN,
459 [CAPABILITY_CODE_ORF] = sizeof (struct capability_orf_entry),
Paul Jakma370b64a2007-12-22 16:49:52 +0000460 [CAPABILITY_CODE_RESTART] = sizeof (struct capability_gr),
Paul Jakma6d582722007-08-06 15:21:45 +0000461 [CAPABILITY_CODE_AS4] = CAPABILITY_CODE_AS4_LEN,
462 [CAPABILITY_CODE_DYNAMIC] = CAPABILITY_CODE_DYNAMIC_LEN,
463 [CAPABILITY_CODE_REFRESH_OLD] = CAPABILITY_CODE_REFRESH_LEN,
464 [CAPABILITY_CODE_ORF_OLD] = sizeof (struct capability_orf_entry),
465};
466
467/* Parse given capability.
468 * XXX: This is reading into a stream, but not using stream API
469 */
470static int
471bgp_capability_parse (struct peer *peer, size_t length, u_char **error)
paul718e3742002-12-13 20:15:29 +0000472{
473 int ret;
Paul Jakma6d582722007-08-06 15:21:45 +0000474 struct stream *s = BGP_INPUT (peer);
475 size_t end = stream_get_getp (s) + length;
476
477 assert (STREAM_READABLE (s) >= length);
478
479 while (stream_get_getp (s) < end)
paul718e3742002-12-13 20:15:29 +0000480 {
Paul Jakma6d582722007-08-06 15:21:45 +0000481 size_t start;
482 u_char *sp = stream_pnt (s);
483 struct capability_header caphdr;
484
paul718e3742002-12-13 20:15:29 +0000485 /* We need at least capability code and capability length. */
Paul Jakma6d582722007-08-06 15:21:45 +0000486 if (stream_get_getp(s) + 2 > end)
paul718e3742002-12-13 20:15:29 +0000487 {
Paul Jakma6d582722007-08-06 15:21:45 +0000488 zlog_info ("%s Capability length error (< header)", peer->host);
paul718e3742002-12-13 20:15:29 +0000489 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
490 return -1;
491 }
Paul Jakma6d582722007-08-06 15:21:45 +0000492
493 caphdr.code = stream_getc (s);
494 caphdr.length = stream_getc (s);
495 start = stream_get_getp (s);
496
497 /* Capability length check sanity check. */
498 if (start + caphdr.length > end)
paul718e3742002-12-13 20:15:29 +0000499 {
Paul Jakma6d582722007-08-06 15:21:45 +0000500 zlog_info ("%s Capability length error (< length)", peer->host);
paul718e3742002-12-13 20:15:29 +0000501 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
502 return -1;
503 }
Paul Jakma6d582722007-08-06 15:21:45 +0000504
505 if (BGP_DEBUG (normal, NORMAL))
506 zlog_debug ("%s OPEN has %s capability (%u), length %u",
507 peer->host,
508 LOOKUP (capcode_str, caphdr.code),
509 caphdr.code, caphdr.length);
510
511 /* Length sanity check, type-specific, for known capabilities */
512 switch (caphdr.code)
513 {
514 case CAPABILITY_CODE_MP:
515 case CAPABILITY_CODE_REFRESH:
516 case CAPABILITY_CODE_REFRESH_OLD:
517 case CAPABILITY_CODE_ORF:
518 case CAPABILITY_CODE_ORF_OLD:
519 case CAPABILITY_CODE_RESTART:
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000520 case CAPABILITY_CODE_AS4:
Paul Jakma6d582722007-08-06 15:21:45 +0000521 case CAPABILITY_CODE_DYNAMIC:
522 /* Check length. */
523 if (caphdr.length < cap_minsizes[caphdr.code])
524 {
525 zlog_info ("%s %s Capability length error: got %u,"
526 " expected at least %u",
527 peer->host,
528 LOOKUP (capcode_str, caphdr.code),
Stephen Hemmingerfc52f952009-05-15 09:48:55 -0700529 caphdr.length,
530 (unsigned) cap_minsizes[caphdr.code]);
Paul Jakma6d582722007-08-06 15:21:45 +0000531 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
532 return -1;
533 }
534 /* we deliberately ignore unknown codes, see below */
535 default:
536 break;
537 }
538
539 switch (caphdr.code)
540 {
541 case CAPABILITY_CODE_MP:
542 {
543 /* Ignore capability when override-capability is set. */
544 if (! CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY))
545 {
546 /* Set negotiated value. */
547 ret = bgp_capability_mp (peer, &caphdr);
paul718e3742002-12-13 20:15:29 +0000548
Paul Jakma6d582722007-08-06 15:21:45 +0000549 /* Unsupported Capability. */
550 if (ret < 0)
551 {
552 /* Store return data. */
553 memcpy (*error, sp, caphdr.length + 2);
554 *error += caphdr.length + 2;
555 }
556 }
557 }
558 break;
559 case CAPABILITY_CODE_REFRESH:
560 case CAPABILITY_CODE_REFRESH_OLD:
561 {
562 /* BGP refresh capability */
563 if (caphdr.code == CAPABILITY_CODE_REFRESH_OLD)
564 SET_FLAG (peer->cap, PEER_CAP_REFRESH_OLD_RCV);
565 else
566 SET_FLAG (peer->cap, PEER_CAP_REFRESH_NEW_RCV);
567 }
568 break;
569 case CAPABILITY_CODE_ORF:
570 case CAPABILITY_CODE_ORF_OLD:
571 if (bgp_capability_orf (peer, &caphdr))
572 return -1;
573 break;
574 case CAPABILITY_CODE_RESTART:
575 if (bgp_capability_restart (peer, &caphdr))
576 return -1;
577 break;
578 case CAPABILITY_CODE_DYNAMIC:
579 SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_RCV);
580 break;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000581 case CAPABILITY_CODE_AS4:
582 /* Already handled as a special-case parsing of the capabilities
583 * at the beginning of OPEN processing. So we care not a jot
584 * for the value really, only error case.
585 */
586 if (!bgp_capability_as4 (peer, &caphdr))
587 return -1;
588 break;
Paul Jakma6d582722007-08-06 15:21:45 +0000589 default:
590 if (caphdr.code > 128)
591 {
592 /* We don't send Notification for unknown vendor specific
593 capabilities. It seems reasonable for now... */
594 zlog_warn ("%s Vendor specific capability %d",
595 peer->host, caphdr.code);
596 }
597 else
598 {
599 zlog_warn ("%s unrecognized capability code: %d - ignored",
600 peer->host, caphdr.code);
601 memcpy (*error, sp, caphdr.length + 2);
602 *error += caphdr.length + 2;
603 }
604 }
605 if (stream_get_getp(s) != (start + caphdr.length))
606 {
607 if (stream_get_getp(s) > (start + caphdr.length))
608 zlog_warn ("%s Cap-parser for %s read past cap-length, %u!",
609 peer->host, LOOKUP (capcode_str, caphdr.code),
610 caphdr.length);
611 stream_set_getp (s, start + caphdr.length);
612 }
paul718e3742002-12-13 20:15:29 +0000613 }
614 return 0;
615}
616
paul94f2b392005-06-28 12:44:16 +0000617static int
Paul Jakma6d582722007-08-06 15:21:45 +0000618bgp_auth_parse (struct peer *peer, size_t length)
paul718e3742002-12-13 20:15:29 +0000619{
620 bgp_notify_send (peer,
621 BGP_NOTIFY_OPEN_ERR,
622 BGP_NOTIFY_OPEN_AUTH_FAILURE);
623 return -1;
624}
625
paul94f2b392005-06-28 12:44:16 +0000626static int
paul718e3742002-12-13 20:15:29 +0000627strict_capability_same (struct peer *peer)
628{
629 int i, j;
630
631 for (i = AFI_IP; i < AFI_MAX; i++)
632 for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
633 if (peer->afc[i][j] != peer->afc_nego[i][j])
634 return 0;
635 return 1;
636}
637
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000638/* peek into option, stores ASN to *as4 if the AS4 capability was found.
639 * Returns 0 if no as4 found, as4cap value otherwise.
640 */
641as_t
642peek_for_as4_capability (struct peer *peer, u_char length)
643{
644 struct stream *s = BGP_INPUT (peer);
645 size_t orig_getp = stream_get_getp (s);
646 size_t end = orig_getp + length;
647 as_t as4 = 0;
648
649 /* The full capability parser will better flag the error.. */
650 if (STREAM_READABLE(s) < length)
651 return 0;
652
653 if (BGP_DEBUG (as4, AS4))
654 zlog_info ("%s [AS4] rcv OPEN w/ OPTION parameter len: %u,"
655 " peeking for as4",
656 peer->host, length);
657 /* the error cases we DONT handle, we ONLY try to read as4 out of
658 * correctly formatted options.
659 */
660 while (stream_get_getp(s) < end)
661 {
662 u_char opt_type;
663 u_char opt_length;
664
665 /* Check the length. */
666 if (stream_get_getp (s) + 2 > end)
667 goto end;
668
669 /* Fetch option type and length. */
670 opt_type = stream_getc (s);
671 opt_length = stream_getc (s);
672
673 /* Option length check. */
674 if (stream_get_getp (s) + opt_length > end)
675 goto end;
676
677 if (opt_type == BGP_OPEN_OPT_CAP)
678 {
679 unsigned long capd_start = stream_get_getp (s);
680 unsigned long capd_end = capd_start + opt_length;
681
682 assert (capd_end <= end);
683
684 while (stream_get_getp (s) < capd_end)
685 {
686 struct capability_header hdr;
687
688 if (stream_get_getp (s) + 2 > capd_end)
689 goto end;
690
691 hdr.code = stream_getc (s);
692 hdr.length = stream_getc (s);
693
694 if ((stream_get_getp(s) + hdr.length) > capd_end)
695 goto end;
696
697 if (hdr.code == CAPABILITY_CODE_AS4)
698 {
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000699 if (BGP_DEBUG (as4, AS4))
700 zlog_info ("[AS4] found AS4 capability, about to parse");
701 as4 = bgp_capability_as4 (peer, &hdr);
702
703 goto end;
704 }
705 stream_forward_getp (s, hdr.length);
706 }
707 }
708 }
709
710end:
711 stream_set_getp (s, orig_getp);
712 return as4;
713}
714
paul718e3742002-12-13 20:15:29 +0000715/* Parse open option */
716int
717bgp_open_option_parse (struct peer *peer, u_char length, int *capability)
718{
719 int ret;
paul718e3742002-12-13 20:15:29 +0000720 u_char *error;
721 u_char error_data[BGP_MAX_PACKET_SIZE];
Paul Jakma6d582722007-08-06 15:21:45 +0000722 struct stream *s = BGP_INPUT(peer);
723 size_t end = stream_get_getp (s) + length;
paul718e3742002-12-13 20:15:29 +0000724
725 ret = 0;
paul718e3742002-12-13 20:15:29 +0000726 error = error_data;
727
728 if (BGP_DEBUG (normal, NORMAL))
ajs8325cd72004-12-08 20:47:40 +0000729 zlog_debug ("%s rcv OPEN w/ OPTION parameter len: %u",
paul718e3742002-12-13 20:15:29 +0000730 peer->host, length);
731
Paul Jakma6d582722007-08-06 15:21:45 +0000732 while (stream_get_getp(s) < end)
paul718e3742002-12-13 20:15:29 +0000733 {
Paul Jakma6d582722007-08-06 15:21:45 +0000734 u_char opt_type;
735 u_char opt_length;
736
737 /* Must have at least an OPEN option header */
738 if (STREAM_READABLE(s) < 2)
paul718e3742002-12-13 20:15:29 +0000739 {
740 zlog_info ("%s Option length error", peer->host);
741 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
742 return -1;
743 }
744
745 /* Fetch option type and length. */
Paul Jakma6d582722007-08-06 15:21:45 +0000746 opt_type = stream_getc (s);
747 opt_length = stream_getc (s);
paul718e3742002-12-13 20:15:29 +0000748
749 /* Option length check. */
Paul Jakma6d582722007-08-06 15:21:45 +0000750 if (STREAM_READABLE (s) < opt_length)
paul718e3742002-12-13 20:15:29 +0000751 {
752 zlog_info ("%s Option length error", peer->host);
753 bgp_notify_send (peer, BGP_NOTIFY_CEASE, 0);
754 return -1;
755 }
756
757 if (BGP_DEBUG (normal, NORMAL))
ajs8325cd72004-12-08 20:47:40 +0000758 zlog_debug ("%s rcvd OPEN w/ optional parameter type %u (%s) len %u",
paul718e3742002-12-13 20:15:29 +0000759 peer->host, opt_type,
760 opt_type == BGP_OPEN_OPT_AUTH ? "Authentication" :
761 opt_type == BGP_OPEN_OPT_CAP ? "Capability" : "Unknown",
762 opt_length);
763
764 switch (opt_type)
765 {
766 case BGP_OPEN_OPT_AUTH:
Paul Jakma6d582722007-08-06 15:21:45 +0000767 ret = bgp_auth_parse (peer, opt_length);
paul718e3742002-12-13 20:15:29 +0000768 break;
769 case BGP_OPEN_OPT_CAP:
Paul Jakma6d582722007-08-06 15:21:45 +0000770 ret = bgp_capability_parse (peer, opt_length, &error);
paul718e3742002-12-13 20:15:29 +0000771 *capability = 1;
772 break;
773 default:
774 bgp_notify_send (peer,
775 BGP_NOTIFY_OPEN_ERR,
776 BGP_NOTIFY_OPEN_UNSUP_PARAM);
777 ret = -1;
778 break;
779 }
780
781 /* Parse error. To accumulate all unsupported capability codes,
782 bgp_capability_parse does not return -1 when encounter
783 unsupported capability code. To detect that, please check
784 error and erro_data pointer, like below. */
785 if (ret < 0)
786 return -1;
paul718e3742002-12-13 20:15:29 +0000787 }
788
789 /* All OPEN option is parsed. Check capability when strict compare
790 flag is enabled.*/
791 if (CHECK_FLAG (peer->flags, PEER_FLAG_STRICT_CAP_MATCH))
792 {
793 /* If Unsupported Capability exists. */
794 if (error != error_data)
795 {
796 bgp_notify_send_with_data (peer,
797 BGP_NOTIFY_OPEN_ERR,
798 BGP_NOTIFY_OPEN_UNSUP_CAPBL,
799 error_data, error - error_data);
800 return -1;
801 }
802
803 /* Check local capability does not negotiated with remote
804 peer. */
805 if (! strict_capability_same (peer))
806 {
807 bgp_notify_send (peer,
808 BGP_NOTIFY_OPEN_ERR,
809 BGP_NOTIFY_OPEN_UNSUP_CAPBL);
810 return -1;
811 }
812 }
813
814 /* Check there is no common capability send Unsupported Capability
815 error. */
816 if (*capability && ! CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY))
817 {
818 if (! peer->afc_nego[AFI_IP][SAFI_UNICAST]
819 && ! peer->afc_nego[AFI_IP][SAFI_MULTICAST]
820 && ! peer->afc_nego[AFI_IP][SAFI_MPLS_VPN]
821 && ! peer->afc_nego[AFI_IP6][SAFI_UNICAST]
822 && ! peer->afc_nego[AFI_IP6][SAFI_MULTICAST])
823 {
824 plog_err (peer->log, "%s [Error] No common capability", peer->host);
825
826 if (error != error_data)
827
828 bgp_notify_send_with_data (peer,
829 BGP_NOTIFY_OPEN_ERR,
830 BGP_NOTIFY_OPEN_UNSUP_CAPBL,
831 error_data, error - error_data);
832 else
833 bgp_notify_send (peer,
834 BGP_NOTIFY_OPEN_ERR,
835 BGP_NOTIFY_OPEN_UNSUP_CAPBL);
836 return -1;
837 }
838 }
839 return 0;
840}
841
paul94f2b392005-06-28 12:44:16 +0000842static void
paul718e3742002-12-13 20:15:29 +0000843bgp_open_capability_orf (struct stream *s, struct peer *peer,
844 afi_t afi, safi_t safi, u_char code)
845{
846 u_char cap_len;
847 u_char orf_len;
848 unsigned long capp;
849 unsigned long orfp;
850 unsigned long numberp;
851 int number_of_orfs = 0;
852
853 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +0400854 safi = SAFI_MPLS_LABELED_VPN;
paul718e3742002-12-13 20:15:29 +0000855
856 stream_putc (s, BGP_OPEN_OPT_CAP);
paul9985f832005-02-09 15:51:56 +0000857 capp = stream_get_endp (s); /* Set Capability Len Pointer */
paul718e3742002-12-13 20:15:29 +0000858 stream_putc (s, 0); /* Capability Length */
859 stream_putc (s, code); /* Capability Code */
paul9985f832005-02-09 15:51:56 +0000860 orfp = stream_get_endp (s); /* Set ORF Len Pointer */
paul718e3742002-12-13 20:15:29 +0000861 stream_putc (s, 0); /* ORF Length */
862 stream_putw (s, afi);
863 stream_putc (s, 0);
864 stream_putc (s, safi);
paul9985f832005-02-09 15:51:56 +0000865 numberp = stream_get_endp (s); /* Set Number Pointer */
paul718e3742002-12-13 20:15:29 +0000866 stream_putc (s, 0); /* Number of ORFs */
867
868 /* Address Prefix ORF */
869 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM)
870 || CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_RM))
871 {
872 stream_putc (s, (code == CAPABILITY_CODE_ORF ?
873 ORF_TYPE_PREFIX : ORF_TYPE_PREFIX_OLD));
874
875 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM)
876 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_RM))
877 {
878 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV);
879 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV);
880 stream_putc (s, ORF_MODE_BOTH);
881 }
882 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM))
883 {
884 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV);
885 stream_putc (s, ORF_MODE_SEND);
886 }
887 else
888 {
889 SET_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV);
890 stream_putc (s, ORF_MODE_RECEIVE);
891 }
892 number_of_orfs++;
893 }
894
895 /* Total Number of ORFs. */
896 stream_putc_at (s, numberp, number_of_orfs);
897
898 /* Total ORF Len. */
paul9985f832005-02-09 15:51:56 +0000899 orf_len = stream_get_endp (s) - orfp - 1;
paul718e3742002-12-13 20:15:29 +0000900 stream_putc_at (s, orfp, orf_len);
901
902 /* Total Capability Len. */
paul9985f832005-02-09 15:51:56 +0000903 cap_len = stream_get_endp (s) - capp - 1;
paul718e3742002-12-13 20:15:29 +0000904 stream_putc_at (s, capp, cap_len);
905}
906
907/* Fill in capability open option to the packet. */
908void
909bgp_open_capability (struct stream *s, struct peer *peer)
910{
911 u_char len;
912 unsigned long cp;
913 afi_t afi;
914 safi_t safi;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000915 as_t local_as;
paul718e3742002-12-13 20:15:29 +0000916
917 /* Remember current pointer for Opt Parm Len. */
paul9985f832005-02-09 15:51:56 +0000918 cp = stream_get_endp (s);
paul718e3742002-12-13 20:15:29 +0000919
920 /* Opt Parm Len. */
921 stream_putc (s, 0);
922
923 /* Do not send capability. */
924 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_CAPABILITY_OPEN)
925 || CHECK_FLAG (peer->flags, PEER_FLAG_DONT_CAPABILITY))
926 return;
927
paul718e3742002-12-13 20:15:29 +0000928 /* IPv4 unicast. */
929 if (peer->afc[AFI_IP][SAFI_UNICAST])
930 {
931 peer->afc_adv[AFI_IP][SAFI_UNICAST] = 1;
932 stream_putc (s, BGP_OPEN_OPT_CAP);
933 stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
934 stream_putc (s, CAPABILITY_CODE_MP);
935 stream_putc (s, CAPABILITY_CODE_MP_LEN);
936 stream_putw (s, AFI_IP);
937 stream_putc (s, 0);
938 stream_putc (s, SAFI_UNICAST);
939 }
940 /* IPv4 multicast. */
941 if (peer->afc[AFI_IP][SAFI_MULTICAST])
942 {
943 peer->afc_adv[AFI_IP][SAFI_MULTICAST] = 1;
944 stream_putc (s, BGP_OPEN_OPT_CAP);
945 stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
946 stream_putc (s, CAPABILITY_CODE_MP);
947 stream_putc (s, CAPABILITY_CODE_MP_LEN);
948 stream_putw (s, AFI_IP);
949 stream_putc (s, 0);
950 stream_putc (s, SAFI_MULTICAST);
951 }
952 /* IPv4 VPN */
953 if (peer->afc[AFI_IP][SAFI_MPLS_VPN])
954 {
955 peer->afc_adv[AFI_IP][SAFI_MPLS_VPN] = 1;
956 stream_putc (s, BGP_OPEN_OPT_CAP);
957 stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
958 stream_putc (s, CAPABILITY_CODE_MP);
959 stream_putc (s, CAPABILITY_CODE_MP_LEN);
960 stream_putw (s, AFI_IP);
961 stream_putc (s, 0);
Denis Ovsienko42e6d742011-07-14 12:36:19 +0400962 stream_putc (s, SAFI_MPLS_LABELED_VPN);
paul718e3742002-12-13 20:15:29 +0000963 }
964#ifdef HAVE_IPV6
965 /* IPv6 unicast. */
966 if (peer->afc[AFI_IP6][SAFI_UNICAST])
967 {
968 peer->afc_adv[AFI_IP6][SAFI_UNICAST] = 1;
969 stream_putc (s, BGP_OPEN_OPT_CAP);
970 stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
971 stream_putc (s, CAPABILITY_CODE_MP);
972 stream_putc (s, CAPABILITY_CODE_MP_LEN);
973 stream_putw (s, AFI_IP6);
974 stream_putc (s, 0);
975 stream_putc (s, SAFI_UNICAST);
976 }
977 /* IPv6 multicast. */
978 if (peer->afc[AFI_IP6][SAFI_MULTICAST])
979 {
980 peer->afc_adv[AFI_IP6][SAFI_MULTICAST] = 1;
981 stream_putc (s, BGP_OPEN_OPT_CAP);
982 stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
983 stream_putc (s, CAPABILITY_CODE_MP);
984 stream_putc (s, CAPABILITY_CODE_MP_LEN);
985 stream_putw (s, AFI_IP6);
986 stream_putc (s, 0);
987 stream_putc (s, SAFI_MULTICAST);
988 }
989#endif /* HAVE_IPV6 */
990
991 /* Route refresh. */
hassoc9502432005-02-01 22:01:48 +0000992 SET_FLAG (peer->cap, PEER_CAP_REFRESH_ADV);
993 stream_putc (s, BGP_OPEN_OPT_CAP);
994 stream_putc (s, CAPABILITY_CODE_REFRESH_LEN + 2);
995 stream_putc (s, CAPABILITY_CODE_REFRESH_OLD);
996 stream_putc (s, CAPABILITY_CODE_REFRESH_LEN);
997 stream_putc (s, BGP_OPEN_OPT_CAP);
998 stream_putc (s, CAPABILITY_CODE_REFRESH_LEN + 2);
999 stream_putc (s, CAPABILITY_CODE_REFRESH);
1000 stream_putc (s, CAPABILITY_CODE_REFRESH_LEN);
paul718e3742002-12-13 20:15:29 +00001001
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001002 /* AS4 */
1003 SET_FLAG (peer->cap, PEER_CAP_AS4_ADV);
1004 stream_putc (s, BGP_OPEN_OPT_CAP);
1005 stream_putc (s, CAPABILITY_CODE_AS4_LEN + 2);
1006 stream_putc (s, CAPABILITY_CODE_AS4);
1007 stream_putc (s, CAPABILITY_CODE_AS4_LEN);
1008 if ( peer->change_local_as )
1009 local_as = peer->change_local_as;
1010 else
1011 local_as = peer->local_as;
1012 stream_putl (s, local_as );
1013
paul718e3742002-12-13 20:15:29 +00001014 /* ORF capability. */
1015 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
1016 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
1017 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM)
1018 || CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_RM))
1019 {
1020 bgp_open_capability_orf (s, peer, afi, safi, CAPABILITY_CODE_ORF_OLD);
1021 bgp_open_capability_orf (s, peer, afi, safi, CAPABILITY_CODE_ORF);
1022 }
1023
1024 /* Dynamic capability. */
1025 if (CHECK_FLAG (peer->flags, PEER_FLAG_DYNAMIC_CAPABILITY))
1026 {
1027 SET_FLAG (peer->cap, PEER_CAP_DYNAMIC_ADV);
1028 stream_putc (s, BGP_OPEN_OPT_CAP);
1029 stream_putc (s, CAPABILITY_CODE_DYNAMIC_LEN + 2);
1030 stream_putc (s, CAPABILITY_CODE_DYNAMIC);
1031 stream_putc (s, CAPABILITY_CODE_DYNAMIC_LEN);
1032 }
1033
hasso538621f2004-05-21 09:31:30 +00001034 /* Graceful restart capability */
1035 if (bgp_flag_check (peer->bgp, BGP_FLAG_GRACEFUL_RESTART))
1036 {
1037 SET_FLAG (peer->cap, PEER_CAP_RESTART_ADV);
1038 stream_putc (s, BGP_OPEN_OPT_CAP);
1039 stream_putc (s, CAPABILITY_CODE_RESTART_LEN + 2);
1040 stream_putc (s, CAPABILITY_CODE_RESTART);
1041 stream_putc (s, CAPABILITY_CODE_RESTART_LEN);
1042 stream_putw (s, peer->bgp->restart_time);
1043 }
1044
paul718e3742002-12-13 20:15:29 +00001045 /* Total Opt Parm Len. */
paul9985f832005-02-09 15:51:56 +00001046 len = stream_get_endp (s) - cp - 1;
paul718e3742002-12-13 20:15:29 +00001047 stream_putc_at (s, cp, len);
1048}