Commit graph

363 commits

Author SHA1 Message Date
Donald Sharp 2a3f51cf6b bgpd: Add accessor for bgp_attr.pmsi_tnl_type
Add an accessor for the bgp_attr.pmsi_tnl_type to allow
us to abstract where it is.  Every attribute is paying
the price of this bit of data as part of `struct bgp_attr`
In the future we'll move it elsewhere.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-15 09:44:47 -05:00
Donald Sharp df7d4670ea bgpd: Allow NULL to be passed in for ecommunity_free
Allow some cleanup of if statements to just make
ecommunity_free() check this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-15 09:39:25 -05:00
Anuradha Karuppiah 74e2bd891d bgpd: support for DF election in EVPN-MH
DF (Designated forwarder) election is used for picking a single
BUM-traffic forwarded per-ES. RFC7432 specifies a mechanism called
service carving for DF election. However that mechanism has many
disadvantages -
1. LBs poorly.
2. Doesn't allow for a controlled failover needed in upgrade
scenarios.
3. Not easy to hw accelerate.

To fix the poor performance of service carving alternate DF mechanisms
have been proposed via the following drafts -
draft-ietf-bess-evpn-df-election-framework
draft-ietf-bess-evpn-pref-df

This commit adds support for the pref-df election mechanism which
is used as the default. Other mechanisms including service-carving
may be added later.

In this mechanism one switch on an ES is elected as DF based on the
preference value; higher preference wins with IP address acting
as the tie-breaker (lower-IP wins if pref value is the same).

Sample output
=============
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
torm-11# sh bgp l2vpn evpn es 03:00:00:00:00:01:11:00:00:01
ESI: 03:00:00:00:00:01:11:00:00:01
 Type: LR
 RD: 27.0.0.15:6
 Originator-IP: 27.0.0.15
 Local ES DF preference: 100
 VNI Count: 10
 Remote VNI Count: 10
 Inconsistent VNI VTEP Count: 0
 Inconsistencies: -
 VTEPs:
  27.0.0.16 flags: EA df_alg: preference df_pref: 32767
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
torm-11# sh bgp l2vpn evpn route esi 03:00:00:00:00:01:11:00:00:01
*> [4]:[03:00:00:00:00:01:11:00:00:01]:[32]:[27.0.0.15]
                    27.0.0.15                          32768 i
                    ET:8 ES-Import-Rt:00:00:00:00:01:11 DF: (alg: 2, pref: 100)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2020-10-26 10:26:21 -07:00
Donatas Abraitis 23d0a75356 bgpd: Convert inet_ntoa to %pI4/inet_ntop
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-18 11:22:30 +03:00
vivek 637e5ba492 bgpd: Define function to check if performing graceful shutdown
Signed-off-by: Vivek Venkatraman <vivek@nvidia.com>
2020-09-19 12:50:46 -07:00
Renato Westphal dcdaabcede
Merge pull request #7046 from qlyoung/fix-various-integer-issues
Fix various integer signedness / overflow issues
2020-09-04 22:33:48 -03:00
Renato Westphal c7b5a0ae3a
Merge pull request #7055 from qlyoung/fix-bgp-localpref-overflow
bgpd: fix asserting read of localpref
2020-09-04 18:56:46 -03:00
Quentin Young 763a5d3c2d bgpd: use stream_rewind_getp() to remove overflow
Passing a negative argument to a size_t parameter creates an overflow
condition

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-09-03 14:23:57 -04:00
Quentin Young ad61f7780e bgpd: fix asserting read of localpref
Attribute may not be long enough to contain a localpref value, resulting
in an assert on stream size. Gracefully handle this case instead.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-09-03 14:10:33 -04:00
Sebastien Merle ef3e0d0476 bgpd: Add support for SR-TE Policies in route-maps
Example configuration:
    route-map SET_SR_POLICY permit 10
     set sr-te color 1
     !
    router bgp 1
     bgp router-id 1.1.1.1
     neighbor 2.2.2.2 remote-as 1
     neighbor 2.2.2.2 update-source lo
     address-family ipv4 unicast
      neighbor 2.2.2.2 next-hop-self
      neighbor 2.2.2.2 route-map SET_SR_POLICY in
     exit-address-family
     !
    !
Learned BGP routes from 2.2.2.2 are mapped to the SR-TE Policy
which is uniquely determined by the BGP nexthop (2.2.2.2 in this
case) and the SR-TE color in the route-map.

