Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2322391pxa; Mon, 24 Aug 2020 10:53:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHvcrEVLWl2ZJhStEINMeF32iA+K0vgCIWIX534kA8MGkyYFH5sbWjWMl+saKF8O/bRFAn X-Received: by 2002:a17:906:5902:: with SMTP id h2mr6962608ejq.423.1598291584898; Mon, 24 Aug 2020 10:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598291584; cv=none; d=google.com; s=arc-20160816; b=b0uYMpKzAOuvYLZKqtnbmoSjSLoCYbnBJQUjmtrY8SVOxauhIXmPXjMzGjeJStYTsJ pyfHVQ5yUcLdLq0LSiXPHy94LZ2A95M7NTcU4IcK75db7D4E9t0r0bGjq+RQlBz3G/zC ukHeH7srcWI/GJ7CLqpU6TLt1h02WxVuGuibIzZfVpwgsJRcFFWm29kiWRedJ5t5oWHr rOltlQjdfwDkGW2Fz8JrRlwNjQVXgZoG7uHSimS0d9KLkezrH5YUa2GbhMsW9tOVxnWJ mkL+sdTch34hRdWN7p2pG38ZFXA/p0w/mXSbxFSm+OSjE/QlbZ0rG2rKKA7UHeOwTlSi Kwrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=cwXNhoOC/etrURLT+3s0J9Bh7cXwdDiltZopj0JYS3g=; b=gjo5mJmC1BSZspsMEWyOMchheVOh9KouhVsYQsQiB3JCPy8xIyEYJkXZQfan3X7uMk cLJUPbqQGNn+zDcegJx+eZxFc3AVEEdt1Vd3enQlVtHewRWJpMCfd/qBuWDa07X231ZB 2qaMV5xEK73Ful38N+88g+Z5NflPEHedOjvzwDXkzySlEc8hLbD38K4ipLltfGw+R3gI 8r4SRG9x2Xok9m9apVGEvF9P/l/M7yH1a4QVDJ5QjlSzY3JPHHZ+txR9k0jAS/vJ8hw1 /dSSfC9wDXTZTArZfIn65HqVV3CyPxTjdQ8fuLJvwDBQ6GQNfyC6GLEBRfJv5+6c8imV wktA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si6780180edb.557.2020.08.24.10.52.37; Mon, 24 Aug 2020 10:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbgHXRvZ (ORCPT + 99 others); Mon, 24 Aug 2020 13:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgHXRvX (ORCPT ); Mon, 24 Aug 2020 13:51:23 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA907C061573; Mon, 24 Aug 2020 10:51:22 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94) (envelope-from ) id 1kAGco-00A1ue-Dy; Mon, 24 Aug 2020 19:51:18 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org, Stephen Hemminger , netdev@vger.kernel.org Cc: David Ahern Subject: [PATCH 1/3] libnetlink: add rtattr_for_each_nested() iteration macro Date: Mon, 24 Aug 2020 19:51:06 +0200 Message-Id: <20200824175108.53101-1-johannes@sipsolutions.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org This is useful for iterating elements in a nested attribute, if they're not parsed with a strict length limit or such. Signed-off-by: Johannes Berg --- include/libnetlink.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/libnetlink.h b/include/libnetlink.h index e27516f7648f..0d4a9f29afbd 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -284,4 +284,9 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, * messages from dump file */ #define NLMSG_TSTAMP 15 +#define rtattr_for_each_nested(attr, nest) \ + for ((attr) = (void *)RTA_DATA(nest); \ + RTA_OK(attr, RTA_PAYLOAD(nest) - ((char *)(attr) - (char *)RTA_DATA((nest)))); \ + (attr) = RTA_TAIL((attr))) + #endif /* __LIBNETLINK_H__ */ -- 2.26.2