Commit Graph

32168 Commits

Author SHA1 Message Date
Christian Hopps
c10f8e6da6 mgmtd: KISS the locking code
Move away from things like "lock if not locked" type code, require the
user has locked prior to geting to that point.

For now we warn if we are taking a lock we already had; however, this
should really be a failure point.

New requirements:

SETCFG -
  not implicit commit - requires user has locked candidate DS and they
    must unlock after

  implicit commit - requires user has locked candidate and running DS
    both locks will be unlocked on reply to the SETCFG

COMMITCFG -
  requires user has locked candidate and running DS and they must unlock
  after

  rollback - this code now get both locks and then does an unlock and
  early return thing on the adapter side. It needs to be un-special
  cased in follow up work that would also include tests for this
  functionality.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-25 04:46:54 -04:00
Christian Hopps
318de85f62 mgmtd: simplify locking, removing read locks
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-25 04:46:54 -04:00
Christian Hopps
f8e0a6f1bc lib: mgmtd: use short-circuit for locking
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-25 04:46:54 -04:00
Christian Hopps
286654d2dc lib: mgmtd: re-purpose is_short_circuit and fix depth variable inc/dec
`is_short_circuit` now is set to true when a message is being
short-circuit handled.

`short_circuit_depth` was being inc/dec inside conditional macro, move
that out of the macro.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-25 04:46:54 -04:00
Donatas Abraitis
0ea4297e3c
Merge pull request #13843 from FRRouting/mergify/bp/dev/9.0/pr-13768
mgmtd: improvements in logging and commentary (backport #13768)
2023-06-24 23:12:10 +03:00
Christian Hopps
e11168b654 lib: mgmtd: improvements in logging and commentary
- log names of datastores not numbers
- improve logging for mgmt_msg_read
- Rather than use a bool, instead store the pending const string name of
the command being run that has postponed the CLI. This adds some nice
information to the logging when enabled.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 96f9e7853b)
2023-06-24 14:37:31 +00:00
Jafar Al-Gharaibeh
9dd8d15047
Merge pull request #13840 from FRRouting/mergify/bp/dev/9.0/pr-13766
mgmtd cleanup/simplify some code (backport #13766)
2023-06-24 09:30:54 -05:00
Christian Hopps
0ba883b274 mgmtd: complex redux in txn cleanup
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit c9d153e5e9)
2023-06-23 19:18:36 +00:00
Christian Hopps
ce23b1e4f4 lib: mgmtd: simplify implicit commit code
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 70ff6bb80b)
2023-06-23 19:18:36 +00:00
Jafar Al-Gharaibeh
5b14f854df
Merge pull request #13835 from FRRouting/mergify/bp/dev/9.0/pr-13764
lib: mgmtd: make error handling more robust (backport #13764)
2023-06-23 14:03:14 -05:00
Jafar Al-Gharaibeh
63bd539089
Merge pull request #13833 from FRRouting/mergify/bp/dev/9.0/pr-13809
doc: start of mgmtd developer doc (backport #13809)
2023-06-23 08:35:57 -05:00
Christian Hopps
118a170218 lib: mgmtd: make error handling more robust
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit d694cd40f2)
2023-06-23 12:08:11 +00:00
Jafar Al-Gharaibeh
f4502c7be1
Merge pull request #13834 from FRRouting/mergify/bp/dev/9.0/pr-13763
fix 'exit' bug in config file processing, et al. (backport #13763)
2023-06-22 21:09:24 -05:00
Jafar Al-Gharaibeh
2b2427bfcb
Merge pull request #13832 from FRRouting/mergify/bp/dev/9.0/pr-13734
remove mentions of socat (backport #13734)
2023-06-22 21:09:08 -05:00
Christian Hopps
b354f1a761 tests: add mgmtd config test
Testing early exits/ends from config files loaded with `vtysh -f cfgfile`
as well as `vtysh < cfgfile`, verify the same as non-mgmtd behavior.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit dac48df52a)
2023-06-22 21:56:44 +00:00
Christian Hopps
b5a7275602 lib: mgmtd: fix/stdize debug message macros
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 79d40972fd)
2023-06-22 21:56:44 +00:00
Christian Hopps
869d3252ea mgmtd: remove unused code
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit f0fa4c0370)
2023-06-22 21:56:44 +00:00
Christian Hopps
58c7dd98d2 lib: mgmtd: session create and destroy both short-circuit
For creation this is the first thing done so short-circuit just means inline
sync response. However, for destroy there could be commands in-flight, these
will be discarded when they match no session, and the state cleaned up
immediately when the message short-circuits.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 0fc08fa738)
2023-06-22 21:56:44 +00:00
Christian Hopps
c874d567cc lib: mgmtd: avoid recursion with vty_close and add error log
Avoid recursion into vty_close() when being notified of a session closure that
happened inside vty_close().

