Commit graph

309 commits

Author SHA1 Message Date
Mark Stapp 098d692b6f *: expose and clean up 'noreturn' functions
Enable the -Wmissing-noreturn warning, and resolve warnings
for gcc and clang. Add a FRR_NORETURN macro and use that for
the new changes.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-24 13:41:23 -04:00
Mark Stapp 2998eeb0a5 pbrd,staticd,vrrpd: clean up variable-shadow warnings
Clean up -Wshadow warnings in three daemons

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-08 14:41:27 -04:00
Donald Sharp b4786a61e2 pbr: Add tableid to some debugs
Add prefix and tableid to one debug instead of several.
Consolidate a bit.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-02-13 10:40:17 -05:00
David Lamparter c88589f5e9 pbrd: initialize structs used in hash_lookup
Doesn't seem to break anything but really poor style to pass potentially
uninitialized data to hash_lookup.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2025-01-29 16:48:37 +01:00
Wesley Coakley a72d1a1124 pbrd: fix vrf_unchanged which may depend on other seqs
Ticket: 2740911
Signed-off-by: Wesley Coakley <wcoakley@nvidia.com>
2024-12-09 12:31:29 -05:00
Igor Ryzhov 830972cab2 lib: common debug status output
Implement common code for debug status output and remove daemon-specific
code that is duplicated everywhere.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-08-27 09:53:02 -04:00
Igor Ryzhov 82e52e0f21 lib: common debug config output
Implement common code for debug config output and remove daemon-specific
code that is duplicated everywhere.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-08-27 09:53:02 -04:00
Igor Ryzhov 5dac696154 lib: rework debug init
The debug library allows to register a `debug_set_all` callback which
should enable all debugs in a daemon. This callback is implemented
exactly the same in each daemon. Instead of duplicating the code, rework
the lib to allow registration of each debug type, and implement the
common code only once in the lib.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-08-27 09:53:02 -04:00
Donald Sharp f01205bb96 pbrd: Call vrf_terminate on shutdown
Free up vrf memory on shutdown.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-13 14:11:07 -04:00
Mark Stapp 72b31b96fc *: create a single registry of daemons' default port values
Create a single registry of default port values that daemons
are using. Most of these are vty ports, but there are some
others for features like ospfapi and zebra FPM.

Signed-off-by: Mark Stapp <mjs@labn.net>
2024-02-01 11:40:02 -05:00
David Lamparter 634f481113 *: fix frr_daemon_info indentation
clang-format doesn't understand FRR_DAEMON_INFO is a long macro where
laying out items semantically makes sense.

(Also use only one `FRR_DAEMON_INFO(` in isisd so editors don't get
confused with the mismatching `( ( )`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:51 +01:00
Rajesh Varatharaj aa12c72c2a 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>
2024-01-23 09:04:34 -08:00
Chirag Shah 64745d413c pbrd: fix map seq installed flag in json
Ticket:#3638598
Testing:

Post fix:
tor-2# show pbr map json
[
  {
    "name":"global-vrf-PBR-map",
    "valid":true,
    "policies":[
      {
        "id":1,
        "sequenceNumber":10,
        "ruleNumber":309,
        "vrfUnchanged":false,
        "installed":true,   <<<< now display correct value
        "installedReason":"Valid",
        "vrfName":"sym_1",
        "matchSrc":"10.1.200.0\/24",
        "matchDst":"10.6.200.0\/24"
      }
    ]
  }

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2023-12-05 11:30:50 -08:00
David Lamparter 500a09d2dc pbrd: replace receive_notify with request
Send `ZEBRA_ROUTE_NOTIFY_REQUEST` rather than relying on the options
field in zclient startup.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-23 14:57:36 +01:00
Donatas Abraitis b84476e0bb
Merge pull request #14850 from donaldsharp/IFNAMSIZ_GET_YOUR_SHIT_TOGETHER
*: Let's use the native IFNAMSIZ instead of INTERFACE_NAMSIZ
2023-11-22 09:13:58 +02:00
Donald Sharp 07b91ca096 *: Let's use the native IFNAMSIZ instead of INTERFACE_NAMSIZ
INTERFACE_NAMSIZ is just a redefine of IFNAMSIZ and IFNAMSIZ
is the standard for interface name length on all platforms
that FRR currently compiles on.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-21 08:08:29 -05:00
David Lamparter 20007eb773 pbrd: use zclient->nexthop_update
Have the library decode the nexthop.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-20 11:24:28 +01:00
Donald Sharp 0e44d248a0 pbrd: Cleanup zclient on shutdown
For some reason pbrd had no shutdown code for zclient.
Now it does.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-13 09:15:43 -05:00
David Lamparter d889055d8e lib: convert if_zapi_callbacks into actual hooks
...so that multiple functions can be subscribed.

The create/destroy hooks are renamed to real/unreal because that's what
they *actually* signal.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-02 17:10:43 -07:00
Sindhu Parvathi Gopinathan d621c365a6 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>
2023-10-27 08:07:38 -07:00
Igor Ryzhov 7d67b9ff28 build: add -Wimplicit-fallthrough
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc
- cleanup some code to remove unnecessary fallthrough

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-12 21:23:18 +03:00
Donald Sharp 0dc12c9003 Revert "lib: register bgp link-state afi/safi"
This reverts commit 1642a68d60.
2023-10-10 16:45:57 -04:00
anlan_cs b580c52698 *: remove ZEBRA_INTERFACE_VRF_UPDATE
Currently when one interface changes its VRF, zebra will send these messages to
all daemons in *order*:
    1) `ZEBRA_INTERFACE_DELETE` ( notify them delete from old VRF )
    2) `ZEBRA_INTERFACE_VRF_UPDATE` ( notify them move from old to new VRF )
    3) `ZEBRA_INTERFACE_ADD` ( notify them added into new VRF )

