From patchwork Fri Aug 23 16:15:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775490 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F21318BC31 for ; Fri, 23 Aug 2024 16:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429757; cv=none; b=m/vngT2qDoksqFUasJEj7DYM+hldZV71e689gVFGp1KeiPBQ/9sUuGNf2T/ct16NjJWTRtq2j0uMMrjR2vNzf7fTZaGRU7DleCPRImDsWSASkZW+iAaeZyU9D3LEF2tzArHCbsB445Jz8SYAnM5aMZey/Or0ku3WUULnoi1vWpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429757; c=relaxed/simple; bh=ZjMp0u2393LT8iz7OfixDBw9ywdR2DKD5lV/UO2ij3o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uqb0doYQadzZH6yXCNaYWFOW+rgETG1BtTOxbic3wgRdHVrRUlH7dJSH46OZUilFN4pxsZ/osUpmxKfEt26sZ95GGoKOUNzNJKtZuMs8XgzeXDte2y81V/7zRooncz4e95igVCXXrQ6wo6uy032ZmOEQPNGw1pLbTnnMQr8ffhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aVAUyE/u; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aVAUyE/u" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5d5eec95a74so1485451eaf.1 for ; Fri, 23 Aug 2024 09:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429755; x=1725034555; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=htVfznG7fepxsS7pzxoMJVB2hZnfsGO89YO7ZE1YQxI=; b=aVAUyE/u2LNRkw/VnaQ1EAmmEGCG8Pw9Uqw/ueTGzP8gus5iRCsJI497R26zlDqoFY AGAJczFvVLclH41O8SIuOndYeXX+uIY1I9MI5nlPraAoWmmY4zK2M9ZF/7xPr0usZtrZ SaJONrfaXRx6pR5drVSvsJfvMPvbnKtuilgSuS7ofdXAFjX14Y6FKw5YzB7/nvgN6vaL 6JjQGNi7okYgen9DDThexNLaAK1qUeGKjnDtyeLW20nHMXh8akZgT28u08kEQ2ebYnr4 dihN0PcB9DZBHYUiAereaOSuGjaZs10vaJnYfZOEPQjRTBkIRATGKnhL9jK1K96TgCM7 F29g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429755; x=1725034555; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=htVfznG7fepxsS7pzxoMJVB2hZnfsGO89YO7ZE1YQxI=; b=eamv+/LqJ1O2syXBDhP455/guiOCGM3oIUOVtHTrUVej+/aomUxSKp6yUuqNDIZ4Xh 4hvkIO1PjRO10tMJ+/eaG4H++L7TVDVkc5Ar0CRGSeYN8+fpgZgvau8MW9ZMX8qJj34c 1S5nPNhAooB0CStmGExNqWUewJOfRpuaePkW3I9DGKYp1toFVEUGFxIX6EK3IYb7K3h4 hjPsqLINa7L6TvinGsALtxaMga9/ODnSgsCD0yDLDfPBOWVzyYJSLrlCHDCKaajQ5+4M VgpPwWz4Y0kE97Nrh7VKsi6rbEBFlDUZXW6sY3Z94wsIHCOuU8WbbWYcv7xD09u3Yrwl g1Uw== X-Gm-Message-State: AOJu0YxygtzqjscGLaN5GHxYPpfuo/drBO/fUcmxc3kL5n0W/IBZzS5y 6PlsJhhZHgW+ARuUpDx7+qwqag5h80/vKL/+amn5T52fAK4kLqKqez3eOQ== X-Google-Smtp-Source: AGHT+IFi2WKKnsx/uL2USm2JzS46vwk6WwZuFQ+oN/NSXDh2NQCc35XMotR9vBLLswnvOSRUCoDZ2Q== X-Received: by 2002:a05:6820:451:b0:5dc:cdf8:21c8 with SMTP id 006d021491bc7-5dccdf8229dmr1370347eaf.4.1724429755241; Fri, 23 Aug 2024 09:15:55 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:55 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/6] netlink: Add l_netlink_iter Date: Fri, 23 Aug 2024 11:15:45 -0500 Message-ID: <20240823161553.479576-1-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move netlink attribute iterator out of genl.c and into netlink.c. Both genl and netlink use the same attribute structure, and is applicable to both. This makes implementing netlink and rtnl message parsers much easier. In order to keep source compatibility, structure the netlink iterator in the same way as the genl iterator. In the future, the use of genl iterators will be removed. --- ell/ell.sym | 5 ++-- ell/genl.c | 76 +++------------------------------------------------ ell/genl.h | 18 +++++++++--- ell/netlink.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ ell/netlink.h | 15 ++++++++++ 5 files changed, 111 insertions(+), 78 deletions(-) diff --git a/ell/ell.sym b/ell/ell.sym index c5d1c2a9edea..1499081cb25e 100644 --- a/ell/ell.sym +++ b/ell/ell.sym @@ -344,8 +344,6 @@ global: l_genl_msg_enter_nested; l_genl_msg_leave_nested; l_genl_attr_init; - l_genl_attr_next; - l_genl_attr_recurse; l_genl_family_info_can_send; l_genl_family_info_can_dump; l_genl_family_info_has_group; @@ -445,6 +443,9 @@ global: l_netlink_message_add_header; l_netlink_message_enter_nested; l_netlink_message_leave_nested; + l_netlink_attr_init; + l_netlink_attr_next; + l_netlink_attr_recurse; /* path */ l_basename; l_path_find; diff --git a/ell/genl.c b/ell/genl.c index 5a8dd371a970..ac10cbf07ef0 100644 --- a/ell/genl.c +++ b/ell/genl.c @@ -1559,80 +1559,12 @@ LIB_EXPORT bool l_genl_msg_leave_nested(struct l_genl_msg *msg) LIB_EXPORT bool l_genl_attr_init(struct l_genl_attr *attr, struct l_genl_msg *msg) { - const struct nlattr *nla; - uint32_t len; - - if (unlikely(!attr) || unlikely(!msg)) - return false; - - if (!msg->nlm || - msg->nlm->hdr->nlmsg_len < NLMSG_HDRLEN + GENL_HDRLEN) - return false; - - nla = msg->nlm->data + NLMSG_HDRLEN + GENL_HDRLEN; - len = msg->nlm->hdr->nlmsg_len - NLMSG_HDRLEN - GENL_HDRLEN; - - if (!NLA_OK(nla, len)) - return false; - - attr->data = NULL; - attr->len = 0; - attr->next_data = nla; - attr->next_len = len; - - return true; -} - -LIB_EXPORT bool l_genl_attr_next(struct l_genl_attr *attr, - uint16_t *type, - uint16_t *len, - const void **data) -{ - const struct nlattr *nla; - - if (unlikely(!attr)) - return false; - - nla = attr->next_data; - - if (!NLA_OK(nla, attr->next_len)) + if (unlikely(!msg) || unlikely(!msg->nlm)) return false; - if (type) - *type = nla->nla_type & NLA_TYPE_MASK; - - if (len) - *len = NLA_PAYLOAD(nla); - - if (data) - *data = NLA_DATA(nla); - - attr->data = attr->next_data; - attr->len = attr->next_len; - - attr->next_data = NLA_NEXT(nla, attr->next_len); - - return true; -} - -LIB_EXPORT bool l_genl_attr_recurse(const struct l_genl_attr *attr, - struct l_genl_attr *nested) -{ - const struct nlattr *nla; - - if (unlikely(!attr) || unlikely(!nested)) - return false; - - nla = attr->data; - if (!nla) - return false; - - nested->data = NULL; - nested->len = 0; - nested->next_data = NLA_DATA(nla); - nested->next_len = NLA_PAYLOAD(nla); - - return true; + return l_netlink_attr_init((struct l_netlink_attr *) attr, + NLMSG_HDRLEN + GENL_HDRLEN, + msg->nlm->data, msg->nlm->hdr->nlmsg_len) == 0; } /** diff --git a/ell/genl.h b/ell/genl.h index 3f38fd9d5710..ed5f17c4fd2e 100644 --- a/ell/genl.h +++ b/ell/genl.h @@ -91,10 +91,20 @@ bool l_genl_msg_enter_nested(struct l_genl_msg *msg, uint16_t type); bool l_genl_msg_leave_nested(struct l_genl_msg *msg); bool l_genl_attr_init(struct l_genl_attr *attr, struct l_genl_msg *msg); -bool l_genl_attr_next(struct l_genl_attr *attr, uint16_t *type, - uint16_t *len, const void **data); -bool l_genl_attr_recurse(const struct l_genl_attr *attr, - struct l_genl_attr *nested); + +static inline bool l_genl_attr_next(struct l_genl_attr *attr, uint16_t *type, + uint16_t *len, const void **data) +{ + return l_netlink_attr_next((struct l_netlink_attr *) attr, + type, len, data) == 0; +} + +static inline bool l_genl_attr_recurse(const struct l_genl_attr *attr, + struct l_genl_attr *nested) +{ + return l_netlink_attr_recurse((struct l_netlink_attr *) attr, + (struct l_netlink_attr *) nested) == 0; +} bool l_genl_family_info_has_group(const struct l_genl_family_info *info, const char *group); diff --git a/ell/netlink.c b/ell/netlink.c index 121a322fccf5..0be3009c736f 100644 --- a/ell/netlink.c +++ b/ell/netlink.c @@ -944,3 +944,78 @@ LIB_EXPORT int l_netlink_message_leave_nested(struct l_netlink_message *message) return 0; } + +LIB_EXPORT int l_netlink_attr_init(struct l_netlink_attr *iter, + size_t header_len, + const void *data, uint32_t len) +{ + const struct nlattr *nla; + + if (unlikely(!iter) || unlikely(!data)) + return -EINVAL; + + if (len < NLA_ALIGN(header_len)) + return -EMSGSIZE; + + nla = data + NLA_ALIGN(header_len); + len -= NLA_ALIGN(header_len); + + if (!NLA_OK(nla, len)) + return -EMSGSIZE; + + iter->data = NULL; + iter->len = 0; + iter->next_data = nla; + iter->next_len = len; + + return 0; +} + +LIB_EXPORT int l_netlink_attr_next(struct l_netlink_attr *iter, + uint16_t *type, uint16_t *len, + const void **data) +{ + const struct nlattr *nla; + + if (unlikely(!iter)) + return -EINVAL; + + nla = iter->next_data; + if (!NLA_OK(nla, iter->next_len)) + return -EMSGSIZE; + + if (type) + *type = nla->nla_type & NLA_TYPE_MASK; + + if (len) + *len = NLA_PAYLOAD(nla); + + if (data) + *data = NLA_DATA(nla); + + iter->data = iter->next_data; + iter->len = iter->next_len; + + iter->next_data = NLA_NEXT(nla, iter->next_len); + return 0; +} + +LIB_EXPORT int l_netlink_attr_recurse(const struct l_netlink_attr *iter, + struct l_netlink_attr *nested) +{ + const struct nlattr *nla; + + if (unlikely(!iter) || unlikely(!nested)) + return -EINVAL; + + nla = iter->data; + if (!nla) + return false; + + nested->data = NULL; + nested->len = 0; + nested->next_data = NLA_DATA(nla); + nested->next_len = NLA_PAYLOAD(nla); + + return 0; +} diff --git a/ell/netlink.h b/ell/netlink.h index 08aff74fbac2..f09d42043675 100644 --- a/ell/netlink.h +++ b/ell/netlink.h @@ -119,6 +119,21 @@ static inline int l_netlink_message_append_mac(struct l_netlink_message *message return l_netlink_message_append(message, type, mac, 6); } +struct l_netlink_attr { + const struct nlattr *data; + uint32_t len; + const struct nlattr *next_data; + uint32_t next_len; +}; + +int l_netlink_attr_init(struct l_netlink_attr *attr, size_t header_len, + const void *data, uint32_t len); +int l_netlink_attr_next(struct l_netlink_attr *attr, + uint16_t *type, uint16_t *len, + const void **data); +int l_netlink_attr_recurse(const struct l_netlink_attr *iter, + struct l_netlink_attr *nested); + #ifdef __cplusplus } #endif From patchwork Fri Aug 23 16:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775491 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13E8318BC39 for ; Fri, 23 Aug 2024 16:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429758; cv=none; b=RIXnyHJQIvm93ytfgwnQqKykMrliCTxKO2eEI8seyQ50YXgj1HDCTb9zEyS4SfiDIOwzP54KyrPH29QoqgfvnLk/dkwyvb/StJQfKJHJ6Q4Giukq5nbW3nJS6h7ED9luMqzKXI+ACtmeeKnTIvL7t8fX1u2cSUU09OIq0OjvgQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429758; c=relaxed/simple; bh=X8CIYuXzXLrJ32tJUUltHPOUDQ5iLdwyLHAitt6pd0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtwBvWksJRy6oHi4KKLDjsHotATb9ttShB/rjoLouutzaEydSyER7oAnMulHZoBO1YIFVwlPKVBSO66EVibCcygbVVXSipWJVDa9dfiwp58FTVsU/KGIHe1ZrXpDp2aR3pB0CmV0CsZA+yJhHx8K9MB6Tj1iN8uRHionA2N8dFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jKqe9zns; arc=none smtp.client-ip=209.85.161.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jKqe9zns" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5d5c8c1006eso1525752eaf.3 for ; Fri, 23 Aug 2024 09:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429756; x=1725034556; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s8trhKgXPl0k8p/Xs8doNH3rTsnqbgyAarZYQgKSCEM=; b=jKqe9znsDA7IzkSmIobyv6c/iPDSkuKOQnt+9eYhb8+eRFUnTTggA2c+Mpg3OOqjPj VrM9Itu7fJrmSABrYcefyf17Hk73oK2YjXM5CENUgljp0xLGF3oM4Hds38Iij0RILAd6 IXSBsBFln5QGiLgyqrLYc8kZ5tN+7hUcCl/l7CLYaE3pGerxcWAjwFbxrID/TaYKtVMV bcSiBgGlOyCgaURwYhS98rp1AKNm/wHqrdC3LrkU1fuI8z7ZkqZSo6hXBDN2vkKSm6j6 uBk3IIuP8+erUwmmm9iAcr/DQhuJhXiJsRXEomEWVjKQI7BWuKdybbB8T95Io+U6kBxT DZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429756; x=1725034556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s8trhKgXPl0k8p/Xs8doNH3rTsnqbgyAarZYQgKSCEM=; b=EDu+PdfwxX/7VTOxNVHX1PbEPGD9H6J45nm1UwgcWulLlsu9uXx5ViI8afQ4BRnrrm B0W1UTRB7lgExho1AZxZC1mi9HPfj6T1NOoK7mk45tcyF9ZnGSuEuuQwmEZxfwknWeH8 n43sh6W49M7x+2orrrkOM8suuWGIXgY7mtOOVW04z6JmQC/0NcdKD0brHXRxfJKe2cYf Ze0I82nQSbSLPiQqCE3yyk8Aws/gXQroRf4QMRyLmc3JQ9zSaxm67DZwl6+z/N8AkpF5 QWbXZN2p59LIzFeo3r/UCQialOApQlNM7kblupgpePiBukMS2b0UPqOn3UoE4PUh6M8K Wrjw== X-Gm-Message-State: AOJu0Yx32u9mmqEA6W84G7GBqaH4lseyADoFLIxwWhzAhWyBjgCxhz0r wYrcmdNTiIh4LnSijJVYKBcsmsoY0SjWG1Yb0vUoDIaZ7g40xvyWZ0GPSA== X-Google-Smtp-Source: AGHT+IH50q6kkz5e66+P+GkDtzkTUFBc7xWB1GB9JoOjUjuJBcqRcDvXo54s1fqoxouoBoAUNoR72A== X-Received: by 2002:a05:6820:820:b0:5da:9ef9:55c5 with SMTP id 006d021491bc7-5dcc5d51d14mr2801504eaf.0.1724429755996; Fri, 23 Aug 2024 09:15:55 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:55 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/6] unit: Use the new l_netlink_attr API Date: Fri, 23 Aug 2024 11:15:46 -0500 Message-ID: <20240823161553.479576-2-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240823161553.479576-1-denkenz@gmail.com> References: <20240823161553.479576-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- unit/test-netlink.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/unit/test-netlink.c b/unit/test-netlink.c index da23ee5c9b0e..113d735adf40 100644 --- a/unit/test-netlink.c +++ b/unit/test-netlink.c @@ -27,31 +27,34 @@ static void getlink_callback(int error, uint16_t type, const void *data, uint32_t len, void *user_data) { const struct ifinfomsg *ifi = data; - struct rtattr *rta; - int bytes; + struct l_netlink_attr attr; char ifname[IF_NAMESIZE]; uint32_t index, flags; + uint16_t rta_type; + uint16_t rta_len; + const void *rta_data; if (error) goto done; - bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg)); + if (l_netlink_attr_init(&attr, sizeof(struct ifinfomsg), data, len) < 0) + goto done; memset(ifname, 0, sizeof(ifname)); - index = ifi->ifi_index; - flags = ifi->ifi_flags; + while (!l_netlink_attr_next(&attr, &rta_type, &rta_len, &rta_data)) { + if (rta_type != IFLA_IFNAME) + continue; + + if (rta_len <= IF_NAMESIZE) + strcpy(ifname, rta_data); - for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes); - rta = RTA_NEXT(rta, bytes)) { - switch (rta->rta_type) { - case IFLA_IFNAME: - if (RTA_PAYLOAD(rta) <= IF_NAMESIZE) - strcpy(ifname, RTA_DATA(rta)); - break; - } + break; } + index = ifi->ifi_index; + flags = ifi->ifi_flags; + l_info("index=%d flags=0x%08x name=%s", index, flags, ifname); done: From patchwork Fri Aug 23 16:15:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775492 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7F3318BC2E for ; Fri, 23 Aug 2024 16:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429759; cv=none; b=YGRODqpclANRE7ixBflQoq9G8R7K2ukVziijwCeXLpC6u9zOt0EpF1/ddopFYoxefeVjEbbxuhPJIUOTL/k/YNeqLZXDEZvC7dWkdraDdYMXogwBRXvhUHZ8cnmWYcRh4hBCg3VERWZangYibp02LK4wiU/uzq74SJhUEkQ4q2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429759; c=relaxed/simple; bh=54KVPL2jbEaF7pVSk0BT+5BpPNnmujeRsM+hi2JHpQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iZJroMYkLKoum3et5WKsrrrgVI7nuRGkOYyq3+IyRnEVm6s6Rc76Pi+dNSXFI8TL553DS9CkJgJsAzyBfl5INtKXDL5YCzgbjoJQY8aOB3yjl0G+ekj8aVZbhJpW3ASHELSQJsTBER5uA1lKaCp0F/GetPrP9S75Xt3Kq9opJ8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aWQEK63b; arc=none smtp.client-ip=209.85.161.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aWQEK63b" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5d5e1c86b83so1697702eaf.3 for ; Fri, 23 Aug 2024 09:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429757; x=1725034557; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=caLvEP4uqOkSjUVG14X4mzjxCuPiPLM9F/FntgMV0ho=; b=aWQEK63bVnNDsGBrxsnhfrOgFSj19ZMNjSgBRdrh2zQ9uIsz+fZpbVszujtjm6CsAN WrUTnmKLrJp1iDN2EJys1VRZm10WOufFGq0HNetM+i4ZuzJ7rh8VI+lSyW4EkWEKse72 BkDrmsUXv6bg49KJ6CWRs8Lchx7QUn23mwg0Ye9YCS10FaoEwGiASGUcomnVFVyctpJW kqYWxfdlJ1yo3YRACLOLpEhYOoSW5eRXNwhjF8T/XW85tMqgsZ2eRgKVNpAsaZK6s8eW 7ZmncgYS3mrr78fBYMqFrJmAv0OCfHqqSws/SNXLMCJKHS+ZcDDHIrAi+0dPmJOKNToq mcrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429757; x=1725034557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=caLvEP4uqOkSjUVG14X4mzjxCuPiPLM9F/FntgMV0ho=; b=AnUGwDIy7Eza4beZdh62FS8i5Nmbz/gxNqa+EF+E9PkXar0s3nd7sKQlmCUN3vfjR0 4qUz7LuGxtk5+PFSEcvlgGEvtIIPJVudVr5Fx82zlVkmHgEtwPLBOchCHLdd880HpU4z j3v4MkzIx4E4Ik7/QyOMptqoBAOjQXPAuOhg+Teoa7YEikUZj44JpSCbxdaKnA/l3+MI rdmwBYUudzV6roJ6Du3V/6bfILqdJHm5V9WPc0CuhV2SLVNLW8QMx9LMLO32Qt3iZRnU RxLblxFOiU87illfZVngOPtVNw3NWUr7STq+fPa92/oFUM2Xtj9i8tNjf4j1dFF2zfmw XcMA== X-Gm-Message-State: AOJu0Yyjrs5ywpqABPYh1AjfqptyXC9DBzRBsRjXL11ppVZAjMoRIQh1 mvlvHih3anYyaCLpnCzHJCSZL1k5LLzq3IMOSLBzQBMZnzOBNAV0QujDZA== X-Google-Smtp-Source: AGHT+IFyxcVqIHep68mVCObySLM0nQEG8Jvfkqb6FjQy59jdsDysLl2khtgvcm560pzt/ZB5m4arUQ== X-Received: by 2002:a05:6820:1607:b0:5da:b29a:3c84 with SMTP id 006d021491bc7-5dcc625a882mr3102674eaf.5.1724429756771; Fri, 23 Aug 2024 09:15:56 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:56 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 3/6] netlink: Add l_netlink_message_append_string Date: Fri, 23 Aug 2024 11:15:47 -0500 Message-ID: <20240823161553.479576-3-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240823161553.479576-1-denkenz@gmail.com> References: <20240823161553.479576-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- ell/netlink.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ell/netlink.h b/ell/netlink.h index f09d42043675..b51748195ca6 100644 --- a/ell/netlink.h +++ b/ell/netlink.h @@ -10,6 +10,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -119,6 +120,14 @@ static inline int l_netlink_message_append_mac(struct l_netlink_message *message return l_netlink_message_append(message, type, mac, 6); } +static inline int l_netlink_message_append_string( + struct l_netlink_message *message, + uint16_t type, + const char *str) +{ + return l_netlink_message_append(message, type, str, strlen(str) + 1); +} + struct l_netlink_attr { const struct nlattr *data; uint32_t len; From patchwork Fri Aug 23 16:15:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775493 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADB6018BC2B for ; Fri, 23 Aug 2024 16:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429760; cv=none; b=pY3MMvde/YrlpknRxIAKaoFklGmYe+vHLXmu5Yvo03CqmyAEoyEKEjMlWPDbs1bCPd9Kh+ZzEJZYz0ak2THM4V51mZW32ksKl5Ney4aau0vg9PYFSD8mUaiRhqdmZj4oYrwtjcx76iH6I8J/N7RWSRpq00TAVFGfZvG0p5ShOuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429760; c=relaxed/simple; bh=S2f4P1wGYdCEeQHUgjA11esFgqPd0ov/6ItqVytAk58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gVr8LlPimA4/KIMU52iEAZ4ASgEL4cmGfUYKsQuWXoDJqeCkciashmwN8716r0ZIqPdgD+Ivu1fybs8h2qvp6bvbrBrrqtmn2/NpLlIMSisE1QWeBzNsSHwfm57ETicgfgLwcdvlZZ1JSRNHWGmOOOJHTK2AThu3Xl7Y0RfaPrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lJu3OVDg; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lJu3OVDg" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5d5f9d68805so1489823eaf.3 for ; Fri, 23 Aug 2024 09:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429757; x=1725034557; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4w7wyimAVYwCR9+Zgwizb3qWELx/lJyhNxXQhOkG29k=; b=lJu3OVDgpdBD/Nl2QdiLbReO+bo0pYlQTWHSbUorHq9hy2q/D78JcBLFnUU3Vlzw4H TCH2zZynwTODSeOKlUXCY9g/iKNujMUm6TD0QkETkyriJTNKKhM2ZZqwgSuB11z9WdK3 BFBDLCtD032ACT3HbxY2qu+ydqinfFl6zvTAT09TvG7mdQduwnmdDVjLNRQf80QSQqea 3/kpJ1nyrWxz+8h2dMf9Fgnjtll3+LoEkW74cpCvhL3zd/uHQmaqnGmYrlH+LnwvpE8A SMw+WbbYm4Bskm7V9ciBHcJM1Vfd/sTSgJxKyidYddQvy+QP7FVoqi/TlIQWOA/kKnVn VOTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429757; x=1725034557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4w7wyimAVYwCR9+Zgwizb3qWELx/lJyhNxXQhOkG29k=; b=ZY4ObfL4DKvdnhQ+7JHl+RhzzUm8unMZoBiZdq57eg1Gw/LgqI68m6BgQgagHWdDbm +3zPqYfW56l3YzPpGglAvMw7cfQnY1FXiIGh4l8nfhE92PrVZQ9cugbDNLMuIzUcVypV J8D4xQplt0DNSDOBYyyTObbcZxOnsmbO144YgSTixDrW+kA/YpQ1vbFXcXDLprlhk0ai 6FLIZfGvrsnAj/5eLrCK0shzfVa6U/U/jVubbxfp/QsYdyxoNEhx5QtGKbC0m6OQuxS7 6PQSvz/cSgKv7cd23WThG+rnxluNkPzavjudkU6y+xr7b7pnu9h/UDYg+TD1DyLRix9Z iTAg== X-Gm-Message-State: AOJu0YzxeqrfEf1BDL7sGAqtDZzeZcTfJhxrZXGxjQeeFmAU4Gk9S5S3 0NO0Ep8n95vnoPJBH7dJ56HmXABr8DPZq3P12RkZeLfMOrPjXCOSecDdyw== X-Google-Smtp-Source: AGHT+IEpPDoFycGWvYGu5/WNDmHMjtrz0+ooomdX4bdTJSxR8NcnR1sTv/L9TYINqrAMZH3dz0Y8Xw== X-Received: by 2002:a05:6820:1e12:b0:5da:b554:b84c with SMTP id 006d021491bc7-5dcc625d655mr2490614eaf.5.1724429757459; Fri, 23 Aug 2024 09:15:57 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:57 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 4/6] netlink: Add l_netlink_request_sent Date: Fri, 23 Aug 2024 11:15:48 -0500 Message-ID: <20240823161553.479576-4-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240823161553.479576-1-denkenz@gmail.com> References: <20240823161553.479576-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is similar to l_genl_family_request_sent() --- ell/ell.sym | 1 + ell/netlink.c | 18 ++++++++++++++++++ ell/netlink.h | 1 + 3 files changed, 20 insertions(+) diff --git a/ell/ell.sym b/ell/ell.sym index 1499081cb25e..cbeb61ff0f46 100644 --- a/ell/ell.sym +++ b/ell/ell.sym @@ -431,6 +431,7 @@ global: l_netlink_destroy; l_netlink_send; l_netlink_cancel; + l_netlink_request_sent; l_netlink_register; l_netlink_unregister; l_netlink_set_debug; diff --git a/ell/netlink.c b/ell/netlink.c index 0be3009c736f..7e6ef0f760e7 100644 --- a/ell/netlink.c +++ b/ell/netlink.c @@ -467,6 +467,24 @@ LIB_EXPORT bool l_netlink_cancel(struct l_netlink *netlink, unsigned int id) return true; } +LIB_EXPORT bool l_netlink_request_sent(struct l_netlink *netlink, + unsigned int id) +{ + struct command *command; + struct nlmsghdr *hdr; + + if (unlikely(!netlink || !id)) + return false; + + command = l_hashmap_lookup(netlink->command_lookup, L_UINT_TO_PTR(id)); + if (!command) + return false; + + hdr = command->message->hdr; + return l_hashmap_lookup(netlink->command_pending, + L_UINT_TO_PTR(hdr->nlmsg_seq)); +} + static bool add_membership(struct l_netlink *netlink, uint32_t group) { int sk, value = group; diff --git a/ell/netlink.h b/ell/netlink.h index b51748195ca6..368f38619155 100644 --- a/ell/netlink.h +++ b/ell/netlink.h @@ -37,6 +37,7 @@ unsigned int l_netlink_send(struct l_netlink *netlink, void *user_data, l_netlink_destroy_func_t destroy); bool l_netlink_cancel(struct l_netlink *netlink, unsigned int id); +bool l_netlink_request_sent(struct l_netlink *netlink, unsigned int id); unsigned int l_netlink_register(struct l_netlink *netlink, uint32_t group, l_netlink_notify_func_t function, From patchwork Fri Aug 23 16:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775494 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FDF9189B8A for ; Fri, 23 Aug 2024 16:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429760; cv=none; b=Dpnp+vlSN4/++b7IYr2W5w55pL229oYWPKCAGXiJb6m1Btco9cLlem7SCirVStZUGvkngh2GYvhcw2iD4B8nDZfUSqpFqraekf6W1jhnZATbAQ/iQs92FRiQxbrdVlZWZGm4s8x8zfrxVOjVibMgLi0BGPb6tVDcA9Ixf3C/K00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429760; c=relaxed/simple; bh=BV7SeL2/B5lex2MVj42aZr2pI1JPqv+Tuah8jEOjo5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EWseYyMlAGmJcbu+UgB8Fx81UtREvRRAHZ/Q6L0cVFK5iODb2VhFO2Y/yjMs54HnZ7oSsdHW+dd01y95bzmhHax/XM7dvBQ+o4JfoIsnXyZQ2cTJqg51u4+DsfLpu8lT8HnsikxIGHRmMvFX1N/esRF66OnqJIuPR+hFqsQ17Bs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PHpS2NkA; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PHpS2NkA" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5dccc6cdc96so433326eaf.0 for ; Fri, 23 Aug 2024 09:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429758; x=1725034558; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0V77cBuCb4zBLJXH7bpBm49sAAKt6Rv6W1Gs1Jg7D50=; b=PHpS2NkAJhlNKaNIiilEh5NcbTPoyCjK+O6/p9oBcmMTXUfCA+gWgaW9og1SnlmvQi DcxxY0Ro2KrsgX+3vE3qKSZ+Oew1aAVOH6pdlFS1Dn2VMYnSRlFJP4UWFE/2T+wMCZmx bz9iJNNSMNCMpZ8mKj4UluzcUmiGP6Hsh/QQZCzVzwYmzvftv5G8yjplvGYwlaIbXUph u/IASQySd4t/3LO3VJ9JUdJ5v1gvOPvUoC+mqAal1CGi87vfUFc2rWq0Dapp/0vVSTwt MaWUM9b1LEYBQLNEGA5pNNWYS9YkwK5uQyiQ9ZTemGNlRFwe3M+1Xp4z+nCNpDOO4P6V USGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429758; x=1725034558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0V77cBuCb4zBLJXH7bpBm49sAAKt6Rv6W1Gs1Jg7D50=; b=NNhsmkMuIOPXGoOfDYx8Ag8Pf/NqYifllKLLJ3W7zPafcQiEKYd4XxZOZNWNUspXF3 3j9Z0EFDYZhKyqmzqbBUtETg/UwSHBw0ufp/kQjSLHgZBvz8ASBQAl1aP3or7PiAdAMR cE3Prhj9BuQsMiXnKmSmF5uc6AeMAgEI++m03lbgoSX0r4/+ljrhXcLrm8x8jKRUP4hT HwKxDB4arHWvFzeT759h4Eua/hyHZP5+3DDbUQ1H/v/9zs3ilFG5Di2OWHpf/FN3xgwV qdpGrmuuFFcgavQyR7KiRg3RZbhaRvVLEaFlzfy3K1VbUx8xefnLtjHXri9hU7P+JUWz FQDg== X-Gm-Message-State: AOJu0Yw1DF8tik8+B2grX3RedacgNjq7ZHe0l/oyUw8IGHGY3AGEfWpp MR8k1Vt0C8LYzJuKL8lXrhJuXdDOVJbul7GFTXRT7oS7YnrGxngX5t/qSg== X-Google-Smtp-Source: AGHT+IHLgE4Ih/7qMt/BEdJwKNKXrFG6n6/P5/kv+Ldo6Fda/BbC2wciEkT4RZb1z2MA4mYlUM8qxg== X-Received: by 2002:a05:6820:1ac6:b0:5c9:d9db:6a51 with SMTP id 006d021491bc7-5dcc5b67513mr3137200eaf.0.1724429758249; Fri, 23 Aug 2024 09:15:58 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:57 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 5/6] util: Handle NULL pointers in l_safe_ato* functions Date: Fri, 23 Aug 2024 11:15:49 -0500 Message-ID: <20240823161553.479576-5-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240823161553.479576-1-denkenz@gmail.com> References: <20240823161553.479576-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- ell/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ell/util.c b/ell/util.c index 45ec6c8110bc..f474098c082b 100644 --- a/ell/util.c +++ b/ell/util.c @@ -760,6 +760,9 @@ static int safe_atou(const char *s, int base, unsigned int *out_u) LIB_EXPORT int l_safe_atou32(const char *s, uint32_t *out_u) { + if (unlikely(!s)) + return -EINVAL; + if (!l_ascii_isdigit(s[0])) return -EINVAL; @@ -808,6 +811,9 @@ LIB_EXPORT int l_safe_atox16(const char *s, uint16_t *out_x) LIB_EXPORT int l_safe_atox32(const char *s, uint32_t *out_x) { + if (unlikely(!s)) + return -EINVAL; + if (!l_ascii_isxdigit(s[0])) return -EINVAL; From patchwork Fri Aug 23 16:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13775495 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD8DC191477 for ; Fri, 23 Aug 2024 16:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429761; cv=none; b=Kgys5rZ1RKGvGAt84DgqQEZkBuBPdaNlpTLaZrmmO17AyZ8ttcHriiJv/a56xjIb2RBYIVQmCJ0i8YWXlMTqrV/SSv7sw9IbvaeHoQSVU1AHDDRPey0YAW6PP51cVKR51S3JaJMvNlQJG15Nfje2mT+jIiOp6ciJRJcflHZx2TI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724429761; c=relaxed/simple; bh=7kqYP2QTb/vILsf7TDrEhKFkBFqpUyHLVlGdxwFFlgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t594B+F/NJK1G5W0fD87OQ+FvqjdwU5MrvKLr/uq1jVQd7gcRxKFjljg3soVEYnl3+UdmbpB6shtAD2mQEfl7awjCS28DELLm2OGMPnk01cs/4K8IX7CGkAfbRG1aifMYCB/SkO0+myAHI5+Dp2ugmRcIHf2IFPfrufV8uY6Ep0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cMUNXj05; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cMUNXj05" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5dca9cc71b2so1520567eaf.2 for ; Fri, 23 Aug 2024 09:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724429759; x=1725034559; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W37T93nQYjVhwPsq2wKL7gb2Ey+ez8DgaYMWL7GgPUA=; b=cMUNXj05JQLljo4Yrh3h53zTVSO0qd73N0xydLZdaDpfDQ/O8vb+VqrhAg6M/v9qFE 1LmvPXr5v4mjLigYxqbAdZ8+AVIXlHHHjU7jnt+CfdYbLB4rzU17ZEHL/bqZTGVXPhtl j544xgxnAlr9jwBdmG3RJeHQFSA/bZaQ8QBdT8BJwddWj6O/dpXCOFZ4k460dZhmqFBo CZ33yikpu6DBQWBJCJB4C0LP2VvYXiLBc/IMhry0ZO8/3cR2Ejh+6b6fbh3QwJ8ppa1Z rjdkORteSsZnrB2bv6DVKAyWpW6jI9TPvay4HoA0MUMRCVVvrPcVaI49KmUyUKO2DXvr bEiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724429759; x=1725034559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W37T93nQYjVhwPsq2wKL7gb2Ey+ez8DgaYMWL7GgPUA=; b=MP6Rxno7f8tcPbI4KhtEw6Y1cmnJjpMU/9aJfjZUjQLLJh3aIJmHOtEIRjwgcPgZcR EHCTlnvhia/VeHwfN/Wih5FFRkcJ+5L4qFnAgeVcDmXN7gknGWDHMBW226q8OZ71py5X s8CvufMo0rvp8MFb1hEMtZWc3xRZcztg2iaDRlpmavDTBnLbK03/CUg4gLW5zs/2BTIm rVmv6suILR4gz4kps5TyVfq5h9BGFc1GtHYPj/f8DNlpTjAdU6YrZ8gCyQYIVnnqq82b b/CiBJBjDq6DCs84NJWBb5Js1RwNE5PLaFUwdaWsFyQ5cRWd9GGrwxGF37qFgMTlcZHs 9EGA== X-Gm-Message-State: AOJu0YxThfHbQWBFhOQAYP7+7bHOYXi9m1gWMeP+cN6Tfn1aPQccdkEL /nxCujEl6DgDElnUqGnwSbx72grE6fHhPG4TTvGKvCLg0kLsLhaaKsOG3Q== X-Google-Smtp-Source: AGHT+IGvygxjyJwYhwtyp1mg4dM8UYwSlPy2Qr5yPz7DYLhUsC/t1Dab8Ad1cAv57ig4nztikjTotQ== X-Received: by 2002:a05:6820:1b93:b0:5da:9204:6733 with SMTP id 006d021491bc7-5dcc6214954mr2858204eaf.3.1724429758920; Fri, 23 Aug 2024 09:15:58 -0700 (PDT) Received: from archdev.attlocal.net (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dcb5de7c83sm750222eaf.14.2024.08.23.09.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:15:58 -0700 (PDT) From: Denis Kenzior To: ell@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 6/6] rtnl: Add l_rtnl_link_set_mtu Date: Fri, 23 Aug 2024 11:15:50 -0500 Message-ID: <20240823161553.479576-6-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240823161553.479576-1-denkenz@gmail.com> References: <20240823161553.479576-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ell@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This helper is used to set a given MTU on a network interface (link). --- ell/ell.sym | 1 + ell/rtnl.c | 18 ++++++++++++++++++ ell/rtnl.h | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/ell/ell.sym b/ell/ell.sym index cbeb61ff0f46..00123136a527 100644 --- a/ell/ell.sym +++ b/ell/ell.sym @@ -701,6 +701,7 @@ global: l_rtnl_set_linkmode_and_operstate; l_rtnl_set_mac; l_rtnl_set_powered; + l_rtnl_link_set_mtu; l_rtnl_ifaddr4_extract; l_rtnl_ifaddr4_dump; l_rtnl_ifaddr4_add; diff --git a/ell/rtnl.c b/ell/rtnl.c index da5d219feb48..fbad795949be 100644 --- a/ell/rtnl.c +++ b/ell/rtnl.c @@ -787,6 +787,24 @@ LIB_EXPORT uint32_t l_rtnl_set_powered(struct l_netlink *rtnl, int ifindex, return l_netlink_send(rtnl, nlm, cb, user_data, destroy); } +LIB_EXPORT uint32_t l_rtnl_link_set_mtu(struct l_netlink *rtnl, int ifindex, + uint32_t mtu, + l_netlink_command_func_t cb, void *user_data, + l_netlink_destroy_func_t destroy) +{ + struct l_netlink_message *nlm = l_netlink_message_new(RTM_SETLINK, 0); + struct ifinfomsg ifi; + + memset(&ifi, 0, sizeof(ifi)); + ifi.ifi_family = AF_UNSPEC; + ifi.ifi_index = ifindex; + + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); + l_netlink_message_append_u32(nlm, IFLA_MTU, mtu); + + return l_netlink_send(rtnl, nlm, cb, user_data, destroy); +} + LIB_EXPORT void l_rtnl_ifaddr4_extract(const struct ifaddrmsg *ifa, int bytes, char **label, char **ip, char **broadcast) { diff --git a/ell/rtnl.h b/ell/rtnl.h index fa5d99eb4b53..d44cda24d6fd 100644 --- a/ell/rtnl.h +++ b/ell/rtnl.h @@ -103,6 +103,10 @@ uint32_t l_rtnl_set_powered(struct l_netlink *rtnl, int ifindex, bool powered, l_netlink_command_func_t cb, void *user_data, l_netlink_destroy_func_t destroy); +uint32_t l_rtnl_link_set_mtu(struct l_netlink *rtnl, int ifindex, uint32_t mtu, + l_netlink_command_func_t cb, void *user_data, + l_netlink_destroy_func_t destroy); + void l_rtnl_ifaddr4_extract(const struct ifaddrmsg *ifa, int bytes, char **label, char **ip, char **broadcast); uint32_t l_rtnl_ifaddr4_dump(struct l_netlink *rtnl, l_netlink_command_func_t cb,