If a vty is closed with outstanding config yet to be commited
issue a warning that it is being lost.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 4307fdd070)
2023-06-22 21:56:44 +00:00
Christian Hopps
cfca317c59 vtysh: stop reading config file if user exits from root level.
This is required to make sure that we properly send the
XFRR_end_configuration tag to the daemons. Previously if the user had an
`exit` at the root level the parser would just drop out of the config
node and so XFRR_end_configuration, even if sent, would be ignored

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 315e9032e4)
2023-06-22 21:56:43 +00:00
Christian Hopps
edf01373b8 staticd: staticd no longer loads config files
We need to ignore SIGHUP rather than reload config now.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit f7a2c2ab5a)
2023-06-22 21:56:43 +00:00
Christian Hopps
51d1633a5b doc: start of mgmtd developer doc
- docs on how to convert daemon to mgmtd and some diagrams
- and a fix for code-block in cspf.rst

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit a552543640)
2023-06-22 21:55:03 +00:00
Christian Hopps
96db273b29 doc: update doc removing socat req + remove unused tests code
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 17054f373e)
2023-06-22 21:52:52 +00:00
Donatas Abraitis
7ede6dda1a
Merge pull request #13816 from FRRouting/mergify/bp/dev/9.0/pr-13758
isisd: Fix read beyond end of stream of ASLA Sub-TLV parsing (backport #13758)
2023-06-21 16:47:02 +03:00
Carmine Scarpitta
f1c151c7ff isisd: Fix use beyond end of stream of ASLA Sub-TLV parsing
Fixes a crash associated with attempting to read beyond the end of the
stream when parsing ASLA Sub-TLV.

```
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
    subtlv_len=13 '\r') at isisd/isis_tlvs.c:1473
    at isisd/isis_tlvs.c:3264
    context=<optimized out>, mtid=<optimized out>) at isisd/isis_tlvs.c:6078
    indent=4) at isisd/isis_tlvs.c:6142
    avail_len=<optimized out>, context=<optimized out>) at isisd/isis_tlvs.c:7032
    at isisd/isis_tlvs.c:7054
(gdb)
```

Caught by fuzzer.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
(cherry picked from commit 2a9e0824a7)
2023-06-20 13:20:13 +00:00
Donald Sharp
61ba3a4d56
Merge pull request #13786 from FRRouting/mergify/bp/dev/9.0/pr-13612
ospfd: fix interface param type update (backport #13612)
2023-06-13 16:03:28 -04:00
Donald Sharp
948a984434
Merge pull request #13791 from FRRouting/mergify/bp/dev/9.0/pr-13589
pbrd, zebra: fix zapi and netlink rule encoding (backport #13589)
2023-06-13 16:03:04 -04:00
Mark Stapp
3326a17cfd pbrd, zebra: fix zapi and netlink rule encoding
In pbrd, don't encode a rule without a table. There are cases
where the zapi encoding was incorrect because the 4-octet
table id was missing. In zebra, mask off the ECN bits in the
TOS byte when encoding an iprule to match netlink's
expectation.

Signed-off-by: Mark Stapp <mjs@labn.net>
(cherry picked from commit 4112baec9f)
2023-06-13 15:11:21 +00:00
Chirag Shah
4edc16b7a3 ospfd: fix interface param type update
interface link update event needs
to be handle properly in ospf interface
cache.

Example:
When vrf (interface) is created its default type
would be set to BROADCAST because ifp->status
is not set to VRF.
Subsequent link event sets ifp->status to vrf,
ospf interface update need to compare current type
to new default type which would be VRF (OSPF_IFTYPE_LOOPBACK).
Since ospf type param was created in first add event,
ifp vrf link event didn't update ospf type param which
leads to treat vrf as non loopback interface.

Ticket:#3459451
Testing Done:

Running config suppose to bypass rendering default
network broadcast for loopback/vrf types.

Before fix:

vrf vrf1
 vni 4001
exit-vrf
!
interface vrf1
 ip ospf network broadcast
exit

After fix: (interface vrf1 is not displayed).

vrf vrf1
 vni 4001
exit-vrf

Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit 0d005b2d5c)
2023-06-13 13:55:52 +00:00
Donatas Abraitis
5dc6972e13
Merge pull request #13760 from FRRouting/mergify/bp/dev/9.0/pr-13675
bfd:fix version bits check (backport #13675)
2023-06-11 21:40:02 +03:00
zmw12306
7e6fe5fe1b bfdd: fix version bits check.
The version of bfd pkt is represented by 3 bits in B[0].
Signed-off-by: zmw12306 <zmw12306@gmail.com>
(cherry picked from commit 3f658e8b1c)
2023-06-11 11:17:31 +00:00
Donatas Abraitis
fdfee18f54
Merge pull request #13744 from FRRouting/mergify/bp/dev/9.0/pr-13726
tests: fixing pim6 topotest bugs (backport #13726)
2023-06-09 15:37:42 +03:00
Donatas Abraitis
9fa39ba3ce
Merge pull request #13746 from FRRouting/mergify/bp/dev/9.0/pr-13739
zebra: Prevent crash because nl is NULL on shutdown (backport #13739)
2023-06-09 15:37:05 +03:00
Donatas Abraitis
497c887e37
Merge pull request #13741 from FRRouting/mergify/bp/dev/9.0/pr-13364
bfd: fix missing Authentication in control pkt (backport #13364)
2023-06-09 10:15:15 +03:00
Jafar Al-Gharaibeh
bddbcc60da
Merge pull request #13736 from FRRouting/mergify/bp/dev/9.0/pr-13645
bfdd: remove redundant nb destroy callbacks (backport #13645)
2023-06-08 23:47:51 -05:00
Donald Sharp
fecd91afbe zebra: Prevent crash because nl is NULL on shutdown
When shutting down the main pthread was first closing
the sockets associated with the dplane pthread and
then telling it to shutdown the pthread at a later point
in time.  This caused the dplane to crash because the nl
data has been freed already.  Change the shutdown order
to stop the dplane pthread *and* then close the sockets.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 977d7e24ff)
2023-06-09 04:45:36 +00:00
Christian Hopps
4e6e3e66c6 tests: convert old pim test to more cleanly use pytest fixture
This is a good way to run a per-test background helper process. Here the
helper object is created before the test function requesting it (through param
name match), and then cleaned up after the test function exits (pass or failed).

A context manager is used to further guarantee the cleanup is done.

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit b28bc2561e)
2023-06-08 18:52:51 +00:00
Christian Hopps
b442bc17db tests: fixing pim6 topotest bugs
- Remove use of bespoke socat
- Use ipv6 support in mcast-tester.py
- do not run processes in the background behind munet/micronet's
  back with `&` (ever) -- use popen or the helper class

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit efedb18976)
2023-06-08 18:52:51 +00:00
Christian Hopps
1daa8842e0 tests: mcast-tester.py handles IPv6
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 71231d304f)
2023-06-08 18:52:51 +00:00
zmw12306
4bcaae4cb5 bfd: fix missing Authentication in control pkt
According RFC 5880, add a simpilfed version handling authentication
Signed-off-by: zmw12306 <zmw12306@gmail.com>
(cherry picked from commit 98707b04d4)
2023-06-08 17:14:06 +00:00
Igor Ryzhov
1c2ff1c21a bfdd: remove redundant nb destroy callbacks
Fixes warning logs:
```
2023/05/29 20:11:50 BFD: [ZKB8W-3S2Q4][EC 100663330] unneeded 'destroy' callback for '/frr-bfdd:bfdd/bfd/profile/minimum-ttl'
2023/05/29 20:11:50 BFD: [ZKB8W-3S2Q4][EC 100663330] unneeded 'destroy' callback for '/frr-bfdd:bfdd/bfd/sessions/multi-hop/minimum-ttl'
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit f7884aedf7)
2023-06-08 15:20:16 +00:00
Donatas Abraitis
2681de7b19
Merge pull request #13723 from FRRouting/mergify/bp/dev/9.0/pr-13624
bgpd: Free temp memory (backport #13624)
2023-06-08 08:35:22 +03:00
Keelan10
78cda591ac bgpd: Free temp memory
This commit addresses a memory leak issue in the BGP Flowspec NLRI parsing function.

Previously when processing NLRI, dynamically allocated memory to `temp` was not being freed, leading to a memory leak.

The commit introduces the necessary code (XFREE) to properly free the temp memory after processing Flowspec NLRI.

The ASan leak log for reference:

```
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689:Direct leak of 56 byte(s) in 2 object(s) allocated from:
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #0 0x7fc9872b5037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #1 0x7fc986e5b1ee in qcalloc lib/memory.c:105
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #2 0x560421351bfe in bgp_nlri_parse_flowspec bgpd/bgp_flowspec.c:155
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #3 0x56042107d01c in bgp_nlri_parse bgpd/bgp_packet.c:350
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #4 0x560421086cf3 in bgp_update_receive bgpd/bgp_packet.c:2023
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #5 0x56042108deed in bgp_process_packet bgpd/bgp_packet.c:2933
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #6 0x7fc986f35bf7 in event_call lib/event.c:1995
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #7 0x7fc986e1e99d in frr_run lib/libfrr.c:1185
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #8 0x560420f3f59d in main bgpd/bgp_main.c:505
./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689-    #9 0x7fc986805d09 in __libc_start_main ../csu/libc-start.c:308
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
(cherry picked from commit 269a2d3dae)
2023-06-07 21:36:45 +00:00
Donald Sharp
0d0c8798e9
Merge pull request #13712 from FRRouting/mergify/bp/dev/9.0/pr-13693
tools: fix list value remove in frr-reload (backport #13693)
2023-06-07 08:07:40 -04:00
Donatas Abraitis
c3f7381eaf
Merge pull request #13711 from FRRouting/mergify/bp/dev/9.0/pr-13706
lib: close config files after reading (coverity) (backport #13706)
2023-06-07 13:23:14 +03:00
Donatas Abraitis
5f687dce66
Merge pull request #13710 from FRRouting/mergify/bp/dev/9.0/pr-13707
mgmtd: assert an assertion for coverity (backport #13707)
2023-06-07 12:49:27 +03:00
Chirag Shah
ba9f9c979d tools: fix list value remove in frr-reload
There might be a time element(s) from
temporary list are removed more than once
which leads to valueError in certain python3
version.

commit-id 1543f58b5 did not handle valueError
properly. This caused regression where
prefix-list config leads to delete followed
by add.

The new fix should just pass the exception as
value removal from list_to_add or list_to_del
is best effort.
This allows prefix-list config has no change
then removes the lines from lines_to_del and
lines_to_add properly.

Ticket:#3490252
Testing:

Configure prefix-list in frr.conf and perform
multiple frr-reload. After first reload operatoin
subsequent ones should not result in delete followed
by add of the prefix-list but rather no-op operation.

(Pdb) lines_to_add
[(('ip prefix-list FOO permit 10.2.1.0/24',), None)]
(Pdb) lines_to_del
[(('ip prefix-list FOO seq 5 permit 10.2.1.0/24',), None),
 (('ip prefix-list FOO seq 10 permit 10.2.1.0/24',), None)]
(Pdb) lines_to_del_to_del
[(('ip prefix-list FOO seq 5 permit 10.2.1.0/24',), None),
 (('ip prefix-list FOO seq 10 permit 10.2.1.0/24',), None)]
(Pdb) lines_to_add_to_del
[(('ip prefix-list FOO permit 10.2.1.0/24',), None),
 (('ip prefix-list FOO permit 10.2.1.0/24',), None)]
(Pdb) c
> /usr/lib/frr/frr-reload.py(1562)ignore_delete_re_add_lines()
-> return (lines_to_add, lines_to_del)
(Pdb) lines_to_add
[]
(Pdb) lines_to_del
[]

Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit 9845c09d61)
2023-06-07 06:23:53 +00:00
Christian Hopps
7678f2dbc0 lib: close config files after reading (coverity)
fixes coverity CID# 1564375

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit f5626596ee)
2023-06-07 06:13:37 +00:00
Christian Hopps
e5c6161439 mgmtd: assert an assertion for coverity
I believe coverity can't tell the length of the return value from strftime based
on the format string (like we can), so it allows `n` to be larger than it could
be which then allows `sz - n` to be negative which is size_t positive and very
large so it thinks an overrun is possible.

CID#1563211

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit 565139a6d5)
2023-06-07 06:13:12 +00:00
Donald Sharp
b615b1094a
Merge pull request #13701 from opensourcerouting/fix/update_show_ip_bgp_summary_doc
doc: Document RFC8212 under `Displaying BGP Information` section
2023-06-06 14:55:52 -04:00