private void HandleFromInternal(Frame fInputFrame, int iSourcePort, int iDestinationPort, IP.IPFrame ipFrame, TCP.TCPFrame tcpFrame, UDP.UDPFrame udpFrame) { NATEntry neEntry = GetTranslationEntry(ipFrame.SourceAddress, ipFrame.DestinationAddress, iSourcePort, iDestinationPort, ipFrame.Protocol); if (neEntry == null) { neEntry = CreateTranslationEntry(ipFrame.SourceAddress, ipFrame.DestinationAddress, iSourcePort, iDestinationPort, ipFrame.Protocol); } ipFrame.SourceAddress = neEntry.TranslatedSourceAddress; if (tcpFrame != null) { tcpFrame.SourcePort = neEntry.TranslatedSourcePort; tcpFrame.Checksum = tcpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); CheckForTCPFinish(tcpFrame, neEntry); } else if (udpFrame != null) { udpFrame.SourcePort = neEntry.TranslatedSourcePort; udpFrame.Checksum = udpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); } NotifyNextExternal(ipFrame); }
private void HandleFromExternal(Frame fInputFrame, int iSourcePort, int iDestinationPort, IP.IPFrame ipFrame, TCP.TCPFrame tcpFrame, UDP.UDPFrame udpFrame) { NATEntry neEntry = GetReTranslationEntry(ipFrame.DestinationAddress, ipFrame.SourceAddress, iDestinationPort, iSourcePort, ipFrame.Protocol); if (neEntry != null) { ipFrame.DestinationAddress = neEntry.OriginalSourceAddress; if (tcpFrame != null) { tcpFrame.DestinationPort = neEntry.OriginalSourcePort; tcpFrame.Checksum = tcpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); CheckForTCPFinish(tcpFrame, neEntry); } else if (udpFrame != null) { udpFrame.DestinationPort = neEntry.OriginalSourcePort; udpFrame.Checksum = udpFrame.CalculateChecksum(ipFrame.GetPseudoHeader()); } NotifyNextInternal(ipFrame); } else { PushDroppedFrame(fInputFrame); if (bThrowOnNonNATFrame) { throw new Exception("The external frame was discarded because there was no corresponding translation entry in the database. (Source: " + ipFrame.SourceAddress + "/" + iSourcePort + ", Destination: " + ipFrame.DestinationAddress + "/" + iDestinationPort + ", Protocol: " + ipFrame.Protocol.ToString()); } } }