1 /* BGP open message handling
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
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
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"
37 #include "bgpd/bgp_aspath.h"
38 #include "bgpd/bgp_vty.h"
40 /* 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.
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. */
51 bgp_capability_vty_out (struct vty
*vty
, struct peer
*peer
)
55 struct capability_mp_data mpc
;
56 struct capability_header
*hdr
;
58 pnt
= peer
->notify
.data
;
59 end
= pnt
+ peer
->notify
.length
;
63 if (pnt
+ sizeof (struct capability_mp_data
) + 2 > end
)
66 hdr
= (struct capability_header
*)pnt
;
67 if (pnt
+ hdr
->length
+ 2 > end
)
70 memcpy (&mpc
, pnt
+ 2, sizeof(struct capability_mp_data
));
72 if (hdr
->code
== CAPABILITY_CODE_MP
)
74 vty_out (vty
, " Capability error for: Multi protocol ");
76 switch (ntohs (mpc
.afi
))
79 vty_out (vty
, "AFI IPv4, ");
82 vty_out (vty
, "AFI IPv6, ");
85 vty_out (vty
, "AFI Unknown %d, ", ntohs (mpc
.afi
));
91 vty_out (vty
, "SAFI Unicast");
94 vty_out (vty
, "SAFI Multicast");
96 case SAFI_UNICAST_MULTICAST
:
97 vty_out (vty
, "SAFI Unicast Multicast");
100 vty_out (vty
, "SAFI MPLS-VPN");
103 vty_out (vty
, "SAFI Unknown %d ", mpc
.safi
);
106 vty_out (vty
, "%s", VTY_NEWLINE
);
108 else if (hdr
->code
>= 128)
109 vty_out (vty
, " Capability error: vendor specific capability code %d",
112 vty_out (vty
, " Capability error: unknown capability code %d",
115 pnt
+= hdr
->length
+ 2;
120 bgp_capability_mp_data (struct stream
*s
, struct capability_mp_data
*mpc
)
122 mpc
->afi
= stream_getw (s
);
123 mpc
->reserved
= stream_getc (s
);
124 mpc
->safi
= stream_getc (s
);
128 bgp_afi_safi_valid_indices (afi_t afi
, safi_t
*safi
)
130 /* VPNvX are AFI specific */
131 if ((afi
== AFI_IP6
&& *safi
== BGP_SAFI_VPNV4
)
132 || (afi
== AFI_IP
&& *safi
== BGP_SAFI_VPNV6
))
134 zlog_warn ("Invalid afi/safi combination (%u/%u)", afi
, *safi
);
146 /* BGP VPNvX SAFI isn't contigious with others, remap */
149 *safi
= SAFI_MPLS_VPN
;
156 zlog_debug ("unknown afi/safi (%u/%u)", afi
, *safi
);
161 /* Set negotiated capability value. */
163 bgp_capability_mp (struct peer
*peer
, struct capability_header
*hdr
)
165 struct capability_mp_data mpc
;
166 struct stream
*s
= BGP_INPUT (peer
);
168 bgp_capability_mp_data (s
, &mpc
);
170 if (BGP_DEBUG (normal
, NORMAL
))
171 zlog_debug ("%s OPEN has MP_EXT CAP for afi/safi: %u/%u",
172 peer
->host
, mpc
.afi
, mpc
.safi
);
174 if (!bgp_afi_safi_valid_indices (mpc
.afi
, &mpc
.safi
))
177 /* Now safi remapped, and afi/safi are valid array indices */
178 peer
->afc_recv
[mpc
.afi
][mpc
.safi
] = 1;
180 if (peer
->afc
[mpc
.afi
][mpc
.safi
])
181 peer
->afc_nego
[mpc
.afi
][mpc
.safi
] = 1;
189 bgp_capability_orf_not_support (struct peer
*peer
, afi_t afi
, safi_t safi
,
190 u_char type
, u_char mode
)
192 if (BGP_DEBUG (normal
, NORMAL
))
193 zlog_debug ("%s Addr-family %d/%d has ORF type/mode %d/%d not supported",
194 peer
->host
, afi
, safi
, type
, mode
);
197 static const struct message orf_type_str
[] =
199 { ORF_TYPE_PREFIX
, "Prefixlist" },
200 { ORF_TYPE_PREFIX_OLD
, "Prefixlist (old)" },
202 static const int orf_type_str_max
203 = sizeof(orf_type_str
)/sizeof(orf_type_str
[0]);
205 static const struct message orf_mode_str
[] =
207 { ORF_MODE_RECEIVE
, "Receive" },
208 { ORF_MODE_SEND
, "Send" },
209 { ORF_MODE_BOTH
, "Both" },
211 static const int orf_mode_str_max
212 = sizeof(orf_mode_str
)/sizeof(orf_mode_str
[0]);
215 bgp_capability_orf_entry (struct peer
*peer
, struct capability_header
*hdr
)
217 struct stream
*s
= BGP_INPUT (peer
);
218 struct capability_orf_entry entry
;
223 u_int16_t sm_cap
= 0; /* capability send-mode receive */
224 u_int16_t rm_cap
= 0; /* capability receive-mode receive */
227 /* ORF Entry header */
228 bgp_capability_mp_data (s
, &entry
.mpc
);
229 entry
.num
= stream_getc (s
);
231 safi
= entry
.mpc
.safi
;
233 if (BGP_DEBUG (normal
, NORMAL
))
234 zlog_debug ("%s ORF Cap entry for afi/safi: %u/%u",
235 peer
->host
, entry
.mpc
.afi
, entry
.mpc
.safi
);
237 /* Check AFI and SAFI. */
238 if (!bgp_afi_safi_valid_indices (entry
.mpc
.afi
, &safi
))
240 zlog_info ("%s Addr-family %d/%d not supported."
241 " Ignoring the ORF capability",
242 peer
->host
, entry
.mpc
.afi
, entry
.mpc
.safi
);
246 /* validate number field */
247 if (sizeof (struct capability_orf_entry
) + (entry
.num
* 2) > hdr
->length
)
249 zlog_info ("%s ORF Capability entry length error,"
250 " Cap length %u, num %u",
251 peer
->host
, hdr
->length
, entry
.num
);
252 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
256 for (i
= 0 ; i
< entry
.num
; i
++)
258 type
= stream_getc(s
);
259 mode
= stream_getc(s
);
261 /* ORF Mode error check */
266 case ORF_MODE_RECEIVE
:
269 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
272 /* ORF Type and afi/safi error checks */
273 /* capcode versus type */
276 case CAPABILITY_CODE_ORF
:
279 case ORF_TYPE_PREFIX
:
282 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
286 case CAPABILITY_CODE_ORF_OLD
:
289 case ORF_TYPE_PREFIX_OLD
:
292 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
297 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
302 if (!((afi
== AFI_IP
&& safi
== SAFI_UNICAST
)
303 || (afi
== AFI_IP
&& safi
== SAFI_MULTICAST
)
304 || (afi
== AFI_IP6
&& safi
== SAFI_UNICAST
)))
306 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
310 if (BGP_DEBUG (normal
, NORMAL
))
311 zlog_debug ("%s OPEN has %s ORF capability"
312 " as %s for afi/safi: %d/%d",
313 peer
->host
, LOOKUP (orf_type_str
, type
),
314 LOOKUP (orf_mode_str
, mode
),
315 entry
.mpc
.afi
, safi
);
317 if (hdr
->code
== CAPABILITY_CODE_ORF
)
319 sm_cap
= PEER_CAP_ORF_PREFIX_SM_RCV
;
320 rm_cap
= PEER_CAP_ORF_PREFIX_RM_RCV
;
322 else if (hdr
->code
== CAPABILITY_CODE_ORF_OLD
)
324 sm_cap
= PEER_CAP_ORF_PREFIX_SM_OLD_RCV
;
325 rm_cap
= PEER_CAP_ORF_PREFIX_RM_OLD_RCV
;
329 bgp_capability_orf_not_support (peer
, afi
, safi
, type
, mode
);
336 SET_FLAG (peer
->af_cap
[afi
][safi
], sm_cap
);
337 SET_FLAG (peer
->af_cap
[afi
][safi
], rm_cap
);
340 SET_FLAG (peer
->af_cap
[afi
][safi
], sm_cap
);
342 case ORF_MODE_RECEIVE
:
343 SET_FLAG (peer
->af_cap
[afi
][safi
], rm_cap
);
351 bgp_capability_orf (struct peer
*peer
, struct capability_header
*hdr
)
353 struct stream
*s
= BGP_INPUT (peer
);
354 size_t end
= stream_get_getp (s
) + hdr
->length
;
356 assert (stream_get_getp(s
) + sizeof(struct capability_orf_entry
) <= end
);
358 /* We must have at least one ORF entry, as the caller has already done
359 * minimum length validation for the capability code - for ORF there must
360 * at least one ORF entry (header and unknown number of pairs of bytes).
364 if (bgp_capability_orf_entry (peer
, hdr
) == -1)
367 while (stream_get_getp(s
) + sizeof(struct capability_orf_entry
) < end
);
373 bgp_capability_restart (struct peer
*peer
, struct capability_header
*caphdr
)
375 struct stream
*s
= BGP_INPUT (peer
);
376 u_int16_t restart_flag_time
;
378 size_t end
= stream_get_getp (s
) + caphdr
->length
;
380 SET_FLAG (peer
->cap
, PEER_CAP_RESTART_RCV
);
381 restart_flag_time
= stream_getw(s
);
382 if (CHECK_FLAG (restart_flag_time
, RESTART_R_BIT
))
384 UNSET_FLAG (restart_flag_time
, 0xF000);
385 peer
->v_gr_restart
= restart_flag_time
;
387 if (BGP_DEBUG (normal
, NORMAL
))
389 zlog_debug ("%s OPEN has Graceful Restart capability", peer
->host
);
390 zlog_debug ("%s Peer has%srestarted. Restart Time : %d",
391 peer
->host
, restart_bit
? " " : " not ",
395 while (stream_get_getp (s
) + 4 < end
)
397 afi_t afi
= stream_getw (s
);
398 safi_t safi
= stream_getc (s
);
399 u_char flag
= stream_getc (s
);
401 if (!bgp_afi_safi_valid_indices (afi
, &safi
))
403 if (BGP_DEBUG (normal
, NORMAL
))
404 zlog_debug ("%s Addr-family %d/%d(afi/safi) not supported."
405 " Ignore the Graceful Restart capability",
406 peer
->host
, afi
, safi
);
408 else if (!peer
->afc
[afi
][safi
])
410 if (BGP_DEBUG (normal
, NORMAL
))
411 zlog_debug ("%s Addr-family %d/%d(afi/safi) not enabled."
412 " Ignore the Graceful Restart capability",
413 peer
->host
, afi
, safi
);
417 if (BGP_DEBUG (normal
, NORMAL
))
418 zlog_debug ("%s Address family %s is%spreserved", peer
->host
,
419 afi_safi_print (afi
, safi
),
420 CHECK_FLAG (peer
->af_cap
[afi
][safi
],
421 PEER_CAP_RESTART_AF_PRESERVE_RCV
)
424 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_RESTART_AF_RCV
);
425 if (CHECK_FLAG (flag
, RESTART_F_BIT
))
426 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_RESTART_AF_PRESERVE_RCV
);
434 bgp_capability_as4 (struct peer
*peer
, struct capability_header
*hdr
)
436 as_t as4
= stream_getl (BGP_INPUT(peer
));
438 if (BGP_DEBUG (as4
, AS4
))
439 zlog_debug ("%s [AS4] about to set cap PEER_CAP_AS4_RCV, got as4 %u",
441 SET_FLAG (peer
->cap
, PEER_CAP_AS4_RCV
);
446 static const struct message capcode_str
[] =
448 { CAPABILITY_CODE_MP
, "MultiProtocol Extensions" },
449 { CAPABILITY_CODE_REFRESH
, "Route Refresh" },
450 { CAPABILITY_CODE_ORF
, "Cooperative Route Filtering" },
451 { CAPABILITY_CODE_RESTART
, "Graceful Restart" },
452 { CAPABILITY_CODE_AS4
, "4-octet AS number" },
453 { CAPABILITY_CODE_DYNAMIC
, "Dynamic" },
454 { CAPABILITY_CODE_REFRESH_OLD
, "Route Refresh (Old)" },
455 { CAPABILITY_CODE_ORF_OLD
, "ORF (Old)" },
457 static const int capcode_str_max
= sizeof(capcode_str
)/sizeof(capcode_str
[0]);
459 /* Minimum sizes for length field of each cap (so not inc. the header) */
460 static const size_t cap_minsizes
[] =
462 [CAPABILITY_CODE_MP
] = sizeof (struct capability_mp_data
),
463 [CAPABILITY_CODE_REFRESH
] = CAPABILITY_CODE_REFRESH_LEN
,
464 [CAPABILITY_CODE_ORF
] = sizeof (struct capability_orf_entry
),
465 [CAPABILITY_CODE_RESTART
] = sizeof (struct capability_gr
),
466 [CAPABILITY_CODE_AS4
] = CAPABILITY_CODE_AS4_LEN
,
467 [CAPABILITY_CODE_DYNAMIC
] = CAPABILITY_CODE_DYNAMIC_LEN
,
468 [CAPABILITY_CODE_REFRESH_OLD
] = CAPABILITY_CODE_REFRESH_LEN
,
469 [CAPABILITY_CODE_ORF_OLD
] = sizeof (struct capability_orf_entry
),
472 /* Parse given capability.
473 * XXX: This is reading into a stream, but not using stream API
476 bgp_capability_parse (struct peer
*peer
, size_t length
, u_char
**error
)
479 struct stream
*s
= BGP_INPUT (peer
);
480 size_t end
= stream_get_getp (s
) + length
;
482 assert (STREAM_READABLE (s
) >= length
);
484 while (stream_get_getp (s
) < end
)
487 u_char
*sp
= stream_pnt (s
);
488 struct capability_header caphdr
;
490 /* We need at least capability code and capability length. */
491 if (stream_get_getp(s
) + 2 > end
)
493 zlog_info ("%s Capability length error (< header)", peer
->host
);
494 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
498 caphdr
.code
= stream_getc (s
);
499 caphdr
.length
= stream_getc (s
);
500 start
= stream_get_getp (s
);
502 /* Capability length check sanity check. */
503 if (start
+ caphdr
.length
> end
)
505 zlog_info ("%s Capability length error (< length)", peer
->host
);
506 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
510 if (BGP_DEBUG (normal
, NORMAL
))
511 zlog_debug ("%s OPEN has %s capability (%u), length %u",
513 LOOKUP (capcode_str
, caphdr
.code
),
514 caphdr
.code
, caphdr
.length
);
516 /* Length sanity check, type-specific, for known capabilities */
519 case CAPABILITY_CODE_MP
:
520 case CAPABILITY_CODE_REFRESH
:
521 case CAPABILITY_CODE_REFRESH_OLD
:
522 case CAPABILITY_CODE_ORF
:
523 case CAPABILITY_CODE_ORF_OLD
:
524 case CAPABILITY_CODE_RESTART
:
525 case CAPABILITY_CODE_AS4
:
526 case CAPABILITY_CODE_DYNAMIC
:
528 if (caphdr
.length
< cap_minsizes
[caphdr
.code
])
530 zlog_info ("%s %s Capability length error: got %u,"
531 " expected at least %u",
533 LOOKUP (capcode_str
, caphdr
.code
),
535 (unsigned) cap_minsizes
[caphdr
.code
]);
536 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
539 /* we deliberately ignore unknown codes, see below */
546 case CAPABILITY_CODE_MP
:
548 /* Ignore capability when override-capability is set. */
549 if (! CHECK_FLAG (peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
551 /* Set negotiated value. */
552 ret
= bgp_capability_mp (peer
, &caphdr
);
554 /* Unsupported Capability. */
557 /* Store return data. */
558 memcpy (*error
, sp
, caphdr
.length
+ 2);
559 *error
+= caphdr
.length
+ 2;
564 case CAPABILITY_CODE_REFRESH
:
565 case CAPABILITY_CODE_REFRESH_OLD
:
567 /* BGP refresh capability */
568 if (caphdr
.code
== CAPABILITY_CODE_REFRESH_OLD
)
569 SET_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
);
571 SET_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
);
574 case CAPABILITY_CODE_ORF
:
575 case CAPABILITY_CODE_ORF_OLD
:
576 if (bgp_capability_orf (peer
, &caphdr
))
579 case CAPABILITY_CODE_RESTART
:
580 if (bgp_capability_restart (peer
, &caphdr
))
583 case CAPABILITY_CODE_DYNAMIC
:
584 SET_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_RCV
);
586 case CAPABILITY_CODE_AS4
:
587 /* Already handled as a special-case parsing of the capabilities
588 * at the beginning of OPEN processing. So we care not a jot
589 * for the value really, only error case.
591 if (!bgp_capability_as4 (peer
, &caphdr
))
595 if (caphdr
.code
> 128)
597 /* We don't send Notification for unknown vendor specific
598 capabilities. It seems reasonable for now... */
599 zlog_warn ("%s Vendor specific capability %d",
600 peer
->host
, caphdr
.code
);
604 zlog_warn ("%s unrecognized capability code: %d - ignored",
605 peer
->host
, caphdr
.code
);
606 memcpy (*error
, sp
, caphdr
.length
+ 2);
607 *error
+= caphdr
.length
+ 2;
610 if (stream_get_getp(s
) != (start
+ caphdr
.length
))
612 if (stream_get_getp(s
) > (start
+ caphdr
.length
))
613 zlog_warn ("%s Cap-parser for %s read past cap-length, %u!",
614 peer
->host
, LOOKUP (capcode_str
, caphdr
.code
),
616 stream_set_getp (s
, start
+ caphdr
.length
);
623 bgp_auth_parse (struct peer
*peer
, size_t length
)
625 bgp_notify_send (peer
,
627 BGP_NOTIFY_OPEN_AUTH_FAILURE
);
632 strict_capability_same (struct peer
*peer
)
636 for (i
= AFI_IP
; i
< AFI_MAX
; i
++)
637 for (j
= SAFI_UNICAST
; j
< SAFI_MAX
; j
++)
638 if (peer
->afc
[i
][j
] != peer
->afc_nego
[i
][j
])
643 /* peek into option, stores ASN to *as4 if the AS4 capability was found.
644 * Returns 0 if no as4 found, as4cap value otherwise.
647 peek_for_as4_capability (struct peer
*peer
, u_char length
)
649 struct stream
*s
= BGP_INPUT (peer
);
650 size_t orig_getp
= stream_get_getp (s
);
651 size_t end
= orig_getp
+ length
;
654 /* The full capability parser will better flag the error.. */
655 if (STREAM_READABLE(s
) < length
)
658 if (BGP_DEBUG (as4
, AS4
))
659 zlog_info ("%s [AS4] rcv OPEN w/ OPTION parameter len: %u,"
662 /* the error cases we DONT handle, we ONLY try to read as4 out of
663 * correctly formatted options.
665 while (stream_get_getp(s
) < end
)
670 /* Check the length. */
671 if (stream_get_getp (s
) + 2 > end
)
674 /* Fetch option type and length. */
675 opt_type
= stream_getc (s
);
676 opt_length
= stream_getc (s
);
678 /* Option length check. */
679 if (stream_get_getp (s
) + opt_length
> end
)
682 if (opt_type
== BGP_OPEN_OPT_CAP
)
684 unsigned long capd_start
= stream_get_getp (s
);
685 unsigned long capd_end
= capd_start
+ opt_length
;
687 assert (capd_end
<= end
);
689 while (stream_get_getp (s
) < capd_end
)
691 struct capability_header hdr
;
693 if (stream_get_getp (s
) + 2 > capd_end
)
696 hdr
.code
= stream_getc (s
);
697 hdr
.length
= stream_getc (s
);
699 if ((stream_get_getp(s
) + hdr
.length
) > capd_end
)
702 if (hdr
.code
== CAPABILITY_CODE_AS4
)
704 if (hdr
.length
!= CAPABILITY_CODE_AS4_LEN
)
707 if (BGP_DEBUG (as4
, AS4
))
708 zlog_info ("[AS4] found AS4 capability, about to parse");
709 as4
= bgp_capability_as4 (peer
, &hdr
);
713 stream_forward_getp (s
, hdr
.length
);
719 stream_set_getp (s
, orig_getp
);
723 /* Parse open option */
725 bgp_open_option_parse (struct peer
*peer
, u_char length
, int *capability
)
729 u_char error_data
[BGP_MAX_PACKET_SIZE
];
730 struct stream
*s
= BGP_INPUT(peer
);
731 size_t end
= stream_get_getp (s
) + length
;
736 if (BGP_DEBUG (normal
, NORMAL
))
737 zlog_debug ("%s rcv OPEN w/ OPTION parameter len: %u",
740 while (stream_get_getp(s
) < end
)
745 /* Must have at least an OPEN option header */
746 if (STREAM_READABLE(s
) < 2)
748 zlog_info ("%s Option length error", peer
->host
);
749 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
753 /* Fetch option type and length. */
754 opt_type
= stream_getc (s
);
755 opt_length
= stream_getc (s
);
757 /* Option length check. */
758 if (STREAM_READABLE (s
) < opt_length
)
760 zlog_info ("%s Option length error", peer
->host
);
761 bgp_notify_send (peer
, BGP_NOTIFY_CEASE
, 0);
765 if (BGP_DEBUG (normal
, NORMAL
))
766 zlog_debug ("%s rcvd OPEN w/ optional parameter type %u (%s) len %u",
767 peer
->host
, opt_type
,
768 opt_type
== BGP_OPEN_OPT_AUTH
? "Authentication" :
769 opt_type
== BGP_OPEN_OPT_CAP
? "Capability" : "Unknown",
774 case BGP_OPEN_OPT_AUTH
:
775 ret
= bgp_auth_parse (peer
, opt_length
);
777 case BGP_OPEN_OPT_CAP
:
778 ret
= bgp_capability_parse (peer
, opt_length
, &error
);
782 bgp_notify_send (peer
,
784 BGP_NOTIFY_OPEN_UNSUP_PARAM
);
789 /* Parse error. To accumulate all unsupported capability codes,
790 bgp_capability_parse does not return -1 when encounter
791 unsupported capability code. To detect that, please check
792 error and erro_data pointer, like below. */
797 /* All OPEN option is parsed. Check capability when strict compare
799 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_STRICT_CAP_MATCH
))
801 /* If Unsupported Capability exists. */
802 if (error
!= error_data
)
804 bgp_notify_send_with_data (peer
,
806 BGP_NOTIFY_OPEN_UNSUP_CAPBL
,
807 error_data
, error
- error_data
);
811 /* Check local capability does not negotiated with remote
813 if (! strict_capability_same (peer
))
815 bgp_notify_send (peer
,
817 BGP_NOTIFY_OPEN_UNSUP_CAPBL
);
822 /* Check there is no common capability send Unsupported Capability
824 if (*capability
&& ! CHECK_FLAG (peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
))
826 if (! peer
->afc_nego
[AFI_IP
][SAFI_UNICAST
]
827 && ! peer
->afc_nego
[AFI_IP
][SAFI_MULTICAST
]
828 && ! peer
->afc_nego
[AFI_IP
][SAFI_MPLS_VPN
]
829 && ! peer
->afc_nego
[AFI_IP6
][SAFI_UNICAST
]
830 && ! peer
->afc_nego
[AFI_IP6
][SAFI_MULTICAST
])
832 plog_err (peer
->log
, "%s [Error] No common capability", peer
->host
);
834 if (error
!= error_data
)
836 bgp_notify_send_with_data (peer
,
838 BGP_NOTIFY_OPEN_UNSUP_CAPBL
,
839 error_data
, error
- error_data
);
841 bgp_notify_send (peer
,
843 BGP_NOTIFY_OPEN_UNSUP_CAPBL
);
851 bgp_open_capability_orf (struct stream
*s
, struct peer
*peer
,
852 afi_t afi
, safi_t safi
, u_char code
)
858 unsigned long numberp
;
859 int number_of_orfs
= 0;
861 if (safi
== SAFI_MPLS_VPN
)
862 safi
= BGP_SAFI_VPNV4
;
864 stream_putc (s
, BGP_OPEN_OPT_CAP
);
865 capp
= stream_get_endp (s
); /* Set Capability Len Pointer */
866 stream_putc (s
, 0); /* Capability Length */
867 stream_putc (s
, code
); /* Capability Code */
868 orfp
= stream_get_endp (s
); /* Set ORF Len Pointer */
869 stream_putc (s
, 0); /* ORF Length */
870 stream_putw (s
, afi
);
872 stream_putc (s
, safi
);
873 numberp
= stream_get_endp (s
); /* Set Number Pointer */
874 stream_putc (s
, 0); /* Number of ORFs */
876 /* Address Prefix ORF */
877 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
878 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
880 stream_putc (s
, (code
== CAPABILITY_CODE_ORF
?
881 ORF_TYPE_PREFIX
: ORF_TYPE_PREFIX_OLD
));
883 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
884 && CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
886 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_ADV
);
887 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_ADV
);
888 stream_putc (s
, ORF_MODE_BOTH
);
890 else if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
))
892 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_ADV
);
893 stream_putc (s
, ORF_MODE_SEND
);
897 SET_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_RM_ADV
);
898 stream_putc (s
, ORF_MODE_RECEIVE
);
903 /* Total Number of ORFs. */
904 stream_putc_at (s
, numberp
, number_of_orfs
);
907 orf_len
= stream_get_endp (s
) - orfp
- 1;
908 stream_putc_at (s
, orfp
, orf_len
);
910 /* Total Capability Len. */
911 cap_len
= stream_get_endp (s
) - capp
- 1;
912 stream_putc_at (s
, capp
, cap_len
);
915 /* Fill in capability open option to the packet. */
917 bgp_open_capability (struct stream
*s
, struct peer
*peer
)
925 /* Remember current pointer for Opt Parm Len. */
926 cp
= stream_get_endp (s
);
931 /* Do not send capability. */
932 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_CAPABILITY_OPEN
)
933 || CHECK_FLAG (peer
->flags
, PEER_FLAG_DONT_CAPABILITY
))
937 if (peer
->afc
[AFI_IP
][SAFI_UNICAST
])
939 peer
->afc_adv
[AFI_IP
][SAFI_UNICAST
] = 1;
940 stream_putc (s
, BGP_OPEN_OPT_CAP
);
941 stream_putc (s
, CAPABILITY_CODE_MP_LEN
+ 2);
942 stream_putc (s
, CAPABILITY_CODE_MP
);
943 stream_putc (s
, CAPABILITY_CODE_MP_LEN
);
944 stream_putw (s
, AFI_IP
);
946 stream_putc (s
, SAFI_UNICAST
);
948 /* IPv4 multicast. */
949 if (peer
->afc
[AFI_IP
][SAFI_MULTICAST
])
951 peer
->afc_adv
[AFI_IP
][SAFI_MULTICAST
] = 1;
952 stream_putc (s
, BGP_OPEN_OPT_CAP
);
953 stream_putc (s
, CAPABILITY_CODE_MP_LEN
+ 2);
954 stream_putc (s
, CAPABILITY_CODE_MP
);
955 stream_putc (s
, CAPABILITY_CODE_MP_LEN
);
956 stream_putw (s
, AFI_IP
);
958 stream_putc (s
, SAFI_MULTICAST
);
961 if (peer
->afc
[AFI_IP
][SAFI_MPLS_VPN
])
963 peer
->afc_adv
[AFI_IP
][SAFI_MPLS_VPN
] = 1;
964 stream_putc (s
, BGP_OPEN_OPT_CAP
);
965 stream_putc (s
, CAPABILITY_CODE_MP_LEN
+ 2);
966 stream_putc (s
, CAPABILITY_CODE_MP
);
967 stream_putc (s
, CAPABILITY_CODE_MP_LEN
);
968 stream_putw (s
, AFI_IP
);
970 stream_putc (s
, BGP_SAFI_VPNV4
);
974 if (peer
->afc
[AFI_IP6
][SAFI_UNICAST
])
976 peer
->afc_adv
[AFI_IP6
][SAFI_UNICAST
] = 1;
977 stream_putc (s
, BGP_OPEN_OPT_CAP
);
978 stream_putc (s
, CAPABILITY_CODE_MP_LEN
+ 2);
979 stream_putc (s
, CAPABILITY_CODE_MP
);
980 stream_putc (s
, CAPABILITY_CODE_MP_LEN
);
981 stream_putw (s
, AFI_IP6
);
983 stream_putc (s
, SAFI_UNICAST
);
985 /* IPv6 multicast. */
986 if (peer
->afc
[AFI_IP6
][SAFI_MULTICAST
])
988 peer
->afc_adv
[AFI_IP6
][SAFI_MULTICAST
] = 1;
989 stream_putc (s
, BGP_OPEN_OPT_CAP
);
990 stream_putc (s
, CAPABILITY_CODE_MP_LEN
+ 2);
991 stream_putc (s
, CAPABILITY_CODE_MP
);
992 stream_putc (s
, CAPABILITY_CODE_MP_LEN
);
993 stream_putw (s
, AFI_IP6
);
995 stream_putc (s
, SAFI_MULTICAST
);
997 #endif /* HAVE_IPV6 */
1000 SET_FLAG (peer
->cap
, PEER_CAP_REFRESH_ADV
);
1001 stream_putc (s
, BGP_OPEN_OPT_CAP
);
1002 stream_putc (s
, CAPABILITY_CODE_REFRESH_LEN
+ 2);
1003 stream_putc (s
, CAPABILITY_CODE_REFRESH_OLD
);
1004 stream_putc (s
, CAPABILITY_CODE_REFRESH_LEN
);
1005 stream_putc (s
, BGP_OPEN_OPT_CAP
);
1006 stream_putc (s
, CAPABILITY_CODE_REFRESH_LEN
+ 2);
1007 stream_putc (s
, CAPABILITY_CODE_REFRESH
);
1008 stream_putc (s
, CAPABILITY_CODE_REFRESH_LEN
);
1011 SET_FLAG (peer
->cap
, PEER_CAP_AS4_ADV
);
1012 stream_putc (s
, BGP_OPEN_OPT_CAP
);
1013 stream_putc (s
, CAPABILITY_CODE_AS4_LEN
+ 2);
1014 stream_putc (s
, CAPABILITY_CODE_AS4
);
1015 stream_putc (s
, CAPABILITY_CODE_AS4_LEN
);
1016 if ( peer
->change_local_as
)
1017 local_as
= peer
->change_local_as
;
1019 local_as
= peer
->local_as
;
1020 stream_putl (s
, local_as
);
1022 /* ORF capability. */
1023 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1024 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
1025 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_SM
)
1026 || CHECK_FLAG (peer
->af_flags
[afi
][safi
], PEER_FLAG_ORF_PREFIX_RM
))
1028 bgp_open_capability_orf (s
, peer
, afi
, safi
, CAPABILITY_CODE_ORF_OLD
);
1029 bgp_open_capability_orf (s
, peer
, afi
, safi
, CAPABILITY_CODE_ORF
);
1032 /* Dynamic capability. */
1033 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_DYNAMIC_CAPABILITY
))
1035 SET_FLAG (peer
->cap
, PEER_CAP_DYNAMIC_ADV
);
1036 stream_putc (s
, BGP_OPEN_OPT_CAP
);
1037 stream_putc (s
, CAPABILITY_CODE_DYNAMIC_LEN
+ 2);
1038 stream_putc (s
, CAPABILITY_CODE_DYNAMIC
);
1039 stream_putc (s
, CAPABILITY_CODE_DYNAMIC_LEN
);
1042 /* Graceful restart capability */
1043 if (bgp_flag_check (peer
->bgp
, BGP_FLAG_GRACEFUL_RESTART
))
1045 SET_FLAG (peer
->cap
, PEER_CAP_RESTART_ADV
);
1046 stream_putc (s
, BGP_OPEN_OPT_CAP
);
1047 stream_putc (s
, CAPABILITY_CODE_RESTART_LEN
+ 2);
1048 stream_putc (s
, CAPABILITY_CODE_RESTART
);
1049 stream_putc (s
, CAPABILITY_CODE_RESTART_LEN
);
1050 stream_putw (s
, peer
->bgp
->restart_time
);
1053 /* Total Opt Parm Len. */
1054 len
= stream_get_endp (s
) - cp
- 1;
1055 stream_putc_at (s
, cp
, len
);