From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next v2 1/4] utils: Introduce and use inet_prefix_reset_flags() Date: Sun, 11 Feb 2018 22:02:30 +0200 Message-ID: <1518379353-31995-2-git-send-email-serhe.popovych@gmail.com> References: <1518379353-31995-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f67.google.com ([209.85.215.67]:41783 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753650AbeBKUCj (ORCPT ); Sun, 11 Feb 2018 15:02:39 -0500 Received: by mail-lf0-f67.google.com with SMTP id f136so17793369lff.8 for ; Sun, 11 Feb 2018 12:02:38 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id s20sm1283327ljd.79.2018.02.11.12.02.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Feb 2018 12:02:36 -0800 (PST) In-Reply-To: <1518379353-31995-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Initializing @inet_prefix using C initializers or memset() seems inefficient and unnecessary: only small part of ->data[] field will be used to store address corresponding to ->family. Instead initialize ->flags with zero and assume no other fields accessed before checking corresponding bits in ->flags. For example special helpers (e.g. is_addrtype_*()) can be used to ensure that @inet_prefix contains valid ip or ipv6 address. Signed-off-by: Serhey Popovych --- include/utils.h | 5 +++++ ip/iplink_geneve.c | 2 +- ip/iplink_vxlan.c | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/utils.h b/include/utils.h index 4dc514d..ccbf353 100644 --- a/include/utils.h +++ b/include/utils.h @@ -65,6 +65,11 @@ enum { ADDRTYPE_INET_MULTI = ADDRTYPE_INET | ADDRTYPE_MULTI }; +static inline void inet_prefix_reset_flags(inet_prefix *p) +{ + p->flags = 0; +} + static inline bool is_addrtype_inet(const inet_prefix *p) { return p->flags & ADDRTYPE_INET; diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index c666072..f90bca6 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -71,7 +71,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, bool set_op = (n->nlmsg_type == RTM_NEWLINK && !(n->nlmsg_flags & NLM_F_CREATE)); - daddr.flags = 0; + inet_prefix_reset_flags(&daddr); while (argc > 0) { if (!matches(*argv, "id") || diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 00875ba..02fdc66 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -74,8 +74,7 @@ static void check_duparg(__u64 *attrs, int type, const char *key, static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { - inet_prefix saddr; - inet_prefix daddr; + inet_prefix saddr, daddr; __u32 vni = 0; __u8 learning = 1; __u16 dstport = 0; @@ -85,7 +84,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, !(n->nlmsg_flags & NLM_F_CREATE)); saddr.family = daddr.family = AF_UNSPEC; - saddr.flags = daddr.flags = 0; + + inet_prefix_reset_flags(&saddr); + inet_prefix_reset_flags(&daddr); while (argc > 0) { if (!matches(*argv, "id") || -- 1.7.10.4