I think it's time to get rid of all the bpf open() loops in base.
dhclient and libpcap do a plain open("/dev/bpf0", ...) since a couple of
weeks now and the upgrade issue (/dev/bpf vs. /dev/bpf0) has been fixed.
I didn't hear any other complaints in the meantime.
Ok? Too soon?
natano
Index: usr.sbin/arp/arp.c
===================================================================
RCS file: /cvs/src/usr.sbin/arp/arp.c,v
retrieving revision 1.74
diff -u -p -r1.74 arp.c
--- usr.sbin/arp/arp.c 23 Mar 2016 08:28:31 -0000 1.74
+++ usr.sbin/arp/arp.c 26 May 2016 18:29:21 -0000
@@ -808,12 +808,7 @@ sec2str(time_t total)
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef BPF_PATH_FORMAT
-#define BPF_PATH_FORMAT "/dev/bpf%u"
-#endif
-
int do_wakeup(const char *, const char *, int);
-int get_bpf(void);
int bind_if_to_bpf(const char *, int);
int get_ether(const char *, struct ether_addr *);
int send_frame(int, const struct ether_addr *);
@@ -825,9 +820,8 @@ wake(const char *ether_addr, const char
char *pname = NULL;
int bpf;
- bpf = get_bpf();
- if (bpf == -1)
- errx(1, "Failed to bind to bpf.");
+ if ((bpf = open("/dev/bpf0", O_RDWR)) == -1)
+ err(1, "Failed to bind to bpf");
if (iface == NULL) {
if (getifaddrs(&ifa) == -1)
@@ -873,25 +867,6 @@ do_wakeup(const char *eaddr, const char
if (send_frame(bpf, &macaddr) != 0)
errx(1, "Failed to send WoL frame on %s", iface);
return 0;
-}
-
-int
-get_bpf(void)
-{
- char path[PATH_MAX];
- int i, fd;
-
- for (i = 0; ; i++) {
- if (snprintf(path, sizeof(path), BPF_PATH_FORMAT, i) == -1)
- return -1;
- fd = open(path, O_RDWR);
- if (fd != -1)
- return fd;
- if (errno == EBUSY)
- continue;
- break;
- }
- return -1;
}
int
Index: usr.sbin/dhcpd/bpf.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/bpf.c,v
retrieving revision 1.13
diff -u -p -r1.13 bpf.c
--- usr.sbin/dhcpd/bpf.c 6 Feb 2016 23:50:10 -0000 1.13
+++ usr.sbin/dhcpd/bpf.c 26 May 2016 18:29:21 -0000
@@ -63,8 +63,6 @@
#include "tree.h"
#include "dhcpd.h"
-#define BPF_FORMAT "/dev/bpf%d"
-
ssize_t send_packet (struct interface_info *, struct dhcp_packet *,
size_t, struct in_addr, struct sockaddr_in *, struct hardware *);
@@ -76,26 +74,15 @@ ssize_t send_packet (struct interface_i
int
if_register_bpf(struct interface_info *info)
{
- char filename[50];
- int sock, b;
+ int sock;
- /* Open a BPF device */
- for (b = 0; 1; b++) {
- snprintf(filename, sizeof(filename), BPF_FORMAT, b);
- sock = open(filename, O_RDWR, 0);
- if (sock == -1) {
- if (errno == EBUSY)
- continue;
- else
- error("Can't find free bpf: %m");
- } else
- break;
- }
+ if ((sock = open("/dev/bpf0", O_RDWR)) == -1)
+ error("Can't open bpf device: %m");
/* Set the BPF device to point at this interface. */
if (ioctl(sock, BIOCSETIF, info->ifp) == -1)
- error("Can't attach interface %s to bpf device %s: %m",
- info->name, filename);
+ error("Can't attach interface %s to bpf device: %m",
+ info->name);
info->send_packet = send_packet;
return (sock);
Index: usr.sbin/dhcrelay/bpf.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcrelay/bpf.c,v
retrieving revision 1.10
diff -u -p -r1.10 bpf.c
--- usr.sbin/dhcrelay/bpf.c 7 Feb 2016 00:49:28 -0000 1.10
+++ usr.sbin/dhcrelay/bpf.c 26 May 2016 18:29:21 -0000
@@ -60,9 +60,6 @@
#include "dhcp.h"
#include "dhcpd.h"
-
-#define BPF_FORMAT "/dev/bpf%d"
-
/*
* Called by get_interface_list for each interface that's discovered.
* Opens a packet filter for each interface and adds it to the select
@@ -71,26 +68,16 @@
int
if_register_bpf(struct interface_info *info)
{
- char filename[50];
- int sock, b;
+ int sock;
- /* Open a BPF device */
- for (b = 0; 1; b++) {
- snprintf(filename, sizeof(filename), BPF_FORMAT, b);
- sock = open(filename, O_RDWR, 0);
- if (sock == -1) {
- if (errno == EBUSY)
- continue;
- else
- error("Can't find free bpf: %m");
- } else
- break;
- }
+ /* Open the BPF device */
+ if ((sock = open("/dev/bpf0", O_RDWR)) == -1)
+ error("Can't open bpf device: %m");
/* Set the BPF device to point at this interface. */
if (ioctl(sock, BIOCSETIF, info->ifp) == -1)
- error("Can't attach interface %s to bpf device %s: %m",
- info->name, filename);
+ error("Can't attach interface %s to bpf device: %m",
+ info->name);
return (sock);
}
Index: usr.sbin/hostapd/hostapd.c
===================================================================
RCS file: /cvs/src/usr.sbin/hostapd/hostapd.c,v
retrieving revision 1.36
diff -u -p -r1.36 hostapd.c
--- usr.sbin/hostapd/hostapd.c 22 Dec 2015 19:45:09 -0000 1.36
+++ usr.sbin/hostapd/hostapd.c 26 May 2016 18:29:21 -0000
@@ -170,28 +170,13 @@ hostapd_check_file_secrecy(int fd, const
int
hostapd_bpf_open(u_int flags)
{
- u_int i;
int fd = -1;
- char *dev;
struct bpf_version bpv;
- /*
- * Try to open the next available BPF device
- */
- for (i = 0; i < 255; i++) {
- if (asprintf(&dev, "/dev/bpf%u", i) == -1)
- hostapd_fatal("failed to allocate buffer\n");
-
- if ((fd = open(dev, flags)) != -1) {
- free(dev);
- break;
- }
-
- free(dev);
+ if ((fd = open("/dev/bpf0", flags)) == -1) {
+ hostapd_fatal("unable to open BPF device: %s\n",
+ strerror(errno));
}
-
- if (fd == -1)
- hostapd_fatal("unable to open BPF device\n");
/*
* Get and validate the BPF version
Index: usr.sbin/mopd/common/pf.c
===================================================================
RCS file: /cvs/src/usr.sbin/mopd/common/pf.c,v
retrieving revision 1.15
diff -u -p -r1.15 pf.c
--- usr.sbin/mopd/common/pf.c 27 Oct 2009 23:59:52 -0000 1.15
+++ usr.sbin/mopd/common/pf.c 26 May 2016 18:29:21 -0000
@@ -79,8 +79,6 @@ int
pfInit(char *interface, int mode, u_short protocol, int typ)
{
int fd;
- int n = 0;
- char device[sizeof "/dev/bpf000"];
struct ifreq ifr;
u_int dlt;
int immediate;
@@ -100,13 +98,7 @@ pfInit(char *interface, int mode, u_shor
insns
};
- /* Go through all the minors and find one that isn't in use. */
- do {
- snprintf(device, sizeof device, "/dev/bpf%d", n++);
- fd = open(device, mode);
- } while (fd < 0 && errno == EBUSY);
-
- if (fd < 0) {
+ if ((fd = open("/dev/bpf0", mode)) == -1) {
syslog(LOG_ERR,"pfInit: open bpf %m");
return (-1);
}
@@ -129,7 +121,7 @@ pfInit(char *interface, int mode, u_shor
return (-1);
}
if (dlt != DLT_EN10MB) {
- syslog(LOG_ERR,"pfInit: %s is not ethernet", device);
+ syslog(LOG_ERR,"pfInit: %s is not ethernet", interface);
return (-1);
}
if (promisc)
Index: usr.sbin/npppd/npppd/privsep.c
===================================================================
RCS file: /cvs/src/usr.sbin/npppd/npppd/privsep.c,v
retrieving revision 1.21
diff -u -p -r1.21 privsep.c
--- usr.sbin/npppd/npppd/privsep.c 2 Feb 2016 17:51:11 -0000 1.21
+++ usr.sbin/npppd/npppd/privsep.c 26 May 2016 18:29:21 -0000
@@ -983,7 +983,7 @@ privsep_npppd_check_open(struct PRIVSEP_
int readonly;
} const allow_paths[] = {
{ NPPPD_DIR "/", 1, 1 },
- { "/dev/bpf", 1, 0 },
+ { "/dev/bpf0", 0, 0 },
{ "/etc/resolv.conf", 0, 1 },
{ "/dev/tun", 1, 0 },
{ "/dev/pppx", 1, 0 }
Index: usr.sbin/npppd/pppoe/pppoed.c
===================================================================
RCS file: /cvs/src/usr.sbin/npppd/pppoe/pppoed.c,v
retrieving revision 1.19
diff -u -p -r1.19 pppoed.c
--- usr.sbin/npppd/pppoe/pppoed.c 17 Dec 2015 08:09:20 -0000 1.19
+++ usr.sbin/npppd/pppoe/pppoed.c 26 May 2016 18:29:21 -0000
@@ -202,9 +202,7 @@ pppoed_reload_listeners(pppoed *_this)
static int
pppoed_listener_start(pppoed_listener *_this, int restart)
{
- int i;
int log_level;
- char buf[BUFSIZ];
struct ifreq ifreq;
int ival;
int found;
@@ -275,17 +273,8 @@ pppoed_listener_start(pppoed_listener *_
goto fail;
}
- /* Open /dev/bpfXX */
- /* FIXME: /dev/bpf of NetBSD3.0 can simultaneity open */
- for (i = 0; i < 256; i++) {
- snprintf(buf, sizeof(buf), "/dev/bpf%d", i);
- if ((_this->bpf = priv_open(buf, O_RDWR)) >= 0) {
- break;
- } else if (errno == ENXIO || errno == ENOENT)
- break; /* no more entries */
- }
- if (_this->bpf < 0) {
- pppoed_log(_pppoed, log_level, "Cannot open bpf");
+ if ((_this->bpf = priv_open("/dev/bpf0", O_RDWR)) == -1) {
+ pppoed_log(_pppoed, log_level, "Cannot open bpf: %m");
goto fail;
}
@@ -327,9 +316,9 @@ pppoed_listener_start(pppoed_listener *_
pppoed_io_event, _this);
event_add(&_this->ev_bpf, NULL);
- pppoed_log(_pppoed, LOG_INFO, "Listening on %s (PPPoE) [%s] using=%s "
+ pppoed_log(_pppoed, LOG_INFO, "Listening on %s (PPPoE) [%s] "
"address=%02x:%02x:%02x:%02x:%02x:%02x", _this->listen_ifname,
- _this->tun_name, buf, _this->ether_addr[0], _this->ether_addr[1],
+ _this->tun_name, _this->ether_addr[0], _this->ether_addr[1],
_this->ether_addr[2], _this->ether_addr[3], _this->ether_addr[4],
_this->ether_addr[5]);
Index: usr.sbin/rarpd/rarpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/rarpd/rarpd.c,v
retrieving revision 1.67
diff -u -p -r1.67 rarpd.c
--- usr.sbin/rarpd/rarpd.c 19 Nov 2015 19:31:20 -0000 1.67
+++ usr.sbin/rarpd/rarpd.c 26 May 2016 18:29:21 -0000
@@ -226,25 +226,6 @@ usage(void)
exit(1);
}
-static int
-bpf_open(void)
-{
- int fd, n = 0;
- char device[sizeof "/dev/bpf0000000000"];
-
- /* Go through all the minors and find one that isn't in use. */
- do {
- (void) snprintf(device, sizeof device, "/dev/bpf%d", n++);
- fd = open(device, O_RDWR);
- } while (fd < 0 && errno == EBUSY);
-
- if (fd < 0) {
- error(FATAL, "%s: %s", device, strerror(errno));
- /* NOTREACHED */
- }
- return fd;
-}
-
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETHERTYPE_REVARP, 0, 3),
@@ -271,7 +252,8 @@ rarp_open(char *device)
struct ifreq ifr;
u_int dlt;
- fd = bpf_open();
+ if ((fd = open("/dev/bpf0", O_RDWR)) == -1)
+ error(FATAL, "/dev/bpf0: %s", strerror(errno));
/* Set immediate mode so packets are processed as they arrive. */
immediate = 1;
Index: usr.sbin/rbootd/bpf.c
===================================================================
RCS file: /cvs/src/usr.sbin/rbootd/bpf.c,v
retrieving revision 1.24
diff -u -p -r1.24 bpf.c
--- usr.sbin/rbootd/bpf.c 16 Apr 2016 22:23:01 -0000 1.24
+++ usr.sbin/rbootd/bpf.c 26 May 2016 18:29:21 -0000
@@ -61,7 +61,6 @@
#include <limits.h>
#include <ifaddrs.h>
#include "defs.h"
-#include "pathnames.h"
static int BpfFd = -1;
static unsigned int BpfLen = 0;
@@ -83,19 +82,10 @@ int
BpfOpen(void)
{
struct ifreq ifr;
- char bpfdev[32];
- int n = 0;
+ int n;
- /*
- * Open the first available BPF device.
- */
- do {
- (void) snprintf(bpfdev, sizeof bpfdev, _PATH_BPF, n++);
- BpfFd = open(bpfdev, O_RDWR);
- } while (BpfFd < 0 && (errno == EBUSY || errno == EPERM));
-
- if (BpfFd < 0) {
- syslog(LOG_ERR, "bpf: no available devices: %m");
+ if ((BpfFd = open("/dev/bpf0", O_RDWR)) == -1) {
+ syslog(LOG_ERR, "bpf: can't open device: %m");
DoExit();
}
Index: usr.sbin/rbootd/pathnames.h
===================================================================
RCS file: /cvs/src/usr.sbin/rbootd/pathnames.h,v
retrieving revision 1.5
diff -u -p -r1.5 pathnames.h
--- usr.sbin/rbootd/pathnames.h 1 May 2004 00:39:22 -0000 1.5
+++ usr.sbin/rbootd/pathnames.h 26 May 2016 18:29:21 -0000
@@ -43,7 +43,6 @@
* Author: Jeff Forys, University of Utah CSS
*/
-#define _PATH_BPF "/dev/bpf%d"
#define _PATH_RBOOTDCONF "/etc/rbootd.conf"
#define _PATH_RBOOTDDBG "/tmp/rbootd.dbg"
#define _PATH_RBOOTDDIR "/usr/mdec/rbootd"
Index: usr.sbin/rbootd/rbootd.8
===================================================================
RCS file: /cvs/src/usr.sbin/rbootd/rbootd.8,v
retrieving revision 1.15
diff -u -p -r1.15 rbootd.8
--- usr.sbin/rbootd/rbootd.8 28 Oct 2015 10:02:59 -0000 1.15
+++ usr.sbin/rbootd/rbootd.8 26 May 2016 18:29:21 -0000
@@ -135,7 +135,7 @@ Turn off debugging, do nothing if alread
.El
.Sh FILES
.Bl -tag -width /usr/libexec/rbootd -compact
-.It Pa /dev/bpf#
+.It Pa /dev/bpf0
packet-filter device
.It Pa /etc/rbootd.conf
configuration file