-/* $OpenBSD: dhclient.c,v 1.546 2018/01/28 11:29:30 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.547 2018/01/28 23:12:36 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
void send_request(struct interface_info *);
void send_decline(struct interface_info *);
+void process_offer(struct interface_info *, struct option_data *);
void bind_lease(struct interface_info *);
void make_discover(struct interface_info *, struct client_lease *);
}
void
-dhcpoffer(struct interface_info *ifi, struct option_data *options, char *info)
+dhcpoffer(struct interface_info *ifi, struct option_data *options,
+ const char *src)
{
- struct client_lease *lease;
- time_t cur_time, stop_selecting;
+ if (ifi->state != S_SELECTING) {
+ DPRINTF("%s: unexpected DHCPOFFER from %s - state #%d",
+ log_procname, src, ifi->state);
+ return;
+ }
+
+ log_info("%s: DHCPOFFER from %s", log_procname, src);
+ process_offer(ifi, options);
+}
+void
+bootreply(struct interface_info *ifi, struct option_data *options,
+ const char *src)
+{
if (ifi->state != S_SELECTING) {
- DPRINTF("%s: unexpected %s - state #%d", log_procname, info,
- ifi->state);
+ DPRINTF("%s: unexpected BOOTREPLY from %s - state #%d",
+ log_procname, src, ifi->state);
return;
}
+ log_info("%s: BOOTREPLY from %s", log_procname, src);
+ process_offer(ifi, options);
+}
+
+void
+process_offer(struct interface_info *ifi, struct option_data *options)
+{
+ struct client_lease *lease;
+ time_t cur_time, stop_selecting;
+
time(&cur_time);
- log_info("%s: %s", log_procname, info);
lease = packet_to_lease(ifi, options);
if (lease != NULL) {
}
void
-dhcpack(struct interface_info *ifi, struct option_data *options, char *info)
+dhcpack(struct interface_info *ifi, struct option_data *options,
+ const char *src)
{
struct client_lease *lease;
ifi->state != S_REQUESTING &&
ifi->state != S_RENEWING &&
ifi->state != S_REBINDING) {
- DPRINTF("%s: unexpected %s - state #%d", log_procname, info,
- ifi->state);
+ DPRINTF("%s: unexpected DHCPACK from %s - state #%d",
+ log_procname, src, ifi->state);
return;
}
- log_info("%s: %s", log_procname, info);
+ log_info("%s: DHCPACK from %s", log_procname, src);
lease = packet_to_lease(ifi, options);
if (lease == NULL) {
}
void
-dhcpnak(struct interface_info *ifi, struct option_data *options, char *info)
+dhcpnak(struct interface_info *ifi, const char *src)
{
if (ifi->state != S_REBOOTING &&
ifi->state != S_REQUESTING &&
ifi->state != S_RENEWING &&
ifi->state != S_REBINDING) {
- DPRINTF("%s: unexpected %s - state #%d", log_procname, info,
- ifi->state);
+ DPRINTF("%s: unexpected DHCPNAK from %s - state #%d",
+ log_procname, src, ifi->state);
return;
}
if (ifi->active == NULL) {
- DPRINTF("%s: unexpected %s - no active lease", log_procname,
- info);
+ DPRINTF("%s: unexpected DHCPNAK from %s - no active lease",
+ log_procname, src);
return;
}
- log_info("%s: %s", log_procname, info);
+ log_info("%s: DHCPNAK from %s", log_procname, src);
delete_address(ifi->active->address);
/* XXX Do we really want to remove a NAK'd lease from the database? */
-/* $OpenBSD: dhcpd.h,v 1.246 2018/01/25 15:43:51 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.247 2018/01/28 23:12:36 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
#define OPT_FOREGROUND 4
void dhcpoffer(struct interface_info *, struct option_data *,
- char *);
-void dhcpack(struct interface_info *, struct option_data *,char *);
-void dhcpnak(struct interface_info *, struct option_data *,char *);
+ const char *);
+void dhcpack(struct interface_info *, struct option_data *,
+ const char *);
+void dhcpnak(struct interface_info *, const char *);
+void bootreply(struct interface_info *, struct option_data *,
+ const char *);
void free_client_lease(struct client_lease *);
void routehandler(struct interface_info *, int);
-/* $OpenBSD: dispatch.c,v 1.148 2018/01/25 15:43:51 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.149 2018/01/28 23:12:36 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
struct dhcp_packet *packet = &ifi->recv_packet;
struct reject_elem *ap;
struct option_data *options;
- char *type, *info;
+ char *src;
ssize_t result;
- void (*handler)(struct interface_info *,
- struct option_data *, char *);
int i, rslt;
result = receive_packet(ifi, &from, &hfrom);
return;
}
- type = "<unknown>";
- handler = NULL;
+ rslt = asprintf(&src, "%s (%s)",inet_ntoa(ifrom), ether_ntoa(&hfrom));
+ if (rslt == -1)
+ fatal("src");
i = DHO_DHCP_MESSAGE_TYPE;
if (options[i].data != NULL) {
/* Always try a DHCP packet, even if a bad option was seen. */
switch (options[i].data[0]) {
case DHCPOFFER:
- handler = dhcpoffer;
- type = "DHCPOFFER";
+ dhcpoffer(ifi, options, src);
break;
case DHCPNAK:
- handler = dhcpnak;
- type = "DHCPNACK";
+ dhcpnak(ifi, src);
break;
case DHCPACK:
- handler = dhcpack;
- type = "DHCPACK";
+ dhcpack(ifi, options, src);
break;
default:
DPRINTF("%s: discarding DHCP packet of unknown type "
"(%d)", log_procname, options[i].data[0]);
- return;
+ break;
}
} else if (packet->op == BOOTREPLY) {
- handler = dhcpoffer;
- type = "BOOTREPLY";
+ bootreply(ifi, options, src);
} else {
DPRINTF("%s: discarding packet which is neither DHCP nor "
"BOOTP", log_procname);
- return;
}
- rslt = asprintf(&info, "%s from %s (%s)", type, inet_ntoa(ifrom),
- ether_ntoa(&hfrom));
- if (rslt == -1)
- fatal("info string");
-
- if (handler != NULL)
- (*handler)(ifi, options, info);
-
- free(info);
+ free(src);
}
/*