Skip to content

Commit 52eef59

Browse files
committed
DAG: Enumerate streams without trying to lock them.
Switch from dag_attach_stream64() to dag_get_stream_buffer_size(), this notably simplifies the logistics. While at it, decrement the Rx stream count for every existing Rx stream regardless of the amount of buffer memory.
1 parent c81dd51 commit 52eef59

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
7979
Make device descriptions more useful, make dagN conditional.
8080
Use PCAP_ERROR_NO_SUCH_DEVICE more in dag_activate().
8181
Validate capture device names better.
82+
Enumerate streams without trying to lock them.
8283

8384
DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
8485
Summary for 1.10.6 libpcap release (so far!)

pcap-dag.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,24 +1126,30 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
11261126
// Do not add a shorthand device for stream 0 (dagN) yet -- the
11271127
// user can disable any stream in the card configuration.
11281128
const dag_card_inf_t * inf = dag_pciinfo(dagfd); // NULL is fine
1129+
// The count includes existing streams that have no buffer memory.
11291130
rxstreams = dag_rx_get_stream_count(dagfd);
11301131
if (rxstreams < 0) {
11311132
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
11321133
errno, "dag_rx_get_stream_count");
11331134
goto failclose;
11341135
}
11351136
for(stream=0;stream<DAG_STREAM_MAX;stream+=2) {
1136-
if (0 == dag_attach_stream64(dagfd, stream, 0, 0)) {
1137-
// The Rx stream definitely exists and wasn't attached.
1138-
// Detach and proceed to the device registration below.
1139-
dag_detach_stream(dagfd, stream);
1140-
} else if (errno != EBUSY) {
1141-
// The Rx stream most likely does not exist.
1142-
continue;
1143-
}
1144-
1145-
// The Rx stream exists, whether already attached or not.
1146-
{
1137+
/*
1138+
* dag_attach_stream64() was used before to test if the
1139+
* stream exists, but it is not the best tool for the
1140+
* job because it tries to lock the stream exclusively.
1141+
* If the stream is already locked by another process,
1142+
* it fails with EBUSY, otherwise it creates a race
1143+
* condition for other processes that may be trying to
1144+
* lock the same stream at the same time. Therefore
1145+
* dag_get_stream_buffer_size64() seems to be a better
1146+
* fit.
1147+
*/
1148+
dag_ssize_t bufsize = dag_get_stream_buffer_size64(dagfd, stream);
1149+
if (bufsize < 0)
1150+
continue; // Does not exist.
1151+
// Only streams with buffer memory are usable.
1152+
if (bufsize > 0) {
11471153
description = dag_device_description (c);
11481154
// a conditional shorthand device
11491155
if (stream == 0 &&
@@ -1156,12 +1162,9 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
11561162
if (pcapint_add_dev(devlistp, name, flags, description, errbuf) == NULL) {
11571163
goto failclose;
11581164
}
1159-
1160-
rxstreams--;
1161-
if(rxstreams <= 0) {
1162-
break;
1163-
}
11641165
}
1166+
if (--rxstreams <= 0)
1167+
break;
11651168
}
11661169
dag_close(dagfd);
11671170
dagfd = -1;

0 commit comments

Comments
 (0)