ETHER: Fix possible race conditions when closing a network device

Added pcap version to the SCP output of SHOW VERSION command.
This commit is contained in:
Mark Pizzolato 2019-08-13 20:04:09 -07:00
parent d6f9c586d1
commit 6a193c032d
4 changed files with 23 additions and 11 deletions

3
scp.c
View file

@ -5866,6 +5866,9 @@ if (flag) {
#endif #endif
fprintf (st, "\n OS clock resolution: %dms", os_tick_size); fprintf (st, "\n OS clock resolution: %dms", os_tick_size);
fprintf (st, "\n Time taken by msleep(1): %dms", os_ms_sleep_1); fprintf (st, "\n Time taken by msleep(1): %dms", os_ms_sleep_1);
if (eth_version ())
fprintf (st, "\n Ethernet packet info: %s", eth_version());
fprintf (st, "\n Time taken by msleep(1): %dms", os_ms_sleep_1);
#if defined(__VMS) #if defined(__VMS)
if (1) { if (1) {
char *arch = char *arch =

View file

@ -750,7 +750,6 @@ static char* (*p_pcap_lib_version) (void);
static ETH_DEV **eth_open_devices = NULL; static ETH_DEV **eth_open_devices = NULL;
static int eth_open_device_count = 0; static int eth_open_device_count = 0;
static t_bool eth_show_active = FALSE;
#if defined (USE_NETWORK) || defined (USE_SHARED) #if defined (USE_NETWORK) || defined (USE_SHARED)
static void _eth_add_to_open_list (ETH_DEV* dev) static void _eth_add_to_open_list (ETH_DEV* dev)
@ -778,7 +777,6 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, CONST void* desc)
ETH_LIST list[ETH_MAX_DEVICE]; ETH_LIST list[ETH_MAX_DEVICE];
int number; int number;
eth_show_active = TRUE;
number = eth_devices(ETH_MAX_DEVICE, list); number = eth_devices(ETH_MAX_DEVICE, list);
fprintf(st, "ETH devices:\n"); fprintf(st, "ETH devices:\n");
if (number == -1) if (number == -1)
@ -794,9 +792,6 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, CONST void* desc)
for (i=0; i<number; i++) for (i=0; i<number; i++)
fprintf(st," eth%d\t%-*s (%s)\n", i, (int)min, list[i].name, list[i].desc); fprintf(st," eth%d\t%-*s (%s)\n", i, (int)min, list[i].name, list[i].desc);
} }
if (p_pcap_lib_version) {
fprintf(st, "%s\n", p_pcap_lib_version());
}
if (eth_open_device_count) { if (eth_open_device_count) {
int i; int i;
char desc[ETH_DEV_DESC_MAX], *d; char desc[ETH_DEV_DESC_MAX], *d;
@ -811,7 +806,6 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, CONST void* desc)
eth_show_dev (st, eth_open_devices[i]); eth_show_dev (st, eth_open_devices[i]);
} }
} }
eth_show_active = FALSE;
return SCPE_OK; return SCPE_OK;
} }
@ -964,6 +958,8 @@ t_stat eth_filter_hash (ETH_DEV* dev, int addr_count, ETH_MAC* const addresses,
{return SCPE_NOFNC;} {return SCPE_NOFNC;}
int eth_devices (int max, ETH_LIST* dev) int eth_devices (int max, ETH_LIST* dev)
{return -1;} {return -1;}
const char *eth_version (void)
{return NULL;}
void eth_show_dev (FILE* st, ETH_DEV* dev) void eth_show_dev (FILE* st, ETH_DEV* dev)
{} {}
static int _eth_get_system_id (char *buf, size_t buf_size) static int _eth_get_system_id (char *buf, size_t buf_size)
@ -1188,11 +1184,6 @@ int load_pcap(void) {
load_function("pcap_setfilter", (_func *) &p_pcap_setfilter); load_function("pcap_setfilter", (_func *) &p_pcap_setfilter);
load_function("pcap_setnonblock", (_func *) &p_pcap_setnonblock); load_function("pcap_setnonblock", (_func *) &p_pcap_setnonblock);
load_function("pcap_lib_version", (_func *) &p_pcap_lib_version); load_function("pcap_lib_version", (_func *) &p_pcap_lib_version);
if ((lib_loaded == 1) && (!eth_show_active)) {
/* log successful load */
sim_messagef (SCPE_OK, "%s\n", p_pcap_lib_version());
}
break; break;
default: /* loaded or failed */ default: /* loaded or failed */
break; break;
@ -1220,6 +1211,14 @@ int pcap_compile(pcap_t* a, struct bpf_program* b, const char* c, int d, bpf_u_i
} }
} }
const char *pcap_lib_version(void) {
if ((load_pcap() != 0) && (p_pcap_lib_version != NULL)) {
return p_pcap_lib_version();
} else {
return NULL;
}
}
int pcap_datalink(pcap_t* a) { int pcap_datalink(pcap_t* a) {
if (a && (load_pcap() != 0)) { if (a && (load_pcap() != 0)) {
return p_pcap_datalink(a); return p_pcap_datalink(a);
@ -1903,6 +1902,8 @@ sim_debug(dev->dbit, dev->dptr, "Writer Thread Starting\n");
pthread_mutex_lock (&dev->writer_lock); pthread_mutex_lock (&dev->writer_lock);
while (dev->handle) { while (dev->handle) {
pthread_cond_wait (&dev->writer_cond, &dev->writer_lock); pthread_cond_wait (&dev->writer_cond, &dev->writer_lock);
if (dev->handle == NULL) /* Shutting down? */
break;
while (NULL != (request = dev->write_requests)) { while (NULL != (request = dev->write_requests)) {
/* Pull buffer off request list */ /* Pull buffer off request list */
dev->write_requests = request->next; dev->write_requests = request->next;
@ -2437,6 +2438,11 @@ _eth_remove_from_open_list (dev);
return SCPE_OK; return SCPE_OK;
} }
const char *eth_version (void)
{
return pcap_lib_version();
}
t_stat eth_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr) t_stat eth_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr)
{ {
fprintf (st, "%s attach help\n\n", dptr->name); fprintf (st, "%s attach help\n\n", dptr->name);

View file

@ -349,6 +349,7 @@ t_stat eth_filter_hash (ETH_DEV* dev, int addr_count, /* set filter on incomin
ETH_MULTIHASH* const hash); ETH_MULTIHASH* const hash);
t_stat eth_check_address_conflict (ETH_DEV* dev, t_stat eth_check_address_conflict (ETH_DEV* dev,
ETH_MAC* const address); ETH_MAC* const address);
const char *eth_version (void); /* Version of dynamically loaded library (pcap) */
int eth_devices (int max, ETH_LIST* dev); /* get ethernet devices on host */ int eth_devices (int max, ETH_LIST* dev); /* get ethernet devices on host */
void eth_setcrc (ETH_DEV* dev, int need_crc); /* enable/disable CRC mode */ void eth_setcrc (ETH_DEV* dev, int need_crc); /* enable/disable CRC mode */
t_stat eth_set_async (ETH_DEV* dev, int latency); /* set read behavior to be async */ t_stat eth_set_async (ETH_DEV* dev, int latency); /* set read behavior to be async */

View file

@ -595,6 +595,8 @@ fd_set rfds, wfds, xfds;
fd_set save_rfds, save_wfds, save_xfds; fd_set save_rfds, save_wfds, save_xfds;
int nfds; int nfds;
if (!slirp) /* Not active? */
return -1; /* That's an error */
/* Populate the GPollFDs from slirp */ /* Populate the GPollFDs from slirp */
g_array_set_size (slirp->gpollfds, 1); /* Leave the doorbell chime alone */ g_array_set_size (slirp->gpollfds, 1); /* Leave the doorbell chime alone */
slirp_pollfds_fill(slirp->gpollfds, &slirp_timeout); slirp_pollfds_fill(slirp->gpollfds, &slirp_timeout);