📄 nat_cleanup.c
字号:
/* nat_cleanup.c - library that supplies nat_cleanup() *//* Copyright 2000-2003 Wind River Systems, Inc. *//* @format.tab-size 4, @format.use-tabs true, @format.new-line lf *//*modification history--------------------01f,29aug03,zhu updated the format for refgen01e,16jun03,myz Use new fragment translation cleanup routine.01d,12may03,myz added natIcmpErrorHookRemove in nat_cleanup.01c,25apr03,myz make dllFreeList a global func and add delays in nat_cleanup01b,24apr03,zhu updated copyright01a,21apr03,myz enhanced nat_cleanup function, and added dllFreeList 040803 vks updated Copyright info040303 vks replaced table_free with free092502 vvv modified fragment lists to use lstLib instead of rw_container092402 vvv replaced rw_container references with direct linked list access to improve performance030901 tk Add call to delete natInitSync semaphore*//*DESCRIPTIONThis library provides nat_cleanup(), a routine that you can use to shut down WIND NET NAT entirely, thus freeing all its associated resources (configuration information, tasks, message queues, etc.).*/#include "nat.h"void ipFilterHookDelete(void); /* Missing from VxWorks headers */extern void natIcmpErrorHookRemove (void);/****************************************************************************/static void nat_free_udp_translation_list (void);static void nat_free_icmp_translation_list (void);/****************************************************************************//****************************************************************************** nat_cleanup - shut down WIND NET NAT, free all associated resources** Call this function to shut down WIND NET NAT entirely and free all its * associated resources. * * 'Note:' To merely pause WIND NET NAT, you can call natEnable() with * the <enable> parameter set to FALSE. **/void nat_cleanup (void){ IP_TRANSLATION_ENTRY *sptr_ip_translation_entry; /* Remove the VxWorks IP Filter Hook */ ipFilterHookDelete(); /* remove the NAT ICMP error hook */ natIcmpErrorHookRemove(); /* give the unhooked NAT engine some time in case it's in progress */ taskDelay(2); /* delete the NAT task */ natTaskDelete(); /* cleanup the rest of resource */ for (sptr_ip_translation_entry = (IP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &nat.natg.ip_translation_list); sptr_ip_translation_entry != NULL; sptr_ip_translation_entry = (IP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &nat.natg.ip_translation_list)) { dllRemove ((DL_LIST *) &nat.natg.ip_translation_list, (DL_NODE *) sptr_ip_translation_entry); if (sptr_ip_translation_entry->sptr_local_address_use_entry != NULL) { sptr_ip_translation_entry->sptr_local_address_use_entry->address_in_use = FALSE; } free (sptr_ip_translation_entry); } natFragTranCleanup(nat.pFragTranResrc); delete_tcp_connection_entry_list (&nat.nats.tcp_translation_list); nat_free_udp_translation_list (); nat_free_icmp_translation_list (); /* Clean-up passthrough list */ lstFree (&nat.passthru_list); /* Clean-up agent list */ lstFree (&nat.agent_list); /* Clean-up bind list */ lstFree (&nat.bind_list); /* Clean up the semaphores */ if (udpListLock) semDelete (udpListLock); if (tcpListLock) semDelete (tcpListLock); if (spoofingPortLock) semDelete (spoofingPortLock); if (natInitSync) semDelete (natInitSync); if (ipListLock) semDelete(ipListLock); if (bindListLock) semDelete(bindListLock); if (agentListLock) semDelete(agentListLock); if (nat.natg.global_address_pool != NULL) { free (nat.natg.global_address_pool); nat.natg.global_address_pool = NULL; } nat.enabled = FALSE; }/************************************************************************/void delete_sequence_entry_list (SEQUENCE_HEADER *sptr_sequence_list){ dllFreeList ((DL_LIST *) sptr_sequence_list);} /***************************************************************************** dllFreeList - Free a link list** Free a link list.* * NOMANUAL*/void dllFreeList ( DL_LIST * pList ) { DL_NODE * pNode; DL_NODE * pPrevNode; pNode = DLL_FIRST(pList); while (pNode) { pPrevNode = pNode; pNode = DLL_NEXT(pNode); free((void *)pPrevNode); } dllInit(pList); }/************************************************************************/void delete_tcp_connection_entry_list (TCP_TRANSLATION_HEADER *sptr_tcp_translation_list){ TCP_TRANSLATION_ENTRY *sptr_tcp_translation_entry; for (sptr_tcp_translation_entry = (TCP_TRANSLATION_ENTRY *) dllGet ((DL_LIST *) sptr_tcp_translation_list); sptr_tcp_translation_entry != NULL; sptr_tcp_translation_entry = (TCP_TRANSLATION_ENTRY *) dllGet ((DL_LIST *) sptr_tcp_translation_list)) { delete_sequence_entry_list (&sptr_tcp_translation_entry->local_sequence_delta_list); delete_sequence_entry_list (&sptr_tcp_translation_entry->global_sequence_delta_list); free (sptr_tcp_translation_entry); }} /************************************************************************/static void nat_free_udp_translation_list (void){ UDP_TRANSLATION_ENTRY* p_udp_entry; UDP_TRANSLATION_ENTRY* p_next_udp_entry; for (p_udp_entry = nat.nats.udp_translation_list.sptr_forward_link; p_udp_entry != NULL; p_udp_entry = p_next_udp_entry) { p_next_udp_entry = p_udp_entry->link.sptr_forward_link; dllRemove ((DL_LIST*) &nat.nats.udp_translation_list, (DL_NODE*) p_udp_entry); free (p_udp_entry); }} /************************************************************************/static void nat_free_icmp_translation_list (void){ ICMP_TRANSLATION_ENTRY* p_icmp_entry; ICMP_TRANSLATION_ENTRY* p_next_icmp_entry; for (p_icmp_entry = nat.nats.icmp_translation_list.sptr_forward_link; p_icmp_entry != NULL; p_icmp_entry = p_next_icmp_entry) { p_next_icmp_entry = p_icmp_entry->link.sptr_forward_link; dllRemove ((DL_LIST*) &nat.nats.icmp_translation_list, (DL_NODE*) p_icmp_entry); free (p_icmp_entry); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -