feat(config-repl): wire handle_upgrade_config() via raw packet interception

Pre-decode opcode peek in myreq_handler() captures raw packet bytes for
OP_upgradeConfig before xce_decode() frees the capnp segment. Passes
raw bytes to xce_upgrade_config_req_extract_raw() to extract sha256 and
config blob, then delegates to do_upgrade_config_with_bytes().

Removes Task 11 dependency. Phase 2 still gated by CONF_ENABLE_UPGRADE_CONFIG.
This commit is contained in:
Rongsong Shen 2026-05-21 13:51:52 +00:00
parent 2aae45f046
commit 5053c8d42f
3 changed files with 66 additions and 27 deletions

View file

@ -1131,13 +1131,8 @@ int push_config_to_standbys(cluster_t *c, const uint8_t *bytes, size_t blen,
/*
* do_upgrade_config_with_bytes: core upgrade logic called after the raw
* capnp bytes have been extracted from the wire.
*
* Task 11 dependency note: the upgrade_config_req_t.bytes and .sha256 fields
* are typed as xce_data_t* (a discriminated cluster-data union) in the current
* typemap. Extracting raw byte content from them requires the Task 11 capnp
* Data-type shims. This helper accepts the bytes directly so that the logic
* can be tested independently of the typemap shim work.
* capnp bytes have been extracted from the wire via
* xce_upgrade_config_req_extract_raw().
*
* Steps:
* 0. Validate size limits
@ -1298,28 +1293,41 @@ static int do_upgrade_config_with_bytes(cluster_t *c, endpoint_t *ep,
}
#if CONF_ENABLE_UPGRADE_CONFIG
int handle_upgrade_config(cluster_t *c, endpoint_t *ep, xce_request_t *req)
int handle_upgrade_config(cluster_t *c, endpoint_t *ep, xce_request_t *req,
const uint8_t *raw_pkt, size_t raw_pkt_sz)
{
/*
* Task 11 dependency: upgrade_config_req_t.bytes and .sha256 are typed
* as xce_data_t* (discriminated cluster-data union). Extracting raw
* byte content requires the Task 11 capnp Data-type shims.
*
* Until Task 11 lands this handler rejects all upgrade requests with
* -ENOSYS even when CONF_ENABLE_UPGRADE_CONFIG=1. The
* do_upgrade_config_with_bytes() helper above contains the full
* implementation and will be wired here in Task 11.
*/
(void)c;
send_upgrade_error(ep, req, c,
"OP_upgradeConfig byte extraction requires Task 11"
" typemap shims -- not yet available");
return -ENOSYS;
uint8_t *in_bytes = NULL;
size_t in_len = 0;
uint8_t *in_sha = NULL;
int rc = xce_upgrade_config_req_extract_raw(raw_pkt, raw_pkt_sz,
&in_bytes, &in_len, &in_sha);
if (rc != 0 || !in_bytes || !in_sha) {
send_upgrade_error(ep, req, c,
"Failed to extract bytes from UpgradeConfigRequest");
free(in_bytes);
free(in_sha);
return rc != 0 ? rc : -EINVAL;
}
if (in_len == 0) {
free(in_bytes);
free(in_sha);
send_upgrade_error(ep, req, c, "bytes or sha256 field missing");
return -EINVAL;
}
rc = do_upgrade_config_with_bytes(c, ep, req, in_bytes, in_len, in_sha);
free(in_bytes);
free(in_sha);
return rc;
}
#else
int handle_upgrade_config(cluster_t *c, endpoint_t *ep, xce_request_t *req)
int handle_upgrade_config(cluster_t *c, endpoint_t *ep, xce_request_t *req,
const uint8_t *raw_pkt, size_t raw_pkt_sz)
{
(void)c;
(void)raw_pkt;
(void)raw_pkt_sz;
xce_reply_t reply;
init_reply_by_req(&reply, req);
reply.status = -ENOSYS;