From: Serhey Popovych Date: Mon, 12 Feb 2018 20:17:56 +0000 (+0200) Subject: utils: Introduce and use inet_prefix_reset() X-Git-Tag: v4.17.0~83^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cc173d4855a279631f91736d83a6005dd4ee5f3;p=thirdparty%2Fiproute2.git utils: Introduce and use inet_prefix_reset() 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 Signed-off-by: David Ahern --- diff --git a/include/utils.h b/include/utils.h index 4dc514d66..867e5404c 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(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 c66607267..1fcdd83ac 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(&daddr); while (argc > 0) { if (!matches(*argv, "id") || diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 00875ba73..d768c07ee 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(&saddr); + inet_prefix_reset(&daddr); while (argc > 0) { if (!matches(*argv, "id") ||