Co-authored-by: Renato Westphal <renato@opensourcerouting.org>
Co-authored-by: GalaxyGorilla <sascha@netdef.org>
Co-authored-by: Sebastien Merle <sebastien@netdef.org>
Signed-off-by: Sebastien Merle <sebastien@netdef.org>
2020-08-31 09:09:12 +00:00
Philippe Guibert c6423c3153 bgp, zebra: add some alignments with remarks from community
align the code to remarks from community.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-08-21 13:37:08 +02:00
Philippe Guibert 9a659715df bgpd: support for bgp ipv6 ext community, and flowspec redirect ipv6
rfc 5701 is supported. it is possible to configure in bgp vpn, a list of
route target with ipv6 external communities to import. it is to be noted
that this ipv6 external community has been developed only for matching a
bgp flowspec update with same ipv6 ext commmunity.
adding to this, draft-ietf-idr-flow-spec-v6-09 is implemented regarding
the redirect ipv6 option.

Practically, under bgp vpn, under ipv6 unicast, it is possible to
configure : [no] rt6 redirect import <IPV6>:<AS> values.

An incoming bgp update with fs ipv6 and that option matching a bgp vrf,
will be imported in that bgp vrf.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-08-21 13:37:08 +02:00
Donatas Abraitis 99ab4d233d bgpd: Use sizeof() in bgp_dump_attr()
Missed this in 5022c8331d

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-08-19 15:57:26 +03:00
Donatas Abraitis 599f7b330d bgpd: Dump attributes before returning from bgp_attr_malformed()
This would be handy for situations when a notification was sent, but it's
absolutely not clear who triggered that.

Just in case dumping all attributes under the debug mode would help finding
the _bad_ attribute.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-08-13 18:42:31 +03:00
Anuradha Karuppiah 7904e9fdfa bgpd: extended-community and attrs for MAC-IP SYNC route handling
A new proxy flag has been added to the already existing NA extended
community to allow proxy advertisment of a local host by a VTEP that is
yet to indpendently establish local reachability.
Reference: draft-rbickhart-evpn-ip-mac-proxy-adv

The extendend mac-mobility sequence number needs to be synced across
the ES peers. However we cannot let a ES-peer path win over a local
path on the same ES. To accomplish that some parameters such as the
MM seq number are bubbled up from the non-best path to the local path.
This mechanism is explained further in the path-selection patch.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2020-08-05 06:46:12 -07:00
Anuradha Karuppiah 0a50c24813 bgpd: attr changes for EAD routes
Add ESI as an inline attribute field along with the other EVPN
attributes. This may be re-worked when the rest of the EVPN
attributes find a new home.

