On 5 Oct 2026, at 17:27, Mike Pattrick via dev wrote:
> Currently last_observe_offset is used to track a raw offset into the
> netlink actions array. This offset is tracked and adjusted repeatedly
> during action translation but is only ever used in one case. That is,
> when explicit_sampled_drops is enabled and the last action is
> observational.
>
> This patch removes the offset and instead just checks if the last action
> is an observe.
>
> Signed-off-by: Mike Pattrick <[email protected]>
Thanks Mike for following this up, and sorry for the late reply.
Two comments below.
//Eelco
[...]
> +static bool
> +act_is_observe(struct nlattr *action)
> +{
> + static const struct nl_policy ovs_userspace_policy[] = {
> + [OVS_USERSPACE_ATTR_USERDATA] = { .type = NL_A_UNSPEC,
> + .optional = true },
> + };
> + struct nlattr *attr[ARRAY_SIZE(ovs_userspace_policy)];
> + const struct user_action_cookie *cookie;
> + const struct nlattr *userdata_attr;
> + size_t userdata_len;
> +
> + switch (nl_attr_type(action)) {
Normally we type-cast this to "enum ovs_action_attr" to make sure we cover all
cases.
This will allow you to do OVS_NOT_REACHED() on default:.
> + case OVS_ACTION_ATTR_USERSPACE: {
In OVS, the case should be aligned with the switch.
> + if (!nl_parse_nested(action, ovs_userspace_policy, attr,
> + ARRAY_SIZE(attr))) {
> + break;
> + }
> +
> + userdata_attr = attr[OVS_USERSPACE_ATTR_USERDATA];
> + if (!userdata_attr) {
> + break;
> + }
> +
> + userdata_len = nl_attr_get_size(userdata_attr);
> + if (userdata_len != sizeof *cookie) {
> + break;
> + }
> +
> + cookie = nl_attr_get(userdata_attr);
> + switch (cookie->type) {
> + case USER_ACTION_COOKIE_SFLOW:
> + case USER_ACTION_COOKIE_FLOW_SAMPLE:
> + case USER_ACTION_COOKIE_IPFIX:
> + return true;
> + }
> +
> + return false;
> + }
> + case OVS_ACTION_ATTR_METER:
> + case OVS_ACTION_ATTR_SAMPLE:
The old code only appended a drop when compose_sample_action() had
set last_observe_offset, so metered controller actions were never
affected.
This new predicate returns true for all OVS_ACTION_ATTR_SAMPLE
actions, but put_controller_user_action() also wraps metered
controller delivery in a sample. So a flow with just
actions=controller(meter_id=1) ends up with a spurious drop
appended. The packets still reach the controller, but they get
incorrectly counted as pipeline drops.
Guess you need to look inside the sample and check whether the
nested userspace cookie is USER_ACTION_COOKIE_CONTROLLER.
> + case OVS_ACTION_ATTR_PSAMPLE:
> + return true;
> + }
> +
> + return false;
Also do the cleanup of this function in the later patch in this one.
> +}
> +
> /* This will tweak the odp actions generated. For now, it will:
> * - Remove trailing clone actions that are unnecessary.
> * - Add an explicit drop action if the action list is empty.
> @@ -8243,7 +8274,6 @@ xlate_wc_finish(struct xlate_ctx *ctx)
> static void
> xlate_tweak_odp_actions(struct xlate_ctx *ctx)
> {
> - uint32_t last_observe_offset = ctx->xout->last_observe_offset;
> struct ofpbuf *actions = ctx->xin->odp_actions;
> struct nlattr *last_action = NULL;
> struct nlattr *a;
> @@ -8268,16 +8298,6 @@ xlate_tweak_odp_actions(struct xlate_ctx *ctx)
> if (nl_attr_type(last_action) == OVS_ACTION_ATTR_CLONE) {
> void *dest;
>
> - if (last_observe_offset != UINT32_MAX &&
> - (unsigned char *) actions->data + last_observe_offset >
> - (unsigned char *) last_action) {
> - /* The last sample is inside the trailing clone.
> - * Adjust its offset. */
> - last_observe_offset -= (unsigned char *)
> nl_attr_get(last_action) -
> - (unsigned char *) last_action;
> - ctx->xout->last_observe_offset = last_observe_offset;
> - }
> -
> nl_msg_reset_size(actions,
> (unsigned char *) last_action -
> (unsigned char *) actions->data);
> @@ -8288,11 +8308,10 @@ xlate_tweak_odp_actions(struct xlate_ctx *ctx)
>
Copying in the whole code to show the problem:
/* Remove the trailing clone() action, by directly embedding the nested
* actions. */
if (nl_attr_type(last_action) == OVS_ACTION_ATTR_CLONE) {
void *dest;
nl_msg_reset_size(actions,
(unsigned char *) last_action -
(unsigned char *) actions->data);
dest = nl_msg_put_uninit(actions, nl_attr_get_size(last_action));
memmove(dest, nl_attr_get(last_action), nl_attr_get_size(last_action));
After the memmove, last_action is no longer valid. It still
points to the start of where the clone was, which is now the
first nested action rather than the last one. It needs to be
re-determined before the act_is_observe() call below.
}
/* If the last action of the list is an observability action, add an
* explicit drop action so that drop statistics remain reliable. */
if (ctx->xbridge->ofproto->explicit_sampled_drops) {
if (act_is_observe(last_action)) {
put_drop_action(ctx->xbridge->ofproto, actions, XLATE_OK);
}
}
> /* If the last action of the list is an observability action, add an
> * explicit drop action so that drop statistics remain reliable. */
> - if (ctx->xbridge->ofproto->explicit_sampled_drops &&
> - last_observe_offset != UINT32_MAX &&
> - (unsigned char *) last_action == (unsigned char *) actions->data +
> - last_observe_offset) {
> - put_drop_action(ctx->xbridge->ofproto, actions, XLATE_OK);
> + if (ctx->xbridge->ofproto->explicit_sampled_drops) {
> + if (act_is_observe(last_action)) {
> + put_drop_action(ctx->xbridge->ofproto, actions, XLATE_OK);
> + }
> }
> }
[...]
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev