From e0750c7a763526bfde077f0ac541021f6aa00746 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 18 May 2021 17:52:26 -0700 Subject: [PATCH] base: Eliminate macros in base/inet.hh|cc. The macro in base/inet.hh, HOME_ADDRESS_OPTION, was not used by anything. The IP6_EXTENSION macro was replaced with a static inline function called ip6Extension. The awkward nested ternary operator was replaced with an equivalent ||. Change-Id: I100894811159b39b964a49c43a09d493d1268739 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45739 Reviewed-by: Daniel Carvalho Maintainer: Gabe Black Tested-by: kokoro --- src/base/inet.cc | 24 +++++++++++++++--------- src/base/inet.hh | 1 - 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/base/inet.cc b/src/base/inet.cc index 7ae36c384e..bc9c51615e 100644 --- a/src/base/inet.cc +++ b/src/base/inet.cc @@ -274,12 +274,18 @@ IpHdr::options(std::vector &vec) const return true; } -#define IP6_EXTENSION(nxt) (nxt == IP_PROTO_HOPOPTS) ? true : \ - (nxt == IP_PROTO_ROUTING) ? true : \ - (nxt == IP_PROTO_FRAGMENT) ? true : \ - (nxt == IP_PROTO_AH) ? true : \ - (nxt == IP_PROTO_ESP) ? true: \ - (nxt == IP_PROTO_DSTOPTS) ? true : false +namespace +{ + +bool +ip6Extension(uint8_t nxt) +{ + return nxt == IP_PROTO_HOPOPTS || nxt == IP_PROTO_ROUTING || + nxt == IP_PROTO_FRAGMENT || nxt == IP_PROTO_AH || + nxt == IP_PROTO_ESP || nxt == IP_PROTO_DSTOPTS; +} + +} // anonymous namespace /* Scan the IP6 header for all header extensions * and return the number of headers found @@ -292,7 +298,7 @@ Ip6Hdr::extensionLength() const int len = 0; int all = plen(); - while (IP6_EXTENSION(nxt)) { + while (ip6Extension(nxt)) { const Ip6Opt *ext = (const Ip6Opt *)data; nxt = ext->nxt(); len += ext->len(); @@ -315,7 +321,7 @@ Ip6Hdr::getExt(uint8_t ext_type) const Ip6Opt* opt = NULL; int all = plen(); - while (IP6_EXTENSION(nxt)) { + while (ip6Extension(nxt)) { opt = (Ip6Opt *)data; if (nxt == ext_type) { break; @@ -340,7 +346,7 @@ Ip6Hdr::proto() const uint8_t nxt = ip6_nxt; int all = plen(); - while (IP6_EXTENSION(nxt)) { + while (ip6Extension(nxt)) { const Ip6Opt *ext = (const Ip6Opt *)data; nxt = ext->nxt(); data += ext->len(); diff --git a/src/base/inet.hh b/src/base/inet.hh index b9c0c1c60a..f0d1f7543f 100644 --- a/src/base/inet.hh +++ b/src/base/inet.hh @@ -565,7 +565,6 @@ struct ip6_opt_routing_type2 ip6_addr_t addr; }; -#define HOME_ADDRESS_OPTION 0xC9 struct GEM5_PACKED ip6_opt_dstopts { uint8_t type;