libalias: Serialize updates to the global instance list
libalias maintains a global list of all libalias handles. The list was updated without any locking, but nothing prevents updates from running concurrently. MFC after: 1 week
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <sys/systm.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/stdarg.h>
|
||||
#include <sys/syslog.h>
|
||||
@@ -61,6 +62,10 @@
|
||||
|
||||
#include "alias_db.h"
|
||||
|
||||
#ifdef _KERNEL
|
||||
static struct mtx list_mtx;
|
||||
MTX_SYSINIT(libalias_list, &list_mtx, "libalias list lock", MTX_DEF);
|
||||
#endif
|
||||
static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead);
|
||||
int LibAliasTime;
|
||||
|
||||
@@ -2190,8 +2195,14 @@ LibAliasInit(struct libalias *la)
|
||||
/* kernel cleans up on module unload */
|
||||
if (LIST_EMPTY(&instancehead))
|
||||
atexit(finishoff);
|
||||
#endif
|
||||
#ifdef _KERNEL
|
||||
mtx_lock(&list_mtx);
|
||||
#endif
|
||||
LIST_INSERT_HEAD(&instancehead, la, instancelist);
|
||||
#ifdef _KERNEL
|
||||
mtx_unlock(&list_mtx);
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL
|
||||
LibAliasTime = time_uptime;
|
||||
@@ -2259,8 +2270,14 @@ LibAliasUninit(struct libalias *la)
|
||||
UninitPacketAliasLog(la);
|
||||
#ifndef NO_FW_PUNCH
|
||||
UninitPunchFW(la);
|
||||
#endif
|
||||
#ifdef _KERNEL
|
||||
mtx_lock(&list_mtx);
|
||||
#endif
|
||||
LIST_REMOVE(la, instancelist);
|
||||
#ifdef _KERNEL
|
||||
mtx_unlock(&list_mtx);
|
||||
#endif
|
||||
LIBALIAS_UNLOCK(la);
|
||||
LIBALIAS_LOCK_DESTROY(la);
|
||||
free(la);
|
||||
|
||||
Reference in New Issue
Block a user