Package: bird3
Version: 3.1.8-0+deb13u1
Severity: important
Tags: upstream fixed-upstream patch

Hi,

While testing a routing policy change on our Debian trixie route reflectors
(AS214507), we ran into a crash on birdc configure. The configuration
change only affects filters; no protocols are added or removed.

    Reconfiguring
    Reloading channel slow4.ipv4
    Trying to lock in a bad order: <ptr> <ptr>
    bird.service: Main process exited, code=killed, status=6/ABRT

BIRD is restarted by systemd, which means all BGP sessions on that router
are reset.

The relevant part of the backtrace is:

    do_lock
    bgp_create_update
    bgp_fire_tx
    bgp_schedule_packet
    rt_feeding_done
    rt_feeder_unsubscribe
    rtex_export_unsubscribe
    channel_reconfigure

This matches the upstream fix for issue #513:
https://gitlab.nic.cz/labs/bird/-/commit/decbcf496aba70b44e83586d03c0cc5f42b08915

We reproduced the crash with two route reflectors exporting about 172k IPv4
and 50k IPv6 routes each to a RouterOS 7.25 CHR client. Reloading while the
export feed is still active can trigger the crash. Our reflectors are
Debian 13 amd64 VMs with 1 vCPU, 2 GB RAM and kernel
6.12.113+deb13-cloud-amd64.

In the first set of parallel reload tests after startup, the stock Debian
package crashed in 10 of 20 node-cycles (one forward reload and one
rollback per node). Rebuilding the same package with only decbcf49 gave
0/20. Upstream 3.1.10 gave 0/10. We also reproduced the crash on reflectors
that had been running for several minutes (2/6 cycles).

I've attached the backtraces, test results, patch and a reduced lab
configuration. The reduced configuration has been syntax-checked but not
run as a complete lab. We could not reproduce the crash in our smaller
container setup without a large route feed and a slow receiver.

The fix is already in 3.1.10 and applies to the trixie source package
without conflicts. It would be useful to have it in stable, as we currently
cannot rely on a routine configuration reload keeping the daemon running.

Best regards,
AS214507 / SIA Pūces datorsistēmas (PLDS)
bird3 3.1.8-0+deb13u1 (Debian 13, amd64), symbols from bird3-dbgsym 
3.1.8-0+deb13u1.
Four core dumps from `birdc configure` aborts in a lab (2026-11-30). All four 
have the same
main-thread stack from frame #3 to #15; frames #16+ differ only in how the 
configure was started
(three via the event loop, one synchronously from the CLI command). Pointer 
values are process-local.

Journal immediately before each abort (channel names generic here; lab names 
were the iBGP
sessions to the slow receiver):

  Reconfiguring
  Reloading channel slow4.ipv4
  slow4.ipv4: reloading
  Reloading channel slow6.ipv6
  slow6.ipv6: reloading
  Trying to lock in a bad order: 00007ffcf4cdc6e0 00007fbfb641bdd8
  bird.service: Main process exited, code=killed, status=6/ABRT

