Commit graph

128 commits

Author SHA1 Message Date
Chirag Shah 054b408b1e 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>
(cherry picked from commit 64745d413c)
2023-12-06 05:57:47 +00:00
Sindhu Parvathi Gopinathan ee0286d62a 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 d621c365a6)
2023-10-29 08:42:23 +00: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 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 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
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 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
Chirag Shah 03494887ed pbrd:fix mismatching in match src-dst
upstream commit 67765a232d has incorect
address family check which prevent from
deleting src/dst config under pbr rule.

Ticket:#3405024
Issue:3405024
Testing Done:

Config:

pbr-map map6 seq 1
 match src-ip 2000::200:100💯0/96
 match dst-ip 2000:💯100💯0/96
 set nexthop-group group3

Before:
torc-12(config)# pbr-map map6 seq 1
torc-12(config-pbr-map)# no match src-ip 2000::200:100💯0/96
Cannot mismatch families within match src/dst

After:
torc-12(config)# pbr-map map6 seq 1
torc-12(config-pbr-map)# no match src-ip 2000::200:100💯0/96
torc-12(config-pbr-map)#

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2023-03-17 17:01:13 -07:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Wesley Coakley 8dc2001c91 pbrd: fix large tableids displayed as negative
Ticket: 2699411
Signed-off-by: Wesley Coakley <wcoakley@nvidia.com>
2023-02-08 16:28:27 -05:00
David Lamparter 89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Donald Sharp cf00164b69 *: Create and use infrastructure to show debugs in lib
There are lib debugs being set but never show up in
`show debug` commands because there was no way to show
that they were being used.  Add a bit of infrastructure
to allow this and then use it for `debug route-map`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-07 12:39:05 -04:00
Donald Sharp 7021983670 pbrd: VTY_GET_CONTEXT can fail
Although VTY_GET_CONTEXT can return a failed value, it will
never happen in pbrd because of how context work.  In
any event add some code to make coverity happy

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-15 15:45:05 -04:00
Anuradha Karuppiah 59f47eb010 zebra: expand pbr rule action for dataplane programming
PBR rules are installed as match, action rules in most dataplanes. This
requires the action to be resolved via a GW. And the GW to be subsequently
resolved to {SMAC, DMAC}.

Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
2022-06-27 07:56:55 -04:00
anlan_cs 4d4c404bf6 *: Add necessary new line for output of vty_out()
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-02-27 10:59:19 +08:00
Stephen Worley 9a7ea213c0 pbrd: pbr route maps get addr family of nhgs
When adding a nhg to a route map, make sure to specify the `family`
of the rm by looking at the contents of the nhg. Installation in the
kernel (for DSCP rules in particular) relies on this being specified in
the netlink message.

