diff --git a/sys/net/if.c b/sys/net/if.c --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1857,8 +1857,18 @@ void ifa_ref(struct ifaddr *ifa) { + u_int old; - refcount_acquire(&ifa->ifa_refcnt); + old = refcount_acquire(&ifa->ifa_refcnt); + KASSERT(old > 0, ("%s: ifa %p has 0 refs", __func__, ifa)); +} + +int +ifa_try_ref(struct ifaddr *ifa) +{ + + NET_EPOCH_ASSERT(); + return (refcount_acquire_if_not_zero(&ifa->ifa_refcnt)); } static void diff --git a/sys/net/if_var.h b/sys/net/if_var.h --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -577,6 +577,7 @@ struct ifaddr * ifa_alloc(size_t size, int flags); void ifa_free(struct ifaddr *ifa); void ifa_ref(struct ifaddr *ifa); +int ifa_try_ref(struct ifaddr *ifa); /* * Multicast address structure. This is analogous to the ifaddr