From owner-p4-projects@FreeBSD.ORG Mon Oct 16 21:29:39 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DE22B16A415; Mon, 16 Oct 2006 21:29:38 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9FE6E16A40F for ; Mon, 16 Oct 2006 21:29:38 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6AA2543D49 for ; Mon, 16 Oct 2006 21:29:30 +0000 (GMT) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k9GLTTks086210 for ; Mon, 16 Oct 2006 21:29:29 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k9GLTTAF086207 for perforce@freebsd.org; Mon, 16 Oct 2006 21:29:29 GMT (envelope-from piso@freebsd.org) Date: Mon, 16 Oct 2006 21:29:29 GMT Message-Id: <200610162129.k9GLTTAF086207@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to piso@freebsd.org using -f From: Paolo Pisati To: Perforce Change Reviews Cc: Subject: PERFORCE change 108000 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Oct 2006 21:29:39 -0000 http://perforce.freebsd.org/chv.cgi?CH=108000 Change 108000 by piso@piso_newluxor on 2006/10/16 21:28:34 Move nat locking from private nat_chain_rwl to layer3_chain rwl. Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#21 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#21 (text+ko) ==== @@ -305,20 +305,11 @@ MODULE_DEPEND(ipfw, libalias, 1, 1, 1); -struct rwlock nat_chain_rwl; - -#define NAT_LOCK_INIT(_chain) \ - rw_init(_chain, "NAT instances") -#define NAT_LOCK_DESTROY(_chain) rw_destroy(_chain) -#define NAT_WLOCK_ASSERT(_chain) do { \ - rw_assert(_chain, RA_WLOCKED); \ - NET_ASSERT_GIANT(); \ -} while (0) - -#define NAT_RLOCK(p) rw_rlock(p) -#define NAT_RUNLOCK(p) rw_runlock(p) -#define NAT_WLOCK(p) rw_wlock(p) -#define NAT_WUNLOCK(p) rw_wunlock(p) +#define NAT_WLOCK_ASSERT(_chain) IPFW_WLOCK_ASSERT(_chain) +#define NAT_RLOCK(p) IPFW_RLOCK(p) +#define NAT_RUNLOCK(p) IPFW_RUNLOCK(p) +#define NAT_WLOCK(p) IPFW_WLOCK(p) +#define NAT_WUNLOCK(p) IPFW_WUNLOCK(p) static eventhandler_tag ifaddr_event_tag; @@ -2073,12 +2064,12 @@ } #define HOOK_NAT(b, p) do { \ - NAT_WLOCK_ASSERT(&nat_chain_rwl); \ + NAT_WLOCK_ASSERT(&layer3_chain); \ LIST_INSERT_HEAD(b, p, _next); \ } while (0) #define UNHOOK_NAT(p) do { \ - NAT_WLOCK_ASSERT(&nat_chain_rwl); \ + NAT_WLOCK_ASSERT(&layer3_chain); \ LIST_REMOVE(p, _next); \ } while (0) @@ -3447,12 +3438,12 @@ args->rule = f; /* Report matching rule. */ retval = 0; t = ((ipfw_insn_nat *)cmd)->nat; - NAT_RLOCK(&nat_chain_rwl); + NAT_RLOCK(&layer3_chain); if (t == NULL) { t = lookup_nat(cmd->arg1); if (t == NULL) { retval = IP_FW_DENY; - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); goto done; } else ((ipfw_insn_nat *)cmd)->nat = t; @@ -3518,7 +3509,7 @@ /* XXX - should i add some logging? */ m_free(mcl); badnat: - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); args->m = NULL; retval = IP_FW_DENY; goto done; @@ -3584,7 +3575,7 @@ args->m = mcl; retval = IP_FW_NAT; - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); goto done; } @@ -4319,7 +4310,7 @@ struct cfg_nat *ptr; struct ifaddr *ifa; - NAT_WLOCK(&nat_chain_rwl); + NAT_WLOCK(&layer3_chain); /* Check every nat entry... */ LIST_FOREACH(ptr, &layer3_chain.nat, _next) { /* ...using nic 'ifp->if_xname' as dynamic alias address. */ @@ -4337,7 +4328,7 @@ mtx_unlock(&ifp->if_addr_mtx); } } - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); } /** @@ -4577,21 +4568,21 @@ /* * Find/create nat rule. */ - NAT_WLOCK(&nat_chain_rwl); + NAT_WLOCK(&layer3_chain); ptr = lookup_nat(ser_n->id); if (ptr == NULL) { /* New rule: allocate and init new instance. */ ptr = malloc(sizeof(struct cfg_nat), M_IPFW, M_NOWAIT | M_ZERO); if (ptr == NULL) { free(buf, M_IPFW); - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); return (ENOSPC); } ptr->lib = LibAliasInit(NULL); if (ptr->lib == NULL) { free(ptr, M_IPFW); free(buf, M_IPFW); - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); return(EINVAL); } LIST_INIT(&ptr->redir_chain); @@ -4599,7 +4590,7 @@ UNHOOK_NAT(ptr); flush_nat_ptrs(ser_n->id); } - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); /* * Basic nat configuration. @@ -4623,9 +4614,9 @@ add_redir_spool_cfg(&buf[(sizeof(struct cfg_nat))], ptr); /* Add new entries. */ free(buf, M_IPFW); - NAT_WLOCK(&nat_chain_rwl); + NAT_WLOCK(&layer3_chain); HOOK_NAT(&layer3_chain.nat, ptr); - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); } break; @@ -4635,15 +4626,15 @@ int i; error = sooptcopyin(sopt, &i, sizeof i, sizeof i); - NAT_WLOCK(&nat_chain_rwl); + NAT_WLOCK(&layer3_chain); ptr = lookup_nat(i); if (ptr == NULL) { error = EINVAL; - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); break; } UNHOOK_NAT(ptr); - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); flush_nat_ptrs(i); del_redir_spool_cfg(ptr, &ptr->redir_chain); LibAliasUninit(ptr->lib); @@ -4665,7 +4656,7 @@ data = malloc(NAT_BUF_LEN, M_IPFW, M_NOWAIT | M_ZERO); if (data == NULL) return (ENOSPC); - NAT_RLOCK(&nat_chain_rwl); + NAT_RLOCK(&layer3_chain); /* Serialize all the data. */ LIST_FOREACH(n, &layer3_chain.nat, _next) { nat_cnt++; @@ -4690,12 +4681,12 @@ goto nospace; } bcopy(&nat_cnt, data, sizeof(nat_cnt)); - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); error = sooptcopyout(sopt, data, NAT_BUF_LEN); free(data, M_IPFW); break; nospace: - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); printf("serialized data buffer not big enough: please increase NAT_BUF_LEN\n"); free(data, M_IPFW); } @@ -4708,7 +4699,7 @@ int sof = LIBALIAS_BUF_SIZE; int i, size, cnt = 0; - NAT_RLOCK(&nat_chain_rwl); + NAT_RLOCK(&layer3_chain); size = i = 0; LIST_FOREACH(ptr, &layer3_chain.nat, _next) { if (ptr->lib->logDesc == NULL) @@ -4717,7 +4708,7 @@ size = cnt * (sof + sizeof(int)); data = realloc(data, size, M_IPFW, M_NOWAIT | M_ZERO); if (data == NULL) { - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); return (ENOSPC); } bcopy(&ptr->id, &data[i], sizeof(int)); @@ -4725,7 +4716,7 @@ bcopy(ptr->lib->logDesc, &data[i], sof); i += sof; } - NAT_RUNLOCK(&nat_chain_rwl); + NAT_RUNLOCK(&layer3_chain); error = sooptcopyout(sopt, data, size); free(data, M_IPFW); } @@ -4904,7 +4895,6 @@ ip_fw_chk_ptr = ipfw_chk; callout_reset(&ipfw_timeout, hz, ipfw_tick, NULL); LIST_INIT(&layer3_chain.nat); - NAT_LOCK_INIT(&nat_chain_rwl); ifaddr_event_tag = EVENTHANDLER_REGISTER(ifaddr_event, ifaddr_change, NULL, EVENTHANDLER_PRI_ANY); return (0); @@ -4921,16 +4911,15 @@ callout_drain(&ipfw_timeout); IPFW_WLOCK(&layer3_chain); flush_tables(&layer3_chain); - NAT_WLOCK(&nat_chain_rwl); + NAT_WLOCK(&layer3_chain); LIST_FOREACH_SAFE(ptr, &layer3_chain.nat, _next, ptr_temp) { LIST_REMOVE(ptr, _next); del_redir_spool_cfg(ptr, &ptr->redir_chain); LibAliasUninit(ptr->lib); free(ptr, M_IPFW); } - NAT_WUNLOCK(&nat_chain_rwl); + NAT_WUNLOCK(&layer3_chain); EVENTHANDLER_DEREGISTER(ifaddr_event, ifaddr_event_tag); - NAT_LOCK_DESTROY(&nat_chain_rwl); layer3_chain.reap = NULL; free_chain(&layer3_chain, 1 /* kill default rule */); reap = layer3_chain.reap, layer3_chain.reap = NULL;