📄 natpptpptalg.c
字号:
(sptr_pptp_translation_entry->remote_address == remote_address)) { nat_printf (NAT_PRINTF_TRACE, "Found match for local addr = %08lx, remote addr = %08lx\n\t peers_call_id = %04x in PPTP list\n", local_address, remote_address, call_id); semGive (pptpListLock); return (sptr_pptp_translation_entry); } } nat_printf (NAT_PRINTF_TRACE, "No match for local addr = %08lx, remote addr = %08lx\n\t peers_call_id = %04x in PPTP list\n", local_address, remote_address, call_id); semGive (pptpListLock); return (NULL);}/*****************************************************************************Function: find_outbound_pptp_entryDescription:Look for PPTP entry with matching call_id, local address and remote address.*****************************************************************************/LOCAL PPTP_TRANSLATION_ENTRY *find_outbound_pptp_entry ( IP_ADDRESS local_address, IP_ADDRESS remote_address, USHORT call_id, PPTP_TRANSLATION_HEADER *sptr_pptp_translation_list){ PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry; semTake (pptpListLock, WAIT_FOREVER); for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry)) { if ((sptr_pptp_translation_entry->call_id == call_id) && (sptr_pptp_translation_entry->local_address == local_address) && (sptr_pptp_translation_entry->remote_address == remote_address)) { nat_printf (NAT_PRINTF_TRACE, "Found match for local addr = %08lx, remote addr = %08lx\n\t call_id = %04x in PPTP list\n", local_address, remote_address, call_id); semGive (pptpListLock); return (sptr_pptp_translation_entry); } } nat_printf (NAT_PRINTF_TRACE, "No match for local addr = %08lx, remote addr = %08lx\n\t call_id = %04x in PPTP list\n", local_address, remote_address, call_id); semGive (pptpListLock); return (NULL);}/*****************************************************************************Function: find_inbound_pptp_entryDescription:Look for PPTP entry with call_id, local address and remote address.*****************************************************************************/LOCAL PPTP_TRANSLATION_ENTRY *find_inbound_pptp_entry ( IP_ADDRESS remote_address, USHORT call_id, PPTP_TRANSLATION_HEADER *sptr_pptp_translation_list){ PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry; semTake (pptpListLock, WAIT_FOREVER); /* Look up by spoofed call ID and remote address (NAT'ed client) */ for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry)) { if ((sptr_pptp_translation_entry->spoofed_call_id == call_id) && (sptr_pptp_translation_entry->remote_address == remote_address)) { nat_printf (NAT_PRINTF_TRACE, "Found match for remote addr = %08lx\n\t call_id = %04x in PPTP list\n", remote_address, call_id); semGive (pptpListLock); return (sptr_pptp_translation_entry); } } /* Look up by remote address and faked spoofed call ID (NAT'ed server) */ for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry)) { if ((sptr_pptp_translation_entry->spoofed_call_id == (remote_address & FAKE_SPOOFED_CALL_ID_MASK)) && (!sptr_pptp_translation_entry->nated_client) && (sptr_pptp_translation_entry->remote_address == remote_address)) { nat_printf (NAT_PRINTF_TRACE, "Found match for remote addr = %08lx\n\t call_id = %04x in PPTP list\n", remote_address, call_id); semGive (pptpListLock); return (sptr_pptp_translation_entry); } } nat_printf (NAT_PRINTF_TRACE, "No match for remote addr = %08lx\n\t call_id = %04x in PPTP list\n", remote_address, call_id); semGive (pptpListLock); return (NULL);}/************************************************************************/LOCAL void nat_pptp_timer (void){ if (nat.single_global_address_enabled == TRUE) { check_pptp_translation_entry_timer (&pptp_translation_list); }}/************************************************************************/static void check_pptp_translation_entry_timer (PPTP_TRANSLATION_HEADER *sptr_pptp_translation_list){ PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry; PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry_next; char addr_str[32]; semTake (pptpListLock, WAIT_FOREVER); for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = sptr_pptp_translation_entry_next) { sptr_pptp_translation_entry_next = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry); if (sptr_pptp_translation_entry->pptp_translation_entry_timer > 0x00000000L) { --sptr_pptp_translation_entry->pptp_translation_entry_timer; } else { if (nat.printing_enabled == true || nat.logging_enabled == true) { struct in_addr iaddr; iaddr.s_addr = sptr_pptp_translation_entry->local_address; iaddr.s_addr = htonl(iaddr.s_addr); inet_ntoa_b(iaddr,addr_str); nat_printf (NAT_PRINTF_TRACE, "PPTP translation entry expired, addr: %s\n",addr_str); } dllRemove ((DL_LIST *) sptr_pptp_translation_list, (DL_NODE *) sptr_pptp_translation_entry); free (sptr_pptp_translation_entry); } } semGive (pptpListLock);}/************************************************************************/static void clear_pptp_translation_entry_list (PPTP_TRANSLATION_HEADER *sptr_pptp_translation_list){ PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry; PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry_next; semTake (pptpListLock, WAIT_FOREVER); for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) sptr_pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = sptr_pptp_translation_entry_next) { sptr_pptp_translation_entry_next = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry); dllRemove ((DL_LIST *) sptr_pptp_translation_list, (DL_NODE *) sptr_pptp_translation_entry); free (sptr_pptp_translation_entry); } semGive (pptpListLock);}/************************************************************************/LOCAL USHORT new_spoofed_call_id(void){ PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry_next; PPTP_TRANSLATION_ENTRY *sptr_pptp_translation_entry; BOOL conflict; BOOL first_pass; first_pass = FALSE; for (next_pptp_spoofed_call_id = next_pptp_spoofed_call_id + 1; ; next_pptp_spoofed_call_id = next_pptp_spoofed_call_id +1) { if (next_pptp_spoofed_call_id > UPPER_SPOOFED_CALL_ID_VALUE) { next_pptp_spoofed_call_id = LOWER_SPOOFED_CALL_ID_VALUE; if (first_pass == FALSE) first_pass = TRUE; else return (UPPER_SPOOFED_CALL_ID_VALUE+1); } conflict = FALSE; semTake (pptpListLock, WAIT_FOREVER); for (sptr_pptp_translation_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *)&pptp_translation_list); sptr_pptp_translation_entry != NULL; sptr_pptp_translation_entry = sptr_pptp_translation_entry_next) { if (sptr_pptp_translation_entry->spoofed_call_id == next_pptp_spoofed_call_id) { conflict = TRUE; break; } sptr_pptp_translation_entry_next = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) sptr_pptp_translation_entry); } semGive (pptpListLock); if (conflict == TRUE) { continue; } return(next_pptp_spoofed_call_id); }}/**********************************************************************************/void natPPTPXlatShow(){ char local_addr[INET_ADDR_LEN]; char remote_addr[INET_ADDR_LEN]; char type[10]; int entry_num; PPTP_TRANSLATION_ENTRY* pptp_entry; struct in_addr iaddr; entry_num = 0; pptp_entry = (PPTP_TRANSLATION_ENTRY *) DLL_FIRST( (DL_LIST *) &pptp_translation_list); while (pptp_entry != NULL) { if(entry_num==0) { printf("\n"); printf("NAT PPTP Client Translation List\n"); printf("-------------------------------\n"); printf("# %-*s CallID SpoofedCallID PeersCallID" " %-*s Type Timer\n" ,15,"Local Address" ,15,"Remote Address"); } entry_num++; iaddr.s_addr = htonl(pptp_entry->local_address); inet_ntoa_b(iaddr, local_addr); iaddr.s_addr = htonl(pptp_entry->remote_address); inet_ntoa_b(iaddr, remote_addr); if (pptp_entry->nated_client) strcpy(type,"Client"); else strcpy(type,"Server"); printf("%-3d %-*s %04x %04x %04x " " %-*s %-*s %5lu\n", entry_num, 15,local_addr, pptp_entry->call_id, pptp_entry->spoofed_call_id, pptp_entry->peers_call_id, 15,remote_addr, 6,type, pptp_entry->pptp_translation_entry_timer ); pptp_entry = (PPTP_TRANSLATION_ENTRY *) DLL_NEXT( (DL_NODE *) pptp_entry); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -