//..............................................................................
//
// Ethernet Tap log filter
//

import "log_Filter.jnc"
import "io_pcap.jncx"
import "NetSnifferLog/NetSnifferLogFilter.jnc"

//..............................................................................

class EthernetTapLogFilter: NetSnifferLogFilter {
	construct(doc.PluginHost* pluginHost) {
		basetype.construct(pluginHost);
	}

protected:
	override bool filter(
		uint64_t timestamp,
		uint64_t recordCode,
		void const* p,
		size_t size
	);

	override NetSnifferLogToPcap* createLogToPcap() {
		return new EthernetTapLogToPcap(m_log);
	}
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bool EthernetTapLogFilter.filter(
	uint64_t timestamp,
	uint64_t recordCode,
	void const* p,
	size_t size
) {
	switch (recordCode) {
	case EthernetTapLogRecordCode.Packet_ch1:
	case EthernetTapLogRecordCode.Packet_ch2:
		io.PcapFilter* filter = getPcapFilter(io.PcapLinkType.Ethernet);
		return filter ? filter.match(p + MetaSize, size - MetaSize) : true;

	default:
		return true; // everything else is visible
	}
}

//..............................................................................
