Page MenuHomeFreeBSD

D55858.id173701.diff
No OneTemporary

D55858.id173701.diff

diff --git a/pcap-bpf.c b/pcap-bpf.c
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -43,9 +43,9 @@
#endif
#include <sys/utsname.h>
-#if defined(__FreeBSD__) && defined(SIOCIFCREATE2)
+#if defined(__FreeBSD__) && __FreeBSD_version < 1600006
/*
- * Add support for capturing on FreeBSD usbusN interfaces.
+ * Add support for creating FreeBSD usbusN interfaces as necessary.
*/
static const char usbus_prefix[] = "usbus";
#define USBUS_PREFIX_LEN (sizeof(usbus_prefix) - 1)
@@ -1721,7 +1721,7 @@
}
#endif /* HAVE_BSD_IEEE80211 */
-#if defined(__FreeBSD__) && defined(SIOCIFCREATE2)
+#if defined(__FreeBSD__) && __FreeBSD_version < 1600006
/*
* Attempt to destroy the usbusN interface that we created.
*/
@@ -1738,7 +1738,7 @@
}
}
}
-#endif /* defined(__FreeBSD__) && defined(SIOCIFCREATE2) */
+#endif /* defined(__FreeBSD__) && __FreeBSD_version < 1600006 */
/*
* Take this pcap out of the list of pcaps for which we
* have to take the interface out of some mode.
@@ -2037,11 +2037,11 @@
}
#endif /* __APPLE__ */
+#if defined(__FreeBSD__) && __FreeBSD_version < 1600006
/*
- * If this is FreeBSD, and the device name begins with "usbus",
- * try to create the interface if it's not available.
+ * If this is FreeBSD 15 or earlier, and the device name begins
+ * with "usbus", try to create the interface if it's not available.
*/
-#if defined(__FreeBSD__) && defined(SIOCIFCREATE2)
if (strncmp(p->opt.device, usbus_prefix, USBUS_PREFIX_LEN) == 0) {
/*
* Do we already have an interface with that name?
@@ -2115,7 +2115,7 @@
pcapint_add_to_pcaps_to_close(p);
}
}
-#endif /* defined(__FreeBSD__) && defined(SIOCIFCREATE2) */
+#endif /* defined(__FreeBSD__) && __FreeBSD_version < 1600006 */
#ifdef HAVE_ZEROCOPY_BPF
/*
@@ -2864,18 +2864,80 @@
return (1);
}
-#if defined(__FreeBSD__) && defined(SIOCIFCREATE2)
+#if defined(__FreeBSD__)
static int
-get_usb_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
+get_flags_stub(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
{
- /*
- * XXX - if there's a way to determine whether there's something
- * plugged into a given USB bus, use that to determine whether
- * this device is "connected" or not.
- */
return (0);
}
+#if __FreeBSD_version >= 1600006
+static int
+finddevs_bpf(pcap_if_list_t *devlistp, char *errbuf)
+{
+ struct bpf_iflist bi;
+ const char *name;
+ int fd;
+
+ if ((fd = bpf_open(errbuf)) < 0) {
+ /*
+ * XXX - this just means we won't have permission to
+ * open any BPF devices, an thus we don't have
+ * permission to capture on network interfaces.
+ */
+ return (-1);
+ }
+
+ memset(&bi, 0, sizeof(bi));
+ if (ioctl(fd, BIOCGETIFLIST, (caddr_t)&bi) != 0) {
+ pcapint_fmt_errmsg_for_errno(errbuf,
+ PCAP_ERRBUF_SIZE, errno, "BIOCGETIFLIST to get buffer size");
+ close(fd);
+ return (-1);
+ }
+ if (bi.bi_size == 0) {
+ /*
+ * There are no devices attached to BPF.
+ * This means that, in practice, whatever network
+ * interfaces we found don't support packet capture
+ * or injection.
+ */
+ close(fd);
+ return (0);
+ }
+
+ if ((bi.bi_ubuf = malloc(bi.bi_size)) == NULL) {
+ pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno,
+ "malloc");
+ close(fd);
+ return (-1);
+ }
+
+ if (ioctl(fd, BIOCGETIFLIST, (caddr_t)&bi) != 0) {
+ pcapint_fmt_errmsg_for_errno(errbuf,
+ PCAP_ERRBUF_SIZE, errno, "BIOCGETIFLIST to attached devics");
+ free(bi.bi_ubuf);
+ close(fd);
+ return (-1);
+ }
+ close(fd);
+
+ for (name = bi.bi_ubuf; bi.bi_count > 0;
+ bi.bi_count--, name += strlen(name) + 1)
+ /*
+ * Add only those devices that were not added via the
+ * getifaddrs() loop in pcapint_findalldevs_interfaces().
+ */
+ if (pcapint_find_or_add_dev(devlistp, name, PCAP_IF_UP,
+ get_flags_stub, NULL, errbuf) == NULL) {
+ free(bi.bi_ubuf);
+ return (-1);
+ }
+
+ free(bi.bi_ubuf);
+ return (0);
+}
+#else
static int
finddevs_usb(pcap_if_list_t *devlistp, char *errbuf)
{
@@ -2940,7 +3002,7 @@
* for each bus.
*/
if (pcapint_find_or_add_dev(devlistp, name, PCAP_IF_UP,
- get_usb_if_flags, NULL, errbuf) == NULL) {
+ get_flags_stub, NULL, errbuf) == NULL) {
free(name);
closedir(usbdir);
return (PCAP_ERROR);
@@ -2951,6 +3013,7 @@
return (0);
}
#endif
+#endif /* FreeBSD */
/*
* Get additional flags for a device, using SIOCGIFMEDIA.
@@ -3093,9 +3156,14 @@
return (-1);
#endif
-#if defined(__FreeBSD__) && defined(SIOCIFCREATE2)
+#if defined(__FreeBSD__)
+#if __FreeBSD_version >= 1600006
+ if (finddevs_bpf(devlistp, errbuf) == -1)
+ return (-1);
+#else
if (finddevs_usb(devlistp, errbuf) == -1)
return (-1);
+#endif
#endif
return (0);
diff --git a/pcap/bpf.h b/pcap/bpf.h
--- a/pcap/bpf.h
+++ b/pcap/bpf.h
@@ -86,6 +86,18 @@
extern "C" {
#endif
+/*
+ * In the past, we modified pcap/pcap.h to include the system net/bpf.h,
+ * rather than this file. However, starting around 1.10.2, libpcap requires
+ * the extern functions defined here to build. Simply reverting that local
+ * change is not a solution, because some ports with '#include <pcap.h>'
+ * such as mail/spamd and net/xprobe require the system net/bpf.h to be
+ * pulled in. To accommodate both requirements, make this header a wrapper
+ * around the system net/bpf.h, but keep the extern function definitions.
+ */
+#if defined(__FreeBSD__)
+#include <net/bpf.h>
+#else
/* BSD style release date */
#define BPF_RELEASE 199606
@@ -267,6 +279,8 @@
#endif
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
+#endif /* defined(__FreeBSD__) */
+
PCAP_AVAILABLE_0_4
PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
@@ -279,10 +293,12 @@
PCAP_AVAILABLE_0_6
PCAP_API void bpf_dump(const struct bpf_program *, int);
+#if !defined(__FreeBSD__)
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
+#endif
#ifdef __cplusplus
}
diff --git a/pcap/pcap.h b/pcap/pcap.h
--- a/pcap/pcap.h
+++ b/pcap/pcap.h
@@ -902,6 +902,7 @@
#endif /* _WIN32/MSDOS/UN*X */
+#if 0 /* Remote capture is disabled on FreeBSD */
/*
* Remote capture definitions.
*
@@ -1262,6 +1263,7 @@
PCAP_AVAILABLE_1_9_REMOTE
PCAP_API void pcap_remoteact_cleanup(void);
+#endif /* Remote capture is disabled on FreeBSD */
#ifdef __cplusplus
}

File Metadata

Mime Type
text/plain
Expires
Fri, May 29, 6:44 AM (16 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33598996
Default Alt Text
D55858.id173701.diff (6 KB)

Event Timeline