Do filtering on USB and Bluetooth capturing.
Do the standard userland filtering on USB and Bluetooth captures, rather than returning "success" when the filter is installed without doing anything with the filter. Also, squelch some "dereferencing type-punned pointer will break strict-aliasing rules" warnings in pcap-bt-linux.c, by using memcpy rather than pointer-casting.
This commit is contained in:
parent
f0a4bdf8e0
commit
85089fea57
|
@ -67,7 +67,6 @@ static const char rcsid[] _U_ =
|
||||||
static int bt_activate(pcap_t *);
|
static int bt_activate(pcap_t *);
|
||||||
static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *);
|
static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *);
|
||||||
static int bt_inject_linux(pcap_t *, const void *, size_t);
|
static int bt_inject_linux(pcap_t *, const void *, size_t);
|
||||||
static int bt_setfilter_linux(pcap_t *, struct bpf_program *);
|
|
||||||
static int bt_setdirection_linux(pcap_t *, pcap_direction_t);
|
static int bt_setdirection_linux(pcap_t *, pcap_direction_t);
|
||||||
static int bt_stats_linux(pcap_t *, struct pcap_stat *);
|
static int bt_stats_linux(pcap_t *, struct pcap_stat *);
|
||||||
|
|
||||||
|
@ -172,7 +171,7 @@ bt_activate(pcap_t* handle)
|
||||||
|
|
||||||
handle->read_op = bt_read_linux;
|
handle->read_op = bt_read_linux;
|
||||||
handle->inject_op = bt_inject_linux;
|
handle->inject_op = bt_inject_linux;
|
||||||
handle->setfilter_op = bt_setfilter_linux;
|
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||||
handle->setdirection_op = bt_setdirection_linux;
|
handle->setdirection_op = bt_setdirection_linux;
|
||||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||||
|
@ -301,10 +300,11 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
|
||||||
while (cmsg) {
|
while (cmsg) {
|
||||||
switch (cmsg->cmsg_type) {
|
switch (cmsg->cmsg_type) {
|
||||||
case HCI_CMSG_DIR:
|
case HCI_CMSG_DIR:
|
||||||
in = *((int *) CMSG_DATA(cmsg));
|
memcpy(&in, CMSG_DATA(cmsg), sizeof in);
|
||||||
break;
|
break;
|
||||||
case HCI_CMSG_TSTAMP:
|
case HCI_CMSG_TSTAMP:
|
||||||
pkth.ts = *((struct timeval *) CMSG_DATA(cmsg));
|
memcpy(&pkth.ts, CMSG_DATA(cmsg),
|
||||||
|
sizeof pkth.ts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
||||||
|
@ -316,9 +316,14 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
|
||||||
bthdr->direction = htonl(in != 0);
|
bthdr->direction = htonl(in != 0);
|
||||||
pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
|
pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
|
||||||
pkth.len = pkth.caplen;
|
pkth.len = pkth.caplen;
|
||||||
|
if (handle->fcode.bf_insns == NULL ||
|
||||||
|
bpf_filter(handle->fcode.bf_insns, &handle->buffer[handle->offset],
|
||||||
|
pkth.len, pkth.caplen)) {
|
||||||
callback(user, &pkth, &handle->buffer[handle->offset]);
|
callback(user, &pkth, &handle->buffer[handle->offset]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0; /* didn't pass filter */
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
|
bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
|
||||||
|
@ -357,13 +362,6 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
bt_setfilter_linux(pcap_t *p, struct bpf_program *fp)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bt_setdirection_linux(pcap_t *p, pcap_direction_t d)
|
bt_setdirection_linux(pcap_t *p, pcap_direction_t d)
|
||||||
{
|
{
|
||||||
|
|
|
@ -122,7 +122,6 @@ static int usb_read_linux(pcap_t *, int , pcap_handler , u_char *);
|
||||||
static int usb_read_linux_bin(pcap_t *, int , pcap_handler , u_char *);
|
static int usb_read_linux_bin(pcap_t *, int , pcap_handler , u_char *);
|
||||||
static int usb_read_linux_mmap(pcap_t *, int , pcap_handler , u_char *);
|
static int usb_read_linux_mmap(pcap_t *, int , pcap_handler , u_char *);
|
||||||
static int usb_inject_linux(pcap_t *, const void *, size_t);
|
static int usb_inject_linux(pcap_t *, const void *, size_t);
|
||||||
static int usb_setfilter_linux(pcap_t *, struct bpf_program *);
|
|
||||||
static int usb_setdirection_linux(pcap_t *, pcap_direction_t);
|
static int usb_setdirection_linux(pcap_t *, pcap_direction_t);
|
||||||
static void usb_cleanup_linux_mmap(pcap_t *);
|
static void usb_cleanup_linux_mmap(pcap_t *);
|
||||||
|
|
||||||
|
@ -301,7 +300,7 @@ usb_activate(pcap_t* handle)
|
||||||
handle->linktype = DLT_USB_LINUX;
|
handle->linktype = DLT_USB_LINUX;
|
||||||
|
|
||||||
handle->inject_op = usb_inject_linux;
|
handle->inject_op = usb_inject_linux;
|
||||||
handle->setfilter_op = usb_setfilter_linux;
|
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||||
handle->setdirection_op = usb_setdirection_linux;
|
handle->setdirection_op = usb_setdirection_linux;
|
||||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||||
|
@ -597,13 +596,18 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
|
||||||
|
|
||||||
got:
|
got:
|
||||||
uhdr->data_len = data_len;
|
uhdr->data_len = data_len;
|
||||||
handle->md.packets_read++;
|
|
||||||
if (pkth.caplen > handle->snapshot)
|
if (pkth.caplen > handle->snapshot)
|
||||||
pkth.caplen = handle->snapshot;
|
pkth.caplen = handle->snapshot;
|
||||||
|
|
||||||
|
if (handle->fcode.bf_insns == NULL ||
|
||||||
|
bpf_filter(handle->fcode.bf_insns, handle->buffer,
|
||||||
|
pkth.len, pkth.caplen)) {
|
||||||
|
handle->md.packets_read++;
|
||||||
callback(user, &pkth, handle->buffer);
|
callback(user, &pkth, handle->buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0; /* didn't pass filter */
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
usb_inject_linux(pcap_t *handle, const void *buf, size_t size)
|
usb_inject_linux(pcap_t *handle, const void *buf, size_t size)
|
||||||
|
@ -688,12 +692,6 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
usb_setfilter_linux(pcap_t *p, struct bpf_program *fp)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
usb_setdirection_linux(pcap_t *p, pcap_direction_t d)
|
usb_setdirection_linux(pcap_t *p, pcap_direction_t d)
|
||||||
{
|
{
|
||||||
|
@ -767,11 +765,17 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha
|
||||||
pkth.ts.tv_sec = info.hdr->ts_sec;
|
pkth.ts.tv_sec = info.hdr->ts_sec;
|
||||||
pkth.ts.tv_usec = info.hdr->ts_usec;
|
pkth.ts.tv_usec = info.hdr->ts_usec;
|
||||||
|
|
||||||
|
if (handle->fcode.bf_insns == NULL ||
|
||||||
|
bpf_filter(handle->fcode.bf_insns, handle->buffer,
|
||||||
|
pkth.len, pkth.caplen)) {
|
||||||
handle->md.packets_read++;
|
handle->md.packets_read++;
|
||||||
callback(user, &pkth, handle->buffer);
|
callback(user, &pkth, handle->buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0; /* didn't pass filter */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
|
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
|
||||||
* <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
|
* <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
|
||||||
|
@ -841,10 +845,14 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
|
||||||
pkth.ts.tv_sec = hdr->ts_sec;
|
pkth.ts.tv_sec = hdr->ts_sec;
|
||||||
pkth.ts.tv_usec = hdr->ts_usec;
|
pkth.ts.tv_usec = hdr->ts_usec;
|
||||||
|
|
||||||
|
if (handle->fcode.bf_insns == NULL ||
|
||||||
|
bpf_filter(handle->fcode.bf_insns, (u_char*) hdr,
|
||||||
|
pkth.len, pkth.caplen)) {
|
||||||
handle->md.packets_read++;
|
handle->md.packets_read++;
|
||||||
callback(user, &pkth, (u_char*) hdr);
|
callback(user, &pkth, (u_char*) hdr);
|
||||||
packets++;
|
packets++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* with max_packets <= 0 we stop afer the first chunk*/
|
/* with max_packets <= 0 we stop afer the first chunk*/
|
||||||
if ((max_packets <= 0) || (packets == max_packets))
|
if ((max_packets <= 0) || (packets == max_packets))
|
||||||
|
|
Reference in New Issue