vpp: private plugin that adds npol matched rule to acl trace#939
vpp: private plugin that adds npol matched rule to acl trace#939
Conversation
When a custom access policy matches a packet, store the matched rule id in the session so subsequent packets of the same flow can retrieve it without re-running the match, avoiding repeated policy evaluation overhead. The rule id is propagated to the trace for debuggability. The new field fits within existing reserved space in fa_session_t, keeping the struct at 128 bytes with no cache-line impact.
5b7705d to
df3489d
Compare
sknat
left a comment
There was a problem hiding this comment.
Thanks a bunch, a few comments inline
| fa_session_t *sess = get_session_ptr_no_check (am, f_sess_id.thread_index, | ||
| f_sess_id.session_index); | ||
| - | ||
| + if (do_custom_access_policies) |
There was a problem hiding this comment.
We can probably avoid the check and always copy the value, that'll be quicker
| u64 packet_info[6]; | ||
| u32 trace_bitmap; | ||
| u8 action; | ||
| + u32 npol_matched_rule_id; |
There was a problem hiding this comment.
Maybe we could mutate the type a bit more e.g.
typedef struct
{
u32 next_index;
u32 sw_if_index;
fa_full_session_id_t f_sess_id;
union
{
struct
{
u32 lc_index;
u32 match_acl_in_index;
u32 match_rule_index;
} acl_info;
u64[2] caiop_opaque;
} u64 packet_info[6];
u32 trace_bitmap;
u8 fa_flow_state; // fa_flow_state_t
u8 action;
} acl_fa_trace_t;where
typedef enum fa_flow_state_t_
{
FA_TYPE_EXISTING_ACL_FLOW,
FA_TYPE_NEW_ACL_FLOW,
FA_TYPE_NEW_CAIOP_FLOW,
} fa_flow_state_t;Which would allow a few things:
f_sess_idnow being in the trace, we can correlate first and subsequent packets, thus we don't have to keep all the policies metadata in the ACL session table- depending on the value of
fa_flow_statewe can print the trace differently (caiop_opaqueifFA_TYPE_NEW_CAIOP_FLOW;acl_infoifFA_TYPE_NEW_ACL_FLOWand nothing ifFA_TYPE_EXISTING_ACL_FLOW)
There was a problem hiding this comment.
Actually looking again at the code, match_rule_index already contains the session id, so no need for an additional field I think.
The reason I didn't follow this approach is I wanted to be able to have the policies for subsequent packets when we don't necessarily have the first, i.e in the middle of a flow. I don't believe we can if we rely on this correlation, can we ?
| u8 is_ip6; /* +1 bytes = 19 */ | ||
| - u8 reserved1[5]; /* +5 bytes = 24 */ | ||
| + u8 reserved1[1]; /* +1 bytes = 20 */ | ||
| + u32 npol_matched_rule_id; /* +4 bytes = 24 */ |
There was a problem hiding this comment.
And would try avoiding this so that we don't fiddle with acl_sessions too much
There was a problem hiding this comment.
Any drawback if we use reserved fields without cache-line impact ?
| + int is_match = (*pf) (am, sw_if_index[0], is_input, | ||
| + (fa_5tuple_opaque_t *) &fa_5tuple[0], is_ip6, | ||
| + &action, &trace_bitmap, &npol_matched_rule_id); |
There was a problem hiding this comment.
And here, we might want to
- remove
trace_bitmap(not sure what it is useful for anyway) - pass
&caiop_opaque
| -npol_match_func (u32 sw_if_index, u32 is_inbound, fa_5tuple_t *pkt_5tuple, | ||
| - int is_ip6, u8 *r_action) | ||
| +npol_match_func (u32 sw_if_index, u32 is_inbound, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *r_action, | ||
| + u32 *matched_rule_id) |
There was a problem hiding this comment.
Here npol_match_func can then receive *caiop_opaque which it can cast to
typedef struct
{
u32 policy_id; // policy id we matched, otherwise ~0
u32 rule_id; // rule id we matched, otherwise ~0
int rule_match_res; // stores the code of npol_match_rule
u32 flag_is_profile:1; // result comes from a profile
u32 flag_policy_pass:1; // we matched a policy that made us PASS
u32 flag_pad:30; //
} npol_trace_t;
And then the format would just be a call to format_cnat_trace()
| git_apply_private 0002-cnat-WIP-no-k8s-maglev-from-pods.patch | ||
| git_apply_private 0003-acl-acl-plugin-custom-policies.patch | ||
| git_apply_private 0004-ip-neighbor-preserve-interface-ll-receive-dpo.patch | ||
| git_apply_private 0005-npol-add-matched-rule-id-to-acl-trace.patch No newline at end of file |
There was a problem hiding this comment.
Can you try upstreaming npol changes as dedicated patch to gerrit ?
The acl plugin changes can also probably be collapsed in acl-acl-plugin-custom-policies.patch
There was a problem hiding this comment.
Actually we maintain npol part of npol integration into ACL changes as a private plugin as well (part of 0003-acl-acl-plugin-custom-policies.patch) so this can't be upstreamed in the current state.
sknat
left a comment
There was a problem hiding this comment.
Let's get this in then and get more info in as things go
This adds the rule that matched in npol policy engine to the trace shown by acl node.
Example of a deny policy hit:
Packet 49
npol_matched_rule_id 25
Corresponding rule can be checked here: