diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-06-13 15:49:33 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-06-13 15:49:33 +0000 |
commit | 5fe797e771f6b3c3baf01972fa474cd9713065aa (patch) | |
tree | ad7073902f8791afef7709fdcc0f40e08c7ba0b0 /sbin | |
parent | ed1c35fde1fff2d1363f942a2807acbebeb232b9 (diff) |
Rename 'packet' field to 'recv_packet' and 'bootrequest_packet'
field to 'sent_packet'. Also 'bootrequest_packet_length' to
'sent_packet_length'.
Adopt consistent idiom of a local variable 'packet' to point at
packet being manipulated.
No intentional functional change.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/bpf.c | 24 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 57 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 8 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 10 |
4 files changed, 49 insertions, 50 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index bdf44d2e8e4..c298f63de80 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.50 2017/04/19 05:36:12 natano Exp $ */ +/* $OpenBSD: bpf.c,v 1.51 2017/06/13 15:49:32 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -256,16 +256,15 @@ if_register_receive(struct interface_info *ifi) ssize_t send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to) { - struct client_state *client = ifi->client; struct sockaddr_in dest; struct ether_header eh; struct ip ip; struct udphdr udp; struct iovec iov[4]; struct msghdr msg; - unsigned char *data; + struct dhcp_packet *packet = &ifi->client->sent_packet; ssize_t result; - int iovcnt = 0, len; + int iovcnt = 0, len = ifi->client->sent_packet_length; memset(&dest, 0, sizeof(dest)); dest.sin_family = AF_INET; @@ -279,9 +278,6 @@ send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to) iovcnt++; } - data = (unsigned char *)&client->bootrequest_packet; - len = client->bootrequest_packet_length; - ip.ip_v = 4; ip.ip_hl = 5; ip.ip_tos = IPTOS_LOWDELAY; @@ -303,14 +299,15 @@ send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to) udp.uh_ulen = htons(sizeof(udp) + len); udp.uh_sum = 0; udp.uh_sum = wrapsum(checksum((unsigned char *)&udp, sizeof(udp), - checksum(data, len, checksum((unsigned char *)&ip.ip_src, + checksum((unsigned char *)packet, len, + checksum((unsigned char *)&ip.ip_src, 2 * sizeof(ip.ip_src), IPPROTO_UDP + (u_int32_t)ntohs(udp.uh_ulen))))); iov[iovcnt].iov_base = &udp; iov[iovcnt].iov_len = sizeof(udp); iovcnt++; - iov[iovcnt].iov_base = data; + iov[iovcnt].iov_base = packet; iov[iovcnt].iov_len = len; iovcnt++; @@ -334,7 +331,7 @@ ssize_t receive_packet(struct interface_info *ifi, struct sockaddr_in *from, struct ether_addr *hfrom) { - struct client_state *client = ifi->client; + struct dhcp_packet *packet = &ifi->client->recv_packet; int length = 0, offset = 0; struct bpf_hdr hdr; @@ -431,16 +428,15 @@ receive_packet(struct interface_info *ifi, struct sockaddr_in *from, * we have to skip it (this shouldn't happen in real * life, though). */ - if (hdr.bh_caplen > sizeof(client->packet)) { + if (hdr.bh_caplen > sizeof(*packet)) { ifi->rbuf_offset = BPF_WORDALIGN( ifi->rbuf_offset + hdr.bh_caplen); continue; } /* Copy out the data in the packet. */ - memset(&client->packet, DHO_END, sizeof(client->packet)); - memcpy(&client->packet, ifi->rbuf + ifi->rbuf_offset, - hdr.bh_caplen); + memset(packet, DHO_END, sizeof(*packet)); + memcpy(packet, ifi->rbuf + ifi->rbuf_offset, hdr.bh_caplen); ifi->rbuf_offset = BPF_WORDALIGN(ifi->rbuf_offset + hdr.bh_caplen); return (hdr.bh_caplen); diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 8fc32933fd6..37a1eaa1f31 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.418 2017/05/26 14:57:41 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.419 2017/06/13 15:49:32 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -1132,6 +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 client_lease *lease, *lp; time_t stop_selecting; @@ -1146,7 +1147,7 @@ dhcpoffer(struct interface_info *ifi, struct in_addr client_addr, /* If we've already seen this lease, don't record it again. */ TAILQ_FOREACH(lp, &client->offered_leases, next) { - if (!memcmp(&lp->address.s_addr, &client->packet.yiaddr, + if (!memcmp(&lp->address.s_addr, &packet->yiaddr, sizeof(in_addr_t))) { #ifdef DEBUG log_debug("Duplicate %s.", info); @@ -1222,6 +1223,7 @@ 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; char ifname[IF_NAMESIZE]; struct client_lease *lease; char *pretty, *buf; @@ -1300,7 +1302,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, * If this lease is trying to sell us an address we are already * using, blow it off. */ - lease->address.s_addr = client->packet.yiaddr.s_addr; + lease->address.s_addr = packet->yiaddr.s_addr; memset(ifname, 0, sizeof(ifname)); if (addressinuse(ifi, lease->address, ifname) && strncmp(ifname, ifi->name, IF_NAMESIZE) != 0) { @@ -1310,19 +1312,18 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, } /* Save the siaddr (a.k.a. next-server) info. */ - lease->next_server.s_addr = client->packet.siaddr.s_addr; + lease->next_server.s_addr = packet->siaddr.s_addr; /* If the server name was filled out, copy it. */ if ((!lease->options[DHO_DHCP_OPTION_OVERLOAD].len || !(lease->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) && - client->packet.sname[0]) { + packet->sname[0]) { lease->server_name = malloc(DHCP_SNAME_LEN + 1); if (!lease->server_name) { log_warnx("dhcpoffer: no memory for server name."); lease->is_invalid = 1; } - memcpy(lease->server_name, client->packet.sname, - DHCP_SNAME_LEN); + memcpy(lease->server_name, packet->sname, DHCP_SNAME_LEN); lease->server_name[DHCP_SNAME_LEN] = '\0'; if (!res_hnok(lease->server_name)) { log_warnx("Bogus server name %s", lease->server_name); @@ -1333,14 +1334,14 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, /* Ditto for the filename. */ if ((!lease->options[DHO_DHCP_OPTION_OVERLOAD].len || !(lease->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) && - client->packet.file[0]) { + packet->file[0]) { /* Don't count on the NUL terminator. */ lease->filename = malloc(DHCP_FILE_LEN + 1); if (!lease->filename) { log_warnx("dhcpoffer: no memory for filename."); lease->is_invalid = 1; } - memcpy(lease->filename, client->packet.file, DHCP_FILE_LEN); + memcpy(lease->filename, packet->file, DHCP_FILE_LEN); lease->filename[DHCP_FILE_LEN] = '\0'; } return lease; @@ -1396,6 +1397,7 @@ send_discover(void *xifi) { struct interface_info *ifi = xifi; struct client_state *client = ifi->client; + struct dhcp_packet *packet = &client->sent_packet; time_t cur_time; ssize_t rslt; int interval; @@ -1436,10 +1438,10 @@ send_discover(void *xifi) /* Record the number of seconds since we started sending. */ if (interval < UINT16_MAX) - client->bootrequest_packet.secs = htons(interval); + packet->secs = htons(interval); else - client->bootrequest_packet.secs = htons(UINT16_MAX); - client->secs = client->bootrequest_packet.secs; + packet->secs = htons(UINT16_MAX); + client->secs = packet->secs; log_info("DHCPDISCOVER on %s - interval %lld", ifi->name, (long long)client->interval); @@ -1487,6 +1489,7 @@ send_request(void *xifi) { struct interface_info *ifi = xifi; struct client_state *client = ifi->client; + struct dhcp_packet *packet = &client->sent_packet; struct sockaddr_in destination; struct in_addr from; time_t cur_time; @@ -1572,12 +1575,12 @@ send_request(void *xifi) /* Record the number of seconds since we started sending. */ if (client->state == S_REQUESTING) - client->bootrequest_packet.secs = client->secs; + packet->secs = client->secs; else { if (interval < UINT16_MAX) - client->bootrequest_packet.secs = htons(interval); + packet->secs = htons(interval); else - client->bootrequest_packet.secs = htons(UINT16_MAX); + packet->secs = htons(UINT16_MAX); } log_info("DHCPREQUEST on %s to %s", ifi->name, @@ -1603,7 +1606,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->bootrequest_packet; + struct dhcp_packet *packet = &client->sent_packet; unsigned char discover = DHCPDISCOVER; int i; @@ -1641,9 +1644,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->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->bootrequest_packet_length < BOOTP_MIN_LEN) - client->bootrequest_packet_length = BOOTP_MIN_LEN; + 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; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; @@ -1667,7 +1670,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->bootrequest_packet; + struct dhcp_packet *packet = &client->sent_packet; unsigned char request = DHCPREQUEST; int i; @@ -1713,9 +1716,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->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->bootrequest_packet_length < BOOTP_MIN_LEN) - client->bootrequest_packet_length = BOOTP_MIN_LEN; + 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; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; @@ -1749,7 +1752,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->bootrequest_packet; + struct dhcp_packet *packet = &client->sent_packet; unsigned char decline = DHCPDECLINE; int i; @@ -1782,9 +1785,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->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; - if (client->bootrequest_packet_length < BOOTP_MIN_LEN) - client->bootrequest_packet_length = BOOTP_MIN_LEN; + 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; packet->op = BOOTREQUEST; packet->htype = HTYPE_ETHER ; diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 0381f93299d..e4b15503156 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.173 2017/06/10 18:03:50 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.174 2017/06/13 15:49:32 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -135,9 +135,9 @@ struct client_state { time_t first_sending; time_t startup_time; time_t interval; - struct dhcp_packet packet; - struct dhcp_packet bootrequest_packet; - int bootrequest_packet_length; + struct dhcp_packet recv_packet; + struct dhcp_packet sent_packet; + int sent_packet_length; struct in_addr requested_address; }; diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 62c1bcaf6b7..2b761861945 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */ +/* $OpenBSD: options.c,v 1.89 2017/06/13 15:49:32 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -163,7 +163,7 @@ int cons_options(struct interface_info *ifi, struct option_data *options) { struct client_state *client = ifi->client; - unsigned char *buf = client->bootrequest_packet.options; + unsigned char *buf = client->sent_packet.options; int buflen = 576 - DHCP_FIXED_LEN; int ix, incr, length, bufix, code, lastopt = -1; @@ -635,7 +635,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->packet; + struct dhcp_packet *packet = &client->recv_packet; struct option_data options[256]; struct reject_elem *ap; void (*handler)(struct interface_info *, struct in_addr, @@ -659,10 +659,10 @@ do_packet(struct interface_info *ifi, unsigned int from_port, return; } - if (client->xid != client->packet.xid) { + if (client->xid != packet->xid) { #ifdef DEBUG log_debug("Discarding packet with XID != %u (%u)", client->xid, - client->packet.xid); + packet->xid); #endif /* DEBUG */ return; } |