Fix loopback crashes.

This commit is contained in:
GutPuncher 2023-12-08 00:12:15 -05:00
parent 3bdb731dad
commit ea9e921b62
No known key found for this signature in database
GPG key ID: 38CE0A7B6841D1C7
6 changed files with 46 additions and 11 deletions

View file

@ -24,8 +24,8 @@ U0 ChatMessageTask(I64)
while (message = StrGet("> ",, SGF_SHIFT_ESC_EXIT)) while (message = StrGet("> ",, SGF_SHIFT_ESC_EXIT))
{ {
DocBottom(chat_display_task->put_doc); DocBottom(chat_display_task->put_doc);
DocPrint(chat_display_task->put_doc, // DocPrint(chat_display_task->put_doc,
"$$BG,BLUE$$$$BLACK$$<local>$$FG$$$$BG$$ %s\n", message); // "$$BG,BLUE$$$$BLACK$$<local>$$FG$$$$BG$$ %s\n", message);
TCPSocketSendString(tcp, message); TCPSocketSendString(tcp, message);

View file

@ -37,7 +37,7 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length)
{ {
dest_socket = conn->socket; dest_socket = conn->socket;
if (dest_socket != tcp_socket) // if (dest_socket != tcp_socket)
{ {
addr.address = EndianU32(dest_socket->destination_address(CSocketAddressIPV4).address.address); addr.address = EndianU32(dest_socket->destination_address(CSocketAddressIPV4).address.address);
@ -51,7 +51,10 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length)
ip_string = NetworkToPresentation(AF_INET, &addr); ip_string = NetworkToPresentation(AF_INET, &addr);
// TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ? // TODO: is NetworkToPresentation backwards? or, do socket addrs store BE or LE ?
message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s>$$FG$$$$BG$$ %%0%dts", ip_string, length); if (dest_socket == tcp_socket)
message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s (you)>$$FG$$$$BG$$ %%0%dts", ip_string, length);
else
message_prefix = MStrPrint("$$BG,PURPLE$$$$BLACK$$<%s>$$FG$$$$BG$$ %%0%dts", ip_string, length);
message = MStrPrint(message_prefix, buffer); message = MStrPrint(message_prefix, buffer);

View file

@ -54,12 +54,17 @@ U0 EthernetFrameParse(CEthernetFrame *frame_out, U8 *frame, U16 length)
U0 EthernetFrameFinish(I64 de_index) U0 EthernetFrameFinish(I64 de_index)
{//Alias for generic driver Finish TX function. {//Alias for generic driver Finish TX function.
U8 *data = NetDriverPacketBufferGet(de_index);
I64 length = NetDriverPacketLengthGet(de_index);
U8 *mac = EthernetMACGet();
Bool is_loopback = !MemCompare(mac, data, MAC_ADDRESS_LENGTH); // check the TX packet MAC against local MAC
// check the TX packet MAC against local MAC, if they match: software loopback the TX packet to RX NetQueue // software loopback the TX packet to RX NetQueue if it's loopback
if (!MemCompare(EthernetMACGet(), NetDriverPacketBufferGet(de_index), MAC_ADDRESS_LENGTH)) if (is_loopback)
NetQueuePush(NetDriverPacketBufferGet(de_index), NetDriverPacketLengthGet(de_index)); NetQueueLazyPush(data, length);
NetDriverTransmitPacketFinish(de_index); NetDriverTransmitPacketFinish(de_index);
} }
EthernetGlobalsInit; EthernetGlobalsInit;

View file

@ -68,5 +68,32 @@ U0 NetQueuePush(U8 *data, I64 length)
MPInt(I_NETHANDLER, INT_DEST_CPU); MPInt(I_NETHANDLER, INT_DEST_CPU);
} }
U0 NetQueueLazyPull()
{
PUSHFD
CLI
if (net_queue->next != net_queue)
{
NetLog("NETQUEUE LAZY PULL: Generating NetHandler interrupt.");
MPInt(I_NETHANDLER, INT_DEST_CPU);
}
POPFD
}
U0 NetQueueLazyPush(U8 *data, I64 length)
{ // Push into NetQueue, don't trigger interrupt in this func.
// Trigger interrupt by Spawn-ing another Task to check queue.
CNetQueueEntry *entry = CAlloc(sizeof(CNetQueueEntry));
entry->packet_length = length;
MemCopy(entry->frame, data, length);
QueueInsert(entry, net_queue->last);
Spawn(&NetQueueLazyPull,, "NetQueueLazyPull");
}
NetQueueInit;
NetQueueInit;

View file

@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed
CDate local_time_offset; CDate local_time_offset;
F64 *pow10_I64, F64 *pow10_I64,
sys_os_version = 2.03; sys_os_version = 2.03;
U64 sys_os_version_sub = 107; U64 sys_os_version_sub = 108;
U8 *sys_os_version_str; U8 *sys_os_version_str;
U8 *sys_os_version_full; U8 *sys_os_version_full;
U8 *sys_os_version_nice; U8 *sys_os_version_nice;

View file

@ -15,7 +15,7 @@ U0 LoadDocDefines()
//$LK,"DD_BOOT_HIGH_LOC_DVD",A="FF:::/System/Boot/BootDVD.ZC,DD_BOOT_HIGH_LOC_DVD"$ //$LK,"DD_BOOT_HIGH_LOC_DVD",A="FF:::/System/Boot/BootDVD.ZC,DD_BOOT_HIGH_LOC_DVD"$
$TR,"LineRep"$ $TR,"LineRep"$
$ID,2$DefinePrint("DD_ZEALOS_LOC","98,756"); $ID,2$DefinePrint("DD_ZEALOS_LOC","99,737");
$ID,-2$ $ID,-2$
DefinePrint("DD_MP_VECT", "%08X", MP_VECT_ADDR); DefinePrint("DD_MP_VECT", "%08X", MP_VECT_ADDR);
DefinePrint("DD_MP_VECT_END", "%08X", MP_VECT_ADDR + COREAP_16BIT_INIT_END - COREAP_16BIT_INIT - 1); DefinePrint("DD_MP_VECT_END", "%08X", MP_VECT_ADDR + COREAP_16BIT_INIT_END - COREAP_16BIT_INIT - 1);