From patchwork Wed Apr 21 16:28:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sava Jakovljev X-Patchwork-Id: 1468764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23b; helo=mail-lj1-x23b.google.com; envelope-from=swupdate+bncbaabbwvfqgcamgqecpasm2i@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=M4zaM2AN; dkim-atps=neutral Received: from mail-lj1-x23b.google.com (mail-lj1-x23b.google.com [IPv6:2a00:1450:4864:20::23b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQQxF23tNz9sWX for ; Thu, 22 Apr 2021 02:29:19 +1000 (AEST) Received: by mail-lj1-x23b.google.com with SMTP id a14-20020a2e7f0e0000b02900b9011db00csf8960860ljd.8 for ; Wed, 21 Apr 2021 09:29:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1619022555; cv=pass; d=google.com; s=arc-20160816; b=F2k6jfcoZ53TJ2BrMYrpJ0vSF1b5MZ6pAEZfrwPkhT5o2Yhw3Nvkm5XQNXl2LUkjPO gCFJuDSctuK7Dv/3Z8oH5DjnKVC3eDkUlAcRLXJKcX0yNl4q+a4dXAWbAvBhZxqOgKBt cQOmsKHCTKz3a00lhasFKaBFnDF/GRJ3vU9LoxYSZr5oi5jZvgfSWGhCCrRRicVdh3Eu 9lwsaiitPA6U8sx/XANhxunpBkHi7iraQ+xaCCixidVkQJrOAqA+J7U/k7Vjno0NvW1g 1ob8Agcg8Qs0dlmh5ZkjGDu6Cub2drRgLcuq4tnephREnJEV1GiSUndlsA5W19XHmZ6K heFA== 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:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=S2lWPzffgFHqaVr6stMQ44v+6JNu+ZBGV2/2I0g1t3A=; b=JkSEpH5Aj74QR7xY1RFVa4/zeo7uKMwRjgosvepBdH64RksWf1H3HIoKlNN01mh5Mg 8fksSa4sxNyxuudhsisqovsT1uZlFBkI3fCT9Dc0LCrk3xsQ/n5FpKP0Sruej5RGT+yE nlmw/3lQaWTywu0jbEvBjZcp15/SHSuNX/vECAYu6adFp2wii2GqlIOFTSd+ggqhFiXb 9iBVjhV/KPf5OYvQqs3KKaTK16LAkDvzj2V4bml0jN7naBN1S8ZebTcSlfGbfRh+cbOR EGanqeRDgZjTXYl621eTfmZbtyva6NdrNswpUaIyJcRnc/+1igzOj/CUGWzwWTcz6qeg B//w== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=F8uU5hmv; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.92 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=S2lWPzffgFHqaVr6stMQ44v+6JNu+ZBGV2/2I0g1t3A=; b=M4zaM2ANwoTeQGCJOXAP2W3dOiVNOLvI+KWZ9gxQPo4MO7nmdz9M8YHZ+BWkx8RiFM mUP2HkdA9d1UF/PtT7kC7dtj0ZkKJi9FjkevOiHmpmGwSwsMHekl2qe2jYPRtTVI/OkU PkcCWcwEJDEDz+QEcuKhLglv83FgrkiNBMF/h2//YLWl3pVQA3x564UmTi3/8pcheIvy hAmkEAndGbuq5O2jULJl1bPLUCiw23c+gGXD7QIQR/NoLuRto+4+O22kW6/KDfOv3lCQ RmVLCiBA1Bcf0/j7Q6ndT3SSx9U4RX7fWHuBrcnBzyAdUD/Vj/i55ABKvXL2CYPxjna7 ONjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=S2lWPzffgFHqaVr6stMQ44v+6JNu+ZBGV2/2I0g1t3A=; b=OtUrG4J+znmloePy3CLgpVAkJ4P2DB+sKiEb7+F+A+M78ibtteCc5s+JUr6AM2mv3t Do6O/JJJAvCnUklDqxAtwaG1kNtn3+Hw9DPYu7Pz+8RTSwlmqLASYt8Ctbik32oFvV7g V60K+NpYsvxGpl4pIiWTtbkHGeg7zZ4wvhWGJlDPaoBm8RMOaS9SIcePUvu739aAkE7I HOYqAp/ftSsxt2eTQ6zYLEHS/AI2pFScfbvpG5wXtGCo+pSexHx5g0/+hclOjXN65Eec 1jXUmWF4d9of1zbUdRzN34x4yf+sFoZ4q9nsIms14DFaURMF27AeKVV+i/IMuTRAMRx6 Cg7Q== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM5318VnmNgO7rT/dupqQ29MaWW72V/qeUIcwqGmJuSq5/zegkh1QS pMAWHppPK4wslzXE7obrLi0= X-Google-Smtp-Source: ABdhPJz8poqPE69v4DOw61KpjBx3r0QQH4Hz8Wk+b8zOJ1pKtpGTJy/4Z/IHdS12VL21sfkNe0Zutg== X-Received: by 2002:a2e:9710:: with SMTP id r16mr20081231lji.25.1619022555109; Wed, 21 Apr 2021 09:29:15 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:f815:: with SMTP id a21ls2135163lff.1.gmail; Wed, 21 Apr 2021 09:29:14 -0700 (PDT) X-Received: by 2002:ac2:44d5:: with SMTP id d21mr14111673lfm.203.1619022554297; Wed, 21 Apr 2021 09:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619022554; cv=none; d=google.com; s=arc-20160816; b=H++iuNBom6Oz4SnDRaMYerC5BdqbnhoJPuK7MN5L6MUWoP9jyWqtZL7jaoHLKyLh0l mgi2+9YD+KFNhZ+6ot+5QLvBNWeqDdM57KGCGHbUbn0uJBb6i6b3J7s8skbZ2iwxQ0Gy BKjMamnULwgrLo/0TwCBz2kdHUJUluTJnpXBDWdh79/AswASTm4jILRqjcDgW5SjyuA6 tPyB3HE1k8SfGjBjoPYWuZmyZlesQXUqTD2fLcnTp9vMCCDIa4LMS4zgeEilO4rczlSN 2K+y2bbICsCT2akdm35JtArK/m0yvGw1SV+0fVHLgeHJrZpDEcLdWTWBeriJxeNvcMb9 KSdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from; bh=pnfS82kgKuLeY5cVXnyGvYmzB0XbgoTOkaKoM/de62c=; b=CHyy6xhRlzZT1EUAiQoXr5OiW7y6huqAGGxn20iAt91/jadA1FBe9e3DA9a5Uj7XsL vxl8Cio2u9u+wX+gx/mEO+SKt7z6NAhEl0nxBOeXBUsfPkwdHUUAJ94QjI/ktmxuKc/1 t+U7seAEhCLLndCzpXIWDc7z5xNj2HaAmqrVsOIAdcGHE2t6JH74LYRc4NlE8DoPRN+H OhG7vAJOvMQR5PZL/I0A3rmXZaQxSsTk4j9gwjblsGLC+etcnOsgBcCqvQP+fpaxPECd tjU1z1O6QouYa0ogHCiGLqeAzUkifdkQumDDMtDntdt7MrtyUf9co0DwGlR9yontrM93 0beA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=F8uU5hmv; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.92 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de Received: from mx-relay92-hz1.antispameurope.com (mx-relay92-hz1.antispameurope.com. [94.100.133.92]) by gmr-mx.google.com with ESMTPS id y11si223656lfg.8.2021.04.21.09.29.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Apr 2021 09:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.92 as permitted sender) client-ip=94.100.133.92; Received: from unknown ([212.91.255.190]) by mx-relay92-hz1.antispameurope.com; Wed, 21 Apr 2021 18:29:13 +0200 From: Sava Jakovljev To: CC: Sava Jakovljev Subject: [swupdate] [PATCH] libcurl channel: enable connection timeout option Date: Wed, 21 Apr 2021 18:28:51 +0200 Message-ID: <20210421162851.1027886-1-sava.jakovljev@teufel.de> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Originating-IP: [10.10.25.44] X-ClientProxiedBy: DNS-EX-01.teufel.local (10.10.0.80) To DNS-EX-02.teufel.local (10.10.0.81) X-C2ProcessedOrg: b93e13a0-e8da-4ba4-97b8-f14375b21c41 X-cloud-security-sender: sava.jakovljev@teufel.de X-cloud-security-recipient: swupdate@googlegroups.com X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mx-relay92-hz1.antispameurope.com with 54BB480DBF X-cloud-security-connect: unknown[212.91.255.190], TLS=1, IP=212.91.255.190 X-cloud-security-Digest: 0346599042ce18038cedd74ed38f8f7a X-cloud-security: scantime:1.681 X-Original-Sender: sava.jakovljev@teufel.de X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=F8uU5hmv; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.92 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de 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: , * Add new configuration option for Suricatta which enables users to set connection timeout in seconds. * Update documentation. Signed-off-by: Sava Jakovljev --- corelib/channel_curl.c | 9 +++++++++ doc/source/swupdate.rst | 11 +++++++++-- examples/configuration/swupdate.cfg | 8 ++++++-- include/channel_curl.h | 3 +++ suricatta/server_hawkbit.c | 19 +++++++++++++++---- 5 files changed, 42 insertions(+), 8 deletions(-) -- 2.26.3 diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index d2c1ab0..ff5f6d1 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -534,6 +534,13 @@ channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_da "this is most probably not what you want. " "Adapted it to %us instead.\n", SPEED_LOW_TIME_SEC); } + if (channel_data->connection_timeout <= 0) { + channel_data->connection_timeout = DEFAULT_CONNECTION_TIMEOUT; + DEBUG("cURL's connection timeout is disabled or invalid." + "This is most probably not what you want. " + "Adapted it to %us instead.\n", DEFAULT_CONNECTION_TIMEOUT); + } + channel_curl_t *channel_curl = this->priv; channel_op_res_t result = CHANNEL_OK; if ((curl_easy_setopt(channel_curl->handle, CURLOPT_URL, @@ -544,6 +551,8 @@ channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_da SPEED_LOW_BYTES_SEC) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_LOW_SPEED_TIME, channel_data->low_speed_timeout) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_CONNECTTIMEOUT, + channel_data->connection_timeout) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_HTTPHEADER, channel_curl->header) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_MAXREDIRS, -1) != diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst index d20e250..0b8e0c1 100644 --- a/doc/source/swupdate.rst +++ b/doc/source/swupdate.rst @@ -184,7 +184,7 @@ Images fully streamed --------------------- In case of remote update, SWUpdate extracts relevant images from the stream -and copies them into the directory pointed to by the environment variable +and copies them into the directory pointed to by the environment variable ``TMPDIR`` (if unset, to ``/tmp``) before calling the handlers. This guarantee that an update is initiated only if all parts are present and correct. However, on some systems with less resources, the amount of RAM @@ -643,6 +643,13 @@ Mandatory arguments are marked with '\*': | | | Suricatta is started with initial state of | | | | STATE_WAIT ("-c 6"), this value is ignored.| +-------------------------+----------+--------------------------------------------+ +| -s | integer | Connection timeout to use in seconds. | +| | | Default value is 15 seconds. | +| | | NOTE: it is not possible for Suricatta to | +| | | respond to external program API requests | +| | | during this period - adapt this value to | +| | | your use case! | ++-------------------------+----------+--------------------------------------------+ systemd Integration @@ -697,7 +704,7 @@ files are also handed over on a "regular" start of SWUpdate via ``systemctl start swupdate.service``. Note that the socket paths in the two ``ListenStream=`` directives -have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and +have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and ``CONFIG_SOCKET_PROGRESS_PATH`` in SWUpdate's configuration. Here, the default socket path configuration is depicted. diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg index c0547c5..49f9b00 100644 --- a/examples/configuration/swupdate.cfg +++ b/examples/configuration/swupdate.cfg @@ -15,7 +15,7 @@ # enable sending logs to syslog daemon # public-key-file : string # file with public key for -# image verification +# image verification # mtd-blacklist : list integers # MTD devices where SWUpdate # must not try to check for UBI filesystem. @@ -120,7 +120,7 @@ identify : ( { name = "swCompatibility"; value = "unknown";} ); -# +# # suricatta section: setup for backend # # Currently, they refer to the Hawkbit agent. @@ -169,6 +169,9 @@ identify : ( # initial-report-resend-period : integer # Specify period between re-tryint to send initial state, specified with "-c" option, # when connection to Hawkbit is not available. Default value is 10 seconds. +# connection-timeout : integer +# Specify server connection timeout. If no connection has been established in this +# period, libcurl will consider connection unsuccessful. Default value is 15 seconds. suricatta : { @@ -184,6 +187,7 @@ suricatta : groupid = 1000; enable = true; initial-report-resend-period = 30; + connection-timeout = 10; /* cafile = "/etc/ssl/cafile"; sslkey = "/etc/ssl/sslkey"; diff --git a/include/channel_curl.h b/include/channel_curl.h index 67cc971..c5ff881 100644 --- a/include/channel_curl.h +++ b/include/channel_curl.h @@ -14,6 +14,8 @@ #include #include "swupdate_status.h" +#define DEFAULT_CONNECTION_TIMEOUT 15 + /* Curl Channel Implementation Private Header File. * * This is a "private" header for testability, i.e., the declarations and @@ -60,6 +62,7 @@ typedef struct { unsigned int method; unsigned int retries; unsigned int low_speed_timeout; + unsigned int connection_timeout; channel_body_t format; bool debug; bool usessl; diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index f0d10c0..1ae1a07 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -51,6 +51,7 @@ static struct option long_options[] = { {"disable-token-for-dwl", no_argument, NULL, '1'}, {"cache", required_argument, NULL, '2'}, {"initial-report-resend-period", required_argument, NULL, 'm'}, + {"connection-timeout", required_argument, NULL, 's'}, {NULL, 0, NULL, 0}}; static unsigned short mandatory_argument_count = 0; @@ -130,7 +131,8 @@ static channel_data_t channel_data_defaults = {.debug = false, .format = CHANNEL_PARSE_JSON, .nocheckanswer = false, .nofollow = false, - .strictssl = true + .strictssl = true, + .connection_timeout = 0 }; static struct timeval server_time; @@ -1599,10 +1601,12 @@ void server_print_help(void) "\t --disable-token-for-dwl Do not send authentication header when downlloading SWU.\n" "\t --cache Use cache file as starting SWU\n" "\t -m, --initial-report-resend-period Time to wait prior to retry " - "sending initial state with '-c' option (default: %ds).\n", + "sending initial state with '-c' option (default: %ds).\n" + "\t -s, --connection-timeout Set the server connection timeout (default: %ds).\n", CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES, CHANNEL_DEFAULT_RESUME_DELAY, - INITIAL_STATUS_REPORT_WAIT_DELAY); + INITIAL_STATUS_REPORT_WAIT_DELAY, + DEFAULT_CONNECTION_TIMEOUT); } static int server_hawkbit_settings(void *elem, void __attribute__ ((__unused__)) *data) @@ -1636,6 +1640,9 @@ static int server_hawkbit_settings(void *elem, void __attribute__ ((__unused__) get_field(LIBCFG_PARSER, elem, "usetokentodwl", &server_hawkbit.usetokentodwl); + get_field(LIBCFG_PARSER, elem, "connection-timeout", + &channel_data_defaults.connection_timeout); + GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "targettoken", tmp); if (strlen(tmp)) SETSTRING(server_hawkbit.targettoken, tmp); @@ -1683,7 +1690,7 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) /* reset to optind=1 to parse suricatta's argument vector */ optind = 1; opterr = 0; - while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:m:", + while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:m:s:", long_options, NULL)) != -1) { switch (choice) { case 't': @@ -1772,6 +1779,10 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) server_hawkbit.initial_report_resend_period = (unsigned int)strtoul(optarg, NULL, 10); break; + case 's': + channel_data_defaults.connection_timeout = + (unsigned int)strtoul(optarg, NULL, 10); + break; /* Ignore not recognized options, they can be already parsed by the caller */ case '?': break;