Date: Wed, 30 Aug 2006 11:42:34 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 105322 for review Message-ID: <200608301142.k7UBgYx7060877@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=105322 Change 105322 by piso@piso_newluxor on 2006/08/30 11:42:29 Move the nat rwlock outside of nat_chain (in preparation of turning all the lists data structs into LIST macro). Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#8 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#8 (text+ko) ==== @@ -301,23 +301,23 @@ MODULE_DEPEND(ipfw, libalias, 1, 1, 1); +struct rwlock nat_chain_rwl; struct _nat_chain { - struct cfg_nat *chain; - struct rwlock rwl; + struct cfg_nat *chain; } nat_chain; #define NAT_LOCK_INIT(_chain) \ - rw_init(&(_chain)->rwl, "NAT instances") -#define NAT_LOCK_DESTROY(_chain) rw_destroy(&(_chain)->rwl) + rw_init(_chain, "NAT instances") +#define NAT_LOCK_DESTROY(_chain) rw_destroy(_chain) #define NAT_WLOCK_ASSERT(_chain) do { \ - rw_assert(&(_chain)->rwl, RA_WLOCKED); \ + rw_assert(_chain, RA_WLOCKED); \ NET_ASSERT_GIANT(); \ } while (0) -#define NAT_RLOCK(p) rw_rlock(&(p)->rwl) -#define NAT_RUNLOCK(p) rw_runlock(&(p)->rwl) -#define NAT_WLOCK(p) rw_wlock(&(p)->rwl) -#define NAT_WUNLOCK(p) rw_wunlock(&(p)->rwl) +#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) static eventhandler_tag ifaddr_event_tag; @@ -2077,19 +2077,19 @@ static void unhook_entry(struct _chain **b, struct _chain *p) { - NAT_WLOCK_ASSERT(&nat_chain); + NAT_WLOCK_ASSERT(&nat_chain_rwl); for(; *b != p; b = &((*b)->next)) ; *b = p->next; } #define HOOK_NAT(b, p) do { \ - NAT_WLOCK_ASSERT(&nat_chain); \ + NAT_WLOCK_ASSERT(&nat_chain_rwl); \ hook_entry((struct _chain **)b, (struct _chain *)p); \ } while (0) #define UNHOOK_NAT(b, p) do { \ - NAT_WLOCK_ASSERT(&nat_chain); \ + NAT_WLOCK_ASSERT(&nat_chain_rwl); \ unhook_entry((struct _chain **)b, (struct _chain *)p); \ } while (0) @@ -3448,7 +3448,7 @@ retval = 0; t = ((ipfw_insn_nat *)cmd)->nat; if (t == NULL) { - NAT_RLOCK(&nat_chain); + NAT_RLOCK(&nat_chain_rwl); t = lookup_nat(cmd->arg1); if (t == NULL) { retval = IP_FW_DENY; @@ -3582,7 +3582,7 @@ args->m = mcl; retval = IP_FW_NAT; - NAT_RUNLOCK(&nat_chain); + NAT_RUNLOCK(&nat_chain_rwl); goto done; } @@ -4317,7 +4317,7 @@ struct cfg_nat *ptr; struct ifaddr *ifa; - NAT_WLOCK(&nat_chain); + NAT_WLOCK(&nat_chain_rwl); /* Check every nat entry... */ for (ptr = nat_chain.chain; ptr; ptr = ptr->next) { /* ...using nic 'ifp->if_xname' as dynamic alias address. */ @@ -4335,7 +4335,7 @@ mtx_unlock(&ifp->if_addr_mtx); } } - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); } /** @@ -4576,28 +4576,28 @@ /* * Find/create nat rule. */ - NAT_WLOCK(&nat_chain); + NAT_WLOCK(&nat_chain_rwl); 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); + NAT_WUNLOCK(&nat_chain_rwl); return (ENOSPC); } ptr->lib = LibAliasInit(NULL); if (ptr->lib == NULL) { free(ptr, M_IPFW); free(buf, M_IPFW); - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); return(EINVAL); } } else { /* Entry already present: temporarly unhook it. */ UNHOOK_NAT(&nat_chain.chain, ptr); flush_nat_ptrs(ser_n->id); } - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); /* * Basic nat configuration. @@ -4622,9 +4622,9 @@ ptr); /* Add new entries. */ free(buf, M_IPFW); if (err == 1) { - NAT_WLOCK(&nat_chain); + NAT_WLOCK(&nat_chain_rwl); HOOK_NAT(&nat_chain.chain, ptr); - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); } else /* Something bad happened, redir cfg not added. */ return(EINVAL); } @@ -4636,15 +4636,15 @@ int i; error = sooptcopyin(sopt, &i, sizeof i, sizeof i); - NAT_WLOCK(&nat_chain); + NAT_WLOCK(&nat_chain_rwl); ptr = lookup_nat(i); if (ptr == NULL) { error = EINVAL; - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); break; } UNHOOK_NAT(&nat_chain.chain, ptr); - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); flush_nat_ptrs(i); del_redir_spool_cfg(ptr, ptr->redir_chain); LibAliasUninit(ptr->lib); @@ -4666,7 +4666,7 @@ data = malloc(NAT_BUF_LEN, M_IPFW, M_NOWAIT | M_ZERO); if (data == NULL) return (ENOSPC); - NAT_RLOCK(&nat_chain); + NAT_RLOCK(&nat_chain_rwl); /* Serialize all the data. */ for (n = nat_chain.chain; (n && (off + sof_nat < NAT_BUF_LEN)); n = n->next) { @@ -4683,7 +4683,7 @@ } } } - NAT_RUNLOCK(&nat_chain); + NAT_RUNLOCK(&nat_chain_rwl); error = sooptcopyout(sopt, data, NAT_BUF_LEN); free(data, M_IPFW); @@ -4697,7 +4697,7 @@ int sof = LIBALIAS_BUF_SIZE; int i, size, cnt = 0; - NAT_RLOCK(&nat_chain); + NAT_RLOCK(&nat_chain_rwl); for (ptr = nat_chain.chain, size = i = 0; ptr; ptr = ptr->next) { if (ptr->lib->logDesc == NULL) continue; @@ -4711,7 +4711,7 @@ bcopy(ptr->lib->logDesc, &data[i], sof); i += sof; } - NAT_RUNLOCK(&nat_chain); + NAT_RUNLOCK(&nat_chain_rwl); error = sooptcopyout(sopt, data, size); free(data, M_IPFW); } @@ -4890,7 +4890,7 @@ ip_fw_chk_ptr = ipfw_chk; callout_reset(&ipfw_timeout, hz, ipfw_tick, NULL); nat_chain.chain = NULL; - NAT_LOCK_INIT(&nat_chain); + NAT_LOCK_INIT(&nat_chain_rwl); ifaddr_event_tag = EVENTHANDLER_REGISTER(ifaddr_event, ifaddr_change, NULL, EVENTHANDLER_PRI_ANY); return (0); @@ -4907,16 +4907,16 @@ callout_drain(&ipfw_timeout); IPFW_WLOCK(&layer3_chain); flush_tables(&layer3_chain); - NAT_WLOCK(&nat_chain); + NAT_WLOCK(&nat_chain_rwl); for (ptr = nat_chain.chain; ptr; ptr = ptr_temp) { ptr_temp = ptr->next; del_redir_spool_cfg(ptr, ptr->redir_chain); LibAliasUninit(ptr->lib); free(ptr, M_IPFW); } - NAT_WUNLOCK(&nat_chain); + NAT_WUNLOCK(&nat_chain_rwl); EVENTHANDLER_DEREGISTER(ifaddr_event, ifaddr_event_tag); - NAT_LOCK_DESTROY(&nat_chain); + 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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608301142.k7UBgYx7060877>