]> git.puffer.fish Git - mirror/frr.git/log
mirror/frr.git
12 months agobgpd: Prevent from one more CVE triggering this place 15659/head
Donatas Abraitis [Wed, 27 Mar 2024 17:08:38 +0000 (19:08 +0200)]
bgpd: Prevent from one more CVE triggering this place

If we receive an attribute that is handled by bgp_attr_malformed(), use
treat-as-withdraw behavior for unknown (or missing to add - if new) attributes.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit babb23b74855e23c987a63f8256d24e28c044d07)

12 months agobgpd: Fix error handling when receiving BGP Prefix SID attribute
Donatas Abraitis [Wed, 27 Mar 2024 16:42:56 +0000 (18:42 +0200)]
bgpd: Fix error handling when receiving BGP Prefix SID attribute

Without this patch, we always set the BGP Prefix SID attribute flag without
checking if it's malformed or not. RFC8669 says that this attribute MUST be discarded.

Also, this fixes the bgpd crash when a malformed Prefix SID attribute is received,
with malformed transitive flags and/or TLVs.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit ba6a8f1a31e1a88df2de69ea46068e8bd9b97138)

13 months agoMerge pull request #15568 from opensourcerouting/fix/backport_bgp_filter_fun_8.5
Russ White [Tue, 19 Mar 2024 14:36:56 +0000 (10:36 -0400)]
Merge pull request #15568 from opensourcerouting/fix/backport_bgp_filter_fun_8.5

BGP memory backports

13 months agobgpd: Ensure community data is freed in some cases. 15568/head
Donald Sharp [Sat, 2 Mar 2024 14:50:38 +0000 (09:50 -0500)]
bgpd: Ensure community data is freed in some cases.

Customer has this valgrind trace:

Direct leak of 2829120 byte(s) in 70728 object(s) allocated from:
  0 in community_new ../bgpd/bgp_community.c:39
  1 in community_uniq_sort ../bgpd/bgp_community.c:170
  2 in route_set_community ../bgpd/bgp_routemap.c:2342
  3 in route_map_apply_ext ../lib/routemap.c:2673
  4 in subgroup_announce_check ../bgpd/bgp_route.c:2367
  5 in subgroup_process_announce_selected ../bgpd/bgp_route.c:2914
  6 in group_announce_route_walkcb ../bgpd/bgp_updgrp_adv.c:199
  7 in hash_walk ../lib/hash.c:285
  8 in update_group_af_walk ../bgpd/bgp_updgrp.c:2061
  9 in group_announce_route ../bgpd/bgp_updgrp_adv.c:1059
 10 in bgp_process_main_one ../bgpd/bgp_route.c:3221
 11 in bgp_process_wq ../bgpd/bgp_route.c:3221
 12 in work_queue_run ../lib/workqueue.c:282

The above leak detected by valgrind was from a screenshot so I copied it
by hand.  Any mistakes in line numbers are purely from my transcription.
Additionally this is against a slightly modified 8.5.1 version of FRR.
Code inspection of 8.5.1 -vs- latest master shows the same problem
exists.  Code should be able to be followed from there to here.

What is happening:

There is a route-map being applied that modifes the outgoing community
to a peer.  This is saved in the attr copy created in
subgroup_process_announce_selected.  This community pointer is not
interned.  So the community->refcount is still 0.  Normally when
a prefix is announced, the attr and the prefix are placed on a
adjency out structure where the attribute is interned.  This will
cause the community to be saved in the community hash list as well.
In a non-normal operation when the decision to send is aborted after
the route-map application, the attribute is just dropped and the
pointer to the community is just dropped too, leading to situations
where the memory is leaked.  The usage of bgp suppress-fib would
would be a case where the community is caused to be leaked.
Additionally the previous commit where an unsuppress-map is used
to modify the outgoing attribute but since unsuppress-map was
not considered part of outgoing policy the attribute would be dropped as
well.  This pointer drop also extends to any dynamically allocated
memory saved by the attribute pointer that was not interned yet as well.

So let's modify the return case where the decision is made to
not send the prefix to the peer to always just flush the attribute
to ensure memory is not leaked.

Fixes: #15459
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
13 months agobgpd: Include unsuppress-map as a valid outgoing policy
Donald Sharp [Sat, 2 Mar 2024 14:42:30 +0000 (09:42 -0500)]
bgpd: Include unsuppress-map as a valid outgoing policy

If unsuppress-map is setup for outgoing peers, consider that
policy is being applied as for RFC 8212.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
13 months agobgpd: Ensure that the correct aspath is free'd
Donald Sharp [Wed, 13 Mar 2024 14:26:58 +0000 (10:26 -0400)]
bgpd: Ensure that the correct aspath is free'd

Currently in subgroup_default_originate the attr.aspath
is set in bgp_attr_default_set, which hashs the aspath
and creates a refcount for it.  If this is a withdraw
the subgroup_announce_check and bgp_adj_out_set_subgroup
is called which will intern the attribute.  This will
cause the the attr.aspath to be set to a new value
finally at the bottom of the function it intentionally
uninterns the aspath which is not the one that was
created for this function.  This reduces the other
aspath's refcount by 1 and if a clear bgp * is issued
fast enough the aspath for that will be removed
and the system will crash.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
14 months agoMerge pull request #15445 from FRRouting/mergify/bp/stable/8.5/pr-15399
Russ White [Tue, 27 Feb 2024 19:16:59 +0000 (14:16 -0500)]
Merge pull request #15445 from FRRouting/mergify/bp/stable/8.5/pr-15399

