summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-02-13 19:13:14 +0000
committerkrw <krw@openbsd.org>2017-02-13 19:13:14 +0000
commitc525a1850093eeda7e2f4793bb28f06faaca922a (patch)
treebae08923087470164b0eddd80c96e3124bf720bf
parentFix powerdown with vmmci(4) VMs using a shutdown and no reset. (diff)
downloadwireguard-openbsd-c525a1850093eeda7e2f4793bb28f06faaca922a.tar.xz
wireguard-openbsd-c525a1850093eeda7e2f4793bb28f06faaca922a.zip
Switch from old errwarn.c logging to shiny new log.[ch].
ok benno@
-rw-r--r--usr.sbin/dhcpd/Makefile4
-rw-r--r--usr.sbin/dhcpd/alloc.c7
-rw-r--r--usr.sbin/dhcpd/bootp.c21
-rw-r--r--usr.sbin/dhcpd/bpf.c29
-rw-r--r--usr.sbin/dhcpd/confpars.c41
-rw-r--r--usr.sbin/dhcpd/db.c13
-rw-r--r--usr.sbin/dhcpd/dhcp.c81
-rw-r--r--usr.sbin/dhcpd/dhcpd.c38
-rw-r--r--usr.sbin/dhcpd/dhcpd.h11
-rw-r--r--usr.sbin/dhcpd/dispatch.c41
-rw-r--r--usr.sbin/dhcpd/hash.c7
-rw-r--r--usr.sbin/dhcpd/icmp.c15
-rw-r--r--usr.sbin/dhcpd/log.c199
-rw-r--r--usr.sbin/dhcpd/log.h46
-rw-r--r--usr.sbin/dhcpd/memory.c35
-rw-r--r--usr.sbin/dhcpd/options.c19
-rw-r--r--usr.sbin/dhcpd/packet.c13
-rw-r--r--usr.sbin/dhcpd/parse.c80
-rw-r--r--usr.sbin/dhcpd/pfutils.c23
-rw-r--r--usr.sbin/dhcpd/sync.c23
-rw-r--r--usr.sbin/dhcpd/tables.c5
-rw-r--r--usr.sbin/dhcpd/tree.c17
-rw-r--r--usr.sbin/dhcpd/udpsock.c23
23 files changed, 544 insertions, 247 deletions
diff --git a/usr.sbin/dhcpd/Makefile b/usr.sbin/dhcpd/Makefile
index 6f0cfedf556..7300cc3de35 100644
--- a/usr.sbin/dhcpd/Makefile
+++ b/usr.sbin/dhcpd/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.5 2014/07/11 09:42:27 yasuoka Exp $
+# $OpenBSD: Makefile,v 1.6 2017/02/13 19:13:14 krw Exp $
.include <bsd.own.mk>
-SRCS= bootp.c confpars.c db.c dhcp.c dhcpd.c bpf.c packet.c errwarn.c \
+SRCS= bootp.c confpars.c db.c dhcp.c dhcpd.c bpf.c packet.c log.c \
dispatch.c print.c memory.c options.c inet.c conflex.c parse.c \
alloc.c tables.c tree.c hash.c convert.c icmp.c pfutils.c sync.c \
udpsock.c
diff --git a/usr.sbin/dhcpd/alloc.c b/usr.sbin/dhcpd/alloc.c
index 89a906b1e20..7621a48764c 100644
--- a/usr.sbin/dhcpd/alloc.c
+++ b/usr.sbin/dhcpd/alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: alloc.c,v 1.14 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: alloc.c,v 1.15 2017/02/13 19:13:14 krw Exp $ */
/* Memory allocation... */
@@ -53,6 +53,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
struct lease_state *free_lease_states;
struct tree_cache *free_tree_caches;
@@ -68,7 +69,7 @@ new_tree_cache(char *name)
} else {
rval = calloc(1, sizeof(struct tree_cache));
if (!rval)
- error("unable to allocate tree cache for %s.", name);
+ fatalx("unable to allocate tree cache for %s.", name);
}
return (rval);
}
@@ -91,7 +92,7 @@ new_lease_state(char *name)
} else {
rval = calloc(1, sizeof(struct lease_state));
if (!rval)
- error("unable to allocate lease state for %s.", name);
+ fatalx("unable to allocate lease state for %s.", name);
}
return (rval);
diff --git a/usr.sbin/dhcpd/bootp.c b/usr.sbin/dhcpd/bootp.c
index 36d79190f19..6ac7486fb95 100644
--- a/usr.sbin/dhcpd/bootp.c
+++ b/usr.sbin/dhcpd/bootp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bootp.c,v 1.16 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: bootp.c,v 1.17 2017/02/13 19:13:14 krw Exp $ */
/*
* BOOTP Protocol support.
@@ -57,6 +57,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
void
bootp(struct packet *packet)
@@ -76,7 +77,7 @@ bootp(struct packet *packet)
if (packet->raw->op != BOOTREQUEST)
return;
- note("BOOTREQUEST from %s via %s%s", print_hw_addr(packet->raw->htype,
+ log_info("BOOTREQUEST from %s via %s%s", print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
packet->interface->name,
@@ -113,14 +114,14 @@ bootp(struct packet *packet)
}
if (host && (!host->group->allow_booting)) {
- note("Ignoring excluded BOOTP client %s", host->name ?
+ log_info("Ignoring excluded BOOTP client %s", host->name ?
host->name : print_hw_addr (packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr));
return;
}
if (host && (!host->group->allow_bootp)) {
- note("Ignoring BOOTP request from client %s",
+ log_info("Ignoring BOOTP request from client %s",
host->name ? host->name :
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr));
@@ -132,7 +133,7 @@ bootp(struct packet *packet)
* find any host record for this client, ignore it.
*/
if (!host && !(s->group->boot_unknown_clients)) {
- note("Ignoring unknown BOOTP client %s via %s",
+ log_info("Ignoring unknown BOOTP client %s via %s",
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
packet->raw->giaddr.s_addr ?
@@ -146,7 +147,7 @@ bootp(struct packet *packet)
* ignore it.
*/
if (!host && !(s->group->allow_bootp)) {
- note("Ignoring BOOTP request from client %s via %s",
+ log_info("Ignoring BOOTP request from client %s via %s",
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
packet->raw->giaddr.s_addr ?
@@ -162,7 +163,7 @@ bootp(struct packet *packet)
*/
if (!(s->group->dynamic_bootp)) {
lose:
- note("No applicable record for BOOTP host %s via %s",
+ log_info("No applicable record for BOOTP host %s via %s",
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
packet->raw->giaddr.s_addr ?
@@ -218,13 +219,13 @@ lose:
/* Make sure we're allowed to boot this client. */
if (hp && (!hp->group->allow_booting)) {
- note("Ignoring excluded BOOTP client %s", hp->name);
+ log_info("Ignoring excluded BOOTP client %s", hp->name);
return;
}
/* Make sure we're allowed to boot this client with bootp. */
if (hp && (!hp->group->allow_bootp)) {
- note("Ignoring BOOTP request from client %s", hp->name);
+ log_info("Ignoring BOOTP request from client %s", hp->name);
return;
}
@@ -322,7 +323,7 @@ lose:
from = packet->interface->primary_address;
/* Report what we're doing... */
- note("BOOTREPLY for %s to %s (%s) via %s", piaddr(ip_address),
+ log_info("BOOTREPLY for %s to %s (%s) via %s", piaddr(ip_address),
hp->name, print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr), packet->raw->giaddr.s_addr ?
inet_ntoa(packet->raw->giaddr) : packet->interface->name);
diff --git a/usr.sbin/dhcpd/bpf.c b/usr.sbin/dhcpd/bpf.c
index b84fb6d6c89..b862a44cd62 100644
--- a/usr.sbin/dhcpd/bpf.c
+++ b/usr.sbin/dhcpd/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.14 2016/05/28 07:00:18 natano Exp $ */
+/* $OpenBSD: bpf.c,v 1.15 2017/02/13 19:13:14 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -62,6 +62,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
ssize_t send_packet (struct interface_info *, struct dhcp_packet *,
size_t, struct in_addr, struct sockaddr_in *, struct hardware *);
@@ -77,11 +78,11 @@ if_register_bpf(struct interface_info *info)
int sock;
if ((sock = open("/dev/bpf0", O_RDWR)) == -1)
- error("Can't open bpf device: %m");
+ fatalx("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: %m",
+ fatalx("Can't attach interface %s to bpf device: %m",
info->name);
info->send_packet = send_packet;
@@ -181,11 +182,11 @@ if_register_receive(struct interface_info *info)
/* Make sure the BPF version is in range... */
if (ioctl(info->rfdesc, BIOCVERSION, &v) == -1)
- error("Can't get BPF version: %m");
+ fatalx("Can't get BPF version: %m");
if (v.bv_major != BPF_MAJOR_VERSION ||
v.bv_minor < BPF_MINOR_VERSION)
- error("Kernel BPF version out of range - recompile dhcpd!");
+ fatalx("Kernel BPF version out of range - recompile dhcpd!");
/*
* Set immediate mode so that reads return as soon as a packet
@@ -193,22 +194,22 @@ if_register_receive(struct interface_info *info)
* with packets.
*/
if (ioctl(info->rfdesc, BIOCIMMEDIATE, &flag) == -1)
- error("Can't set immediate mode on bpf device: %m");
+ fatalx("Can't set immediate mode on bpf device: %m");
if (ioctl(info->rfdesc, BIOCSFILDROP, &flag) == -1)
- error("Can't set filter-drop mode on bpf device: %m");
+ fatalx("Can't set filter-drop mode on bpf device: %m");
/* make sure kernel fills in the source ethernet address */
if (ioctl(info->rfdesc, BIOCSHDRCMPLT, &cmplt) == -1)
- error("Can't set header complete flag on bpf device: %m");
+ fatalx("Can't set header complete flag on bpf device: %m");
/* Get the required BPF buffer length from the kernel. */
if (ioctl(info->rfdesc, BIOCGBLEN, &sz) == -1)
- error("Can't get bpf buffer length: %m");
+ fatalx("Can't get bpf buffer length: %m");
info->rbuf_max = sz;
info->rbuf = malloc(info->rbuf_max);
if (!info->rbuf)
- error("Can't allocate %lu bytes for bpf input buffer.",
+ fatalx("Can't allocate %lu bytes for bpf input buffer.",
(unsigned long)info->rbuf_max);
info->rbuf_offset = 0;
info->rbuf_len = 0;
@@ -218,18 +219,18 @@ if_register_receive(struct interface_info *info)
p.bf_insns = dhcp_bpf_filter;
if (ioctl(info->rfdesc, BIOCSETF, &p) == -1)
- error("Can't install packet filter program: %m");
+ fatalx("Can't install packet filter program: %m");
/* Set up the bpf write filter program structure. */
p.bf_len = dhcp_bpf_wfilter_len;
p.bf_insns = dhcp_bpf_wfilter;
if (ioctl(info->rfdesc, BIOCSETWF, &p) == -1)
- error("Can't install write filter program: %m");
+ fatalx("Can't install write filter program: %m");
/* make sure these settings cannot be changed after dropping privs */
if (ioctl(info->rfdesc, BIOCLOCK) == -1)
- error("Failed to lock bpf descriptor: %m");
+ fatalx("Failed to lock bpf descriptor: %m");
}
ssize_t
@@ -255,7 +256,7 @@ send_packet(struct interface_info *interface, struct dhcp_packet *raw,
result = writev(interface->wfdesc, iov, 2);
if (result == -1)
- warning("send_packet: %m");
+ log_warnx("send_packet: %m");
return (result);
}
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index 878c078bd50..28da5fd6a69 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.28 2016/08/17 00:55:33 krw Exp $ */
+/* $OpenBSD: confpars.c,v 1.29 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -52,6 +52,7 @@
#include "tree.h"
#include "dhcpd.h"
#include "dhctoken.h"
+#include "log.h"
/*
* conf-file :== parameters declarations EOF
@@ -81,7 +82,7 @@ readconf(void)
root_group.authoritative = 1;
if ((cfile = fopen(path_dhcpd_conf, "r")) == NULL)
- error("Can't open %s: %m", path_dhcpd_conf);
+ fatalx("Can't open %s: %m", path_dhcpd_conf);
do {
token = peek_token(&val, cfile);
@@ -125,11 +126,11 @@ read_leases(void)
* could create severe network chaos.
*/
if ((cfile = fopen(path_dhcpd_db, "r")) == NULL) {
- warning("Can't open lease database %s: %m -- %s",
+ log_warnx("Can't open lease database %s: %m -- %s",
path_dhcpd_db,
"check for failed database rewrite attempt!");
- warning("Please read the dhcpd.leases manual page if you");
- error("don't know what to do about this.");
+ log_warnx("Please read the dhcpd.leases manual page if you");
+ fatalx("don't know what to do about this.");
}
do {
@@ -137,7 +138,7 @@ read_leases(void)
if (token == EOF)
break;
if (token != TOK_LEASE) {
- warning("Corrupt lease file - possible data loss!");
+ log_warnx("Corrupt lease file - possible data loss!");
skip_to_semi(cfile);
} else {
struct lease *lease;
@@ -250,7 +251,7 @@ parse_statement(FILE *cfile, struct group *group, int type,
share = calloc(1, sizeof(struct shared_network));
if (!share)
- error("No memory for shared subnet");
+ fatalx("No memory for shared subnet");
share->group = clone_group(group, "parse_statement:subnet");
share->group->shared_network = share;
@@ -265,7 +266,7 @@ parse_statement(FILE *cfile, struct group *group, int type,
n = piaddr(share->subnets->net);
share->name = strdup(n);
if (share->name == NULL)
- error("no memory for subnet name");
+ fatalx("no memory for subnet name");
/*
* Copy the authoritative parameter from the subnet,
@@ -357,7 +358,7 @@ parse_statement(FILE *cfile, struct group *group, int type,
break;
cache = tree_cache(tree);
if (!tree_evaluate (cache))
- error("next-server is not known");
+ fatalx("next-server is not known");
group->next_server.len = 4;
memcpy(group->next_server.iabuf,
cache->value, group->next_server.len);
@@ -534,7 +535,7 @@ parse_host_declaration(FILE *cfile, struct group *group)
host = calloc(1, sizeof (struct host_decl));
if (!host)
- error("can't allocate host decl struct %s.", name);
+ fatalx("can't allocate host decl struct %s.", name);
host->name = name;
host->group = clone_group(group, "parse_host_declaration");
@@ -566,7 +567,7 @@ parse_host_declaration(FILE *cfile, struct group *group)
host->group->options[DHO_HOST_NAME] =
new_tree_cache("parse_host_declaration");
if (!host->group->options[DHO_HOST_NAME])
- error("can't allocate a tree cache for hostname.");
+ fatalx("can't allocate a tree cache for hostname.");
host->group->options[DHO_HOST_NAME]->len =
strlen(name);
host->group->options[DHO_HOST_NAME]->value =
@@ -601,7 +602,7 @@ parse_class_declaration(FILE *cfile, struct group *group, int type)
class = add_class (type, val);
if (!class)
- error("No memory for class %s.", val);
+ fatalx("No memory for class %s.", val);
class->group = clone_group(group, "parse_class_declaration");
if (!parse_lbrace(cfile)) {
@@ -642,7 +643,7 @@ parse_shared_net_declaration(FILE *cfile, struct group *group)
share = calloc(1, sizeof(struct shared_network));
if (!share)
- error("No memory for shared subnet");
+ fatalx("No memory for shared subnet");
share->leases = NULL;
share->last_lease = NULL;
share->insertion_point = NULL;
@@ -662,7 +663,7 @@ parse_shared_net_declaration(FILE *cfile, struct group *group)
}
name = strdup(val);
if (name == NULL)
- error("no memory for shared network name");
+ fatalx("no memory for shared network name");
} else {
name = parse_host_name(cfile);
if (!name) {
@@ -721,7 +722,7 @@ parse_subnet_declaration(FILE *cfile, struct shared_network *share)
subnet = calloc(1, sizeof(struct subnet));
if (!subnet)
- error("No memory for new subnet");
+ fatalx("No memory for new subnet");
subnet->shared_network = share;
subnet->group = clone_group(share->group, "parse_subnet_declaration");
subnet->group->subnet = subnet;
@@ -998,7 +999,7 @@ parse_option_param(FILE *cfile, struct group *group)
}
vendor = strdup(val);
if (vendor == NULL)
- error("no memory for vendor token.");
+ fatalx("no memory for vendor token.");
token = peek_token(&val, cfile);
if (token == '.') {
/* Go ahead and take the DOT token. */
@@ -1198,7 +1199,7 @@ parse_option_param(FILE *cfile, struct group *group)
(cprefix + 7) / 8));
break;
default:
- warning("Bad format %c in parse_option_param.",
+ log_warnx("Bad format %c in parse_option_param.",
*fmt);
skip_to_semi(cfile);
return;
@@ -1310,7 +1311,7 @@ parse_lease_declaration(FILE *cfile)
lease.uid_len = strlen(val);
lease.uid = malloc(lease.uid_len);
if (!lease.uid) {
- warning("no space for uid");
+ log_warnx("no space for uid");
return NULL;
}
memcpy(lease.uid, val, lease.uid_len);
@@ -1321,7 +1322,7 @@ parse_lease_declaration(FILE *cfile)
parse_numeric_aggregate(cfile,
NULL, &lease.uid_len, ':', 16, 8);
if (!lease.uid) {
- warning("no space for uid");
+ log_warnx("no space for uid");
return NULL;
}
if (lease.uid_len == 0) {
@@ -1332,7 +1333,7 @@ parse_lease_declaration(FILE *cfile)
}
}
if (!lease.uid)
- error("No memory for lease uid");
+ fatalx("No memory for lease uid");
break;
case TOK_CLASS:
diff --git a/usr.sbin/dhcpd/db.c b/usr.sbin/dhcpd/db.c
index 7f401403b37..cc153373da4 100644
--- a/usr.sbin/dhcpd/db.c
+++ b/usr.sbin/dhcpd/db.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db.c,v 1.16 2016/08/27 01:26:22 guenther Exp $ */
+/* $OpenBSD: db.c,v 1.17 2017/02/13 19:13:14 krw Exp $ */
/*
* Persistent database management routines for DHCPD.
@@ -57,6 +57,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
FILE *db_file;
@@ -149,7 +150,7 @@ bad_hostname:
++errors;
if (errors)
- note("write_lease: unable to write lease %s",
+ log_info("write_lease: unable to write lease %s",
piaddr(lease->ip_addr));
return (!errors);
@@ -167,12 +168,12 @@ commit_leases(void)
* rewrite fails.
*/
if (fflush(db_file) == EOF) {
- note("commit_leases: unable to commit: %m");
+ log_info("commit_leases: unable to commit: %m");
return (0);
}
if (fsync(fileno(db_file)) == -1) {
- note("commit_leases: unable to commit: %m");
+ log_info("commit_leases: unable to commit: %m");
return (0);
}
@@ -197,9 +198,9 @@ db_startup(void)
/* open lease file. once we dropped privs it has to stay open */
db_fd = open(path_dhcpd_db, O_WRONLY|O_CREAT, 0640);
if (db_fd == -1)
- error("Can't create new lease file: %m");
+ fatalx("Can't create new lease file: %m");
if ((db_file = fdopen(db_fd, "w")) == NULL)
- error("Can't fdopen new lease file!");
+ fatalx("Can't fdopen new lease file!");
/* Read in the existing lease file... */
read_leases();
diff --git a/usr.sbin/dhcpd/dhcp.c b/usr.sbin/dhcpd/dhcp.c
index 89a2dd90037..f67c6439e93 100644
--- a/usr.sbin/dhcpd/dhcp.c
+++ b/usr.sbin/dhcpd/dhcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.c,v 1.52 2016/10/24 21:05:55 krw Exp $ */
+/* $OpenBSD: dhcp.c,v 1.53 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -55,6 +55,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
#include "sync.h"
int outstanding_pings;
@@ -68,7 +69,7 @@ dhcp(struct packet *packet, int is_udpsock)
return;
if (is_udpsock && packet->packet_type != DHCPINFORM) {
- note("Unable to handle a DHCP message type=%d on UDP "
+ log_info("Unable to handle a DHCP message type=%d on UDP "
"socket", packet->packet_type);
return;
}
@@ -105,7 +106,7 @@ dhcpdiscover(struct packet *packet)
struct lease *lease = find_lease(packet, packet->shared_network, 0);
struct host_decl *hp;
- note("DHCPDISCOVER from %s via %s",
+ log_info("DHCPDISCOVER from %s via %s",
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr),
packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
@@ -113,7 +114,7 @@ dhcpdiscover(struct packet *packet)
/* Sourceless packets don't make sense here. */
if (!packet->shared_network) {
- note("Packet from unknown subnet: %s",
+ log_info("Packet from unknown subnet: %s",
inet_ntoa(packet->raw->giaddr));
return;
}
@@ -127,7 +128,7 @@ dhcpdiscover(struct packet *packet)
* expired, we have nothing to offer this client.
*/
if (!lease || lease->ends > cur_time) {
- note("no free leases on subnet %s",
+ log_info("no free leases on subnet %s",
packet->shared_network->name);
return;
}
@@ -155,7 +156,7 @@ dhcpdiscover(struct packet *packet)
* reclaim the abandoned lease.
*/
if ((lease->flags & ABANDONED_LEASE)) {
- warning("Reclaiming abandoned IP address %s.",
+ log_warnx("Reclaiming abandoned IP address %s.",
piaddr(lease->ip_addr));
lease->flags &= ~ABANDONED_LEASE;
@@ -188,11 +189,11 @@ dhcpdiscover(struct packet *packet)
request. */
if (!lease->host &&
!lease->subnet->group->boot_unknown_clients) {
- note("Ignoring unknown client %s",
+ log_info("Ignoring unknown client %s",
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr));
} else if (lease->host && !lease->host->group->allow_booting) {
- note("Declining to boot client %s",
+ log_info("Declining to boot client %s",
lease->host->name ? lease->host->name :
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr));
@@ -223,7 +224,7 @@ dhcprequest(struct packet *packet)
else
lease = NULL;
- note("DHCPREQUEST for %s from %s via %s", piaddr(cip),
+ log_info("DHCPREQUEST for %s from %s via %s", piaddr(cip),
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr),
packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
@@ -331,12 +332,12 @@ dhcprequest(struct packet *packet)
/* If we're not allowed to serve this client anymore, don't. */
if (lease && !lease->host &&
!lease->subnet->group->boot_unknown_clients) {
- note("Ignoring unknown client %s",
+ log_info("Ignoring unknown client %s",
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr));
return;
} else if (lease && lease->host && !lease->host->group->allow_booting) {
- note("Declining to renew client %s",
+ log_info("Declining to renew client %s",
lease->host->name ? lease->host->name :
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr));
@@ -390,7 +391,7 @@ dhcprelease(struct packet *packet)
* so let it go.
*/
if (packet->options[DHO_DHCP_REQUESTED_ADDRESS].len) {
- note("DHCPRELEASE from %s specified requested-address.",
+ log_info("DHCPRELEASE from %s specified requested-address.",
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr));
}
@@ -424,7 +425,7 @@ dhcprelease(struct packet *packet)
/* Can't do >1 inet_ntoa() in a printf()! */
strlcpy(ciaddrbuf, inet_ntoa(packet->raw->ciaddr), sizeof(ciaddrbuf));
- note("DHCPRELEASE of %s from %s via %s (%sfound)",
+ log_info("DHCPRELEASE of %s from %s via %s (%sfound)",
ciaddrbuf,
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr),
@@ -434,7 +435,7 @@ dhcprelease(struct packet *packet)
/* If we're already acking this lease, don't do it again. */
if (lease && lease->state) {
- note("DHCPRELEASE already acking lease %s",
+ log_info("DHCPRELEASE already acking lease %s",
piaddr(lease->ip_addr));
return;
}
@@ -448,7 +449,7 @@ dhcprelease(struct packet *packet)
* addresses from the server.
*/
if (!lease->releasing) {
- note("DHCPRELEASE of %s from %s via %s (found)",
+ log_info("DHCPRELEASE of %s from %s via %s (found)",
ciaddrbuf,
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
@@ -461,7 +462,7 @@ dhcprelease(struct packet *packet)
icmp_echorequest(&(lease->ip_addr));
++outstanding_pings;
} else {
- note("DHCPRELEASE of %s from %s via %s ignored "
+ log_info("DHCPRELEASE of %s from %s via %s ignored "
"(release already pending)",
ciaddrbuf,
print_hw_addr(packet->raw->htype,
@@ -471,7 +472,7 @@ dhcprelease(struct packet *packet)
packet->interface->name);
}
} else {
- note("DHCPRELEASE of %s from %s via %s for nonexistent lease",
+ log_info("DHCPRELEASE of %s from %s via %s for nonexistent lease",
ciaddrbuf,
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr),
@@ -496,7 +497,7 @@ dhcpdecline(struct packet *packet)
packet->options[DHO_DHCP_REQUESTED_ADDRESS].data, 4);
lease = find_lease_by_ip_addr(cip);
- note("DHCPDECLINE on %s from %s via %s",
+ log_info("DHCPDECLINE on %s from %s via %s",
piaddr(cip), print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
@@ -504,7 +505,7 @@ dhcpdecline(struct packet *packet)
/* If we're already acking this lease, don't do it again. */
if (lease && lease->state) {
- note("DHCPDECLINE already acking lease %s",
+ log_info("DHCPDECLINE already acking lease %s",
piaddr(lease->ip_addr));
return;
}
@@ -529,7 +530,7 @@ dhcpinform(struct packet *packet)
if (packet->raw->ciaddr.s_addr) {
if (memcmp(&packet->raw->ciaddr.s_addr,
packet->client_addr.iabuf, 4) != 0) {
- note("DHCPINFORM from %s but ciaddr %s is not "
+ log_info("DHCPINFORM from %s but ciaddr %s is not "
"consistent with actual address",
piaddr(packet->client_addr),
inet_ntoa(packet->raw->ciaddr));
@@ -539,7 +540,7 @@ dhcpinform(struct packet *packet)
} else
memcpy(cip.iabuf, &packet->client_addr.iabuf, 4);
- note("DHCPINFORM from %s", piaddr(cip));
+ log_info("DHCPINFORM from %s", piaddr(cip));
/* Find the lease that matches the address requested by the client. */
subnet = find_subnet(cip);
@@ -548,7 +549,7 @@ dhcpinform(struct packet *packet)
/* Sourceless packets don't make sense here. */
if (!subnet->shared_network) {
- note("Packet from unknown subnet: %s",
+ log_info("Packet from unknown subnet: %s",
inet_ntoa(packet->raw->giaddr));
return;
}
@@ -660,7 +661,7 @@ nak_lease(struct packet *packet, struct iaddr *cip)
raw.op = BOOTREPLY;
/* Report what we're sending... */
- note("DHCPNAK on %s to %s via %s", piaddr(*cip),
+ log_info("DHCPNAK on %s to %s via %s", piaddr(*cip),
print_hw_addr(packet->raw->htype, packet->raw->hlen,
packet->raw->chaddr), packet->raw->giaddr.s_addr ?
inet_ntoa(packet->raw->giaddr) : packet->interface->name);
@@ -687,7 +688,7 @@ nak_lease(struct packet *packet, struct iaddr *cip)
result = packet->interface->send_packet(packet->interface, &raw,
outgoing.packet_length, from, &to, packet->haddr);
if (result == -1)
- warning("send_fallback: %m");
+ log_warnx("send_fallback: %m");
return;
} else {
to.sin_addr.s_addr = htonl(INADDR_BROADCAST);
@@ -713,7 +714,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
if (lease->state) {
if ((lease->flags & STATIC_LEASE) ||
cur_time - lease->timestamp < 60) {
- note("already acking lease %s", piaddr(lease->ip_addr));
+ log_info("already acking lease %s", piaddr(lease->ip_addr));
return;
}
free_lease_state(lease->state, "ACK timed out");
@@ -741,12 +742,12 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
*/
if (!lease->host) {
if (vendor_class && !vendor_class->group->allow_booting) {
- debug("Booting denied by vendor class");
+ log_debug("Booting denied by vendor class");
return;
}
if (user_class && !user_class->group->allow_booting) {
- debug("Booting denied by user class");
+ log_debug("Booting denied by user class");
return;
}
}
@@ -754,7 +755,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
/* Allocate a lease state structure... */
state = new_lease_state("ack_lease");
if (!state)
- error("unable to allocate lease state!");
+ fatalx("unable to allocate lease state!");
memset(state, 0, sizeof *state);
state->got_requested_address = packet->got_requested_address;
state->shared_network = packet->interface->shared_network;
@@ -774,7 +775,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
free(lease->client_hostname);
lease->client_hostname = malloc( packet->options[i].len + 1);
if (!lease->client_hostname)
- error("no memory for client hostname.\n");
+ fatalx("no memory for client hostname.\n");
memcpy(lease->client_hostname, packet->options[i].data,
packet->options[i].len);
lease->client_hostname[packet->options[i].len] = 0;
@@ -794,7 +795,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
free(lease->client_identifier);
lease->client_identifier = malloc(packet->options[i].len);
if (!lease->client_identifier)
- error("no memory for client identifier.\n");
+ fatalx("no memory for client identifier.\n");
lease->client_identifier_len = packet->options[i].len;
memcpy(lease->client_identifier, packet->options[i].data,
packet->options[i].len);
@@ -922,7 +923,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
lt.uid_max = lt.uid_len = packet->options[i].len;
lt.uid = malloc(lt.uid_max);
if (!lt.uid)
- error("can't allocate memory for large uid.");
+ fatalx("can't allocate memory for large uid.");
memcpy(lt.uid, packet->options[i].data, lt.uid_len);
}
}
@@ -1032,7 +1033,7 @@ ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
if (packet->options[i].data) {
state->prl = calloc(1, packet->options[i].len);
if (!state->prl)
- warning("no memory for parameter request list");
+ log_warnx("no memory for parameter request list");
else {
memcpy(state->prl, packet->options[i].data,
packet->options[i].len);
@@ -1278,7 +1279,7 @@ dhcp_reply(struct lease *lease)
int prl_len;
if (!state)
- error("dhcp_reply was supplied lease with no state!");
+ fatalx("dhcp_reply was supplied lease with no state!");
/* Compose a response for the client... */
memset(&raw, 0, sizeof raw);
@@ -1365,14 +1366,14 @@ dhcp_reply(struct lease *lease)
/* Say what we're doing... */
if ((state->offer == DHCPACK) && (lease->flags & INFORM_NOLEASE))
- note("DHCPACK to %s (%s) via %s",
+ log_info("DHCPACK to %s (%s) via %s",
ciaddrbuf,
print_hw_addr(lease->hardware_addr.htype,
lease->hardware_addr.hlen, lease->hardware_addr.haddr),
state->giaddr.s_addr ? inet_ntoa(state->giaddr) :
state->ip->name);
else
- note("%s on %s to %s via %s",
+ log_info("%s on %s to %s via %s",
(state->offer ? (state->offer == DHCPACK ? "DHCPACK" :
"DHCPOFFER") : "BOOTREPLY"),
piaddr(lease->ip_addr),
@@ -1589,7 +1590,7 @@ find_lease(struct packet *packet, struct shared_network *share,
ip_lease->hardware_addr.hlen))) {
if (uid_lease) {
if (uid_lease->ends > cur_time) {
- warning("client %s has duplicate leases on %s",
+ log_warnx("client %s has duplicate leases on %s",
print_hw_addr(packet->raw->htype,
packet->raw->hlen, packet->raw->chaddr),
ip_lease->shared_network->name);
@@ -1611,13 +1612,13 @@ find_lease(struct packet *packet, struct shared_network *share,
if (packet->packet_type == DHCPREQUEST && fixed_lease) {
fixed_lease = NULL;
db_conflict:
- warning("Both dynamic and static leases present for %s.",
+ log_warnx("Both dynamic and static leases present for %s.",
piaddr(cip));
- warning("Either remove host declaration %s or remove %s",
+ log_warnx("Either remove host declaration %s or remove %s",
(fixed_lease && fixed_lease->host ?
(fixed_lease->host->name ? fixed_lease->host->name :
piaddr(cip)) : piaddr(cip)), piaddr(cip));
- warning("from the dynamic address pool for %s",
+ log_warnx("from the dynamic address pool for %s",
share->name);
if (fixed_lease)
ip_lease = NULL;
@@ -1738,7 +1739,7 @@ db_conflict:
the administrator will eventually investigate. */
if (lease && (lease->flags & ABANDONED_LEASE)) {
if (packet->packet_type == DHCPREQUEST) {
- warning("Reclaiming REQUESTed abandoned IP address %s.",
+ log_warnx("Reclaiming REQUESTed abandoned IP address %s.",
piaddr(lease->ip_addr));
lease->flags &= ~ABANDONED_LEASE;
} else
diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c
index d109a4a5b97..de133992dd3 100644
--- a/usr.sbin/dhcpd/dhcpd.c
+++ b/usr.sbin/dhcpd/dhcpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.c,v 1.52 2016/08/27 01:26:22 guenther Exp $ */
+/* $OpenBSD: dhcpd.c,v 1.53 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org>
@@ -60,6 +60,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
#include "sync.h"
@@ -84,21 +85,19 @@ char *path_dhcpd_db = _PATH_DHCPD_DB;
char *abandoned_tab = NULL;
char *changedmac_tab = NULL;
char *leased_tab = NULL;
-struct syslog_data sdata = SYSLOG_DATA_INIT;
int
main(int argc, char *argv[])
{
int ch, cftest = 0, daemonize = 1, rdomain = -1, udpsockmode = 0;
- extern char *__progname;
char *sync_iface = NULL;
char *sync_baddr = NULL;
u_short sync_port = 0;
struct servent *ent;
struct in_addr udpaddr;
- /* Initially, log errors to stderr as well as to syslogd. */
- openlog_r(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY, &sdata);
+ log_init(1, LOG_DAEMON); /* log to stderr until daemonized */
+ log_setverbose(1);
opterr = 0;
while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::Y:y:")) != -1)
@@ -176,7 +175,7 @@ main(int argc, char *argv[])
while (argc > 0) {
struct interface_info *tmp = calloc(1, sizeof(*tmp));
if (!tmp)
- error("calloc");
+ fatalx("calloc");
strlcpy(tmp->name, argv[0], sizeof(tmp->name));
tmp->next = interfaces;
interfaces = tmp;
@@ -192,7 +191,7 @@ main(int argc, char *argv[])
time(&cur_time);
if (!readconf())
- error("Configuration file errors encountered");
+ fatalx("Configuration file errors encountered");
if (cftest)
exit(0);
@@ -203,7 +202,7 @@ main(int argc, char *argv[])
if (rdomain != -1)
if (setrtable(rdomain) == -1)
- error("setrtable (%m)");
+ fatalx("setrtable (%m)");
if (syncsend || syncrecv) {
syncfd = sync_init(sync_iface, sync_baddr, sync_port);
@@ -214,18 +213,21 @@ main(int argc, char *argv[])
if (daemonize)
daemon(0, 0);
+ log_init(0, LOG_DAEMON); /* stop logging to stderr */
+ log_setverbose(0);
+
if ((pw = getpwnam("_dhcp")) == NULL)
- error("user \"_dhcp\" not found");
+ fatalx("user \"_dhcp\" not found");
/* don't go near /dev/pf unless we actually intend to use it */
if ((abandoned_tab != NULL) ||
(changedmac_tab != NULL) ||
(leased_tab != NULL)){
if (pipe(pfpipe) == -1)
- error("pipe (%m)");
+ fatalx("pipe (%m)");
switch (pfproc_pid = fork()){
case -1:
- error("fork (%m)");
+ fatalx("fork (%m)");
/* NOTREACHED */
exit(1);
case 0:
@@ -247,13 +249,13 @@ main(int argc, char *argv[])
icmp_startup(1, lease_pinged);
if (chroot(_PATH_VAREMPTY) == -1)
- error("chroot %s: %m", _PATH_VAREMPTY);
+ fatalx("chroot %s: %m", _PATH_VAREMPTY);
if (chdir("/") == -1)
- error("chdir(\"/\"): %m");
+ fatalx("chdir(\"/\"): %m");
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- error("can't drop privileges: %m");
+ fatalx("can't drop privileges: %m");
if (udpsockmode) {
if (pledge("stdio inet route sendfd", NULL) == -1)
@@ -300,12 +302,12 @@ lease_pinged(struct iaddr from, u_int8_t *packet, int length)
lp = find_lease_by_ip_addr(from);
if (!lp) {
- note("unexpected ICMP Echo Reply from %s", piaddr(from));
+ log_info("unexpected ICMP Echo Reply from %s", piaddr(from));
return;
}
if (!lp->state && !lp->releasing) {
- warning("ICMP Echo Reply for %s arrived late or is spurious.",
+ log_warnx("ICMP Echo Reply for %s arrived late or is spurious.",
piaddr(from));
return;
}
@@ -319,9 +321,9 @@ lease_pinged(struct iaddr from, u_int8_t *packet, int length)
* and something answered, so we don't release it.
*/
if (lp->releasing) {
- warning("IP address %s answers a ping after sending a release",
+ log_warnx("IP address %s answers a ping after sending a release",
piaddr(lp->ip_addr));
- warning("Possible release spoof - Not releasing address %s",
+ log_warnx("Possible release spoof - Not releasing address %s",
piaddr(lp->ip_addr));
lp->releasing = 0;
} else {
diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h
index 49663332253..fb99f797eb2 100644
--- a/usr.sbin/dhcpd/dhcpd.h
+++ b/usr.sbin/dhcpd/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.56 2017/02/11 16:12:36 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.57 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -446,6 +446,7 @@ typedef unsigned char option_mask[16];
/* External definitions... */
/* parse.c */
+extern int warnings_occurred;
void do_percentm(char *obuf, size_t size, char *ibuf);
int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1,
2)));
@@ -459,13 +460,6 @@ char *pretty_print_option(unsigned int, unsigned char *, int, int, int);
void do_packet(struct interface_info *, struct dhcp_packet *, int,
unsigned int, struct iaddr, struct hardware *);
-/* errwarn.c */
-extern int warnings_occurred;
-void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
-
/* dhcpd.c */
extern time_t cur_time;
extern struct group root_group;
@@ -673,7 +667,6 @@ void pf_kill_state(int, struct in_addr);
size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
#define vwrite (ssize_t (*)(int, void *, size_t))write
void pfmsg(char, struct lease *);
-extern struct syslog_data sdata;
/* udpsock.c */
void udpsock_startup(struct in_addr);
diff --git a/usr.sbin/dhcpd/dispatch.c b/usr.sbin/dhcpd/dispatch.c
index 023aac6dd4d..450a416b33e 100644
--- a/usr.sbin/dhcpd/dispatch.c
+++ b/usr.sbin/dhcpd/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.38 2016/11/15 10:49:37 mestre Exp $ */
+/* $OpenBSD: dispatch.c,v 1.39 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -64,6 +64,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
#include "sync.h"
extern int syncfd;
@@ -95,7 +96,7 @@ discover_interfaces(int *rdomain)
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0)
- error("getifaddrs failed");
+ fatalx("getifaddrs failed");
/*
* If we already have a list of interfaces, the interfaces were
@@ -134,7 +135,7 @@ discover_interfaces(int *rdomain)
if (*rdomain == -1)
*rdomain = ird;
else if (*rdomain != ird && ir)
- error("Interface %s is not in rdomain %d",
+ fatalx("Interface %s is not in rdomain %d",
tmp->name, *rdomain);
else if (*rdomain != ird && !ir)
continue;
@@ -144,7 +145,7 @@ discover_interfaces(int *rdomain)
if (tmp == NULL) {
tmp = calloc(1, sizeof *tmp);
if (!tmp)
- error("Insufficient memory to %s %s",
+ fatalx("Insufficient memory to %s %s",
"record interface", ifa->ifa_name);
strlcpy(tmp->name, ifa->ifa_name, sizeof(tmp->name));
tmp->next = interfaces;
@@ -179,7 +180,7 @@ discover_interfaces(int *rdomain)
int len = (IFNAMSIZ + ifa->ifa_addr->sa_len);
tif = malloc(len);
if (!tif)
- error("no space to remember ifp.");
+ fatalx("no space to remember ifp.");
strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
memcpy(&tif->ifr_addr, ifa->ifa_addr,
ifa->ifa_addr->sa_len);
@@ -201,7 +202,7 @@ discover_interfaces(int *rdomain)
subnet->interface = tmp;
subnet->interface_address = addr;
} else if (subnet->interface != tmp) {
- warning("Multiple %s %s: %s %s",
+ log_warnx("Multiple %s %s: %s %s",
"interfaces match the",
"same subnet",
subnet->interface->name,
@@ -210,7 +211,7 @@ discover_interfaces(int *rdomain)
share = subnet->shared_network;
if (tmp->shared_network &&
tmp->shared_network != share) {
- warning("Interface %s matches %s",
+ log_warnx("Interface %s matches %s",
tmp->name,
"multiple shared networks");
} else {
@@ -220,7 +221,7 @@ discover_interfaces(int *rdomain)
if (!share->interface) {
share->interface = tmp;
} else if (share->interface != tmp) {
- warning("Multiple %s %s: %s %s",
+ log_warnx("Multiple %s %s: %s %s",
"interfaces match the",
"same shared network",
share->interface->name,
@@ -236,7 +237,7 @@ discover_interfaces(int *rdomain)
next = tmp->next;
if (!tmp->ifp) {
- warning("Can't listen on %s - it has no IP address.",
+ log_warnx("Can't listen on %s - it has no IP address.",
tmp->name);
/* Remove tmp from the list of interfaces. */
if (!last)
@@ -249,7 +250,7 @@ discover_interfaces(int *rdomain)
memcpy(&foo, &tmp->ifp->ifr_addr, sizeof tmp->ifp->ifr_addr);
if (!tmp->shared_network) {
- warning("Can't listen on %s - dhcpd.conf has no subnet "
+ log_warnx("Can't listen on %s - dhcpd.conf has no subnet "
"declaration for %s.", tmp->name,
inet_ntoa(foo.sin_addr));
/* Remove tmp from the list of interfaces. */
@@ -279,12 +280,12 @@ discover_interfaces(int *rdomain)
/* Register the interface... */
if_register_receive(tmp);
if_register_send(tmp);
- note("Listening on %s (%s).", tmp->name,
+ log_info("Listening on %s (%s).", tmp->name,
inet_ntoa(foo.sin_addr));
}
if (interfaces == NULL)
- error("No interfaces to listen on.");
+ fatalx("No interfaces to listen on.");
/* Now register all the remaining interfaces as protocols. */
for (tmp = interfaces; tmp; tmp = tmp->next)
@@ -314,7 +315,7 @@ dispatch(void)
if (nfds > nfds_max) {
fds = reallocarray(fds, nfds, sizeof(struct pollfd));
if (fds == NULL)
- error("Can't allocate poll structures.");
+ fatalx("Can't allocate poll structures.");
nfds_max = nfds;
}
@@ -361,7 +362,7 @@ another:
}
if (i == 0)
- error("No live interfaces to poll on - exiting.");
+ fatalx("No live interfaces to poll on - exiting.");
if (syncfd != -1) {
/* add syncer */
@@ -373,7 +374,7 @@ another:
switch (poll(fds, nfds, to_msec)) {
case -1:
if (errno != EAGAIN && errno != EINTR)
- error("poll: %m");
+ fatalx("poll: %m");
/* FALLTHROUGH */
case 0:
continue; /* no packets */
@@ -416,13 +417,13 @@ got_one(struct protocol *l)
if ((result = receive_packet(ip, u.packbuf, sizeof u,
&from, &hfrom)) == -1) {
- warning("receive_packet failed on %s: %s", ip->name,
+ log_warnx("receive_packet failed on %s: %s", ip->name,
strerror(errno));
ip->errors++;
if ((!interface_status(ip)) ||
(ip->noifmedia && ip->errors > 20)) {
/* our interface has gone away. */
- warning("Interface %s no longer appears valid.",
+ log_warnx("Interface %s no longer appears valid.",
ip->name);
ip->dead = 1;
interfaces_invalidated = 1;
@@ -553,7 +554,7 @@ add_timeout(time_t when, void (*where)(void *), void *what)
} else {
q = malloc(sizeof (struct dhcpd_timeout));
if (!q)
- error("Can't allocate timeout structure!");
+ fatalx("Can't allocate timeout structure!");
q->func = where;
q->what = what;
}
@@ -618,7 +619,7 @@ add_protocol(char *name, int fd, void (*handler)(struct protocol *),
p = malloc(sizeof *p);
if (!p)
- error("can't allocate protocol struct for %s", name);
+ fatalx("can't allocate protocol struct for %s", name);
p->fd = fd;
p->handler = handler;
p->local = local;
@@ -650,7 +651,7 @@ get_rdomain(char *name)
struct ifreq ifr;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- error("get_rdomain socket: %m");
+ fatalx("get_rdomain socket: %m");
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
diff --git a/usr.sbin/dhcpd/hash.c b/usr.sbin/dhcpd/hash.c
index 2f478d14de9..2f84aad9e93 100644
--- a/usr.sbin/dhcpd/hash.c
+++ b/usr.sbin/dhcpd/hash.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hash.c,v 1.7 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: hash.c,v 1.8 2017/02/13 19:13:14 krw Exp $ */
/* Routines for manipulating hash tables... */
@@ -54,6 +54,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
static int do_hash(unsigned char *, int, int);
@@ -64,7 +65,7 @@ new_hash(void)
rv = calloc(1, sizeof(struct hash_table));
if (!rv)
- warning("No memory for new hash.");
+ log_warnx("No memory for new hash.");
else
rv->hash_count = DEFAULT_HASH_SIZE;
@@ -102,7 +103,7 @@ void add_hash(struct hash_table *table, unsigned char *name, int len,
hashno = do_hash(name, len, table->hash_count);
bp = calloc(1, sizeof(struct hash_bucket));
if (!bp) {
- warning("Can't add %s to hash table.", name);
+ log_warnx("Can't add %s to hash table.", name);
return;
}
bp->name = name;
diff --git a/usr.sbin/dhcpd/icmp.c b/usr.sbin/dhcpd/icmp.c
index 7c1ea841c78..e01bed054a2 100644
--- a/usr.sbin/dhcpd/icmp.c
+++ b/usr.sbin/dhcpd/icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: icmp.c,v 1.15 2016/11/15 10:49:37 mestre Exp $ */
+/* $OpenBSD: icmp.c,v 1.16 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1997, 1998 The Internet Software Consortium.
@@ -56,6 +56,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
static int icmp_protocol_initialized;
static int icmp_protocol_fd;
@@ -70,7 +71,7 @@ icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int))
/* Only initialize icmp once. */
if (icmp_protocol_initialized)
- error("attempted to reinitialize icmp protocol");
+ fatalx("attempted to reinitialize icmp protocol");
icmp_protocol_initialized = 1;
/* Get the protocol number (should be 1). */
@@ -79,13 +80,13 @@ icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int))
/* Get a raw socket for the ICMP protocol. */
if ((icmp_protocol_fd = socket(AF_INET, SOCK_RAW, protocol)) == -1)
- error("unable to create icmp socket: %m");
+ fatalx("unable to create icmp socket: %m");
/* Make sure it does routing... */
state = 0;
if (setsockopt(icmp_protocol_fd, SOL_SOCKET, SO_DONTROUTE,
&state, sizeof(state)) == -1)
- error("Unable to disable SO_DONTROUTE on ICMP socket: %m");
+ fatalx("Unable to disable SO_DONTROUTE on ICMP socket: %m");
add_protocol("icmp", icmp_protocol_fd, icmp_echoreply, (void *)handler);
}
@@ -98,7 +99,7 @@ icmp_echorequest(struct iaddr *addr)
int status;
if (!icmp_protocol_initialized)
- error("attempt to use ICMP protocol before initialization.");
+ fatalx("attempt to use ICMP protocol before initialization.");
memset(&to, 0, sizeof(to));
to.sin_len = sizeof to;
@@ -118,7 +119,7 @@ icmp_echorequest(struct iaddr *addr)
status = sendto(icmp_protocol_fd, &icmp, sizeof(icmp), 0,
(struct sockaddr *)&to, sizeof(to));
if (status == -1)
- warning("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr));
+ log_warnx("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr));
if (status != sizeof icmp)
return 0;
@@ -140,7 +141,7 @@ icmp_echoreply(struct protocol *protocol)
status = recvfrom(protocol->fd, icbuf, sizeof(icbuf), 0,
(struct sockaddr *)&from, &salen);
if (status == -1) {
- warning("icmp_echoreply: %m");
+ log_warnx("icmp_echoreply: %m");
return;
}
diff --git a/usr.sbin/dhcpd/log.c b/usr.sbin/dhcpd/log.c
new file mode 100644
index 00000000000..9f9b1cae332
--- /dev/null
+++ b/usr.sbin/dhcpd/log.c
@@ -0,0 +1,199 @@
+/* $OpenBSD: log.c,v 1.1 2017/02/13 19:13:14 krw Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <syslog.h>
+#include <errno.h>
+#include <time.h>
+
+#include "log.h"
+
+static int debug;
+static int verbose;
+static const char *log_procname;
+
+void
+log_init(int n_debug, int facility)
+{
+ extern char *__progname;
+
+ debug = n_debug;
+ verbose = n_debug;
+ log_procinit(__progname);
+
+ if (!debug)
+ openlog(__progname, LOG_PID | LOG_NDELAY, facility);
+
+ tzset();
+}
+
+void
+log_procinit(const char *procname)
+{
+ if (procname != NULL)
+ log_procname = procname;
+}
+
+void
+log_setverbose(int v)
+{
+ verbose = v;
+}
+
+int
+log_getverbose(void)
+{
+ return (verbose);
+}
+
+void
+logit(int pri, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vlog(pri, fmt, ap);
+ va_end(ap);
+}
+
+void
+vlog(int pri, const char *fmt, va_list ap)
+{
+ char *nfmt;
+ int saved_errno = errno;
+
+ if (debug) {
+ /* best effort in out of mem situations */
+ if (asprintf(&nfmt, "%s\n", fmt) == -1) {
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ } else {
+ vfprintf(stderr, nfmt, ap);
+ free(nfmt);
+ }
+ fflush(stderr);
+ } else
+ vsyslog(pri, fmt, ap);
+
+ errno = saved_errno;
+}
+
+void
+log_warn(const char *emsg, ...)
+{
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
+
+ /* best effort to even work in out of memory situations */
+ if (emsg == NULL)
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
+ else {
+ va_start(ap, emsg);
+
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
+ /* we tried it... */
+ vlog(LOG_CRIT, emsg, ap);
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
+ } else {
+ vlog(LOG_CRIT, nfmt, ap);
+ free(nfmt);
+ }
+ va_end(ap);
+ }
+
+ errno = saved_errno;
+}
+
+void
+log_warnx(const char *emsg, ...)
+{
+ va_list ap;
+
+ va_start(ap, emsg);
+ vlog(LOG_CRIT, emsg, ap);
+ va_end(ap);
+}
+
+void
+log_info(const char *emsg, ...)
+{
+ va_list ap;
+
+ va_start(ap, emsg);
+ vlog(LOG_INFO, emsg, ap);
+ va_end(ap);
+}
+
+void
+log_debug(const char *emsg, ...)
+{
+ va_list ap;
+
+ if (verbose) {
+ va_start(ap, emsg);
+ vlog(LOG_DEBUG, emsg, ap);
+ va_end(ap);
+ }
+}
+
+static void
+vfatalc(int code, const char *emsg, va_list ap)
+{
+ static char s[BUFSIZ];
+ const char *sep;
+
+ if (emsg != NULL) {
+ (void)vsnprintf(s, sizeof(s), emsg, ap);
+ sep = ": ";
+ } else {
+ s[0] = '\0';
+ sep = "";
+ }
+ if (code)
+ logit(LOG_CRIT, "fatal in %s: %s%s%s",
+ log_procname, s, sep, strerror(code));
+ else
+ logit(LOG_CRIT, "fatal in %s%s%s", log_procname, sep, s);
+}
+
+void
+fatal(const char *emsg, ...)
+{
+ va_list ap;
+
+ va_start(ap, emsg);
+ vfatalc(errno, emsg, ap);
+ va_end(ap);
+ exit(1);
+}
+
+void
+fatalx(const char *emsg, ...)
+{
+ va_list ap;
+
+ va_start(ap, emsg);
+ vfatalc(0, emsg, ap);
+ va_end(ap);
+ exit(1);
+}
diff --git a/usr.sbin/dhcpd/log.h b/usr.sbin/dhcpd/log.h
new file mode 100644
index 00000000000..ff240f3f624
--- /dev/null
+++ b/usr.sbin/dhcpd/log.h
@@ -0,0 +1,46 @@
+/* $OpenBSD: log.h,v 1.1 2017/02/13 19:13:14 krw Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+#include <stdarg.h>
+#include <sys/cdefs.h>
+
+void log_init(int, int);
+void log_procinit(const char *);
+void log_setverbose(int);
+int log_getverbose(void);
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void fatal(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+__dead void fatalx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+
+#endif /* LOG_H */
diff --git a/usr.sbin/dhcpd/memory.c b/usr.sbin/dhcpd/memory.c
index 24e406dd689..6d479bafbad 100644
--- a/usr.sbin/dhcpd/memory.c
+++ b/usr.sbin/dhcpd/memory.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: memory.c,v 1.25 2016/02/07 10:24:04 jsg Exp $ */
+/* $OpenBSD: memory.c,v 1.26 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
@@ -53,6 +53,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
#include "sync.h"
struct subnet *subnets;
@@ -200,7 +201,7 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
/* All subnets should have attached shared network structures. */
if (!share) {
strlcpy(netbuf, piaddr(subnet->net), sizeof(netbuf));
- error("No shared network for network %s (%s)",
+ fatalx("No shared network for network %s (%s)",
netbuf, piaddr(subnet->netmask));
}
@@ -218,7 +219,7 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
strlcpy(lowbuf, piaddr(low), sizeof(lowbuf));
strlcpy(highbuf, piaddr(high), sizeof(highbuf));
strlcpy(netbuf, piaddr(subnet->netmask), sizeof(netbuf));
- error("Address range %s to %s, netmask %s spans %s!",
+ fatalx("Address range %s to %s, netmask %s spans %s!",
lowbuf, highbuf, netbuf, "multiple subnets");
}
@@ -227,7 +228,7 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
strlcpy(lowbuf, piaddr(low), sizeof(lowbuf));
strlcpy(highbuf, piaddr(high), sizeof(highbuf));
strlcpy(netbuf, piaddr(subnet->netmask), sizeof(netbuf));
- error("Address range %s to %s not on net %s/%s!",
+ fatalx("Address range %s to %s not on net %s/%s!",
lowbuf, highbuf, piaddr(subnet->net), netbuf);
}
@@ -246,7 +247,7 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
if (!address_range) {
strlcpy(lowbuf, piaddr(low), sizeof(lowbuf));
strlcpy(highbuf, piaddr(high), sizeof(highbuf));
- error("No memory for address range %s-%s.", lowbuf, highbuf);
+ fatalx("No memory for address range %s-%s.", lowbuf, highbuf);
}
memset(address_range, 0, (sizeof *address_range) * (max - min + 1));
@@ -269,11 +270,11 @@ new_address_range(struct iaddr low, struct iaddr high, struct subnet *subnet,
if (subnet->group->get_lease_hostnames) {
h = gethostbyaddr((char *)&ia, sizeof ia, AF_INET);
if (!h)
- warning("No hostname for %s", inet_ntoa(ia));
+ log_warnx("No hostname for %s", inet_ntoa(ia));
else {
address_range[i].hostname = strdup(h->h_name);
if (address_range[i].hostname == NULL)
- error("no memory for hostname %s.",
+ fatalx("no memory for hostname %s.",
h->h_name);
}
}
@@ -361,7 +362,7 @@ subnet_inner_than(struct subnet *subnet, struct subnet *scan, int warnp)
break;
strlcpy(n1buf, piaddr(subnet->net), sizeof(n1buf));
if (warnp)
- warning("%ssubnet %s/%d conflicts with subnet %s/%d",
+ log_warnx("%ssubnet %s/%d conflicts with subnet %s/%d",
"Warning: ", n1buf, 32 - i,
piaddr(scan->net), 32 - j);
if (i < j)
@@ -424,7 +425,7 @@ enter_lease(struct lease *lease)
if (!comp) {
comp = calloc(1, sizeof(struct lease));
if (!comp)
- error("No memory for lease %s\n",
+ fatalx("No memory for lease %s\n",
piaddr(lease->ip_addr));
*comp = *lease;
comp->next = dangling_leases;
@@ -489,7 +490,7 @@ supersede_lease(struct lease *comp, struct lease *lease, int commit)
*/
if (!(lease->flags & ABANDONED_LEASE) &&
comp->ends > cur_time && uid_or_hwaddr_cmp(comp, lease)) {
- warning("Lease conflict at %s", piaddr(comp->ip_addr));
+ log_warnx("Lease conflict at %s", piaddr(comp->ip_addr));
return 0;
} else {
/* If there's a Unique ID, dissociate it from the hash
@@ -529,7 +530,7 @@ supersede_lease(struct lease *comp, struct lease *lease, int commit)
lease->uid = NULL;
lease->uid_max = 0;
} else {
- error("corrupt lease uid."); /* XXX */
+ fatalx("corrupt lease uid."); /* XXX */
}
} else {
comp->uid = NULL;
@@ -639,7 +640,7 @@ release_lease(struct lease *lease)
if (lt.ends > cur_time) {
lt.ends = cur_time;
supersede_lease(lease, &lt, 1);
- note("Released lease for IP address %s",
+ log_info("Released lease for IP address %s",
piaddr(lease->ip_addr));
pfmsg('R', lease);
}
@@ -661,7 +662,7 @@ abandon_lease(struct lease *lease, char *message)
lease->flags |= ABANDONED_LEASE;
lt = *lease;
lt.ends = cur_time + abtime;
- warning("Abandoning IP address %s for %lld seconds: %s",
+ log_warnx("Abandoning IP address %s for %lld seconds: %s",
piaddr(lease->ip_addr), (long long)abtime, message);
lt.hardware_addr.htype = 0;
lt.hardware_addr.hlen = 0;
@@ -824,7 +825,7 @@ add_class(int type, char *name)
user_class_hash = new_hash();
if (!tname || !class || !vendor_class_hash || !user_class_hash) {
- warning("No memory for %s.", name);
+ log_warnx("No memory for %s.", name);
free(class);
free(tname);
return NULL;
@@ -856,7 +857,7 @@ clone_group(struct group *group, char *caller)
g = calloc(1, sizeof(struct group));
if (!g)
- error("%s: can't allocate new group", caller);
+ fatalx("%s: can't allocate new group", caller);
*g = *group;
return g;
}
@@ -874,12 +875,12 @@ write_leases(void)
if (l->hardware_addr.hlen || l->uid_len ||
(l->flags & ABANDONED_LEASE)) {
if (!write_lease(l))
- error("Can't rewrite lease database");
+ fatalx("Can't rewrite lease database");
if (syncsend)
sync_lease(l);
}
}
}
if (!commit_leases())
- error("Can't commit leases to new database: %m");
+ fatalx("Can't commit leases to new database: %m");
}
diff --git a/usr.sbin/dhcpd/options.c b/usr.sbin/dhcpd/options.c
index ac9c425c621..8c3557520dc 100644
--- a/usr.sbin/dhcpd/options.c
+++ b/usr.sbin/dhcpd/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.33 2016/11/15 10:49:37 mestre Exp $ */
+/* $OpenBSD: options.c,v 1.34 2017/02/13 19:13:14 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -54,6 +54,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
int bad_options = 0;
int bad_options_max = 5;
@@ -150,17 +151,17 @@ parse_option_buffer(struct packet *packet,
if (s + len + 2 > end) {
bogus:
bad_options++;
- warning("option %s (%d) %s.",
+ log_warnx("option %s (%d) %s.",
dhcp_options[code].name, len,
"larger than buffer");
if (bad_options == bad_options_max) {
packet->options_valid = 1;
bad_options = 0;
- warning("Many bogus options seen in offers.");
- warning("Taking this offer in spite of bogus");
- warning("options - hope for the best!");
+ log_warnx("Many bogus options seen in offers.");
+ log_warnx("Taking this offer in spite of bogus");
+ log_warnx("options - hope for the best!");
} else {
- warning("rejecting bogus offer.");
+ log_warnx("rejecting bogus offer.");
packet->options_valid = 0;
}
return;
@@ -172,7 +173,7 @@ parse_option_buffer(struct packet *packet,
if (!packet->options[code].data) {
t = calloc(1, len + 1);
if (!t)
- error("Can't allocate storage for option %s.",
+ fatalx("Can't allocate storage for option %s.",
dhcp_options[code].name);
/*
* Copy and NUL-terminate the option (in case
@@ -190,7 +191,7 @@ parse_option_buffer(struct packet *packet,
*/
t = calloc(1, len + packet->options[code].len + 1);
if (!t)
- error("Can't expand storage for option %s.",
+ fatalx("Can't expand storage for option %s.",
dhcp_options[code].name);
memcpy(t, packet->options[code].data,
packet->options[code].len);
@@ -530,7 +531,7 @@ do_packet(struct interface_info *interface, struct dhcp_packet *packet,
int i;
if (packet->hlen > sizeof(packet->chaddr)) {
- note("Discarding packet with invalid hlen.");
+ log_info("Discarding packet with invalid hlen.");
return;
}
diff --git a/usr.sbin/dhcpd/packet.c b/usr.sbin/dhcpd/packet.c
index 121cfa96815..2514c73404a 100644
--- a/usr.sbin/dhcpd/packet.c
+++ b/usr.sbin/dhcpd/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.11 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: packet.c,v 1.12 2017/02/13 19:13:14 krw Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
@@ -56,6 +56,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
u_int32_t checksum(unsigned char *, unsigned, u_int32_t);
u_int32_t wrapsum(u_int32_t);
@@ -198,7 +199,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
ip_packets_bad_checksum++;
if (ip_packets_seen > 4 && ip_packets_bad_checksum != 0 &&
(ip_packets_seen / ip_packets_bad_checksum) < 2) {
- note("%u bad IP checksums seen in %u packets",
+ log_info("%u bad IP checksums seen in %u packets",
ip_packets_bad_checksum, ip_packets_seen);
ip_packets_seen = ip_packets_bad_checksum = 0;
}
@@ -209,7 +210,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
#ifdef DEBUG
if (ntohs(ip->ip_len) != buflen)
- debug("ip length %d disagrees with bytes received %d.",
+ log_debug("ip length %d disagrees with bytes received %d.",
ntohs(ip->ip_len), buflen);
#endif
@@ -242,7 +243,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
udp_packets_length_overflow != 0 &&
(udp_packets_length_checked /
udp_packets_length_overflow) < 2) {
- note("%u udp packets in %u too long - dropped",
+ log_info("%u udp packets in %u too long - dropped",
udp_packets_length_overflow,
udp_packets_length_checked);
udp_packets_length_overflow =
@@ -251,7 +252,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
return (-1);
}
if (len + data != buf + bufix + buflen)
- debug("accepting packet with data after udp payload.");
+ log_debug("accepting packet with data after udp payload.");
usum = udp->uh_sum;
udp->uh_sum = 0;
@@ -266,7 +267,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
udp_packets_bad_checksum++;
if (udp_packets_seen > 4 && udp_packets_bad_checksum != 0 &&
(udp_packets_seen / udp_packets_bad_checksum) < 2) {
- note("%u bad udp checksums in %u packets",
+ log_info("%u bad udp checksums in %u packets",
udp_packets_bad_checksum, udp_packets_seen);
udp_packets_seen = udp_packets_bad_checksum = 0;
}
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 392b2b792a8..018983f1dc0 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.22 2017/02/11 16:12:36 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.23 2017/02/13 19:13:14 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -48,6 +48,7 @@
#include <netinet/in.h>
#include <ctype.h>
+#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
@@ -61,6 +62,7 @@
#include "tree.h"
#include "dhcpd.h"
#include "dhctoken.h"
+#include "log.h"
/*
* Skip to the semicolon ending the current statement. If we encounter
@@ -144,7 +146,7 @@ parse_string(FILE *cfile)
}
s = strdup(val);
if (s == NULL)
- error("no memory for string %s.", val);
+ fatalx("no memory for string %s.", val);
if (!parse_semi(cfile)) {
free(s);
@@ -175,7 +177,7 @@ parse_host_name(FILE *cfile)
/* Store this identifier... */
s = strdup(val);
if (s == NULL)
- error("can't allocate temp space for hostname.");
+ fatalx("can't allocate temp space for hostname.");
c = cons((caddr_t) s, c);
len += strlen(s) + 1;
/*
@@ -189,7 +191,7 @@ parse_host_name(FILE *cfile)
/* Assemble the hostname together into a string. */
if (!(s = malloc(len)))
- error("can't allocate space for hostname.");
+ fatalx("can't allocate space for hostname.");
t = s + len;
*--t = '\0';
while (c) {
@@ -310,7 +312,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
if (!bufp && *max) {
bufp = malloc(*max * size / 8);
if (!bufp)
- error("can't allocate space for numeric aggregate");
+ fatalx("can't allocate space for numeric aggregate");
} else
s = bufp;
@@ -350,7 +352,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
} else {
t = strdup(val);
if (t == NULL)
- error("no temp space for number.");
+ fatalx("no temp space for number.");
c = cons(t, c);
}
} while (++count != *max);
@@ -359,7 +361,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
if (c) {
bufp = malloc(count * size / 8);
if (!bufp)
- error("can't allocate space for numeric aggregate.");
+ fatalx("can't allocate space for numeric aggregate.");
s = bufp + count - size / 8;
*max = count;
}
@@ -413,11 +415,11 @@ convert_num(unsigned char *buf, char *str, int base, int size)
else if (tval >= '0')
tval -= '0';
else {
- warning("Bogus number: %s.", str);
+ log_warnx("Bogus number: %s.", str);
break;
}
if (tval >= base) {
- warning("Bogus number: %s: digit %d not in base %d",
+ log_warnx("Bogus number: %s: digit %d not in base %d",
str, tval, base);
break;
}
@@ -431,15 +433,15 @@ convert_num(unsigned char *buf, char *str, int base, int size)
if (val > max) {
switch (base) {
case 8:
- warning("value %s%o exceeds max (%d) for precision.",
+ log_warnx("value %s%o exceeds max (%d) for precision.",
negative ? "-" : "", val, max);
break;
case 16:
- warning("value %s%x exceeds max (%d) for precision.",
+ log_warnx("value %s%x exceeds max (%d) for precision.",
negative ? "-" : "", val, max);
break;
default:
- warning("value %s%u exceeds max (%d) for precision.",
+ log_warnx("value %s%u exceeds max (%d) for precision.",
negative ? "-" : "", val, max);
break;
}
@@ -457,7 +459,7 @@ convert_num(unsigned char *buf, char *str, int base, int size)
putLong(buf, -(unsigned long)val);
break;
default:
- warning("Unexpected integer size: %d", size);
+ log_warnx("Unexpected integer size: %d", size);
break;
}
} else {
@@ -472,7 +474,7 @@ convert_num(unsigned char *buf, char *str, int base, int size)
putULong(buf, val);
break;
default:
- warning("Unexpected integer size: %d", size);
+ log_warnx("Unexpected integer size: %d", size);
break;
}
}
@@ -545,11 +547,50 @@ parse_date(FILE *cfile)
return (guess);
}
+/*
+ * Find %m in the input string and substitute an error message string.
+ */
+void
+do_percentm(char *obuf, size_t size, char *ibuf)
+{
+ char ch;
+ char *s = ibuf;
+ char *t = obuf;
+ size_t prlen;
+ size_t fmt_left;
+ int saved_errno = errno;
+
+ /*
+ * We wouldn't need this mess if printf handled %m, or if
+ * strerror() had been invented before syslog_r().
+ */
+ for (fmt_left = size; (ch = *s); ++s) {
+ if (ch == '%' && s[1] == 'm') {
+ ++s;
+ prlen = snprintf(t, fmt_left, "%s",
+ strerror(saved_errno));
+ if (prlen == -1)
+ prlen = 0;
+ if (prlen >= fmt_left)
+ prlen = fmt_left - 1;
+ t += prlen;
+ fmt_left -= prlen;
+ } else {
+ if (fmt_left > 1) {
+ *t++ = ch;
+ fmt_left--;
+ }
+ }
+ }
+ *t = '\0';
+}
+int warnings_occurred;
+
int
parse_warn(char *fmt, ...)
{
- extern char mbuf[1024];
- extern char fbuf[1024];
+ static char fbuf[1024];
+ static char mbuf[1024];
va_list list;
static char spaces[] =
" "
@@ -582,11 +623,10 @@ parse_warn(char *fmt, ...)
}
writev(STDERR_FILENO, iov, iovcnt);
} else {
- syslog_r(log_priority | LOG_ERR, &sdata, "%s", mbuf);
- syslog_r(log_priority | LOG_ERR, &sdata, "%s", token_line);
+ log_warnx("%s", mbuf);
+ log_warnx("%s", token_line);
if (lexchar < 81)
- syslog_r(log_priority | LOG_ERR, &sdata, "%*c", lexchar,
- '^');
+ log_warnx("%*c", lexchar, '^');
}
warnings_occurred = 1;
diff --git a/usr.sbin/dhcpd/pfutils.c b/usr.sbin/dhcpd/pfutils.c
index 401eee02539..145c58cc9ff 100644
--- a/usr.sbin/dhcpd/pfutils.c
+++ b/usr.sbin/dhcpd/pfutils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfutils.c,v 1.15 2016/11/15 10:49:37 mestre Exp $ */
+/* $OpenBSD: pfutils.c,v 1.16 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 2006 Chris Kuethe <ckuethe@openbsd.org>
*
@@ -36,6 +36,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
extern struct passwd *pw;
extern int pfpipe[2];
@@ -52,15 +53,15 @@ pftable_handler()
int l, r, fd, nfds;
if ((fd = open(_PATH_DEV_PF, O_RDWR|O_NOFOLLOW, 0660)) == -1)
- error("can't open pf device: %m");
+ log_warnx("can't open pf device: %m");
if (chroot(_PATH_VAREMPTY) == -1)
- error("chroot %s: %m", _PATH_VAREMPTY);
+ log_warnx("chroot %s: %m", _PATH_VAREMPTY);
if (chdir("/") == -1)
- error("chdir(\"/\"): %m");
+ log_warnx("chdir(\"/\"): %m");
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- error("can't drop privileges: %m");
+ log_warnx("can't drop privileges: %m");
setproctitle("pf table handler");
l = sizeof(struct pf_cmd);
@@ -70,17 +71,17 @@ pftable_handler()
pfd[0].events = POLLIN;
if ((nfds = poll(pfd, 1, -1)) == -1)
if (errno != EINTR)
- error("poll: %m");
+ log_warnx("poll: %m");
if (nfds > 0 && (pfd[0].revents & POLLHUP))
- error("pf pipe closed");
+ log_warnx("pf pipe closed");
if (nfds > 0 && (pfd[0].revents & POLLIN)) {
memset(&cmd, 0, l);
r = atomicio(read, pfpipe[0], &cmd, l);
if (r != l)
- error("pf pipe error: %m");
+ log_warnx("pf pipe error: %m");
switch (cmd.type) {
case 'A':
@@ -155,7 +156,7 @@ pf_change_table(int fd, int op, struct in_addr ip, char *table)
if (ioctl(fd, op ? DIOCRADDADDRS : DIOCRDELADDRS, &io) &&
errno != ESRCH) {
- warning( "DIOCR%sADDRS on table %s: %s",
+ log_warnx( "DIOCR%sADDRS on table %s: %s",
op ? "ADD" : "DEL", table, strerror(errno));
}
}
@@ -178,7 +179,7 @@ pf_kill_state(int fd, struct in_addr ip)
memset(&psk.psk_src.addr.v.a.mask, 0xff,
sizeof(psk.psk_src.addr.v.a.mask));
if (ioctl(fd, DIOCKILLSTATES, &psk)) {
- warning("DIOCKILLSTATES failed (%s)", strerror(errno));
+ log_warnx("DIOCKILLSTATES failed (%s)", strerror(errno));
}
/* Kill all states to target */
@@ -188,7 +189,7 @@ pf_kill_state(int fd, struct in_addr ip)
memset(&psk.psk_dst.addr.v.a.mask, 0xff,
sizeof(psk.psk_dst.addr.v.a.mask));
if (ioctl(fd, DIOCKILLSTATES, &psk)) {
- warning("DIOCKILLSTATES failed (%s)", strerror(errno));
+ log_warnx("DIOCKILLSTATES failed (%s)", strerror(errno));
}
}
diff --git a/usr.sbin/dhcpd/sync.c b/usr.sbin/dhcpd/sync.c
index faaac10cbea..781e1f328af 100644
--- a/usr.sbin/dhcpd/sync.c
+++ b/usr.sbin/dhcpd/sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sync.c,v 1.19 2016/10/21 11:34:48 mestre Exp $ */
+/* $OpenBSD: sync.c,v 1.20 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 2008 Bob Beck <beck@openbsd.org>
@@ -40,6 +40,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
#include "sync.h"
int sync_debug;
@@ -104,7 +105,7 @@ sync_addhost(const char *name, u_short port)
LIST_INSERT_HEAD(&sync_hosts, shost, h_entry);
if (sync_debug)
- note("added dhcp sync host %s (address %s, port %d)\n",
+ log_info("added dhcp sync host %s (address %s, port %d)\n",
shost->h_name, inet_ntoa(shost->sh_addr.sin_addr), port);
return (0);
@@ -219,7 +220,7 @@ sync_init(const char *iface, const char *baddr, u_short port)
}
if (sync_debug)
- syslog_r(LOG_DEBUG, &sdata, "using multicast dhcp sync %smode "
+ log_debug("using multicast dhcp sync %smode "
"(ttl %u, group %s, port %d)\n",
sendmcast ? "" : "receive ",
ttl, inet_ntoa(sync_out.sin_addr), port);
@@ -277,7 +278,7 @@ sync_recv(void)
goto trunc;
if (sync_debug)
- note("%s(sync): received packet of %d bytes\n",
+ log_info("%s(sync): received packet of %d bytes\n",
inet_ntoa(addr.sin_addr), (int)len);
p = (u_int8_t *)(hdr + 1);
@@ -308,7 +309,7 @@ sync_recv(void)
sizeof(lp->ip_addr));
memcpy(&lp->hardware_addr, &lv->lv_hardware_addr,
sizeof(lp->hardware_addr));
- note("DHCP_SYNC_LEASE from %s for hw %s -> ip %s, "
+ log_info("DHCP_SYNC_LEASE from %s for hw %s -> ip %s, "
"start %lld, end %lld",
inet_ntoa(addr.sin_addr),
print_hw_addr(lp->hardware_addr.htype,
@@ -346,7 +347,7 @@ sync_recv(void)
trunc:
if (sync_debug)
- note("%s(sync): truncated or invalid packet\n",
+ log_info("%s(sync): truncated or invalid packet\n",
inet_ntoa(addr.sin_addr));
}
@@ -366,21 +367,21 @@ sync_send(struct iovec *iov, int iovlen)
if (sendmcast) {
if (sync_debug)
- note("sending multicast sync message\n");
+ log_info("sending multicast sync message\n");
msg.msg_name = &sync_out;
msg.msg_namelen = sizeof(sync_out);
if (sendmsg(syncfd, &msg, 0) == -1)
- warning("sending multicast sync message failed: %m");
+ log_warnx("sending multicast sync message failed: %m");
}
LIST_FOREACH(shost, &sync_hosts, h_entry) {
if (sync_debug)
- note("sending sync message to %s (%s)\n",
+ log_info("sending sync message to %s (%s)\n",
shost->h_name, inet_ntoa(shost->sh_addr.sin_addr));
msg.msg_name = &shost->sh_addr;
msg.msg_namelen = sizeof(shost->sh_addr);
if (sendmsg(syncfd, &msg, 0) == -1)
- warning("sending sync message failed: %m");
+ log_warnx("sending sync message failed: %m");
}
}
@@ -429,7 +430,7 @@ sync_lease(struct lease *lease)
memcpy(&lv.lv_ip_addr, &lease->ip_addr, sizeof(lv.lv_ip_addr));
memcpy(&lv.lv_hardware_addr, &lease->hardware_addr,
sizeof(lv.lv_hardware_addr));
- note("sending DHCP_SYNC_LEASE for hw %s -> ip %s, start %d, end %d",
+ log_info("sending DHCP_SYNC_LEASE for hw %s -> ip %s, start %d, end %d",
print_hw_addr(lv.lv_hardware_addr.htype, lv.lv_hardware_addr.hlen,
lv.lv_hardware_addr.haddr), piaddr(lease->ip_addr),
ntohl(lv.lv_starts), ntohl(lv.lv_ends));
diff --git a/usr.sbin/dhcpd/tables.c b/usr.sbin/dhcpd/tables.c
index e56e20497bc..48763251eb7 100644
--- a/usr.sbin/dhcpd/tables.c
+++ b/usr.sbin/dhcpd/tables.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tables.c,v 1.12 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: tables.c,v 1.13 2017/02/13 19:13:14 krw Exp $ */
/* Tables of information... */
@@ -52,6 +52,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
/*
* DHCP Option names, formats and codes, from RFC1533.
@@ -698,7 +699,7 @@ initialize_universes(void)
dhcp_universe.name = "dhcp";
dhcp_universe.hash = new_hash();
if (!dhcp_universe.hash)
- error("Can't allocate dhcp option hash table.");
+ fatalx("Can't allocate dhcp option hash table.");
for (i = 0; i < 256; i++) {
dhcp_universe.options[i] = &dhcp_options[i];
add_hash(dhcp_universe.hash,
diff --git a/usr.sbin/dhcpd/tree.c b/usr.sbin/dhcpd/tree.c
index 52f0a36a7b0..a0a61e362bc 100644
--- a/usr.sbin/dhcpd/tree.c
+++ b/usr.sbin/dhcpd/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.17 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: tree.c,v 1.18 2017/02/13 19:13:14 krw Exp $ */
/* Routines for manipulating parse trees... */
@@ -54,6 +54,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
static time_t tree_evaluate_recurse(int *, unsigned char **, int *,
struct tree *);
@@ -66,7 +67,7 @@ cons(caddr_t car, pair cdr)
foo = calloc(1, sizeof *foo);
if (!foo)
- error("no memory for cons.");
+ fatalx("no memory for cons.");
foo->car = car;
foo->cdr = cdr;
return foo;
@@ -96,7 +97,7 @@ tree_const(unsigned char *data, int len)
d = calloc(1, len);
nt = calloc(1, sizeof(struct tree));
if (!nt || !d)
- error("No memory for constant data tree node.");
+ fatalx("No memory for constant data tree node.");
memcpy(d, data, len);
@@ -130,7 +131,7 @@ tree_concat(struct tree *left, struct tree *right)
+ right->data.const_val.len);
if (!buf)
- error("No memory to concatenate constants.");
+ fatalx("No memory to concatenate constants.");
memcpy(buf, left->data.const_val.data,
left->data.const_val.len);
memcpy(buf + left->data.const_val.len,
@@ -146,7 +147,7 @@ tree_concat(struct tree *left, struct tree *right)
/* Otherwise, allocate a new node to concatenate the two. */
nt = calloc(1, sizeof(struct tree));
if (!nt)
- error("No memory for data tree concatenation node.");
+ fatalx("No memory for data tree concatenation node.");
nt->op = TREE_CONCAT;
nt->data.concat.left = left;
nt->data.concat.right = right;
@@ -168,7 +169,7 @@ tree_limit(struct tree *tree, int limit)
/* Otherwise, put in a node which enforces the limit on evaluation. */
rv = calloc(1, sizeof(struct tree));
if (!rv) {
- warning("No memory for data tree limit node.");
+ log_warnx("No memory for data tree limit node.");
return NULL;
}
rv->op = TREE_LIMIT;
@@ -207,7 +208,7 @@ tree_evaluate(struct tree_cache *tree_cache)
*/
bp = calloc(1, bufix);
if (!bp) {
- warning("no more memory for option data");
+ log_warnx("no more memory for option data");
return 0;
}
@@ -264,7 +265,7 @@ tree_evaluate_recurse(int *bufix, unsigned char **bufp,
return t1;
default:
- warning("Bad node id in tree: %d.", tree->op);
+ log_warnx("Bad node id in tree: %d.", tree->op);
t1 = MAX_TIME;
return t1;
}
diff --git a/usr.sbin/dhcpd/udpsock.c b/usr.sbin/dhcpd/udpsock.c
index 2c4c0503218..f88cc72a596 100644
--- a/usr.sbin/dhcpd/udpsock.c
+++ b/usr.sbin/dhcpd/udpsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udpsock.c,v 1.7 2016/04/27 10:16:10 mestre Exp $ */
+/* $OpenBSD: udpsock.c,v 1.8 2017/02/13 19:13:14 krw Exp $ */
/*
* Copyright (c) 2014 YASUOKA Masahiko <yasuoka@openbsd.org>
@@ -37,6 +37,7 @@
#include "dhcp.h"
#include "tree.h"
#include "dhcpd.h"
+#include "log.h"
void udpsock_handler (struct protocol *);
ssize_t udpsock_send_packet(struct interface_info *, struct dhcp_packet *,
@@ -54,15 +55,15 @@ udpsock_startup(struct in_addr bindaddr)
struct udpsock *udpsock;
if ((udpsock = calloc(1, sizeof(struct udpsock))) == NULL)
- error("could not create udpsock: %s", strerror(errno));
+ fatalx("could not create udpsock: %s", strerror(errno));
memset(&sin4, 0, sizeof(sin4));
if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- error("creating a socket failed for udp: %s", strerror(errno));
+ fatalx("creating a socket failed for udp: %s", strerror(errno));
onoff = 1;
if (setsockopt(sock, IPPROTO_IP, IP_RECVIF, &onoff, sizeof(onoff)) != 0)
- error("setsocketopt IP_RECVIF failed for udp: %s",
+ fatalx("setsocketopt IP_RECVIF failed for udp: %s",
strerror(errno));
sin4.sin_family = AF_INET;
@@ -71,10 +72,10 @@ udpsock_startup(struct in_addr bindaddr)
sin4.sin_port = server_port;
if (bind(sock, (struct sockaddr *)&sin4, sizeof(sin4)) != 0)
- error("bind failed for udp: %s", strerror(errno));
+ fatalx("bind failed for udp: %s", strerror(errno));
add_protocol("udp", sock, udpsock_handler, (void *)(intptr_t)udpsock);
- note("Listening on %s:%d/udp.", inet_ntoa(sin4.sin_addr),
+ log_info("Listening on %s:%d/udp.", inet_ntoa(sin4.sin_addr),
ntohs(server_port));
udpsock->sock = sock;
@@ -115,11 +116,11 @@ udpsock_handler(struct protocol *protocol)
memset(&iface, 0, sizeof(iface));
if ((len = recvmsg(udpsock->sock, &m, 0)) < 0) {
- warning("receiving a DHCP message failed: %s", strerror(errno));
+ log_warnx("receiving a DHCP message failed: %s", strerror(errno));
return;
}
if (ss.ss_family != AF_INET) {
- warning("received DHCP message is not AF_INET");
+ log_warnx("received DHCP message is not AF_INET");
return;
}
sin4 = (struct sockaddr_in *)&ss;
@@ -131,18 +132,18 @@ udpsock_handler(struct protocol *protocol)
sdl = (struct sockaddr_dl *)CMSG_DATA(cm);
}
if (sdl == NULL) {
- warning("could not get the received interface by IP_RECVIF");
+ log_warnx("could not get the received interface by IP_RECVIF");
return;
}
if_indextoname(sdl->sdl_index, ifname);
if ((sockio = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- warning("socket creation failed: %s", strerror(errno));
+ log_warnx("socket creation failed: %s", strerror(errno));
return;
}
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sockio, SIOCGIFADDR, &ifr, sizeof(ifr)) != 0) {
- warning("Failed to get address for %s: %s", ifname,
+ log_warnx("Failed to get address for %s: %s", ifname,
strerror(errno));
close(sockio);
return;