Some cleanup has been done to get rid of stale/unused references
to ESI. And also to consolidate duplicate definitions of ES ID
types.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2020-08-05 06:46:12 -07:00
David Lamparter 6cde4b4552 *: remove PRI[udx](8|16|32)
These are completely pointless and break coccinelle string replacements.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --pri8-16-32 `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:43:40 +02:00
David Lamparter 3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00
Donatas Abraitis cbfc39df11 bgpd: Ignore aggregator attribute if it's malformed (0.0.0.0)
This is not the attribute involved in path selection and by rfc7606 it should
be just ignored.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-05-06 12:55:55 +03:00
Donatas Abraitis 6ded3e181b bgpd: Use slightly modified version of error message if AS path contains 0
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-05-06 12:55:13 +03:00
Donatas Abraitis c4efd0f423 *: Do not cast to the same type
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-04-08 17:15:06 +03:00
Russ White a6c322ab18
Merge pull request #6173 from ton31337/fix/treat-as-withdraw_community
bgpd: Treat-as-withdraw if [el]community length is zero
2020-04-07 11:42:01 -04:00
Donatas Abraitis 6680b5508c bgpd: Treat-as-withdraw if [el]community length is zero
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-04-07 10:08:16 +03:00
Quentin Young 33ba22c248 bgpd: treat 0-length cluster_list as withdraw
See source comment...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-06 12:30:35 -04:00
Quentin Young 628565c73d bgpd: fix multiple bugs with cluster_list attrs
Multiple different issues causing mostly UAFs but maybe other more
subtle things.

- Cluster lists were the only attributes whose pointers were not being
  NULL'd when freed, resulting in heap UAF
- When performing an insert into the cluster hash, our temporary struct
  used for hash_get() was inconsistent with our hash keying and
  comparison functions. In the case of a zero length cluster list, the
  ->length field is 0 and the ->list field is NULL. When performing an
  insert, we set the ->list field regardless of whether the length is 0.
  This resulted in the two cluster lists hashing equal but not comparing
  equal. Later, when removing one of them from the hash before freeing
  it, because the key matched and the comparison succeeded (because it
  was set to NULL *after* the search but *before* inserting into the
  hash) we would sometimes release the duplicated copy of the struct,
  and then free the one that remained in the hash table. Later accesses
  constitute UAF. This is fixed by making sure the fields used for the
  existence check match what is actually inserted into the hash when
  that check fails.

This patch also makes cluster_unintern static, because it should be.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-05 20:55:02 -04:00
Sri Mohana Singamsetty 70ecc066e7
Merge pull request #6105 from vivek-cumulus/bgp_link_bandwidth_unequal_cost_multipath
Unequal cost multipath (a.ka. weighted ECMP) with BGP link-bandwidth
2020-04-05 11:41:42 -07:00
Quentin Young f22ed884c1 bgpd: fix memcmp(null, *) when parsing bgp attrs
My first patch for this only fixed the memcmp(NULL, NULL) case.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-05 01:02:42 -04:00
vivek d901dc13cb bgpd: Check and extract link bandwidth value
Extract link bandwidth value into attribute from the extended
community, if present.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2020-03-30 20:12:31 -07:00
Sri Mohana Singamsetty 0298bb01bb
Merge pull request #6085 from donaldsharp/bgp_node_get_prefix
Bgp node get prefix
2020-03-26 19:07:36 -07:00
Donald Sharp 5f040085ba lib, bgpd: Another round of struct const prefix cleanup
Cleanup another set of functions that need to respect the
const'ness of a prefix.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-03-26 16:22:00 -04:00
Donatas Abraitis 0f2a703d5e bgpd: Print readable error message when parsing AGGREGATOR attribute
Having a full feed this leads to unknown. You can't point which prefix or
aspath has this malforming behavior.

Printing just `[EC 33554434] AGGREGATOR attribute is BGP_AS_ZERO(0)` isn't
enough, you can't directly pin-point where is the problem.

Additionally print at least aspath here:
```
[EC 33554434] AGGREGATOR AS number is 0 for aspath: 65000 65031
```

Overall the full table has only 6 such malformed prefixes:
```
aspath: 64539 15096 6939 45430 45458
aspath: 64539 15096 6939 1299 3257 34984 34984 34984 34984 34984 51174
aspath: 64539 15096 6939 286 34984 16135 16135 {16135}
aspath: 64539 15096 6939 7545 7545 136001
aspath: 64539 15096 6939 6762 3269 20746
aspath: 64539 15096 6939 7018 3379
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-26 16:06:00 +02:00
Donald Sharp bd494ec5ed bgpd: More const struct prefix work
Modify more code to use `const struct prefix` throughout
bgp.  This is all prep work for adding an accessor function
for bgp_node to get the prefix and reduce all the places that
code needs to be touched when we get that work done.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-03-22 14:50:46 -04:00
Donatas Abraitis 3dc339cdc2 bgpd: Convert lots of int type functions to bool/void
Some were converted to bool, where true/false status is needed.
Converted to void only those, where the return status was only false or true.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-21 14:59:18 +02:00
Quentin Young 9c23deece2
Merge pull request #6045 from rubenk/bgpd-use-correct-format-specifier
bgpd: use the right format specifier
2020-03-19 13:55:04 -04:00
Quentin Young cbbd3b30ba
Merge pull request #5755 from slankdev/bgpd-fix-prefix-sid-parse-error
bgpd: fix Prefix-SID parse error
2020-03-19 12:28:36 -04:00
Ruben Kerkhof cc92ee388c bgpd: use the right format specifier
Fixes:
/Library/Developer/CommandLineTools/usr/bin/make  all-am
  CC       bgpd/bgp_attr.o
