📄 natmgmt.c
字号:
*/STATUS m2NatBindTblEntryGet ( NAT_BINDTBL_ENTRY * pNatBindEntry, /* pointer to buffer */ int searchType /* GET/NEXT */ ) { IP_TRANSLATION_ENTRY * pIpEntry = NULL; TCP_TRANSLATION_ENTRY * pTcpEntry = NULL; UDP_TRANSLATION_ENTRY * pUdpEntry = NULL; ICMP_TRANSLATION_ENTRY * pIcmpEntry = NULL; void * pBestEntry = NULL; NAT_IP_ADDRESS savLocAddr; NAT_IP_ADDRESS savRemAddr; USHORT savLocPort; USHORT savRemPort; UINT16 matchType = 0; NAT_IP_ADDRESS icmpGlobAddr = nat.global_address; int index; int found = 0; UINT16 natType; USHORT basicPort = 0xffff; if (!pNatBindEntry) return ERROR; /* * Initialize the ports and the IP address of the saved entry to the * maximum possible values */ savLocAddr = 0xffffffff; savRemAddr = 0xffffffff; savLocPort = 0xffff; savRemPort = 0xffff; if (nat.single_global_address_enabled == TRUE) natType = NAT_NAPT; else natType = NAT_BASIC; /* Both basic NAT and NAPT will go through this*/ pIpEntry = (IP_TRANSLATION_ENTRY *)DLL_FIRST ((DL_LIST *)&nat.natg.ip_translation_list); while (pIpEntry && !found) { if (transListWalk ( &pIpEntry->sa_local_address, &basicPort, &pIpEntry->sa_global_address, &basicPort, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, &savLocAddr, &savLocPort, &savRemAddr, &savRemPort, natType, searchType ) != ERROR) { pBestEntry = pIpEntry; matchType = IP_TRANS_LIST; if (searchType == GET_VALUE) { found = 1; break; } } /* * If this is a GET_VALUE search, and we found an entry, then we are * done. If this is a NEXT_VALUE, then we execute this code in any case. */ if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) ) { /* * We now search the TCP translation list within each of these IP * translation entries */ pTcpEntry = (TCP_TRANSLATION_ENTRY *)DLL_FIRST ((DL_LIST *)&pIpEntry->tcp_translation_list); while (pTcpEntry) { if (transListWalk ( &pTcpEntry->local_address, &pTcpEntry->local_port, &pTcpEntry->remote_address, &pTcpEntry->remote_port, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, &savLocAddr, &savLocPort, &savRemAddr, &savRemPort, natType, searchType ) != ERROR) { pBestEntry = pTcpEntry; matchType = TCP_TRANS_LIST; if (searchType == GET_VALUE) { found = 1; break; } } pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pTcpEntry); } } /* Done with this IP entry, get the next one */ pIpEntry = (IP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pIpEntry); } /* The following code will be only executed at NAPT mode*/ if (natType == NAT_NAPT) { /* * NAPT mode : * We will have to browse through the other three lists - TCP, UDP and * ICMP to figure out our best match; * If this is a GET_VALUE search, and we found an entry, then we are * done. If this is a NEXT_VALUE, then we execute this code in any case. * We will start off with the TCP list */ if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) ) { pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &nat.nats.tcp_translation_list); while (pTcpEntry) { if (transListWalk ( &pTcpEntry->local_address, &pTcpEntry->local_port, &pTcpEntry->remote_address, &pTcpEntry->remote_port, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, &savLocAddr, &savLocPort, &savRemAddr, &savRemPort, natType, searchType ) != ERROR) { pBestEntry = pTcpEntry; matchType = TCP_TRANS_LIST; if (searchType == GET_VALUE) { found = 1; break; } } pTcpEntry = (TCP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pTcpEntry); } } /* * If this is a GET_VALUE search, and we found an entry, then we are * done. If this is a NEXT_VALUE, then we execute this code in any case. */ if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) ) { pUdpEntry = (UDP_TRANSLATION_ENTRY *) DLL_FIRST ((DL_LIST *) &nat.nats.udp_translation_list); while (pUdpEntry) { if (transListWalk ( &pUdpEntry->local_address, &pUdpEntry->local_port, &pUdpEntry->remote_address, &pUdpEntry->remote_port, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, &savLocAddr, &savLocPort, &savRemAddr, &savRemPort, natType, searchType ) != ERROR) { pBestEntry = pUdpEntry; matchType = UDP_TRANS_LIST; if (searchType == GET_VALUE) { found = 1; break; } } pUdpEntry = (UDP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pUdpEntry); } } /* * If this is a GET_VALUE search, and we found an entry, then we are * done. If this is a NEXT_VALUE, then we execute this code in any case. */ if ( (searchType == NEXT_VALUE) || (searchType == GET_VALUE && !found) ) { /* Look thru the ICMP list */ pIcmpEntry = (ICMP_TRANSLATION_ENTRY *) DLL_FIRST((DL_LIST *) &nat.nats.icmp_translation_list); while (pIcmpEntry) { if (transListWalk ( &pIcmpEntry->local_address, &pIcmpEntry->icmp_identifier, &icmpGlobAddr, &pIcmpEntry->spoofed_icmp_identifier, &pNatBindEntry->natBindLocalAddress, &pNatBindEntry->natBindLocalPort, &pNatBindEntry->natBindRemAddress, &pNatBindEntry->natBindRemPort, &savLocAddr, &savLocPort, &savRemAddr, &savRemPort, natType, searchType ) != ERROR) { pBestEntry = pIcmpEntry; matchType = ICMP_TRANS_LIST; if (searchType == GET_VALUE) { found = 1; break; } } pIcmpEntry = (ICMP_TRANSLATION_ENTRY *) DLL_NEXT ((DL_NODE *) pIcmpEntry); } } } /* pBestEntry should have the best match, so start copying the values */ switch (matchType) { case IP_TRANS_LIST: pIpEntry = (IP_TRANSLATION_ENTRY *) pBestEntry; pNatBindEntry->natBindStatic = (pIpEntry->static_entry) ? STATIC_ENTRY : DYNAMIC_ENTRY; pNatBindEntry->natBindType = ADDRESS_BINDING; pNatBindEntry->natBindLocalAddress = htonl(pIpEntry->sa_local_address); pNatBindEntry->natBindLocalPort = 0xffff; pNatBindEntry->natBindRemAddress = htonl(pIpEntry->sa_global_address); pNatBindEntry->natBindRemPort = 0xffff; pNatBindEntry->natBindMaxLeaseTime = 0xffffffff; pNatBindEntry->natBindLeaseLeft = 0xffffffff; pNatBindEntry->natBindMaxIdle = nat.ip_translation_entry_timer; pNatBindEntry->natBindCurrIdle = pIpEntry->time_stamp; pNatBindEntry->natBindDirection = NAT_UNIDIRECTIONAL; pNatBindEntry->natBindProto = IP_TRANS_LIST; pNatBindEntry->natBindAction = NAT_BIND_ACTIVE; break; case TCP_TRANS_LIST: pTcpEntry = (TCP_TRANSLATION_ENTRY *) pBestEntry; pNatBindEntry->natBindStatic = (pTcpEntry->static_entry) ? STATIC_ENTRY : DYNAMIC_ENTRY; pNatBindEntry->natBindType = TRANSPORT_BINDING; pNatBindEntry->natBindLocalAddress = htonl(pTcpEntry->local_address); pNatBindEntry->natBindLocalPort = pTcpEntry->local_port; pNatBindEntry->natBindRemAddress = htonl(pTcpEntry->remote_address); pNatBindEntry->natBindRemPort = pTcpEntry->remote_port; pNatBindEntry->natBindMaxLeaseTime = 0xffffffff; pNatBindEntry->natBindLeaseLeft = 0xffffffff; pNatBindEntry->natBindMaxIdle = nat.tcp_connected_timer; pNatBindEntry->natBindCurrIdle = pTcpEntry->local_connection_timer; pNatBindEntry->natBindDirection = NAT_UNIDIRECTIONAL; pNatBindEntry->natBindProto = TCP_TRANS_LIST; pNatBindEntry->natBindAction = NAT_BIND_ACTIVE; break; case UDP_TRANS_LIST: pUdpEntry = (UDP_TRANSLATION_ENTRY *) pBestEntry; pNatBindEntry->natBindStatic = (pUdpEntry->static_entry) ? STATIC_ENTRY : DYNAMIC_ENTRY; pNatBindEntry->natBindType = TRANSPORT_BINDING; pNatBindEntry->natBindLocalAddress = htonl(pUdpEntry->local_address); pNatBindEntry->natBindLocalPort = pUdpEntry->local_port; pNatBindEntry->natBindRemAddress = htonl(pUdpEntry->remote_address); pNatBindEntry->natBindRemPort = pUdpEntry->remote_port; pNatBindEntry->natBindMaxLeaseTime = 0xffffffff; pNatBindEntry->natBindLeaseLeft = 0xffffffff; pNatBindEntry->natBindMaxIdle = nat.udp_translation_entry_timer; pNatBindEntry->natBindCurrIdle = pUdpEntry->udp_translation_entry_timer; pNatBindEntry->natBindDirection = NAT_UNIDIRECTIONAL; pNatBindEntry->natBindProto = UDP_TRANS_LIST; pNatBindEntry->natBindAction = NAT_BIND_ACTIVE; break; case ICMP_TRANS_LIST: pIcmpEntry = (ICMP_TRANSLATION_ENTRY *) pBestEntry; pNatBindEntry->natBindStatic = DYNAMIC_ENTRY; pNatBindEntry->natBindType = TRANSPORT_BINDING; pNatBindEntry->natBindLocalAddress = htonl(pIcmpEntry->local_address); pNatBindEntry->natBindLocalPort = pIcmpEntry->icmp_identifier; pNatBindEntry->natBindRemAddress = htonl(icmpGlobAddr); /* the remote port contains the spoofed icmp identifier in this case*/ pNatBindEntry->natBindRemPort = pIcmpEntry->spoofed_icmp_identifier; pNatBindEntry->natBindMaxLeaseTime = 0xffffffff; pNatBindEntry->natBindLeaseLeft = 0xffffffff; pNatBindEntry->natBindMaxIdle = nat.icmp_translation_entry_timer; pNatBindEntry->natBindCurrIdle = pIcmpEntry->icmp_translation_entry_timer; pNatBindEntry->natBindDirection = NAT_UNIDIRECTIONAL; pNatBindEntry->natBindProto = ICMP_TRANS_LIST; pNatBindEntry->natBindAction = NAT_BIND_ACTIVE; break; default: errnoSet(S_m2Lib_ENTRY_NOT_FOUND); return ERROR; } /* * Get the interface information for each IP address from the global * "nat" structure */ for (index = 0; index < NUMBER_OF_IP_PORTS; index++) { unsigned char * pStr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -