Commit Graph

498 Commits

Author SHA1 Message Date
Donatas Abraitis
bcb6b58d95 bgpd: Use treat-as-withdraw for tunnel encapsulation attribute
Before this path we used session reset method, which is discouraged by rfc7606.

Handle this as rfc requires.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-29 16:09:26 +03:00
Donald Sharp
673a11a54f
Merge pull request #14232 from opensourcerouting/fix/aigp_validation_bytes
bgpd: Make sure we have enough data to read two bytes when validating AIGP
2023-08-24 07:43:59 -04:00
Donatas Abraitis
f96201e104 bgpd: Make sure we have enough data to read two bytes when validating AIGP
Found when fuzzing:

```
==3470861==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xffff77801ef7 at pc 0xaaaaba7b3dbc bp 0xffffcff0e760 sp 0xffffcff0df50
READ of size 2 at 0xffff77801ef7 thread T0
    0 0xaaaaba7b3db8 in __asan_memcpy (/home/ubuntu/frr_8_5_2/frr_8_5_2_fuzz_clang/bgpd/bgpd+0x363db8) (BuildId: cc710a2356e31c7f4e4a17595b54de82145a6e21)
    1 0xaaaaba81a8ac in ptr_get_be16 /home/ubuntu/frr_8_5_2/frr_8_5_2_fuzz_clang/./lib/stream.h:399:2
    2 0xaaaaba819f2c in bgp_attr_aigp_valid /home/ubuntu/frr_8_5_2/frr_8_5_2_fuzz_clang/bgpd/bgp_attr.c:504:3
    3 0xaaaaba808c20 in bgp_attr_aigp /home/ubuntu/frr_8_5_2/frr_8_5_2_fuzz_clang/bgpd/bgp_attr.c:3275:7
    4 0xaaaaba7ff4e0 in bgp_attr_parse /home/ubuntu/frr_8_5_2/frr_8_5_2_fuzz_clang/bgpd/bgp_attr.c:3678:10
```

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-20 21:26:00 +03:00
Donatas Abraitis
f023a2e03f bgpd: Treat-as-withdraw attribute if remaining data is not enough
Relax this handling (RFC 7606) only for eBGP peers.

More details: https://datatracker.ietf.org/doc/html/rfc7606#section-4

There are two error cases in which the Total Attribute Length value
can be in conflict with the enclosed path attributes, which
themselves carry length values:

    * In the first case, the length of the last encountered path
    attribute would cause the Total Attribute Length to be exceeded
    when parsing the enclosed path attributes.

    * In the second case, fewer than three octets remain (or fewer than
    four octets, if the Attribute Flags field has the Extended Length
    bit set) when beginning to parse the attribute.  That is, this
    case exists if there remains unconsumed data in the path
    attributes but yet insufficient data to encode a single minimum-
    sized path attribute. <<<< HANDLING THIS CASE IN THIS COMMIT >>>>

In either of these cases, an error condition exists and the "treat-
as-withdraw" approach MUST be used (unless some other, more severe
error is encountered dictating a stronger approach), and the Total
Attribute Length MUST be relied upon to enable the beginning of the
NLRI field to be located.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-16 11:14:39 +03:00
Samanvitha B Bhargav
32f91a88b6 bgpd: Fix update message error handling for multiple same attributes
As per RFC7606 section 3g,
   g.  If the MP_REACH_NLRI attribute or the MP_UNREACH_NLRI [RFC4760]
       attribute appears more than once in the UPDATE message, then a
       NOTIFICATION message MUST be sent with the Error Subcode
       "Malformed Attribute List".  If any other attribute (whether
       recognized or unrecognized) appears more than once in an UPDATE
       message, then all the occurrences of the attribute other than the
       first one SHALL be discarded and the UPDATE message will continue
       to be processed.
However, notification is sent out currently for all the cases.
Fix:
For cases other than MP_REACH_NLRI & MP_UNREACH_NLRI, handling has been updated
to discard the occurrences other than the first one and proceed with further parsing.
Again, the handling is relaxed only for the EBGP case.
Also, since in case of error, the attribute is discarded &
stream pointer is being adjusted accordingly based on length,
the total attribute length sanity check case has been moved up in the function
to be checked before this case.

