From patchwork Thu Oct 26 08:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1855664 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=I6MbWCHK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13c; helo=mail-lf1-x13c.google.com; envelope-from=swupdate+bncbaabbegr5cuqmgqe7f4mxwa@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lf1-x13c.google.com (mail-lf1-x13c.google.com [IPv6:2a00:1450:4864:20::13c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SGKKP72KKz23jr for ; Thu, 26 Oct 2023 19:51:36 +1100 (AEDT) Received: by mail-lf1-x13c.google.com with SMTP id 2adb3069b0e04-507cc15323asf670817e87.0 for ; Thu, 26 Oct 2023 01:51:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698310290; cv=pass; d=google.com; s=arc-20160816; b=cNmpK2kt3Rx9IU3sS14DNrPH84CT24fwnnfmI9i9GPFEjVz9+b/LRITDzed7D6NFbm Q253ew7+N5loniA4QoRzBnr+qilKOoOM2y4WgUEzndUMSZARIDj2v+dazDDF+E/g+QuB i3RoA9QM4hJjwdE4MPp6s2l2EMAaAzqfe6VEJ+6kaFNBmxUxWBYHakq+ojv/azDUtR1x sNJhRq6bS90DxBpE+CVZxWpkOlBby9eT7R2IjKjlZJgVuLenZTJojQZiPQGwIsAsrDxc V7zArL4B7uHF4UPTbDbASNapKQokFc468+NRtoRB56RdFrLvheOgXgOmsmytWhqqFv1a hUyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=uwv75bX+LTKuUoUZ/HlL/PVMb+6o6DdU4kGVw/KtXLo=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=hvGA+z2yn5IDPTODwLuwajRK9p2kI6Kev9A1O84uepJmJ7Yfp+FXY8nw98ACk9D5ML czn4cgzuZN8alwZTDaMeJUD/H/9q6xBq1Yu+lw00hfbwqH/xFMmqWGIVxU5KmFLtK3hX zrhaEz2wE0t+T4mDNCYT1Vr4luP3+EDyW9RYR9dp25+zuCX8jD5hiPY2sP8IUvEowQ6L QnYF5hPGUnQan+FmGtr10wcOocCl3blAM3E3uyeYgflS79No4L5MSdxuvVBNjaQikkKL VHeqt4peXlia4XAHS7azJ6/4ea4LZkhvWH3VS3DU6+hYUEX6JmSUooXXQh9t9kwjPRI8 OobQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.135 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1698310290; x=1698915090; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:message-id:date :subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=uwv75bX+LTKuUoUZ/HlL/PVMb+6o6DdU4kGVw/KtXLo=; b=I6MbWCHKIZJNTmJnl2a2OxeWbJALQIzuVHBa17wM2D78SfRQcFwjNsLWe+kr7s1gtL 1yuFnrz0e68En5+cxGLHHqiYWAFy6x4cNRdVw4MjEaW3d8RILJAViOSx/eyWotdJb/05 TMz1NGhO3q0NV9ueAE0Q4xQ62wwMX/N/+mmSG3CdYjCLau46AS6zUGo0J35SSRt/Iqmn ENR+YQ3uwFGMlVFyRv8OLgjPhWRZOlEBBG5zBqCfBV9BcVTsgT7iYJqHr5gJyyi5cRDF riPwngMH5sU/dfOKvj0CjQt821CFq1CNXQip78MGvVhaSpNhEy5Z2kKf2eGFoao43qxb Dqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698310290; x=1698915090; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=uwv75bX+LTKuUoUZ/HlL/PVMb+6o6DdU4kGVw/KtXLo=; b=MFXsWArVWFK5pmy62k003FUKUaocPSMQgH2ijMM/XNIN/WLwMCS8c2/AWd3DqpKlt1 PrYo2E2v1MC2Q+qY2RhHp3DgdOEL3iYR2CcBXuSzxCfWSju3ArzU3N2asMF64fl1RtVj roYDcpOwoP2KQTog/YlhtLQhymVRqmFrG8qka1fqq6nS/Sst8dFUBvbS4VWizxzGzlGq Tt3LlQYe4KBYKwlWmfN8W1on0tmCjPciDgVSkCY86hNkSi6YCyzk544DF4D9COTlMITV EQx6v1R5s0MqeDvIIdiTF3qKpCSsA3FQ7aZH9tXW08Ve26hGDpu4Rqf4bZzEXYaBiGmq ySyA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0YySPJiZqR7zvagjXsxoZILANnWUsjdWXsdiLSEao/Crbfw1DDue KJuy/Ctycw1sifmx1cFQ9QI= X-Google-Smtp-Source: AGHT+IHqNJdpUkmb63OC0recRxyr5FvREAPMweGTHcuSKDt5pFHtIdEA8UiMwPVXHhT0327V9ITWFg== X-Received: by 2002:a05:6512:3096:b0:507:f0f2:57b1 with SMTP id z22-20020a056512309600b00507f0f257b1mr12893410lfd.15.1698310289226; Thu, 26 Oct 2023 01:51:29 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:b89:b0:504:1c05:94aa with SMTP id b9-20020a0565120b8900b005041c0594aals223890lfv.0.-pod-prod-06-eu; Thu, 26 Oct 2023 01:51:27 -0700 (PDT) X-Received: by 2002:a05:6512:4016:b0:508:1178:efa4 with SMTP id br22-20020a056512401600b005081178efa4mr5366791lfb.55.1698310287173; Thu, 26 Oct 2023 01:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698310287; cv=none; d=google.com; s=arc-20160816; b=Ae8htPuk1+eQtXO3Gjp3WwcEXD/q/SEYlnk8RTqQ3CCpFz4HcT6U+jhfEZFvROtQ3f +xjnnfA1bUShum8XBZbzl+F6HOTfukdFNsSEjbhFc49+LSBQKcjCx9cKAC/LexHrhmGI xsjFs0zatBrEgcUKVhhEp0adTi8cMp+Eqq8wyFQ+7qbWvUxO+AQnemoPv3Dvlx8vCU/4 X4uwHDqDPA1lyKZ1Xsols2EZ5cxGjwfFqcy15Qxkq+2xIX+IgaX0KKKC5ZcLd49JOz/o 5UE42qbaPgnWBBknvV8m7EBsF/iPxKkwUYrU0yGNLZdb4nPvNJeXMUi+77A7P+18f9VY sf1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from; bh=k6XshkXpToruV+8+HRtdLYfSvOFNLZvdFOH6+RM6l1o=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=vB1iE+Ryxv1OY3qHlxiWQWIzCfYbPCyotx6pDwtZfaWpBfAgGF5zG6nEf/AnRyrSuU 7oTpudLWH/27r2+6jil6A14hwVYDThf072/dCSuUPKGytrW8A399kUwIz/e87/4IHLYw 0p5J5c81YGuZfgZMIGvXyACYgFsQdxgyD1U92xb4ydf3iecD3FIlkwXpMji8fKv9iQ3D 3+3NUhdFfE4EPrdXFfpSt6uiLufBQV/weXtocW3If1EDjkc3Pj/RZ87KMRH6qHqwzZXJ +F6Dr78H0AuCguN38qwOzdXCVba+SKMsiUGEjKOu3FvUsGtG1qq+7v+d1eF9vHsZH1g8 qYJw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.135 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.126.135]) by gmr-mx.google.com with ESMTPS id t26-20020ac24c1a000000b004ffa201cad8si607445lfq.9.2023.10.26.01.51.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 01:51:27 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.135 as permitted sender) client-ip=212.227.126.135; Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue011 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MVMqF-1r5bQ11SOl-00SKrM; Thu, 26 Oct 2023 10:51:26 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] progress: versioning of the API Date: Thu, 26 Oct 2023 10:51:24 +0200 Message-Id: <20231026085124.627056-1-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:6MQfmRiqd6tc5dbU+/rVyEWzkD88lkHhT0lf+bkbIAVFqPB4rjN Y8pToLJamvhMl7EbyNZ0Jn8uMKTtalL8cSVCsz8b7b6xDbcQdFJNtsuIq9PkUn21CFiSoKP vDUVf4RPhuO06UQZ9VAKddBMDJcSO/ZoLGSHQGBd8yzujuxmD8Z7ne5LocqHo4PbQ7bHXmL 3zmepsd+vlc+RMCWAZ1Lw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:K25gPHAn0ms=;jr3mx1ndnZ2CWmL54q2T5Rko6AY xO46DAiD42JMYyo/6qBODJbGWVwvOURBNGdq4H/s2Rcf8Zy8MJwXgSux9hftaG9WBr/Pu6Ag1 R3UY+xzFl6wH+0/G1N+S99owWjzvKVAx73tPxsn8yMLhrn5YzLvgvubXpyoLte5gi9RGd7j4D Ogkka5ZcsmQ1d84lOYfPZMd1ANOh5Huc0+zo1YQYw/P7VJpDgCLwKQIGwiD7Cp6PKCk+dIv/1 yk/Zu5Qxk7sQe6Lo7rJBjZZhdcjSj5GJ1NWJZDewVIetrQXF0kmKdhmRuMfoizjLxKeOWsJTk +bVc8hD1E0Jug7zdDVsWklnusqoUT6bh3Zs3U6OviOuovTXsLDX7DMh3XCLABvpnzOBOkX6m8 ZisrCbXooF80V5KkhAuyhr0TO9hDR7y+iLLw+nE9ox2+xyG7zKEtB8BT/80W8wLxS2UAlAPsV QsiJoITqklHe16mSy9AH2Hwdi1ylTTju9pGfKp0SM93PjMoo5rj5haZzmdkUX3lJvDuZnBRa7 hcymQCt6a9xLL9j1WpohdcDW+Yym54TtKwi09HXvrsAW1qtgyD4xTm9ipV7vtpp/dSKrNod1k Iepw4rBOhZSxGFdC+EvT7DEq2o0aDNiUszZgtSaIeys2pux+5ku5W6UPpek+4bfZjce2C6eI+ eo5AhMMBL3rOdLrQSYLnaDVbW6xwrImJfTI+j9wHnRXWzXm50sWghOIQBrtp243xUdWgE8SV7 Fg99nD4Nw483gpGqp5IsyJ+eBJU0c6pEUzXIjsbAyUJ9GlNpPxnFMy+tmJgfBmcFWlPWZu897 vjkxv41+y9WyyhkVm64G4xJ1FiSJeXstrvkL9VWBUEwz1S2T3J/APINU6WrQMwoC1oHPtY1zI be4oxsx6hgHwPYw== X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.135 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , It is not excluded that the message structure use to exchange messages via progress interface can be changed in future, raising compatibility issues. To check this, the unused "magic" field assumes the value for the current API version. Schema for the versioning is put into include/progress_ipc.h. The receiver (progress_ipc_receive) is changed to check for changes in the major version of the API, returning an error in that case. Signed-off-by: Stefano Babic --- core/progress_thread.c | 1 + include/progress_ipc.h | 24 +++++++++++++++++++++++- ipc/progress_ipc.c | 7 +++++++ suricatta/server_lua.c | 2 +- tools/swupdate-ipc.c | 4 ++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/core/progress_thread.c b/core/progress_thread.c index f579f302..d0935445 100644 --- a/core/progress_thread.c +++ b/core/progress_thread.c @@ -130,6 +130,7 @@ void swupdate_progress_init(unsigned int nsteps) { struct swupdate_progress *pprog = &progress; pthread_mutex_lock(&pprog->lock); + pprog->msg.apiversion = PROGRESS_API_VERSION; pprog->msg.nsteps = nsteps; pprog->msg.cur_step = 0; pprog->msg.status = START; diff --git a/include/progress_ipc.h b/include/progress_ipc.h index c1ff78b0..0d4551f9 100644 --- a/include/progress_ipc.h +++ b/include/progress_ipc.h @@ -23,12 +23,34 @@ extern "C" { extern char* SOCKET_PROGRESS_PATH; +/* + * Versioning of API + * it is defined as + * bits 31..24 : unused, set to 0 + * bits 23..16 : Major Version + * bits 15..8 : Minor version + * bits 7..0 : small changes not relevant for compatibility + * + * The following policy is followed: + * - changes in minor version mean that the API was enhanced and it has + * new features, but it is compatible with the older. It is suggested + * that clients are updated, but they still work. + * - changes in major mean an incompatibility and clients do not work anymore + */ + +#define PROGRESS_API_MAJOR 1 +#define PROGRESS_API_MINOR 0 +#define PROGRESS_API_PATCH 0 + +#define PROGRESS_API_VERSION ((PROGRESS_API_MAJOR & 0xFFFF) << 16 | \ + (PROGRESS_API_MINOR & 0xFF) << 8 | \ + (PROGRESS_API_PATCH & 0xFF)) /* * Message sent via progress socket. * Data is sent in LE if required. */ struct progress_msg { - unsigned int magic; /* Magic Number */ + unsigned int apiversion; /* API Version for compatibility check */ RECOVERY_STATUS status; /* Update Status (Running, Failure) */ unsigned int dwl_percent; /* % downloaded data */ unsigned long long dwl_bytes; /* total of bytes to be downloaded */ diff --git a/ipc/progress_ipc.c b/ipc/progress_ipc.c index 745dc443..3e5641c3 100644 --- a/ipc/progress_ipc.c +++ b/ipc/progress_ipc.c @@ -82,6 +82,13 @@ int progress_ipc_receive(int *connfd, struct progress_msg *msg) { if (ret == -1 && (errno == EAGAIN || errno == EINTR)) return 0; + /* + * size of message can vary if the API version does not match + * First check it to return a correct error, else it always + * return -1. + */ + if (ret > sizeof(msg->apiversion) && (msg->apiversion != PROGRESS_API_VERSION)) + return -EBADMSG; if (ret != sizeof(*msg)) { close(*connfd); *connfd = -1; diff --git a/suricatta/server_lua.c b/suricatta/server_lua.c index 7ff79ae9..0244bf2e 100644 --- a/suricatta/server_lua.c +++ b/suricatta/server_lua.c @@ -903,7 +903,7 @@ static void *progress_offloader_thread(void *data) (void)pthread_mutex_lock(thread_data->lua_lock); lua_newtable(thread_data->L); - push_to_table(thread_data->L, "magic", message->magic); + push_to_table(thread_data->L, "apiversion", message->apiversion); push_to_table(thread_data->L, "status", message->status); push_to_table(thread_data->L, "dwl_percent", message->dwl_percent); push_to_table(thread_data->L, "nsteps", message->nsteps); diff --git a/tools/swupdate-ipc.c b/tools/swupdate-ipc.c index ea8c7dc9..d070b18d 100644 --- a/tools/swupdate-ipc.c +++ b/tools/swupdate-ipc.c @@ -747,10 +747,10 @@ static int monitor(cmd_t __attribute__((__unused__)) *cmd, int argc, char *argv msg.hnd_name[sizeof(msg.hnd_name) - 1] = '\0'; msg.cur_image[sizeof(msg.cur_image) - 1] = '\0'; - fprintf(stdout, "[{ \"magic\": %d, \"status\": %u, \"dwl_percent\": %u, \"dwl_bytes\": %llu" + fprintf(stdout, "[{ \"apiversion\": 0x%x, \"status\": %u, \"dwl_percent\": %u, \"dwl_bytes\": %llu" ", \"nsteps\": %u, \"cur_step\": %u, \"cur_percent\": %u, \"cur_image\": \"%s\"" ", \"hnd_name\": \"%s\", \"source\": %u, \"infolen\": %u }", - msg.magic, msg.status, msg.dwl_percent, + msg.apiversion, msg.status, msg.dwl_percent, msg.dwl_bytes, msg.nsteps, msg.cur_step, msg.cur_percent, msg.cur_image, msg.hnd_name, msg.source, msg.infolen);