When daemons deal with `VRF_UPDATE`, they use
`zebra_interface_vrf_update_read()->if_lookup_by_name()`
to check the interface exist or not in old VRF. This check will always return
*NULL* because `DELETE` ( deleted from old VRF ) is already done, so can't
find this interface in old VRF.

Send `VRF_UPDATE` is redundant and unuseful. `DELETE` and `ADD` are enough,
they will deal with RB tree, so don't send this `VRF_UPDATE` message when
vrf changes.

Since all daemons have good mechanism to deal with changing vrf, and don't
use this `VRF_UPDATE` mechanism.  So, it is safe to completely remove
all the code with `VRF_UPDATE`.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2023-10-07 10:06:39 +08:00
Louis Scalbert 1642a68d60 lib: register bgp link-state afi/safi
Register BGP Link-State AFI/SAFI values from RFC7752.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-09-18 14:22:51 +02:00
Keelan10 0214fb7bfc pbrd: Free Memory in pbr_map_delete
This commit frees dynamically allocated memory associated
with `pbrms->nhgrp_name` and `pbrms->dst` which were causing memory leaks.

The ASan leak log for reference:

```
=================================================================
==107458==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f87d644ca37 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f87d5feaa37 in qcalloc ../lib/memory.c:105
    #2 0x7f87d6054ffd in prefix_new ../lib/prefix.c:1180
    #3 0x55722f3c2885 in pbr_map_match_dst_magic ../pbrd/pbr_vty.c:302
    #4 0x55722f3b5c24 in pbr_map_match_dst pbrd/pbr_vty_clippy.c:228
    #5 0x7f87d5f32d61 in cmd_execute_command_real ../lib/command.c:993
    #6 0x7f87d5f330ee in cmd_execute_command ../lib/command.c:1052
    #7 0x7f87d5f33dc0 in cmd_execute ../lib/command.c:1218
    #8 0x7f87d60e4177 in vty_command ../lib/vty.c:591
    #9 0x7f87d60e905c in vty_execute ../lib/vty.c:1354
    #10 0x7f87d60ef45a in vtysh_read ../lib/vty.c:2362
    #11 0x7f87d60d42d4 in event_call ../lib/event.c:1979
    #12 0x7f87d5fbe828 in frr_run ../lib/libfrr.c:1213
    #13 0x55722f3ac795 in main ../pbrd/pbr_main.c:168
    #14 0x7f87d5b82d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Direct leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x7f87d63f39a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x7f87d5feaafc in qstrdup ../lib/memory.c:117
    #2 0x55722f3da139 in pbr_nht_set_seq_nhg ../pbrd/pbr_nht.c:551
    #3 0x55722f3c693f in pbr_map_nexthop_group_magic ../pbrd/pbr_vty.c:1140
    #4 0x55722f3bdaae in pbr_map_nexthop_group pbrd/pbr_vty_clippy.c:1284
    #5 0x7f87d5f32d61 in cmd_execute_command_real ../lib/command.c:993
    #6 0x7f87d5f330ee in cmd_execute_command ../lib/command.c:1052
    #7 0x7f87d5f33dc0 in cmd_execute ../lib/command.c:1218
    #8 0x7f87d60e4177 in vty_command ../lib/vty.c:591
    #9 0x7f87d60e905c in vty_execute ../lib/vty.c:1354
    #10 0x7f87d60ef45a in vtysh_read ../lib/vty.c:2362
    #11 0x7f87d60d42d4 in event_call ../lib/event.c:1979
    #12 0x7f87d5fbe828 in frr_run ../lib/libfrr.c:1213
    #13 0x55722f3ac795 in main ../pbrd/pbr_main.c:168
    #14 0x7f87d5b82d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: 58 byte(s) leaked in 2 allocation(s).
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-09-05 12:58:18 +04:00
Russ White fa0dd3d6d0
Merge pull request #14252 from LabNConsulting/ziemba-pbr-bugfix-match-dscp-numeric
pbrd: fix dscp field value computation
2023-08-29 08:05:17 -04:00
Russ White 58ade1ba5d
Merge pull request #14217 from LabNConsulting/ziemba-pbr-action-drop
pbrd: add advisory flag PBR_ACTION_DROP
2023-08-22 12:16:01 -04:00
G. Paul Ziemba 1efae6b537 pbrd: fix dscp field value computation
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-21 13:27:50 -07:00
Donatas Abraitis 19ad3e2770
Merge pull request #14226 from Keelan10/fix-pbrd-leak
pbrd: Correct Handling of Sequence Deletion
2023-08-20 22:32:21 +03:00
Keelan10 c09013e33a pbrd: Correct Handling of Sequence Deletion
This commit ensures that sequence data
and associated structures are correctly deleted to prevent memory leaks

The ASan leak log for reference:
```
Direct leak of 432 byte(s) in 1 object(s) allocated from:
    #0 0x7f911ebaba37 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7f911e749a4e in qcalloc ../lib/memory.c:105
    #2 0x564fd444b2d3 in pbrms_get ../pbrd/pbr_map.c:527
    #3 0x564fd443a82d in pbr_map ../pbrd/pbr_vty.c:90
    #4 0x7f911e691d61 in cmd_execute_command_real ../lib/command.c:993
    #5 0x7f911e6920ee in cmd_execute_command ../lib/command.c:1052
    #6 0x7f911e692dc0 in cmd_execute ../lib/command.c:1218
    #7 0x7f911e843197 in vty_command ../lib/vty.c:591
    #8 0x7f911e84807c in vty_execute ../lib/vty.c:1354
    #9 0x7f911e84e47a in vtysh_read ../lib/vty.c:2362
    #10 0x7f911e8332f4 in event_call ../lib/event.c:1979
    #11 0x7f911e71d828 in frr_run ../lib/libfrr.c:1213
    #12 0x564fd4425795 in main ../pbrd/pbr_main.c:168
    #13 0x7f911e2e1d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-08-20 07:07:36 +04:00
