From: Zbigniew Jędrzejewski-Szmek Date: Fri, 26 Nov 2021 10:59:53 +0000 (+0100) Subject: networkd: replace a table with log2 fields by a list X-Git-Tag: v250-rc1~125^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7396e014844614b11458866da6e7e0a4e8804a60;p=thirdparty%2Fsystemd.git networkd: replace a table with log2 fields by a list --- diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 701bffe5ee3..826b061f24e 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -26,33 +26,30 @@ int address_flags_to_string_alloc(uint32_t flags, int family, char **ret) { _cleanup_free_ char *str = NULL; - static const struct { - uint32_t flag; - const char *name; - } map[] = { - { IFA_F_SECONDARY, "secondary" }, /* This is also called "temporary" for ipv6. */ - { IFA_F_NODAD, "nodad" }, - { IFA_F_OPTIMISTIC, "optimistic" }, - { IFA_F_DADFAILED, "dadfailed" }, - { IFA_F_HOMEADDRESS, "home-address" }, - { IFA_F_DEPRECATED, "deprecated" }, - { IFA_F_TENTATIVE, "tentative" }, - { IFA_F_PERMANENT, "permanent" }, - { IFA_F_MANAGETEMPADDR, "manage-temporary-address" }, - { IFA_F_NOPREFIXROUTE, "no-prefixroute" }, - { IFA_F_MCAUTOJOIN, "auto-join" }, - { IFA_F_STABLE_PRIVACY, "stable-privacy" }, + static const char* map[] = { + [LOG2U(IFA_F_SECONDARY)] = "secondary", /* This is also called "temporary" for ipv6. */ + [LOG2U(IFA_F_NODAD)] = "nodad", + [LOG2U(IFA_F_OPTIMISTIC)] = "optimistic", + [LOG2U(IFA_F_DADFAILED)] = "dadfailed", + [LOG2U(IFA_F_HOMEADDRESS)] = "home-address", + [LOG2U(IFA_F_DEPRECATED)] = "deprecated", + [LOG2U(IFA_F_TENTATIVE)] = "tentative", + [LOG2U(IFA_F_PERMANENT)] = "permanent", + [LOG2U(IFA_F_MANAGETEMPADDR)] = "manage-temporary-address", + [LOG2U(IFA_F_NOPREFIXROUTE)] = "no-prefixroute", + [LOG2U(IFA_F_MCAUTOJOIN)] = "auto-join", + [LOG2U(IFA_F_STABLE_PRIVACY)] = "stable-privacy", }; assert(IN_SET(family, AF_INET, AF_INET6)); assert(ret); for (size_t i = 0; i < ELEMENTSOF(map); i++) - if (flags & map[i].flag && - !strextend_with_separator( - &str, ",", - map[i].flag == IFA_F_SECONDARY && family == AF_INET6 ? "temporary" : map[i].name)) - return -ENOMEM; + if (FLAGS_SET(flags, 1 << i) && map[i]) + if (!strextend_with_separator( + &str, ",", + family == AF_INET6 && (1 << i) == IFA_F_SECONDARY ? "temporary" : map[i])) + return -ENOMEM; *ret = TAKE_PTR(str); return 0;