Signed-off-by: Wesley Coakley <wcoakley@nvidia.com>
Signed-off-by: Stephen Worley <sworley@nvidia.com>
2022-01-27 12:47:00 -05:00
Igor Ryzhov 788a036fdb *: do not print vrf name for interface config when using vrf-lite
VRF name should not be printed in the config since 574445ec. The update
was done for NB config output but I missed it for regular vty output.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-24 14:44:05 +03:00
Igor Ryzhov cb3fa0a612
Merge pull request #10124 from ton31337/feature/vty_json 2021-11-29 02:11:29 +03:00
Donatas Abraitis c48349e346 *: Remove redundand braces for single statement blocks
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-27 11:20:59 +02:00
Donatas Abraitis 760441ea3a pbrd: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:50:12 +02:00
Donatas Abraitis 746a6eda2f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:35:55 +02:00
Donatas Abraitis 60200fdd9b pbrd: Replace prefix2str for JSON to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:29:18 +02:00
Igor Ryzhov 096f7609f9 *: cleanup ifp->vrf_id
Since f60a1188 we store a pointer to the VRF in the interface structure.
There's no need anymore to store a separate vrf_id field.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-22 20:47:23 +03:00
Russ White f727c6ae8a
Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-all
*: fix usage of if_lookup_by_name_all_vrf
2021-10-27 15:29:39 -04:00
Jafar Al-Gharaibeh 63da89db77
Merge pull request #9742 from elimbaum/add-vlan-actions
pbrd: add vlan actions to vty
2021-10-23 00:06:16 -05:00
Igor Ryzhov 4ff97453d0 pbrd: fix "set nexthop" for netns
With netns VRF backend, we may have multiple interfaces with the same
name. Currently, the function is not deterministic in this case as it
uses the first interface that it finds in the list. Be more restrictive
and ask the user to provide the VRF name.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-15 03:44:34 +03:00
Igor Ryzhov 9a0e62d41e pbrd: protect from a possible NULL dereference
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-14 19:45:43 +03:00
Eli Baum d70a31a3ef pbrd: add vlan actions to vty
Signed-off-by: Eli Baum <ebaum@mitre.org>
2021-10-07 09:14:59 -04:00
David Lamparter 8268be3d16
Merge pull request #9496 from idryzhov/vrf-cmd-init-unused-arg
lib: remove unused argument from vrf_cmd_init
2021-08-27 10:39:45 +02:00
Igor Ryzhov cfc369c43a lib: remove unused argument from vrf_cmd_init
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-26 12:01:22 +03:00
Igor Ryzhov 07679ad98a *: explicitly print "exit" at the end of every node config
There is a possibility that the same line can be matched as a command in
some node and its parent node. In this case, when reading the config,
this line is always executed as a command of the child node.

For example, with the following config:
```
router ospf
 network 193.168.0.0/16 area 0
!
mpls ldp
 discovery hello interval 111
!
```
Line `mpls ldp` is processed as command `mpls ldp-sync` inside the
`router ospf` node. This leads to a complete loss of `mpls ldp` node
configuration.

To eliminate this issue and all possible similar issues, let's print an
explicit "exit" at the end of every node config.

This commit also changes indentation for a couple of existing exit
commands so that all existing commands are on the same level as their
corresponding node-entering commands.

Fixes #9206.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-23 22:08:20 +03:00
Igor Ryzhov 9da01b0b7b *: cleanup interface node installation
The only difference in daemons' interface node definition is the config
write function. No need to define the node in every daemon, just pass
the callback as an argument to a library function and define the node
there.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-07-29 21:35:25 +03:00
Donald Sharp 5e732768f4 pbrd: Add match ip-protocol [tcp|udp]
Add the `match ip-protocol [tcp|udp]` command to allow pbr to
match on tcp or udp streams.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-08 11:12:47 -04:00
Donald Sharp a7f0e5c3e3 pbrd: Add ability to set/unset src and dest ports
Add `match src-port (1-65535)` and `match dst-port (1-65535)`
commands to allow pbr to pass these values down to zebra.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-08 11:12:46 -04:00
Igor Ryzhov f5eef2d5a8 lib: remove vrf-interface config when removing the VRF
If we have the following configuration:
```
vrf red
 smth
 exit-vrf
!
interface red vrf red
 smth
```
And we delete the VRF using "no vrf red" command, we end up with:
```
interface red
 smth
```
Interface config is preserved but moved to the default VRF.

This is not an expected behavior. We should remove the interface config
when the VRF is deleted.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-21 18:04:46 +03:00
Stephen Worley 67765a232d pbrd: disallow ipv4/ipv6 mismatching in match src/dst
Disallow mismatching of ipv4/ipv6 matching in src/dst.
Doesn't make a lot of sense to allow this based on how
IP Headers work. The kernel does not allow it at all
obviously.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2020-12-17 16:14:38 -05:00
Donald Sharp c195ae78e9 pbrd: Fix memory leak in json output
Fix a memory leak in using some pbr json commands.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-11-04 09:11:13 -05:00
Donatas Abraitis 2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03:00