Date: Mon, 18 Apr 2011 20:07:08 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r220800 - in head/sys: netgraph netinet/ipfw netinet/libalias Message-ID: <201104182007.p3IK78GW082790@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Mon Apr 18 20:07:08 2011 New Revision: 220800 URL: http://svn.freebsd.org/changeset/base/220800 Log: LibAliasInit() should allocate memory with M_WAITOK flag. Modify it and its callers. Modified: head/sys/netgraph/ng_nat.c head/sys/netinet/ipfw/ip_fw_nat.c head/sys/netinet/libalias/alias_db.c Modified: head/sys/netgraph/ng_nat.c ============================================================================== --- head/sys/netgraph/ng_nat.c Mon Apr 18 19:20:47 2011 (r220799) +++ head/sys/netgraph/ng_nat.c Mon Apr 18 20:07:08 2011 (r220800) @@ -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, Modified: head/sys/netinet/ipfw/ip_fw_nat.c ============================================================================== --- head/sys/netinet/ipfw/ip_fw_nat.c Mon Apr 18 19:20:47 2011 (r220799) +++ head/sys/netinet/ipfw/ip_fw_nat.c Mon Apr 18 20:07:08 2011 (r220800) @@ -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); Modified: head/sys/netinet/libalias/alias_db.c ============================================================================== --- head/sys/netinet/libalias/alias_db.c Mon Apr 18 19:20:47 2011 (r220799) +++ head/sys/netinet/libalias/alias_db.c Mon Apr 18 20:07:08 2011 (r220800) @@ -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))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104182007.p3IK78GW082790>