bgpd/bgp_attr.c:2664:5: warning: format specifies type 'unsigned char' but the argument has type 'uint16_t' (aka 'unsigned short') [-Wformat]
                                length, STREAM_READABLE(peer->curr));
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./lib/log.h:94:50: note: expanded from macro 'flog_err'
        zlog_err("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
                                     ~~~~~~             ^~~~~~~~~~~
1 warning generated.

Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2020-03-19 14:00:20 +01:00
Russ White 047315df42
Merge pull request #5954 from ton31337/feature/rfc7607
bgpd: Proscribe the use of AS 0 (zero)
2020-03-17 10:27:35 -04:00
Donatas Abraitis 33d022bcf6 bgpd: Proscribe the use of AS 0 (zero)
Implements https://tools.ietf.org/html/rfc7607

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-17 13:31:23 +02:00
Ruben Kerkhof 1e20238af5 treewide: fix some issues found with -Werror=undef
Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2020-03-10 16:53:13 +01:00
Quentin Young 340594a929 bgpd: properly initialize SRv6 attributes
We were using XMALLOC for these, and only initializing the refcount to 0
on one of them. Let's just use XCALLOC instead...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-03-05 16:15:32 -05:00
Quentin Young b502ca1165 bgpd: correctly handle repeated SRv6 attributes
Repeating SRv6 attributes N times leaks (N-1)*32 bytes of memory.

Fix it!

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-03-05 16:15:01 -05:00
Hiroki Shirokura 45a06b11a6 bgpd: refactor func prototype arround Prefix-SID
mp_update value isn't used by the function arround Prefix-SID.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2020-02-14 00:13:43 +00:00
Hiroki Shirokura e5d4cda0a7 bgpd: fix Prefix-SID parsing failure case
Prefix-SID path attribute Label-index TLV (type-1) is
used by SR-MPLS. And Label-index TLV MUST ignored
if that path attribute is append on non-Labeled-unicast
UPDATE message described on [ref1].
There is a problem case exist arround this implementation.
This commit fix that.

Before this commit,
unfortunally, setting Label-Index value is skipped at somecases.
because, Label-Index TLV implementation check the AFI/SAFI pair.
by mp_update variable that is set by bgp_mp_reach_parse function.
if MP_REACH_NLRI is present after PREFIX_SID, bgp_attr_psid_sub
function can't understand AFI/SAFI pair. and the order of each
path attributes is never no-deterministic thing for receiver.[ref2]

In this commit,
I re-located checking code of AFI/SAFI pair after path-attr loop.

[ref1](https://tools.ietf.org/html/draft-ietf-idr-bgp-prefix-sid-27#section-3.2)
> The Originator SRGB TLV may only appear in a BGP Prefix-SID attribute
> attached to IPv4/IPv6 Labeled Unicast prefixes ([RFC8277]).  It MUST
> be ignored when received for other BGP AFI/SAFI combinations.

[ref2](https://tools.ietf.org/html/rfc4271#section-5)
> The sender of an UPDATE message SHOULD order path attributes within
> the UPDATE message in ascending order of attribute type.  The
> receiver of an UPDATE message MUST be prepared to handle path
> attributes within UPDATE messages that are out of order.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2020-02-14 00:13:43 +00:00
Hiroki Shirokura 38774fc5e6 bgpd: fix Prefix-SID parse error
Prefix-SID is desined to capable for TLV array.
That behaviour is important to support SR-MPLS feature
and that supported by previous PR #5418.

In that implementation, but if some additional data
(such as next BGP update message or next path attributes)
was present after Prefix-SID path attribute,
bgpd will parse that addional data as Prefix-SID TLV.

This commit fix that. before this commit, loop condition
is determed by stream is readable or not. In more correct
implementatoin, the prefix-sid boundaly should be checked
additonally. the length of Prefix-sid path attribute can
be get by bgp_attr_parse_args.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2020-02-14 00:13:43 +00:00
Russ White 35f50b9305
Merge pull request #5744 from ton31337/fix/thread-as-withdraw_attributes
bgpd: Update some attributes how they are handled if malformed
2020-02-11 10:04:19 -05:00
Donatas Abraitis 892fedb611 bgpd: Replace bgp_flag_* to [UN]SET/CHECK_FLAG macros
Most of the code uses macros, thus let's keep the code unified.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-06 17:11:38 +02:00
Donatas Abraitis 975a328e2e *: Replace s_addr 0 => INADDR_ANY
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-06 09:00:12 +02:00
Donatas Abraitis 4ba5a9c55f bgpd: Update some attributes how they are handled if malformed
According to https://tools.ietf.org/html/rfc7606 some of the attributes
MUST be handled as "treat-as-withdraw" approach.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-05 11:01:39 +02:00
Quentin Young 03ed0334e8
Merge pull request #5717 from pguibert6WIND/flowspec_issue_redistribute
Flowspec issue redistribute
2020-02-04 15:48:24 -05:00
Philippe Guibert f1af8f04e7 bgpd: forge bgp flowspec packets to be sent
bgp flowspec packets are being forged correctly. There is no need to
check for bgp length, as the bgp nlri length is checked at reception.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-02-04 17:40:11 +01:00