Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Replace macros related to multicast address with inl...
details: https://anonhg.NetBSD.org/src/rev/c877b9fb5521
branches: trunk
changeset: 833170:c877b9fb5521
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Thu Jun 14 07:44:31 2018 +0000
description:
Replace macros related to multicast address with inline functions
ok ozaki-r@
diffstat:
sys/net/if_ether.h | 67 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 46 insertions(+), 21 deletions(-)
diffs (101 lines):
diff -r 0aefd1252a8d -r c877b9fb5521 sys/net/if_ether.h
--- a/sys/net/if_ether.h Thu Jun 14 07:39:16 2018 +0000
+++ b/sys/net/if_ether.h Thu Jun 14 07:44:31 2018 +0000
@@ -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 @@
};
/*
- * 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)
Home |
Main Index |
Thread Index |
Old Index