summaryrefslogtreecommitdiff
path: root/pbrd/pbr_map.c
diff options
context:
space:
mode:
authorG. Paul Ziemba <paulz@labn.net>2023-07-30 21:33:10 -0700
committerG. Paul Ziemba <paulz@labn.net>2023-08-09 12:11:35 -0700
commit887367a01c0e978e992935ae93f3df4e3c1bd86c (patch)
tree533826535f9359febf6b935fb6ee44b63121c63a /pbrd/pbr_map.c
parentc47fd378f33b721cc32b788c6ce89353b1076416 (diff)
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>
Diffstat (limited to 'pbrd/pbr_map.c')
-rw-r--r--pbrd/pbr_map.c77
1 files changed, 30 insertions, 47 deletions
diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c
index 758e08b565..30148fe093 100644
--- a/pbrd/pbr_map.c
+++ b/pbrd/pbr_map.c
@@ -105,38 +105,6 @@ static bool pbrms_is_installed(const struct pbr_map_sequence *pbrms,
return false;
}
-void pbr_set_match_clause_for_pcp(struct pbr_map_sequence *pbrms, bool set,
- uint8_t pcp)
-{
- bool changed = false;
-
- if (set) {
- if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP) ||
- (pcp != pbrms->match_pcp)) {
- SET_FLAG(pbrms->filter_bm, PBR_FILTER_PCP);
- pbrms->match_pcp = pcp;
- changed = true;
- }
- } else {
- if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP)) {
- UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_PCP);
- changed = true;
- }
- }
- if (changed)
- pbr_map_check(pbrms, true);
-}
-
-void pbr_set_match_clause_for_vlan(struct pbr_map_sequence *pbrms,
- uint16_t vlan_id, uint16_t vlan_flags)
-{
- if (pbrms) {
- pbrms->match_vlan_id = vlan_id;
- pbrms->match_vlan_flags = vlan_flags;
- pbr_map_check(pbrms, true);
- }
-}
-
/* If any sequence is installed on the interface, assume installed */
static bool
pbr_map_interface_is_installed(const struct pbr_map *pbrm,
@@ -562,14 +530,6 @@ struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno)
pbrms->ruleno = pbr_nht_get_next_rule(seqno);
pbrms->parent = pbrm;
- pbrms->match_vlan_id = 0;
- pbrms->match_vlan_flags = 0;
- pbrms->match_pcp = 0;
-
- pbrms->action_vlan_id = 0;
- pbrms->action_vlan_flags = 0;
- pbrms->action_pcp = 0;
-
pbrms->action_queue_id = PBR_MAP_UNDEFINED_QUEUE_ID;
pbrms->reason =
@@ -634,13 +594,35 @@ pbr_map_sequence_check_nexthops_valid(struct pbr_map_sequence *pbrms)
static void pbr_map_sequence_check_not_empty(struct pbr_map_sequence *pbrms)
{
- if (!pbrms->src && !pbrms->dst && !pbrms->mark && !pbrms->dsfield &&
- !CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP) &&
- !pbrms->action_pcp && !pbrms->match_vlan_id &&
- !pbrms->match_vlan_flags && !pbrms->action_vlan_id &&
- !pbrms->action_vlan_flags &&
- pbrms->action_queue_id == PBR_MAP_UNDEFINED_QUEUE_ID)
+ /* clang-format off */
+ if (
+ !CHECK_FLAG(pbrms->filter_bm, (
+ PBR_FILTER_SRC_IP |
+ PBR_FILTER_DST_IP |
+ PBR_FILTER_SRC_PORT |
+ PBR_FILTER_DST_PORT |
+
+ PBR_FILTER_IP_PROTOCOL |
+ PBR_FILTER_DSCP |
+ PBR_FILTER_ECN |
+
+ PBR_FILTER_FWMARK |
+ PBR_FILTER_PCP |
+ PBR_FILTER_VLAN_ID |
+ PBR_FILTER_VLAN_FLAGS
+ )) &&
+ !CHECK_FLAG(pbrms->action_bm, (
+
+ PBR_ACTION_PCP |
+ PBR_ACTION_VLAN_ID |
+ PBR_ACTION_VLAN_STRIP_INNER_ANY |
+
+ PBR_ACTION_QUEUE_ID
+ ))
+ ) {
pbrms->reason |= PBR_MAP_INVALID_EMPTY;
+ }
+ /* clang-format on */
}
static void pbr_map_sequence_check_vlan_actions(struct pbr_map_sequence *pbrms)
@@ -653,7 +635,8 @@ static void pbr_map_sequence_check_vlan_actions(struct pbr_map_sequence *pbrms)
* The strip vlan action removes any inner tag, so it is invalid to
* specify both a set and strip action.
*/
- if ((pbrms->action_vlan_id != 0) && (pbrms->action_vlan_flags != 0))
+ if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID) &&
+ (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY)))
pbrms->reason |= PBR_MAP_INVALID_SET_STRIP_VLAN;
}