summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient/bpf.c
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-02-12 13:15:50 +0000
committerkrw <krw@openbsd.org>2017-02-12 13:15:50 +0000
commit385a6373a5dfa6ec0381515b88c6a52fc9942024 (patch)
tree14586c3dfa7509247944d62f181838ffbee229a4 /sbin/dhclient/bpf.c
parentRemove incorrect if statement (diff)
downloadwireguard-openbsd-385a6373a5dfa6ec0381515b88c6a52fc9942024.tar.xz
wireguard-openbsd-385a6373a5dfa6ec0381515b88c6a52fc9942024.zip
Switch from 'legacy' errwarn.c to standard daemon logging functions.
No objections heard. Feedback from millert@ guenther@
Diffstat (limited to 'sbin/dhclient/bpf.c')
-rw-r--r--sbin/dhclient/bpf.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c
index 9d1f6051cad..12278f6256f 100644
--- a/sbin/dhclient/bpf.c
+++ b/sbin/dhclient/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.44 2016/08/31 12:57:31 mpi Exp $ */
+/* $OpenBSD: bpf.c,v 1.45 2017/02/12 13:15:50 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -63,6 +63,7 @@
#include "dhcp.h"
#include "dhcpd.h"
+#include "log.h"
int if_register_bpf(struct interface_info *ifi);
@@ -78,12 +79,12 @@ if_register_bpf(struct interface_info *ifi)
int sock;
if ((sock = open("/dev/bpf0", O_RDWR | O_CLOEXEC)) == -1)
- error("Can't open bpf: %s", strerror(errno));
+ fatalx("Can't open bpf: %s", strerror(errno));
/* Set the BPF device to point at this interface. */
strlcpy(ifr.ifr_name, ifi->name, IFNAMSIZ);
if (ioctl(sock, BIOCSETIF, &ifr) < 0)
- error("Can't attach interface %s to /dev/bpf0: %s",
+ fatalx("Can't attach interface %s to /dev/bpf0: %s",
ifi->name, strerror(errno));
return (sock);
@@ -98,13 +99,13 @@ if_register_send(struct interface_info *ifi)
* Use raw socket for unicast send.
*/
if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) == -1)
- error("socket(SOCK_RAW): %s", strerror(errno));
+ fatalx("socket(SOCK_RAW): %s", strerror(errno));
if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on,
sizeof(on)) == -1)
- error("setsockopt(IP_HDRINCL): %s", strerror(errno));
+ fatalx("setsockopt(IP_HDRINCL): %s", strerror(errno));
if (setsockopt(sock, IPPROTO_IP, SO_RTABLE, &ifi->rdomain,
sizeof(ifi->rdomain)) == -1)
- error("setsockopt(SO_RTABLE): %s", strerror(errno));
+ fatalx("setsockopt(SO_RTABLE): %s", strerror(errno));
ifi->ufdesc = sock;
}
@@ -196,11 +197,11 @@ if_register_receive(struct interface_info *ifi)
/* Make sure the BPF version is in range. */
if (ioctl(ifi->bfdesc, BIOCVERSION, &v) < 0)
- error("Can't get BPF version: %s", strerror(errno));
+ fatalx("Can't get BPF version: %s", strerror(errno));
if (v.bv_major != BPF_MAJOR_VERSION ||
v.bv_minor < BPF_MINOR_VERSION)
- error("Kernel BPF version out of range - recompile dhclient!");
+ fatalx("Kernel BPF version out of range - recompile dhclient!");
/*
* Set immediate mode so that reads return as soon as a packet
@@ -208,20 +209,20 @@ if_register_receive(struct interface_info *ifi)
* with packets.
*/
if (ioctl(ifi->bfdesc, BIOCIMMEDIATE, &flag) < 0)
- error("Can't set immediate mode on bpf device: %s",
+ fatalx("Can't set immediate mode on bpf device: %s",
strerror(errno));
if (ioctl(ifi->bfdesc, BIOCSFILDROP, &flag) < 0)
- error("Can't set filter-drop mode on bpf device: %s",
+ fatalx("Can't set filter-drop mode on bpf device: %s",
strerror(errno));
/* Get the required BPF buffer length from the kernel. */
if (ioctl(ifi->bfdesc, BIOCGBLEN, &sz) < 0)
- error("Can't get bpf buffer length: %s", strerror(errno));
+ fatalx("Can't get bpf buffer length: %s", strerror(errno));
ifi->rbuf_max = sz;
ifi->rbuf = malloc(ifi->rbuf_max);
if (!ifi->rbuf)
- error("Can't allocate %lu bytes for bpf input buffer.",
+ fatalx("Can't allocate %lu bytes for bpf input buffer.",
(unsigned long)ifi->rbuf_max);
ifi->rbuf_offset = 0;
ifi->rbuf_len = 0;
@@ -238,7 +239,7 @@ if_register_receive(struct interface_info *ifi)
dhcp_bpf_filter[8].k = LOCAL_PORT;
if (ioctl(ifi->bfdesc, BIOCSETF, &p) < 0)
- error("Can't install packet filter program: %s",
+ fatalx("Can't install packet filter program: %s",
strerror(errno));
/* Set up the bpf write filter program structure. */
@@ -249,11 +250,11 @@ if_register_receive(struct interface_info *ifi)
dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK);
if (ioctl(ifi->bfdesc, BIOCSETWF, &p) < 0)
- error("Can't install write filter program: %s",
+ fatalx("Can't install write filter program: %s",
strerror(errno));
if (ioctl(ifi->bfdesc, BIOCLOCK, NULL) < 0)
- error("Cannot lock bpf");
+ fatalx("Cannot lock bpf");
}
ssize_t
@@ -329,7 +330,7 @@ send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to)
}
if (result == -1)
- warning("send_packet: %s", strerror(errno));
+ log_warnx("send_packet: %s", strerror(errno));
return (result);
}