Signed-off-by: Samanvitha B Bhargav <bsamanvitha@vmware.com>
2023-08-12 04:10:05 -07:00
Samanvitha B Bhargav
e9e304e810 bgpd: Fix update message error handling for total attribute length
As per RFC7606 section 4,
when the total attribute length value is in conflict with the
enclosed attribute length, treat-as-withdraw approach must be followed.
However, notification is being sent out for this case currently,
that leads to session reset.
Fix:
The handling has been updated to conform to treat-as-withdraw
approach only for EBGP case. For IBGP, since we are not following
treat-as-withdraw approach for any of the error handling cases,
the existing behavior is retained for the IBGP.

Signed-off-by: Samanvitha B Bhargav <bsamanvitha@vmware.com>
2023-08-12 04:07:21 -07:00
Donatas Abraitis
fa2749f58e bgpd: Handle srv6 attributes the same way as others using setters/getters
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:53:21 +03:00
Donatas Abraitis
312b8c02a6 bgpd: Handle encap attributes the same way as others using setters/getters
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:52:09 +03:00
Donatas Abraitis
09b4537755 bgpd: Handle transit attributes the same way as others using setters/getters
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:48:40 +03:00
Donatas Abraitis
0a0137da85 bgpd: Handle cluster attribute the same way as others using setters/getters
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-03 22:44:17 +03:00
Donald Sharp
7415f1e120
Merge pull request #14129 from samanvithab/bgpd_frr_fix
bgpd: Fix for session reset issue caused by malformed core attributes  in update message
2023-08-02 13:48:14 -04:00
Samanvitha B Bhargav
70ff940fd1 bgpd: Fix session reset issue caused by malformed core attributes
RCA:
On encountering any attribute error for core attributes in update message,
the error handling is set to 'treat as withdraw' and
further parsing of the remaining attributes is skipped.
But the stream pointer is not being correctly adjusted to
point to the next NLRI field skipping the rest of the attributes.
This leads to incorrect parsing of the NLRI field,
which causes BGP session to reset.

Fix:
The stream pointer offset is rightly adjusted to point to the NLRI field correctly
when the malformed attribute is encountered and remaining attribute parsing is skipped.

Signed-off-by: Samanvitha B Bhargav <bsamanvitha@vmware.com>
2023-08-01 23:17:19 -07:00
Russ White
220d7b1a89
Merge pull request #13948 from opensourcerouting/fix/bgpd_rfc7606_adjustments
bgpd: Some rfc7606 adjustments
2023-07-11 10:19:30 -04:00
Donatas Abraitis
79563af564 bgpd: Get 1 or 2 octets for Sub-TLV length (Tunnel Encap attr)
The total number of octets of the Sub-TLV Value field. The Sub-TLV Length field
contains 1 octet if the Sub-TLV Type field contains a value in the range from
0-127. The Sub-TLV Length field contains two octets if the Sub-TLV Type field
contains a value in the range from 128-255.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-07-10 16:05:18 +03:00
Donatas Abraitis
29196a6a5f bgpd: Check if cluster list attribute is not received via eBGP session
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-07-07 23:02:18 +03:00
Donatas Abraitis
c1ccfa977a bgpd: Check if originator-id attribute is not received via eBGP session
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-07-07 23:01:13 +03:00
Donatas Abraitis
4199f032e5
Merge pull request #13722 from fdumontet6WIND/color_extcomm
bgpd,lib,yang: add colored extended communities support
2023-06-27 13:03:22 +03:00
Francois Dumontet
442e2edcfa bgpd: add functions related to srte_color management
Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2023-06-26 14:27:27 +02:00
Russ White
56a10caa03
Merge pull request #12971 from taspelund/trey/mac_vrf_soo_upstream
bgpd: Add MAC-VRF Site-of-Origin support
2023-06-20 09:08:28 -04:00
Yuan Yuan
32af4995aa bgpd: fix bgpd core when unintern attr
When the remote peer is neither EBGP nor confed, aspath is the
shadow copy of attr->aspath in bgp_packet_attribute(). Striping
AS4_PATH should not be done on the aspath directly, since
that would lead to bgpd core dump when unintern the attr.

