Ported the WinPcap thread's packet sanity checks to the SLiRP thread - SLiRP is now more stable;

Unified all three NIC families' DP8390 chip implementations in net_dp8390.c/h;
Some fixes for the WD8013EBT NIC;
Network status bar icon updating is now done at WinPcap/SLiRP handler level, not at the NIC level anymore.
This commit is contained in:
OBattler
2018-10-19 00:37:25 +02:00
parent c663147d11
commit d56df03a53
8 changed files with 1737 additions and 3351 deletions

View File

@@ -8,7 +8,7 @@
*
* Handle SLiRP library processing.
*
* Version: @(#)net_slirp.c 1.0.4 2018/10/02
* Version: @(#)net_slirp.c 1.0.5 2018/10/17
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
*
@@ -56,6 +56,7 @@
#include "../86box.h"
#include "../device.h"
#include "../plat.h"
#include "../ui.h"
#include "network.h"
@@ -67,22 +68,22 @@ static event_t *poll_state;
#ifdef ENABLE_SLIRP_LOG
int slirp_do_log = ENABLE_SLIRP_LOG;
#endif
static void
slirp_log(const char *format, ...)
slirp_log(const char *fmt, ...)
{
#ifdef ENABLE_SLIRP_LOG
va_list ap;
if (slirp_do_log) {
va_start(ap, format);
pclog_ex(format, ap);
va_start(ap, fmt);
pclog_ex(fmt, ap);
va_end(ap);
}
#endif
}
#else
#define slirp_log(fmt, ...)
#endif
static void
@@ -116,10 +117,14 @@ slirp_tic(void)
/* Handle the receiving of frames. */
static void
poll_thread(UNUSED(void *arg))
poll_thread(void *arg)
{
uint8_t *mac = (uint8_t *)arg;
struct queuepacket *qp;
uint32_t mac_cmp32[2];
uint16_t mac_cmp16[2];
event_t *evt;
int data_valid = 0;
slirp_log("SLiRP: polling started.\n");
thread_set_event(poll_state);
@@ -141,18 +146,37 @@ poll_thread(UNUSED(void *arg))
if (slirpq == NULL) break;
/* Wait for the next packet to arrive. */
data_valid = 0;
if (QueuePeek(slirpq) != 0) {
/* Grab a packet from the queue. */
ui_sb_update_icon(SB_NETWORK, 1);
qp = QueueDelete(slirpq);
slirp_log("SLiRP: inQ:%d got a %dbyte packet @%08lx\n",
QueuePeek(slirpq), qp->len, qp);
poll_card->rx(poll_card->priv, (uint8_t *)qp->data, qp->len);
/* Received MAC. */
mac_cmp32[0] = *(uint32_t *)(((uint8_t *)qp->data)+6);
mac_cmp16[0] = *(uint16_t *)(((uint8_t *)qp->data)+10);
/* Local MAC. */
mac_cmp32[1] = *(uint32_t *)mac;
mac_cmp16[1] = *(uint16_t *)(mac+4);
if ((mac_cmp32[0] != mac_cmp32[1]) ||
(mac_cmp16[0] != mac_cmp16[1])) {
poll_card->rx(poll_card->priv, (uint8_t *)qp->data, qp->len);
data_valid = 1;
}
/* Done with this one. */
free(qp);
} else {
/* If we did not get anything, wait a while. */
}
/* If we did not get anything, wait a while. */
if (!data_valid) {
ui_sb_update_icon(SB_NETWORK, 0);
thread_wait_event(evt, 10);
}
@@ -194,6 +218,8 @@ net_slirp_init(void)
int
net_slirp_reset(const netcard_t *card, uint8_t *mac)
{
ui_sb_update_icon(SB_NETWORK, 0);
/* Save the callback info. */
poll_card = card;
@@ -211,6 +237,8 @@ net_slirp_close(void)
{
queueADT sl;
ui_sb_update_icon(SB_NETWORK, 0);
if (slirpq == NULL) return;
slirp_log("SLiRP: closing.\n");
@@ -245,11 +273,15 @@ net_slirp_in(uint8_t *pkt, int pkt_len)
{
if (slirpq == NULL) return;
ui_sb_update_icon(SB_NETWORK, 1);
network_busy(1);
slirp_input((const uint8_t *)pkt, pkt_len);
network_busy(0);
ui_sb_update_icon(SB_NETWORK, 0);
}