From f9ef96ca7179b80ae61f9ff76c2f0e49c58345eb Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Fri, 26 Jun 2009 00:36:47 +0000 Subject: [PATCH] Define four wrapper functions for interface address locking, if_addr_rlock() and if_addr_runlock() for regular address lists, and if_maddr_rlock() and if_maddr_runlock() for multicast address lists. We will use these in various kernel modules to avoid encoding specific type and locking strategy information into modules that currently use IF_ADDR_LOCK() and IF_ADDR_UNLOCK() directly. MFC after: 6 weeks --- sys/net/if.c | 34 ++++++++++++++++++++++++++++++++++ sys/net/if_var.h | 10 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 58ab6792cf8f..c41390a07497 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1418,6 +1418,40 @@ if_rtdel(struct radix_node *rn, void *arg) return (0); } +/* + * Wrapper functions for struct ifnet address list locking macros. These are + * used by kernel modules to avoid encoding programming interface or binary + * interface assumptions that may be violated when kernel-internal locking + * approaches change. + */ +void +if_addr_rlock(struct ifnet *ifp) +{ + + IF_ADDR_LOCK(ifp); +} + +void +if_addr_runlock(struct ifnet *ifp) +{ + + IF_ADDR_UNLOCK(ifp); +} + +void +if_maddr_rlock(struct ifnet *ifp) +{ + + IF_ADDR_LOCK(ifp); +} + +void +if_maddr_runlock(struct ifnet *ifp) +{ + + IF_ADDR_UNLOCK(ifp); +} + /* * Reference count functions for ifaddrs. */ diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 35e4232b0a50..df09035f0d7d 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -252,6 +252,16 @@ typedef void if_init_f_t(void *); #define IF_ADDR_UNLOCK(if) mtx_unlock(&(if)->if_addr_mtx) #define IF_ADDR_LOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED) +/* + * Function variations on locking macros intended to be used by loadable + * kernel modules in order to divorce them from the internals of address list + * locking. + */ +void if_addr_rlock(struct ifnet *ifp); /* if_addrhead */ +void if_addr_runlock(struct ifnet *ifp); /* if_addrhead */ +void if_maddr_rlock(struct ifnet *ifp); /* if_multiaddrs */ +void if_maddr_runlock(struct ifnet *ifp); /* if_multiaddrs */ + /* * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) * are queues of messages stored on ifqueue structures