From ea9e921b627ea9e6b4042c7a36562f4699221aea Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Fri, 8 Dec 2023 00:12:15 -0500 Subject: [PATCH] Fix loopback crashes. --- src/Home/Net/Programs/TCPChatClient.ZC | 4 ++-- src/Home/Net/Programs/TCPChatServer.ZC | 7 +++++-- src/Home/Net/Protocols/Ethernet.ZC | 13 ++++++++---- src/Home/Net/Utilities/NetQueue.ZC | 29 +++++++++++++++++++++++++- src/Kernel/KGlobals.ZC | 2 +- src/System/Define.ZC | 2 +- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/Home/Net/Programs/TCPChatClient.ZC b/src/Home/Net/Programs/TCPChatClient.ZC index 2d8d6a68..4ae33e9f 100755 --- a/src/Home/Net/Programs/TCPChatClient.ZC +++ b/src/Home/Net/Programs/TCPChatClient.ZC @@ -24,8 +24,8 @@ U0 ChatMessageTask(I64) while (message = StrGet("> ",, SGF_SHIFT_ESC_EXIT)) { DocBottom(chat_display_task->put_doc); - DocPrint(chat_display_task->put_doc, - "$$BG,BLUE$$$$BLACK$$$$FG$$$$BG$$ %s\n", message); +// DocPrint(chat_display_task->put_doc, +// "$$BG,BLUE$$$$BLACK$$$$FG$$$$BG$$ %s\n", message); TCPSocketSendString(tcp, message); diff --git a/src/Home/Net/Programs/TCPChatServer.ZC b/src/Home/Net/Programs/TCPChatServer.ZC index db21e363..f7c2935c 100755 --- a/src/Home/Net/Programs/TCPChatServer.ZC +++ b/src/Home/Net/Programs/TCPChatServer.ZC @@ -37,7 +37,7 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length) { dest_socket = conn->socket; - if (dest_socket != tcp_socket) +// if (dest_socket != tcp_socket) { 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); // 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); diff --git a/src/Home/Net/Protocols/Ethernet.ZC b/src/Home/Net/Protocols/Ethernet.ZC index f2f75652..3a4de9f0 100755 --- a/src/Home/Net/Protocols/Ethernet.ZC +++ b/src/Home/Net/Protocols/Ethernet.ZC @@ -54,12 +54,17 @@ U0 EthernetFrameParse(CEthernetFrame *frame_out, U8 *frame, U16 length) U0 EthernetFrameFinish(I64 de_index) {//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 - if (!MemCompare(EthernetMACGet(), NetDriverPacketBufferGet(de_index), MAC_ADDRESS_LENGTH)) - NetQueuePush(NetDriverPacketBufferGet(de_index), NetDriverPacketLengthGet(de_index)); + // software loopback the TX packet to RX NetQueue if it's loopback + if (is_loopback) + NetQueueLazyPush(data, length); NetDriverTransmitPacketFinish(de_index); + } -EthernetGlobalsInit; \ No newline at end of file +EthernetGlobalsInit; diff --git a/src/Home/Net/Utilities/NetQueue.ZC b/src/Home/Net/Utilities/NetQueue.ZC index 1e709dda..c6eddb41 100755 --- a/src/Home/Net/Utilities/NetQueue.ZC +++ b/src/Home/Net/Utilities/NetQueue.ZC @@ -68,5 +68,32 @@ U0 NetQueuePush(U8 *data, I64 length) 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; \ No newline at end of file diff --git a/src/Kernel/KGlobals.ZC b/src/Kernel/KGlobals.ZC index c372e793..bc646ec1 100755 --- a/src/Kernel/KGlobals.ZC +++ b/src/Kernel/KGlobals.ZC @@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed CDate local_time_offset; F64 *pow10_I64, 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_full; U8 *sys_os_version_nice; diff --git a/src/System/Define.ZC b/src/System/Define.ZC index 901ce1bc..d9411781 100755 --- a/src/System/Define.ZC +++ b/src/System/Define.ZC @@ -15,7 +15,7 @@ U0 LoadDocDefines() //$LK,"DD_BOOT_HIGH_LOC_DVD",A="FF:::/System/Boot/BootDVD.ZC,DD_BOOT_HIGH_LOC_DVD"$ $TR,"LineRep"$ -$ID,2$DefinePrint("DD_ZEALOS_LOC","98,756"); +$ID,2$DefinePrint("DD_ZEALOS_LOC","99,737"); $ID,-2$ 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);