From 1a458088fff790956dc22bb9130f49881456f6fd Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Mon, 27 Apr 2015 09:16:22 +0000 Subject: [PATCH] Use free_nat_instance() for nat instance deletion. Sponsored by: Yandex LLC --- sys/netpfil/ipfw/ip_fw_nat.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/sys/netpfil/ipfw/ip_fw_nat.c b/sys/netpfil/ipfw/ip_fw_nat.c index 201b77a9c92d..df403982086b 100644 --- a/sys/netpfil/ipfw/ip_fw_nat.c +++ b/sys/netpfil/ipfw/ip_fw_nat.c @@ -265,6 +265,16 @@ add_redir_spool_cfg(char *buf, struct cfg_nat *ptr) return (0); } +static void +free_nat_instance(struct cfg_nat *ptr) +{ + + del_redir_spool_cfg(ptr, &ptr->redir_chain); + LibAliasUninit(ptr->lib); + free(ptr, M_IPFW); +} + + /* * ipfw_nat - perform mbuf header translation. * @@ -538,7 +548,7 @@ nat44_config(struct ip_fw_chain *chain, struct nat44_cfg_nat *ucfg) IPFW_UH_WUNLOCK(chain); if (tcfg != NULL) - free(tcfg, M_IPFW); + free_nat_instance(ptr); } /* @@ -628,9 +638,7 @@ nat44_destroy(struct ip_fw_chain *chain, ip_fw3_opheader *op3, IPFW_WUNLOCK(chain); IPFW_UH_WUNLOCK(chain); - del_redir_spool_cfg(ptr, &ptr->redir_chain); - LibAliasUninit(ptr->lib); - free(ptr, M_IPFW); + free_nat_instance(ptr); return (0); } @@ -996,9 +1004,7 @@ ipfw_nat_del(struct sockopt *sopt) flush_nat_ptrs(chain, i); IPFW_WUNLOCK(chain); IPFW_UH_WUNLOCK(chain); - del_redir_spool_cfg(ptr, &ptr->redir_chain); - LibAliasUninit(ptr->lib); - free(ptr, M_IPFW); + free_nat_instance(ptr); return (0); } @@ -1141,9 +1147,7 @@ vnet_ipfw_nat_uninit(const void *arg __unused) IPFW_WLOCK(chain); LIST_FOREACH_SAFE(ptr, &chain->nat, _next, ptr_temp) { LIST_REMOVE(ptr, _next); - del_redir_spool_cfg(ptr, &ptr->redir_chain); - LibAliasUninit(ptr->lib); - free(ptr, M_IPFW); + free_nat_instance(ptr); } flush_nat_ptrs(chain, -1 /* flush all */); V_ipfw_nat_ready = 0;