summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbin/dhclient/dhclient.c72
-rw-r--r--sbin/dhclient/dhcpd.h8
-rw-r--r--sbin/dhclient/options.c22
3 files changed, 66 insertions, 36 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index f4ee0b9805f..3ec2097fb2e 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.207 2013/01/16 05:16:02 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.208 2013/01/16 06:11:21 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -170,7 +170,7 @@ routehandler(void)
char msg[2048];
struct in_addr a, b;
ssize_t n;
- int linkstat;
+ int linkstat, rslt;
struct rt_msghdr *rtm;
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
@@ -199,7 +199,7 @@ routehandler(void)
sa = get_ifa((char *)ifam + ifam->ifam_hdrlen,
ifam->ifam_addrs);
if (sa == NULL) {
- errmsg = "sa == NULL";
+ rslt = asprintf(&errmsg, "%s sa == NULL", ifi->name);
goto die;
}
@@ -221,7 +221,13 @@ routehandler(void)
go_daemon();
break;
}
- errmsg = "interface address added";
+ if (adding.s_addr != INADDR_ANY)
+ rslt = asprintf(&errmsg, "%s, not %s, added "
+ "to %s", inet_ntoa(a), inet_ntoa(adding),
+ ifi->name);
+ else
+ rslt = asprintf(&errmsg, "%s added to %s",
+ inet_ntoa(a), ifi->name);
} else {
if (a.s_addr == deleting.s_addr) {
deleting.s_addr = INADDR_ANY;
@@ -234,7 +240,13 @@ routehandler(void)
add_address(ifi->name, 0, b, b);
break;
}
- errmsg = "interface address deleted";
+ if (deleting.s_addr != INADDR_ANY)
+ rslt = asprintf(&errmsg, "%s, not %s, deleted "
+ "from %s", inet_ntoa(a),
+ inet_ntoa(deleting), ifi->name);
+ else
+ rslt = asprintf(&errmsg, "%s deleted from %s",
+ inet_ntoa(a), ifi->name);
}
goto die;
case RTM_IFINFO:
@@ -242,7 +254,7 @@ routehandler(void)
if (ifm->ifm_index != ifi->index)
break;
if ((rtm->rtm_flags & RTF_UP) == 0) {
- errmsg = "interface down";
+ rslt = asprintf(&errmsg, "%s down", ifi->name);
goto die;
}
@@ -265,7 +277,7 @@ routehandler(void)
ifan = (struct if_announcemsghdr *)rtm;
if (ifan->ifan_what == IFAN_DEPARTURE &&
ifan->ifan_index == ifi->index) {
- errmsg = "interface departure";
+ rslt = asprintf(&errmsg, "%s departured", ifi->name);
goto die;
}
break;
@@ -275,7 +287,10 @@ routehandler(void)
return;
die:
+ if (rslt == -1)
+ error("no memory for errmsg");
error("routehandler: %s", errmsg);
+ free(errmsg);
}
char **saved_argv;
@@ -627,7 +642,7 @@ state_selecting(void)
}
void
-dhcpack(struct in_addr client_addr, struct option_data *options)
+dhcpack(struct in_addr client_addr, struct option_data *options, char *info)
{
struct client_lease *lease;
time_t cur_time;
@@ -635,15 +650,19 @@ dhcpack(struct in_addr client_addr, struct option_data *options)
if (client->state != S_REBOOTING &&
client->state != S_REQUESTING &&
client->state != S_RENEWING &&
- client->state != S_REBINDING)
+ client->state != S_REBINDING) {
+ note("Unexpected %s. State #%d", info, client->state);
return;
+ }
lease = packet_to_lease(client_addr, options);
if (!lease) {
- note("DHCPACK isn't satisfactory.");
+ note("Unsatisfactory %s", info);
return;
}
+ note("%s", info);
+
client->new = lease;
/* Stop resending DHCPREQUEST. */
@@ -792,19 +811,13 @@ state_bound(void)
}
void
-dhcpoffer(struct in_addr client_addr, struct option_data *options)
+dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info)
{
struct client_lease *lease, *lp;
time_t stop_selecting;
- char *name = options[DHO_DHCP_MESSAGE_TYPE].len ? "DHCPOFFER" :
- "BOOTREPLY";
-
- if (client->state != S_SELECTING)
- return;
- lease = packet_to_lease(client_addr, options);
- if (!lease) {
- note("%s isn't satisfactory.", name);
+ if (client->state != S_SELECTING) {
+ note("Unexpected %s. State #%d.", info, client->state);
return;
}
@@ -813,13 +826,18 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options)
if (!memcmp(&lp->address.s_addr, &client->packet.yiaddr,
sizeof(in_addr_t))) {
#ifdef DEBUG
- debug("%s already seen.", name);
+ debug("Duplicate %s.", info);
#endif
- free_client_lease(lease);
return;
}
}
+ lease = packet_to_lease(client_addr, options);
+ if (!lease) {
+ note("Unsatisfactory %s", info);
+ return;
+ }
+
/*
* Reject offers whose subnet is already configured on another
* interface.
@@ -853,6 +871,8 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options)
}
}
+ note("%s", info);
+
/* If the selecting interval has expired, go immediately to
state_selecting(). Otherwise, time out into
state_selecting at the select interval. */
@@ -964,19 +984,23 @@ packet_to_lease(struct in_addr client_addr, struct option_data *options)
}
void
-dhcpnak(struct in_addr client_addr, struct option_data *options)
+dhcpnak(struct in_addr client_addr, struct option_data *options, char *info)
{
if (client->state != S_REBOOTING &&
client->state != S_REQUESTING &&
client->state != S_RENEWING &&
- client->state != S_REBINDING)
+ client->state != S_REBINDING) {
+ note("Unexpected %s. State #%d", info, client->state);
return;
+ }
if (!client->active) {
- note("DHCPNAK with no active lease.");
+ note("Unexpected %s. No active lease.", info);
return;
}
+ note("%s", info);
+
free_client_lease(client->active);
client->active = NULL;
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 1d144bfe6e1..c18717bdf6f 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.99 2013/01/05 20:34:17 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.100 2013/01/16 06:11:21 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -270,9 +270,9 @@ extern char *path_dhclient_db;
extern int log_perror;
extern int routefd;
-void dhcpoffer(struct in_addr, struct option_data *);
-void dhcpack(struct in_addr, struct option_data *);
-void dhcpnak(struct in_addr, struct option_data *);
+void dhcpoffer(struct in_addr, struct option_data *, char *);
+void dhcpack(struct in_addr, struct option_data *, char *);
+void dhcpnak(struct in_addr, struct option_data *, char *);
void send_discover(void);
void send_request(void);
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index 205312b0ae5..ca0fa0542d4 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.47 2013/01/13 22:50:33 krw Exp $ */
+/* $OpenBSD: options.c,v 1.48 2013/01/16 06:11:21 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -463,9 +463,9 @@ do_packet(int len, unsigned int from_port, struct in_addr from,
struct dhcp_packet *packet = &client->packet;
struct option_data options[256];
struct reject_elem *ap;
- void (*handler)(struct in_addr, struct option_data *);
- char *type;
- int i, options_valid = 1;
+ void (*handler)(struct in_addr, struct option_data *, char *);
+ char *type, *info;
+ int i, rslt, options_valid = 1;
if (packet->hlen > sizeof(packet->chaddr)) {
note("Discarding packet with invalid hlen.");
@@ -531,21 +531,27 @@ do_packet(int len, unsigned int from_port, struct in_addr from,
if (handler && client->xid == client->packet.xid) {
if (hfrom->hlen == 6)
- note("%s from %s (%s)", type, inet_ntoa(from),
+ rslt = asprintf(&info, "%s from %s (%s)", type,
+ inet_ntoa(from),
ether_ntoa((struct ether_addr *)hfrom->haddr));
else
- note("%s from %s", type, inet_ntoa(from));
+ rslt = asprintf(&info, "%s from %s", type,
+ inet_ntoa(from));
+ if (rslt == -1)
+ error("no memory for info string");
} else
handler = NULL;
for (ap = config->reject_list; ap && handler; ap = ap->next)
if (from.s_addr == ap->addr.s_addr) {
- note("%s from %s rejected.", type, inet_ntoa(from));
+ note("Rejected %s.", info);
handler = NULL;
}
if (handler)
- (*handler)(from, options);
+ (*handler)(from, options, info);
+
+ free(info);
for (i = 0; i < 256; i++)
if (options[i].len && options[i].data)