1 /* BGP packet management routine.
2 * Contains utility functions for constructing and consuming BGP messages.
3 * Copyright (C) 2017 Cumulus Networks
4 * Copyright (C) 1999 Kunihiro Ishiguro
6 * This file is part of GNU Zebra.
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include "sockunion.h" /* for inet_ntop () */
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_table.h"
42 #include "bgpd/bgp_dump.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_debug.h"
45 #include "bgpd/bgp_fsm.h"
46 #include "bgpd/bgp_route.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_open.h"
49 #include "bgpd/bgp_aspath.h"
50 #include "bgpd/bgp_community.h"
51 #include "bgpd/bgp_ecommunity.h"
52 #include "bgpd/bgp_lcommunity.h"
53 #include "bgpd/bgp_network.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_evpn.h"
56 #include "bgpd/bgp_advertise.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_updgrp.h"
59 #include "bgpd/bgp_label.h"
60 #include "bgpd/bgp_io.h"
63 * Sets marker and type fields for a BGP message.
65 * @param s the stream containing the packet
66 * @param type the packet type
67 * @return the size of the stream
69 int bgp_packet_set_marker(struct stream
*s
, u_char type
)
74 for (i
= 0; i
< BGP_MARKER_SIZE
; i
++)
77 /* Dummy total length. This field is should be filled in later on. */
80 /* BGP packet type. */
83 /* Return current stream size. */
84 return stream_get_endp(s
);
88 * Sets size field for a BGP message.
90 * Size field is set to the size of the stream passed.
92 * @param s the stream containing the packet
93 * @return the size of the stream
95 int bgp_packet_set_size(struct stream
*s
)
99 /* Preserve current pointer. */
100 cp
= stream_get_endp(s
);
101 stream_putw_at(s
, BGP_MARKER_SIZE
, cp
);
107 * Push a packet onto the beginning of the peer's output queue.
108 * This function acquires the peer's write mutex before proceeding.
110 static void bgp_packet_add(struct peer
*peer
, struct stream
*s
)
112 pthread_mutex_lock(&peer
->io_mtx
);
113 stream_fifo_push(peer
->obuf
, s
);
114 pthread_mutex_unlock(&peer
->io_mtx
);
117 static struct stream
*bgp_update_packet_eor(struct peer
*peer
, afi_t afi
,
122 iana_safi_t pkt_safi
;
124 if (DISABLE_BGP_ANNOUNCE
)
127 if (bgp_debug_neighbor_events(peer
))
128 zlog_debug("send End-of-RIB for %s to %s",
129 afi_safi_print(afi
, safi
), peer
->host
);
131 s
= stream_new(BGP_MAX_PACKET_SIZE
);
133 /* Make BGP update packet. */
134 bgp_packet_set_marker(s
, BGP_MSG_UPDATE
);
136 /* Unfeasible Routes Length */
139 if (afi
== AFI_IP
&& safi
== SAFI_UNICAST
) {
140 /* Total Path Attribute Length */
143 /* Convert AFI, SAFI to values for packet. */
144 bgp_map_afi_safi_int2iana(afi
, safi
, &pkt_afi
, &pkt_safi
);
146 /* Total Path Attribute Length */
148 stream_putc(s
, BGP_ATTR_FLAG_OPTIONAL
);
149 stream_putc(s
, BGP_ATTR_MP_UNREACH_NLRI
);
151 stream_putw(s
, pkt_afi
);
152 stream_putc(s
, pkt_safi
);
155 bgp_packet_set_size(s
);
159 /* Called when there is a change in the EOR(implicit or explicit) status of a
160 * peer. Ends the update-delay if all expected peers are done with EORs. */
161 void bgp_check_update_delay(struct bgp
*bgp
)
163 struct listnode
*node
, *nnode
;
164 struct peer
*peer
= NULL
;
166 if (bgp_debug_neighbor_events(peer
))
167 zlog_debug("Checking update delay, T: %d R: %d I:%d E: %d",
168 bgp
->established
, bgp
->restarted_peers
,
169 bgp
->implicit_eors
, bgp
->explicit_eors
);
172 <= bgp
->restarted_peers
+ bgp
->implicit_eors
+ bgp
->explicit_eors
) {
174 * This is an extra sanity check to make sure we wait for all
175 * the eligible configured peers. This check is performed if
176 * establish wait timer is on, or establish wait option is not
177 * given with the update-delay command
179 if (bgp
->t_establish_wait
180 || (bgp
->v_establish_wait
== bgp
->v_update_delay
))
181 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
182 if (CHECK_FLAG(peer
->flags
,
183 PEER_FLAG_CONFIG_NODE
)
184 && !CHECK_FLAG(peer
->flags
,
186 && !peer
->update_delay_over
) {
187 if (bgp_debug_neighbor_events(peer
))
189 " Peer %s pending, continuing read-only mode",
196 "Update delay ended, restarted: %d, EORs implicit: %d, explicit: %d",
197 bgp
->restarted_peers
, bgp
->implicit_eors
,
199 bgp_update_delay_end(bgp
);
204 * Called if peer is known to have restarted. The restart-state bit in
205 * Graceful-Restart capability is used for that
207 void bgp_update_restarted_peers(struct peer
*peer
)
209 if (!bgp_update_delay_active(peer
->bgp
))
210 return; /* BGP update delay has ended */
211 if (peer
->update_delay_over
)
212 return; /* This peer has already been considered */
214 if (bgp_debug_neighbor_events(peer
))
215 zlog_debug("Peer %s: Checking restarted", peer
->host
);
217 if (peer
->status
== Established
) {
218 peer
->update_delay_over
= 1;
219 peer
->bgp
->restarted_peers
++;
220 bgp_check_update_delay(peer
->bgp
);
225 * Called as peer receives a keep-alive. Determines if this occurence can be
226 * taken as an implicit EOR for this peer.
227 * NOTE: The very first keep-alive after the Established state of a peer is
228 * considered implicit EOR for the update-delay purposes
230 void bgp_update_implicit_eors(struct peer
*peer
)
232 if (!bgp_update_delay_active(peer
->bgp
))
233 return; /* BGP update delay has ended */
234 if (peer
->update_delay_over
)
235 return; /* This peer has already been considered */
237 if (bgp_debug_neighbor_events(peer
))
238 zlog_debug("Peer %s: Checking implicit EORs", peer
->host
);
240 if (peer
->status
== Established
) {
241 peer
->update_delay_over
= 1;
242 peer
->bgp
->implicit_eors
++;
243 bgp_check_update_delay(peer
->bgp
);
248 * Should be called only when there is a change in the EOR_RECEIVED status
249 * for any afi/safi on a peer.
251 static void bgp_update_explicit_eors(struct peer
*peer
)
256 if (!bgp_update_delay_active(peer
->bgp
))
257 return; /* BGP update delay has ended */
258 if (peer
->update_delay_over
)
259 return; /* This peer has already been considered */
261 if (bgp_debug_neighbor_events(peer
))
262 zlog_debug("Peer %s: Checking explicit EORs", peer
->host
);
264 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
265 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
266 if (peer
->afc_nego
[afi
][safi
]
267 && !CHECK_FLAG(peer
->af_sflags
[afi
][safi
],
268 PEER_STATUS_EOR_RECEIVED
)) {
269 if (bgp_debug_neighbor_events(peer
))
271 " afi %d safi %d didnt receive EOR",
277 peer
->update_delay_over
= 1;
278 peer
->bgp
->explicit_eors
++;
279 bgp_check_update_delay(peer
->bgp
);
283 * Frontend for NLRI parsing, to fan-out to AFI/SAFI specific parsers.
285 * mp_withdraw, if set, is used to nullify attr structure on most of the
286 * calling safi function and for evpn, passed as parameter
288 int bgp_nlri_parse(struct peer
*peer
, struct attr
*attr
,
289 struct bgp_nlri
*packet
, int mp_withdraw
)
291 switch (packet
->safi
) {
294 return bgp_nlri_parse_ip(peer
, mp_withdraw
? NULL
: attr
,
296 case SAFI_LABELED_UNICAST
:
297 return bgp_nlri_parse_label(peer
, mp_withdraw
? NULL
: attr
,
300 return bgp_nlri_parse_vpn(peer
, mp_withdraw
? NULL
: attr
,
303 return bgp_nlri_parse_evpn(peer
, attr
, packet
, mp_withdraw
);
308 /* The next action for the peer from a write perspective */
309 static void bgp_write_proceed_actions(struct peer
*peer
)
314 struct bpacket
*next_pkt
;
315 struct update_subgroup
*subgrp
;
317 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
318 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
319 paf
= peer_af_find(peer
, afi
, safi
);
322 subgrp
= paf
->subgroup
;
326 next_pkt
= paf
->next_pkt_to_send
;
327 if (next_pkt
&& next_pkt
->buffer
) {
328 BGP_TIMER_ON(peer
->t_generate_updgrp_packets
,
329 bgp_generate_updgrp_packets
, 0);
333 /* No packets readily available for AFI/SAFI, are there
335 * that need to be generated? */
336 if (bpacket_queue_is_full(SUBGRP_INST(subgrp
),
338 || subgroup_packets_to_build(subgrp
)) {
339 BGP_TIMER_ON(peer
->t_generate_updgrp_packets
,
340 bgp_generate_updgrp_packets
, 0);
344 /* No packets to send, see if EOR is pending */
345 if (CHECK_FLAG(peer
->cap
, PEER_CAP_RESTART_RCV
)) {
346 if (!subgrp
->t_coalesce
347 && peer
->afc_nego
[afi
][safi
]
349 && !CHECK_FLAG(peer
->af_sflags
[afi
][safi
],
350 PEER_STATUS_EOR_SEND
)
351 && safi
!= SAFI_MPLS_VPN
) {
353 peer
->t_generate_updgrp_packets
,
354 bgp_generate_updgrp_packets
, 0);
362 * Enqueue onto the peer's output buffer any packets which are pending for the
363 * update group it is a member of.
365 * XXX: Severely needs performance work.
367 int bgp_generate_updgrp_packets(struct thread
*thread
)
369 struct peer
*peer
= THREAD_ARG(thread
);
373 struct bpacket
*next_pkt
;
378 * The code beyond this part deals with update packets, proceed only
379 * if peer is Established and updates are not on hold (as part of
380 * update-delay post processing).
382 if (peer
->status
!= Established
)
385 if (peer
->bgp
&& peer
->bgp
->main_peers_update_hold
)
390 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
391 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
392 paf
= peer_af_find(peer
, afi
, safi
);
393 if (!paf
|| !PAF_SUBGRP(paf
))
395 next_pkt
= paf
->next_pkt_to_send
;
398 * Try to generate a packet for the peer if we
399 * are at the end of the list. Always try to
400 * push out WITHDRAWs first.
402 if (!next_pkt
|| !next_pkt
->buffer
) {
403 next_pkt
= subgroup_withdraw_packet(
405 if (!next_pkt
|| !next_pkt
->buffer
)
406 subgroup_update_packet(
408 next_pkt
= paf
->next_pkt_to_send
;
412 * If we still don't have a packet to send to
413 * the peer, then try to find out out if we
414 * have to send eor or if not, skip to the next
415 * AFI, SAFI. Don't send the EOR prematurely...
416 * if the subgroup's coalesce timer is running,
417 * the adjacency-out structure is not created
420 if (!next_pkt
|| !next_pkt
->buffer
) {
421 if (CHECK_FLAG(peer
->cap
,
422 PEER_CAP_RESTART_RCV
)) {
423 if (!(PAF_SUBGRP(paf
))
425 && peer
->afc_nego
[afi
][safi
]
431 PEER_STATUS_EOR_SEND
)) {
436 PEER_STATUS_EOR_SEND
);
438 if ((s
= bgp_update_packet_eor(
453 /* Found a packet template to send, overwrite
454 * packet with appropriate attributes from peer
455 * and advance peer */
456 s
= bpacket_reformat_for_peer(next_pkt
, paf
);
457 bgp_packet_add(peer
, s
);
459 bpacket_queue_advance_peer(paf
);
463 bgp_write_proceed_actions(peer
);
469 * Creates a BGP Keepalive packet and appends it to the peer's output queue.
471 void bgp_keepalive_send(struct peer
*peer
)
475 s
= stream_new(BGP_MAX_PACKET_SIZE
);
477 /* Make keepalive packet. */
478 bgp_packet_set_marker(s
, BGP_MSG_KEEPALIVE
);
480 /* Set packet size. */
481 (void)bgp_packet_set_size(s
);
483 /* Dump packet if debug option is set. */
484 /* bgp_packet_dump (s); */
486 if (bgp_debug_keepalive(peer
))
487 zlog_debug("%s sending KEEPALIVE", peer
->host
);
489 /* Add packet to the peer. */
490 bgp_packet_add(peer
, s
);
496 * Creates a BGP Open packet and appends it to the peer's output queue.
497 * Sets capabilities as necessary.
499 void bgp_open_send(struct peer
*peer
)
502 u_int16_t send_holdtime
;
505 if (PEER_OR_GROUP_TIMER_SET(peer
))
506 send_holdtime
= peer
->holdtime
;
508 send_holdtime
= peer
->bgp
->default_holdtime
;
510 /* local-as Change */
511 if (peer
->change_local_as
)
512 local_as
= peer
->change_local_as
;
514 local_as
= peer
->local_as
;
516 s
= stream_new(BGP_MAX_PACKET_SIZE
);
518 /* Make open packet. */
519 bgp_packet_set_marker(s
, BGP_MSG_OPEN
);
521 /* Set open packet values. */
522 stream_putc(s
, BGP_VERSION_4
); /* BGP version */
524 (local_as
<= BGP_AS_MAX
) ? (u_int16_t
)local_as
526 stream_putw(s
, send_holdtime
); /* Hold Time */
527 stream_put_in_addr(s
, &peer
->local_id
); /* BGP Identifier */
529 /* Set capability code. */
530 bgp_open_capability(s
, peer
);
532 /* Set BGP packet length. */
533 (void)bgp_packet_set_size(s
);
535 if (bgp_debug_neighbor_events(peer
))
537 "%s sending OPEN, version %d, my as %u, holdtime %d, id %s",
538 peer
->host
, BGP_VERSION_4
, local_as
, send_holdtime
,
539 inet_ntoa(peer
->local_id
));
541 /* Dump packet if debug option is set. */
542 /* bgp_packet_dump (s); */
544 /* Add packet to the peer. */
545 bgp_packet_add(peer
, s
);
550 /* This is only for sending NOTIFICATION message to neighbor. */
551 static int bgp_write_notify(struct peer
*peer
)
557 pthread_mutex_lock(&peer
->io_mtx
);
559 /* There should be at least one packet. */
560 s
= stream_fifo_pop(peer
->obuf
);
563 assert(stream_get_endp(s
) >= BGP_HEADER_SIZE
);
565 pthread_mutex_unlock(&peer
->io_mtx
);
567 /* Stop collecting data within the socket */
568 sockopt_cork(peer
->fd
, 0);
571 * socket is in nonblocking mode, if we can't deliver the NOTIFY, well,
572 * we only care about getting a clean shutdown at this point.
574 ret
= write(peer
->fd
, STREAM_DATA(s
), stream_get_endp(s
));
577 * only connection reset/close gets counted as TCP_fatal_error, failure
578 * to write the entire NOTIFY doesn't get different FSM treatment
582 BGP_EVENT_ADD(peer
, TCP_fatal_error
);
586 /* Disable Nagle, make NOTIFY packet go out right away */
588 (void)setsockopt(peer
->fd
, IPPROTO_TCP
, TCP_NODELAY
, (char *)&val
,
591 /* Retrieve BGP packet type. */
592 stream_set_getp(s
, BGP_MARKER_SIZE
+ 2);
593 type
= stream_getc(s
);
595 assert(type
== BGP_MSG_NOTIFY
);
597 /* Type should be notify. */
600 /* Double start timer. */
603 /* Overflow check. */
604 if (peer
->v_start
>= (60 * 2))
605 peer
->v_start
= (60 * 2);
608 * Handle Graceful Restart case where the state changes to
609 * Connect instead of Idle
611 BGP_EVENT_ADD(peer
, BGP_Stop
);
619 * Creates a BGP Notify and appends it to the peer's output queue.
621 * This function attempts to write the packet from the thread it is called
622 * from, to ensure the packet gets out ASAP.
625 * @param code BGP error code
626 * @param sub_code BGP error subcode
627 * @param data Data portion
628 * @param datalen length of data portion
630 void bgp_notify_send_with_data(struct peer
*peer
, u_char code
, u_char sub_code
,
631 u_char
*data
, size_t datalen
)
636 /* Allocate new stream. */
637 s
= stream_new(BGP_MAX_PACKET_SIZE
);
639 /* Make notify packet. */
640 bgp_packet_set_marker(s
, BGP_MSG_NOTIFY
);
642 /* Set notify packet values. */
643 stream_putc(s
, code
); /* BGP notify code */
644 stream_putc(s
, sub_code
); /* BGP notify sub_code */
646 /* If notify data is present. */
648 stream_write(s
, data
, datalen
);
650 /* Set BGP packet length. */
651 length
= bgp_packet_set_size(s
);
653 /* wipe output buffer */
654 pthread_mutex_lock(&peer
->io_mtx
);
656 stream_fifo_clean(peer
->obuf
);
658 pthread_mutex_unlock(&peer
->io_mtx
);
661 * If possible, store last packet for debugging purposes. This check is
662 * in place because we are sometimes called with a doppelganger peer,
663 * who tends to have a plethora of fields nulled out.
665 if (peer
->curr
&& peer
->last_reset_cause_size
) {
666 size_t packetsize
= stream_get_endp(peer
->curr
);
667 assert(packetsize
<= peer
->last_reset_cause_size
);
668 memcpy(peer
->last_reset_cause
, peer
->curr
->data
, packetsize
);
669 peer
->last_reset_cause_size
= packetsize
;
674 struct bgp_notify bgp_notify
;
679 bgp_notify
.code
= code
;
680 bgp_notify
.subcode
= sub_code
;
681 bgp_notify
.data
= NULL
;
682 bgp_notify
.length
= length
- BGP_MSG_NOTIFY_MIN_SIZE
;
683 bgp_notify
.raw_data
= data
;
685 peer
->notify
.code
= bgp_notify
.code
;
686 peer
->notify
.subcode
= bgp_notify
.subcode
;
688 if (bgp_notify
.length
) {
690 XMALLOC(MTYPE_TMP
, bgp_notify
.length
* 3);
691 for (i
= 0; i
< bgp_notify
.length
; i
++)
693 sprintf(c
, " %02x", data
[i
]);
694 strcat(bgp_notify
.data
, c
);
697 sprintf(c
, "%02x", data
[i
]);
698 strcpy(bgp_notify
.data
, c
);
701 bgp_notify_print(peer
, &bgp_notify
, "sending");
703 if (bgp_notify
.data
) {
704 XFREE(MTYPE_TMP
, bgp_notify
.data
);
705 bgp_notify
.data
= NULL
;
706 bgp_notify
.length
= 0;
710 /* peer reset cause */
711 if (code
== BGP_NOTIFY_CEASE
) {
712 if (sub_code
== BGP_NOTIFY_CEASE_ADMIN_RESET
)
713 peer
->last_reset
= PEER_DOWN_USER_RESET
;
714 else if (sub_code
== BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
)
715 peer
->last_reset
= PEER_DOWN_USER_SHUTDOWN
;
717 peer
->last_reset
= PEER_DOWN_NOTIFY_SEND
;
719 peer
->last_reset
= PEER_DOWN_NOTIFY_SEND
;
721 /* Add packet to peer's output queue */
722 bgp_packet_add(peer
, s
);
724 bgp_write_notify(peer
);
728 * Creates a BGP Notify and appends it to the peer's output queue.
730 * This function attempts to write the packet from the thread it is called
731 * from, to ensure the packet gets out ASAP.
734 * @param code BGP error code
735 * @param sub_code BGP error subcode
737 void bgp_notify_send(struct peer
*peer
, u_char code
, u_char sub_code
)
739 bgp_notify_send_with_data(peer
, code
, sub_code
, NULL
, 0);
743 * Creates BGP Route Refresh packet and appends it to the peer's output queue.
746 * @param afi Address Family Identifier
747 * @param safi Subsequent Address Family Identifier
748 * @param orf_type Outbound Route Filtering type
749 * @param when_to_refresh Whether to refresh immediately or defer
750 * @param remove Whether to remove ORF for specified AFI/SAFI
752 void bgp_route_refresh_send(struct peer
*peer
, afi_t afi
, safi_t safi
,
753 u_char orf_type
, u_char when_to_refresh
, int remove
)
756 struct bgp_filter
*filter
;
759 iana_safi_t pkt_safi
;
761 if (DISABLE_BGP_ANNOUNCE
)
764 filter
= &peer
->filter
[afi
][safi
];
766 /* Convert AFI, SAFI to values for packet. */
767 bgp_map_afi_safi_int2iana(afi
, safi
, &pkt_afi
, &pkt_safi
);
769 s
= stream_new(BGP_MAX_PACKET_SIZE
);
771 /* Make BGP update packet. */
772 if (CHECK_FLAG(peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
773 bgp_packet_set_marker(s
, BGP_MSG_ROUTE_REFRESH_NEW
);
775 bgp_packet_set_marker(s
, BGP_MSG_ROUTE_REFRESH_OLD
);
777 /* Encode Route Refresh message. */
778 stream_putw(s
, pkt_afi
);
780 stream_putc(s
, pkt_safi
);
782 if (orf_type
== ORF_TYPE_PREFIX
|| orf_type
== ORF_TYPE_PREFIX_OLD
)
783 if (remove
|| filter
->plist
[FILTER_IN
].plist
) {
788 stream_putc(s
, when_to_refresh
);
789 stream_putc(s
, orf_type
);
790 orfp
= stream_get_endp(s
);
794 UNSET_FLAG(peer
->af_sflags
[afi
][safi
],
795 PEER_STATUS_ORF_PREFIX_SEND
);
796 stream_putc(s
, ORF_COMMON_PART_REMOVE_ALL
);
797 if (bgp_debug_neighbor_events(peer
))
799 "%s sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %d/%d",
800 peer
->host
, orf_type
,
801 (when_to_refresh
== REFRESH_DEFER
806 SET_FLAG(peer
->af_sflags
[afi
][safi
],
807 PEER_STATUS_ORF_PREFIX_SEND
);
808 prefix_bgp_orf_entry(
809 s
, filter
->plist
[FILTER_IN
].plist
,
811 ORF_COMMON_PART_PERMIT
,
812 ORF_COMMON_PART_DENY
);
813 if (bgp_debug_neighbor_events(peer
))
815 "%s sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %d/%d",
816 peer
->host
, orf_type
,
817 (when_to_refresh
== REFRESH_DEFER
823 /* Total ORF Entry Len. */
824 orf_len
= stream_get_endp(s
) - orfp
- 2;
825 stream_putw_at(s
, orfp
, orf_len
);
828 /* Set packet size. */
829 (void)bgp_packet_set_size(s
);
831 if (bgp_debug_neighbor_events(peer
)) {
833 zlog_debug("%s sending REFRESH_REQ for afi/safi: %d/%d",
834 peer
->host
, pkt_afi
, pkt_safi
);
837 /* Add packet to the peer. */
838 bgp_packet_add(peer
, s
);
844 * Create a BGP Capability packet and append it to the peer's output queue.
847 * @param afi Address Family Identifier
848 * @param safi Subsequent Address Family Identifier
849 * @param capability_code BGP Capability Code
850 * @param action Set or Remove capability
852 void bgp_capability_send(struct peer
*peer
, afi_t afi
, safi_t safi
,
853 int capability_code
, int action
)
857 iana_safi_t pkt_safi
;
859 /* Convert AFI, SAFI to values for packet. */
860 bgp_map_afi_safi_int2iana(afi
, safi
, &pkt_afi
, &pkt_safi
);
862 s
= stream_new(BGP_MAX_PACKET_SIZE
);
864 /* Make BGP update packet. */
865 bgp_packet_set_marker(s
, BGP_MSG_CAPABILITY
);
867 /* Encode MP_EXT capability. */
868 if (capability_code
== CAPABILITY_CODE_MP
) {
869 stream_putc(s
, action
);
870 stream_putc(s
, CAPABILITY_CODE_MP
);
871 stream_putc(s
, CAPABILITY_CODE_MP_LEN
);
872 stream_putw(s
, pkt_afi
);
874 stream_putc(s
, pkt_safi
);
876 if (bgp_debug_neighbor_events(peer
))
878 "%s sending CAPABILITY has %s MP_EXT CAP for afi/safi: %d/%d",
880 action
== CAPABILITY_ACTION_SET
? "Advertising"
885 /* Set packet size. */
886 (void)bgp_packet_set_size(s
);
888 /* Add packet to the peer. */
889 bgp_packet_add(peer
, s
);
894 /* RFC1771 6.8 Connection collision detection. */
895 static int bgp_collision_detect(struct peer
*new, struct in_addr remote_id
)
899 /* Upon receipt of an OPEN message, the local system must examine
900 all of its connections that are in the OpenConfirm state. A BGP
901 speaker may also examine connections in an OpenSent state if it
902 knows the BGP Identifier of the peer by means outside of the
903 protocol. If among these connections there is a connection to a
904 remote BGP speaker whose BGP Identifier equals the one in the
905 OPEN message, then the local system performs the following
906 collision resolution procedure: */
908 if ((peer
= new->doppelganger
) != NULL
) {
909 /* Do not accept the new connection in Established or Clearing
911 * Note that a peer GR is handled by closing the existing
913 * upon receipt of new one.
915 if (peer
->status
== Established
|| peer
->status
== Clearing
) {
916 bgp_notify_send(new, BGP_NOTIFY_CEASE
,
917 BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
);
919 } else if ((peer
->status
== OpenConfirm
)
920 || (peer
->status
== OpenSent
)) {
921 /* 1. The BGP Identifier of the local system is compared
923 the BGP Identifier of the remote system (as specified
925 the OPEN message). */
927 if (ntohl(peer
->local_id
.s_addr
)
928 < ntohl(remote_id
.s_addr
))
929 if (!CHECK_FLAG(peer
->sflags
,
930 PEER_STATUS_ACCEPT_PEER
)) {
931 /* 2. If the value of the local BGP
933 than the remote one, the local system
935 connection that already exists (the
937 already in the OpenConfirm state),
939 connection initiated by the remote
942 peer
, BGP_NOTIFY_CEASE
,
943 BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
);
947 new, BGP_NOTIFY_CEASE
,
948 BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
);
952 /* 3. Otherwise, the local system closes newly
954 BGP connection (the one associated with the
956 received OPEN message), and continues to use
958 existing one (the one that is already in the
959 OpenConfirm state). */
960 if (CHECK_FLAG(peer
->sflags
,
961 PEER_STATUS_ACCEPT_PEER
)) {
963 peer
, BGP_NOTIFY_CEASE
,
964 BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
);
968 new, BGP_NOTIFY_CEASE
,
969 BGP_NOTIFY_CEASE_COLLISION_RESOLUTION
);
978 /* Packet processing routines ---------------------------------------------- */
980 * This is a family of functions designed to be called from
981 * bgp_process_packet(). These functions all share similar behavior and should
982 * adhere to the following invariants and restrictions:
986 * The return code of any one of those functions should be one of the FSM event
987 * codes specified in bgpd.h. If a NOTIFY was sent, this event code MUST be
988 * BGP_Stop. Otherwise, the code SHOULD correspond to the function's expected
989 * packet type. For example, bgp_open_receive() should return BGP_Stop upon
990 * error and Receive_OPEN_message otherwise.
992 * If no action is necessary, the correct return code is BGP_PACKET_NOOP as
997 * - May send NOTIFY messages
998 * - May not modify peer->status
999 * - May not call bgp_event_update()
1002 #define BGP_PACKET_NOOP 0
1005 * Process BGP OPEN message for peer.
1007 * If any errors are encountered in the OPEN message, immediately sends NOTIFY
1008 * and returns BGP_Stop.
1011 * @param size size of the packet
1012 * @return as in summary
1014 static int bgp_open_receive(struct peer
*peer
, bgp_size_t size
)
1020 u_int16_t send_holdtime
;
1023 struct in_addr remote_id
;
1025 u_int8_t notify_data_remote_as
[2];
1026 u_int8_t notify_data_remote_as4
[4];
1027 u_int8_t notify_data_remote_id
[4];
1028 u_int16_t
*holdtime_ptr
;
1030 /* Parse open packet. */
1031 version
= stream_getc(peer
->curr
);
1032 memcpy(notify_data_remote_as
, stream_pnt(peer
->curr
), 2);
1033 remote_as
= stream_getw(peer
->curr
);
1034 holdtime_ptr
= (u_int16_t
*)stream_pnt(peer
->curr
);
1035 holdtime
= stream_getw(peer
->curr
);
1036 memcpy(notify_data_remote_id
, stream_pnt(peer
->curr
), 4);
1037 remote_id
.s_addr
= stream_get_ipv4(peer
->curr
);
1039 /* Receive OPEN message log */
1040 if (bgp_debug_neighbor_events(peer
))
1042 "%s rcv OPEN, version %d, remote-as (in open) %u,"
1043 " holdtime %d, id %s",
1044 peer
->host
, version
, remote_as
, holdtime
,
1045 inet_ntoa(remote_id
));
1047 /* BEGIN to read the capability here, but dont do it yet */
1049 optlen
= stream_getc(peer
->curr
);
1052 /* If not enough bytes, it is an error. */
1053 if (STREAM_READABLE(peer
->curr
) < optlen
) {
1054 bgp_notify_send(peer
, BGP_NOTIFY_OPEN_ERR
,
1055 BGP_NOTIFY_OPEN_MALFORMED_ATTR
);
1059 /* We need the as4 capability value *right now* because
1060 * if it is there, we have not got the remote_as yet, and
1062 * that we do not know which peer is connecting to us now.
1064 as4
= peek_for_as4_capability(peer
, optlen
);
1065 memcpy(notify_data_remote_as4
, &as4
, 4);
1068 /* Just in case we have a silly peer who sends AS4 capability set to 0
1070 if (CHECK_FLAG(peer
->cap
, PEER_CAP_AS4_RCV
) && !as4
) {
1071 zlog_err("%s bad OPEN, got AS4 capability, but AS4 set to 0",
1073 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1074 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1075 notify_data_remote_as4
, 4);
1079 if (remote_as
== BGP_AS_TRANS
) {
1080 /* Take the AS4 from the capability. We must have received the
1081 * capability now! Otherwise we have a asn16 peer who uses
1082 * BGP_AS_TRANS, for some unknown reason.
1084 if (as4
== BGP_AS_TRANS
) {
1086 "%s [AS4] NEW speaker using AS_TRANS for AS4, not allowed",
1088 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1089 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1090 notify_data_remote_as4
, 4);
1094 if (!as4
&& BGP_DEBUG(as4
, AS4
))
1096 "%s [AS4] OPEN remote_as is AS_TRANS, but no AS4."
1097 " Odd, but proceeding.",
1099 else if (as4
< BGP_AS_MAX
&& BGP_DEBUG(as4
, AS4
))
1101 "%s [AS4] OPEN remote_as is AS_TRANS, but AS4 (%u) fits "
1102 "in 2-bytes, very odd peer.",
1107 /* We may have a partner with AS4 who has an asno < BGP_AS_MAX
1109 /* If we have got the capability, peer->as4cap must match
1111 if (CHECK_FLAG(peer
->cap
, PEER_CAP_AS4_RCV
)
1112 && as4
!= remote_as
) {
1113 /* raise error, log this, close session */
1115 "%s bad OPEN, got AS4 capability, but remote_as %u"
1116 " mismatch with 16bit 'myasn' %u in open",
1117 peer
->host
, as4
, remote_as
);
1118 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1119 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1120 notify_data_remote_as4
, 4);
1125 /* remote router-id check. */
1126 if (remote_id
.s_addr
== 0 || IPV4_CLASS_DE(ntohl(remote_id
.s_addr
))
1127 || ntohl(peer
->local_id
.s_addr
) == ntohl(remote_id
.s_addr
)) {
1128 if (bgp_debug_neighbor_events(peer
))
1129 zlog_debug("%s bad OPEN, wrong router identifier %s",
1130 peer
->host
, inet_ntoa(remote_id
));
1131 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1132 BGP_NOTIFY_OPEN_BAD_BGP_IDENT
,
1133 notify_data_remote_id
, 4);
1137 /* Set remote router-id */
1138 peer
->remote_id
= remote_id
;
1140 /* Peer BGP version check. */
1141 if (version
!= BGP_VERSION_4
) {
1142 u_int16_t maxver
= htons(BGP_VERSION_4
);
1143 /* XXX this reply may not be correct if version < 4 XXX */
1144 if (bgp_debug_neighbor_events(peer
))
1146 "%s bad protocol version, remote requested %d, local request %d",
1147 peer
->host
, version
, BGP_VERSION_4
);
1148 /* Data must be in network byte order here */
1149 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1150 BGP_NOTIFY_OPEN_UNSUP_VERSION
,
1151 (u_int8_t
*)&maxver
, 2);
1155 /* Check neighbor as number. */
1156 if (peer
->as_type
== AS_UNSPECIFIED
) {
1157 if (bgp_debug_neighbor_events(peer
))
1159 "%s bad OPEN, remote AS is unspecified currently",
1161 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1162 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1163 notify_data_remote_as
, 2);
1165 } else if (peer
->as_type
== AS_INTERNAL
) {
1166 if (remote_as
!= peer
->bgp
->as
) {
1167 if (bgp_debug_neighbor_events(peer
))
1169 "%s bad OPEN, remote AS is %u, internal specified",
1170 peer
->host
, remote_as
);
1171 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1172 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1173 notify_data_remote_as
, 2);
1176 peer
->as
= peer
->local_as
;
1177 } else if (peer
->as_type
== AS_EXTERNAL
) {
1178 if (remote_as
== peer
->bgp
->as
) {
1179 if (bgp_debug_neighbor_events(peer
))
1181 "%s bad OPEN, remote AS is %u, external specified",
1182 peer
->host
, remote_as
);
1183 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1184 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1185 notify_data_remote_as
, 2);
1188 peer
->as
= remote_as
;
1189 } else if ((peer
->as_type
== AS_SPECIFIED
) && (remote_as
!= peer
->as
)) {
1190 if (bgp_debug_neighbor_events(peer
))
1191 zlog_debug("%s bad OPEN, remote AS is %u, expected %u",
1192 peer
->host
, remote_as
, peer
->as
);
1193 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1194 BGP_NOTIFY_OPEN_BAD_PEER_AS
,
1195 notify_data_remote_as
, 2);
1199 /* From the rfc: Upon receipt of an OPEN message, a BGP speaker MUST
1200 calculate the value of the Hold Timer by using the smaller of its
1201 configured Hold Time and the Hold Time received in the OPEN message.
1202 The Hold Time MUST be either zero or at least three seconds. An
1203 implementation may reject connections on the basis of the Hold Time.
1206 if (holdtime
< 3 && holdtime
!= 0) {
1207 bgp_notify_send_with_data(peer
, BGP_NOTIFY_OPEN_ERR
,
1208 BGP_NOTIFY_OPEN_UNACEP_HOLDTIME
,
1209 (u_char
*)holdtime_ptr
, 2);
1213 /* From the rfc: A reasonable maximum time between KEEPALIVE messages
1214 would be one third of the Hold Time interval. KEEPALIVE messages
1215 MUST NOT be sent more frequently than one per second. An
1216 implementation MAY adjust the rate at which it sends KEEPALIVE
1217 messages as a function of the Hold Time interval. */
1219 if (PEER_OR_GROUP_TIMER_SET(peer
))
1220 send_holdtime
= peer
->holdtime
;
1222 send_holdtime
= peer
->bgp
->default_holdtime
;
1224 if (holdtime
< send_holdtime
)
1225 peer
->v_holdtime
= holdtime
;
1227 peer
->v_holdtime
= send_holdtime
;
1229 if ((PEER_OR_GROUP_TIMER_SET(peer
))
1230 && (peer
->keepalive
< peer
->v_holdtime
/ 3))
1231 peer
->v_keepalive
= peer
->keepalive
;
1233 peer
->v_keepalive
= peer
->v_holdtime
/ 3;
1235 /* Open option part parse. */
1237 if ((ret
= bgp_open_option_parse(peer
, optlen
, &mp_capability
))
1241 if (bgp_debug_neighbor_events(peer
))
1242 zlog_debug("%s rcvd OPEN w/ OPTION parameter len: 0",
1247 * Assume that the peer supports the locally configured set of
1248 * AFI/SAFIs if the peer did not send us any Mulitiprotocol
1249 * capabilities, or if 'override-capability' is configured.
1252 || CHECK_FLAG(peer
->flags
, PEER_FLAG_OVERRIDE_CAPABILITY
)) {
1253 peer
->afc_nego
[AFI_IP
][SAFI_UNICAST
] =
1254 peer
->afc
[AFI_IP
][SAFI_UNICAST
];
1255 peer
->afc_nego
[AFI_IP
][SAFI_MULTICAST
] =
1256 peer
->afc
[AFI_IP
][SAFI_MULTICAST
];
1257 peer
->afc_nego
[AFI_IP
][SAFI_LABELED_UNICAST
] =
1258 peer
->afc
[AFI_IP
][SAFI_LABELED_UNICAST
];
1259 peer
->afc_nego
[AFI_IP6
][SAFI_UNICAST
] =
1260 peer
->afc
[AFI_IP6
][SAFI_UNICAST
];
1261 peer
->afc_nego
[AFI_IP6
][SAFI_MULTICAST
] =
1262 peer
->afc
[AFI_IP6
][SAFI_MULTICAST
];
1263 peer
->afc_nego
[AFI_IP6
][SAFI_LABELED_UNICAST
] =
1264 peer
->afc
[AFI_IP6
][SAFI_LABELED_UNICAST
];
1265 peer
->afc_nego
[AFI_L2VPN
][SAFI_EVPN
] =
1266 peer
->afc
[AFI_L2VPN
][SAFI_EVPN
];
1269 /* When collision is detected and this peer is closed. Retrun
1271 ret
= bgp_collision_detect(peer
, remote_id
);
1276 if ((ret
= bgp_getsockname(peer
)) < 0) {
1277 zlog_err("%s: bgp_getsockname() failed for peer: %s",
1278 __FUNCTION__
, peer
->host
);
1282 /* Verify valid local address present based on negotiated
1283 * address-families. */
1284 if (peer
->afc_nego
[AFI_IP
][SAFI_UNICAST
]
1285 || peer
->afc_nego
[AFI_IP
][SAFI_LABELED_UNICAST
]
1286 || peer
->afc_nego
[AFI_IP
][SAFI_MULTICAST
]
1287 || peer
->afc_nego
[AFI_IP
][SAFI_MPLS_VPN
]
1288 || peer
->afc_nego
[AFI_IP
][SAFI_ENCAP
]) {
1289 if (!peer
->nexthop
.v4
.s_addr
) {
1290 #if defined(HAVE_CUMULUS)
1292 "%s: No local IPv4 addr resetting connection, fd %d",
1293 peer
->host
, peer
->fd
);
1294 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
,
1295 BGP_NOTIFY_SUBCODE_UNSPECIFIC
);
1300 if (peer
->afc_nego
[AFI_IP6
][SAFI_UNICAST
]
1301 || peer
->afc_nego
[AFI_IP6
][SAFI_LABELED_UNICAST
]
1302 || peer
->afc_nego
[AFI_IP6
][SAFI_MULTICAST
]
1303 || peer
->afc_nego
[AFI_IP6
][SAFI_MPLS_VPN
]
1304 || peer
->afc_nego
[AFI_IP6
][SAFI_ENCAP
]) {
1305 if (IN6_IS_ADDR_UNSPECIFIED(&peer
->nexthop
.v6_global
)) {
1306 #if defined(HAVE_CUMULUS)
1308 "%s: No local IPv6 addr resetting connection, fd %d",
1309 peer
->host
, peer
->fd
);
1310 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
,
1311 BGP_NOTIFY_SUBCODE_UNSPECIFIC
);
1316 peer
->rtt
= sockopt_tcp_rtt(peer
->fd
);
1318 return Receive_OPEN_message
;
1322 * Process BGP KEEPALIVE message for peer.
1325 * @param size size of the packet
1326 * @return as in summary
1328 static int bgp_keepalive_receive(struct peer
*peer
, bgp_size_t size
)
1330 if (bgp_debug_keepalive(peer
))
1331 zlog_debug("%s KEEPALIVE rcvd", peer
->host
);
1333 bgp_update_implicit_eors(peer
);
1335 return Receive_KEEPALIVE_message
;
1340 * Process BGP UPDATE message for peer.
1342 * Parses UPDATE and creates attribute object.
1345 * @param size size of the packet
1346 * @return as in summary
1348 static int bgp_update_receive(struct peer
*peer
, bgp_size_t size
)
1354 bgp_size_t attribute_len
;
1355 bgp_size_t update_len
;
1356 bgp_size_t withdraw_len
;
1365 struct bgp_nlri nlris
[NLRI_TYPE_MAX
];
1367 /* Status must be Established. */
1368 if (peer
->status
!= Established
) {
1369 zlog_err("%s [FSM] Update packet received under status %s",
1371 lookup_msg(bgp_status_msg
, peer
->status
, NULL
));
1372 bgp_notify_send(peer
, BGP_NOTIFY_FSM_ERR
, 0);
1376 /* Set initial values. */
1377 memset(&attr
, 0, sizeof(struct attr
));
1378 attr
.label_index
= BGP_INVALID_LABEL_INDEX
;
1379 attr
.label
= MPLS_INVALID_LABEL
;
1380 memset(&nlris
, 0, sizeof(nlris
));
1381 memset(peer
->rcvd_attr_str
, 0, BUFSIZ
);
1382 peer
->rcvd_attr_printed
= 0;
1385 end
= stream_pnt(s
) + size
;
1387 /* RFC1771 6.3 If the Unfeasible Routes Length or Total Attribute
1388 Length is too large (i.e., if Unfeasible Routes Length + Total
1389 Attribute Length + 23 exceeds the message Length), then the Error
1390 Subcode is set to Malformed Attribute List. */
1391 if (stream_pnt(s
) + 2 > end
) {
1393 "%s [Error] Update packet error"
1394 " (packet length is short for unfeasible length)",
1396 bgp_notify_send(peer
, BGP_NOTIFY_UPDATE_ERR
,
1397 BGP_NOTIFY_UPDATE_MAL_ATTR
);
1401 /* Unfeasible Route Length. */
1402 withdraw_len
= stream_getw(s
);
1404 /* Unfeasible Route Length check. */
1405 if (stream_pnt(s
) + withdraw_len
> end
) {
1407 "%s [Error] Update packet error"
1408 " (packet unfeasible length overflow %d)",
1409 peer
->host
, withdraw_len
);
1410 bgp_notify_send(peer
, BGP_NOTIFY_UPDATE_ERR
,
1411 BGP_NOTIFY_UPDATE_MAL_ATTR
);
1415 /* Unfeasible Route packet format check. */
1416 if (withdraw_len
> 0) {
1417 nlris
[NLRI_WITHDRAW
].afi
= AFI_IP
;
1418 nlris
[NLRI_WITHDRAW
].safi
= SAFI_UNICAST
;
1419 nlris
[NLRI_WITHDRAW
].nlri
= stream_pnt(s
);
1420 nlris
[NLRI_WITHDRAW
].length
= withdraw_len
;
1421 stream_forward_getp(s
, withdraw_len
);
1424 /* Attribute total length check. */
1425 if (stream_pnt(s
) + 2 > end
) {
1427 "%s [Error] Packet Error"
1428 " (update packet is short for attribute length)",
1430 bgp_notify_send(peer
, BGP_NOTIFY_UPDATE_ERR
,
1431 BGP_NOTIFY_UPDATE_MAL_ATTR
);
1435 /* Fetch attribute total length. */
1436 attribute_len
= stream_getw(s
);
1438 /* Attribute length check. */
1439 if (stream_pnt(s
) + attribute_len
> end
) {
1441 "%s [Error] Packet Error"
1442 " (update packet attribute length overflow %d)",
1443 peer
->host
, attribute_len
);
1444 bgp_notify_send(peer
, BGP_NOTIFY_UPDATE_ERR
,
1445 BGP_NOTIFY_UPDATE_MAL_ATTR
);
1449 /* Certain attribute parsing errors should not be considered bad enough
1450 * to reset the session for, most particularly any partial/optional
1451 * attributes that have 'tunneled' over speakers that don't understand
1452 * them. Instead we withdraw only the prefix concerned.
1454 * Complicates the flow a little though..
1456 bgp_attr_parse_ret_t attr_parse_ret
= BGP_ATTR_PARSE_PROCEED
;
1457 /* This define morphs the update case into a withdraw when lower levels
1458 * have signalled an error condition where this is best.
1460 #define NLRI_ATTR_ARG (attr_parse_ret != BGP_ATTR_PARSE_WITHDRAW ? &attr : NULL)
1462 /* Parse attribute when it exists. */
1463 if (attribute_len
) {
1464 attr_parse_ret
= bgp_attr_parse(peer
, &attr
, attribute_len
,
1465 &nlris
[NLRI_MP_UPDATE
],
1466 &nlris
[NLRI_MP_WITHDRAW
]);
1467 if (attr_parse_ret
== BGP_ATTR_PARSE_ERROR
) {
1468 bgp_attr_unintern_sub(&attr
);
1473 /* Logging the attribute. */
1474 if (attr_parse_ret
== BGP_ATTR_PARSE_WITHDRAW
1475 || BGP_DEBUG(update
, UPDATE_IN
)
1476 || BGP_DEBUG(update
, UPDATE_PREFIX
)) {
1477 ret
= bgp_dump_attr(&attr
, peer
->rcvd_attr_str
, BUFSIZ
);
1479 if (attr_parse_ret
== BGP_ATTR_PARSE_WITHDRAW
)
1481 "%s rcvd UPDATE with errors in attr(s)!! Withdrawing route.",
1484 if (ret
&& bgp_debug_update(peer
, NULL
, NULL
, 1)) {
1485 zlog_debug("%s rcvd UPDATE w/ attr: %s", peer
->host
,
1486 peer
->rcvd_attr_str
);
1487 peer
->rcvd_attr_printed
= 1;
1491 /* Network Layer Reachability Information. */
1492 update_len
= end
- stream_pnt(s
);
1495 /* Set NLRI portion to structure. */
1496 nlris
[NLRI_UPDATE
].afi
= AFI_IP
;
1497 nlris
[NLRI_UPDATE
].safi
= SAFI_UNICAST
;
1498 nlris
[NLRI_UPDATE
].nlri
= stream_pnt(s
);
1499 nlris
[NLRI_UPDATE
].length
= update_len
;
1500 stream_forward_getp(s
, update_len
);
1503 if (BGP_DEBUG(update
, UPDATE_IN
))
1504 zlog_debug("%s rcvd UPDATE wlen %d attrlen %d alen %d",
1505 peer
->host
, withdraw_len
, attribute_len
, update_len
);
1507 /* Parse any given NLRIs */
1508 for (int i
= NLRI_UPDATE
; i
< NLRI_TYPE_MAX
; i
++) {
1512 /* NLRI is processed iff the peer if configured for the specific
1514 if (!peer
->afc
[nlris
[i
].afi
][nlris
[i
].safi
]) {
1516 "%s [Info] UPDATE for non-enabled AFI/SAFI %u/%u",
1517 peer
->host
, nlris
[i
].afi
, nlris
[i
].safi
);
1521 /* EoR handled later */
1522 if (nlris
[i
].length
== 0)
1527 case NLRI_MP_UPDATE
:
1528 nlri_ret
= bgp_nlri_parse(peer
, NLRI_ATTR_ARG
,
1532 case NLRI_MP_WITHDRAW
:
1533 nlri_ret
= bgp_nlri_parse(peer
, &attr
, &nlris
[i
], 1);
1540 zlog_err("%s [Error] Error parsing NLRI", peer
->host
);
1541 if (peer
->status
== Established
)
1543 peer
, BGP_NOTIFY_UPDATE_ERR
,
1545 ? BGP_NOTIFY_UPDATE_INVAL_NETWORK
1546 : BGP_NOTIFY_UPDATE_OPT_ATTR_ERR
);
1547 bgp_attr_unintern_sub(&attr
);
1554 * Non-MP IPv4/Unicast EoR is a completely empty UPDATE
1555 * and MP EoR should have only an empty MP_UNREACH
1557 if ((!update_len
&& !withdraw_len
&&
1558 nlris
[NLRI_MP_UPDATE
].length
== 0) ||
1559 (attr_parse_ret
== BGP_ATTR_PARSE_EOR
)) {
1563 /* Non-MP IPv4/Unicast is a completely emtpy UPDATE - already
1565 * update and withdraw NLRI lengths are 0.
1567 if (!attribute_len
) {
1569 safi
= SAFI_UNICAST
;
1570 } else if (attr
.flag
& ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI
)
1571 && nlris
[NLRI_MP_WITHDRAW
].length
== 0) {
1572 afi
= nlris
[NLRI_MP_WITHDRAW
].afi
;
1573 safi
= nlris
[NLRI_MP_WITHDRAW
].safi
;
1574 } else if (attr_parse_ret
== BGP_ATTR_PARSE_EOR
) {
1575 afi
= nlris
[NLRI_MP_UPDATE
].afi
;
1576 safi
= nlris
[NLRI_MP_UPDATE
].safi
;
1579 if (afi
&& peer
->afc
[afi
][safi
]) {
1580 /* End-of-RIB received */
1581 if (!CHECK_FLAG(peer
->af_sflags
[afi
][safi
],
1582 PEER_STATUS_EOR_RECEIVED
)) {
1583 SET_FLAG(peer
->af_sflags
[afi
][safi
],
1584 PEER_STATUS_EOR_RECEIVED
);
1585 bgp_update_explicit_eors(peer
);
1588 /* NSF delete stale route */
1589 if (peer
->nsf
[afi
][safi
])
1590 bgp_clear_stale_route(peer
, afi
, safi
);
1592 if (bgp_debug_neighbor_events(peer
)) {
1593 zlog_debug("rcvd End-of-RIB for %s from %s",
1594 afi_safi_print(afi
, safi
),
1600 /* Everything is done. We unintern temporary structures which
1601 interned in bgp_attr_parse(). */
1602 bgp_attr_unintern_sub(&attr
);
1604 peer
->update_time
= bgp_clock();
1606 /* Rearm holdtime timer */
1607 BGP_TIMER_OFF(peer
->t_holdtime
);
1608 bgp_timer_set(peer
);
1610 return Receive_UPDATE_message
;
1614 * Process BGP NOTIFY message for peer.
1617 * @param size size of the packet
1618 * @return as in summary
1620 static int bgp_notify_receive(struct peer
*peer
, bgp_size_t size
)
1622 struct bgp_notify bgp_notify
;
1624 if (peer
->notify
.data
) {
1625 XFREE(MTYPE_TMP
, peer
->notify
.data
);
1626 peer
->notify
.data
= NULL
;
1627 peer
->notify
.length
= 0;
1630 bgp_notify
.code
= stream_getc(peer
->curr
);
1631 bgp_notify
.subcode
= stream_getc(peer
->curr
);
1632 bgp_notify
.length
= size
- 2;
1633 bgp_notify
.data
= NULL
;
1635 /* Preserv notify code and sub code. */
1636 peer
->notify
.code
= bgp_notify
.code
;
1637 peer
->notify
.subcode
= bgp_notify
.subcode
;
1638 /* For further diagnostic record returned Data. */
1639 if (bgp_notify
.length
) {
1640 peer
->notify
.length
= size
- 2;
1641 peer
->notify
.data
= XMALLOC(MTYPE_TMP
, size
- 2);
1642 memcpy(peer
->notify
.data
, stream_pnt(peer
->curr
), size
- 2);
1651 if (bgp_notify
.length
) {
1653 XMALLOC(MTYPE_TMP
, bgp_notify
.length
* 3);
1654 for (i
= 0; i
< bgp_notify
.length
; i
++)
1657 stream_getc(peer
->curr
));
1658 strcat(bgp_notify
.data
, c
);
1662 stream_getc(peer
->curr
));
1663 strcpy(bgp_notify
.data
, c
);
1665 bgp_notify
.raw_data
= (u_char
*)peer
->notify
.data
;
1668 bgp_notify_print(peer
, &bgp_notify
, "received");
1669 if (bgp_notify
.data
) {
1670 XFREE(MTYPE_TMP
, bgp_notify
.data
);
1671 bgp_notify
.data
= NULL
;
1672 bgp_notify
.length
= 0;
1676 /* peer count update */
1679 peer
->last_reset
= PEER_DOWN_NOTIFY_RECEIVED
;
1681 /* We have to check for Notify with Unsupported Optional Parameter.
1682 in that case we fallback to open without the capability option.
1683 But this done in bgp_stop. We just mark it here to avoid changing
1685 if (bgp_notify
.code
== BGP_NOTIFY_OPEN_ERR
1686 && bgp_notify
.subcode
== BGP_NOTIFY_OPEN_UNSUP_PARAM
)
1687 UNSET_FLAG(peer
->sflags
, PEER_STATUS_CAPABILITY_OPEN
);
1689 return Receive_NOTIFICATION_message
;
1693 * Process BGP ROUTEREFRESH message for peer.
1696 * @param size size of the packet
1697 * @return as in summary
1699 static int bgp_route_refresh_receive(struct peer
*peer
, bgp_size_t size
)
1703 iana_safi_t pkt_safi
;
1706 struct peer_af
*paf
;
1707 struct update_group
*updgrp
;
1708 struct peer
*updgrp_peer
;
1710 /* If peer does not have the capability, send notification. */
1711 if (!CHECK_FLAG(peer
->cap
, PEER_CAP_REFRESH_ADV
)) {
1712 zlog_err("%s [Error] BGP route refresh is not enabled",
1714 bgp_notify_send(peer
, BGP_NOTIFY_HEADER_ERR
,
1715 BGP_NOTIFY_HEADER_BAD_MESTYPE
);
1719 /* Status must be Established. */
1720 if (peer
->status
!= Established
) {
1722 "%s [Error] Route refresh packet received under status %s",
1724 lookup_msg(bgp_status_msg
, peer
->status
, NULL
));
1725 bgp_notify_send(peer
, BGP_NOTIFY_FSM_ERR
, 0);
1732 pkt_afi
= stream_getw(s
);
1733 (void)stream_getc(s
);
1734 pkt_safi
= stream_getc(s
);
1736 if (bgp_debug_update(peer
, NULL
, NULL
, 0))
1737 zlog_debug("%s rcvd REFRESH_REQ for afi/safi: %d/%d",
1738 peer
->host
, pkt_afi
, pkt_safi
);
1740 /* Convert AFI, SAFI to internal values and check. */
1741 if (bgp_map_afi_safi_iana2int(pkt_afi
, pkt_safi
, &afi
, &safi
)) {
1743 "%s REFRESH_REQ for unrecognized afi/safi: %d/%d - ignored",
1744 peer
->host
, pkt_afi
, pkt_safi
);
1745 return BGP_PACKET_NOOP
;
1748 if (size
!= BGP_MSG_ROUTE_REFRESH_MIN_SIZE
- BGP_HEADER_SIZE
) {
1750 u_char when_to_refresh
;
1754 if (size
- (BGP_MSG_ROUTE_REFRESH_MIN_SIZE
- BGP_HEADER_SIZE
)
1756 zlog_info("%s ORF route refresh length error",
1758 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
, 0);
1762 when_to_refresh
= stream_getc(s
);
1763 end
= stream_pnt(s
) + (size
- 5);
1765 while ((stream_pnt(s
) + 2) < end
) {
1766 orf_type
= stream_getc(s
);
1767 orf_len
= stream_getw(s
);
1769 /* orf_len in bounds? */
1770 if ((stream_pnt(s
) + orf_len
) > end
)
1771 break; /* XXX: Notify instead?? */
1772 if (orf_type
== ORF_TYPE_PREFIX
1773 || orf_type
== ORF_TYPE_PREFIX_OLD
) {
1774 uint8_t *p_pnt
= stream_pnt(s
);
1775 uint8_t *p_end
= stream_pnt(s
) + orf_len
;
1776 struct orf_prefix orfp
;
1781 int ret
= CMD_SUCCESS
;
1783 if (bgp_debug_neighbor_events(peer
)) {
1785 "%s rcvd Prefixlist ORF(%d) length %d",
1786 peer
->host
, orf_type
, orf_len
);
1789 /* we're going to read at least 1 byte of common
1791 * and 7 bytes of ORF Address-filter entry from
1797 /* ORF prefix-list name */
1798 sprintf(name
, "%s.%d.%d", peer
->host
, afi
,
1801 while (p_pnt
< p_end
) {
1802 /* If the ORF entry is malformed, want
1803 * to read as much of it
1804 * as possible without going beyond the
1805 * bounds of the entry,
1806 * to maximise debug information.
1810 sizeof(struct orf_prefix
));
1812 /* after ++: p_pnt <= p_end */
1814 & ORF_COMMON_PART_REMOVE_ALL
) {
1815 if (bgp_debug_neighbor_events(
1818 "%s rcvd Remove-All pfxlist ORF request",
1820 prefix_bgp_orf_remove_all(afi
,
1824 ok
= ((u_int32_t
)(p_end
- p_pnt
)
1825 >= sizeof(u_int32_t
));
1829 p_pnt
+= sizeof(u_int32_t
);
1830 orfp
.seq
= ntohl(seq
);
1834 if ((ok
= (p_pnt
< p_end
)))
1838 prefix_bgp_orf_set()
1840 if ((ok
= (p_pnt
< p_end
)))
1844 prefix_bgp_orf_set()
1846 if ((ok
= (p_pnt
< p_end
)))
1847 orfp
.p
.prefixlen
= *p_pnt
++;
1848 orfp
.p
.family
= afi2family(
1849 afi
); /* afi checked already */
1852 orfp
.p
.prefixlen
); /* 0 if not
1856 &orfp
.p
)) /* valid for
1860 psize
= prefix_blen(&orfp
.p
);
1863 > (p_end
- p_pnt
)) /* valid for
1867 psize
= p_end
- p_pnt
;
1871 memcpy(&orfp
.p
.u
.prefix
, p_pnt
,
1875 if (bgp_debug_neighbor_events(peer
)) {
1876 char buf
[INET6_BUFSIZ
];
1879 "%s rcvd %s %s seq %u %s/%d ge %d le %d%s",
1881 (common
& ORF_COMMON_PART_REMOVE
1884 (common
& ORF_COMMON_PART_DENY
1895 ok
? "" : " MALFORMED");
1899 ret
= prefix_bgp_orf_set(
1901 (common
& ORF_COMMON_PART_DENY
1904 (common
& ORF_COMMON_PART_REMOVE
1908 if (!ok
|| (ok
&& ret
!= CMD_SUCCESS
)) {
1910 "%s Received misformatted prefixlist ORF."
1911 " Remove All pfxlist",
1913 prefix_bgp_orf_remove_all(afi
,
1919 peer
->orf_plist
[afi
][safi
] =
1920 prefix_bgp_orf_lookup(afi
, name
);
1922 stream_forward_getp(s
, orf_len
);
1924 if (bgp_debug_neighbor_events(peer
))
1925 zlog_debug("%s rcvd Refresh %s ORF request", peer
->host
,
1926 when_to_refresh
== REFRESH_DEFER
1929 if (when_to_refresh
== REFRESH_DEFER
)
1930 return BGP_PACKET_NOOP
;
1933 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1934 if (CHECK_FLAG(peer
->af_sflags
[afi
][safi
],
1935 PEER_STATUS_ORF_WAIT_REFRESH
))
1936 UNSET_FLAG(peer
->af_sflags
[afi
][safi
],
1937 PEER_STATUS_ORF_WAIT_REFRESH
);
1939 paf
= peer_af_find(peer
, afi
, safi
);
1940 if (paf
&& paf
->subgroup
) {
1941 if (peer
->orf_plist
[afi
][safi
]) {
1942 updgrp
= PAF_UPDGRP(paf
);
1943 updgrp_peer
= UPDGRP_PEER(updgrp
);
1944 updgrp_peer
->orf_plist
[afi
][safi
] =
1945 peer
->orf_plist
[afi
][safi
];
1948 /* If the peer is configured for default-originate clear the
1949 * SUBGRP_STATUS_DEFAULT_ORIGINATE flag so that we will
1953 if (CHECK_FLAG(paf
->subgroup
->sflags
,
1954 SUBGRP_STATUS_DEFAULT_ORIGINATE
))
1955 UNSET_FLAG(paf
->subgroup
->sflags
,
1956 SUBGRP_STATUS_DEFAULT_ORIGINATE
);
1959 /* Perform route refreshment to the peer */
1960 bgp_announce_route(peer
, afi
, safi
);
1962 /* No FSM action necessary */
1963 return BGP_PACKET_NOOP
;
1967 * Parse BGP CAPABILITY message for peer.
1970 * @param size size of the packet
1971 * @return as in summary
1973 static int bgp_capability_msg_parse(struct peer
*peer
, u_char
*pnt
,
1977 struct capability_mp_data mpc
;
1978 struct capability_header
*hdr
;
1982 iana_safi_t pkt_safi
;
1988 /* We need at least action, capability code and capability
1990 if (pnt
+ 3 > end
) {
1991 zlog_info("%s Capability length error", peer
->host
);
1992 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
, 0);
1996 hdr
= (struct capability_header
*)(pnt
+ 1);
1998 /* Action value check. */
1999 if (action
!= CAPABILITY_ACTION_SET
2000 && action
!= CAPABILITY_ACTION_UNSET
) {
2001 zlog_info("%s Capability Action Value error %d",
2002 peer
->host
, action
);
2003 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
, 0);
2007 if (bgp_debug_neighbor_events(peer
))
2009 "%s CAPABILITY has action: %d, code: %u, length %u",
2010 peer
->host
, action
, hdr
->code
, hdr
->length
);
2012 /* Capability length check. */
2013 if ((pnt
+ hdr
->length
+ 3) > end
) {
2014 zlog_info("%s Capability length error", peer
->host
);
2015 bgp_notify_send(peer
, BGP_NOTIFY_CEASE
, 0);
2019 /* Fetch structure to the byte stream. */
2020 memcpy(&mpc
, pnt
+ 3, sizeof(struct capability_mp_data
));
2021 pnt
+= hdr
->length
+ 3;
2023 /* We know MP Capability Code. */
2024 if (hdr
->code
== CAPABILITY_CODE_MP
) {
2025 pkt_afi
= ntohs(mpc
.afi
);
2026 pkt_safi
= mpc
.safi
;
2028 /* Ignore capability when override-capability is set. */
2029 if (CHECK_FLAG(peer
->flags
,
2030 PEER_FLAG_OVERRIDE_CAPABILITY
))
2033 /* Convert AFI, SAFI to internal values. */
2034 if (bgp_map_afi_safi_iana2int(pkt_afi
, pkt_safi
, &afi
,
2036 if (bgp_debug_neighbor_events(peer
))
2038 "%s Dynamic Capability MP_EXT afi/safi invalid "
2040 peer
->host
, pkt_afi
, pkt_safi
);
2044 /* Address family check. */
2045 if (bgp_debug_neighbor_events(peer
))
2047 "%s CAPABILITY has %s MP_EXT CAP for afi/safi: %u/%u",
2049 action
== CAPABILITY_ACTION_SET
2054 if (action
== CAPABILITY_ACTION_SET
) {
2055 peer
->afc_recv
[afi
][safi
] = 1;
2056 if (peer
->afc
[afi
][safi
]) {
2057 peer
->afc_nego
[afi
][safi
] = 1;
2058 bgp_announce_route(peer
, afi
, safi
);
2061 peer
->afc_recv
[afi
][safi
] = 0;
2062 peer
->afc_nego
[afi
][safi
] = 0;
2064 if (peer_active_nego(peer
))
2065 bgp_clear_route(peer
, afi
, safi
);
2071 "%s unrecognized capability code: %d - ignored",
2072 peer
->host
, hdr
->code
);
2076 /* No FSM action necessary */
2077 return BGP_PACKET_NOOP
;
2081 * Parse BGP CAPABILITY message for peer.
2083 * Exported for unit testing.
2086 * @param size size of the packet
2087 * @return as in summary
2089 int bgp_capability_receive(struct peer
*peer
, bgp_size_t size
)
2093 /* Fetch pointer. */
2094 pnt
= stream_pnt(peer
->curr
);
2096 if (bgp_debug_neighbor_events(peer
))
2097 zlog_debug("%s rcv CAPABILITY", peer
->host
);
2099 /* If peer does not have the capability, send notification. */
2100 if (!CHECK_FLAG(peer
->cap
, PEER_CAP_DYNAMIC_ADV
)) {
2101 zlog_err("%s [Error] BGP dynamic capability is not enabled",
2103 bgp_notify_send(peer
, BGP_NOTIFY_HEADER_ERR
,
2104 BGP_NOTIFY_HEADER_BAD_MESTYPE
);
2108 /* Status must be Established. */
2109 if (peer
->status
!= Established
) {
2111 "%s [Error] Dynamic capability packet received under status %s",
2113 lookup_msg(bgp_status_msg
, peer
->status
, NULL
));
2114 bgp_notify_send(peer
, BGP_NOTIFY_FSM_ERR
, 0);
2119 return bgp_capability_msg_parse(peer
, pnt
, size
);
2123 * Processes a peer's input buffer.
2125 * This function sidesteps the event loop and directly calls bgp_event_update()
2126 * after processing each BGP message. This is necessary to ensure proper
2127 * ordering of FSM events and unifies the behavior that was present previously,
2128 * whereby some of the packet handling functions would update the FSM and some
2129 * would not, making event flow difficult to understand. Please think twice
2130 * before hacking this.
2132 * Thread type: THREAD_EVENT
2136 int bgp_process_packet(struct thread
*thread
)
2138 /* Yes first of all get peer pointer. */
2139 struct peer
*peer
; // peer
2140 uint32_t rpkt_quanta_old
; // how many packets to read
2141 int fsm_update_result
; // return code of bgp_event_update()
2142 int mprc
; // message processing return code
2144 peer
= THREAD_ARG(thread
);
2146 * This functionality is presently disabled. Unfortunately due to the
2147 * way bgpd is structured, reading more than one packet per input cycle
2148 * severely impacts convergence time. This is because advancing the
2149 * state of the routing table based on prefixes learned from one peer
2150 * prior to all (or at least most) peers being established and placed
2151 * into an update-group will make UPDATE generation starve
2152 * bgp_accept(), delaying convergence. This is a deficiency that needs
2153 * to be fixed elsewhere in the codebase, but for now our hand is
2157 rpkt_quanta_old
= atomic_load_explicit(&peer
->bgp
->rpkt_quanta
,
2158 memory_order_relaxed
);
2160 rpkt_quanta_old
= 1;
2161 fsm_update_result
= 0;
2163 /* Guard against scheduled events that occur after peer deletion. */
2164 if (peer
->status
== Deleted
|| peer
->status
== Clearing
)
2167 unsigned int processed
= 0;
2169 while (processed
< rpkt_quanta_old
) {
2172 char notify_data_length
[2];
2174 pthread_mutex_lock(&peer
->io_mtx
);
2176 peer
->curr
= stream_fifo_pop(peer
->ibuf
);
2178 pthread_mutex_unlock(&peer
->io_mtx
);
2180 if (peer
->curr
== NULL
) // no packets to process, hmm...
2183 /* skip the marker and copy the packet length */
2184 stream_forward_getp(peer
->curr
, BGP_MARKER_SIZE
);
2185 memcpy(notify_data_length
, stream_pnt(peer
->curr
), 2);
2187 /* read in the packet length and type */
2188 size
= stream_getw(peer
->curr
);
2189 type
= stream_getc(peer
->curr
);
2191 /* BGP packet dump function. */
2192 bgp_dump_packet(peer
, type
, peer
->curr
);
2194 /* adjust size to exclude the marker + length + type */
2195 size
-= BGP_HEADER_SIZE
;
2197 /* Read rest of the packet and call each sort of packet routine
2202 mprc
= bgp_open_receive(peer
, size
);
2203 if (mprc
== BGP_Stop
)
2205 "%s: BGP OPEN receipt failed for peer: %s",
2206 __FUNCTION__
, peer
->host
);
2208 case BGP_MSG_UPDATE
:
2210 peer
->readtime
= monotime(NULL
);
2211 mprc
= bgp_update_receive(peer
, size
);
2212 if (mprc
== BGP_Stop
)
2214 "%s: BGP UPDATE receipt failed for peer: %s",
2215 __FUNCTION__
, peer
->host
);
2217 case BGP_MSG_NOTIFY
:
2219 mprc
= bgp_notify_receive(peer
, size
);
2220 if (mprc
== BGP_Stop
)
2222 "%s: BGP NOTIFY receipt failed for peer: %s",
2223 __FUNCTION__
, peer
->host
);
2225 case BGP_MSG_KEEPALIVE
:
2226 peer
->readtime
= monotime(NULL
);
2227 peer
->keepalive_in
++;
2228 mprc
= bgp_keepalive_receive(peer
, size
);
2229 if (mprc
== BGP_Stop
)
2231 "%s: BGP KEEPALIVE receipt failed for peer: %s",
2232 __FUNCTION__
, peer
->host
);
2234 case BGP_MSG_ROUTE_REFRESH_NEW
:
2235 case BGP_MSG_ROUTE_REFRESH_OLD
:
2237 mprc
= bgp_route_refresh_receive(peer
, size
);
2238 if (mprc
== BGP_Stop
)
2240 "%s: BGP ROUTEREFRESH receipt failed for peer: %s",
2241 __FUNCTION__
, peer
->host
);
2243 case BGP_MSG_CAPABILITY
:
2244 peer
->dynamic_cap_in
++;
2245 mprc
= bgp_capability_receive(peer
, size
);
2246 if (mprc
== BGP_Stop
)
2248 "%s: BGP CAPABILITY receipt failed for peer: %s",
2249 __FUNCTION__
, peer
->host
);
2253 * The message type should have been sanitized before
2254 * we ever got here. Receipt of a message with an
2255 * invalid header at this point is indicative of a
2258 assert (!"Message of invalid type received during input processing");
2261 /* delete processed packet */
2262 stream_free(peer
->curr
);
2267 if (mprc
!= BGP_PACKET_NOOP
)
2268 fsm_update_result
= bgp_event_update(peer
, mprc
);
2273 * If peer was deleted, do not process any more packets. This
2274 * is usually due to executing BGP_Stop or a stub deletion.
2276 if (fsm_update_result
== FSM_PEER_TRANSFERRED
2277 || fsm_update_result
== FSM_PEER_STOPPED
)
2281 if (fsm_update_result
!= FSM_PEER_TRANSFERRED
2282 && fsm_update_result
!= FSM_PEER_STOPPED
) {
2283 pthread_mutex_lock(&peer
->io_mtx
);
2285 // more work to do, come back later
2286 if (peer
->ibuf
->count
> 0)
2287 thread_add_timer_msec(
2288 bm
->master
, bgp_process_packet
, peer
, 0,
2289 &peer
->t_process_packet
);
2291 pthread_mutex_unlock(&peer
->io_mtx
);