20 #include "modules/Module.h" 21 #include "modules/system/network-stack/Filter.h" 22 #include "pedigree/kernel/LockGuard.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/compiler.h" 25 #include "pedigree/kernel/machine/Machine.h" 26 #include "pedigree/kernel/machine/Serial.h" 27 #include "pedigree/kernel/process/Mutex.h" 28 #include "pedigree/kernel/processor/types.h" 29 #include "pedigree/kernel/time/Time.h" 46 uint32_t stored_length;
50 #define PCAP_MAGIC 0xa1b2c3d4 55 #define PCAP_NETWORK 1 57 static size_t g_FilterEntry = 0;
59 static Mutex g_PcapMutex(
false);
65 if (!Machine::instance().isInitialised())
71 if (Machine::instance().getNumSerial() < 3)
79 bool pcapLogPacket(uintptr_t packet,
size_t size)
83 Serial *pSerial = getSerial();
92 ERROR(
"pcap: packet is way too big - size is " << size);
96 static uint64_t time = 0;
102 time += Time::Multiplier::Millisecond;
105 header.ts_sec = time / Time::Multiplier::Second;
107 (time % Time::Multiplier::Second) / Time::Multiplier::Microsecond;
108 header.stored_length = size;
109 header.orig_length = size;
112 const uint8_t *headerData =
reinterpret_cast<const uint8_t *
>(&header);
113 for (
size_t i = 0; i <
sizeof(header); ++i)
115 pSerial->write(headerData[i]);
119 const uint8_t *data =
reinterpret_cast<const uint8_t *
>(packet);
120 for (
size_t i = 0; i < size; ++i)
122 pSerial->write(data[i]);
133 Serial *pSerial = getSerial();
136 NOTICE(
"pcap: could not find a useful serial port");
141 if (g_FilterEntry == static_cast<size_t>(-1))
143 NOTICE(
"pcap: could not install callback");
148 header.magic = PCAP_MAGIC;
149 header.major = PCAP_MAJOR;
150 header.minor = PCAP_MINOR;
153 header.caplen = 0xFFFF;
154 header.network = PCAP_NETWORK;
156 const uint8_t *data =
reinterpret_cast<const uint8_t *
>(&header);
157 for (
size_t i = 0; i <
sizeof(header); ++i)
159 pSerial->write(data[i]);
170 MODULE_INFO(
"pcap", &entry, &exit,
"network-stack");
virtual Serial * getSerial(size_t n)=0
void removeCallback(size_t level, size_t id)
size_t installCallback(size_t level, bool(*callback)(uintptr_t, size_t))
static NetworkFilter & instance()