2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/* BGP packet management header.
|
2017-05-13 10:25:29 +02:00
|
|
|
* Copyright (C) 1999 Kunihiro Ishiguro
|
|
|
|
*/
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-05-23 16:19:54 +02:00
|
|
|
#ifndef _QUAGGA_BGP_PACKET_H
|
|
|
|
#define _QUAGGA_BGP_PACKET_H
|
|
|
|
|
2019-04-24 17:19:09 +02:00
|
|
|
#include "hook.h"
|
|
|
|
|
2025-01-14 17:57:45 +01:00
|
|
|
struct bgp_enhe_capability {
|
|
|
|
uint16_t afi;
|
|
|
|
uint16_t safi;
|
|
|
|
uint16_t nh_afi;
|
|
|
|
};
|
|
|
|
|
2019-04-24 17:19:09 +02:00
|
|
|
DECLARE_HOOK(bgp_packet_dump,
|
|
|
|
(struct peer *peer, uint8_t type, bgp_size_t size,
|
|
|
|
struct stream *s),
|
|
|
|
(peer, type, size, s));
|
|
|
|
|
2019-05-10 19:29:01 +02:00
|
|
|
DECLARE_HOOK(bgp_packet_send,
|
|
|
|
(struct peer *peer, uint8_t type, bgp_size_t size,
|
|
|
|
struct stream *s),
|
|
|
|
(peer, type, size, s));
|
|
|
|
|
2004-10-13 07:06:08 +02:00
|
|
|
#define BGP_NLRI_LENGTH 1U
|
|
|
|
#define BGP_TOTAL_ATTR_LEN 2U
|
|
|
|
#define BGP_UNFEASIBLE_LEN 2U
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* When to refresh */
|
|
|
|
#define REFRESH_IMMEDIATE 1
|
2019-09-17 10:27:03 +02:00
|
|
|
#define REFRESH_DEFER 2
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* ORF Common part flag */
|
2019-09-17 10:27:03 +02:00
|
|
|
#define ORF_COMMON_PART_ADD 0x00
|
|
|
|
#define ORF_COMMON_PART_REMOVE 0x80
|
|
|
|
#define ORF_COMMON_PART_REMOVE_ALL 0xC0
|
|
|
|
#define ORF_COMMON_PART_PERMIT 0x00
|
|
|
|
#define ORF_COMMON_PART_DENY 0x20
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2020-01-31 19:04:00 +01:00
|
|
|
#define BGP_UPDATE_EOR_PKT(_peer, _afi, _safi, _s) \
|
|
|
|
do { \
|
|
|
|
_s = bgp_update_packet_eor(_peer, _afi, _safi); \
|
|
|
|
if (_s) { \
|
2023-08-28 19:04:26 +02:00
|
|
|
bgp_packet_add(_peer->connection, _peer, _s); \
|
2020-01-31 19:04:00 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
2019-10-24 12:21:18 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Packet send and receive function prototypes. */
|
2023-04-05 20:51:47 +02:00
|
|
|
extern void bgp_keepalive_send(struct peer *peer);
|
2023-04-13 15:28:32 +02:00
|
|
|
extern struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as);
|
2023-08-27 03:31:54 +02:00
|
|
|
extern void bgp_open_send(struct peer_connection *connection);
|
2023-08-26 23:30:10 +02:00
|
|
|
extern void bgp_notify_send(struct peer_connection *connection, uint8_t code,
|
|
|
|
uint8_t sub_code);
|
|
|
|
extern void bgp_notify_send_with_data(struct peer_connection *connection,
|
|
|
|
uint8_t code, uint8_t sub_code,
|
|
|
|
uint8_t *data, size_t datalen);
|
2022-09-08 22:14:36 +02:00
|
|
|
void bgp_notify_io_invalid(struct peer *peer, uint8_t code, uint8_t sub_code,
|
|
|
|
uint8_t *data, size_t datalen);
|
2020-10-01 22:08:06 +02:00
|
|
|
extern void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
|
|
|
|
uint8_t orf_type, uint8_t when_to_refresh,
|
|
|
|
int remove, uint8_t subtype);
|
2023-04-05 20:51:47 +02:00
|
|
|
extern void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
|
|
|
|
int capabilty_code, int action);
|
2005-05-23 16:19:54 +02:00
|
|
|
|
2023-08-27 05:55:10 +02:00
|
|
|
extern int bgp_capability_receive(struct peer_connection *connection,
|
|
|
|
struct peer *peer, bgp_size_t length);
|
2023-04-05 20:51:47 +02:00
|
|
|
extern int bgp_nlri_parse(struct peer *peer, struct attr *attr,
|
2023-04-05 21:25:57 +02:00
|
|
|
struct bgp_nlri *nlri, bool mp_withdraw);
|
bgpd: Regularise bgp_update_receive, add missing notifies and checks
* bgp_packet.c: (bgp_update_receive) Lots of repeated code, doing same
thing for each AFI/SAFI. Except when it doesn't, e.g. the IPv4/VPN
case was missing the EoR bgp_clear_stale_route call - the only action
really needed for EoR.
Make this function a lot more regular, using common, AFI/SAFI
independent blocks so far as possible.
Replace the 4 separate bgp_nlris with an array, indexed by an enum.
The distinct blocks that handle calling bgp_nlri_parse for each
different AFI/SAFI can now be replaced with a loop.
Transmogrify the nlri SAFI from the SAFI_MPLS_LABELED_VPN code-point
used on the wire, to the SAFI_MPLS_VPN safi_t enum we use internally
as early as possible.
The existing code was not necessarily sending a NOTIFY for NLRI
parsing errors, if they arose via bgp_nlri_sanity_check. Send the
correct NOTIFY - INVAL_NETWORK for the classic NLRIs and OPT_ATTR_ERR
for the MP ones.
EoR can now be handled in one block. The existing code seemed broken
for EoR recognition in a number of ways:
1. A v4/unicast EoR should be an empty UPDATE. However, it seemed
to be treating an UPDATE with attributes, inc. MP REACH/UNREACH,
but no classic NLRIs, as a v4/uni EoR.
2. For other AFI/SAFIs, it was treating UPDATEs with no classic
withraw and with a zero-length MP withdraw as EoRs. However, that
would mean an UPDATE packet _with_ update NLRIs and a 0-len MP
withdraw could be classed as an EoR.
This seems to be loose coding leading to ambiguous protocol
situations and likely incorrect behaviour, rather than simply being
liberal. Be more strict about checking that an UPDATE really is an
EoR and definitely is not trying to update any NLRIs.
This same loose EoR parsing was noted by Chris Hall previously on
list.
(bgp_nlri_parse) Front end NLRI parse function, to fan-out to the correct
parser for the AFI/SAFI.
* bgp_route.c: (bgp_nlri_sanity_check) We try convert NLRI safi to
internal code-point ASAP, adjust switch for that. Leave the wire
code point in for defensive coding.
(bgp_nlri_parse) rename to bgp_nlri_parse_ip.
* tests/bgp_mp_attr_test.c: Can just use bgp_nlri_parse frontend.
2016-02-04 14:27:04 +01:00
|
|
|
|
2023-04-05 20:51:47 +02:00
|
|
|
extern void bgp_update_restarted_peers(struct peer *peer);
|
|
|
|
extern void bgp_update_implicit_eors(struct peer *peer);
|
|
|
|
extern void bgp_check_update_delay(struct bgp *peer);
|
2015-05-20 03:03:47 +02:00
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
extern int bgp_packet_set_marker(struct stream *s, uint8_t type);
|
2021-11-29 20:23:53 +01:00
|
|
|
extern void bgp_packet_set_size(struct stream *s);
|
2017-02-07 00:39:06 +01:00
|
|
|
|
2022-03-01 22:18:12 +01:00
|
|
|
extern void bgp_generate_updgrp_packets(struct event *event);
|
|
|
|
extern void bgp_process_packet(struct event *event);
|
2015-05-20 03:03:47 +02:00
|
|
|
|
2019-10-24 16:59:43 +02:00
|
|
|
extern void bgp_send_delayed_eor(struct bgp *bgp);
|
2021-03-09 17:13:41 +01:00
|
|
|
|
|
|
|
/* Task callback to handle socket error encountered in the io pthread */
|
2022-03-01 22:18:12 +01:00
|
|
|
void bgp_packet_process_error(struct event *thread);
|
2022-04-30 22:04:58 +02:00
|
|
|
extern struct bgp_notify
|
|
|
|
bgp_notify_decapsulate_hard_reset(struct bgp_notify *notify);
|
2022-05-11 18:42:53 +02:00
|
|
|
extern bool bgp_has_graceful_restart_notification(struct peer *peer);
|
2022-05-06 09:21:15 +02:00
|
|
|
extern bool bgp_notify_send_hard_reset(struct peer *peer, uint8_t code,
|
|
|
|
uint8_t subcode);
|
|
|
|
extern bool bgp_notify_received_hard_reset(struct peer *peer, uint8_t code,
|
|
|
|
uint8_t subcode);
|
2021-03-09 17:13:41 +01:00
|
|
|
|
2005-05-23 16:19:54 +02:00
|
|
|
#endif /* _QUAGGA_BGP_PACKET_H */
|