mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
Implement initial driver-independent loopback networking.
This commit is contained in:
parent
24e4ae8f2e
commit
514cfe9f88
3 changed files with 47 additions and 18 deletions
|
@ -512,20 +512,28 @@ U0 PCNetTransmitPacketFinish(I64 de_index)
|
|||
|
||||
CPCNetDescriptorEntry *entry = &pcnet.tx_de_buffer[de_index * sizeof(CPCNetDescriptorEntry)];
|
||||
|
||||
// check the TX packet MAC against local MAC, if they match: software loopback the TX packet to RX NetQueue
|
||||
if (!MemCompare(EthernetMACGet(), pcnet.tx_buffer_addr + de_index * ETHERNET_FRAME_SIZE, 6))
|
||||
NetQueuePush(pcnet.tx_buffer_addr + de_index * ETHERNET_FRAME_SIZE, U16_MAX - (entry->status1 & 0xFFFF) + 1);
|
||||
|
||||
Bts(&entry->status1, PCNET_DESCRIPTORf_OWN);
|
||||
NetLog("PCNET FINISH TX PACKET: TX DE index: %X, OWN bit of entry at entry: %b.",
|
||||
de_index, Bt(&entry->status1, PCNET_DESCRIPTORf_OWN));
|
||||
}
|
||||
|
||||
U0 EthernetFrameFinish(I64 de_index)
|
||||
{//Alias for driver Finish TX function.
|
||||
U0 NetDriverTransmitPacketFinish(I64 de_index)
|
||||
{//Alias for driver-specific Finish TX function.
|
||||
PCNetTransmitPacketFinish(de_index);
|
||||
}
|
||||
|
||||
I64 NetDriverPacketBufferGet(I64 de_index)
|
||||
{
|
||||
return pcnet.tx_buffer_addr + de_index * ETHERNET_FRAME_SIZE;
|
||||
}
|
||||
|
||||
I64 NetDriverPacketLengthGet(I64 de_index)
|
||||
{
|
||||
CPCNetDescriptorEntry *entry = &pcnet.tx_de_buffer[de_index * sizeof(CPCNetDescriptorEntry)];
|
||||
|
||||
return U16_MAX - (entry->status1 & 0xFFFF) + 1;
|
||||
}
|
||||
|
||||
I64 PCNetPacketReceive(U8 **packet_buffer_out, U16 *packet_length_out)
|
||||
{/* Receives the packet at the current RX DE index. Parameters
|
||||
are both pointers, since we modify the value at the packet_buffer_out,
|
||||
|
|
|
@ -167,15 +167,15 @@ I64 EthernetFrameAllocate(U8 **buffer_out, U8 *src_addr, U8 *dst_addr,
|
|||
|
||||
I64 index;
|
||||
|
||||
if (!MemCompare(dst_addr, &VirtioNet.mac, 6)) {
|
||||
frame = loopback_frame;
|
||||
loopback_length = length;
|
||||
index = I64_MAX;
|
||||
} else {
|
||||
// if (!MemCompare(dst_addr, &VirtioNet.mac, 6)) {
|
||||
// frame = loopback_frame;
|
||||
// loopback_length = length;
|
||||
// index = I64_MAX;
|
||||
// } else {
|
||||
index = @virtio_net_alloc_tx_packet(&frame, 14 + length/*, flags*/);
|
||||
if (index < 0)
|
||||
return index;
|
||||
}
|
||||
// }
|
||||
|
||||
MemCopy(frame + 0, dst_addr, 6);
|
||||
MemCopy(frame + 6, src_addr, 6);
|
||||
|
@ -186,15 +186,26 @@ I64 EthernetFrameAllocate(U8 **buffer_out, U8 *src_addr, U8 *dst_addr,
|
|||
return index;
|
||||
}
|
||||
|
||||
I64 EthernetFrameFinish(I64 index) {
|
||||
if (index == I64_MAX && loopback_frame && loopback_length) {
|
||||
NetQueuePush(loopback_frame, loopback_length);
|
||||
loopback_length = 0;
|
||||
return 0;
|
||||
}
|
||||
//I64 EthernetFrameFinish(I64 index) {
|
||||
I64 NetDriverTransmitPacketFinish(I64 index) {
|
||||
// if (index == I64_MAX && loopback_frame && loopback_length) {
|
||||
// NetQueuePush(loopback_frame, loopback_length);
|
||||
// loopback_length = 0;
|
||||
// return 0;
|
||||
// }
|
||||
return @virtio_net_finish_tx_packet(index);
|
||||
}
|
||||
|
||||
I64 NetDriverPacketBufferGet(I64 de_index)
|
||||
{
|
||||
return tx_buffers + de_index * ETHERNET_FRAME_SIZE;
|
||||
}
|
||||
|
||||
I64 NetDriverPacketLengthGet(I64 de_index)
|
||||
{ // TODO: ... de_index in Alec's VirtIO-Net driver don't match up to any way to get packet length...
|
||||
return 0;
|
||||
}
|
||||
|
||||
U8 *EthernetMACGet() { return &VirtioNet.mac; }
|
||||
|
||||
I64 @virtio_net_init() {
|
||||
|
|
|
@ -52,4 +52,14 @@ U0 EthernetFrameParse(CEthernetFrame *frame_out, U8 *frame, U16 length)
|
|||
frame_out->length = length - ETHERNET_MAC_HEADER_LENGTH - 4; // He has a comment literally just saying "??". + or - 4?
|
||||
}
|
||||
|
||||
U0 EthernetFrameFinish(I64 de_index)
|
||||
{//Alias for generic driver Finish TX function.
|
||||
|
||||
// check the TX packet MAC against local MAC, if they match: software loopback the TX packet to RX NetQueue
|
||||
if (!MemCompare(EthernetMACGet(), NetDriverPacketBufferGet(de_index), MAC_ADDRESS_LENGTH))
|
||||
NetQueuePush(NetDriverPacketBufferGet(de_index), NetDriverPacketLengthGet(de_index));
|
||||
|
||||
NetDriverTransmitPacketFinish(de_index);
|
||||
}
|
||||
|
||||
EthernetGlobalsInit;
|
Loading…
Reference in a new issue