G. Paul Ziemba 5cde1e89f0 pbrd: address 230815 coverity: pbr_vty.c vrf_name
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-18 11:19:05 -07:00
G. Paul Ziemba eb3929b4fa pbrd: address 230815 coverity: pbr_vty.c pbrms
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-18 11:14:25 -07:00
G. Paul Ziemba 2e6c879e99 pbrd: address 230815 coverity: pbr_vty.c pend/strtoul
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-18 11:13:20 -07:00
G. Paul Ziemba 6182675e7e pbrd: address 230815 coverity: r.action.flags reordering
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-18 11:11:17 -07:00
G. Paul Ziemba d04cf80525 pbrd: add advisory flag PBR_ACTION_DROP
PBR configuration may specify "set nexthop blackhole" which,
    for linux dataplanes, is implemented as a table with a blackhole
    route.

    Other dataplanes might implement this action as an explicit
    packet-filtering "drop" action instead of a route. This new flag
    PBR_ACTION_DROP is now set when a rule has "set nexthop blackhole"
    as an aid to other dataplanes.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-16 07:08:49 -07:00
G. Paul Ziemba ba240bcfa3 pbrd: add packet mangling actions (src/dst ip-addr/port, dscp, ecn)
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-09 12:11:43 -07:00
G. Paul Ziemba 887367a01c pbrd: use flags to indicate active fields
Before now, PBRD used non-zero values to imply that a rule's
    match or action field was active. This approach was getting
    cumbersome for fields where 0 is a valid active value and
    various field-specific magic values had to be used.

    This commit changes PBRD to use a flag bit per field to
    indicate that the field is active.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-09 12:11:35 -07:00
