Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
Fix "tcpdump -i <n>" for something-only libpcap builds.
Remove code related to Riverbed TurboCap card.
Riverbed TurboCap hardware has reached EOA as of Jun 30 2014.
Indicate no-capture and no-inject devices.
Link-layer types:
Add LINKTYPE_ETW/DLT_ETW.
Add LINKTYPE_NETANALYZER_NG/DLT_NETANALYZER_NG (pull request
Expand Down
4 changes: 3 additions & 1 deletion pcap-bt-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* the status to PCAP_IF_CONNECTION_STATUS_CONNECTED
* or PCAP_IF_CONNECTION_STATUS_DISCONNECTED.
*/
if (pcapint_add_dev(devlistp, dev_name, PCAP_IF_WIRELESS, dev_descr, err_str) == NULL)
if (pcapint_add_dev(devlistp, dev_name,
PCAP_IF_WIRELESS | PCAP_IF_NO_INJECT,
dev_descr, err_str) == NULL)
{
ret = PCAP_ERROR;
break;
Expand Down
4 changes: 3 additions & 1 deletion pcap-bt-monitor-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ bt_monitor_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* for the "any" device.
*/
if (pcapint_add_dev(devlistp, INTERFACE_NAME,
PCAP_IF_WIRELESS|PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
PCAP_IF_WIRELESS |
PCAP_IF_NO_INJECT |
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
"Bluetooth Linux Monitor", err_str) == NULL)
{
ret = PCAP_ERROR;
Expand Down
36 changes: 24 additions & 12 deletions pcap-dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,22 @@ dag_stream_long_description(const unsigned stream, const dag_size_t bufsize,
return buf;
}

static bpf_u_int32
dag_flags(const int stream)
{
/*
* A DAG card associates a link status with each physical port, but not
* with the data streams. The number of ports is a matter of hardware,
* the number of streams and how each stream associates with zero or
* more ports is a matter of how the user configures the card. In this
* context libpcap uses the streams only (i.e. "dag0" is a shorthand
* for "dag0:0"), thus the notion of link status does not apply to the
* resulting libpcap DAG capture devices.
*/
return PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE |
(RX_ONLY(stream) ? PCAP_IF_NO_INJECT : PCAP_IF_NO_CAPTURE);
}

/*
* Add all DAG devices.
*/
Expand All @@ -1397,14 +1413,6 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
int dagfd;
const char * description;
int stream, rxstreams;
// A DAG card associates a link status with each physical port, but not
// with the data streams. The number of ports is a matter of hardware,
// the number of streams and how each stream associates with zero or
// more ports is a matter of how the user configures the card. In this
// context libpcap uses the streams only (i.e. "dag0" is a shorthand
// for "dag0:0"), thus the notion of link status does not apply to the
// resulting libpcap DAG capture devices.
const bpf_u_int32 flags = PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
FILE * sysfsinfo = NULL;

/* Try all the DAGs 0-DAG_MAX_BOARDS */
Expand Down Expand Up @@ -1459,13 +1467,15 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
description = dag_device_description (c);
// a conditional shorthand device
if (stream == 0 &&
pcapint_add_dev(devlistp, name, flags, description, errbuf) == NULL)
pcapint_add_dev(devlistp, name, dag_flags(stream),
description, errbuf) == NULL)
goto failclose;
// and the stream device
snprintf(name, sizeof(name), "dag%d:%d", c, stream);
description = dag_stream_long_description(stream,
dag_get_stream_buffer_size64(dagfd, stream), inf);
if (pcapint_add_dev(devlistp, name, flags, description, errbuf) == NULL) {
if (pcapint_add_dev(devlistp, name, dag_flags(stream),
description, errbuf) == NULL) {
goto failclose;
}
}
Expand Down Expand Up @@ -1496,13 +1506,15 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
// a conditional shorthand device
description = dag_device_description(c);
if (stream == 0 &&
pcapint_add_dev(devlistp, name, flags, description, errbuf) == NULL)
pcapint_add_dev(devlistp, name, dag_flags(stream),
description, errbuf) == NULL)
goto failclose;
// and the stream device
snprintf(name, sizeof(name), "dag%u:%u", c, stream);
// TODO: Parse and describe the buffer size too.
description = dag_stream_short_description(stream);
if (pcapint_add_dev(devlistp, name, flags, description, errbuf) == NULL)
if (pcapint_add_dev(devlistp, name, dag_flags(stream),
description, errbuf) == NULL)
goto failclose;
}
fclose(sysfsinfo);
Expand Down
2 changes: 1 addition & 1 deletion pcap-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ int pcap_dpdk_findalldevs(pcap_if_list_t *devlistp, char *ebuf)
// PCI addr
rte_eth_dev_get_name_by_port(i,pci_addr);
snprintf(dpdk_desc,DPDK_DEV_DESC_MAX-1,"%s %s, MAC:%s, PCI:%s", DPDK_DESC, dpdk_name, mac_addr, pci_addr);
if (pcapint_add_dev(devlistp, dpdk_name, 0, dpdk_desc, ebuf)==NULL){
if (pcapint_add_dev(devlistp, dpdk_name, PCAP_IF_NO_INJECT, dpdk_desc, ebuf)==NULL){
ret = PCAP_ERROR;
break;
}
Expand Down
2 changes: 2 additions & 0 deletions pcap-haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
if (validate_ifname(name, errbuf) < 0)
return PCAP_ERROR;

*flags |= PCAP_IF_NO_INJECT;

if (*flags & PCAP_IF_LOOPBACK ||
! strncmp(name, "tun", strlen("tun")) ||
! strncmp(name, "tap", strlen("tap"))) {
Expand Down
2 changes: 2 additions & 0 deletions pcap-netfilter-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,12 @@ netfilter_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* XXX - what about "up" and "running"?
*/
if (pcapint_add_dev(devlistp, NFLOG_IFACE,
PCAP_IF_NO_INJECT |
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
"Linux netfilter log (NFLOG) interface", err_str) == NULL)
return -1;
if (pcapint_add_dev(devlistp, NFQUEUE_IFACE,
PCAP_IF_NO_INJECT |
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
"Linux netfilter queue (NFQUEUE) interface", err_str) == NULL)
return -1;
Expand Down
4 changes: 3 additions & 1 deletion pcap-rdmasniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ rdmasniff_findalldevs(pcap_if_list_t *devlistp, char *err_str)
* XXX - do the notions of "up", "running", or
* "connected" apply here?
*/
if (!pcapint_add_dev(devlistp, dev_list[i]->name, 0, "RDMA sniffer", err_str)) {
if (!pcapint_add_dev(devlistp, dev_list[i]->name,
PCAP_IF_NO_INJECT,
"RDMA sniffer", err_str)) {
ret = -1;
break;
}
Expand Down
5 changes: 4 additions & 1 deletion pcap-usb-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str)
* that would apply to a particular USB interface.
*/
if (pcapint_add_dev(devlistp, dev_name,
PCAP_IF_NO_INJECT |
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
"Raw USB traffic, all USB buses", err_str) == NULL)
return -1;
Expand All @@ -163,7 +164,9 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str)
* PCAP_IF_CONNECTION_STATUS_DISCONNECTED?
*/
snprintf(dev_descr, sizeof(dev_descr), "Raw USB traffic, bus number %d", n);
if (pcapint_add_dev(devlistp, dev_name, 0, dev_descr, err_str) == NULL)
if (pcapint_add_dev(devlistp, dev_name,
PCAP_IF_NO_INJECT,
dev_descr, err_str) == NULL)
return -1;
}