zebra: fix crash when macvlan link-interface is in another netns (backport #15399)

14 months agozebra: fix crash if macvlan link in another netns 15445/head
Louis Scalbert [Tue, 20 Feb 2024 16:49:01 +0000 (17:49 +0100)]
zebra: fix crash if macvlan link in another netns

A macvlan interface can have its underlying link-interface in another
namespace (aka. netns). However, by default, zebra does not know the
interface from the other namespaces. It results in a crash the pointer
to the link interface is NULL.

> 6  0x0000559d77a329d3 in zebra_vxlan_macvlan_up (ifp=0x559d798b8e00) at /root/frr/zebra/zebra_vxlan.c:4676
> 4676 link_zif = link_ifp->info;
> (gdb) list
> 4671 struct interface *link_ifp, *link_if;
> 4672
> 4673 zif = ifp->info;
> 4674 assert(zif);
> 4675 link_ifp = zif->link;
> 4676 link_zif = link_ifp->info;
> 4677 assert(link_zif);
> 4678
> (gdb) p zif->link
> $2 = (struct interface *) 0x0
> (gdb) p zif->link_ifindex
> $3 = 15

Fix the crash by returning when the macvlan link-interface is in another
namespace. No need to go further because any vxlan under the macvlan
interface would not be accessible by zebra.

Link: https://github.com/FRRouting/frr/issues/15370
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
(cherry picked from commit 44e6e3868d7a1488447f2be446dbd7cb5a5559ce)

14 months agoMerge pull request #15362 from FRRouting/mergify/bp/stable/8.5/pr-13413
Donatas Abraitis [Tue, 13 Feb 2024 15:11:06 +0000 (17:11 +0200)]
Merge pull request #15362 from FRRouting/mergify/bp/stable/8.5/pr-13413

zebra: re-install NHG on interface up (backport #13413)

14 months agoMerge pull request #15364 from FRRouting/mergify/bp/stable/8.5/pr-14080
Donatas Abraitis [Tue, 13 Feb 2024 15:10:53 +0000 (17:10 +0200)]
Merge pull request #15364 from FRRouting/mergify/bp/stable/8.5/pr-14080

zebra: fix nhg out of sync between zebra and kernel (backport #14080)

14 months agozebra: fix nhg out of sync between zebra and kernel 15364/head
anlan_cs [Mon, 24 Jul 2023 06:40:22 +0000 (14:40 +0800)]
zebra: fix nhg out of sync between zebra and kernel

PR#13413 introduces reinstall mechanism, but there is problem with the route
leak scenario.

With route leak configuration: ( `x1` and `x2` are binded to `vrf1` )
```
vrf vrf2
 ip route 75.75.75.75/32 77.75.1.75 nexthop-vrf vrf1
 ip route 75.75.75.75/32 77.75.2.75 nexthop-vrf vrf1
exit-vrf
```

Firstly, all are ok.  But after `x1` is set down and up ( The interval
between the down and up operations should be less than 180 seconds. ) ,
`x1` is lost from the nexthop group:
```
anlan# ip nexthop
id 121 group 122/123 proto zebra
id 122 via 77.75.1.75 dev x1 scope link proto zebra
id 123 via 77.75.2.75 dev x2 scope link proto zebra
anlan# ip route show table 2
75.75.75.75 nhid 121 proto 196 metric 20
        nexthop via 77.75.1.75 dev x1 weight 1
        nexthop via 77.75.2.75 dev x2 weight 1
anlan# ip link set dev x1 down
anlan# ip link set dev x1 up
anlan# ip route show table 2 <- Wrong, one nexthop lost from group
75.75.75.75 nhid 121 via 77.75.2.75 dev x2 proto 196 metric 20
anlan# ip nexthop
id 121 group 123 proto zebra
id 122 via 77.75.1.75 dev x1 scope link proto zebra
id 123 via 77.75.2.75 dev x2 scope link proto zebra
anlan# show ip route vrf vrf2 <- Still ok
VRF vrf2:
S>* 75.75.75.75/32 [1/0] via 77.75.1.75, x1 (vrf vrf1), weight 1, 00:00:05
  *                      via 77.75.2.75, x2 (vrf vrf1), weight 1, 00:00:05
```

From the impact on kernel:
The `nh->type` of `id 122` is *always* `NEXTHOP_TYPE_IPV4` in the route leak
case.  Then, `nexthop_is_ifindex_type()` introduced by commit `5bb877` always
returns `false`, so its dependents can't be reinstalled.  After `x1` is down,
there is only `id 123` in the group of `id 121`.  So, Finally `id 121` remains
unchanged after `x1` is up, i.e., `id 122` is not added to the group even it is
reinstalled itself.

From the impact on zebra:
The `show ip route vrf vrf2` is still ok because the `id`s are reused/reinstalled
successfully within 180 seconds after `x1` is down and up.  The group of `id 121`
is with old `NEXTHOP_GROUP_INSTALLED` flag, and it is still the group of `id 122`
and `id 123` as before.

In this way, kernel and zebra have become out of sync.

The `nh->type` of `id 122` should be adjusted to `NEXTHOP_TYPE_IPV4_IFINDEX`
after nexthop resolved.  This commit is for doing this to make that reinstall
mechanism work.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
(cherry picked from commit 045df14427b36b20015f12019dd6730a571fb6d3)

14 months agozebra:re-install dependent nhgs on interface up 15362/head
Chirag Shah [Sat, 29 Apr 2023 02:09:55 +0000 (19:09 -0700)]
zebra:re-install dependent nhgs on interface up

Upon interface up associated singleton NHG's
dependent NHGs needs to be reinstalled as
kernel would have deleted if there is no route
referencing it.

Ticket:#3416477
Issue:3416477
Testing Done:
flap interfaces which are part of route NHG,
upon interfaces up event, NHGs are resynced
into dplane.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit 69cf016ee2c50e624172695b7ea84d52006ebd34)

14 months agozebra: re-install nhg on interface up
Ashwini Reddy [Wed, 19 Apr 2023 18:35:25 +0000 (11:35 -0700)]
zebra: re-install nhg on interface up

Intermittently zebra and kernel are out of sync
when interface flaps and the add's/dels are in
same processing queue and zebra assumes no change in nexthop.
Hence we need to bring in a reinstall to kernel
of the nexthops and routes to sync their states.

Upon interface flap kernel would have deleted NHGs
associated to a interface (the one flapped),
zebra retains NHGs for 3 mins even though upper
layer protocol removes the nexthops (associated NHG).
As part of interface address add ,
re-add singleton NHGs associated to interface.

Ticket: #3173663
Issue: 3173663

Signed-off-by: Ashwini Reddy <ashred@nvidia.com>
Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit 5bb87732f62d8dc0d92cad264fce568e5cf12366)

14 months agoMerge pull request #15342 from FRRouting/mergify/bp/stable/8.5/pr-15327
Donald Sharp [Mon, 12 Feb 2024 02:34:52 +0000 (21:34 -0500)]
Merge pull request #15342 from FRRouting/mergify/bp/stable/8.5/pr-15327

pimd: re-evaluated S,G OILs upon RP changes and empty SG upstream oils (backport #15327)

14 months agoMerge pull request #15348 from FRRouting/mergify/bp/stable/8.5/pr-15316
Donatas Abraitis [Sat, 10 Feb 2024 07:25:45 +0000 (09:25 +0200)]
Merge pull request #15348 from FRRouting/mergify/bp/stable/8.5/pr-15316

nhrp: fix race condition in  null lladdr from zebra (backport #15316)

14 months agonhrp: fix race condition 15348/head
Lou Berger [Tue, 6 Feb 2024 23:14:07 +0000 (23:14 +0000)]
nhrp: fix race condition

where null lladdr recieved from zebra before nhrp next hop
is installed.

Signed-off-by: Lou Berger <lberger@labn.net>
(cherry picked from commit 5d9ebe61815814804fac39597578c57e6420a69c)

14 months agopimd: re-evaluated S,G OILs upon RP changes and for empty SG upstream oils 15342/head
Rajesh Varatharaj [Thu, 8 Feb 2024 02:58:39 +0000 (18:58 -0800)]
pimd: re-evaluated S,G OILs upon RP changes and for empty SG upstream oils

Topology:

TOR11 (FHR) --- LEAF-11---SPINE1 (RP)MSDP SPINE-2(RP)MSDP --- LEAF-12 -- TOR12 (LHR)
        |         |                    | |       |
|         -----------------------------------------------------(ECMP)   |
|         |                                 |               |
 -----------------------------------------------------------------------(ECMP)
Issue:
In some triggers, S,G upstream is preserved even with the PP timer expiry, resulting
in S,G with NULL OILS. This could be because we create a dummy S,G upstream and
dummy channel_oif for *,G, where RPF is UNKNOWN. As a result, PIM+VXLAN traffic is never
forwarded downstream to LHR.

Fix:
when the S,G stream is running, Determine if a reevaluation of the outgoing interface
 list (OIL) is required. S,G upstream should then inherit the OIL from *,G.

Testing:
- Evpn pim tests - TestEvpnPimSingleVtepOneMdt.test_02_broadcast_traffic_spt_zero
- pim-smoke

Ticket: #
Signed-off-by: Rajesh Varatharaj <rvaratharaj@nvidia.com>
(cherry picked from commit 071d43a052e04de52771b2f03461c407f0ced36f)

15 months agoMerge pull request #15219 from FRRouting/mergify/bp/stable/8.5/pr-15210
Donatas Abraitis [Sat, 27 Jan 2024 20:55:20 +0000 (22:55 +0200)]
Merge pull request #15219 from FRRouting/mergify/bp/stable/8.5/pr-15210

bgpd: Fix format overflow for graceful-restart debug logs (backport #15210)

15 months agobgpd: Fix format overflow for graceful-restart debug logs 15219/head
Donatas Abraitis [Wed, 24 Jan 2024 06:57:56 +0000 (08:57 +0200)]
bgpd: Fix format overflow for graceful-restart debug logs

Use enum instead of int, and make the compiler happy when using -format-overflow.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 2c69b4b5162a015f411555e315c908580ba23ee7)

15 months agoMerge pull request #15231 from donaldsharp/null_argument_warning_8.5
Donatas Abraitis [Fri, 26 Jan 2024 07:40:28 +0000 (09:40 +0200)]
Merge pull request #15231 from donaldsharp/null_argument_warning_8.5

bgpd: fix NULL argument warning

15 months agoMerge pull request #15230 from FRRouting/mergify/bp/stable/8.5/pr-15206
Donald Sharp [Thu, 25 Jan 2024 14:35:44 +0000 (09:35 -0500)]
Merge pull request #15230 from FRRouting/mergify/bp/stable/8.5/pr-15206

pbrd: Fix PBR handling for last rule deletion (backport #15206)

15 months agobgpd: fix NULL argument warning 15231/head
David Lamparter [Thu, 16 Mar 2023 10:00:02 +0000 (11:00 +0100)]
bgpd: fix NULL argument warning

gcc 12.2.0 complains `error: ‘%s’ directive argument is null`, even
though all enum values are covered with a string.  Let's just go with a
`???` default.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
15 months agopbrd: Fix PBR handling for last rule deletion 15230/head
Rajesh Varatharaj [Tue, 23 Jan 2024 06:24:33 +0000 (22:24 -0800)]
pbrd: Fix PBR handling for last rule deletion

Issue:
Previously, the PBR common was updated for every rule update or deletion

example:
let say we have three rule 11, 12, 13 and if we are removing rule 12. in the current code
we are making the entire map "valid" to false.

pbr-map MAP1 seq 11
match src-ip 90.1.1.2/32
set nexthop 20.1.1.2 swp1

pbr-map MAP1 seq 12
match src-ip 90.1.1.3/32
set nexthop 20.1.1.2 swp1

pbr-map MAP1 seq 13
match src-ip 90.1.1.4/32
set nexthop 20.1.1.2 swp1

no pbr-map MAP1 seq 12 ==> turns whole map valid to false.

r1(config)# end
r1# show pbr map
  pbr-map MAP1 valid: no
    Seq: 11 rule: 310
        Installed: yes Reason: Valid
        SRC IP Match: 90.1.1.2/32
        nexthop 20.1.1.2 swp1
          Installed: yes Tableid: 10002
    Seq: 13 rule: 312
        Installed: yes Reason: Valid
        SRC IP Match: 90.1.1.4/32
        nexthop 20.1.1.2 swp1
          Installed: yes Tableid: 10004

Fix:
Now, the PBR common will only be updated when the last rule is being deleted.
This change ensures that we only send a delete request to Zebra once, and only
set the valid and installed flags to false when the last rule is deleted.
This optimizes the handling of PBR rules and reduces unnecessary interactions with Zebra

Testing: UT in MR notes

Ticket: #
Signed-off-by: Rajesh Varatharaj <rvaratharaj@nvidia.com>
(cherry picked from commit aa12c72c2a9cc1ea22145db28636e716bbd52ace)

15 months agoMerge pull request #15208 from FRRouting/mergify/bp/stable/8.5/pr-15197
Donald Sharp [Wed, 24 Jan 2024 13:29:27 +0000 (08:29 -0500)]
Merge pull request #15208 from FRRouting/mergify/bp/stable/8.5/pr-15197

pimd: fix crash when configuring ssmpingd (backport #15197)

15 months agopimd: fix crash when configuring ssmpingd 15208/head
Igor Ryzhov [Tue, 23 Jan 2024 00:32:22 +0000 (02:32 +0200)]
pimd: fix crash when configuring ssmpingd

Command: `ip ssmpingd 1.1.1.1`

Backtrace:
```
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
0x00007fd1d3b02859 in __GI_abort () at abort.c:79
0x00007fd1d3e323e1 in yang_dnode_xpath_get_canon (dnode=<optimized out>, xpath_fmt=<optimized out>, ap=<optimized out>) at lib/yang_wrappers.c:61
0x00007fd1d3e34f41 in yang_dnode_get_ipv4 (addr=addr@entry=0x7ffc368554d4, dnode=<optimized out>, xpath_fmt=xpath_fmt@entry=0x5556af8680d4 "./source-addr") at lib/yang_wrappers.c:826
0x00005556af8216d3 in routing_control_plane_protocols_control_plane_protocol_pim_address_family_ssm_pingd_source_ip_create (args=0x7ffc36855530) at pimd/pim_nb_config.c:925
0x00007fd1d3dec13f in nb_callback_create (nb_node=0x5556b197ea40, nb_node=0x5556b197ea40, errmsg_len=8192, errmsg=0x7ffc36855a90 "", resource=0x5556b18fa6f8, dnode=0x5556b1ad7a10, event=NB_EV_APPLY, context=0x5556b1ad75c0) at lib/northbound.c:1260
nb_callback_configuration (context=0x5556b1ad75c0, event=NB_EV_APPLY, change=<optimized out>, errmsg=0x7ffc36855a90 "", errmsg_len=8192) at lib/northbound.c:1648
0x00007fd1d3deca6c in nb_transaction_process (event=event@entry=NB_EV_APPLY, transaction=transaction@entry=0x5556b1ad75c0, errmsg=errmsg@entry=0x7ffc36855a90 "", errmsg_len=errmsg_len@entry=8192) at lib/northbound.c:1779
0x00007fd1d3decdd6 in nb_candidate_commit_apply (transaction=0x5556b1ad75c0, save_transaction=save_transaction@entry=true, transaction_id=transaction_id@entry=0x0, errmsg=errmsg@entry=0x7ffc36855a90 "", errmsg_len=errmsg_len@entry=8192) at lib/northbound.c:1129
0x00007fd1d3decf15 in nb_candidate_commit (context=..., candidate=<optimized out>, save_transaction=save_transaction@entry=true, comment=comment@entry=0x0, transaction_id=transaction_id@entry=0x0, errmsg=0x7ffc36855a90 "", errmsg_len=8192) at lib/northbound.c:1162
0x00007fd1d3ded4af in nb_cli_classic_commit (vty=vty@entry=0x5556b1ada2a0) at lib/northbound_cli.c:50
0x00007fd1d3df025f in nb_cli_apply_changes_internal (vty=vty@entry=0x5556b1ada2a0, xpath_base=xpath_base@entry=0x7ffc36859b50 ".", clear_pending=clear_pending@entry=false) at lib/northbound_cli.c:177
0x00007fd1d3df06ad in nb_cli_apply_changes (vty=vty@entry=0x5556b1ada2a0, xpath_base_fmt=xpath_base_fmt@entry=0x0) at lib/northbound_cli.c:233
0x00005556af80fdd5 in pim_process_ssmpingd_cmd (vty=0x5556b1ada2a0, operation=NB_OP_CREATE, src_str=0x5556b1ad9630 "1.1.1.1") at pimd/pim_cmd_common.c:3423
0x00007fd1d3da7b0e in cmd_execute_command_real (vline=vline@entry=0x5556b1ac9520, vty=vty@entry=0x5556b1ada2a0, cmd=cmd@entry=0x0, up_level=up_level@entry=0) at lib/command.c:982
0x00007fd1d3da7cb1 in cmd_execute_command (vline=vline@entry=0x5556b1ac9520, vty=vty@entry=0x5556b1ada2a0, cmd=0x0, vtysh=vtysh@entry=0) at lib/command.c:1040
0x00007fd1d3da7e50 in cmd_execute (vty=vty@entry=0x5556b1ada2a0, cmd=cmd@entry=0x5556b1ae0a30 "ip ssmpingd 1.1.1.1", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1207
0x00007fd1d3e278be in vty_command (vty=vty@entry=0x5556b1ada2a0, buf=<optimized out>) at lib/vty.c:591
0x00007fd1d3e27afd in vty_execute (vty=0x5556b1ada2a0) at lib/vty.c:1354
0x00007fd1d3e2bb23 in vtysh_read (thread=<optimized out>) at lib/vty.c:2362
0x00007fd1d3e22254 in event_call (thread=thread@entry=0x7ffc3685cd80) at lib/event.c:2003
0x00007fd1d3dce9e8 in frr_run (master=0x5556b183c830) at lib/libfrr.c:1218
0x00005556af803653 in main (argc=6, argv=<optimized out>, envp=<optimized out>) at pimd/pim_main.c:162
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit 8ffc3640f00a7bd97911f997365c693172fafb69)

15 months agoMerge pull request #15140 from FRRouting/mergify/bp/stable/8.5/pr-14664
Donald Sharp [Tue, 16 Jan 2024 15:43:04 +0000 (10:43 -0500)]
Merge pull request #15140 from FRRouting/mergify/bp/stable/8.5/pr-14664

isisd: staticd: need to link directly against libyang (backport #14664)

15 months agoisisd: staticd: need to link directly against libyang 15140/head
Christian Hopps [Fri, 27 Oct 2023 02:51:08 +0000 (22:51 -0400)]
isisd: staticd: need to link directly against libyang

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 81d1d399521bb18f3fdd5353c9d58c4b3988f225)

16 months agoMerge pull request #15041 from FRRouting/mergify/bp/stable/8.5/pr-15032
Donald Sharp [Mon, 18 Dec 2023 20:03:48 +0000 (15:03 -0500)]
Merge pull request #15041 from FRRouting/mergify/bp/stable/8.5/pr-15032

bgpd: "default-originate" shouldn't withdraw non-default routes (backport #15032)

16 months agotests: Check for 0.0.0.0/1 in bgp_default_route 15041/head
Xiao Liang [Mon, 18 Dec 2023 06:57:22 +0000 (14:57 +0800)]
tests: Check for 0.0.0.0/1 in bgp_default_route

Ensure that 0.0.0.0/1 route can be advertised along with
default-originate.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
(cherry picked from commit 4538247c995e551aed0c08c4bb20b187ce95f5f2)

16 months agobgpd: "default-originate" shouldn't withdraw non-default routes
Xiao Liang [Fri, 15 Dec 2023 10:27:39 +0000 (18:27 +0800)]
bgpd: "default-originate" shouldn't withdraw non-default routes

Prevent "default-originate" from withdrawing non-default routes like
0.0.0.0/1 by checking prefix length.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
(cherry picked from commit 4d74ba929daa6e6b2fe15f9df6e61d5e4808b64c)

16 months agoMerge pull request #15021 from FRRouting/mergify/bp/stable/8.5/pr-15014
Donald Sharp [Thu, 14 Dec 2023 15:38:53 +0000 (10:38 -0500)]
Merge pull request #15021 from FRRouting/mergify/bp/stable/8.5/pr-15014

ospfd: fix some ospf cmds' param range (backport #15014)

16 months agoMerge pull request #15005 from opensourcerouting/fix/bdb5ae8bce94432eb5e581f04f48dc4a...
Donald Sharp [Thu, 14 Dec 2023 15:33:04 +0000 (10:33 -0500)]
Merge pull request #15005 from opensourcerouting/fix/bdb5ae8bce94432eb5e581f04f48dc4aa5db7ca4_8.5

bgpd: Make `suppress-fib-pending` clear peering

16 months agodoc: add param range for graceful-restart helper supported-grace-time 15021/head
Bing Shui [Wed, 13 Dec 2023 14:25:43 +0000 (22:25 +0800)]
doc: add param range for graceful-restart helper supported-grace-time

Signed-off-by: Bing Shui <652023330037@smail.nju.edu.cn>
(cherry picked from commit 588b6421433ec0ffbe0d5fbc9ba68126e78d2935)

16 months agoospfd: fix ospf dead-interval minimal hello-multiplier param range
Bing Shui [Wed, 13 Dec 2023 14:23:58 +0000 (22:23 +0800)]
ospfd: fix ospf dead-interval minimal hello-multiplier param range

Signed-off-by: Bing Shui <652023330037@smail.nju.edu.cn>
(cherry picked from commit a1793303c0e8a531812f4176b62ff2ebf9ef9539)

16 months agobgpd: Make `suppress-fib-pending` clear peering 15005/head
Donald Sharp [Mon, 11 Dec 2023 15:46:53 +0000 (10:46 -0500)]
bgpd: Make `suppress-fib-pending` clear peering

When a peer has come up and already started installing
routes into the rib and `suppress-fib-pending` is either
turned on or off.  BGP is left with some routes that
may need to be withdrawn from peers and routes that
it does not know the status of.  Clear the BGP peers
for the interesting parties and let's let us come
up to speed as needed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
16 months agoMerge pull request #14990 from FRRouting/mergify/bp/stable/8.5/pr-14983
Donald Sharp [Tue, 12 Dec 2023 17:22:59 +0000 (12:22 -0500)]
Merge pull request #14990 from FRRouting/mergify/bp/stable/8.5/pr-14983

zebra: The dplane_fpm_nl return path leaks memory (backport #14983)

16 months agozebra: The dplane_fpm_nl return path leaks memory 14990/head
Donald Sharp [Mon, 11 Dec 2023 18:41:36 +0000 (13:41 -0500)]
zebra: The dplane_fpm_nl return path leaks memory

The route entry created when using a ctx to pass route
entry data backup to the master pthread in zebra is
being leaked.  Prevent this from happening.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 7f9c5c7fa2d927033549a806fd9025a9459f22bc)

16 months agoFRR Release 8.5.4 docker/8.5.4 frr-8.5.4
Donatas Abraitis [Fri, 1 Dec 2023 07:51:27 +0000 (09:51 +0200)]
FRR Release 8.5.4

bgpd
    Check mandatory attributes more carefully for the UPDATE message
    Do not suppress conditional advertisement updates if triggered
    Fix crash in SNMP BGP4V2-MIB bgpv2PeerErrorsTable()
    Handle MP_UNREACH_NLRI malformed packets with session reset
    Ignore handling NLRIs if we received the MP_UNREACH_NLRI attribute
    Initialise timebuf arrays to zeros for dampening reuse timer
    Initialise buffer in bgp_notify_admin_message() before using it
    Make sure dampening is enabled for the specified AFI/SAFI
    Use proper AFI when dumping information for dampening stuff
    Treat EOR as withdrawn to avoid unwanted handling of malformed attrs

eigrpd
    Use the correct memory pool on interface deletion

vtysh
    Fix show route map JSON output

ospfd
    Fix infinite loop when listing OSPF interfaces

pbrd
    Fix show pbr map detail json output

zebra
    Add encap type when building packet for FPM
    Display ptmStatus order in interface JSON
    Fix connected route deletion when multiple entry exists
    Fix FPM multipath encap addition
    Fix link update for veth interfaces
    Fix zebra crash when replacing nhe during shutdown
    Prevent null pointer dereference

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
17 months agoMerge pull request #14893 from FRRouting/mergify/bp/stable/8.5/pr-14856
Donald Sharp [Tue, 28 Nov 2023 14:18:00 +0000 (09:18 -0500)]
Merge pull request #14893 from FRRouting/mergify/bp/stable/8.5/pr-14856

lib: fix show route map JSON display (backport #14856)

17 months agodoc: remove duplicated show route-map 14893/head
Rafael Zalamena [Tue, 21 Nov 2023 18:02:44 +0000 (15:02 -0300)]
doc: remove duplicated show route-map

Remove zebra duplicated command documentation without description.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
(cherry picked from commit 1f2ab614031dd169f6fbb495849099c443124f46)

17 months agolib,vtysh: fix show route map JSON output
Rafael Zalamena [Mon, 20 Nov 2023 20:32:19 +0000 (17:32 -0300)]
lib,vtysh: fix show route map JSON output

Move the command from 'lib' to 'vtysh' so we can properly format the
JSON output in a correct manner.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
(cherry picked from commit 570fdc55fd65899cd4376193e833594af6bca093)

17 months agoMerge pull request #14873 from FRRouting/mergify/bp/stable/8.5/pr-14862
Donald Sharp [Fri, 24 Nov 2023 19:33:01 +0000 (14:33 -0500)]
Merge pull request #14873 from FRRouting/mergify/bp/stable/8.5/pr-14862

zebra: fix dplane_ctx_iptable use-after-free (backport #14862)

17 months agozebra: fix dplane_ctx_iptable use-after-free 14873/head
Louis Scalbert [Wed, 22 Nov 2023 17:21:25 +0000 (18:21 +0100)]
zebra: fix dplane_ctx_iptable use-after-free

Fix a crash because a use-after-free.

> =================================================================
> ==1249835==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000074210 at pc 0x7fa1b42a652c bp 0x7ffc477a2aa0 sp 0x7ffc477a2a98
> READ of size 8 at 0x604000074210 thread T0
>     #0 0x7fa1b42a652b in list_delete_all_node git/frr/lib/linklist.c:299:20
>     #1 0x7fa1b42a683f in list_delete git/frr/lib/linklist.c:312:2
>     #2 0x5ee515 in dplane_ctx_free_internal git/frr/zebra/zebra_dplane.c:858:4
>     #3 0x5ee59c in dplane_ctx_free git/frr/zebra/zebra_dplane.c:884:2
>     #4 0x5ee544 in dplane_ctx_fini git/frr/zebra/zebra_dplane.c:905:2
>     #5 0x7045c0 in rib_process_dplane_results git/frr/zebra/zebra_rib.c:4928:4
>     #6 0x7fa1b4434fb2 in event_call git/frr/lib/event.c:1970:2
>     #7 0x7fa1b42a0ccf in frr_run git/frr/lib/libfrr.c:1213:3
>     #8 0x556808 in main git/frr/zebra/main.c:488:2
>     #9 0x7fa1b3d0bd09 in __libc_start_main csu/../csu/libc-start.c:308:16
>     #10 0x4453e9 in _start (/usr/lib/frr/zebra+0x4453e9)
>
> 0x604000074210 is located 0 bytes inside of 40-byte region [0x604000074210,0x604000074238)
> freed by thread T0 here:
>     #0 0x4bf1dd in free (/usr/lib/frr/zebra+0x4bf1dd)
>     #1 0x7fa1b42df0c0 in qfree git/frr/lib/memory.c:130:2
>     #2 0x7fa1b42a68ce in list_free_internal git/frr/lib/linklist.c:24:2
>     #3 0x7fa1b42a6870 in list_delete git/frr/lib/linklist.c:313:2
>     #4 0x5ee515 in dplane_ctx_free_internal git/frr/zebra/zebra_dplane.c:858:4
>     #5 0x5ee59c in dplane_ctx_free git/frr/zebra/zebra_dplane.c:884:2
>     #6 0x5ee544 in dplane_ctx_fini git/frr/zebra/zebra_dplane.c:905:2
>     #7 0x7045c0 in rib_process_dplane_results git/frr/zebra/zebra_rib.c:4928:4
>     #8 0x7fa1b4434fb2 in event_call git/frr/lib/event.c:1970:2
>     #9 0x7fa1b42a0ccf in frr_run git/frr/lib/libfrr.c:1213:3
>     #10 0x556808 in main git/frr/zebra/main.c:488:2
>     #11 0x7fa1b3d0bd09 in __libc_start_main csu/../csu/libc-start.c:308:16
>
> previously allocated by thread T0 here:
>     #0 0x4bf5d2 in calloc (/usr/lib/frr/zebra+0x4bf5d2)
>     #1 0x7fa1b42dee18 in qcalloc git/frr/lib/memory.c:105:27
>     #2 0x7fa1b42a3784 in list_new git/frr/lib/linklist.c:18:9
>     #3 0x6d165f in pbr_iptable_alloc_intern git/frr/zebra/zebra_pbr.c:1015:29
>     #4 0x7fa1b426ad1f in hash_get git/frr/lib/hash.c:147:13
>     #5 0x6d15f2 in zebra_pbr_add_iptable git/frr/zebra/zebra_pbr.c:1030:13
>     #6 0x5db2a3 in zread_iptable git/frr/zebra/zapi_msg.c:3759:3
>     #7 0x5e365d in zserv_handle_commands git/frr/zebra/zapi_msg.c:4039:3
>     #8 0x7e09fc in zserv_process_messages git/frr/zebra/zserv.c:520:3
>     #9 0x7fa1b4434fb2 in event_call git/frr/lib/event.c:1970:2
>     #10 0x7fa1b42a0ccf in frr_run git/frr/lib/libfrr.c:1213:3
>     #11 0x556808 in main git/frr/zebra/main.c:488:2
>     #12 0x7fa1b3d0bd09 in __libc_start_main csu/../csu/libc-start.c:308:16

Fixes: 1cc380679e ("zebra: Actually free all memory associated ctx->u.iptable.interface_name_list")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
(cherry picked from commit 45140bb9e1efd2e603377809e349b35087d24f7d)

17 months agoMerge pull request #14852 from donaldsharp/backport_itis
Donatas Abraitis [Wed, 22 Nov 2023 12:42:55 +0000 (14:42 +0200)]
Merge pull request #14852 from donaldsharp/backport_itis

Backport a couple of fixes to 8.5

17 months agoMerge pull request #14848 from FRRouting/mergify/bp/stable/8.5/pr-14835
Donald Sharp [Tue, 21 Nov 2023 20:00:34 +0000 (15:00 -0500)]
Merge pull request #14848 from FRRouting/mergify/bp/stable/8.5/pr-14835

zebra: Fix fpm multipath encap addition (backport #14835)

17 months agobgpd: Ignore handling NLRIs if we received MP_UNREACH_NLRI 14851/head 14852/head
Donatas Abraitis [Sun, 29 Oct 2023 20:44:45 +0000 (22:44 +0200)]
bgpd: Ignore handling NLRIs if we received MP_UNREACH_NLRI

If we receive MP_UNREACH_NLRI, we should stop handling remaining NLRIs if
no mandatory path attributes received.

In other words, if MP_UNREACH_NLRI received, the remaining NLRIs should be handled
as a new data, but without mandatory attributes, it's a malformed packet.

In normal case, this MUST not happen at all, but to avoid crashing bgpd, we MUST
handle that.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
17 months agobgpd: Treat EOR as withdrawn to avoid unwanted handling of malformed attrs
Donatas Abraitis [Fri, 27 Oct 2023 08:56:45 +0000 (11:56 +0300)]
bgpd: Treat EOR as withdrawn to avoid unwanted handling of malformed attrs

Treat-as-withdraw, otherwise if we just ignore it, we will pass it to be
processed as a normal UPDATE without mandatory attributes, that could lead
to harmful behavior. In this case, a crash for route-maps with the configuration
such as:

```
router bgp 65001
 no bgp ebgp-requires-policy
 neighbor 127.0.0.1 remote-as external
 neighbor 127.0.0.1 passive
 neighbor 127.0.0.1 ebgp-multihop
 neighbor 127.0.0.1 disable-connected-check
 neighbor 127.0.0.1 update-source 127.0.0.2
 neighbor 127.0.0.1 timers 3 90
 neighbor 127.0.0.1 timers connect 1
 !
 address-family ipv4 unicast
  neighbor 127.0.0.1 addpath-tx-all-paths
  neighbor 127.0.0.1 default-originate
  neighbor 127.0.0.1 route-map RM_IN in
 exit-address-family
exit
!
route-map RM_IN permit 10
 set as-path prepend 200
exit
```

Send a malformed optional transitive attribute:

```
import socket
import time

OPEN = (b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
b"\xff\xff\x00\x62\x01\x04\xfd\xea\x00\x5a\x0a\x00\x00\x01\x45\x02"
b"\x06\x01\x04\x00\x01\x00\x01\x02\x02\x02\x00\x02\x02\x46\x00\x02"
b"\x06\x41\x04\x00\x00\xfd\xea\x02\x02\x06\x00\x02\x06\x45\x04\x00"
b"\x01\x01\x03\x02\x0e\x49\x0c\x0a\x64\x6f\x6e\x61\x74\x61\x73\x2d"
b"\x70\x63\x00\x02\x04\x40\x02\x00\x78\x02\x09\x47\x07\x00\x01\x01"
b"\x80\x00\x00\x00")

KEEPALIVE = (b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
b"\xff\xff\xff\xff\xff\xff\x00\x13\x04")

UPDATE = bytearray.fromhex("ffffffffffffffffffffffffffffffff002b0200000003c0ff00010100eb00ac100b0b001ad908ac100b0b")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.2', 179))
s.send(OPEN)
data = s.recv(1024)
s.send(KEEPALIVE)
data = s.recv(1024)
s.send(UPDATE)
data = s.recv(1024)
time.sleep(100)
s.close()
```

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
17 months agozebra: Fix fpm multipath encap addition 14848/head
Donald Sharp [Fri, 17 Nov 2023 21:57:20 +0000 (16:57 -0500)]
zebra: Fix fpm multipath encap addition

The fpm code path in building a ecmp route for evpn has
a bug that caused it to not add the encap attribute to
the netlink message.  See #f0f7b285b99dbd971400d33feea007232c0bd4a9
for the single path case being fixed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 6b23ece88bc061ed6c0bdabf6846e3d981aa757a)

17 months agoMerge pull request #14754 from FRRouting/mergify/bp/stable/8.5/pr-14675
Donald Sharp [Wed, 8 Nov 2023 16:18:51 +0000 (11:18 -0500)]
Merge pull request #14754 from FRRouting/mergify/bp/stable/8.5/pr-14675

zebra: Add encap type when building packet for FPM (backport #14675)

17 months agozebra: Add encap type when building packet for FPM 14754/head
Donald Sharp [Sat, 28 Oct 2023 14:03:39 +0000 (10:03 -0400)]
zebra: Add encap type when building packet for FPM

Currently in the single nexthop case w/ evpn sending
down via the FPM the encap type is not being set
for the nexthop.

This looks like the result of some code reorg for the
nexthop happened but the fpm failed to be accounted for.
Let's just move the encap type encoding to where it
will happen.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 4ac659fcbeb3848ee6caf06676a9ac1543ae62f1)

17 months agoMerge pull request #14686 from FRRouting/mergify/bp/stable/8.5/pr-14681
Donald Sharp [Mon, 30 Oct 2023 19:38:08 +0000 (15:38 -0400)]
Merge pull request #14686 from FRRouting/mergify/bp/stable/8.5/pr-14681

zebra: display ptmStatus order in interface json (backport #14681)

18 months agozebra: display ptmStatus order in interface json 14686/head
Sindhu Parvathi Gopinathan [Wed, 24 Aug 2022 16:17:57 +0000 (09:17 -0700)]
zebra: display ptmStatus order in interface json

Display ptmStatus in correct order in show interface json
output.

Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
(cherry picked from commit aa6dab0369b9ab90291f5596f6b23a4c0b226ed0)

18 months agoMerge pull request #14679 from FRRouting/mergify/bp/stable/8.5/pr-14665
Donald Sharp [Sun, 29 Oct 2023 14:11:04 +0000 (10:11 -0400)]
Merge pull request #14679 from FRRouting/mergify/bp/stable/8.5/pr-14665

pbrd: fix show pbr map detail json (backport #14665)

18 months agodoc: fix pbr map detail json 14679/head
Chirag Shah [Fri, 27 Oct 2023 15:06:27 +0000 (08:06 -0700)]
doc: fix pbr map detail json

Fix the documentation for the pbr map command with
correct syntax.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit df3d91f0851d551cc481599c1fa1a1dc5a29cd92)

18 months agopbrd: fix show pbr map detail json
Sindhu Parvathi Gopinathan [Mon, 23 Oct 2023 05:59:06 +0000 (22:59 -0700)]
pbrd: fix show pbr map detail json

'detail' and 'josn' keyword is given as an optional parameter
for cli arguments. Hence 'detail' keyword was consider as a
pbr 'name' for "show pbr map detail json" command.

Before Fix:

```
cumulus#
cumulus# show pbr map detail json
[
]
cumulus#
```

After Fix:
```
cumulus# show pbr map detail json
[
  {
    "name":"MAP1",
    "valid":false,
    "policies":[
      {
        "id":1,
        "sequenceNumber":10,
        "ruleNumber":309,
        "vrfUnchanged":false,
        "installed":false,
        "installedReason":"Invalid Src or Dst",
        "vrfName":"default"
      }
    ]
  }
]
cumulus#
```

Ticket:#3638600

Issue:3638600

Testing: UT done

Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
(cherry picked from commit d621c365a65f825adfbc00128360390d0b2bd5be)

18 months agoMerge pull request #14655 from FRRouting/mergify/bp/stable/8.5/pr-14645
Donald Sharp [Wed, 25 Oct 2023 19:35:10 +0000 (15:35 -0400)]
Merge pull request #14655 from FRRouting/mergify/bp/stable/8.5/pr-14645

bgpd: A couple more bgpd crashes on malformed attributes (backport #14645)

18 months agoMerge pull request #14650 from FRRouting/mergify/bp/stable/8.5/pr-14628
Donald Sharp [Wed, 25 Oct 2023 19:32:56 +0000 (15:32 -0400)]
Merge pull request #14650 from FRRouting/mergify/bp/stable/8.5/pr-14628

bgpd: Do not suppress conditional advertisement updates if triggered (backport #14628)

18 months agobgpd: Check mandatory attributes more carefully for UPDATE message 14655/head
Donatas Abraitis [Mon, 23 Oct 2023 20:34:10 +0000 (23:34 +0300)]
bgpd: Check mandatory attributes more carefully for UPDATE message

If we send a crafted BGP UPDATE message without mandatory attributes, we do
not check if the length of the path attributes is zero or not. We only check
if attr->flag is at least set or not. Imagine we send only unknown transit
attribute, then attr->flag is always 0. Also, this is true only if graceful-restart
capability is received.

A crash:

```
bgpd[7834]: [TJ23Y-GY0RH] 127.0.0.1 Unknown attribute is received (type 31, length 16)
bgpd[7834]: [PCFFM-WMARW] 127.0.0.1(donatas-pc) rcvd UPDATE wlen 0 attrlen 20 alen 17
BGP[7834]: Received signal 11 at 1698089639 (si_addr 0x0, PC 0x55eefd375b4a); aborting...
BGP[7834]: /usr/local/lib/libfrr.so.0(zlog_backtrace_sigsafe+0x6d) [0x7f3205ca939d]
BGP[7834]: /usr/local/lib/libfrr.so.0(zlog_signal+0xf3) [0x7f3205ca9593]
BGP[7834]: /usr/local/lib/libfrr.so.0(+0xf5181) [0x7f3205cdd181]
BGP[7834]: /lib/x86_64-linux-gnu/libpthread.so.0(+0x12980) [0x7f3204ff3980]
BGP[7834]: /usr/lib/frr/bgpd(+0x18ab4a) [0x55eefd375b4a]
BGP[7834]: /usr/local/lib/libfrr.so.0(route_map_apply_ext+0x310) [0x7f3205cd1290]
BGP[7834]: /usr/lib/frr/bgpd(+0x163610) [0x55eefd34e610]
BGP[7834]: /usr/lib/frr/bgpd(bgp_update+0x9a5) [0x55eefd35c1d5]
BGP[7834]: /usr/lib/frr/bgpd(bgp_nlri_parse_ip+0xb7) [0x55eefd35e867]
BGP[7834]: /usr/lib/frr/bgpd(+0x1555e6) [0x55eefd3405e6]
BGP[7834]: /usr/lib/frr/bgpd(bgp_process_packet+0x747) [0x55eefd345597]
BGP[7834]: /usr/local/lib/libfrr.so.0(event_call+0x83) [0x7f3205cef4a3]
BGP[7834]: /usr/local/lib/libfrr.so.0(frr_run+0xc0) [0x7f3205ca10a0]
BGP[7834]: /usr/lib/frr/bgpd(main+0x409) [0x55eefd2dc979]
```

Sending:

```
import socket
import time

OPEN = (b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
b"\xff\xff\x00\x62\x01\x04\xfd\xea\x00\x5a\x0a\x00\x00\x01\x45\x02"
b"\x06\x01\x04\x00\x01\x00\x01\x02\x02\x02\x00\x02\x02\x46\x00\x02"
b"\x06\x41\x04\x00\x00\xfd\xea\x02\x02\x06\x00\x02\x06\x45\x04\x00"
b"\x01\x01\x03\x02\x0e\x49\x0c\x0a\x64\x6f\x6e\x61\x74\x61\x73\x2d"
b"\x70\x63\x00\x02\x04\x40\x02\x00\x78\x02\x09\x47\x07\x00\x01\x01"
b"\x80\x00\x00\x00")

KEEPALIVE = (b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
b"\xff\xff\xff\xff\xff\xff\x00\x13\x04")

UPDATE = bytearray.fromhex("ffffffffffffffffffffffffffffffff003c0200000014ff1f001000040146464646460004464646464646664646f50d05800100010200ffff000000")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.2', 179))
s.send(OPEN)
data = s.recv(1024)
s.send(KEEPALIVE)
data = s.recv(1024)
s.send(UPDATE)
data = s.recv(1024)
time.sleep(1000)
s.close()
```

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit d8482bf011cb2b173e85b65b4bf3d5061250cdb9)

18 months agobgpd: Handle MP_REACH_NLRI malformed packets with session reset
Donatas Abraitis [Fri, 20 Oct 2023 14:49:18 +0000 (17:49 +0300)]
bgpd: Handle MP_REACH_NLRI malformed packets with session reset

Avoid crashing bgpd.

```
(gdb)
bgp_mp_reach_parse (args=<optimized out>, mp_update=0x7fffffffe140) at bgpd/bgp_attr.c:2341
2341 stream_get(&attr->mp_nexthop_global, s, IPV6_MAX_BYTELEN);
(gdb)
stream_get (dst=0x7fffffffe1ac, s=0x7ffff0006e80, size=16) at lib/stream.c:320
320 {
(gdb)
321 STREAM_VERIFY_SANE(s);
(gdb)
323 if (STREAM_READABLE(s) < size) {
(gdb)
34   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
(gdb)

Thread 1 "bgpd" received signal SIGSEGV, Segmentation fault.
0x00005555556e37be in route_set_aspath_prepend (rule=0x555555aac0d0, prefix=0x7fffffffe050,
    object=0x7fffffffdb00) at bgpd/bgp_routemap.c:2282
2282 if (path->attr->aspath->refcnt)
(gdb)
```

With the configuration:

```
 neighbor 127.0.0.1 remote-as external
 neighbor 127.0.0.1 passive
 neighbor 127.0.0.1 ebgp-multihop
 neighbor 127.0.0.1 disable-connected-check
 neighbor 127.0.0.1 update-source 127.0.0.2
 neighbor 127.0.0.1 timers 3 90
 neighbor 127.0.0.1 timers connect 1
 address-family ipv4 unicast
  redistribute connected
  neighbor 127.0.0.1 default-originate
  neighbor 127.0.0.1 route-map RM_IN in
 exit-address-family
!
route-map RM_IN permit 10
 set as-path prepend 200
exit
```

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit b08afc81c60607a4f736f418f2e3eb06087f1a35)

18 months agotests: Check if BGP conditional advertisement works fine with static routes 14650/head
Donatas Abraitis [Thu, 19 Oct 2023 17:25:23 +0000 (20:25 +0300)]
tests: Check if BGP conditional advertisement works fine with static routes

If we modify the prefix-list that is used to define the routes to be
advertised, all of them MUST be advertised.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 3c9415125818b54416bd89b9f703f987ff91746c)

18 months agobgpd: Do not suppress conditional advertisement updates if triggered
Donatas Abraitis [Fri, 20 Oct 2023 08:59:59 +0000 (11:59 +0300)]
bgpd: Do not suppress conditional advertisement updates if triggered

If we have a prefix-list with one entry, and after some time we append a prefix-list
with some more additional entries, conditional advertisement is triggered, and the
old entries are suppressed (because they look identical as sent before).

Hence, the old entries are sent as withdrawals and only new entries sent as updates.

Force re-sending all BGP updates for conditional advertisement. The same is done
for route-refresh, and/or soft clear operations.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 2d8e85958526493f59e7cb9bf6dac829ed3d687f)

18 months agoMerge pull request #14586 from FRRouting/mergify/bp/stable/8.5/pr-13340
Donald Sharp [Fri, 13 Oct 2023 15:52:34 +0000 (11:52 -0400)]
Merge pull request #14586 from FRRouting/mergify/bp/stable/8.5/pr-13340

zebra: Fix connected route deletion when multiple entry exists (backport #13340)

18 months agozebra: Fix connected route deletion when multiple entry exists 14586/head
Xiao Liang [Thu, 20 Apr 2023 03:40:04 +0000 (11:40 +0800)]
zebra: Fix connected route deletion when multiple entry exists

When multiple interfaces have addresses in the same network, deleting
one of them may cause the wrong connected route being deleted.
For example:

    ip link add veth1 type veth peer veth2
    ip link set veth1 up
    ip link set veth2 up
    ip addr add dev veth1 192.168.0.1/24
    ip addr add dev veth2 192.168.0.2/24
    ip addr flush dev veth1

Zebra deletes the route of interface veth2 rather than veth1.

Should match nexthop against ere->re_nhe instead of ere->re->nhe.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
(cherry picked from commit a35ba7ba602f87390cc9cbce3f0ceb61977f0949)

18 months agoMerge pull request #14570 from FRRouting/mergify/bp/stable/8.5/pr-14437
Donald Sharp [Wed, 11 Oct 2023 16:54:12 +0000 (12:54 -0400)]
Merge pull request #14570 from FRRouting/mergify/bp/stable/8.5/pr-14437

vtysh freezed on ospf 'no network' command when there are multiple networks and interfaces (backport #14437)

18 months agoMerge pull request #14565 from FRRouting/mergify/bp/stable/8.5/pr-14557
Donald Sharp [Wed, 11 Oct 2023 15:32:09 +0000 (11:32 -0400)]
Merge pull request #14565 from FRRouting/mergify/bp/stable/8.5/pr-14557

eigrp: use correct memory pool on interface deletion (backport #14557)

18 months agoospfd: Fixing infinite loop when listing OSPF interfaces 14570/head
Rodrigo Nardi [Mon, 18 Sep 2023 20:40:35 +0000 (17:40 -0300)]
ospfd: Fixing infinite loop when listing OSPF interfaces

The problem was happening because the ospf->oiflist has this behaviour, each interface was removed and added at the end of the list in each ospf_network_run_subnet call, generation an infinite loop.
As a solution, a copy of the list was generated and we interacted with a fixed list.

Signed-off-by: Rodrigo Nardi <rnardi@netdef.org>
(cherry picked from commit e0dbeff5bc599be0dfade8256b53dcfef4435bc8)

18 months agoeigrp: use correct memory pool on interface deletion 14565/head
Volodymyr Huti [Tue, 10 Oct 2023 16:10:18 +0000 (19:10 +0300)]
eigrp: use correct memory pool on interface deletion

Trying to delete an interface during the test test_eigrp_topo1.py triggers a crash.
```
EIGRP: abort+0x12b
EIGRP: _zlog_assert_failed+0x18c
EIGRP: mt_count_free+0x56
EIGRP: qfree+0x2e
EIGRP: eigrp_if_delete_hook+0x8c
EIGRP: hook_call_if_del+0x5f
EIGRP: if_delete_retain+0x1c
EIGRP: if_delete+0xfb
EIGRP: if_destroy_via_zapi+0x69
EIGRP: zclient_interface_delete+0x57
EIGRP: zclient_read+0x3d0
EIGRP: event_call+0xd8
EIGRP: frr_run+0x271
EIGRP: main+0x14b
EIGRP: __libc_start_main+0xf3
EIGRP: _start+0x2e
EIGRP: in thread zclient_read scheduled from lib/zclient.c:4514 zclient_event()
```

Signed-off-by: Volodymyr Huti <v.huti@vyos.io>
(cherry picked from commit 8ddf6a713f2003ccccb884a8c436ffeb2fe34c62)

19 months agoMerge pull request #14497 from FRRouting/mergify/bp/stable/8.5/pr-14342
Donatas Abraitis [Thu, 28 Sep 2023 11:04:16 +0000 (14:04 +0300)]
Merge pull request #14497 from FRRouting/mergify/bp/stable/8.5/pr-14342

bgpd: fix crash in *bgpv2PeerErrorsTable" (backport #14342)

19 months agobgpd: initialization in bgp_notify_admin_message function 14497/head
Francois Dumontet [Mon, 18 Sep 2023 11:55:08 +0000 (13:55 +0200)]
bgpd: initialization in bgp_notify_admin_message function

buffer buff is fully zeroed by a memset in bgp_notify_admin_message
function

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit b8f3f0b86ff3fae4a3e655811680bc11b18fd0e2)

19 months agobgpd: fix crash in *bgpv2PeerErrorsTable
Francois Dumontet [Fri, 1 Sep 2023 15:25:25 +0000 (17:25 +0200)]
bgpd: fix crash in *bgpv2PeerErrorsTable

following crash occurs:
    at ./nptl/pthread_kill.c:44
    at ./nptl/pthread_kill.c:78
    at ./nptl/pthread_kill.c:89
    context=0x7ffd06d3d300)
    at /build/make-pkg/output/_packages/cp-routing/src/lib/sigevent.c:246
    length=0x7ffd06d3da88, exact=1, var_len=0x7ffd06d3da90, write_method=<optimized out>)
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_snmp_bgp4v2.c:364
    vp=vp@entry=0x7f7c88b584c0 <bgpv2_variables>, vp_len=vp_len@entry=102,
    ename=ename@entry=0x7f7c88b58440 <bgpv2_trap_oid>, enamelen=enamelen@entry=8,
    name=name@entry=0x7f7c88b58480 <bgpv2_oid>, namelen=namelen@entry=7,
    iname=0x7ffd06d3e7b0, index_len=1, trapobj=0x7f7c88b53b80 <bgpv2TrapBackListv6>,
    trapobjlen=6, sptrap=2 '\002')
    at /build/make-pkg/output/_packages/cp-routing/src/lib/agentx.c:382
    vp_len=vp_len@entry=102, ename=ename@entry=0x7f7c88b58440 <bgpv2_trap_oid>,
    enamelen=enamelen@entry=8, name=name@entry=0x7f7c88b58480 <bgpv2_oid>,
    namelen=namelen@entry=7, iname=0x7ffd06d3ec30, inamelen=16,
    trapobj=0x7f7c88b53b80 <bgpv2TrapBackListv6>, trapobjlen=6, sptrap=2 '\002')
    at /build/make-pkg/output/_packages/cp-routing/src/lib/agentx.c:298
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_snmp_bgp4v2.c:1496
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_fsm.c:48
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_fsm.c:1314
    event=Receive_NOTIFICATION_message)
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_fsm.c:2665
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_packet.c:3129
    at /build/make-pkg/output/_packages/cp-routing/src/lib/event.c:1979
    at /build/make-pkg/output/_packages/cp-routing/src/lib/libfrr.c:1213
    at /build/make-pkg/output/_packages/cp-routing/src/bgpd/bgp_main.c:510

it's due to function bgpv2PeerErrorsTable returning
return SNMP_STRING(msg_str);
with msg_str NULL rather the string ""

this commit avoid the issue.

Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
(cherry picked from commit d5cb2d9e41135a34baec3663a686e19eff0a316f)

19 months agoMerge pull request #14480 from opensourcerouting/fix/backport_dampening_crash_8.5
Donald Sharp [Mon, 25 Sep 2023 13:53:08 +0000 (09:53 -0400)]
Merge pull request #14480 from opensourcerouting/fix/backport_dampening_crash_8.5

bgpd: Fix dampening info crash

19 months agobgpd: Make sure dampening is enabled for the specified AFI/SAFI 14480/head
Donatas Abraitis [Thu, 21 Sep 2023 12:37:17 +0000 (15:37 +0300)]
bgpd: Make sure dampening is enabled for the specified AFI/SAFI

```
(gdb) bt
0  raise (sig=sig@entry=11) at ../sysdeps/unix/sysv/linux/raise.c:50
1  0x00007f55897c6ab0 in core_handler (signo=11, siginfo=0x7ffd19764bb0, context=<optimized out>) at lib/sigevent.c:246
2  <signal handler called>
3  0x00005624ccabdee9 in bgp_get_reuse_time (penalty=<optimized out>, buf=buf@entry=0x7ffd19765590 "", len=len@entry=25, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_UNICAST, use_json=<optimized out>, json=0x0)
    at bgpd/bgp_damp.c:498
4  0x00005624ccabf5e7 in bgp_damp_reuse_time_vty (vty=vty@entry=0x5624ce484e30, path=path@entry=0x5624cdd797a0, timebuf=timebuf@entry=0x7ffd19765590 "", len=len@entry=25, afi=afi@entry=AFI_IP,
    safi=safi@entry=SAFI_UNICAST, use_json=false, json=0x0) at bgpd/bgp_damp.c:635
5  0x00005624cca146a9 in damp_route_vty_out (afi=AFI_IP, json_paths=0x0, use_json=false, safi=SAFI_UNICAST, display=<optimized out>, path=0x5624cdd797a0, p=0x5624ce3f3160, vty=0x5624ce484e30)
    at bgpd/bgp_route.c:9852
6  bgp_show_table (vty=0x5624ce484e30, bgp=0x5624ce400950, safi=safi@entry=SAFI_UNICAST, table=0x5624ce409300, type=type@entry=bgp_show_type_dampend_paths, output_arg=0x0, rd=0x0, is_last=1, output_cum=0x0,
    total_cum=0x0, json_header_depth=0x7ffd19765830, show_flags=0, rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11448
7  0x00005624cca15f74 in bgp_show (vty=vty@entry=0x5624ce484e30, bgp=<optimized out>, afi=<optimized out>, safi=<optimized out>, type=type@entry=bgp_show_type_dampend_paths, output_arg=output_arg@entry=0x0,
    show_flags=0, rpki_target_state=RPKI_NOT_BEING_USED) at bgpd/bgp_route.c:11702
8  0x00005624cca17679 in show_ip_bgp_magic (self=<optimized out>, viewvrfname=<optimized out>, aa_nn=<optimized out>, community_list=<optimized out>, community_list_str=<optimized out>,
    community_list_name=<optimized out>, as_path_filter_name=<optimized out>, prefix_list=<optimized out>, accesslist_name=<optimized out>, rmap_name=<optimized out>, version=<optimized out>,
    version_str=<optimized out>, alias_name=<optimized out>, wide=<optimized out>, detail_json=<optimized out>, uj=<optimized out>, detail_routes=<optimized out>, all=<optimized out>, argv=0x5624ce3f32f0,
    argc=<optimized out>, vty=0x5624ce484e30) at bgpd/bgp_route.c:12863
9  show_ip_bgp (self=<optimized out>, vty=<optimized out>, argc=<optimized out>, argv=0x5624ce3f32f0) at ./bgpd/bgp_route_clippy.c:514
10 0x00007f55897618ee in cmd_execute_command_real (vline=vline@entry=0x5624ce427020, vty=vty@entry=0x5624ce484e30, cmd=cmd@entry=0x0, up_level=up_level@entry=0) at lib/command.c:993
11 0x00007f5589761a91 in cmd_execute_command (vline=vline@entry=0x5624ce427020, vty=vty@entry=0x5624ce484e30, cmd=0x0, vtysh=vtysh@entry=0) at lib/command.c:1051
12 0x00007f5589761c30 in cmd_execute (vty=vty@entry=0x5624ce484e30, cmd=cmd@entry=0x5624ce47b1b0 "show bgp dampening damp", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1218
13 0x00007f55897de95e in vty_command (vty=vty@entry=0x5624ce484e30, buf=<optimized out>) at lib/vty.c:591
14 0x00007f55897deb9d in vty_execute (vty=0x5624ce484e30) at lib/vty.c:1354
15 0x00007f55897e23eb in vtysh_read (thread=<optimized out>) at lib/vty.c:2362
16 0x00007f55897d9426 in event_call (thread=thread@entry=0x7ffd19767e70) at lib/event.c:1971
17 0x00007f5589789df8 in frr_run (master=0x5624cdc42100) at lib/libfrr.c:1213
18 0x00005624cc985f65 in main (argc=<optimized out>, argv=0x7ffd197680d8) at bgpd/bgp_main.c:510
(gdb) frame 4
(gdb) p damp[1][1]
$4 = {suppress_value = 0, reuse_limit = 0, max_suppress_time = 0, half_life = 0, tmax = 0, reuse_list_size = 0, reuse_index_size = 0, ceiling = 0, decay_rate_per_tick = 0, decay_array_size = 0,
  scale_factor = 0, reuse_scale_factor = 0, decay_array = 0x0, reuse_index = 0x0, reuse_list = 0x0, reuse_offset = 0, no_reuse_list = 0x0, t_reuse = 0x0, afi = AFI_UNSPEC, safi = SAFI_UNSPEC}
(gdb) p damp[2][1]
$5 = {suppress_value = 1, reuse_limit = 1, max_suppress_time = 1800, half_life = 60, tmax = 0, reuse_list_size = 181, reuse_index_size = 1024, ceiling = 1073741824, decay_rate_per_tick = 0,
  decay_array_size = 360, scale_factor = 9.5367431729442842e-07, reuse_scale_factor = 0, decay_array = 0x5624ce483780, reuse_index = 0x5624ce481320, reuse_list = 0x5624ce482c20, reuse_offset = 7,
  no_reuse_list = 0x0, t_reuse = 0x5624ce3ec840, afi = AFI_UNSPEC, safi = SAFI_UNSPEC}
(gdb)
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
19 months agobgpd: Initialise timebuf arrays to zeros for dampening reuse timer
Donatas Abraitis [Thu, 21 Sep 2023 13:00:10 +0000 (16:00 +0300)]
bgpd: Initialise timebuf arrays to zeros for dampening reuse timer

Avoid having something like this in outputs:

Before:
```
munet> r1 shi vtysh -c 'show bgp dampening damp'
BGP table version is 10, local router ID is 10.10.10.1, vrf id 0
Default local pref 100, local AS 65001
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          From             Reuse    Path
 *d 2001:db8:1::1/128
                    2001:db8::2      (null) 65002 ?
 *d 2001:db8:2::1/128
                    2001:db8::2      (null) 65002 ?
 *d 2001:db8:3::1/128
                    2001:db8::2      (null) 65002 ?
 *d 2001:db8:4::1/128
                    2001:db8::2      (null) 65002 ?
 *d 2001:db8:5::1/128
                    2001:db8::2      (null) 65002 ?

Displayed  5 routes and 5 total paths

munet> r1 shi vtysh -c 'show bgp dampening flap'
BGP table version is 10, local router ID is 10.10.10.1, vrf id 0
Default local pref 100, local AS 65001
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          From            Flaps Duration Reuse    Path
 *d 2001:db8:1::1/128
                    2001:db8::2     2    00:03:10 (null) 65002 ?
 *d 2001:db8:2::1/128
                    2001:db8::2     2    00:03:10 (null) 65002 ?
 *d 2001:db8:3::1/128
                    2001:db8::2     2    00:03:10 (null) 65002 ?
 *d 2001:db8:4::1/128
                    2001:db8::2     2    00:03:10 (null) 65002 ?
 *d 2001:db8:5::1/128
                    2001:db8::2     2    00:03:10 (null) 65002 ?

Displayed  5 routes and 5 total paths
```

After:

```
munet> r1 shi vtysh -c 'show bgp dampening damp '
BGP table version is 10, local router ID is 10.10.10.1, vrf id 0
Default local pref 100, local AS 65001
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          From             Reuse    Path
 *d 2001:db8:1::1/128
                    2001:db8::2      00:00:00 65002 ?
 *d 2001:db8:2::1/128
                    2001:db8::2      00:00:00 65002 ?
 *d 2001:db8:3::1/128
                    2001:db8::2      00:00:00 65002 ?
 *d 2001:db8:4::1/128
                    2001:db8::2      00:00:00 65002 ?
 *d 2001:db8:5::1/128
                    2001:db8::2      00:00:00 65002 ?

Displayed  5 routes and 5 total paths

munet> r1 shi vtysh -c 'show bgp dampening flap'
BGP table version is 10, local router ID is 10.10.10.1, vrf id 0
Default local pref 100, local AS 65001
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          From            Flaps Duration Reuse    Path
 *d 2001:db8:1::1/128
                    2001:db8::2     2    00:00:15 00:00:00 65002 ?
 *d 2001:db8:2::1/128
                    2001:db8::2     2    00:00:15 00:00:00 65002 ?
 *d 2001:db8:3::1/128
                    2001:db8::2     2    00:00:15 00:00:00 65002 ?
 *d 2001:db8:4::1/128
                    2001:db8::2     2    00:00:15 00:00:00 65002 ?
 *d 2001:db8:5::1/128
                    2001:db8::2     2    00:00:15 00:00:00 65002 ?

Displayed  5 routes and 5 total paths
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
19 months agobgpd: Use proper AFI when dumping information for dampening stuff
Donatas Abraitis [Thu, 21 Sep 2023 13:08:50 +0000 (16:08 +0300)]
bgpd: Use proper AFI when dumping information for dampening stuff

Before we called IPv4 for IPv6 dampening info.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
19 months agoMerge pull request #14433 from FRRouting/mergify/bp/stable/8.5/pr-14418
Donatas Abraitis [Mon, 18 Sep 2023 11:45:51 +0000 (14:45 +0300)]
Merge pull request #14433 from FRRouting/mergify/bp/stable/8.5/pr-14418

tools: make --quiet actually suppress output (backport #14418)

19 months agotools: make --quiet actually suppress output 14433/head
Jonas Gorski [Thu, 14 Sep 2023 15:04:16 +0000 (17:04 +0200)]
tools: make --quiet actually suppress output

When calling daemon_stop() with --quiet and e.g. the pidfile is empty,
it won't return early since while "$fail" is set, "$2" is "--quiet", so
the if condition isn't met and it will continue executing, resulting
in error messages in the log:

> Sep 14 14:48:33 localhost watchfrr[2085]: [YFT0P-5Q5YX] Forked background command [pid 2086]: /usr/lib/frr/watchfrr.sh restart all
> Sep 14 14:48:33 localhost frrinit.sh[2075]: /usr/lib/frr/frrcommon.sh: line 216: kill: `': not a pid or valid job spec
> Sep 14 14:48:33 localhost frrinit.sh[2075]: /usr/lib/frr/frrcommon.sh: line 216: kill: `': not a pid or valid job spec
> Sep 14 14:48:33 localhost frrinit.sh[2075]: /usr/lib/frr/frrcommon.sh: line 216: kill: `': not a pid or valid job spec

Fix this by moving the --quiet check into the block to log_failure_msg(),
and also add the check to all other invocations of log_*_msg() to make
--quiet properly suppress output.

Fixes: 19a99d89f088 ("tools: suppress unuseful warnings during restarting frr")
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
(cherry picked from commit 312d5ee1592f8c5b616d330233d1de2643f759e2)

19 months agoMerge pull request #14425 from FRRouting/mergify/bp/stable/8.5/pr-14417
Donatas Abraitis [Mon, 18 Sep 2023 05:57:00 +0000 (08:57 +0300)]
Merge pull request #14425 from FRRouting/mergify/bp/stable/8.5/pr-14417

zebra: fix link update for veth interfaces (backport #14417)

19 months agozebra: fix link update for veth interfaces 14425/head
Jafar Al-Gharaibeh [Thu, 14 Sep 2023 14:24:25 +0000 (09:24 -0500)]
zebra: fix link update for veth interfaces

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
(cherry picked from commit d85671181bb06292877633c66cf80cf83a91c7f6)

19 months agoMerge pull request #14362 from FRRouting/mergify/bp/stable/8.5/pr-14358
Donald Sharp [Thu, 7 Sep 2023 13:30:08 +0000 (09:30 -0400)]
Merge pull request #14362 from FRRouting/mergify/bp/stable/8.5/pr-14358

zebra: Prevent Null pointer deref (backport #14358)

19 months agozebra: Prevent Null pointer deref 14362/head
Donald Sharp [Wed, 6 Sep 2023 12:39:02 +0000 (08:39 -0400)]
zebra: Prevent Null pointer deref

If the kernel sends us bad data then the kind_str
will be NULL and a later strcmp operation will
cause a crash.

As a note: If the kernel is not sending us properly
formated netlink messages then we got bigger problems
than zebra crashing.  But at least let's prevent zebra
from crashing.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 2b9373c114dfc0154f6291474789f44256358518)

19 months agoMerge pull request #14354 from opensourcerouting/fix/backport_27ccfd9aa69f05646439e46...
Donald Sharp [Tue, 5 Sep 2023 18:02:27 +0000 (14:02 -0400)]
Merge pull request #14354 from opensourcerouting/fix/backport_27ccfd9aa69f05646439e46db6e25945a9ce8c19_8.5

zebra: Fix zebra crash when replacing NHE during shutdown

19 months agozebra: Fix zebra crash when replacing NHE during shutdown 14354/head
Rajasekar Raja [Thu, 17 Aug 2023 07:47:05 +0000 (00:47 -0700)]
zebra: Fix zebra crash when replacing NHE during shutdown

During replace of a NHE from upper proto in zebra_nhg_proto_add(),
 - rib_handle_nhg_replace() is invoked with old NHE where we walk all
   RNs/REs & replace the re->nhe whose address points to old NHE.
 - In this walk, if prev re->nhe refcnt is decremented to 0, we free up
   the memory which the old NHE is pointing to.
Later in zebra_nhg_proto_add(), we end up accessing this freed memory
and crash.

Logs:
1380766 2023/08/16 22:34:11.994671 ZEBRA: [WDEB1-93HCZ] zebra_nhg_decrement_ref: nhe 0x56091d890840 (70312519[2756/2762/2810]) 2 => 1
1380773 2023/08/16 22:34:11.994678 ZEBRA: [WDEB1-93HCZ] zebra_nhg_decrement_ref: nhe 0x56091d890840 (70312519[2756/2762/2810]) 1 => 0
1380777 2023/08/16 22:34:11.994844 ZEBRA: [JE46R-G2NEE] zebra_nhg_release: nhe 0x56091d890840 (70312519[2756/2762/2810])
1380778 2023/08/16 22:34:11.994849 ZEBRA: [SCDBM-4H062] zebra_nhg_free: nhe 0x56091d890840 (70312519[2756/2762/2810]), refcnt 0
1380782 2023/08/16 22:34:11.995000 ZEBRA: [SCDBM-4H062] zebra_nhg_free: nhe 0x56091d890840 (0[]), refcnt 0
1380783 2023/08/16 22:34:11.995011 ZEBRA: lib/memory.c:84: mt_count_free(): assertion (mt->n_alloc) failed

Backtrace:
0  0x00007f833f5f48eb in raise () from /lib/x86_64-linux-gnu/libc.so.6
1  0x00007f833f5df535 in abort () from /lib/x86_64-linux-gnu/libc.so.6
2  0x00007f833f636648 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
3  0x00007f833f63cd6a in ?? () from /lib/x86_64-linux-gnu/libc.so.6
4  0x00007f833f63cfb4 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
5  0x00007f833f63fbc8 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
6  0x00007f833f64172a in malloc () from /lib/x86_64-linux-gnu/libc.so.6
7  0x00007f833f6c3fd2 in backtrace_symbols () from /lib/x86_64-linux-gnu/libc.so.6
8  0x00007f833f9013fc in zlog_backtrace_sigsafe (priority=priority@entry=2, program_counter=program_counter@entry=0x7f833f5f48eb <raise+267>) at lib/log.c:222
9  0x00007f833f901593 in zlog_signal (signo=signo@entry=6, action=action@entry=0x7f833f988ee8 "aborting...", siginfo_v=siginfo_v@entry=0x7ffee1ce4a30,
    program_counter=program_counter@entry=0x7f833f5f48eb <raise+267>) at lib/log.c:154
10 0x00007f833f92dbd1 in core_handler (signo=6, siginfo=0x7ffee1ce4a30, context=<optimized out>) at lib/sigevent.c:254
11 <signal handler called>
12 0x00007f833f5f48eb in raise () from /lib/x86_64-linux-gnu/libc.so.6
13 0x00007f833f5df535 in abort () from /lib/x86_64-linux-gnu/libc.so.6
14 0x00007f833f958f96 in _zlog_assert_failed (xref=xref@entry=0x7f833f9e4080 <_xref.10705>, extra=extra@entry=0x0) at lib/zlog.c:680
15 0x00007f833f905400 in mt_count_free (mt=0x7f833fa02800 <MTYPE_NH_LABEL>, ptr=0x51) at lib/memory.c:84
16 mt_count_free (ptr=0x51, mt=0x7f833fa02800 <MTYPE_NH_LABEL>) at lib/memory.c:80
17 qfree (mt=0x7f833fa02800 <MTYPE_NH_LABEL>, ptr=0x51) at lib/memory.c:140
18 0x00007f833f90799c in nexthop_del_labels (nexthop=nexthop@entry=0x56091d776640) at lib/nexthop.c:563
19 0x00007f833f907b91 in nexthop_free (nexthop=0x56091d776640) at lib/nexthop.c:393
20 0x00007f833f907be8 in nexthops_free (nexthop=<optimized out>) at lib/nexthop.c:408
21 0x000056091c21aa76 in zebra_nhg_free_members (nhe=0x56091d890840) at zebra/zebra_nhg.c:1628
22 zebra_nhg_free (nhe=0x56091d890840) at zebra/zebra_nhg.c:1628
23 0x000056091c21bab2 in zebra_nhg_proto_add (id=<optimized out>, type=9, instance=<optimized out>, session=0, nhg=nhg@entry=0x56091d7da028, afi=afi@entry=AFI_UNSPEC)
    at zebra/zebra_nhg.c:3532
24 0x000056091c22bc4e in process_subq_nhg (lnode=0x56091d88c540) at zebra/zebra_rib.c:2689
25 process_subq (qindex=META_QUEUE_NHG, subq=0x56091d24cea0) at zebra/zebra_rib.c:3290
26 meta_queue_process (dummy=<optimized out>, data=0x56091d24d4c0) at zebra/zebra_rib.c:3343
27 0x00007f833f9492c8 in work_queue_run (thread=0x7ffee1ce55a0) at lib/workqueue.c:285
28 0x00007f833f93f60d in thread_call (thread=thread@entry=0x7ffee1ce55a0) at lib/thread.c:2008
29 0x00007f833f8f9888 in frr_run (master=0x56091d068660) at lib/libfrr.c:1223
30 0x000056091c1b8366 in main (argc=12, argv=0x7ffee1ce5988) at zebra/main.c:551

Issue: 3492162

Ticket# 3492162

Signed-off-by: Chirag Shah <chirag@nvidia.com>
Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
19 months agoFRR Release 8.5.3 docker/8.5.3 frr-8.5.3
Jafar Al-Gharaibeh [Sat, 2 Sep 2023 04:06:15 +0000 (23:06 -0500)]
FRR Release 8.5.3

Bug Fixes:

bgpd
    Add peers back to peer hash when peer_xfer_conn fails
    Do not explicitly print maxttl value for ebgp-multihop vty output
    Do not process nlris if the attribute length is zero
    Do not try to redistribute routes if we are shutting down
    Don't read the first byte of orf header if we are ahead of stream
    Evpn code was not properly unlocking rd_dest
    Fix `show bgp all rpki notfound`
    Fix session reset issue caused by malformed core attributes
    Free bgp vpn policy
    Free previously dup'ed aspath attribute for aggregate routes
    Free temporary memory after using argv_concat()
    Intern attributes before putting into rib-out
    Make sure we have enough data to read two bytes when validating aigp
    Prevent use after free
    Rfapi memleak fixes, clean ce tables at exit
    Unlock dest if we return earlier for aggregate install
    Use treat-as-withdraw for tunnel encapsulation attribute

lib
    Allow unsetting walltime-warning and cpu-warning
    Skip route-map optimization if !af_inet(6)
    Use max_bitlen instead of magic number

ospf6d
    Fix crash because neighbor structure was freed
    Stop crash in ospf6_write

ospfd
    Check for nulls in vty code
    Prevent use after free( and crash of ospf ) when no router ospf

pbrd
    Fix crash with match command

pimd
    Prevent crash when receiving register message when the rp() is unknown
    When receiving a packet be more careful with length in pim_pim_packet

ripd, ripngd
    Revert "Cleanup memory allocations on shutdown"

tools
    Add what frr thinks as the fib routes for support_bundle

vtysh
    Print uniq lines when parsing `no service ...`

zebra
    Abstract `dplane_ctx_route_init` to init route without copying
    Fix crash when `dplane_fpm_nl` fails to process received routes
    Further handle route replace semantics
    Fix command ipv6 nht xxx
    Fix evpn nexthop config order

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
19 months agoMerge pull request #14338 from FRRouting/mergify/bp/stable/8.5/pr-14294
Jafar Al-Gharaibeh [Sat, 2 Sep 2023 03:19:09 +0000 (22:19 -0500)]
Merge pull request #14338 from FRRouting/mergify/bp/stable/8.5/pr-14294

pimd: Prevent crash when receiving register message when the RP() is … (backport #14294)

19 months agoMerge pull request #14335 from FRRouting/mergify/bp/stable/8.5/pr-14327
Jafar Al-Gharaibeh [Fri, 1 Sep 2023 19:36:09 +0000 (14:36 -0500)]
Merge pull request #14335 from FRRouting/mergify/bp/stable/8.5/pr-14327

bgpd: Fix `show bgp all rpki notfound` (backport #14327)

19 months agoMerge pull request #14337 from opensourcerouting/fix/backport_ce1f5d3774935e1694fd140...
Jafar Al-Gharaibeh [Fri, 1 Sep 2023 19:35:28 +0000 (14:35 -0500)]
Merge pull request #14337 from opensourcerouting/fix/backport_ce1f5d3774935e1694fd140858f3c3cdecf64ba4_8.5

bgpd: Add peers back to peer hash when peer_xfer_conn fails

19 months agopimd: Prevent crash when receiving register message when the RP() is unknown 14338/head
Donald Sharp [Tue, 29 Aug 2023 18:59:34 +0000 (14:59 -0400)]
pimd: Prevent crash when receiving register message when the RP() is unknown

When receiving a register message for a Group, that the group has no
associated RP specified.  Prevent a crash from happening.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 54aa0bf6f294bd3a722d1707aa071ce97aa09a22)

19 months agobgpd: Add peers back to peer hash when peer_xfer_conn fails 14337/head
Donald Sharp [Wed, 30 Aug 2023 11:25:06 +0000 (07:25 -0400)]
bgpd: Add peers back to peer hash when peer_xfer_conn fails

It was noticed that occassionally peering failed in a testbed
upon investigation it was found that the peer was not in the
peer hash and we saw these failure messages:

Aug 25 21:31:15 doca-hbn-service-bf3-s06-1-ipmi bgpd[3048]: %NOTIFICATION: sent to neighbor 2001:cafe:1ead:4::4 4/0 (Hold Timer Expired) 0 bytes
Aug 25 21:31:22 doca-hbn-service-bf3-s06-1-ipmi bgpd[3048]: [EC 100663299] Can't get remote address and port: Transport endpoint is not connected
Aug 25 21:31:22 doca-hbn-service-bf3-s06-1-ipmi bgpd[3048]: [EC 100663299] %bgp_getsockname() failed for  peer 2001:cafe:1ead:4::4 fd 27 (from_peer fd -1)
Aug 25 21:31:22 doca-hbn-service-bf3-s06-1-ipmi bgpd[3048]: [EC 33554464] %Neighbor failed in xfer_conn

root@doca-hbn-service-bf3-s06-1-ipmi:/var/log/hbn/frr# vtysh -c 'show bgp peerhash' | grep 2001:cafe:1ead:4::4
root@doca-hbn-service-bf3-s06-1-ipmi:/var/log/hbn/frr#

Upon looking at the code the peer_xfer_conn function can fail
and the bgp_establish code will then return before adding the
peer back to the peerhash.

This is only part of the failure.  The peer also appears to
be in a state where it is no longer initiating connection attempts
but that will be another commited fix when we figure that one out.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
19 months agobgpd: Fix `show bgp all rpki notfound` 14335/head
Ryo Nakano [Fri, 1 Sep 2023 02:44:03 +0000 (11:44 +0900)]
bgpd: Fix `show bgp all rpki notfound`

The command "show bgp all rpki notfound" includes not only RPKI
notfound routes but also RPKI valid and invalid routes in its results.

Fix the code to display only RPKI notfound routes.

Old output:
```
frr# show bgp all rpki notfound

For address family: IPv4 Unicast
BGP table version is 0, local router ID is 10.0.0.1, vrf id 0
Default local pref 100, local AS 64512
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
N   x.x.x.0/18       a.a.a.a                       100      0 64513 i
V   y.y.y.0/19       a.a.a.a                       200      0 64513 i
I   z.z.z.0/16       a.a.a.a                        10      0 64513 i

Displayed  3 routes and 3 total paths
```

New output:
```
frr# show bgp all rpki notfound

For address family: IPv4 Unicast
BGP table version is 0, local router ID is 10.0.0.1, vrf id 0
Default local pref 100, local AS 64512
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
N   x.x.x.0/18       a.a.a.a                       100      0 64513 i

Displayed  1 routes and 3 total paths
```

Signed-off-by: Ryo Nakano <ryo.z.nakano@gmail.com>
(cherry picked from commit 65d6b56a063006c38ee695e711be3b3e78fb1745)

19 months agoMerge pull request #14320 from opensourcerouting/fix/backport_530be6a4d089600f1028439...
Jafar Al-Gharaibeh [Thu, 31 Aug 2023 16:59:38 +0000 (11:59 -0500)]
Merge pull request #14320 from opensourcerouting/fix/backport_530be6a4d089600f1028439ddec420ef651b983b_8.5

ospfd: Prevent use after free( and crash of ospf ) when no router ospf

19 months agoMerge pull request #14312 from FRRouting/mergify/bp/stable/8.5/pr-14302
Donald Sharp [Thu, 31 Aug 2023 11:41:55 +0000 (07:41 -0400)]
Merge pull request #14312 from FRRouting/mergify/bp/stable/8.5/pr-14302

pimd: When receiving a packet be more careful with length in pim_pim_… (backport #14302)

19 months agoospfd: Prevent use after free( and crash of ospf ) when no router ospf 14320/head
Donald Sharp [Wed, 30 Aug 2023 14:33:29 +0000 (10:33 -0400)]
ospfd: Prevent use after free( and crash of ospf ) when no router ospf

Consider this config:

router ospf
  redistribute kernel

Then you issue:

no router ospf

ospf will crash with a use after free.

The problem is that the event's associated with the
ospf pointer were shut off then the ospf_external_delete
was called which rescheduled the event.  Let's just move
event deletion to the end of the no router ospf.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
19 months agopimd: When receiving a packet be more careful with length in pim_pim_packet 14312/head
Donald Sharp [Wed, 30 Aug 2023 12:54:33 +0000 (08:54 -0400)]
pimd: When receiving a packet be more careful with length in pim_pim_packet

a) If the length passed is the header length then it is possible that
assignment of data will happen without data actually existing.

b) Just move the assignment to after we ensure that the pim packet
received is the minimum possible length that can be received.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 3163c64d2893b5411d299952ff16dfc05e2c7a86)

20 months agoMerge pull request #14296 from FRRouting/mergify/bp/stable/8.5/pr-14290
Donatas Abraitis [Wed, 30 Aug 2023 07:03:19 +0000 (10:03 +0300)]
Merge pull request #14296 from FRRouting/mergify/bp/stable/8.5/pr-14290

bgpd: Use treat-as-withdraw for tunnel encapsulation attribute (backport #14290)

20 months agoMerge pull request #14292 from FRRouting/mergify/bp/stable/8.5/pr-14243
Jafar Al-Gharaibeh [Wed, 30 Aug 2023 03:26:52 +0000 (22:26 -0500)]
Merge pull request #14292 from FRRouting/mergify/bp/stable/8.5/pr-14243

bgpd: Do not explicitly print MAXTTL value for ebgp-multihop vty output (backport #14243)

20 months agobgpd: Use treat-as-withdraw for tunnel encapsulation attribute 14296/head
Donatas Abraitis [Thu, 13 Jul 2023 19:32:03 +0000 (22:32 +0300)]
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>
(cherry picked from commit bcb6b58d9530173df41d3a3cbc4c600ee0b4b186)

20 months agobgpd: Do not explicitly print MAXTTL value for ebgp-multihop vty output 14292/head
Donatas Abraitis [Sun, 20 Aug 2023 21:01:42 +0000 (00:01 +0300)]
bgpd: Do not explicitly print MAXTTL value for ebgp-multihop vty output

1. Create /etc/frr/frr.conf
```
frr version 7.5
frr defaults traditional
hostname centos8.localdomain
no ip forwarding
no ipv6 forwarding
service integrated-vtysh-config
line vty
router bgp 4250001000
  neighbor 192.168.122.207 remote-as 65512
  neighbor 192.168.122.207 ebgp-multihop
```

2. Start FRR
`# systemctl start frr
`
3. Show running configuration. Note that FRR explicitly set and shows the default TTL (225)

```
Building configuration...

Current configuration:
!
frr version 7.5
frr defaults traditional
hostname centos8.localdomain
no ip forwarding
no ipv6 forwarding
service integrated-vtysh-config
!
router bgp 4250001000
 neighbor 192.168.122.207 remote-as 65512
 neighbor 192.168.122.207 ebgp-multihop 255
!
line vty
!
end
```
4. Copy initial frr.conf to frr.conf.new (no changes)
`# cp /etc/frr/frr.conf /root/frr.conf.new
`
5. Run frr-reload.sh:

```
$ /usr/lib/frr/frr-reload.py --test  /root/frr.conf.new
2023-08-20 20:15:48,050  INFO: Called via "Namespace(bindir='/usr/bin', confdir='/etc/frr', daemon='', debug=False, filename='/root/frr.conf.new', input=None, log_level='info', overwrite=False, pathspace=None, reload=False, rundir='/var/run/frr', stdout=False, test=True, vty_socket=None)"
2023-08-20 20:15:48,050  INFO: Loading Config object from file /root/frr.conf.new
2023-08-20 20:15:48,124  INFO: Loading Config object from vtysh show running

Lines To Delete
===============
router bgp 4250001000
 no neighbor 192.168.122.207 ebgp-multihop 255

Lines To Add
============
router bgp 4250001000
 neighbor 192.168.122.207 ebgp-multihop
```

Closes https://github.com/FRRouting/frr/issues/14242

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 767aaa3a80489bfc4ff097f932fc347e3db25b89)

20 months agoMerge pull request #14270 from FRRouting/mergify/bp/stable/8.5/pr-14260
Donald Sharp [Thu, 24 Aug 2023 18:54:14 +0000 (14:54 -0400)]
Merge pull request #14270 from FRRouting/mergify/bp/stable/8.5/pr-14260

bgpd: Do not process NLRIs if the attribute length is zero (backport #14260)

20 months agobgpd: Do not process NLRIs if the attribute length is zero 14270/head
Donatas Abraitis [Tue, 22 Aug 2023 19:52:04 +0000 (22:52 +0300)]
bgpd: Do not process NLRIs if the attribute length is zero

```
3  0x00007f423aa42476 in __GI_raise (sig=sig@entry=11) at ../sysdeps/posix/raise.c:26
4  0x00007f423aef9740 in core_handler (signo=11, siginfo=0x7fffc414deb0, context=<optimized out>) at lib/sigevent.c:246
5  <signal handler called>
6  0x0000564dea2fc71e in route_set_aspath_prepend (rule=0x564debd66d50, prefix=0x7fffc414ea30, object=0x7fffc414e400)
    at bgpd/bgp_routemap.c:2258
7  0x00007f423aeec7e0 in route_map_apply_ext (map=<optimized out>, prefix=prefix@entry=0x7fffc414ea30,
    match_object=match_object@entry=0x7fffc414e400, set_object=set_object@entry=0x7fffc414e400, pref=pref@entry=0x0) at lib/routemap.c:2690
8  0x0000564dea2d277e in bgp_input_modifier (peer=peer@entry=0x7f4238f59010, p=p@entry=0x7fffc414ea30, attr=attr@entry=0x7fffc414e770,
    afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_UNICAST, rmap_name=rmap_name@entry=0x0, label=0x0, num_labels=0, dest=0x564debdd5130)
    at bgpd/bgp_route.c:1772
9  0x0000564dea2df762 in bgp_update (peer=peer@entry=0x7f4238f59010, p=p@entry=0x7fffc414ea30, addpath_id=addpath_id@entry=0,
    attr=0x7fffc414eb50, afi=afi@entry=AFI_IP, safi=<optimized out>, safi@entry=SAFI_UNICAST, type=9, sub_type=0, prd=0x0, label=0x0,
    num_labels=0, soft_reconfig=0, evpn=0x0) at bgpd/bgp_route.c:4374
10 0x0000564dea2e2047 in bgp_nlri_parse_ip (peer=0x7f4238f59010, attr=attr@entry=0x7fffc414eb50, packet=0x7fffc414eaf0)
    at bgpd/bgp_route.c:6249
11 0x0000564dea2c5a58 in bgp_nlri_parse (peer=peer@entry=0x7f4238f59010, attr=attr@entry=0x7fffc414eb50,
    packet=packet@entry=0x7fffc414eaf0, mp_withdraw=mp_withdraw@entry=false) at bgpd/bgp_packet.c:339
12 0x0000564dea2c5d66 in bgp_update_receive (peer=peer@entry=0x7f4238f59010, size=size@entry=109) at bgpd/bgp_packet.c:2024
13 0x0000564dea2c901d in bgp_process_packet (thread=<optimized out>) at bgpd/bgp_packet.c:2933
14 0x00007f423af0bf71 in event_call (thread=thread@entry=0x7fffc414ee40) at lib/event.c:1995
15 0x00007f423aebb198 in frr_run (master=0x564deb73c670) at lib/libfrr.c:1213
16 0x0000564dea261b83 in main (argc=<optimized out>, argv=<optimized out>) at bgpd/bgp_main.c:505
```

With the configuration:

```
frr version 9.1-dev-MyOwnFRRVersion
frr defaults traditional
hostname ip-172-31-13-140
log file /tmp/debug.log
log syslog
service integrated-vtysh-config
!
debug bgp keepalives
debug bgp neighbor-events
debug bgp updates in
debug bgp updates out
!
router bgp 100
 bgp router-id 9.9.9.9
 no bgp ebgp-requires-policy
 bgp bestpath aigp
 neighbor 172.31.2.47 remote-as 200
 !
 address-family ipv4 unicast
  neighbor 172.31.2.47 default-originate
  neighbor 172.31.2.47 route-map RM_IN in
 exit-address-family
exit
!
route-map RM_IN permit 10
 set as-path prepend 200
exit
!
```

The issue is that we try to process NLRIs even if the attribute length is 0.

Later bgp_update() will handle route-maps and a crash occurs because all the
attributes are NULL, including aspath, where we dereference.

According to the RFC 4271:

A value of 0 indicates that neither the Network Layer
         Reachability Information field nor the Path Attribute field is
         present in this UPDATE message.

But with a fuzzed UPDATE message this can be faked. I think it's reasonable
to skip processing NLRIs if both update_len and attribute_len are 0.

Reported-by: Iggy Frankovic <iggyfran@amazon.com>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 28ccc24d38df1d51ed8a563507e5d6f6171fdd38)

20 months agoMerge pull request #14268 from FRRouting/mergify/bp/stable/8.5/pr-14232
Donald Sharp [Thu, 24 Aug 2023 14:52:35 +0000 (10:52 -0400)]
Merge pull request #14268 from FRRouting/mergify/bp/stable/8.5/pr-14232

bgpd: Make sure we have enough data to read two bytes when validating AIGP (backport #14232)