G. Paul Ziemba c47fd378f3 pbrd: add explicit 'family' field for rules
In the netlink-mediated kernel dataplane, each rule is stored
    in either an IPv4-specific database or an IPv6-specific database.
    PBRD opportunistically gleans each rule's address family value
    from its source or destination IP address match value (if either
    exists), or from its nexthop or nexthop-group (if it exists).

    The 'family' value is particularly needed for netlink during
    incremental rule deletion when none of the above fields remain set.

    Before now, this address family has been encoded by occult means
    in the (possibly otherwise unset) source/destination IP match
    fields in ZAPI and zebra.

    This commit documents the reasons for maintaining the 'family'
    field in the PBRD rule structure, adds a 'family' field in the
    common lib/pbr.h rule structure, and carries it explicitly in ZAPI.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-08 10:18:22 -07:00
G. Paul Ziemba 5572f45d51 pbrd: PBR_FILTER_DSFIELD -> {PBR_FILTER_DSCP,PBR_FILTER_ECN}
DSCP and ECN matching are configured independently. Maintain
    these values in independent fields in pbrd, zapi, and zebra.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-08 10:18:22 -07:00
G. Paul Ziemba 09262f1b72 pbrd: add nexthop drop type
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-08 10:18:15 -07:00
G. Paul Ziemba c5d60c4a67 pbrd: pbr_vty.c organize/style
No functional changes: just arrange CLI handlers into logical
    order and standardize DEFPY formatting.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-07 12:29:41 -07:00
Mark Stapp fe2bbcb01d lib,pbrd: clean up style issues
Fix a couple of style warnings introduced by recent PR 14050.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-07-25 11:09:29 -04:00
Russ White 3f043d027f
Merge pull request #14050 from LabNConsulting/ziemba-pbr-zapi-common
pbrd: 2/3 zapi PBR common encode/decode
2023-07-25 10:55:50 -04:00
G. Paul Ziemba 9835196ec9 pbrd: fix coverity issue
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-07-21 09:15:40 -07:00
G. Paul Ziemba 580a98b798 lib: zapi PBR common encode/decode
bgpd, pbrd: use common pbr encoder
    zebra: use common pbr decoder
    tests: pbr_topo1: check more filter fields

    Purpose:
	1. Reduce likelihood of zapi format mismatches when adding
	   PBR fields due to multiple parallel encoder implementations
	2. Encourage common PBR structure usage among various daemons
	3. Reduce coding errors via explicit per-field enable flags

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-07-20 08:10:45 -07:00
G. Paul Ziemba dbade07e0e pbrd: add vlan filters pcp/vlan-id/vlan-flags; ip-protocol any (zapi)
Subset: ZAPI changes to send the new data

    Also adds filter_bm field; currently for PBR_FILTER_PCP, but in the
    future to be used for all of the filter fields.

    Changes by:
	Josh Werner <joshuawerner@mitre.org>
	Eli Baum <ebaum@mitre.org>
	G. Paul Ziemba <paulz@labn.net>

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-07-19 08:14:49 -07:00
G. Paul Ziemba bfd3e8e012 pbrd: add vlan filters pcp/vlan-id/vlan-flags; ip-protocol any (pbr feature)
Subset: feature in PBR

    New PBR rule fields:

    match ip-protocol (was only tcp|udp, now any value in /etc/protocols)
    match pcp (0-7)
    match vlan (1-4094)
    match vlan (tagged|untagged|untagged-or-zero)

    Filter flags
	Add filter_bm (flags) field internally to indicate which
	filter fields should be considered active. Bit definitions
	as in lib/pbr.h.

	This commit uses only the PBR_FILTER_PCP bit, but other
	fields will be added in future commits. (Fixes bug related
	to determining set/not-set state of pcp filter)

	Shift vlan filter flags to lib/pbr.h

    Changes by:
	Josh Werner <joshuawerner@mitre.org>
	Eli Baum <ebaum@mitre.org>
	G. Paul Ziemba <paulz@labn.net>

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-07-19 08:14:09 -07:00
anlan_cs 4e313ee450 pbrd: fix crash with match command
Crash with empty `ip-protocol`:
```
anlan(config-pbr-map)# match ip-protocol
vtysh: error reading from pbrd: Resource temporarily unavailable (11)Warning: closing connection to pbrd because of an I/O error!
```

So, give warning for empty `ip-protocol`.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-06-28 21:46:47 +08:00
Mark Stapp 4112baec9f 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>
2023-06-12 16:39:26 -04:00
Donald Sharp 24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00