Skip to content

Commit

Permalink
Optimistically revert mutex that was needed with WinPcap. Npcap likel…
Browse files Browse the repository at this point in the history
…y is unaffected.
  • Loading branch information
bonsaiviking committed Oct 3, 2018
1 parent 5a505b9 commit 30db709
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 53 deletions.
5 changes: 4 additions & 1 deletion libdnet-stripped/NMAP_MODIFICATIONS
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ index 3c09f9c..77225b6 100644
/* Loop through all the pcap devices until we find a match. */
selected = NULL;

o Use a mutex on Windows to avoid a hang when accessing WinPCAP driver.
o (LATER REVERTED) Use a mutex on Windows to avoid a hang when accessing WinPCAP driver.
Reported by multiple users on Windows 8.1 and Windows Server 2012 R2.
Seems to hang when the WinPCAP driver is accessed via OpenServiceA by
multiple processes at once. Users report that this change, which uses a
Expand Down Expand Up @@ -2408,3 +2408,6 @@ index 434142e..31b9f8c 100644
ipbuf, &type, &flags, macbuf, maskbuf, devbuf);

if (i < 4 || (flags & ATF_COM) == 0)

o REVERTED the change that added a mutex protecting calls to OpenServiceA. We
are optimistic that Npcap does not have the reported problem.
18 changes: 0 additions & 18 deletions libdnet-stripped/src/eth-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,13 @@ eth_open(const char *device)
{
eth_t *eth;
char pcapdev[128];
HANDLE pcapMutex;
DWORD wait;

if (eth_get_pcap_devname(device, pcapdev, sizeof(pcapdev)) != 0)
return (NULL);

if ((eth = calloc(1, sizeof(*eth))) == NULL)
return (NULL);
pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex");
wait = WaitForSingleObject(pcapMutex, INFINITE);
eth->lpa = PacketOpenAdapter(pcapdev);
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
if (eth->lpa == NULL) {
eth_close(eth);
return (NULL);
Expand Down Expand Up @@ -120,21 +112,11 @@ eth_send(eth_t *eth, const void *buf, size_t len)
eth_t *
eth_close(eth_t *eth)
{
HANDLE pcapMutex;
DWORD wait;
if (eth != NULL) {
if (eth->pkt != NULL)
PacketFreePacket(eth->pkt);
if (eth->lpa != NULL)
{
pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex");
wait = WaitForSingleObject(pcapMutex, INFINITE);
PacketCloseAdapter(eth->lpa);
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
}
free(eth);
}
return (NULL);
Expand Down
12 changes: 0 additions & 12 deletions libdnet-stripped/src/intf-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ intf_get_pcap_devname_cached(const char *intf_name, char *pcapdev, int pcapdevle
pcap_if_t *pdev;
intf_t *intf;
char errbuf[PCAP_ERRBUF_SIZE];
HANDLE pcapMutex;
DWORD wait;

if ((intf = intf_open()) == NULL)
return (-1);
Expand All @@ -543,20 +541,10 @@ intf_get_pcap_devname_cached(const char *intf_name, char *pcapdev, int pcapdevle
}

if (pcapdevs == NULL) {
pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex");
wait = WaitForSingleObject(pcapMutex, INFINITE);
if (pcap_findalldevs(&pcapdevs, errbuf) == -1) {
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
intf_close(intf);
return (-1);
}
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
}

/* Loop through all the pcap devices until we find a match. */
Expand Down
6 changes: 0 additions & 6 deletions libnetutil/netutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4094,8 +4094,6 @@ pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_m
with what we have then ... */
Strncpy(pcapdev, device, sizeof(pcapdev));
}
HANDLE pcapMutex = CreateMutex(NULL, 0, TEXT("Global\\DnetPcapHangAvoidanceMutex"));
DWORD wait = WaitForSingleObject(pcapMutex, INFINITE);
#else
Strncpy(pcapdev, device, sizeof(pcapdev));
#endif
Expand Down Expand Up @@ -4145,10 +4143,6 @@ pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_m
#endif /* not __amigaos__ */

#ifdef WIN32
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
/* We want any responses back ASAP */
/* This is unnecessary with Npcap since libpcap calls PacketSetMinToCopy(0)
* based on immediate mode. Have not determined if it is needed for WinPcap
Expand Down
8 changes: 0 additions & 8 deletions mswin32/winfix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ void win_init()
__try
#endif
{
HANDLE pcapMutex;
DWORD wait;
ULONG len = sizeof(pcaplist);

o.have_pcap = true;
Expand All @@ -342,13 +340,7 @@ void win_init()
if (pcap_driver == PCAP_DRIVER_NPCAP)
init_npcap_dll_path();

pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex");
wait = WaitForSingleObject(pcapMutex, INFINITE);
PacketGetAdapterNames(pcaplist, &len);
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);

#ifdef _MSC_VER
if(FAILED(__HrLoadAllImportsForDll("wpcap.dll")))
Expand Down
8 changes: 0 additions & 8 deletions nping/winfix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ void win_init()
__try
#endif
{
HANDLE pcapMutex;
DWORD wait;
ULONG len = sizeof(pcaplist);

if(o.getDebugging() >= DBG_2) printf("Trying to initialize Windows pcap engine\n");
Expand All @@ -341,13 +339,7 @@ void win_init()
if (pcap_driver == PCAP_DRIVER_NPCAP)
init_npcap_dll_path();

pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex");
wait = WaitForSingleObject(pcapMutex, INFINITE);
PacketGetAdapterNames(pcaplist, &len);
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);

#ifdef _MSC_VER
if(FAILED(__HrLoadAllImportsForDll("wpcap.dll")))
Expand Down

0 comments on commit 30db709

Please sign in to comment.