==== core 1 of 4 (full) ====
Core was generated by `/usr/sbin/bird -f -u bird -g bird'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007feee0a6269c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
[Current thread is 1 (Thread 0x7feee0113e00 (LWP 8154))]
  Id   Target Id                        Frame 
* 1    Thread 0x7feee0113e00 (LWP 8154) 0x00007feee0a6269c in ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  2    Thread 0x7feedf7f06c0 (LWP 8157) 0x00007feee0a6872e in ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  3    Thread 0x7feedfff16c0 (LWP 8156) 0x00007feee0a5dbbb in ?? () from 
/lib/x86_64-linux-gnu/libc.so.6

Thread 3 (Thread 0x7feedfff16c0 (LWP 8156)):
#0  0x00007feee0a5dbbb in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007feee0a63cb2 in pthread_mutex_lock () from 
/lib/x86_64-linux-gnu/libc.so.6
#2  0x00005633e2962202 in do_lock (dg=dg@entry=0x5634019300c0, 
lsp=0x7feedfff1698) at sysdep/unix/domain.c:121
#3  0x00005633e28ae833 in lfjour_cleanup_hook (_j=0x563401930258) at 
lib/lockfree.c:465
#4  0x00005633e28aae5e in ev_run_list_limited (l=l@entry=0x56340192fe98, 
limit=4294967292, limit@entry=4294967295) at lib/event.c:338
#5  0x00005633e295c2ef in birdloop_run (_loop=0x56340192fdc0) at 
sysdep/unix/io-loop.c:1843
#6  0x00005633e28aae5e in ev_run_list_limited (l=0x5634019cdd78, 
limit=4294967293, limit@entry=4294967295) at lib/event.c:338
#7  0x00005633e295a172 in bird_thread_main (arg=0x5634019cdfd0) at 
sysdep/unix/io-loop.c:959
#8  0x00007feee0a608bb in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#9  0x00007feee0ade538 in ?? () from /lib/x86_64-linux-gnu/libc.so.6

Thread 2 (Thread 0x7feedf7f06c0 (LWP 8157)):
#0  0x00007feee0a6872e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007feee0a5d388 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007feee0a5d3cd in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007feee0ad1746 in poll () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00005633e295a410 in poll (__fds=<optimized out>, __nfds=<optimized out>, 
__timeout=57) at /usr/include/x86_64-linux-gnu/bits/poll2.h:44
#5  bird_thread_main (arg=0x5634019cf9d0) at sysdep/unix/io-loop.c:1020
#6  0x00007feee0a608bb in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#7  0x00007feee0ade538 in ?? () from /lib/x86_64-linux-gnu/libc.so.6

Thread 1 (Thread 0x7feee0113e00 (LWP 8154)):
#0  0x00007feee0a6269c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007feee0a0dc42 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007feee09f64ac in abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00005633e295f0dc in bug (msg=msg@entry=0x5633e297fd90 "Trying to lock in 
a bad order: %p %p") at sysdep/unix/log.c:446
#4  0x00005633e29622f3 in do_lock (dg=0x563401cdd270, lsp=0x7feee0113dd8) at 
sysdep/unix/domain.c:116
#5  0x00005633e291604b in bgp_create_update (c=0x5634019bc4b0, 
buf=0x563401cdc1c3 "") at proto/bgp/packets.c:2620
#6  bgp_fire_tx (conn=conn@entry=0x5634019bc168) at proto/bgp/packets.c:3220
#7  0x00005633e29171b8 in bgp_schedule_packet (conn=0x5634019bc168, 
c=0x5634019bc4b0, type=2) at proto/bgp/packets.c:3304
#8  0x00005633e28d7191 in rt_feeding_done (f=f@entry=0x5634019bc5f8) at 
nest/rt-export.c:347
#9  0x00005633e28d922a in rt_feeder_unsubscribe (f=f@entry=0x5634019bc5f8) at 
nest/rt-export.c:545
#10 0x00005633e28d9464 in rtex_export_unsubscribe (r=r@entry=0x5634019bc5d8) at 
nest/rt-export.c:428
#11 0x00005633e28c9da5 in channel_reconfigure (c=c@entry=0x5634019bc4b0, 
cf=<optimized out>) at nest/proto.c:1340
#12 0x00005633e28d0538 in proto_configure_channel (p=p@entry=0x5634019bbea0, 
pc=pc@entry=0x7ffcc6fdce50, cf=cf@entry=0x7feedcc87630) at nest/proto.c:1428
#13 0x00005633e29087d4 in bgp_reconfigure (P=0x5634019bbea0, CF=0x7feedcc87390) 
at proto/bgp/bgp.c:3187
#14 0x00005633e28d0029 in proto_reconfigure (p=0x5634019bbea0, 
oc=0x7feee00bfa90, nc=0x7feedcc87390, type=<optimized out>) at nest/proto.c:1770
#15 protos_do_commit (new=0x7feedd86c030, old=<optimized out>, type=1) at 
nest/proto.c:1885
#16 0x00005633e28aae5e in ev_run_list_limited (l=l@entry=0x5633e29ee780 
<global_event_list>, limit=4294967293, limit@entry=0) at lib/event.c:338
#17 0x00005633e295522a in io_loop () at sysdep/unix/io.c:2645
#18 0x00005633e286733e in main (argc=<optimized out>, argv=<optimized out>) at 
sysdep/unix/main.c:1106

==== cores 2-4: main thread, frames #3-#15 (identical function/file:line) and 
the differing tail ====
-- core 2
#0  ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  bug (msg=msg@entry=0x55c81b837d90 "Trying to lock in a bad order: %p %p") 
at sysdep/unix/log.c:446
#4  do_lock (dg=0x55c82e8916c0, lsp=0x7fd482c34dd8) at sysdep/unix/domain.c:116
#5  bgp_create_update (c=0x55c82e87b4b0, buf=0x55c82e9a3fe3 "") at 
proto/bgp/packets.c:2620
#6  bgp_fire_tx (conn=conn@entry=0x55c82e87b1f8) at proto/bgp/packets.c:3220
#7  bgp_schedule_packet (conn=0x55c82e87b1f8, c=0x55c82e87b4b0, type=2) at 
proto/bgp/packets.c:3304
#8  rt_feeding_done (f=f@entry=0x55c82e87b5f8) at nest/rt-export.c:347
#9  rt_feeder_unsubscribe (f=f@entry=0x55c82e87b5f8) at nest/rt-export.c:545
#10 rtex_export_unsubscribe (r=r@entry=0x55c82e87b5d8) at nest/rt-export.c:428
#11 channel_reconfigure (c=c@entry=0x55c82e87b4b0, cf=<optimized out>) at 
nest/proto.c:1340
#12 proto_configure_channel (p=p@entry=0x55c82e87aea0, 
pc=pc@entry=0x7fff2a0c8a90, cf=cf@entry=0x7fd47ea83630) at nest/proto.c:1428
#13 bgp_reconfigure (P=0x55c82e87aea0, CF=0x7fd47ea83390) at 
proto/bgp/bgp.c:3187
#14 proto_reconfigure (p=0x55c82e87aea0, oc=0x7fd482be0a90, nc=0x7fd47ea83390, 
type=<optimized out>) at nest/proto.c:1770
#15 protos_do_commit (new=0x7fd48044d030, old=<optimized out>, type=1) at 
nest/proto.c:1885
#16 ev_run_list_limited (l=l@entry=0x55c81b8a6780 <global_event_list>, 
limit=4294967295, limit@entry=0) at lib/event.c:338
#17 io_loop () at sysdep/unix/io.c:2645
#18 main (argc=<optimized out>, argv=<optimized out>) at sysdep/unix/main.c:1106
=== 
Core was generated by `/usr/sbin/bird -f -u bird -g bird'.
Program terminated with signal SIGABRT, Aborted.
#0  ?? () from /lib/x86_64-linux-gnu/libc.so.6
[Current thread is 1 (Thread 0x7f0198dfee00 (LWP 8248))]
  Id   Target Id                        Frame 
