Module Name: src Committed By: yamaguchi Date: Thu Jun 14 07:44:31 UTC 2018
Modified Files: src/sys/net: if_ether.h Log Message: Replace macros related to multicast address with inline functions ok ozaki-r@ To generate a diff of this commit: cvs rdiff -u -r1.73 -r1.74 src/sys/net/if_ether.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_ether.h diff -u src/sys/net/if_ether.h:1.73 src/sys/net/if_ether.h:1.74 --- src/sys/net/if_ether.h:1.73 Thu Jun 14 07:39:16 2018 +++ src/sys/net/if_ether.h Thu Jun 14 07:44:31 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ether.h,v 1.73 2018/06/14 07:39:16 yamaguchi Exp $ */ +/* $NetBSD: if_ether.h,v 1.74 2018/06/14 07:44:31 yamaguchi Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -247,46 +247,71 @@ struct ether_multistep { }; /* - * Macro for looking up the ether_multi record for a given range of Ethernet - * multicast addresses connected to a given ethercom structure. If no matching - * record is found, "enm" returns NULL. - */ + * lookup the ether_multi record for a given range of Ethernet + * multicast addresses connected to a given ethercom structure. + * If no matching record is found, NULL is returned. + */ +static __inline struct ether_multi * +ether_lookup_multi(const uint8_t *addrlo, const uint8_t *addrhi, + const struct ethercom *ec) +{ + struct ether_multi *enm; + + LIST_FOREACH(enm, &ec->ec_multiaddrs, enm_list) { + if (memcmp(enm->enm_addrlo, addrlo, ETHER_ADDR_LEN) != 0) + continue; + if (memcmp(enm->enm_addrhi, addrhi, ETHER_ADDR_LEN) != 0) + continue; + + break; + } + + return enm; +} #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ec, enm) \ /* uint8_t addrlo[ETHER_ADDR_LEN]; */ \ /* uint8_t addrhi[ETHER_ADDR_LEN]; */ \ /* struct ethercom *ec; */ \ /* struct ether_multi *enm; */ \ -{ \ - for ((enm) = LIST_FIRST(&(ec)->ec_multiaddrs); \ - (enm) != NULL && \ - (memcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \ - memcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \ - (enm) = LIST_NEXT((enm), enm_list)); \ -} + (enm) = ether_lookup_multi((addrlo), (addrhi), (ec)) /* - * Macro to step through all of the ether_multi records, one at a time. + * step through all of the ether_multi records, one at a time. * The current position is remembered in "step", which the caller must - * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step" - * and get the first record. Both macros return a NULL "enm" when there + * provide. ether_first_multi(), below, must be called to initialize "step" + * and get the first record. Both functions return a NULL when there * are no remaining records. */ +static __inline struct ether_multi * +ether_next_multi(struct ether_multistep *step) +{ + struct ether_multi *enm; + + enm = step->e_enm; + if (enm != NULL) + step->e_enm = LIST_NEXT(enm, enm_list); + + return enm; +} #define ETHER_NEXT_MULTI(step, enm) \ /* struct ether_multistep step; */ \ /* struct ether_multi *enm; */ \ -{ \ - if (((enm) = (step).e_enm) != NULL) \ - (step).e_enm = LIST_NEXT((enm), enm_list); \ + (enm) = ether_next_multi(&(step)) + +static __inline struct ether_multi * +ether_first_multi(struct ether_multistep *step, const struct ethercom *ec) +{ + + step->e_enm = LIST_FIRST(&ec->ec_multiaddrs); + + return ether_next_multi(step); } #define ETHER_FIRST_MULTI(step, ec, enm) \ /* struct ether_multistep step; */ \ /* struct ethercom *ec; */ \ /* struct ether_multi *enm; */ \ -{ \ - (step).e_enm = LIST_FIRST(&(ec)->ec_multiaddrs); \ - ETHER_NEXT_MULTI((step), (enm)); \ -} + (enm) = ether_first_multi(&(step), (ec)) #define ETHER_LOCK(ec) mutex_enter((ec)->ec_lock) #define ETHER_UNLOCK(ec) mutex_exit((ec)->ec_lock)