From d128b24e9055a9a6459a6c932c8b57c587d08b6b Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Wed, 16 Jan 2013 11:02:11 +0000 Subject: Revert last. asprintf() breaks something. --- sbin/dhclient/dhclient.c | 72 ++++++++++++++++-------------------------------- sbin/dhclient/dhcpd.h | 8 +++--- sbin/dhclient/options.c | 22 ++++++--------- 3 files changed, 36 insertions(+), 66 deletions(-) (limited to 'sbin') diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 3ec2097fb2e..065a1829f51 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.208 2013/01/16 06:11:21 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.209 2013/01/16 11:02:09 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -170,7 +170,7 @@ routehandler(void) char msg[2048]; struct in_addr a, b; ssize_t n; - int linkstat, rslt; + int linkstat; 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) { - rslt = asprintf(&errmsg, "%s sa == NULL", ifi->name); + errmsg = "sa == NULL"; goto die; } @@ -221,13 +221,7 @@ routehandler(void) go_daemon(); break; } - 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); + errmsg = "interface address added"; } else { if (a.s_addr == deleting.s_addr) { deleting.s_addr = INADDR_ANY; @@ -240,13 +234,7 @@ routehandler(void) add_address(ifi->name, 0, b, b); break; } - 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); + errmsg = "interface address deleted"; } goto die; case RTM_IFINFO: @@ -254,7 +242,7 @@ routehandler(void) if (ifm->ifm_index != ifi->index) break; if ((rtm->rtm_flags & RTF_UP) == 0) { - rslt = asprintf(&errmsg, "%s down", ifi->name); + errmsg = "interface down"; goto die; } @@ -277,7 +265,7 @@ routehandler(void) ifan = (struct if_announcemsghdr *)rtm; if (ifan->ifan_what == IFAN_DEPARTURE && ifan->ifan_index == ifi->index) { - rslt = asprintf(&errmsg, "%s departured", ifi->name); + errmsg = "interface departure"; goto die; } break; @@ -287,10 +275,7 @@ routehandler(void) return; die: - if (rslt == -1) - error("no memory for errmsg"); error("routehandler: %s", errmsg); - free(errmsg); } char **saved_argv; @@ -642,7 +627,7 @@ state_selecting(void) } void -dhcpack(struct in_addr client_addr, struct option_data *options, char *info) +dhcpack(struct in_addr client_addr, struct option_data *options) { struct client_lease *lease; time_t cur_time; @@ -650,19 +635,15 @@ dhcpack(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) { - note("Unexpected %s. State #%d", info, client->state); + client->state != S_REBINDING) return; - } lease = packet_to_lease(client_addr, options); if (!lease) { - note("Unsatisfactory %s", info); + note("DHCPACK isn't satisfactory."); return; } - note("%s", info); - client->new = lease; /* Stop resending DHCPREQUEST. */ @@ -811,13 +792,19 @@ state_bound(void) } void -dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info) +dhcpoffer(struct in_addr client_addr, struct option_data *options) { 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; - if (client->state != S_SELECTING) { - note("Unexpected %s. State #%d.", info, client->state); + lease = packet_to_lease(client_addr, options); + if (!lease) { + note("%s isn't satisfactory.", name); return; } @@ -826,18 +813,13 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info) if (!memcmp(&lp->address.s_addr, &client->packet.yiaddr, sizeof(in_addr_t))) { #ifdef DEBUG - debug("Duplicate %s.", info); + debug("%s already seen.", name); #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. @@ -871,8 +853,6 @@ dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info) } } - note("%s", info); - /* If the selecting interval has expired, go immediately to state_selecting(). Otherwise, time out into state_selecting at the select interval. */ @@ -984,23 +964,19 @@ packet_to_lease(struct in_addr client_addr, struct option_data *options) } void -dhcpnak(struct in_addr client_addr, struct option_data *options, char *info) +dhcpnak(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) { - note("Unexpected %s. State #%d", info, client->state); + client->state != S_REBINDING) return; - } if (!client->active) { - note("Unexpected %s. No active lease.", info); + note("DHCPNAK with no active lease."); 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 c18717bdf6f..436ea0f5d1a 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.100 2013/01/16 06:11:21 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.101 2013/01/16 11:02:09 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -270,9 +270,9 @@ extern char *path_dhclient_db; extern int log_perror; extern int routefd; -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 dhcpoffer(struct in_addr, struct option_data *); +void dhcpack(struct in_addr, struct option_data *); +void dhcpnak(struct in_addr, struct option_data *); void send_discover(void); void send_request(void); diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index ca0fa0542d4..9447dd3eb78 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.48 2013/01/16 06:11:21 krw Exp $ */ +/* $OpenBSD: options.c,v 1.49 2013/01/16 11:02:10 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 *); - char *type, *info; - int i, rslt, options_valid = 1; + void (*handler)(struct in_addr, struct option_data *); + char *type; + int i, options_valid = 1; if (packet->hlen > sizeof(packet->chaddr)) { note("Discarding packet with invalid hlen."); @@ -531,27 +531,21 @@ do_packet(int len, unsigned int from_port, struct in_addr from, if (handler && client->xid == client->packet.xid) { if (hfrom->hlen == 6) - rslt = asprintf(&info, "%s from %s (%s)", type, - inet_ntoa(from), + note("%s from %s (%s)", type, inet_ntoa(from), ether_ntoa((struct ether_addr *)hfrom->haddr)); else - rslt = asprintf(&info, "%s from %s", type, - inet_ntoa(from)); - if (rslt == -1) - error("no memory for info string"); + note("%s from %s", type, inet_ntoa(from)); } else handler = NULL; for (ap = config->reject_list; ap && handler; ap = ap->next) if (from.s_addr == ap->addr.s_addr) { - note("Rejected %s.", info); + note("%s from %s rejected.", type, inet_ntoa(from)); handler = NULL; } if (handler) - (*handler)(from, options, info); - - free(info); + (*handler)(from, options); for (i = 0; i < 256; i++) if (options[i].len && options[i].data) -- cgit v1.2.3