Signed-off-by: Yuan Yuan <yyuanam@amazon.com>
2023-05-30 22:49:07 +00:00
Trey Aspelund
badc4857aa bgpd: add EVPN reimport handler for martian change
Adds a generalized martian reimport function used for triggering a
relearn/reimport of EVPN routes that were previously filtered/deleted
as a result of a "self" check (either during import or by a martian
change handler). The MAC-VRF SoO is the first consumer of this function,
but can be expanded for use with Martian Tunnel-IPs, Interface-IPs,
Interface-MACs, and RMACs.

Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2023-05-30 15:20:35 +00:00
Chirag Shah
ff8bebd2a6 bgpd: fix aggregate route display
Based on RFC-4760, if NEXT_HOP attribute is not
suppose to be set if MP_REACH_NLRI NLRI is used.
for IPv4 aggregate route only NEXT_HOP attribute
with ipv4 prefixlen needs to be set.

Testing Done:

Before fix:
----------
aggregate route:
*> 184.123.0.0/16   ::(TORC11)               0         32768 i

After fix:
---------
aggregate route:
*> 184.123.0.0/16   0.0.0.0(TORC11)          0         32768 i
* i                 peerlink-3               0    100      0 i
*                   uplink1                                0 4435 5546 i
   184.123.1.0/24   0.0.0.0(TORC11)          0         32768 i
