LibAliasInit() should allocate memory with M_WAITOK flag. Modify it

and its callers.
This commit is contained in:
Gleb Smirnoff 2011-04-18 20:07:08 +00:00
parent b9ff20ab7e
commit ca47294ddf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=220800
3 changed files with 12 additions and 18 deletions

View File

@ -276,10 +276,6 @@ ng_nat_constructor(node_p node)
/* Init aliasing engine. */
priv->lib = LibAliasInit(NULL);
if (priv->lib == NULL) {
free(priv, M_NETGRAPH);
return (ENOMEM);
}
/* Set same ports on. */
(void )LibAliasSetMode(priv->lib, PKT_ALIAS_SAME_PORTS,

View File

@ -359,28 +359,17 @@ ipfw_nat_cfg(struct sockopt *sopt)
IPFW_WLOCK(chain);
ptr = lookup_nat(&chain->nat, ser_n->id);
if (ptr == NULL) {
IPFW_WUNLOCK(chain);
/* New rule: allocate and init new instance. */
ptr = malloc(sizeof(struct cfg_nat),
M_IPFW, M_NOWAIT | M_ZERO);
if (ptr == NULL) {
IPFW_WUNLOCK(chain);
free(buf, M_IPFW);
return (ENOSPC);
}
ptr = malloc(sizeof(struct cfg_nat), M_IPFW, M_WAITOK | M_ZERO);
ptr->lib = LibAliasInit(NULL);
if (ptr->lib == NULL) {
IPFW_WUNLOCK(chain);
free(ptr, M_IPFW);
free(buf, M_IPFW);
return (EINVAL);
}
LIST_INIT(&ptr->redir_chain);
} else {
/* Entry already present: temporarly unhook it. */
LIST_REMOVE(ptr, _next);
flush_nat_ptrs(chain, ser_n->id);
IPFW_WUNLOCK(chain);
}
IPFW_WUNLOCK(chain);
/*
* Basic nat configuration.
@ -407,6 +396,10 @@ ipfw_nat_cfg(struct sockopt *sopt)
add_redir_spool_cfg(&buf[(sizeof(struct cfg_nat))], ptr);
free(buf, M_IPFW);
IPFW_WLOCK(chain);
/*
* XXXGL race here: another ipfw_nat_cfg() may already inserted
* entry with the same ser_n->id.
*/
LIST_INSERT_HEAD(&chain->nat, ptr, _next);
IPFW_WUNLOCK(chain);
return (0);

View File

@ -2490,9 +2490,14 @@ LibAliasInit(struct libalias *la)
#endif
if (la == NULL) {
#ifdef _KERNEL
#undef malloc /* XXX: ugly */
la = malloc(sizeof *la, M_ALIAS, M_WAITOK | M_ZERO);
#else
la = calloc(sizeof *la, 1);
if (la == NULL)
return (la);
#endif
#ifndef _KERNEL /* kernel cleans up on module unload */
if (LIST_EMPTY(&instancehead))