From cb26da2010ef108d929f59dd8378f0f42245ce75 Mon Sep 17 00:00:00 2001 From: krw Date: Fri, 7 Jul 2017 16:58:45 +0000 Subject: [PATCH] Replace the many occurances of '256' with a new #define DHO_COUNT. --- sbin/dhclient/clparse.c | 6 +++--- sbin/dhclient/dhclient.c | 26 +++++++++++++------------- sbin/dhclient/dhcp.h | 3 ++- sbin/dhclient/dhcpd.h | 18 +++++++++--------- sbin/dhclient/options.c | 6 +++--- sbin/dhclient/tables.c | 4 ++-- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index edf6637d0fe..431f0fa9455 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.115 2017/07/05 16:17:41 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.116 2017/07/07 16:58:45 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -220,7 +220,7 @@ read_client_leases(char *name, struct client_lease_tq *tq) void parse_client_statement(FILE *cfile, char *name) { - u_int8_t optlist[256]; + u_int8_t optlist[DHO_COUNT]; char *string; int code, count, token; @@ -638,7 +638,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) /* Look up the actual option info. */ fmt = NULL; - for (code = 0; code < 256; code++) + for (code = 0; code < DHO_COUNT; code++) if (strcmp(dhcp_options[code].name, val) == 0) break; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 940049c6b4e..da3f27c491b 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.458 2017/07/07 15:39:30 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.459 2017/07/07 16:58:45 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -1197,7 +1197,7 @@ packet_to_lease(struct interface_info *ifi, struct option_data *options) } /* Copy the lease options. */ - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { if (options[i].len == 0) continue; if (!unknown_ok && strncmp("option-", @@ -1520,7 +1520,7 @@ send_decline(struct interface_info *ifi) void make_discover(struct interface_info *ifi, struct client_lease *lease) { - struct option_data options[256]; + struct option_data options[DHO_COUNT]; struct dhcp_packet *packet = &ifi->sent_packet; unsigned char discover = DHCPDISCOVER; int i; @@ -1548,7 +1548,7 @@ make_discover(struct interface_info *ifi, struct client_lease *lease) ifi->requested_address.s_addr = INADDR_ANY; /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) + for (i = 0; i < DHO_COUNT; i++) if (!options[i].data && config->send_options[i].data) { options[i].data = config->send_options[i].data; @@ -1588,7 +1588,7 @@ make_discover(struct interface_info *ifi, struct client_lease *lease) void make_request(struct interface_info *ifi, struct client_lease * lease) { - struct option_data options[256]; + struct option_data options[DHO_COUNT]; struct dhcp_packet *packet = &ifi->sent_packet; unsigned char request = DHCPREQUEST; int i; @@ -1625,7 +1625,7 @@ make_request(struct interface_info *ifi, struct client_lease * lease) } /* Send any options requested in the config file. */ - for (i = 0; i < 256; i++) + for (i = 0; i < DHO_COUNT; i++) if (!options[i].data && config->send_options[i].data) { options[i].data = config->send_options[i].data; options[i].len = config->send_options[i].len; @@ -1674,7 +1674,7 @@ make_request(struct interface_info *ifi, struct client_lease * lease) void make_decline(struct interface_info *ifi, struct client_lease *lease) { - struct option_data options[256]; + struct option_data options[DHO_COUNT]; struct dhcp_packet *packet = &ifi->sent_packet; unsigned char decline = DHCPDECLINE; int i; @@ -1747,7 +1747,7 @@ free_client_lease(struct client_lease *lease) free(lease->server_name); free(lease->filename); free(lease->resolv_conf); - for (i = 0; i < 256; i++) + for (i = 0; i < DHO_COUNT; i++) free(lease->options[i].data); free(lease); @@ -1876,7 +1876,7 @@ lease_as_string(char *name, char *type, struct client_lease *lease) append_statement(string, sizeof(string), " ssid ", buf); } - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { opt = &lease->options[i]; if (opt->len == 0) continue; @@ -2182,7 +2182,7 @@ apply_defaults(struct client_lease *lease) if (config->next_server.s_addr != INADDR_ANY) newlease->next_server.s_addr = config->next_server.s_addr; - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { for (j = 0; j < config->ignored_option_count; j++) { if (config->ignored_options[j] == i) { free(newlease->options[i].data); @@ -2324,7 +2324,7 @@ clone_lease(struct client_lease *oldlease) goto cleanup; } - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { if (oldlease->options[i].len == 0) continue; newlease->options[i].len = oldlease->options[i].len; @@ -2355,7 +2355,7 @@ cleanup: void apply_ignore_list(char *ignore_list) { - u_int8_t list[256]; + u_int8_t list[DHO_COUNT]; char *p; int ix, i, j; @@ -2480,7 +2480,7 @@ compare_lease(struct client_lease *active, struct client_lease *new) return (1); } - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { if (active->options[i].len != new->options[i].len) return (1); if (memcmp(active->options[i].data, new->options[i].data, diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h index c0dc07c1e99..29f01fa8c1e 100644 --- a/sbin/dhclient/dhcp.h +++ b/sbin/dhclient/dhcp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcp.h,v 1.18 2015/10/26 16:32:33 krw Exp $ */ +/* $OpenBSD: dhcp.h,v 1.19 2017/07/07 16:58:45 krw Exp $ */ /* Protocol structures. */ @@ -182,6 +182,7 @@ struct dhcp_packet { #define DHO_CLASSLESS_MS_STATIC_ROUTES 249 #define DHO_AUTOPROXY_SCRIPT 252 #define DHO_END 255 +#define DHO_COUNT 256 /* # of DHCP options */ /* DHCP message types. */ #define DHCPDISCOVER 1 diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 86b4f7c37f2..a5d8da4cfc0 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.206 2017/07/07 15:14:47 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.207 2017/07/07 16:58:45 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -70,7 +70,7 @@ struct client_lease { char ssid[32]; uint8_t ssid_len; unsigned int is_static; - struct option_data options[256]; + struct option_data options[DHO_COUNT]; }; #define BOOTP_LEASE(l) ((l)->options[DHO_DHCP_MESSAGE_TYPE].len == 0) @@ -89,20 +89,20 @@ enum dhcp_state { TAILQ_HEAD(client_lease_tq, client_lease); struct client_config { - struct option_data defaults[256]; + struct option_data defaults[DHO_COUNT]; enum { ACTION_DEFAULT, ACTION_SUPERSEDE, ACTION_PREPEND, ACTION_APPEND - } default_actions[256]; + } default_actions[DHO_COUNT]; struct in_addr address; struct in_addr next_server; - struct option_data send_options[256]; - u_int8_t required_options[256]; - u_int8_t requested_options[256]; - u_int8_t ignored_options[256]; + struct option_data send_options[DHO_COUNT]; + u_int8_t required_options[DHO_COUNT]; + u_int8_t requested_options[DHO_COUNT]; + u_int8_t ignored_options[DHO_COUNT]; int requested_option_count; int required_option_count; int ignored_option_count; @@ -214,7 +214,7 @@ void get_hw_address(struct interface_info *); void sendhup(void); /* tables.c */ -extern const struct option dhcp_options[256]; +extern const struct option dhcp_options[DHO_COUNT]; /* dhclient.c */ extern char *path_dhclient_conf; diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index aa07efcee41..56d8bc94c9d 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.94 2017/07/07 14:53:07 krw Exp $ */ +/* $OpenBSD: options.c,v 1.95 2017/07/07 16:58:45 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -630,10 +630,10 @@ toobig: struct option_data * unpack_options(struct dhcp_packet *packet) { - static struct option_data options[256]; + static struct option_data options[DHO_COUNT]; int i; - for (i = 0; i < 256; i++) { + for (i = 0; i < DHO_COUNT; i++) { free(options[i].data); options[i].data = NULL; options[i].len = 0; diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c index 1d82123c2d4..47cb740ddb0 100644 --- a/sbin/dhclient/tables.c +++ b/sbin/dhclient/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.20 2016/02/06 19:30:52 krw Exp $ */ +/* $OpenBSD: tables.c,v 1.21 2017/07/07 16:58:45 krw Exp $ */ /* Tables of information. */ @@ -71,7 +71,7 @@ * C - CIDR description */ -const struct option dhcp_options[256] = { +const struct option dhcp_options[DHO_COUNT] = { /* 0 */ { "pad", "" }, /* 1 */ { "subnet-mask", "I" }, /* 2 */ { "time-offset", "l" }, -- 2.20.1