diff options
author | G. Paul Ziemba <paulz@labn.net> | 2023-08-21 22:27:50 +0200 |
---|---|---|
committer | G. Paul Ziemba <paulz@labn.net> | 2023-08-21 22:27:50 +0200 |
commit | 1efae6b5370342bafbd7c6b55fd9857a02b527e0 (patch) | |
tree | 167596f81fa7def6526f2e3eb1c20b5944f29e70 /pbrd | |
parent | Merge pull request #14226 from Keelan10/fix-pbrd-leak (diff) | |
download | frr-1efae6b5370342bafbd7c6b55fd9857a02b527e0.tar.xz frr-1efae6b5370342bafbd7c6b55fd9857a02b527e0.zip |
pbrd: fix dscp field value computation
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
Diffstat (limited to 'pbrd')
-rw-r--r-- | pbrd/pbr_vty.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 1f1e42218..4e1a0f750 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -443,27 +443,28 @@ DEFPY (pbr_map_match_dscp, unsigned long ul_dscp; char *pend = NULL; - uint8_t raw_dscp; + uint8_t shifted_dscp; assert(dscp); ul_dscp = strtoul(dscp, &pend, 0); if (pend && *pend) - raw_dscp = pbr_map_decode_dscp_enum(dscp); - else - raw_dscp = ul_dscp << 2; - if (raw_dscp > PBR_DSFIELD_DSCP) { + ul_dscp = pbr_map_decode_dscp_enum(dscp); + + if (ul_dscp > (PBR_DSFIELD_DSCP >> 2)) { vty_out(vty, "Invalid dscp value: %s%s\n", dscp, ((pend && *pend) ? "" : " (numeric value must be in range 0-63)")); return CMD_WARNING_CONFIG_FAILED; } + shifted_dscp = (ul_dscp << 2) & PBR_DSFIELD_DSCP; + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP) && - (((pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2) == raw_dscp)) { + ((pbrms->dsfield & PBR_DSFIELD_DSCP) == shifted_dscp)) { return CMD_SUCCESS; } /* Set the DSCP bits of the DSField */ - pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_DSCP) | (raw_dscp << 2); + pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_DSCP) | shifted_dscp; SET_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP); check: @@ -870,26 +871,27 @@ DEFPY (pbr_map_action_dscp, unsigned long ul_dscp; char *pend = NULL; - uint8_t raw_dscp; + uint8_t shifted_dscp; assert(dscp); ul_dscp = strtoul(dscp, &pend, 0); if (pend && *pend) - raw_dscp = pbr_map_decode_dscp_enum(dscp); - else - raw_dscp = ul_dscp << 2; + ul_dscp = pbr_map_decode_dscp_enum(dscp); - if (raw_dscp > PBR_DSFIELD_DSCP) { + if (ul_dscp > (PBR_DSFIELD_DSCP >> 2)) { vty_out(vty, "Invalid dscp value: %s%s\n", dscp, ((pend && *pend) ? "" : " (numeric value must be in range 0-63)")); return CMD_WARNING_CONFIG_FAILED; } + + shifted_dscp = (ul_dscp << 2) & PBR_DSFIELD_DSCP; + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP) && - (pbrms->action_dscp == raw_dscp)) { + (pbrms->action_dscp == shifted_dscp)) { return CMD_SUCCESS; } SET_FLAG(pbrms->action_bm, PBR_ACTION_DSCP); - pbrms->action_dscp = raw_dscp; + pbrms->action_dscp = shifted_dscp; check: pbr_map_check(pbrms, true); |