Make LLTABLE list lock private for if_llatbl.c

Rename lock and macros to reflect that it protects V_lltables list.
This commit is contained in:
Andrey V. Elsukov 2016-10-11 17:41:13 +00:00
parent 9ba323071d
commit 199511bcdd
2 changed files with 20 additions and 23 deletions

View File

@ -66,8 +66,13 @@ static VNET_DEFINE(SLIST_HEAD(, lltable), lltables) =
SLIST_HEAD_INITIALIZER(lltables); SLIST_HEAD_INITIALIZER(lltables);
#define V_lltables VNET(lltables) #define V_lltables VNET(lltables)
struct rwlock lltable_rwlock; static struct rwlock lltable_list_lock;
RW_SYSINIT(lltable_rwlock, &lltable_rwlock, "lltable_rwlock"); RW_SYSINIT(lltable_list_lock, &lltable_list_lock, "lltable_list_lock");
#define LLTABLE_LIST_RLOCK() rw_rlock(&lltable_list_lock)
#define LLTABLE_LIST_RUNLOCK() rw_runlock(&lltable_list_lock)
#define LLTABLE_LIST_WLOCK() rw_wlock(&lltable_list_lock)
#define LLTABLE_LIST_WUNLOCK() rw_wunlock(&lltable_list_lock)
#define LLTABLE_LIST_LOCK_ASSERT() rw_assert(&lltable_list_lock, RA_LOCKED)
static void lltable_unlink(struct lltable *llt); static void lltable_unlink(struct lltable *llt);
static void llentries_unlink(struct lltable *llt, struct llentries *head); static void llentries_unlink(struct lltable *llt, struct llentries *head);
@ -85,7 +90,7 @@ lltable_dump_af(struct lltable *llt, struct sysctl_req *wr)
{ {
int error; int error;
LLTABLE_LOCK_ASSERT(); LLTABLE_LIST_LOCK_ASSERT();
if (llt->llt_ifp->if_flags & IFF_LOOPBACK) if (llt->llt_ifp->if_flags & IFF_LOOPBACK)
return (0); return (0);
@ -108,7 +113,7 @@ lltable_sysctl_dumparp(int af, struct sysctl_req *wr)
struct lltable *llt; struct lltable *llt;
int error = 0; int error = 0;
LLTABLE_RLOCK(); LLTABLE_LIST_RLOCK();
SLIST_FOREACH(llt, &V_lltables, llt_link) { SLIST_FOREACH(llt, &V_lltables, llt_link) {
if (llt->llt_af == af) { if (llt->llt_af == af) {
error = lltable_dump_af(llt, wr); error = lltable_dump_af(llt, wr);
@ -117,7 +122,7 @@ lltable_sysctl_dumparp(int af, struct sysctl_req *wr)
} }
} }
done: done:
LLTABLE_RUNLOCK(); LLTABLE_LIST_RUNLOCK();
return (error); return (error);
} }
@ -531,7 +536,7 @@ lltable_drain(int af)
struct llentry *lle; struct llentry *lle;
register int i; register int i;
LLTABLE_RLOCK(); LLTABLE_LIST_RLOCK();
SLIST_FOREACH(llt, &V_lltables, llt_link) { SLIST_FOREACH(llt, &V_lltables, llt_link) {
if (llt->llt_af != af) if (llt->llt_af != af)
continue; continue;
@ -547,7 +552,7 @@ lltable_drain(int af)
} }
} }
} }
LLTABLE_RUNLOCK(); LLTABLE_LIST_RUNLOCK();
} }
#endif #endif
@ -591,14 +596,14 @@ lltable_prefix_free(int af, struct sockaddr *addr, struct sockaddr *mask,
{ {
struct lltable *llt; struct lltable *llt;
LLTABLE_RLOCK(); LLTABLE_LIST_RLOCK();
SLIST_FOREACH(llt, &V_lltables, llt_link) { SLIST_FOREACH(llt, &V_lltables, llt_link) {
if (llt->llt_af != af) if (llt->llt_af != af)
continue; continue;
llt->llt_prefix_free(llt, addr, mask, flags); llt->llt_prefix_free(llt, addr, mask, flags);
} }
LLTABLE_RUNLOCK(); LLTABLE_LIST_RUNLOCK();
} }
struct lltable * struct lltable *
@ -632,18 +637,18 @@ void
lltable_link(struct lltable *llt) lltable_link(struct lltable *llt)
{ {
LLTABLE_WLOCK(); LLTABLE_LIST_WLOCK();
SLIST_INSERT_HEAD(&V_lltables, llt, llt_link); SLIST_INSERT_HEAD(&V_lltables, llt, llt_link);
LLTABLE_WUNLOCK(); LLTABLE_LIST_WUNLOCK();
} }
static void static void
lltable_unlink(struct lltable *llt) lltable_unlink(struct lltable *llt)
{ {
LLTABLE_WLOCK(); LLTABLE_LIST_WLOCK();
SLIST_REMOVE(&V_lltables, llt, lltable, llt_link); SLIST_REMOVE(&V_lltables, llt, lltable, llt_link);
LLTABLE_WUNLOCK(); LLTABLE_LIST_WUNLOCK();
} }
@ -739,13 +744,13 @@ lla_rt_output(struct rt_msghdr *rtm, struct rt_addrinfo *info)
} }
/* XXX linked list may be too expensive */ /* XXX linked list may be too expensive */
LLTABLE_RLOCK(); LLTABLE_LIST_RLOCK();
SLIST_FOREACH(llt, &V_lltables, llt_link) { SLIST_FOREACH(llt, &V_lltables, llt_link) {
if (llt->llt_af == dst->sa_family && if (llt->llt_af == dst->sa_family &&
llt->llt_ifp == ifp) llt->llt_ifp == ifp)
break; break;
} }
LLTABLE_RUNLOCK(); LLTABLE_LIST_RUNLOCK();
KASSERT(llt != NULL, ("Yep, ugly hacks are bad\n")); KASSERT(llt != NULL, ("Yep, ugly hacks are bad\n"));
error = 0; error = 0;

View File

@ -37,17 +37,9 @@ struct ifnet;
struct sysctl_req; struct sysctl_req;
struct rt_msghdr; struct rt_msghdr;
struct rt_addrinfo; struct rt_addrinfo;
struct llentry; struct llentry;
LIST_HEAD(llentries, llentry); LIST_HEAD(llentries, llentry);
extern struct rwlock lltable_rwlock;
#define LLTABLE_RLOCK() rw_rlock(&lltable_rwlock)
#define LLTABLE_RUNLOCK() rw_runlock(&lltable_rwlock)
#define LLTABLE_WLOCK() rw_wlock(&lltable_rwlock)
#define LLTABLE_WUNLOCK() rw_wunlock(&lltable_rwlock)
#define LLTABLE_LOCK_ASSERT() rw_assert(&lltable_rwlock, RA_LOCKED)
#define LLE_MAX_LINKHDR 24 /* Full IB header */ #define LLE_MAX_LINKHDR 24 /* Full IB header */
/* /*
* Code referencing llentry must at least hold * Code referencing llentry must at least hold