Expand Down
5 changes: 4 additions & 1 deletion pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,10 @@ pcap_add_any_dev(pcap_if_list_t *devlistp, char *errbuf)
* doesn't apply to the "any" device.
*/
return pcapint_add_dev(devlistp, "any",
PCAP_IF_UP|PCAP_IF_RUNNING|PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
PCAP_IF_UP |
PCAP_IF_RUNNING |
PCAP_IF_NO_INJECT |
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
any_descr, errbuf);
}

Expand Down
2 changes: 2 additions & 0 deletions pcap/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ struct pcap_if {
#define PCAP_IF_CONNECTION_STATUS_CONNECTED 0x00000010 /* connected */
#define PCAP_IF_CONNECTION_STATUS_DISCONNECTED 0x00000020 /* disconnected */
#define PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE 0x00000030 /* not applicable */
#define PCAP_IF_NO_CAPTURE 0x00000040 /* a no-capture device */
#define PCAP_IF_NO_INJECT 0x00000080 /* a no-inject device */

/*
* Representation of an interface address.
Expand Down
7 changes: 5 additions & 2 deletions pcap_activate.3pcap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP_ACTIVATE 3PCAP "3 June 2024"
.TH PCAP_ACTIVATE 3PCAP "24 November 2024"
.SH NAME
pcap_activate \- activate a capture handle
.SH SYNOPSIS
Expand Down Expand Up @@ -90,7 +90,10 @@ monitor mode.
The capture source device is not up.
.TP
.B PCAP_ERROR_CAPTURE_NOTSUP
Packet capture is not supported on the capture source.
Packet capture is not supported on the capture source. See also the
.B \%PCAP_IF_NO_CAPTURE
device flag in
.BR \%pcap_findalldevs (3PCAP).
.TP
.B PCAP_ERROR
Another error occurred.
Expand Down
18 changes: 17 additions & 1 deletion pcap_findalldevs.3pcap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP_FINDALLDEVS 3PCAP "9 August 2024"
.TH PCAP_FINDALLDEVS 3PCAP "24 November 2024"
.SH NAME
pcap_findalldevs, pcap_freealldevs \- get a list of capture devices, and
free that list
Expand Down Expand Up @@ -112,6 +112,16 @@ set if the device is a wireless interface; this includes IrDA as well as
radio-based networks such as IEEE 802.15.4 and IEEE 802.11, so it
doesn't just mean Wi-Fi
.TP
.B PCAP_IF_NO_CAPTURE
set if the device does not support packet capture in principle, thus any
attempt to capture on the device will fail with an error; note that this flag
.B not
being set does not mean all attempts to capture will succeed: some may fail
as usual because of the capture parameters, device status, permissions etc.
.TP
.B PCAP_IF_NO_INJECT
same as the above, but with regard to packet injection
.TP
.B PCAP_IF_CONNECTION_STATUS
a bitmask for an indication of whether the adapter is connected or not;
for wireless interfaces, "connected" means "associated with a network"
Expand Down Expand Up @@ -262,5 +272,11 @@ The
and
.B PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
constants became available in libpcap release 1.9.0.
.PP
The
.B PCAP_IF_NO_CAPTURE
and
.B PCAP_IF_NO_INJECT
constants became available in libpcap release 1.11.0.
.SH SEE ALSO
.BR pcap (3PCAP)
7 changes: 5 additions & 2 deletions pcap_inject.3pcap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
.TH PCAP_INJECT 3PCAP "23 November 2024"
.TH PCAP_INJECT 3PCAP "24 November 2024"
.SH NAME
pcap_inject, pcap_sendpacket \- transmit a packet
.SH SYNOPSIS
Expand Down Expand Up @@ -50,7 +50,10 @@ The same limitation applies to
.BR \%pcap_create (3PCAP)
and
.BR \%pcap_activate (3PCAP).
Note also that some devices might not support sending packets.
Note also that some devices might not support sending packets. See also the
.B \%PCAP_IF_NO_INJECT
device flag in
.BR \%pcap_findalldevs (3PCAP).
.PP
Note that, on some platforms, the link-layer header of the packet that's
sent might not be the same as the link-layer header of the packet
Expand Down
10 changes: 10 additions & 0 deletions testprogs/findalldevstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ static int ifprint(pcap_if_t *d)
printf("%sLOOPBACK", sep);
sep = ", ";
}
#ifdef PCAP_IF_NO_CAPTURE
if (d->flags & PCAP_IF_NO_CAPTURE) {
printf("%sNO_CAPTURE", sep);
sep = ", ";
}
if (d->flags & PCAP_IF_NO_INJECT) {
printf("%sNO_INJECT", sep);
sep = ", ";
}
#endif
if (d->flags & PCAP_IF_WIRELESS) {
printf("%sWIRELESS", sep);
switch (d->flags & PCAP_IF_CONNECTION_STATUS) {
Expand Down