s> 184.123.8.0/22   0.0.0.0(TORC11)          0         32768 i

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2023-05-19 14:45:49 -07:00
Donatas Abraitis
53afb27eb8 bgpd: Make sure AIGP attribute is non-transitive
The AIGP attribute is an optional, non-transitive BGP path attribute.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-05-08 23:20:04 +03:00
Donald Sharp
06431bfa75 bgpd: Ensure stream received has enough data
BGP_PREFIX_SID_SRV6_L3_SERVICE attributes must not
fully trust the length value specified in the nlri.
Always ensure that the amount of data we need to read
can be fullfilled.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-29 07:59:49 -04:00
Donald Sharp
d8bc11a592 *: Add a hash_clean_and_free() function
Add a hash_clean_and_free() function as well as convert
the code to use it.  This function also takes a double
pointer to the hash to set it NULL.  Also it cleanly
does nothing if the pointer is NULL( as a bunch of
code tested for ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21 08:54:21 -04:00
Russ White
e1ee742b53
Merge pull request #12890 from pguibert6WIND/attr_cleaning_misc
bgp attribute cleaning misc
2023-03-07 09:46:24 -05:00
Donatas Abraitis
9930441c66 bgpd: Avoid double aspath_dup() for confederation when remote-as != AS_SPECIFIED
Just was blind when not seing it's already dup'ed above:

```	if (peer->sort == BGP_PEER_EBGP
	    && (!CHECK_FLAG(peer->af_flags[afi][safi],
			    PEER_FLAG_AS_PATH_UNCHANGED)
		|| attr->aspath->segments == NULL)
	    && (!CHECK_FLAG(peer->af_flags[afi][safi],
			    PEER_FLAG_RSERVER_CLIENT))) {
		aspath = aspath_dup(attr->aspath); <<<<<<<<<<<<<<<
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-24 22:03:08 +02:00
Philippe Guibert
6a38127745 bgpd: apply clang style changes to bgp_attr
Now that an additional attribute has been added, clang
format has to be applied.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-24 08:18:18 +01:00
Donatas Abraitis
db5a5ee6e4 bgpd: Pass global ASN for confederation peers if not AS_SPECIFIED
When we specify remote-as as external/internal, we need to set local_as to
bgp->as, instead of bgp->confed_id. Before this patch, (bgp->as != *as) is
always valid for such a case because *as is always 0.

Also, append peer->local_as as CONFED_SEQ to avoid other side withdrawing
the routes due to confederation own AS received and/or malformed as-path.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-22 00:00:53 +02:00
Russ White
9a4bb5e469
Merge pull request #12795 from pguibert6WIND/vpnv6_nexthop_encoding
Vpnv6 nexthop encoding
2023-02-21 08:15:43 -05:00
Russ White
ba755d35e5
Merge pull request #12248 from pguibert6WIND/bgpasdot
lib, bgp: add initial support for asdot format
2023-02-21 08:01:03 -05:00
Donald Sharp
8383d53e43
Merge pull request #12780 from opensourcerouting/spdx-license-id
*: convert to SPDX License identifiers
2023-02-17 09:43:05 -05:00
Philippe Guibert
558e8f5801 bgpd: factorise ipv6 vpn nexthop encoding
Because mp_nexthop_len attribute value stands for the length
to encode in the stream, simplify the way the nexthop is
forged.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-15 17:02:15 +01:00
Philippe Guibert
629d84f512 bgpd: fix dereference of null pointer in bgp_attr_aspath
The peer pointer theorically have a NULL bgp pointer. This triggers
a SA issue. So let us fix it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10 10:27:23 +01:00
Philippe Guibert
17571c4ae7 bgpd: aspath list format binds on as-notation format
Each BGP prefix may have an as-path list attached. A forged
string is stored in the BGP attribute and shows the as-path
list output.

Before this commit, the as-path list output was expressed as
a list of AS values in plain format. Now, if a given BGP instance
uses a specific asnotation, then the output is changed:

new output:
router bgp 1.1 asnotation dot
!
 address-family ipv4 unicast
  network 10.200.0.0/24 route-map rmap
  network 10.201.0.0/24 route-map rmap
  redistribute connected route-map rmap
 exit-address-family
exit
!
route-map rmap permit 1
 set as-path prepend 1.1 5433.55 264564564
exit

ubuntu2004# do show bgp ipv4
BGP table version is 2, local router ID is 10.0.2.15, vrf id 0
Default local pref 100, local AS 1.1
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path
 *> 4.4.4.4/32       0.0.0.0                  0         32768 1.1 5433.55 4036.61268 ?
 *> 10.0.2.0/24      0.0.0.0                  0         32768 1.1 5433.55 4036.61268 ?
    10.200.0.0/24    0.0.0.0                  0         32768 1.1 5433.55 4036.61268 i
    10.201.0.0/24    0.0.0.0                  0         32768 1.1 5433.55 4036.61268 i

The changes include:
- the aspath structure has a new field: asnotation type
The ashash list will differentiate 2 aspaths using a different
asnotation.
- 3 new printf extensions display the as number in the wished
format: pASP, pASD, pASE for plain, dot, or dot+ format (extended).

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10 10:27:23 +01:00
David Lamparter
acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donatas Abraitis
e2863b4ff5 bgpd: Add neighbor path-attribute treat-as-withdraw command
To filter out routes with unwanted prefixes.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-01 22:57:34 +02:00
Donatas Abraitis
b986d7f41a bgpd: Add missing no form for neighbor path-attribute discard cmd
Just forgot this _somehow_ :)

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-22 22:17:39 +02:00
Philippe Guibert
35ac9b53f2 bgpd: fix vpnv6 nexthop encoding
In ipv6 vpn, when the global and the local ipv6 address are received,
when re-transmitting the bgp ipv6 update, the nexthop attribute
length must still be 48 bytes.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-01-20 08:22:20 +01:00
Donatas Abraitis
a5c6a9b18e bgpd: Add neighbor path-attribute discard command
The idea is to drop unwanted attributes from the BGP UPDATE messages and
continue by just ignoring them. This improves the security, flexiblity, etc.

This is the command that Cisco has also.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-14 21:29:41 +02:00
Donald Sharp
2bb8b49ce1 Revert "Merge pull request #11127 from louis-6wind/bgp-leak"
This reverts commit 16aa1809e7, reversing
changes made to f616e71608.
2023-01-13 08:13:52 -05:00
Donatas Abraitis
f5540d6d41 bgpd: Drop deprecated BGP_ATTR_AS_PATHLIMIT path attribute
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-01-06 14:40:49 +02:00
Russ White
16aa1809e7
Merge pull request #11127 from louis-6wind/bgp-leak
bgpd: multiple fixes for route leaking
2022-12-27 14:51:28 -05:00
Donatas Abraitis
af9aee79f9 bgpd: Check if bgp_path_info is not NULL when setting AIGP metric TLV
*** CID 1530035:  Null pointer dereferences  (FORWARD_NULL)
/bgpd/bgp_updgrp_packet.c: 756 in subgroup_update_packet()
750                              * position.
751                              */
752                             mpattr_pos = stream_get_endp(s);
753
754                             /* 5: Encode all the attributes, except MP_REACH_NLRI
755                              * attr. */
>>>     CID 1530035:  Null pointer dereferences  (FORWARD_NULL)
>>>     Passing null pointer "path" to "bgp_packet_attribute", which dereferences it.
756                             total_attr_len = bgp_packet_attribute(
757                                     NULL, peer, s, adv->baa->attr, &vecarr, NULL,
758                                     afi, safi, from, NULL, NULL, 0, 0, 0, path);
759
760                             space_remaining =
761                                     STREAM_CONCAT_REMAIN(s, snlri, STREAM_SIZE(s))

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-12-20 09:48:43 +02:00
Louis Scalbert
ce82e90260 bgpd: fix attrhash_cmp() clang-format
Fix attrhash_cmp() clang-format

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 15:09:36 +01:00
Louis Scalbert
6030b8b40d bgpd: update route leaking when a VRF loopback is received
At bgpd startup, VRF instances are sent from zebra before the
interfaces. When importing a l3vpn prefix from another local VRF
instance, the interfaces are not known yet. The prefix nexthop interface
cannot be set to the loopback or the VRF interface, which causes setting
invalid routes in zebra.

Update route leaking when the loopback or a VRF interface is received
from zebra.

At a VRF interface deletion, zebra voluntarily sends a
ZEBRA_INTERFACE_ADD message to move it to VRF_DEFAULT. Do not update if
such a message is received. VRF destruction will destroy all the related
routes without adding codes.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 14:52:47 +01:00
Louis Scalbert
1e24860bf7 bgpd: fix prefix VRF leaking with 'network import-check' (4/5)
If 'network import-check' is defined on the source BGP session, prefixes
that are stated in the network command cannot be leaked to the other
VRFs BGP table even if they are present in the origin VRF RIB if the
'rt import' statement is defined after the 'network <prefix>' ones.

When a prefix nexthop is updated, update the prefix route leaking. The
current state of nexthop validation is now stored in the attributes of
the bgp path info. Attributes are compared with the previous ones at
route leaking update so that a nexthop validation change now triggers
the update of destination VRF BGP table.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16 14:52:47 +01:00
Donald Sharp
233b1a3860 bgpd: Convert bgp_packet_mpattr_prefix to use an enum for safi's
The function bgp_packet_mpattr_prefix was using an if statement
to encode packets to the peer.  Change it to a switch and make
it handle all the cases and fail appropriately when something
has gone wrong.  Hopefully in the future when a new afi/safi
is added we can catch it by compilation breaking instead of
weird runtime errors

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-16 08:43:16 -05:00
Donald Sharp
722e8011e1 bgpd: make bgp_packet_mpattr_start more prescriptive when using enum's
This function was just using default: case statements for
the encoding of nlri's to a peer.  Lay out all the different
cases and make things fail hard when a dev escape is found.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-16 08:17:18 -05:00
Donald Sharp
4487f0bd2c bgpd: Convert bgp_packet_mpattr_prefix_size to use an enum
The function bgp_packet_mpattr_prefix_size had an if/else
body that allowed people to add encoding types to bgpd
such that we could build the wrong size packets.  This
was exposed recently in commit:
0a9705a1e0

Where it was discovered flowspec was causing bgp update
messages to exceed the maximum size and the peer to
drop the connection.  Let's be proscriptive about this
and hopefully make it so that things don't work when
someone adds a new safi to the system ( and they'll have
to update this function ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-16 07:58:54 -05:00