📄 nat_timer.c
字号:
/* nat_timer.c *//* Copyright 2000-2003 Wind River Systems, Inc. *//* @format.tab-size 4, @format.use-tabs true, @format.new-line lf *//*modification history--------------------01d,16jun03,myz Call the new fragment translation timer and removed old one.01c,25apr03,myz added debug switch check before calling nat_printf in one case01b,24apr03,zhu updated copyright01a,21apr03,myz replaced swap(_long) with the htons(l) macros, replaced RWOS list functions with ones in dllLib.c.040903 vks updated Copyright info040303 vks replaced table_free with free092502 vvv modified fragment lists to use lstLib instead of rw_container; added semaphore protection (SPR #79675)082301 tk Modify check_tcp_translation_entry_timer so that if static TCP entry, don't delete entry when timer goes to 0. 071101 tk Call natFreeBind to delete TCP, UDP, and IP entry from its respective translation list and the bind list.062801 tk Add the ip semaphore lock in check_ip_translation_entry_timer.060401 tk Fix the static entry disable problem with static address (IP) translations. The IP static entry got permanently deleted from translation list so it can't be revived even when the static entry is reenabled.050401 tk Delete TCP/UDP entry from translation list regardless of whether it is static or dynamic when its translation timer expires. The static entries are kept in separate tables. A static flag in the translation list simply indicates the address is bound to a static entry, but the entry shouldn't stay permanently in the translation list as the next TCP/UDP connection will require creation of a new control block anyway (client's port changes with each connection).*/#include "nat.h"/************************************************************************/static void check_tcp_translation_entry_timer (TCP_TRANSLATION_HEADER *sptr_tcp_translation_list);static void check_ip_translation_entry_timer (IP_TRANSLATION_HEADER *sptr_ip_translation_list);static void check_udp_translation_entry_timer (UDP_TRANSLATION_HEADER *sptr_udp_translation_list);static void check_icmp_translation_entry_timer (ICMP_TRANSLATION_HEADER *sptr_icmp_translation_list);static void check_sequence_entry_timer (SEQUENCE_HEADER *sptr_sequence_list);/************************************************************************/void nat_timer (void){/* nat_printf(NAT_PRINTF_TRACE, "nat_timer\n"); */ if (nat.single_global_address_enabled == TRUE) { check_icmp_translation_entry_timer (&nat.nats.icmp_translation_list); check_udp_translation_entry_timer (&nat.nats.udp_translation_list); check_tcp_translation_entry_timer (&nat.nats.tcp_translation_list); check_ip_translation_entry_timer (&nat.natg.ip_translation_list); } else { check_ip_translation_entry_timer (&nat.natg.ip_translation_list); } natFragTranTimerProcess ();}/************************************************************************/static void check_icmp_translation_entry_timer (ICMP_TRANSLATION_HEADER *sptr_icmp_translation_list){ ICMP_TRANSLATION_ENTRY *sptr_icmp_translation_entry; ICMP_TRANSLATION_ENTRY *sptr_icmp_translation_entry_next; char addr_str[32]; for (sptr_icmp_translation_entry = (ICMP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_icmp_translation_list); sptr_icmp_translation_entry != NULL; sptr_icmp_translation_entry = sptr_icmp_translation_entry_next) { sptr_icmp_translation_entry_next = (ICMP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_icmp_translation_entry); if (sptr_icmp_translation_entry->icmp_translation_entry_timer > 0x00000000L) { --sptr_icmp_translation_entry->icmp_translation_entry_timer; } else { if (nat.printing_enabled == true || nat.logging_enabled == true) { struct in_addr iaddr; iaddr.s_addr = htonl(sptr_icmp_translation_entry->local_address); inet_ntoa_b(iaddr,addr_str); nat_printf (NAT_PRINTF_TRACE, "ICMP translation entry expired, addr: %s\n",addr_str); } dllRemove ((DL_LIST *) sptr_icmp_translation_list, (DL_NODE *) sptr_icmp_translation_entry); natFreeBind ((u_long)&nat, 0, sptr_icmp_translation_entry->bind_id); free (sptr_icmp_translation_entry); } }}/************************************************************************/static void check_udp_translation_entry_timer (UDP_TRANSLATION_HEADER *sptr_udp_translation_list){ UDP_TRANSLATION_ENTRY *sptr_udp_translation_entry; UDP_TRANSLATION_ENTRY *sptr_udp_translation_entry_next; char addr_str[32]; /* Take the UDP list semaphore */ semTake (udpListLock, WAIT_FOREVER); for (sptr_udp_translation_entry = (UDP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_udp_translation_list); sptr_udp_translation_entry != NULL; sptr_udp_translation_entry = sptr_udp_translation_entry_next) { sptr_udp_translation_entry_next = (UDP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_udp_translation_entry); if (sptr_udp_translation_entry->udp_translation_entry_timer > 0x00000000L) { --sptr_udp_translation_entry->udp_translation_entry_timer; } else if (!sptr_udp_translation_entry->static_entry) { semGive (udpListLock); /* must give semaphore since natFreeBind will take it */ if (nat.logging_enabled == true || nat.printing_enabled == true) { struct in_addr iaddr; iaddr.s_addr = htonl(sptr_udp_translation_entry->local_address); inet_ntoa_b(iaddr,addr_str); nat_printf (NAT_PRINTF_TRACE, "UDP translation entry expired, addr: %s\n",addr_str); } natFreeBind ((u_long)&nat, 0, sptr_udp_translation_entry->bind_id); semTake (udpListLock, WAIT_FOREVER); } } semGive (udpListLock);}/************************************************************************/static void check_tcp_translation_entry_timer (TCP_TRANSLATION_HEADER *sptr_tcp_translation_list){ TCP_TRANSLATION_ENTRY *sptr_tcp_translation_entry; TCP_TRANSLATION_ENTRY *sptr_next_tcp_translation_entry; char addr_str[32]; /* Take the TCP list semaphore */ semTake (tcpListLock, WAIT_FOREVER); for (sptr_tcp_translation_entry = (TCP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_tcp_translation_list); sptr_tcp_translation_entry != NULL; sptr_tcp_translation_entry = sptr_next_tcp_translation_entry) { sptr_next_tcp_translation_entry = (TCP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_tcp_translation_entry); if (sptr_tcp_translation_entry->local_connection_timer > 0x00000000L) { --sptr_tcp_translation_entry->local_connection_timer; } if (sptr_tcp_translation_entry->global_connection_timer > 0x00000000L) { --sptr_tcp_translation_entry->global_connection_timer; } check_sequence_entry_timer (&sptr_tcp_translation_entry->local_sequence_delta_list); check_sequence_entry_timer (&sptr_tcp_translation_entry->global_sequence_delta_list); if (sptr_tcp_translation_entry->local_connection_timer == 0 && sptr_tcp_translation_entry->global_connection_timer == 0 && sptr_tcp_translation_entry->static_entry == FALSE) { if (nat.logging_enabled == true || nat.printing_enabled == true) { struct in_addr iaddr; iaddr.s_addr = htonl(sptr_tcp_translation_entry->local_address); inet_ntoa_b(iaddr,addr_str); nat_printf (NAT_PRINTF_TRACE, "TCP translation entry expired, addr: %s\n",addr_str); } delete_sequence_entry_list (&sptr_tcp_translation_entry->local_sequence_delta_list); delete_sequence_entry_list (&sptr_tcp_translation_entry->global_sequence_delta_list); semGive (tcpListLock); /* must give semaphore since natFreeBind will take it */ natFreeBind ((u_long)&nat, 0, sptr_tcp_translation_entry->bind_id); semTake (tcpListLock, WAIT_FOREVER); } } semGive (tcpListLock);}/************************************************************************/static void check_sequence_entry_timer (SEQUENCE_HEADER *sptr_sequence_list){ SEQUENCE_ENTRY *sptr_sequence_entry; SEQUENCE_ENTRY *sptr_next_sequence_entry; for (sptr_sequence_entry = (SEQUENCE_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_sequence_list); sptr_sequence_entry != NULL; sptr_sequence_entry = sptr_next_sequence_entry) { sptr_next_sequence_entry = (SEQUENCE_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_sequence_entry); if (sptr_sequence_entry->timer_enabled == TRUE) { if (sptr_sequence_entry->entry_timer > 0x00000000L) { --sptr_sequence_entry->entry_timer; } else { dllRemove ((DL_LIST *) sptr_sequence_list, (DL_NODE *) sptr_sequence_entry); free (sptr_sequence_entry); } } }} /************************************************************************/static void check_ip_translation_entry_timer (IP_TRANSLATION_HEADER *sptr_ip_translation_list){ IP_TRANSLATION_ENTRY *sptr_ip_translation_entry; IP_TRANSLATION_ENTRY *sptr_ip_translation_entry_next; TCP_TRANSLATION_ENTRY *sptr_tcp_translation_entry; char addr_str[32]; semTake (ipListLock, WAIT_FOREVER); for (sptr_ip_translation_entry = (IP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_ip_translation_list); sptr_ip_translation_entry != NULL; sptr_ip_translation_entry = sptr_ip_translation_entry_next) { sptr_ip_translation_entry_next = (IP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_ip_translation_entry); sptr_tcp_translation_entry = (TCP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &sptr_ip_translation_entry->tcp_translation_list); if (sptr_tcp_translation_entry != NULL) { check_tcp_translation_entry_timer (&sptr_ip_translation_entry->tcp_translation_list); } else if (sptr_ip_translation_entry->time_stamp > 0x00000000L) { --sptr_ip_translation_entry->time_stamp; } else if (!sptr_ip_translation_entry->static_entry) { delete_tcp_connection_entry_list (&sptr_ip_translation_entry->tcp_translation_list); sptr_ip_translation_entry->sptr_local_address_use_entry->address_in_use = FALSE; semGive (ipListLock); /* need to give semaphore since natFreeBind will take it */ if (nat.logging_enabled == true || nat.printing_enabled == true) { struct in_addr iaddr; iaddr.s_addr = htonl(sptr_ip_translation_entry->sa_local_address); inet_ntoa_b(iaddr,addr_str); nat_printf (NAT_PRINTF_TRACE, "IP translation entry expired, addr: %s\n",addr_str); } natFreeBind ((u_long)&nat, 0, sptr_ip_translation_entry->bind_id); semTake (ipListLock, WAIT_FOREVER); } } semGive (ipListLock);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -