From eea1c0a9968a2da37343f868f6c261daecd78f7a Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 14 Jun 2017 15:57:25 +0000 Subject: [PATCH] Start consolidating client_state into interface_info. First fields to move: recv_packet, sent_packet and sent_packet_length. No intentional functional change. --- sbin/dhclient/bpf.c | 8 ++++---- sbin/dhclient/dhclient.c | 35 +++++++++++++++++------------------ sbin/dhclient/dhcpd.h | 8 ++++---- sbin/dhclient/options.c | 7 +++---- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index c298f63de80..ffb7f1d5606 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.51 2017/06/13 15:49:32 krw Exp $ */ +/* $OpenBSD: bpf.c,v 1.52 2017/06/14 15:57:25 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -262,9 +262,9 @@ send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to) struct udphdr udp; struct iovec iov[4]; struct msghdr msg; - struct dhcp_packet *packet = &ifi->client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; ssize_t result; - int iovcnt = 0, len = ifi->client->sent_packet_length; + int iovcnt = 0, len = ifi->sent_packet_length; memset(&dest, 0, sizeof(dest)); dest.sin_family = AF_INET; @@ -331,7 +331,7 @@ ssize_t receive_packet(struct interface_info *ifi, struct sockaddr_in *from, struct ether_addr *hfrom) { - struct dhcp_packet *packet = &ifi->client->recv_packet; + struct dhcp_packet *packet = &ifi->recv_packet; int length = 0, offset = 0; struct bpf_hdr hdr; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 76e906b9f6d..15b0253edaf 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.420 2017/06/14 15:39:55 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.421 2017/06/14 15:57:25 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -1132,7 +1132,7 @@ dhcpoffer(struct interface_info *ifi, struct in_addr client_addr, struct option_data *options, char *info) { struct client_state *client = ifi->client; - struct dhcp_packet *packet = &client->recv_packet; + struct dhcp_packet *packet = &ifi->recv_packet; struct client_lease *lease, *lp; time_t stop_selecting; @@ -1222,8 +1222,7 @@ struct client_lease * packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, struct option_data *options) { - struct client_state *client = ifi->client; - struct dhcp_packet *packet = &client->recv_packet; + struct dhcp_packet *packet = &ifi->recv_packet; char ifname[IF_NAMESIZE]; struct client_lease *lease; char *pretty, *buf; @@ -1397,7 +1396,7 @@ send_discover(void *xifi) { struct interface_info *ifi = xifi; struct client_state *client = ifi->client; - struct dhcp_packet *packet = &client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; time_t cur_time; ssize_t rslt; int interval; @@ -1489,7 +1488,7 @@ send_request(void *xifi) { struct interface_info *ifi = xifi; struct client_state *client = ifi->client; - struct dhcp_packet *packet = &client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; struct sockaddr_in destination; struct in_addr from; time_t cur_time; @@ -1606,7 +1605,7 @@ make_discover(struct interface_info *ifi, struct client_lease *lease) { struct client_state *client = ifi->client; struct option_data options[256]; - struct dhcp_packet *packet = &client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; unsigned char discover = DHCPDISCOVER; int i; @@ -1644,9 +1643,9 @@ make_discover(struct interface_info *ifi, struct client_lease *lease) i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) fatalx("options do not fit in DHCPDISCOVER packet."); - client->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->sent_packet_length < BOOTP_MIN_LEN) - client->sent_packet_length = BOOTP_MIN_LEN; + ifi->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; + if (ifi->sent_packet_length < BOOTP_MIN_LEN) + ifi->sent_packet_length = BOOTP_MIN_LEN; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; @@ -1670,7 +1669,7 @@ make_request(struct interface_info *ifi, struct client_lease * lease) { struct client_state *client = ifi->client; struct option_data options[256]; - struct dhcp_packet *packet = &client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; unsigned char request = DHCPREQUEST; int i; @@ -1716,9 +1715,9 @@ make_request(struct interface_info *ifi, struct client_lease * lease) i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) fatalx("options do not fit in DHCPREQUEST packet."); - client->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->sent_packet_length < BOOTP_MIN_LEN) - client->sent_packet_length = BOOTP_MIN_LEN; + ifi->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; + if (ifi->sent_packet_length < BOOTP_MIN_LEN) + ifi->sent_packet_length = BOOTP_MIN_LEN; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; @@ -1752,7 +1751,7 @@ make_decline(struct interface_info *ifi, struct client_lease *lease) { struct client_state *client = ifi->client; struct option_data options[256]; - struct dhcp_packet *packet = &client->sent_packet; + struct dhcp_packet *packet = &ifi->sent_packet; unsigned char decline = DHCPDECLINE; int i; @@ -1785,9 +1784,9 @@ make_decline(struct interface_info *ifi, struct client_lease *lease) i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) fatalx("options do not fit in DHCPDECLINE packet."); - client->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->sent_packet_length < BOOTP_MIN_LEN) - client->sent_packet_length = BOOTP_MIN_LEN; + ifi->sent_packet_length = DHCP_FIXED_NON_UDP+i+1; + if (ifi->sent_packet_length < BOOTP_MIN_LEN) + ifi->sent_packet_length = BOOTP_MIN_LEN; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index b752a646a21..9e292a689a6 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.176 2017/06/14 15:39:55 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.177 2017/06/14 15:57:25 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -132,9 +132,6 @@ struct client_state { time_t first_sending; time_t startup_time; time_t interval; - struct dhcp_packet recv_packet; - struct dhcp_packet sent_packet; - int sent_packet_length; struct in_addr requested_address; }; @@ -160,6 +157,9 @@ struct interface_info { #define IFI_HUP 0x04 #define IFI_IS_RESPONSIBLE 0x08 #define IFI_IN_CHARGE 0x10 + struct dhcp_packet recv_packet; + struct dhcp_packet sent_packet; + int sent_packet_length; }; struct dhcp_timeout { diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 2b761861945..b85f9c3bd4d 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.89 2017/06/13 15:49:32 krw Exp $ */ +/* $OpenBSD: options.c,v 1.90 2017/06/14 15:57:25 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -162,8 +162,7 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer, int cons_options(struct interface_info *ifi, struct option_data *options) { - struct client_state *client = ifi->client; - unsigned char *buf = client->sent_packet.options; + unsigned char *buf = ifi->sent_packet.options; int buflen = 576 - DHCP_FIXED_LEN; int ix, incr, length, bufix, code, lastopt = -1; @@ -635,7 +634,7 @@ do_packet(struct interface_info *ifi, unsigned int from_port, struct in_addr from, struct ether_addr *hfrom) { struct client_state *client = ifi->client; - struct dhcp_packet *packet = &client->recv_packet; + struct dhcp_packet *packet = &ifi->recv_packet; struct option_data options[256]; struct reject_elem *ap; void (*handler)(struct interface_info *, struct in_addr, -- 2.20.1