* 1    Thread 0x7f0198dfee00 (LWP 8248) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  2    Thread 0x7f01984db6c0 (LWP 8251) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  3    Thread 0x7f0198cdc6c0 (LWP 8250) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6

-- core 3
#0  ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  bug (msg=msg@entry=0x5651ee9ccd90 "Trying to lock in a bad order: %p %p") 
at sysdep/unix/log.c:446
#4  do_lock (dg=0x565218f91570, lsp=0x7f0198dfedd8) at sysdep/unix/domain.c:116
#5  bgp_create_update (c=0x5652190144b0, buf=0x565218faac13 "") at 
proto/bgp/packets.c:2620
#6  bgp_fire_tx (conn=conn@entry=0x5652190141f8) at proto/bgp/packets.c:3220
#7  bgp_schedule_packet (conn=0x5652190141f8, c=0x5652190144b0, type=2) at 
proto/bgp/packets.c:3304
#8  rt_feeding_done (f=f@entry=0x5652190145f8) at nest/rt-export.c:347
#9  rt_feeder_unsubscribe (f=f@entry=0x5652190145f8) at nest/rt-export.c:545
#10 rtex_export_unsubscribe (r=r@entry=0x5652190145d8) at nest/rt-export.c:428
#11 channel_reconfigure (c=c@entry=0x5652190144b0, cf=<optimized out>) at 
nest/proto.c:1340
#12 proto_configure_channel (p=p@entry=0x565219013ea0, 
pc=pc@entry=0x7ffcf21f8730, cf=cf@entry=0x7f01948b4630) at nest/proto.c:1428
#13 bgp_reconfigure (P=0x565219013ea0, CF=0x7f01948b4390) at 
proto/bgp/bgp.c:3187
#14 proto_reconfigure (p=0x565219013ea0, oc=0x7f0198daaa90, nc=0x7f01948b4390, 
type=<optimized out>) at nest/proto.c:1770
#15 protos_do_commit (new=0x7f0193c58030, old=<optimized out>, type=1) at 
nest/proto.c:1885
#16 ev_run_list_limited (l=l@entry=0x5651eea3b780 <global_event_list>, 
limit=4294967293, limit@entry=0) at lib/event.c:338
#17 io_loop () at sysdep/unix/io.c:2645
#18 main (argc=<optimized out>, argv=<optimized out>) at sysdep/unix/main.c:1106
=== 
Core was generated by `/usr/sbin/bird -f -u bird -g bird'.
Program terminated with signal SIGABRT, Aborted.
#0  ?? () from /lib/x86_64-linux-gnu/libc.so.6
[Current thread is 1 (Thread 0x7f41a3055e00 (LWP 8298))]
  Id   Target Id                        Frame 
* 1    Thread 0x7f41a3055e00 (LWP 8298) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  2    Thread 0x7f41a20066c0 (LWP 8301) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6
  3    Thread 0x7f41a28076c0 (LWP 8300) ?? () from 
/lib/x86_64-linux-gnu/libc.so.6

-- core 4
#0  ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  raise () from /lib/x86_64-linux-gnu/libc.so.6
#2  abort () from /lib/x86_64-linux-gnu/libc.so.6
#3  bug (msg=msg@entry=0x55d967da1d90 "Trying to lock in a bad order: %p %p") 
at sysdep/unix/log.c:446
#4  do_lock (dg=0x55d99882e440, lsp=0x7f41a3055dd8) at sysdep/unix/domain.c:116
#5  bgp_create_update (c=0x55d99877a4b0, buf=0x55d998710c13 "") at 
proto/bgp/packets.c:2620
#6  bgp_fire_tx (conn=conn@entry=0x55d99877a168) at proto/bgp/packets.c:3220
#7  bgp_schedule_packet (conn=0x55d99877a168, c=0x55d99877a4b0, type=2) at 
proto/bgp/packets.c:3304
#8  rt_feeding_done (f=f@entry=0x55d99877a5f8) at nest/rt-export.c:347
#9  rt_feeder_unsubscribe (f=f@entry=0x55d99877a5f8) at nest/rt-export.c:545
#10 rtex_export_unsubscribe (r=r@entry=0x55d99877a5d8) at nest/rt-export.c:428
#11 channel_reconfigure (c=c@entry=0x55d99877a4b0, cf=<optimized out>) at 
nest/proto.c:1340
#12 proto_configure_channel (p=p@entry=0x55d998779ea0, 
pc=pc@entry=0x7ffde5935e40, cf=cf@entry=0x7f419d0ccd30) at nest/proto.c:1428
#13 bgp_reconfigure (P=0x55d998779ea0, CF=0x7f419d0cca90) at 
proto/bgp/bgp.c:3187
#14 proto_reconfigure (p=0x55d998779ea0, oc=0x7f419ea5d390, nc=0x7f419d0cca90, 
type=<optimized out>) at nest/proto.c:1770
#15 protos_do_commit (new=new@entry=0x7f419ce9a030, old=<optimized out>, 
type=type@entry=1) at nest/proto.c:1885
#16 protos_commit (new=new@entry=0x7f419ce9a030, old=<optimized out>, 
type=type@entry=1) at nest/proto.c:1830
#17 config_do_commit (cr=cr@entry=0x7ffde5935f80, type=type@entry=1) at 
conf/conf.c:338
#18 config_commit (cr=cr@entry=0x7ffde5935f80, type=type@entry=1, 
timeout=timeout@entry=0) at conf/conf.c:445
#19 cmd_reconfig (name=<optimized out>, type=type@entry=1, timeout=0) at 
sysdep/unix/main.c:369
#20 cf_parse () at sysdep/unix/config.Y:262
#21 cli_parse (main_config=0x7f41a080e030, c=c@entry=0x7ffde59380a0) at 
conf/conf.c:187
#22 cli_command (c=c@entry=0x55d9986f5c10) at nest/cli.c:268
#23 cli_event (data=0x55d9986f5c10) at nest/cli.c:294
#24 ev_run_list_limited (l=l@entry=0x55d967e10780 <global_event_list>, 
limit=4294967294, limit@entry=4294967295) at lib/event.c:338
# bird3 SIGABRT on configuration reload during an active export feed: test results

AS214507, 1 December 2026. Tests were run in isolated containers and GNS3 VMs.

## Lab

- Two BIRD route reflectors (Debian 13 VMs, 1 vCPU, 2 GB RAM, kernel 6.12.113+deb13-cloud-amd64),
  iBGP to each other; ~160k IPv4 + ~46k IPv6 routes from a route generator; each RR exports
  172 010 IPv4 + 50 010 IPv6 routes over iBGP (multihop) to a RouterOS 7.25 CHR VM acting as a
  route-reflector client (the "slow" receiver). Further iBGP/eBGP sessions to emulators.
- Two configurations per RR that differ **only in filters** (the import filter of the channels
  towards the slow receiver and of other iBGP channels: a LOCAL_PREF assignment removed). No
  protocol is added or removed.
- BIRD started on configuration A via a runtime systemd drop-in; `birdc configure` to B, then
  back to A. Abort = BIRD PID changed; every abort was confirmed in the journal
  (`Reloading channel <slow>.ipv4` -> `Trying to lock in a bad order` -> `status=6/ABRT`).
- Scripts: `reproducer/cycle.sh` (generic form of the lab script), compact configs in `reproducer/`.

Packages: `3.1.8-0+deb13u1` (Debian); `+lab1` = Debian source + `decbcf49` + `61be5cde` (kernel
sync, separate report); `+lab1a` = Debian source + `decbcf49` only; upstream v3.1.10 built from
the tag. Lab packages built with `dpkg-buildpackage` in a clean trixie container; unit tests 29 OK.

## Results

| Scenario | Debian 3.1.8 | 3.1.8 + both fixes (`lab1`) | 3.1.8 + `decbcf49` only (`lab1a`) | Upstream 3.1.10 |
|---|---:|---:|---:|---:|
| First configure after start, both RRs restarted and reloaded in parallel (W = 10/30/60/90/180 s after start, forward + rollback) | **10/20** | 0/20 | 0/20 | 0/10 |
| same, control run ~2 h later (same lab) | **4/10** | - | - | - |
| Parallel reload of both RRs, established routing state (BIRD up >= 5 min, export state READY before the call) | **2/6** | 0/16 | not tested | not tested |
| Sequential reload (one RR at a time, ~60 s apart, all channels READY) | 0/24 | not tested | not tested | not tested |

Counts are node-cycles (each cycle = one forward and one rollback configure on one RR).
In the parallel first-reload runs exactly one of the two RRs aborted in every failing pair, at
every W from 10 to 180 s, in both directions (to the new filters and back).

The 0/24 sequential result does **not** show the defect is absent there: the code path needs a
channel whose export feed is active at the moment of the reload; sequential reloads with a pause
simply make that unlikely (feeds had finished). A feed can become active at any time after a
session (re)establishment or a route refresh request from a neighbour.

Earlier (2026-11-30), on the same lab with a configuration that also removed two static protocols:
3.1.7 and 3.1.8 aborted (up to 3/6 per node in parallel runs), v3.1.10 0/12. Four core dumps
with debug symbols: `backtrace.txt`.

## Not reproduced

- Podman lab with 6-7 BIRD instances, no route volume and no slow receiver: 25 rounds of
  toggling configurations (adding/removing protocols and changing filters) on every node, BIRD
  3.1.7 and 3.1.8: **0 aborts**. Same suite on 3.1.8+lab1 and 3.1.10: 0 (as expected).
- Reload of a single RR while the other RR was idle (15 cycles, protocol removal): 0 aborts.

So reproduction needs a large export feed to a slow peer and an overlapping reload; the compact
configuration in `reproducer/` keeps these elements but was not itself run in that form.

## Operational consequence observed

On abort systemd restarts BIRD (about 1 s); all BGP sessions and BFD sessions of that router are
torn down and re-established, its routes are withdrawn from its neighbours and re-learned. With
two route reflectors the clients kept routing through the other reflector in our lab.
Description: BGP: Run external TX from event
 There has been an internal expectation violated by BGP sometimes running
 TX synchronously. That caused several crashes. By moving the
 externally-triggered TX to an event, these crashes are now fixed. The
 bug was introduced by moving the TX to a deferred call which couldn't be
 run externally anymore, and instead of keeping the event as an
 alternative, the bad choice was done to run TX synchronously in that
 case.
 Introduced-In: 45fb9742f07c0db4ffd81f428194de8185ba038f
 Target: patch
 Issue: #513
 Reported-By: taichi aoki
 Actually reported by more independent reporters but taichi aoki also
 sent a really easy reproducer to run.
Author: Maria Matejka <[email protected]>
Origin: upstream, https://gitlab.nic.cz/labs/bird/-/commit/decbcf496aba70b44e83586d03c0cc5f42b08915
Bug: https://gitlab.nic.cz/labs/bird/-/issues/513
Applied-Upstream: v3.1.10, https://gitlab.nic.cz/labs/bird/-/commit/decbcf496aba70b44e83586d03c0cc5f42b08915
Forwarded: not-needed
Last-Update: 2026-12-01
---
 proto/bgp/bgp.c     |  6 +++++-
 proto/bgp/bgp.h     |  2 ++
 proto/bgp/packets.c | 27 ++++++++++++++++++++++-----
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index c2785bcd..a0d8d5a9 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -924,6 +924,8 @@ bgp_close_conn(struct bgp_conn *conn)
   conn->keepalive_timer = NULL;
   rfree(conn->hold_timer);
   conn->hold_timer = NULL;
+  rfree(conn->tx_event);
+  conn->tx_event = NULL;
   rfree(conn->send_hold_timer);
   conn->send_hold_timer = NULL;
 
@@ -1670,7 +1672,7 @@ bgp_sock_err(sock *sk, int err)
   /*
    * This error hook may be called either asynchronously from main
    * loop, or synchronously from sk_send().  But sk_send() is called
-   * only from bgp_tx() and bgp_kick_tx(), which are both called
+   * only from bgp_tx() and bgp_tx_event(), which are both called
    * asynchronously from main loop. Moreover, they end if err hook is
    * called. Therefore, we could suppose that it is always called
    * asynchronously.
@@ -1766,6 +1768,8 @@ bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn)
   conn->hold_timer 	= tm_new_init(p->p.pool, bgp_hold_timeout,	 conn, 0, 0);
   conn->keepalive_timer	= tm_new_init(p->p.pool, bgp_keepalive_timeout, conn, 0, 0);
   conn->send_hold_timer = tm_new_init(p->p.pool, bgp_send_hold_timeout, conn, 0, 0);
+
+  conn->tx_event = ev_new_init(p->p.pool, bgp_tx_event, conn);
 }
 
 static void
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h
index 957d9bd2..3c003291 100644
--- a/proto/bgp/bgp.h
+++ b/proto/bgp/bgp.h
@@ -340,6 +340,7 @@ struct bgp_conn {
   timer *hold_timer;
   timer *keepalive_timer;
   timer *send_hold_timer;
+  event *tx_event;			/* Triggering TX from outside the loop */
   u32 packets_to_send;			/* Bitmap of packet types to be sent */
   u32 channels_to_send;			/* Bitmap of channels with packets to be sent */
   u8 last_channel;			/* Channel used last time for TX */
@@ -787,6 +788,7 @@ const struct bgp_af_desc *bgp_get_af_desc(u32 afi);
 const struct bgp_af_caps *bgp_find_af_caps(struct bgp_caps *caps, u32 afi);
 void bgp_schedule_packet(struct bgp_conn *conn, struct bgp_channel *c, int type);
 void bgp_tx(struct birdsock *sk);
+void bgp_tx_event(void *_conn);
 int bgp_rx(struct birdsock *sk, uint size);
 void bgp_do_uncork(callback *);
 const char * bgp_error_dsc(unsigned code, unsigned subcode);
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c
index 015f5420..6b075f97 100644
--- a/proto/bgp/packets.c
+++ b/proto/bgp/packets.c
@@ -3311,10 +3311,8 @@ bgp_schedule_packet(struct bgp_conn *conn, struct bgp_channel *c, int type)
 
   if (was_active || (conn->sk->tpos != conn->sk->tbuf))
     return;
-  else if ((type == PKT_KEEPALIVE) || (this_birdloop != p->p.loop))
-    while (bgp_fire_tx(conn) > 0)
-      ;
-  else
+
+  if (this_birdloop == p->p.loop)
   {
     struct bgp_tx_deferred_call btdc = {
       .dc.hook = bgp_tx_deferred,
@@ -3322,13 +3320,32 @@ bgp_schedule_packet(struct bgp_conn *conn, struct bgp_channel *c, int type)
     };
     defer_call(&btdc.dc, sizeof btdc);
   }
+  else
+    ev_send_loop(p->p.loop, conn->tx_event);
+}
+
+void
+bgp_tx_event(void *_conn)
+{
+  struct bgp_conn *conn = _conn;
+  DBG("BGP: external TX\n");
+
+  if (conn->tx_event)
+    ev_postpone(conn->tx_event);
+
+  while (bgp_fire_tx(conn) > 0)
+    ;
 }
 
 static void
 bgp_tx_deferred(struct deferred_call *dc)
 {
   struct bgp_conn *conn = SKIP_BACK(struct bgp_tx_deferred_call, dc, dc)->conn;
-  DBG("BGP: kicking TX\n");
+  DBG("BGP: internal TX\n");
+
+  if (conn->tx_event)
+    ev_postpone(conn->tx_event);
+
   while (bgp_fire_tx(conn) > 0)
     ;
 }

Attachment: configure-abort-reproducer.tar.gz
Description: application/gzip

Reply via email to