summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/dhcpd/bootp.c29
-rw-r--r--usr.sbin/dhcpd/confpars.c188
-rw-r--r--usr.sbin/dhcpd/db.c10
-rw-r--r--usr.sbin/dhcpd/dhcp.c1036
-rw-r--r--usr.sbin/dhcpd/dhcpd.c15
-rw-r--r--usr.sbin/dhcpd/dhcpd.h34
-rw-r--r--usr.sbin/dhcpd/dispatch.c19
-rw-r--r--usr.sbin/dhcpd/icmp.c20
-rw-r--r--usr.sbin/dhcpd/memory.c2
-rw-r--r--usr.sbin/dhcpd/parse.c73
-rw-r--r--usr.sbin/dhcpd/print.c18
-rw-r--r--usr.sbin/dhcpd/tables.c3
-rw-r--r--usr.sbin/dhcpd/tree.c19
13 files changed, 673 insertions, 793 deletions
diff --git a/usr.sbin/dhcpd/bootp.c b/usr.sbin/dhcpd/bootp.c
index 7b026a9aa5a..4fdbb62212c 100644
--- a/usr.sbin/dhcpd/bootp.c
+++ b/usr.sbin/dhcpd/bootp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bootp.c,v 1.3 2004/04/15 21:57:04 henning Exp $ */
+/* $OpenBSD: bootp.c,v 1.4 2004/04/18 00:43:27 deraadt Exp $ */
/*
* BOOTP Protocol support.
@@ -47,19 +47,17 @@
void
bootp(struct packet *packet)
{
- int result;
- struct host_decl *hp;
- struct host_decl *host = (struct host_decl *)0;
+ struct host_decl *hp, *host = NULL;
struct packet outgoing;
struct dhcp_packet raw;
struct sockaddr_in to;
struct in_addr from;
struct hardware hto;
- struct tree_cache *options [256];
- struct subnet *subnet;
+ struct tree_cache *options[256];
+ struct subnet *subnet = NULL;
struct lease *lease;
struct iaddr ip_address;
- int i;
+ int result, i;
if (packet->raw->op != BOOTREQUEST)
return;
@@ -85,8 +83,6 @@ bootp(struct packet *packet)
if (hp)
subnet = find_host_for_network(&hp, &ip_address,
packet->shared_network);
- else
- subnet = (struct subnet *)0;
if (!subnet) {
/*
@@ -197,8 +193,8 @@ lose:
* available, try to snag one.
*/
for (lease = packet->shared_network->last_lease;
- lease && lease->ends <= cur_time;
- lease = lease->prev) {
+ lease && lease->ends <= cur_time;
+ lease = lease->prev) {
if ((lease->flags & DYNAMIC_BOOTP_OK)) {
lease->host = host;
ack_lease(packet, lease, 0, 0);
@@ -260,7 +256,7 @@ lose:
netmask_tree.len = lease->subnet->netmask.len;
netmask_tree.buf_size = lease->subnet->netmask.len;
netmask_tree.timeout = 0xFFFFFFFF;
- netmask_tree.tree = (struct tree *)0;
+ netmask_tree.tree = NULL;
}
/*
@@ -269,7 +265,7 @@ lose:
*/
outgoing.packet_length = cons_options(packet, outgoing.raw,
- 0, options, 0, 0, 1, (u_int8_t *)0, 0);
+ 0, options, 0, 0, 1, NULL, 0);
if (outgoing.packet_length < BOOTP_MIN_LEN)
outgoing.packet_length = BOOTP_MIN_LEN;
@@ -337,9 +333,8 @@ lose:
to.sin_port = local_port;
if (fallback_interface) {
- result = send_packet(fallback_interface,
- (struct packet *)0, &raw, outgoing.packet_length,
- from, &to, &hto);
+ result = send_packet(fallback_interface, NULL, &raw,
+ outgoing.packet_length, from, &to, &hto);
return;
}
@@ -353,8 +348,8 @@ lose:
else if (!(raw.flags & htons(BOOTP_BROADCAST))) {
to.sin_addr = raw.yiaddr;
to.sin_port = remote_port;
- /* Otherwise, broadcast it on the local network. */
} else {
+ /* Otherwise, broadcast it on the local network. */
to.sin_addr.s_addr = INADDR_BROADCAST;
to.sin_port = remote_port; /* XXX */
}
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index 9bb1a28872c..0e1b5a02452 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -227,9 +227,9 @@ int parse_statement (cfile, group, type, host_decl, declaration)
}
/* If we're in a subnet declaration, just do the parse. */
- if (group -> shared_network) {
+ if (group->shared_network) {
parse_subnet_declaration (cfile,
- group -> shared_network);
+ group->shared_network);
break;
}
@@ -239,28 +239,28 @@ int parse_statement (cfile, group, type, host_decl, declaration)
share = new_shared_network ("parse_statement");
if (!share)
error ("No memory for shared subnet");
- share -> group = clone_group (group, "parse_statement:subnet");
- share -> group -> shared_network = share;
+ share->group = clone_group (group, "parse_statement:subnet");
+ share->group->shared_network = share;
parse_subnet_declaration (cfile, share);
- /* share -> subnets is the subnet we just parsed. */
- if (share -> subnets) {
- share -> interface =
- share -> subnets -> interface;
+ /* share->subnets is the subnet we just parsed. */
+ if (share->subnets) {
+ share->interface =
+ share->subnets->interface;
/* Make the shared network name from network number. */
- n = piaddr (share -> subnets -> net);
+ n = piaddr (share->subnets->net);
t = malloc (strlen (n) + 1);
if (!t)
error ("no memory for subnet name");
strlcpy (t, n, (strlen(n) + 1));
- share -> name = t;
+ share->name = t;
/* Copy the authoritative parameter from the subnet,
since there is no opportunity to declare it here. */
- share -> group -> authoritative =
- share -> subnets -> group -> authoritative;
+ share->group->authoritative =
+ share->subnets->group->authoritative;
enter_shared_network (share);
}
return 1;
@@ -274,51 +274,51 @@ int parse_statement (cfile, group, type, host_decl, declaration)
return 1;
case DEFAULT_LEASE_TIME:
- parse_lease_time (cfile, &group -> default_lease_time);
+ parse_lease_time (cfile, &group->default_lease_time);
break;
case MAX_LEASE_TIME:
- parse_lease_time (cfile, &group -> max_lease_time);
+ parse_lease_time (cfile, &group->max_lease_time);
break;
case DYNAMIC_BOOTP_LEASE_CUTOFF:
- group -> bootp_lease_cutoff = parse_date (cfile);
+ group->bootp_lease_cutoff = parse_date (cfile);
break;
case DYNAMIC_BOOTP_LEASE_LENGTH:
- parse_lease_time (cfile, &group -> bootp_lease_length);
+ parse_lease_time (cfile, &group->bootp_lease_length);
break;
case BOOT_UNKNOWN_CLIENTS:
if (type == HOST_DECL)
parse_warn ("boot-unknown-clients not allowed here.");
- group -> boot_unknown_clients = parse_boolean (cfile);
+ group->boot_unknown_clients = parse_boolean (cfile);
break;
case ONE_LEASE_PER_CLIENT:
if (type == HOST_DECL)
parse_warn ("one-lease-per-client not allowed here.");
- group -> one_lease_per_client = parse_boolean (cfile);
+ group->one_lease_per_client = parse_boolean (cfile);
break;
case GET_LEASE_HOSTNAMES:
if (type == HOST_DECL)
parse_warn ("get-lease-hostnames not allowed here.");
- group -> get_lease_hostnames = parse_boolean (cfile);
+ group->get_lease_hostnames = parse_boolean (cfile);
break;
case ALWAYS_REPLY_RFC1048:
- group -> always_reply_rfc1048 = parse_boolean (cfile);
+ group->always_reply_rfc1048 = parse_boolean (cfile);
break;
case USE_HOST_DECL_NAMES:
if (type == HOST_DECL)
parse_warn ("use-host-decl-names not allowed here.");
- group -> use_host_decl_names = parse_boolean (cfile);
+ group->use_host_decl_names = parse_boolean (cfile);
break;
case USE_LEASE_ADDR_FOR_DEFAULT_ROUTE:
- group -> use_lease_addr_for_default_route =
+ group->use_lease_addr_for_default_route =
parse_boolean (cfile);
break;
@@ -328,7 +328,7 @@ int parse_statement (cfile, group, type, host_decl, declaration)
case AUTHORITATIVE:
if (type == HOST_DECL)
parse_warn ("authority makes no sense here.");
- group -> authoritative = 0;
+ group->authoritative = 0;
parse_semi (cfile);
break;
default:
@@ -341,7 +341,7 @@ int parse_statement (cfile, group, type, host_decl, declaration)
case AUTHORITATIVE:
if (type == HOST_DECL)
parse_warn ("authority makes no sense here.");
- group -> authoritative = 1;
+ group->authoritative = 1;
parse_semi (cfile);
break;
@@ -352,9 +352,9 @@ int parse_statement (cfile, group, type, host_decl, declaration)
cache = tree_cache (tree);
if (!tree_evaluate (cache))
error ("next-server is not known");
- group -> next_server.len = 4;
- memcpy (group -> next_server.iabuf,
- cache -> value, group -> next_server.len);
+ group->next_server.len = 4;
+ memcpy (group->next_server.iabuf,
+ cache->value, group->next_server.len);
parse_semi (cfile);
break;
@@ -366,23 +366,23 @@ int parse_statement (cfile, group, type, host_decl, declaration)
tree = parse_ip_addr_or_hostname (cfile, 0);
if (!tree)
return declaration;
- group -> options [DHO_DHCP_SERVER_IDENTIFIER] =
+ group->options[DHO_DHCP_SERVER_IDENTIFIER] =
tree_cache (tree);
token = next_token (&val, cfile);
break;
case FILENAME:
- group -> filename = parse_string (cfile);
+ group->filename = parse_string (cfile);
break;
case SERVER_NAME:
- group -> server_name = parse_string (cfile);
+ group->server_name = parse_string (cfile);
break;
case HARDWARE:
parse_hardware_param (cfile, &hardware);
if (host_decl)
- host_decl -> interface = hardware;
+ host_decl->interface = hardware;
else
parse_warn ("hardware address parameter %s",
"not allowed here.");
@@ -391,19 +391,19 @@ int parse_statement (cfile, group, type, host_decl, declaration)
case FIXED_ADDR:
cache = parse_fixed_addr_param (cfile);
if (host_decl)
- host_decl -> fixed_addr = cache;
+ host_decl->fixed_addr = cache;
else
parse_warn ("fixed-address parameter not %s",
"allowed here.");
break;
case RANGE:
- if (type != SUBNET_DECL || !group -> subnet) {
+ if (type != SUBNET_DECL || !group->subnet) {
parse_warn ("range declaration not allowed here.");
skip_to_semi (cfile);
return declaration;
}
- parse_address_range (cfile, group -> subnet);
+ parse_address_range (cfile, group->subnet);
return declaration;
case ALLOW:
@@ -447,19 +447,19 @@ void parse_allow_deny (cfile, group, flag)
token = next_token (&val, cfile);
switch (token) {
case BOOTP:
- group -> allow_bootp = flag;
+ group->allow_bootp = flag;
break;
case BOOTING:
- group -> allow_booting = flag;
+ group->allow_booting = flag;
break;
case DYNAMIC_BOOTP:
- group -> dynamic_bootp = flag;
+ group->dynamic_bootp = flag;
break;
case UNKNOWN_CLIENTS:
- group -> boot_unknown_clients = flag;
+ group->boot_unknown_clients = flag;
break;
default:
@@ -534,8 +534,8 @@ void parse_host_declaration (cfile, group)
if (!host)
error ("can't allocate host decl struct %s.", name);
- host -> name = name;
- host -> group = clone_group (group, "parse_host_declaration");
+ host->name = name;
+ host->group = clone_group (group, "parse_host_declaration");
if (!parse_lbrace (cfile))
return;
@@ -551,26 +551,26 @@ void parse_host_declaration (cfile, group)
parse_warn ("unexpected end of file");
break;
}
- declaration = parse_statement (cfile, host -> group,
+ declaration = parse_statement (cfile, host->group,
HOST_DECL, host,
declaration);
} while (1);
- if (!host -> group -> options [DHO_HOST_NAME] &&
- host -> group -> use_host_decl_names) {
- host -> group -> options [DHO_HOST_NAME] =
+ if (!host->group->options[DHO_HOST_NAME] &&
+ host->group->use_host_decl_names) {
+ host->group->options[DHO_HOST_NAME] =
new_tree_cache ("parse_host_declaration");
- if (!host -> group -> options [DHO_HOST_NAME])
+ if (!host->group->options[DHO_HOST_NAME])
error ("can't allocate a tree cache for hostname.");
- host -> group -> options [DHO_HOST_NAME] -> len =
+ host->group->options[DHO_HOST_NAME]->len =
strlen (name);
- host -> group -> options [DHO_HOST_NAME] -> value =
+ host->group->options[DHO_HOST_NAME]->value =
(unsigned char *)name;
- host -> group -> options [DHO_HOST_NAME] -> buf_size =
- host -> group -> options [DHO_HOST_NAME] -> len;
- host -> group -> options [DHO_HOST_NAME] -> timeout =
+ host->group->options[DHO_HOST_NAME]->buf_size =
+ host->group->options[DHO_HOST_NAME]->len;
+ host->group->options[DHO_HOST_NAME]->timeout =
0xFFFFFFFF;
- host -> group -> options [DHO_HOST_NAME] -> tree =
+ host->group->options[DHO_HOST_NAME]->tree =
(struct tree *)0;
}
@@ -600,7 +600,7 @@ void parse_class_declaration (cfile, group, type)
class = add_class (type, val);
if (!class)
error ("No memory for class %s.", val);
- class -> group = clone_group (group, "parse_class_declaration");
+ class->group = clone_group (group, "parse_class_declaration");
if (!parse_lbrace (cfile))
return;
@@ -615,7 +615,7 @@ void parse_class_declaration (cfile, group, type)
parse_warn ("unexpected end of file");
break;
} else {
- declaration = parse_statement (cfile, class -> group,
+ declaration = parse_statement (cfile, class->group,
CLASS_DECL,
(struct host_decl *)0,
declaration);
@@ -639,20 +639,20 @@ void parse_shared_net_declaration (cfile, group)
share = new_shared_network ("parse_shared_net_declaration");
if (!share)
error ("No memory for shared subnet");
- share -> leases = (struct lease *)0;
- share -> last_lease = (struct lease *)0;
- share -> insertion_point = (struct lease *)0;
- share -> next = (struct shared_network *)0;
- share -> interface = (struct interface_info *)0;
- share -> group = clone_group (group, "parse_shared_net_declaration");
- share -> group -> shared_network = share;
+ share->leases = (struct lease *)0;
+ share->last_lease = (struct lease *)0;
+ share->insertion_point = (struct lease *)0;
+ share->next = (struct shared_network *)0;
+ share->interface = (struct interface_info *)0;
+ share->group = clone_group (group, "parse_shared_net_declaration");
+ share->group->shared_network = share;
/* Get the name of the shared network... */
token = peek_token (&val, cfile);
if (token == STRING) {
token = next_token (&val, cfile);
- if (val [0] == 0) {
+ if (val[0] == 0) {
parse_warn ("zero-length shared network name");
val = "<no-name-given>";
}
@@ -665,7 +665,7 @@ void parse_shared_net_declaration (cfile, group)
if (!name)
return;
}
- share -> name = name;
+ share->name = name;
if (!parse_lbrace (cfile))
return;
@@ -674,7 +674,7 @@ void parse_shared_net_declaration (cfile, group)
token = peek_token (&val, cfile);
if (token == RBRACE) {
token = next_token (&val, cfile);
- if (!share -> subnets) {
+ if (!share->subnets) {
parse_warn ("empty shared-network decl");
return;
}
@@ -686,7 +686,7 @@ void parse_shared_net_declaration (cfile, group)
break;
}
- declaration = parse_statement (cfile, share -> group,
+ declaration = parse_statement (cfile, share->group,
SHARED_NET_DECL,
(struct host_decl *)0,
declaration);
@@ -704,24 +704,24 @@ void parse_subnet_declaration (cfile, share)
int token;
struct subnet *subnet, *t, *u;
struct iaddr iaddr;
- unsigned char addr [4];
+ unsigned char addr[4];
int len = sizeof addr;
int declaration = 0;
subnet = new_subnet ("parse_subnet_declaration");
if (!subnet)
error ("No memory for new subnet");
- subnet -> shared_network = share;
- subnet -> group = clone_group (share -> group,
+ subnet->shared_network = share;
+ subnet->group = clone_group (share->group,
"parse_subnet_declaration");
- subnet -> group -> subnet = subnet;
+ subnet->group->subnet = subnet;
/* Get the network number... */
if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
return;
memcpy (iaddr.iabuf, addr, len);
iaddr.len = len;
- subnet -> net = iaddr;
+ subnet->net = iaddr;
token = next_token (&val, cfile);
if (token != NETMASK) {
@@ -735,7 +735,7 @@ void parse_subnet_declaration (cfile, share)
return;
memcpy (iaddr.iabuf, addr, len);
iaddr.len = len;
- subnet -> netmask = iaddr;
+ subnet->netmask = iaddr;
enter_subnet (subnet);
@@ -752,7 +752,7 @@ void parse_subnet_declaration (cfile, share)
parse_warn ("unexpected end of file");
break;
}
- declaration = parse_statement (cfile, subnet -> group,
+ declaration = parse_statement (cfile, subnet->group,
SUBNET_DECL,
(struct host_decl *)0,
declaration);
@@ -760,28 +760,28 @@ void parse_subnet_declaration (cfile, share)
/* If this subnet supports dynamic bootp, flag it so in the
shared_network containing it. */
- if (subnet -> group -> dynamic_bootp)
- share -> group -> dynamic_bootp = 1;
- if (subnet -> group -> one_lease_per_client)
- share -> group -> one_lease_per_client = 1;
+ if (subnet->group->dynamic_bootp)
+ share->group->dynamic_bootp = 1;
+ if (subnet->group->one_lease_per_client)
+ share->group->one_lease_per_client = 1;
/* Add the subnet to the list of subnets in this shared net. */
- if (!share -> subnets)
- share -> subnets = subnet;
+ if (!share->subnets)
+ share->subnets = subnet;
else {
u = (struct subnet *)0;
- for (t = share -> subnets; t; t = t -> next_sibling) {
+ for (t = share->subnets; t; t = t->next_sibling) {
if (subnet_inner_than (subnet, t, 0)) {
if (u)
- u -> next_sibling = subnet;
+ u->next_sibling = subnet;
else
- share -> subnets = subnet;
- subnet -> next_sibling = t;
+ share->subnets = subnet;
+ subnet->next_sibling = t;
return;
}
u = t;
}
- u -> next_sibling = subnet;
+ u->next_sibling = subnet;
}
}
@@ -830,7 +830,7 @@ struct tree *parse_ip_addr_or_hostname (cfile, uniform)
{
char *val;
int token;
- unsigned char addr [4];
+ unsigned char addr[4];
int len = sizeof addr;
char *name;
struct tree *rv;
@@ -902,7 +902,7 @@ void parse_option_param (cfile, group)
{
char *val;
int token;
- unsigned char buf [4];
+ unsigned char buf[4];
char *vendor;
char *fmt;
struct universe *universe;
@@ -955,7 +955,7 @@ void parse_option_param (cfile, group)
}
/* Look up the actual option info... */
- option = (struct option *)hash_lookup (universe -> hash,
+ option = (struct option *)hash_lookup (universe->hash,
(unsigned char *)val, 0);
/* If we didn't get an option structure, it's an undefined option. */
@@ -977,9 +977,9 @@ void parse_option_param (cfile, group)
/* Set a flag if this is an array of a simple type (i.e.,
not an array of pairs of IP addresses, or something
like that. */
- int uniform = option -> format [1] == 'A';
+ int uniform = option->format[1] == 'A';
- for (fmt = option -> format; *fmt; fmt++) {
+ for (fmt = option->format; *fmt; fmt++) {
if (*fmt == 'A')
break;
switch (*fmt) {
@@ -1080,10 +1080,10 @@ void parse_option_param (cfile, group)
}
if (!strcasecmp (val, "true")
|| !strcasecmp (val, "on"))
- buf [0] = 1;
+ buf[0] = 1;
else if (!strcasecmp (val, "false")
|| !strcasecmp (val, "off"))
- buf [0] = 0;
+ buf[0] = 0;
else {
parse_warn ("expecting boolean.");
goto bad_flag;
@@ -1113,7 +1113,7 @@ void parse_option_param (cfile, group)
skip_to_semi (cfile);
return;
}
- group -> options [option -> code] = tree_cache (tree);
+ group->options[option->code] = tree_cache (tree);
}
/* timestamp :== date
@@ -1152,11 +1152,11 @@ struct lease *parse_lease_declaration (cfile)
{
char *val;
int token;
- unsigned char addr [4];
+ unsigned char addr[4];
int len = sizeof addr;
int seenmask = 0;
int seenbit;
- char tbuf [32];
+ char tbuf[32];
static struct lease lease;
/* Zap the lease structure... */
@@ -1329,7 +1329,7 @@ void parse_address_range (cfile, subnet)
struct subnet *subnet;
{
struct iaddr low, high;
- unsigned char addr [4];
+ unsigned char addr[4];
int len = sizeof addr;
int token;
char *val;
@@ -1337,7 +1337,7 @@ void parse_address_range (cfile, subnet)
if ((token = peek_token (&val, cfile)) == DYNAMIC_BOOTP) {
token = next_token (&val, cfile);
- subnet -> group -> dynamic_bootp = dynamic = 1;
+ subnet->group->dynamic_bootp = dynamic = 1;
}
/* Get the bottom address in the range... */
diff --git a/usr.sbin/dhcpd/db.c b/usr.sbin/dhcpd/db.c
index 6a59abe89ad..459cd0fbd5f 100644
--- a/usr.sbin/dhcpd/db.c
+++ b/usr.sbin/dhcpd/db.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db.c,v 1.5 2004/04/15 23:20:23 henning Exp $ */
+/* $OpenBSD: db.c,v 1.6 2004/04/18 00:43:27 deraadt Exp $ */
/*
* Persistent database management routines for DHCPD.
@@ -57,7 +57,7 @@ int
write_lease(struct lease *lease)
{
struct tm *t;
- char tbuf [64];
+ char tbuf[64];
int errors = 0;
int i;
@@ -143,9 +143,9 @@ write_lease(struct lease *lease)
bad_client_hostname:
if (lease->hostname) {
- for (i = 0; lease->hostname [i]; i++)
- if (lease->hostname [i] < 33 ||
- lease->hostname [i] > 126)
+ for (i = 0; lease->hostname[i]; i++)
+ if (lease->hostname[i] < 33 ||
+ lease->hostname[i] > 126)
goto bad_hostname;
errno = 0;
fprintf(db_file, "\n\thostname \"%s\";",
diff --git a/usr.sbin/dhcpd/dhcp.c b/usr.sbin/dhcpd/dhcp.c
index b025227a4f0..2c2c99b0165 100644
--- a/usr.sbin/dhcpd/dhcp.c
+++ b/usr.sbin/dhcpd/dhcp.c
@@ -78,24 +78,22 @@ dhcp(struct packet *packet)
}
}
-void dhcpdiscover(packet)
- struct packet *packet;
+void
+dhcpdiscover(struct packet *packet)
{
struct lease *lease = find_lease(packet, packet->shared_network, 0);
struct host_decl *hp;
note("DHCPDISCOVER from %s via %s",
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
/* Sourceless packets don't make sense here. */
if (!packet->shared_network) {
note("Packet from unknown subnet: %s",
- inet_ntoa(packet->raw->giaddr));
+ inet_ntoa(packet->raw->giaddr));
return;
}
@@ -103,17 +101,21 @@ void dhcpdiscover(packet)
if (!lease) {
lease = packet->shared_network->last_lease;
- /* If there are no leases in that subnet that have
- expired, we have nothing to offer this client. */
+ /*
+ * If there are no leases in that subnet that have
+ * expired, we have nothing to offer this client.
+ */
if (!lease || lease->ends > cur_time) {
note("no free leases on subnet %s",
- packet->shared_network->name);
+ packet->shared_network->name);
return;
}
- /* If we find an abandoned lease, take it, but print a
- warning message, so that if it continues to lose,
- the administrator will eventually investigate. */
+ /*
+ * If we find an abandoned lease, take it, but print a
+ * warning message, so that if it continues to lose,
+ * the administrator will eventually investigate.
+ */
if ((lease->flags & ABANDONED_LEASE)) {
struct lease *lp;
@@ -127,11 +129,13 @@ void dhcpdiscover(packet)
}
}
- /* If we can't find an unabandoned lease, reclaim the
- abandoned lease. */
+ /*
+ * If we can't find an unabandoned lease,
+ * reclaim the abandoned lease.
+ */
if ((lease->flags & ABANDONED_LEASE)) {
warn("Reclaiming abandoned IP address %s.",
- piaddr(lease->ip_addr));
+ piaddr(lease->ip_addr));
lease->flags &= ~ABANDONED_LEASE;
}
}
@@ -141,25 +145,20 @@ void dhcpdiscover(packet)
has no fixed IP address. If there is one, hang
it off the lease so that its option definitions
can be used. */
- if (((packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len
- != 0) &&
- ((hp = find_hosts_by_uid
- (packet->options[DHO_DHCP_CLIENT_IDENTIFIER].data,
- packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len))
- != (struct host_decl *)0)) ||
+ if (((packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len != 0) &&
+ ((hp = find_hosts_by_uid(
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].data,
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len)) != NULL)) ||
((hp = find_hosts_by_haddr(packet->raw->htype,
- packet->raw->chaddr,
- packet->raw->hlen))
- != (struct host_decl *)0)) {
+ packet->raw->chaddr, packet->raw->hlen)) != NULL)) {
for (; hp; hp = hp->n_ipaddr) {
if (!hp->fixed_addr) {
lease->host = hp;
break;
}
}
- } else {
- lease->host = (struct host_decl *)0;
- }
+ } else
+ lease->host = NULL;
}
/* If this subnet won't boot unknown clients, ignore the
@@ -167,112 +166,101 @@ void dhcpdiscover(packet)
if (!lease->host &&
!lease->subnet->group->boot_unknown_clients) {
note("Ignoring unknown client %s",
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr));
- } else if (lease->host &&
- !lease->host->group->allow_booting) {
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr));
+ } else if (lease->host && !lease->host->group->allow_booting) {
note("Declining to boot client %s",
- lease->host->name
- ? lease->host->name
- : print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr));
+ lease->host->name ? lease->host->name :
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr));
} else
ack_lease(packet, lease, DHCPOFFER, cur_time + 120);
}
-void dhcprequest(packet)
- struct packet *packet;
+void
+dhcprequest(struct packet *packet)
{
struct lease *lease;
struct iaddr cip;
struct subnet *subnet;
int ours = 0;
- if (packet->options[DHO_DHCP_REQUESTED_ADDRESS].len) {
- cip.len = 4;
+ cip.len = 4;
+ if (packet->options[DHO_DHCP_REQUESTED_ADDRESS].len)
memcpy(cip.iabuf,
- packet->options[DHO_DHCP_REQUESTED_ADDRESS].data,
- 4);
- } else {
- cip.len = 4;
+ packet->options[DHO_DHCP_REQUESTED_ADDRESS].data, 4);
+ else
memcpy(cip.iabuf, &packet->raw->ciaddr.s_addr, 4);
- }
subnet = find_subnet(cip);
- /* Find the lease that matches the address requested by the
- client. */
+ /* Find the lease that matches the address requested by the client. */
if (subnet)
lease = find_lease(packet, subnet->shared_network, &ours);
else
lease = NULL;
- note("DHCPREQUEST for %s from %s via %s",
- piaddr(cip),
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
+ note("DHCPREQUEST for %s from %s via %s", piaddr(cip),
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
/* If a client on a given network REQUESTs a lease on an
- address on a different network, NAK it. If the Requested
- Address option was used, the protocol says that it must
- have been broadcast, so we can trust the source network
- information.
-
- If ciaddr was specified and Requested Address was not, then
- we really only know for sure what network a packet came from
- if it came through a BOOTP gateway - if it came through an
- IP router, we'll just have to assume that it's cool.
-
- If we don't think we know where the packet came from, it
- came through a gateway from an unknown network, so it's not
- from a RENEWING client. If we recognize the network it
- *thinks* it's on, we can NAK it even though we don't
- recognize the network it's *actually* on; otherwise we just
- have to ignore it.
-
- We don't currently try to take advantage of access to the
- raw packet, because it's not available on all platforms.
- So a packet that was unicast to us through a router from a
- RENEWING client is going to look exactly like a packet that
- was broadcast to us from an INIT-REBOOT client.
-
- Since we can't tell the difference between these two kinds
- of packets, if the packet appears to have come in off the
- local wire, we have to treat it as if it's a RENEWING
- client. This means that we can't NAK a RENEWING client on
- the local wire that has a bogus address. The good news is
- that we won't ACK it either, so it should revert to INIT
- state and send us a DHCPDISCOVER, which we *can* work with.
-
- Because we can't detect that a RENEWING client is on the
- wrong wire, it's going to sit there trying to renew until
- it gets to the REBIND state, when we *can* NAK it because
- the packet will get to us through a BOOTP gateway. We
- shouldn't actually see DHCPREQUEST packets from RENEWING
- clients on the wrong wire anyway, since their idea of their
- local router will be wrong. In any case, the protocol
- doesn't really allow us to NAK a DHCPREQUEST from a
- RENEWING client, so we can punt on this issue. */
-
+ * address on a different network, NAK it. If the Requested
+ * Address option was used, the protocol says that it must
+ * have been broadcast, so we can trust the source network
+ * information.
+ *
+ * If ciaddr was specified and Requested Address was not, then
+ * we really only know for sure what network a packet came from
+ * if it came through a BOOTP gateway - if it came through an
+ * IP router, we'll just have to assume that it's cool.
+ *
+ * If we don't think we know where the packet came from, it
+ * came through a gateway from an unknown network, so it's not
+ * from a RENEWING client. If we recognize the network it
+ * *thinks* it's on, we can NAK it even though we don't
+ * recognize the network it's *actually* on; otherwise we just
+ * have to ignore it.
+ *
+ * We don't currently try to take advantage of access to the
+ * raw packet, because it's not available on all platforms.
+ * So a packet that was unicast to us through a router from a
+ * RENEWING client is going to look exactly like a packet that
+ * was broadcast to us from an INIT-REBOOT client.
+ *
+ * Since we can't tell the difference between these two kinds
+ * of packets, if the packet appears to have come in off the
+ * local wire, we have to treat it as if it's a RENEWING
+ * client. This means that we can't NAK a RENEWING client on
+ * the local wire that has a bogus address. The good news is
+ * that we won't ACK it either, so it should revert to INIT
+ * state and send us a DHCPDISCOVER, which we *can* work with.
+ *
+ * Because we can't detect that a RENEWING client is on the
+ * wrong wire, it's going to sit there trying to renew until
+ * it gets to the REBIND state, when we *can* NAK it because
+ * the packet will get to us through a BOOTP gateway. We
+ * shouldn't actually see DHCPREQUEST packets from RENEWING
+ * clients on the wrong wire anyway, since their idea of their
+ * local router will be wrong. In any case, the protocol
+ * doesn't really allow us to NAK a DHCPREQUEST from a
+ * RENEWING client, so we can punt on this issue.
+ */
if (!packet->shared_network ||
- (packet->raw->ciaddr.s_addr &&
- packet->raw->giaddr.s_addr) ||
+ (packet->raw->ciaddr.s_addr && packet->raw->giaddr.s_addr) ||
(packet->options[DHO_DHCP_REQUESTED_ADDRESS].len &&
- !packet->raw->ciaddr.s_addr)) {
+ !packet->raw->ciaddr.s_addr)) {
- /* If we don't know where it came from but we do know
- where it claims to have come from, it didn't come
- from there. Fry it. */
+ /*
+ * If we don't know where it came from but we do know
+ * where it claims to have come from, it didn't come
+ * from there. Fry it.
+ */
if (!packet->shared_network) {
if (subnet &&
- subnet->shared_network->group->authoritative)
- {
+ subnet->shared_network->group->authoritative) {
nak_lease(packet, &cip);
return;
}
@@ -280,8 +268,10 @@ void dhcprequest(packet)
return;
}
- /* If we do know where it came from and it asked for an
- address that is not on that shared network, nak it. */
+ /*
+ * If we do know where it came from and it asked for an
+ * address that is not on that shared network, nak it.
+ */
subnet = find_grouped_subnet(packet->shared_network, cip);
if (!subnet) {
if (packet->shared_network->group->authoritative)
@@ -290,222 +280,213 @@ void dhcprequest(packet)
}
}
- /* If we found a lease for the client but it's not the one the
- client asked for, don't send it - some other server probably
- made the cut. */
+ /*
+ * If we found a lease for the client but it's not the one the
+ * client asked for, don't send it - some other server probably
+ * made the cut.
+ */
if (lease && !addr_eq(lease->ip_addr, cip)) {
- /* If we found the address the client asked for, but
- it wasn't what got picked, the lease belongs to us,
- so we should NAK it. */
+ /*
+ * If we found the address the client asked for, but
+ * it wasn't what got picked, the lease belongs to us,
+ * so we should NAK it.
+ */
if (ours)
nak_lease(packet, &cip);
return;
}
- /* If the address the client asked for is ours, but it wasn't
- available for the client, NAK it. */
+ /*
+ * If the address the client asked for is ours, but it wasn't
+ * available for the client, NAK it.
+ */
if (!lease && ours) {
nak_lease(packet, &cip);
return;
}
/* If we're not allowed to serve this client anymore, don't. */
- if (lease &&
- !lease->host &&
+ if (lease && !lease->host &&
!lease->subnet->group->boot_unknown_clients) {
note("Ignoring unknown client %s",
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr));
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr));
return;
- } else if (lease && lease->host &&
- !lease->host->group->allow_booting) {
+ } else if (lease && lease->host && !lease->host->group->allow_booting) {
note("Declining to renew client %s",
- lease->host->name
- ? lease->host->name
- : print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr));
+ lease->host->name ? lease->host->name :
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr));
return;
}
- /* If we own the lease that the client is asking for,
- and it's already been assigned to the client, ack it. */
+ /*
+ * If we own the lease that the client is asking for,
+ * and it's already been assigned to the client, ack it.
+ */
if (lease &&
((lease->uid_len && lease->uid_len ==
- packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len &&
- !memcmp(packet->options
- [DHO_DHCP_CLIENT_IDENTIFIER].data,
- lease->uid, lease->uid_len)) ||
- (lease->hardware_addr.hlen == packet->raw->hlen &&
- lease->hardware_addr.htype == packet->raw->htype &&
- !memcmp(lease->hardware_addr.haddr,
- packet->raw->chaddr,
- packet->raw->hlen)))) {
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len &&
+ !memcmp(packet->options[DHO_DHCP_CLIENT_IDENTIFIER].data,
+ lease->uid, lease->uid_len)) ||
+ (lease->hardware_addr.hlen == packet->raw->hlen &&
+ lease->hardware_addr.htype == packet->raw->htype &&
+ !memcmp(lease->hardware_addr.haddr, packet->raw->chaddr,
+ packet->raw->hlen)))) {
ack_lease(packet, lease, DHCPACK, 0);
return;
}
- /* At this point, the client has requested a lease, and it's
- available, but it wasn't assigned to the client, which
- means that the client probably hasn't gone through the
- DHCPDISCOVER part of the protocol. We are within our
- rights to send a DHCPNAK. We can also send a DHCPACK.
- The thing we probably should not do is to remain silent.
- For now, we'll just assign the lease to the client anyway. */
+ /*
+ * At this point, the client has requested a lease, and it's
+ * available, but it wasn't assigned to the client, which
+ * means that the client probably hasn't gone through the
+ * DHCPDISCOVER part of the protocol. We are within our
+ * rights to send a DHCPNAK. We can also send a DHCPACK.
+ * The thing we probably should not do is to remain silent.
+ * For now, we'll just assign the lease to the client anyway.
+ */
if (lease)
ack_lease(packet, lease, DHCPACK, 0);
}
-void dhcprelease(packet)
- struct packet *packet;
+void
+dhcprelease(struct packet *packet)
{
struct lease *lease;
struct iaddr cip;
int i;
- /* DHCPRELEASE must not specify address in requested-address
- option, but old protocol specs weren't explicit about this,
- so let it go. */
+ /*
+ * DHCPRELEASE must not specify address in requested-address
+ * option, but old protocol specs weren't explicit about this,
+ * so let it go.
+ */
if (packet->options[DHO_DHCP_REQUESTED_ADDRESS].len) {
note("DHCPRELEASE from %s specified requested-address.",
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr));
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr));
}
i = DHO_DHCP_CLIENT_IDENTIFIER;
if (packet->options[i].len) {
lease = find_lease_by_uid(packet->options[i].data,
- packet->options[i].len);
+ packet->options[i].len);
- /* See if we can find a lease that matches the IP address
- the client is claiming. */
+ /*
+ * See if we can find a lease that matches the
+ * IP address the client is claiming.
+ */
for (; lease; lease = lease->n_uid) {
if (!memcmp(&packet->raw->ciaddr,
- lease->ip_addr.iabuf, 4)) {
+ lease->ip_addr.iabuf, 4)) {
break;
}
}
} else {
- /* The client is supposed to pass a valid client-identifier,
- but the spec on this has changed historically, so try the
- IP address in ciaddr if the client-identifier fails. */
+ /*
+ * The client is supposed to pass a valid client-identifier,
+ * but the spec on this has changed historically, so try the
+ * IP address in ciaddr if the client-identifier fails.
+ */
cip.len = 4;
memcpy(cip.iabuf, &packet->raw->ciaddr, 4);
lease = find_lease_by_ip_addr(cip);
}
note("DHCPRELEASE of %s from %s via %s (%sfound)",
- inet_ntoa(packet->raw->ciaddr),
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name,
- lease ? "" : "not ");
+ inet_ntoa(packet->raw->ciaddr),
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name,
+ lease ? "" : "not ");
/* If we found a lease, release it. */
if (lease && lease->ends > cur_time) {
- /* first, we ping this lease to see if it's still
- * there. if it is, we don't release it.
- * this avoids the problem of spoofed releases
- * being used to liberate addresses from the
- * server.
+ /*
+ * First, we ping this lease to see if it's still
+ * there. if it is, we don't release it. This avoids
+ * the problem of spoofed releases being used to liberate
+ * addresses from the server.
*/
if (!lease->releasing) {
note("DHCPRELEASE of %s from %s via %s (found)",
inet_ntoa(packet->raw->ciaddr),
print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
+ packet->raw->hlen, packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ?
+ inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
lease->releasing = 1;
add_timeout(cur_time + 1, lease_ping_timeout, lease);
icmp_echorequest(&(lease->ip_addr));
++outstanding_pings;
+ } else {
+ note("DHCPRELEASE of %s from %s via %s ignored "
+ "(release already pending)",
+ inet_ntoa(packet->raw->ciaddr),
+ print_hw_addr(packet->raw->htype,
+ packet->raw->hlen, packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ?
+ inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
}
- else {
- note("DHCPRELEASE of %s from %s via %s ignored (release already pending)",
- inet_ntoa(packet->raw->ciaddr),
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
- }
- }
- else {
+ } else {
note("DHCPRELEASE of %s from %s via %s for nonexistent lease",
- inet_ntoa(packet->raw->ciaddr),
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
+ inet_ntoa(packet->raw->ciaddr),
+ print_hw_addr(packet->raw->htype, packet->raw->hlen,
+ packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ?
+ inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
}
}
-void dhcpdecline(packet)
- struct packet *packet;
+void
+dhcpdecline(struct packet *packet)
{
struct lease *lease;
struct iaddr cip;
/* DHCPDECLINE must specify address. */
- if (!packet->options[DHO_DHCP_REQUESTED_ADDRESS].len) {
+ if (!packet->options[DHO_DHCP_REQUESTED_ADDRESS].len)
return;
- }
cip.len = 4;
memcpy(cip.iabuf,
- packet->options[DHO_DHCP_REQUESTED_ADDRESS].data, 4);
+ packet->options[DHO_DHCP_REQUESTED_ADDRESS].data, 4);
lease = find_lease_by_ip_addr(cip);
note("DHCPDECLINE on %s from %s via %s",
- piaddr(cip),
- print_hw_addr(packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- packet->raw->giaddr.s_addr
- ? inet_ntoa(packet->raw->giaddr)
- : packet->interface->name);
+ piaddr(cip), print_hw_addr(packet->raw->htype,
+ packet->raw->hlen, packet->raw->chaddr),
+ packet->raw->giaddr.s_addr ? inet_ntoa(packet->raw->giaddr) :
+ packet->interface->name);
/* If we found a lease, mark it as unusable and complain. */
- if (lease) {
+ if (lease)
abandon_lease(lease, "declined.");
- }
}
-void dhcpinform(packet)
- struct packet *packet;
+void
+dhcpinform(struct packet *packet)
{
- note("DHCPINFORM from %s",
- inet_ntoa(packet->raw->ciaddr));
+ note("DHCPINFORM from %s", inet_ntoa(packet->raw->ciaddr));
}
-void nak_lease(packet, cip)
- struct packet *packet;
- struct iaddr *cip;
+void
+nak_lease(struct packet *packet, struct iaddr *cip)
{
struct sockaddr_in to;
struct in_addr from;
- int result;
+ int result, i;
struct dhcp_packet raw;
unsigned char nak = DHCPNAK;
struct packet outgoing;
struct hardware hto;
- int i;
-
- struct tree_cache *options[256];
- struct tree_cache dhcpnak_tree;
- struct tree_cache dhcpmsg_tree;
+ struct tree_cache *options[256], dhcpnak_tree, dhcpmsg_tree;
memset(options, 0, sizeof options);
memset(&outgoing, 0, sizeof outgoing);
@@ -518,28 +499,27 @@ void nak_lease(packet, cip)
options[DHO_DHCP_MESSAGE_TYPE]->len = sizeof nak;
options[DHO_DHCP_MESSAGE_TYPE]->buf_size = sizeof nak;
options[DHO_DHCP_MESSAGE_TYPE]->timeout = 0xFFFFFFFF;
- options[DHO_DHCP_MESSAGE_TYPE]->tree = (struct tree *)0;
+ options[DHO_DHCP_MESSAGE_TYPE]->tree = NULL;
/* Set DHCP_MESSAGE to whatever the message is */
options[DHO_DHCP_MESSAGE] = &dhcpmsg_tree;
options[DHO_DHCP_MESSAGE]->value = (unsigned char *)dhcp_message;
- options[DHO_DHCP_MESSAGE]->len =
- options[DHO_DHCP_MESSAGE]->buf_size = strlen(dhcp_message);
+ options[DHO_DHCP_MESSAGE]->len = strlen(dhcp_message);
+ options[DHO_DHCP_MESSAGE]->buf_size = strlen(dhcp_message);
options[DHO_DHCP_MESSAGE]->timeout = 0xFFFFFFFF;
- options[DHO_DHCP_MESSAGE]->tree = (struct tree *)0;
+ options[DHO_DHCP_MESSAGE]->tree = NULL;
/* Do not use the client's requested parameter list. */
i = DHO_DHCP_PARAMETER_REQUEST_LIST;
if (packet->options[i].data) {
packet->options[i].len = 0;
dfree(packet->options[i].data, "nak_lease");
- packet->options[i].data = (unsigned char *)0;
+ packet->options[i].data = NULL;
}
/* Set up the option buffer... */
- outgoing.packet_length =
- cons_options(packet, outgoing.raw, 0, options, 0, 0, 0,
- (u_int8_t *)0, 0);
+ outgoing.packet_length = cons_options(packet, outgoing.raw,
+ 0, options, 0, 0, 0, NULL, 0);
/* memset(&raw.ciaddr, 0, sizeof raw.ciaddr);*/
raw.siaddr = packet->interface->primary_address;
@@ -547,7 +527,6 @@ void nak_lease(packet, cip)
memcpy(raw.chaddr, packet->raw->chaddr, sizeof raw.chaddr);
raw.hlen = packet->raw->hlen;
raw.htype = packet->raw->htype;
-
raw.xid = packet->raw->xid;
raw.secs = packet->raw->secs;
raw.flags = packet->raw->flags | htons(BOOTP_BROADCAST);
@@ -561,10 +540,10 @@ void nak_lease(packet, cip)
inet_ntoa(packet->raw->giaddr) : packet->interface->name);
#ifdef DEBUG_PACKET
- dump_packet (packet);
- dump_raw ((unsigned char *)packet->raw, packet->packet_length);
- dump_packet (&outgoing);
- dump_raw ((unsigned char *)&raw, outgoing.packet_length);
+ dump_packet(packet);
+ dump_raw((unsigned char *)packet->raw, packet->packet_length);
+ dump_packet(&outgoing);
+ dump_raw((unsigned char *)&raw, outgoing.packet_length);
#endif
hto.htype = packet->raw->htype;
@@ -572,7 +551,7 @@ void nak_lease(packet, cip)
memcpy(hto.haddr, packet->raw->chaddr, hto.hlen);
/* Set up the common stuff... */
- memset (&to, 0, sizeof to);
+ memset(&to, 0, sizeof to);
to.sin_family = AF_INET;
to.sin_len = sizeof to;
@@ -582,76 +561,60 @@ void nak_lease(packet, cip)
if (outgoing.packet_length < BOOTP_MIN_LEN)
outgoing.packet_length = BOOTP_MIN_LEN;
- /* If this was gatewayed, send it back to the gateway.
- Otherwise, broadcast it on the local network. */
+ /*
+ * If this was gatewayed, send it back to the gateway.
+ * Otherwise, broadcast it on the local network.
+ */
if (raw.giaddr.s_addr) {
to.sin_addr = raw.giaddr;
to.sin_port = local_port;
if (fallback_interface) {
- result = send_packet (fallback_interface,
- packet, &raw,
- outgoing.packet_length,
- from, &to, &hto);
+ result = send_packet(fallback_interface, packet, &raw,
+ outgoing.packet_length, from, &to, &hto);
if (result == -1)
warn("send_fallback: %m");
return;
}
} else {
- to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
+ to.sin_addr.s_addr = htonl(INADDR_BROADCAST);
to.sin_port = remote_port;
}
errno = 0;
- result = send_packet (packet->interface,
- packet, &raw, outgoing.packet_length,
- from, &to, (struct hardware *)0);
+ result = send_packet(packet->interface, packet, &raw,
+ outgoing.packet_length, from, &to, NULL);
}
-void ack_lease (packet, lease, offer, when)
- struct packet *packet;
- struct lease *lease;
- unsigned int offer;
- time_t when;
+void
+ack_lease(struct packet *packet, struct lease *lease, unsigned int offer,
+ time_t when)
{
struct lease lt;
struct lease_state *state;
- time_t lease_time;
- time_t offered_lease_time;
- time_t max_lease_time;
- time_t default_lease_time;
- int ulafdr;
-
+ time_t lease_time, offered_lease_time, max_lease_time, default_lease_time;
struct class *vendor_class, *user_class;
- int i;
+ int ulafdr, i;
/* If we're already acking this lease, don't do it again. */
if (lease->state) {
- note ("already acking lease %s", piaddr (lease->ip_addr));
+ note("already acking lease %s", piaddr(lease->ip_addr));
return;
}
if (packet->options[DHO_DHCP_CLASS_IDENTIFIER].len) {
- vendor_class =
- find_class (0,
- packet ->
- options[DHO_DHCP_CLASS_IDENTIFIER].data,
- packet ->
- options[DHO_DHCP_CLASS_IDENTIFIER].len);
- } else {
- vendor_class = (struct class *)0;
- }
+ vendor_class =find_class(0,
+ packet->options[DHO_DHCP_CLASS_IDENTIFIER].data,
+ packet->options[DHO_DHCP_CLASS_IDENTIFIER].len);
+ } else
+ vendor_class = NULL;
if (packet->options[DHO_DHCP_USER_CLASS_ID].len) {
- user_class =
- find_class (1,
- packet ->
- options[DHO_DHCP_USER_CLASS_ID].data,
- packet ->
- options[DHO_DHCP_USER_CLASS_ID].len);
- } else {
- user_class = (struct class *)0;
- }
+ user_class = find_class(1,
+ packet->options[DHO_DHCP_USER_CLASS_ID].data,
+ packet->options[DHO_DHCP_USER_CLASS_ID].len);
+ } else
+ user_class = NULL;
/*
* If there is not a specific host entry, and either the
@@ -660,21 +623,21 @@ void ack_lease (packet, lease, offer, when)
*/
if (!lease->host) {
if (vendor_class && !vendor_class->group->allow_booting) {
- debug ("Booting denied by vendor class");
+ debug("Booting denied by vendor class");
return;
}
if (user_class && !user_class->group->allow_booting) {
- debug ("Booting denied by user class");
+ debug("Booting denied by user class");
return;
}
}
/* Allocate a lease state structure... */
- state = new_lease_state ("ack_lease");
+ state = new_lease_state("ack_lease");
if (!state)
error("unable to allocate lease state!");
- memset (state, 0, sizeof *state);
+ memset(state, 0, sizeof *state);
state->got_requested_address = packet->got_requested_address;
state->shared_network = packet->interface->shared_network;
@@ -685,46 +648,44 @@ void ack_lease (packet, lease, offer, when)
/* Replace the old lease hostname with the new one, if it's changed. */
if (packet->options[DHO_HOST_NAME].len &&
lease->client_hostname &&
- (strlen (lease->client_hostname) ==
- packet->options[DHO_HOST_NAME].len) &&
- !memcmp (lease->client_hostname,
- packet->options[DHO_HOST_NAME].data,
- packet->options[DHO_HOST_NAME].len)) {
+ (strlen (lease->client_hostname) == packet->options[DHO_HOST_NAME].len) &&
+ !memcmp(lease->client_hostname, packet->options[DHO_HOST_NAME].data,
+ packet->options[DHO_HOST_NAME].len)) {
} else if (packet->options[DHO_HOST_NAME].len) {
if (lease->client_hostname)
- free (lease->client_hostname);
- lease->client_hostname =
- malloc (packet->options[DHO_HOST_NAME].len + 1);
+ free(lease->client_hostname);
+ lease->client_hostname = malloc(
+ packet->options[DHO_HOST_NAME].len + 1);
if (!lease->client_hostname)
error("no memory for client hostname.\n");
memcpy(lease->client_hostname,
- packet->options[DHO_HOST_NAME].data,
- packet->options[DHO_HOST_NAME].len);
- lease->client_hostname
- [packet->options[DHO_HOST_NAME].len] = 0;
+ packet->options[DHO_HOST_NAME].data,
+ packet->options[DHO_HOST_NAME].len);
+ lease->client_hostname[packet->options[DHO_HOST_NAME].len] = 0;
} else if (lease->client_hostname) {
- free (lease->client_hostname);
+ free(lease->client_hostname);
lease->client_hostname = 0;
}
- /* Choose a filename; first from the host_decl, if any, then from
- the user class, then from the vendor class. */
+ /*
+ * Choose a filename; first from the host_decl, if any, then from
+ * the user class, then from the vendor class.
+ */
if (lease->host && lease->host->group->filename)
strlcpy(state->filename, lease->host->group->filename,
- sizeof state->filename);
+ sizeof state->filename);
else if (user_class && user_class->group->filename)
strlcpy(state->filename, user_class->group->filename,
- sizeof state->filename);
+ sizeof state->filename);
else if (vendor_class && vendor_class->group->filename)
strlcpy(state->filename, vendor_class->group->filename,
- sizeof state->filename);
+ sizeof state->filename);
else if (packet->raw->file[0])
strlcpy(state->filename, packet->raw->file,
- sizeof state->filename);
+ sizeof state->filename);
else if (lease->subnet->group->filename)
- strlcpy(state->filename,
- lease->subnet->group->filename,
- sizeof state->filename);
+ strlcpy(state->filename, lease->subnet->group->filename,
+ sizeof state->filename);
else
strlcpy(state->filename, "", sizeof state->filename);
@@ -736,48 +697,50 @@ void ack_lease (packet, lease, offer, when)
else if (vendor_class && vendor_class->group->server_name)
state->server_name = vendor_class->group->server_name;
else if (lease->subnet->group->server_name)
- state->server_name =
- lease->subnet->group->server_name;
- else state->server_name = (char *)0;
-
- /* At this point, we have a lease that we can offer the client.
- Now we construct a lease structure that contains what we want,
- and call supersede_lease to do the right thing with it. */
+ state->server_name = lease->subnet->group->server_name;
+ else state->server_name = NULL;
- memset (&lt, 0, sizeof lt);
+ /*
+ * At this point, we have a lease that we can offer the client.
+ * Now we construct a lease structure that contains what we want,
+ * and call supersede_lease to do the right thing with it.
+ */
+ memset(&lt, 0, sizeof lt);
- /* Use the ip address of the lease that we finally found in
- the database. */
+ /*
+ * Use the ip address of the lease that we finally found in
+ * the database.
+ */
lt.ip_addr = lease->ip_addr;
/* Start now. */
lt.starts = cur_time;
/* Figure out maximum lease time. */
- if (lease->host &&
- lease->host->group->max_lease_time)
+ if (lease->host && lease->host->group->max_lease_time)
max_lease_time = lease->host->group->max_lease_time;
else
max_lease_time = lease->subnet->group->max_lease_time;
/* Figure out default lease time. */
- if (lease->host
- && lease->host->group->default_lease_time)
- default_lease_time =
- lease->host->group->default_lease_time;
+ if (lease->host && lease->host->group->default_lease_time)
+ default_lease_time = lease->host->group->default_lease_time;
else
- default_lease_time =
- lease->subnet->group->default_lease_time;
+ default_lease_time = lease->subnet->group->default_lease_time;
- /* Figure out how long a lease to assign. If this is a
- dynamic BOOTP lease, its duration must be infinite. */
+ /*
+ * Figure out how long a lease to assign. If this is a
+ * dynamic BOOTP lease, its duration must be infinite.
+ */
if (offer) {
if (packet->options[DHO_DHCP_LEASE_TIME].len == 4) {
- lease_time = getULong
- (packet->options[DHO_DHCP_LEASE_TIME].data);
+ lease_time = getULong(
+ packet->options[DHO_DHCP_LEASE_TIME].data);
- /* Don't let the client ask for a longer lease than
- is supported for this subnet or host. */
+ /*
+ * Don't let the client ask for a longer lease than
+ * is supported for this subnet or host.
+ */
if (lease_time > max_lease_time)
lease_time = max_lease_time;
} else
@@ -792,18 +755,15 @@ void ack_lease (packet, lease, offer, when)
if (lease->host &&
lease->host->group->bootp_lease_length)
lt.ends = (cur_time +
- lease->host ->
- group->bootp_lease_length);
+ lease->host->group->bootp_lease_length);
else if (lease->subnet->group->bootp_lease_length)
lt.ends = (cur_time +
- lease->subnet ->
- group->bootp_lease_length);
+ lease->subnet->group->bootp_lease_length);
else if (lease->host &&
- lease->host->group->bootp_lease_cutoff)
+ lease->host->group->bootp_lease_cutoff)
lt.ends = lease->host->group->bootp_lease_cutoff;
else
- lt.ends = (lease->subnet ->
- group->bootp_lease_cutoff);
+ lt.ends = lease->subnet->group->bootp_lease_cutoff;
state->offered_expiry = lt.ends;
lt.flags = BOOTP_LEASE;
}
@@ -813,17 +773,16 @@ void ack_lease (packet, lease, offer, when)
if (packet->options[i].len) {
if (packet->options[i].len <= sizeof lt.uid_buf) {
memcpy(lt.uid_buf, packet->options[i].data,
- packet->options[i].len);
+ packet->options[i].len);
lt.uid = lt.uid_buf;
lt.uid_max = sizeof lt.uid_buf;
lt.uid_len = packet->options[i].len;
} else {
lt.uid_max = lt.uid_len = packet->options[i].len;
- lt.uid = (unsigned char *)malloc (lt.uid_max);
+ lt.uid = (unsigned char *)malloc(lt.uid_max);
if (!lt.uid)
error("can't allocate memory for large uid.");
- memcpy(lt.uid,
- packet->options[i].data, lt.uid_len);
+ memcpy(lt.uid, packet->options[i].data, lt.uid_len);
}
}
@@ -838,21 +797,21 @@ void ack_lease (packet, lease, offer, when)
lease->hardware_addr.hlen = packet->raw->hlen;
lease->hardware_addr.htype = packet->raw->htype;
memcpy(lease->hardware_addr.haddr, packet->raw->chaddr,
- sizeof packet->raw->chaddr); /* XXX */
+ sizeof packet->raw->chaddr); /* XXX */
} else {
/* Record the hardware address, if given... */
lt.hardware_addr.hlen = packet->raw->hlen;
lt.hardware_addr.htype = packet->raw->htype;
memcpy(lt.hardware_addr.haddr, packet->raw->chaddr,
- sizeof packet->raw->chaddr);
+ sizeof packet->raw->chaddr);
/* Install the new information about this lease in the
database. If this is a DHCPACK or a dynamic BOOTREPLY
and we can't write the lease, don't ACK it (or BOOTREPLY
it) either. */
- if (!(supersede_lease (lease, &lt, !offer || offer == DHCPACK)
- || (offer && offer != DHCPACK)))
+ if (!(supersede_lease(lease, &lt, !offer || offer == DHCPACK) ||
+ (offer && offer != DHCPACK)))
return;
}
@@ -862,8 +821,8 @@ void ack_lease (packet, lease, offer, when)
/* Set a flag if this client is a lame Microsoft client that NUL
terminates string options and expects us to do likewise. */
if (packet->options[DHO_HOST_NAME].data &&
- packet->options[DHO_HOST_NAME].data
- [packet->options[DHO_HOST_NAME].len - 1] == '\0')
+ packet->options[DHO_HOST_NAME].data[
+ packet->options[DHO_HOST_NAME].len - 1] == '\0')
lease->flags |= MS_NULL_TERMINATION;
else
lease->flags &= ~MS_NULL_TERMINATION;
@@ -880,9 +839,8 @@ void ack_lease (packet, lease, offer, when)
/* Figure out what options to send to the client: */
/* Start out with the subnet options... */
- memcpy(state->options,
- lease->subnet->group->options,
- sizeof state->options);
+ memcpy(state->options, lease->subnet->group->options,
+ sizeof state->options);
/* Vendor and user classes are only supported for DHCP clients. */
if (state->offer) {
@@ -892,8 +850,7 @@ void ack_lease (packet, lease, offer, when)
for (i = 0; i < 256; i++)
if (vendor_class->group->options[i])
state->options[i] =
- (vendor_class->group ->
- options[i]);
+ vendor_class->group->options[i];
}
/* If we have a user class, install those options,
@@ -902,8 +859,7 @@ void ack_lease (packet, lease, offer, when)
for (i = 0; i < 256; i++)
if (user_class->group->options[i])
state->options[i] =
- (user_class->group ->
- options[i]);
+ user_class->group->options[i];
}
}
@@ -913,33 +869,29 @@ void ack_lease (packet, lease, offer, when)
if (lease->host) {
for (i = 0; i < 256; i++)
if (lease->host->group->options[i])
- state->options[i] = (lease->host ->
- group->options[i]);
+ state->options[i] =
+ lease->host->group->options[i];
}
/* Get the Maximum Message Size option from the packet, if one
was sent. */
i = DHO_DHCP_MAX_MESSAGE_SIZE;
if (packet->options[i].data &&
- (packet->options[i].len == sizeof (u_int16_t)))
- state->max_message_size =
- getUShort (packet->options[i].data);
+ packet->options[i].len == sizeof (u_int16_t))
+ state->max_message_size = getUShort(packet->options[i].data);
/* Otherwise, if a maximum message size was specified, use that. */
else if (state->options[i] && state->options[i]->value)
- state->max_message_size =
- getUShort (state->options[i]->value);
+ state->max_message_size = getUShort(state->options[i]->value);
/* Save the parameter request list if there is one. */
i = DHO_DHCP_PARAMETER_REQUEST_LIST;
if (packet->options[i].data) {
- state->prl = dmalloc (packet->options[i].len,
- "ack_lease: prl");
+ state->prl = dmalloc(packet->options[i].len, "ack_lease: prl");
if (!state->prl)
warn("no memory for parameter request list");
else {
- memcpy(state->prl,
- packet->options[i].data,
- packet->options[i].len);
+ memcpy(state->prl, packet->options[i].data,
+ packet->options[i].len);
state->prl_len = packet->options[i].len;
}
}
@@ -948,59 +900,55 @@ void ack_lease (packet, lease, offer, when)
we can get one from the lease. */
i = DHO_HOST_NAME;
if (!state->options[i] && lease->hostname) {
- state->options[i] = new_tree_cache ("hostname");
+ state->options[i] = new_tree_cache("hostname");
state->options[i]->flags = TC_TEMPORARY;
- state->options[i]->value =
- (unsigned char *)lease->hostname;
+ state->options[i]->value = (unsigned char *)lease->hostname;
state->options[i]->len = strlen (lease->hostname);
state->options[i]->buf_size = state->options[i]->len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
}
- /* Now, if appropriate, put in DHCP-specific options that
- override those. */
+ /*
+ * Now, if appropriate, put in DHCP-specific options that
+ * override those.
+ */
if (state->offer) {
i = DHO_DHCP_MESSAGE_TYPE;
- state->options[i] = new_tree_cache ("message-type");
+ state->options[i] = new_tree_cache("message-type");
state->options[i]->flags = TC_TEMPORARY;
state->options[i]->value = &state->offer;
state->options[i]->len = sizeof state->offer;
state->options[i]->buf_size = sizeof state->offer;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
i = DHO_DHCP_SERVER_IDENTIFIER;
if (!state->options[i]) {
use_primary:
- state->options[i] = new_tree_cache ("server-id");
+ state->options[i] = new_tree_cache("server-id");
state->options[i]->value =
- (unsigned char *)&state ->
- ip->primary_address;
+ (unsigned char *)&state->ip->primary_address;
state->options[i]->len =
- sizeof state->ip->primary_address;
- state->options[i]->buf_size
- = state->options[i]->len;
+ sizeof state->ip->primary_address;
+ state->options[i]->buf_size =
+ state->options[i]->len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
- state->from.len =
- sizeof state->ip->primary_address;
- memcpy(state->from.iabuf,
- &state->ip->primary_address,
- state->from.len);
+ state->options[i]->tree = NULL;
+ state->from.len = sizeof state->ip->primary_address;
+ memcpy(state->from.iabuf, &state->ip->primary_address,
+ state->from.len);
} else {
/* Find the value of the server identifier... */
if (!tree_evaluate (state->options[i]))
goto use_primary;
if (!state->options[i]->value ||
- (state->options[i]->len >
- sizeof state->from.iabuf))
+ (state->options[i]->len > sizeof state->from.iabuf))
goto use_primary;
state->from.len = state->options[i]->len;
- memcpy(state->from.iabuf,
- state->options[i]->value,
- state->from.len);
+ memcpy(state->from.iabuf, state->options[i]->value,
+ state->from.len);
}
/* Sanity check the lease time. */
@@ -1010,19 +958,18 @@ void ack_lease (packet, lease, offer, when)
offered_lease_time = max_lease_time;
else
offered_lease_time =
- state->offered_expiry - cur_time;
+ state->offered_expiry - cur_time;
- putULong ((unsigned char *)&state->expiry,
- offered_lease_time);
+ putULong((unsigned char *)&state->expiry,
+ offered_lease_time);
i = DHO_DHCP_LEASE_TIME;
state->options[i] = new_tree_cache ("lease-expiry");
state->options[i]->flags = TC_TEMPORARY;
- state->options[i]->value =
- (unsigned char *)&state->expiry;
+ state->options[i]->value = (unsigned char *)&state->expiry;
state->options[i]->len = sizeof state->expiry;
state->options[i]->buf_size = sizeof state->expiry;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
/* Renewal time is lease time * 0.5. */
offered_lease_time /= 2;
@@ -1036,14 +983,14 @@ void ack_lease (packet, lease, offer, when)
state->options[i]->len = sizeof state->renewal;
state->options[i]->buf_size = sizeof state->renewal;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
/* Rebinding time is lease time * 0.875. */
- offered_lease_time += (offered_lease_time / 2
- + offered_lease_time / 4);
+ offered_lease_time += (offered_lease_time / 2 +
+ offered_lease_time / 4);
putULong ((unsigned char *)&state->rebind,
- offered_lease_time);
+ offered_lease_time);
i = DHO_DHCP_REBINDING_TIME;
state->options[i] = new_tree_cache ("rebind-time");
state->options[i]->flags = TC_TEMPORARY;
@@ -1052,7 +999,7 @@ void ack_lease (packet, lease, offer, when)
state->options[i]->len = sizeof state->rebind;
state->options[i]->buf_size = sizeof state->rebind;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
/* If we used the vendor class the client specified, we
have to return it. */
@@ -1068,7 +1015,7 @@ void ack_lease (packet, lease, offer, when)
state->options[i]->buf_size =
state->options[i]->len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
}
/* If we used the user class the client specified, we
@@ -1084,7 +1031,7 @@ void ack_lease (packet, lease, offer, when)
state->options[i]->buf_size =
state->options[i]->len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
}
}
@@ -1100,7 +1047,7 @@ void ack_lease (packet, lease, offer, when)
state->options[i]->buf_size =
lease->subnet->netmask.len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
}
/* If so directed, use the leased IP address as the router address.
@@ -1117,8 +1064,7 @@ void ack_lease (packet, lease, offer, when)
} else if (vendor_class) {
if (vendor_class->group->use_lease_addr_for_default_route)
ulafdr = 1;
- } else if (lease->subnet->group ->
- use_lease_addr_for_default_route)
+ } else if (lease->subnet->group->use_lease_addr_for_default_route)
ulafdr = 1;
else
ulafdr = 0;
@@ -1127,19 +1073,16 @@ void ack_lease (packet, lease, offer, when)
if (ulafdr && !state->options[i]) {
state->options[i] = new_tree_cache ("routers");
state->options[i]->flags = TC_TEMPORARY;
- state->options[i]->value =
- lease->ip_addr.iabuf;
- state->options[i]->len =
- lease->ip_addr.len;
- state->options[i]->buf_size =
- lease->ip_addr.len;
+ state->options[i]->value = lease->ip_addr.iabuf;
+ state->options[i]->len = lease->ip_addr.len;
+ state->options[i]->buf_size = lease->ip_addr.len;
state->options[i]->timeout = 0xFFFFFFFF;
- state->options[i]->tree = (struct tree *)0;
+ state->options[i]->tree = NULL;
}
#ifdef DEBUG_PACKET
- dump_packet (packet);
- dump_raw ((unsigned char *)packet->raw, packet->packet_length);
+ dump_packet(packet);
+ dump_raw((unsigned char *)packet->raw, packet->packet_length);
#endif
lease->state = state;
@@ -1158,17 +1101,14 @@ void ack_lease (packet, lease, offer, when)
}
}
-void dhcp_reply (lease)
- struct lease *lease;
+void
+dhcp_reply(struct lease *lease)
{
- int bufs = 0;
- int packet_length;
+ int bufs = 0, packet_length, result, i;
struct dhcp_packet raw;
struct sockaddr_in to;
struct in_addr from;
struct hardware hto;
- int result;
- int i;
struct lease_state *state = lease->state;
int nulltp, bootpp;
u_int8_t *prl;
@@ -1178,7 +1118,7 @@ void dhcp_reply (lease)
error("dhcp_reply was supplied lease with no state!");
/* Compose a response for the client... */
- memset (&raw, 0, sizeof raw);
+ memset(&raw, 0, sizeof raw);
/* Copy in the filename if given; otherwise, flag the filename
buffer as available for options. */
@@ -1213,30 +1153,26 @@ void dhcp_reply (lease)
if (state->options[DHO_DHCP_PARAMETER_REQUEST_LIST] &&
state->options[DHO_DHCP_PARAMETER_REQUEST_LIST]->value) {
- prl = state->options
- [DHO_DHCP_PARAMETER_REQUEST_LIST]->value;
- prl_len = state->options
- [DHO_DHCP_PARAMETER_REQUEST_LIST]->len;
+ prl = state->options[DHO_DHCP_PARAMETER_REQUEST_LIST]->value;
+ prl_len = state->options[DHO_DHCP_PARAMETER_REQUEST_LIST]->len;
} else if (state->prl) {
prl = state->prl;
prl_len = state->prl_len;
} else {
- prl = (u_int8_t *)0;
+ prl = NULL;
prl_len = 0;
}
/* Insert such options as will fit into the buffer. */
- packet_length = cons_options ((struct packet *)0, &raw,
- state->max_message_size,
- state->options,
- bufs, nulltp, bootpp, prl, prl_len);
+ packet_length = cons_options(NULL, &raw, state->max_message_size,
+ state->options, bufs, nulltp, bootpp, prl, prl_len);
/* Having done the cons_options(), we can release the tree_cache
entries. */
for (i = 0; i < 256; i++) {
if (state->options[i] &&
state->options[i]->flags & TC_TEMPORARY)
- free_tree_cache (state->options[i], "dhcp_reply");
+ free_tree_cache(state->options[i], "dhcp_reply");
}
memcpy(&raw.ciaddr, &state->ciaddr, sizeof raw.ciaddr);
@@ -1244,14 +1180,11 @@ void dhcp_reply (lease)
/* Figure out the address of the next server. */
if (lease->host && lease->host->group->next_server.len)
- memcpy(&raw.siaddr,
- lease->host->group->next_server.iabuf, 4);
+ memcpy(&raw.siaddr, lease->host->group->next_server.iabuf, 4);
else if (lease->subnet->group->next_server.len)
- memcpy(&raw.siaddr,
- lease->subnet->group->next_server.iabuf, 4);
+ memcpy(&raw.siaddr, lease->subnet->group->next_server.iabuf, 4);
else if (lease->subnet->interface_address.len)
- memcpy(&raw.siaddr,
- lease->subnet->interface_address.iabuf, 4);
+ memcpy(&raw.siaddr, lease->subnet->interface_address.iabuf, 4);
else
raw.siaddr = state->ip->primary_address;
@@ -1264,31 +1197,27 @@ void dhcp_reply (lease)
raw.op = BOOTREPLY;
/* Say what we're doing... */
- note ("%s on %s to %s via %s",
- (state->offer
- ? (state->offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
- : "BOOTREPLY"),
- piaddr (lease->ip_addr),
- print_hw_addr (lease->hardware_addr.htype,
- lease->hardware_addr.hlen,
- lease->hardware_addr.haddr),
- state->giaddr.s_addr
- ? inet_ntoa (state->giaddr)
- : state->ip->name);
+ note("%s on %s to %s via %s",
+ (state->offer ? (state->offer == DHCPACK ? "DHCPACK" : "DHCPOFFER") :
+ "BOOTREPLY"),
+ piaddr(lease->ip_addr),
+ print_hw_addr(lease->hardware_addr.htype, lease->hardware_addr.hlen,
+ lease->hardware_addr.haddr),
+ state->giaddr.s_addr ? inet_ntoa(state->giaddr) : state->ip->name);
/* Set up the hardware address... */
hto.htype = lease->hardware_addr.htype;
hto.hlen = lease->hardware_addr.hlen;
memcpy(hto.haddr, lease->hardware_addr.haddr, hto.hlen);
- memset (&to, 0, sizeof to);
+ memset(&to, 0, sizeof to);
to.sin_family = AF_INET;
#ifdef HAVE_SA_LEN
to.sin_len = sizeof to;
#endif
#ifdef DEBUG_PACKET
- dump_raw ((unsigned char *)&raw, packet_length);
+ dump_raw((unsigned char *)&raw, packet_length);
#endif
/* Make sure outgoing packets are at least as big
@@ -1302,14 +1231,11 @@ void dhcp_reply (lease)
to.sin_port = local_port;
if (fallback_interface) {
- result = send_packet (fallback_interface,
- (struct packet *)0,
- &raw, packet_length,
- raw.siaddr,
- &to, (struct hardware *)0);
-
- free_lease_state (state, "dhcp_reply fallback 1");
- lease->state = (struct lease_state *)0;
+ result = send_packet(fallback_interface, NULL,
+ &raw, packet_length,raw.siaddr, &to, NULL);
+
+ free_lease_state(state, "dhcp_reply fallback 1");
+ lease->state = NULL;
return;
}
@@ -1325,23 +1251,19 @@ void dhcp_reply (lease)
and will therefore get a relayed response from the above
code. */
} else if (raw.ciaddr.s_addr &&
- !((state->got_server_identifier ||
- (raw.flags & htons (BOOTP_BROADCAST))) &&
- /* XXX This won't work if giaddr isn't zero, but it is: */
- (state->shared_network == lease->shared_network)) &&
- state->offer == DHCPACK) {
+ !((state->got_server_identifier ||
+ (raw.flags & htons(BOOTP_BROADCAST))) &&
+ /* XXX This won't work if giaddr isn't zero, but it is: */
+ (state->shared_network == lease->shared_network)) &&
+ state->offer == DHCPACK) {
to.sin_addr = raw.ciaddr;
to.sin_port = remote_port;
if (fallback_interface) {
- result = send_packet (fallback_interface,
- (struct packet *)0,
- &raw, packet_length,
- raw.siaddr, &to,
- (struct hardware *)0);
- free_lease_state (state,
- "dhcp_reply fallback 2");
- lease->state = (struct lease_state *)0;
+ result = send_packet(fallback_interface, NULL,
+ &raw, packet_length, raw.siaddr, &to, NULL);
+ free_lease_state(state, "dhcp_reply fallback 2");
+ lease->state = NULL;
return;
}
@@ -1355,29 +1277,27 @@ void dhcp_reply (lease)
/* Otherwise, broadcast it on the local network. */
} else {
- to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
+ to.sin_addr.s_addr = htonl(INADDR_BROADCAST);
to.sin_port = remote_port;
}
memcpy(&from, state->from.iabuf, sizeof from);
- result = send_packet (state->ip,
- (struct packet *)0, &raw, packet_length,
- from, &to, &hto);
+ result = send_packet(state->ip, NULL, &raw, packet_length,
+ from, &to, &hto);
- free_lease_state (state, "dhcp_reply");
- lease->state = (struct lease_state *)0;
+ free_lease_state(state, "dhcp_reply");
+ lease->state = NULL;
}
-struct lease *find_lease (packet, share, ours)
- struct packet *packet;
- struct shared_network *share;
- int *ours;
+struct lease *
+find_lease(struct packet *packet, struct shared_network *share,
+ int *ours)
{
struct lease *uid_lease, *ip_lease, *hw_lease;
struct lease *lease = NULL;
struct iaddr cip;
- struct host_decl *hp, *host = (struct host_decl *)0;
+ struct host_decl *hp, *host = NULL;
struct lease *fixed_lease;
/* Figure out what IP address the client is requesting, if any. */
@@ -1386,8 +1306,8 @@ struct lease *find_lease (packet, share, ours)
packet->got_requested_address = 1;
cip.len = 4;
memcpy(cip.iabuf,
- packet->options[DHO_DHCP_REQUESTED_ADDRESS].data,
- cip.len);
+ packet->options[DHO_DHCP_REQUESTED_ADDRESS].data,
+ cip.len);
} else if (packet->raw->ciaddr.s_addr) {
cip.len = 4;
memcpy(cip.iabuf, &packet->raw->ciaddr, 4);
@@ -1399,28 +1319,24 @@ struct lease *find_lease (packet, share, ours)
if (packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len) {
/* First, try to find a fixed host entry for the specified
client identifier... */
- hp = find_hosts_by_uid (packet->options
- [DHO_DHCP_CLIENT_IDENTIFIER].data,
- packet->options
- [DHO_DHCP_CLIENT_IDENTIFIER].len);
+ hp = find_hosts_by_uid(
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].data,
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len);
if (hp) {
host = hp;
- fixed_lease = mockup_lease (packet, share, hp);
+ fixed_lease = mockup_lease(packet, share, hp);
uid_lease = NULL;
} else {
- uid_lease = find_lease_by_uid
- (packet->options
- [DHO_DHCP_CLIENT_IDENTIFIER].data,
- packet->options
- [DHO_DHCP_CLIENT_IDENTIFIER].len);
+ uid_lease = find_lease_by_uid(
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].data,
+ packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len);
/* Find the lease matching this uid that's on the
network the packet came from (if any). */
for (; uid_lease; uid_lease = uid_lease->n_uid)
if (uid_lease->shared_network == share)
break;
fixed_lease = NULL;
- if (uid_lease &&
- (uid_lease->flags & ABANDONED_LEASE))
+ if (uid_lease && (uid_lease->flags & ABANDONED_LEASE))
uid_lease = NULL;
}
} else {
@@ -1431,9 +1347,8 @@ struct lease *find_lease (packet, share, ours)
/* If we didn't find a fixed lease using the uid, try doing
it with the hardware address... */
if (!fixed_lease) {
- hp = find_hosts_by_haddr (packet->raw->htype,
- packet->raw->chaddr,
- packet->raw->hlen);
+ hp = find_hosts_by_haddr(packet->raw->htype,
+ packet->raw->chaddr, packet->raw->hlen);
if (hp) {
host = hp; /* Save it for later. */
fixed_lease = mockup_lease (packet, share, hp);
@@ -1445,12 +1360,11 @@ struct lease *find_lease (packet, share, ours)
any other lease, so we might as well return now. */
if (packet->packet_type == DHCPREQUEST && fixed_lease &&
(fixed_lease->ip_addr.len != cip.len ||
- memcmp (fixed_lease->ip_addr.iabuf,
- cip.iabuf, cip.len))) {
+ memcmp(fixed_lease->ip_addr.iabuf, cip.iabuf, cip.len))) {
if (ours)
*ours = 1;
strlcpy(dhcp_message, "requested address is incorrect",
- sizeof (dhcp_message));
+ sizeof (dhcp_message));
return NULL;
}
@@ -1475,7 +1389,7 @@ struct lease *find_lease (packet, share, ours)
/* Try to find a lease that's been allocated to the client's
IP address. */
if (cip.len)
- ip_lease = find_lease_by_ip_addr (cip);
+ ip_lease = find_lease_by_ip_addr(cip);
else
ip_lease = NULL;
@@ -1495,47 +1409,40 @@ struct lease *find_lease (packet, share, ours)
if (ip_lease && (ip_lease->shared_network != share)) {
ip_lease = NULL;
strlcpy(dhcp_message, "requested address on bad subnet",
- sizeof(dhcp_message));
+ sizeof(dhcp_message));
}
/* Toss ip_lease if it hasn't yet expired and isn't owned by the
client. */
- if (ip_lease &&
- ip_lease->ends >= cur_time &&
- ip_lease != uid_lease) {
+ if (ip_lease && ip_lease->ends >= cur_time && ip_lease != uid_lease) {
int i = DHO_DHCP_CLIENT_IDENTIFIER;
+
/* Make sure that ip_lease actually belongs to the client,
and toss it if not. */
- if ((ip_lease->uid_len &&
- packet->options[i].data &&
- ip_lease->uid_len == packet->options[i].len &&
- !memcmp (packet->options[i].data,
- ip_lease->uid, ip_lease->uid_len)) ||
+ if ((ip_lease->uid_len && packet->options[i].data &&
+ ip_lease->uid_len == packet->options[i].len &&
+ !memcmp(packet->options[i].data, ip_lease->uid,
+ ip_lease->uid_len)) ||
(!ip_lease->uid_len &&
- (ip_lease->hardware_addr.htype ==
- packet->raw->htype) &&
- ip_lease->hardware_addr.hlen == packet->raw->hlen &&
- !memcmp (ip_lease->hardware_addr.haddr,
- packet->raw->chaddr,
- ip_lease->hardware_addr.hlen))) {
+ ip_lease->hardware_addr.htype == packet->raw->htype &&
+ ip_lease->hardware_addr.hlen == packet->raw->hlen &&
+ !memcmp(ip_lease->hardware_addr.haddr, packet->raw->chaddr,
+ ip_lease->hardware_addr.hlen))) {
if (uid_lease) {
- if (uid_lease->ends > cur_time) {
- warn("client %s has duplicate leases on %s",
- print_hw_addr (packet->raw->htype,
- packet->raw->hlen,
- packet->raw->chaddr),
- ip_lease->shared_network->name);
-
- if (uid_lease &&
- !packet->raw->ciaddr.s_addr)
- release_lease (uid_lease);
- }
- uid_lease = ip_lease;
+ if (uid_lease->ends > cur_time) {
+ warn("client %s has duplicate leases on %s",
+ print_hw_addr(packet->raw->htype,
+ packet->raw->hlen, packet->raw->chaddr),
+ ip_lease->shared_network->name);
+
+ if (uid_lease && !packet->raw->ciaddr.s_addr)
+ release_lease (uid_lease);
+ }
+ uid_lease = ip_lease;
}
} else {
- strlcpy(dhcp_message,
- "requested address is not available",
- sizeof(dhcp_message));
+ strlcpy(dhcp_message, "requested address is not available",
+ sizeof(dhcp_message));
ip_lease = NULL;
}
@@ -1544,22 +1451,19 @@ struct lease *find_lease (packet, share, ours)
declaration for the same IP address. */
if (packet->packet_type == DHCPREQUEST && fixed_lease) {
fixed_lease = NULL;
- db_conflict:
+db_conflict:
warn("Both dynamic and static leases present for %s.",
- piaddr (cip));
+ piaddr(cip));
warn("Either remove host declaration %s or remove %s",
- (fixed_lease && fixed_lease->host
- ? (fixed_lease->host->name
- ? fixed_lease->host->name : piaddr (cip))
- : piaddr (cip)),
- piaddr (cip));
+ (fixed_lease && fixed_lease->host ?
+ (fixed_lease->host->name ? fixed_lease->host->name :
+ piaddr(cip)) : piaddr(cip)), piaddr(cip));
warn("from the dynamic address pool for %s",
- share->name);
+ share->name);
if (fixed_lease)
ip_lease = NULL;
- strlcpy(dhcp_message,
- "database conflict - call for help!",
- sizeof(dhcp_message));
+ strlcpy(dhcp_message, "database conflict - call for help!",
+ sizeof(dhcp_message));
}
}
@@ -1572,9 +1476,7 @@ struct lease *find_lease (packet, share, ours)
match, except that if the hardware address matches and the
client is now doing dynamic BOOTP (and thus hasn't provided
a uid) we let the client get away with it. */
- if (hw_lease &&
- hw_lease->ends >= cur_time &&
- hw_lease->uid &&
+ if (hw_lease && hw_lease->ends >= cur_time && hw_lease->uid &&
packet->options[DHO_DHCP_CLIENT_IDENTIFIER].len &&
hw_lease != uid_lease)
hw_lease = NULL;
@@ -1596,22 +1498,19 @@ struct lease *find_lease (packet, share, ours)
}
/* Now eliminate leases that are on the wrong network... */
- if (ip_lease &&
- (share != ip_lease->shared_network)) {
+ if (ip_lease && share != ip_lease->shared_network) {
if (packet->packet_type == DHCPREQUEST)
release_lease(ip_lease);
ip_lease = NULL;
}
- if (uid_lease &&
- (share != uid_lease->shared_network)) {
+ if (uid_lease && share != uid_lease->shared_network) {
if (packet->packet_type == DHCPREQUEST)
- release_lease (uid_lease);
+ release_lease(uid_lease);
uid_lease = NULL;
}
- if (hw_lease &&
- (share != hw_lease->shared_network)) {
+ if (hw_lease && share != hw_lease->shared_network) {
if (packet->packet_type == DHCPREQUEST)
- release_lease (hw_lease);
+ release_lease(hw_lease);
hw_lease = NULL;
}
@@ -1623,19 +1522,18 @@ struct lease *find_lease (packet, share, ours)
/* At this point, if fixed_lease is nonzero, we can assign it to
this client. */
- if (fixed_lease) {
+ if (fixed_lease)
lease = fixed_lease;
- }
/* If we got a lease that matched the ip address and don't have
a better offer, use that; otherwise, release it. */
if (ip_lease) {
if (lease) {
if (packet->packet_type == DHCPREQUEST)
- release_lease (ip_lease);
+ release_lease(ip_lease);
} else {
lease = ip_lease;
- lease->host = (struct host_decl *)0;
+ lease->host = NULL;
}
}
@@ -1645,10 +1543,10 @@ struct lease *find_lease (packet, share, ours)
if (uid_lease) {
if (lease) {
if (packet->packet_type == DHCPREQUEST)
- release_lease (uid_lease);
+ release_lease(uid_lease);
} else {
lease = uid_lease;
- lease->host = (struct host_decl *)0;
+ lease->host = NULL;
}
}
@@ -1656,10 +1554,10 @@ struct lease *find_lease (packet, share, ours)
if (hw_lease) {
if (lease) {
if (packet->packet_type == DHCPREQUEST)
- release_lease (hw_lease);
+ release_lease(hw_lease);
} else {
lease = hw_lease;
- lease->host = (struct host_decl *)0;
+ lease->host = NULL;
}
}
@@ -1682,7 +1580,7 @@ struct lease *find_lease (packet, share, ours)
if (lease && (lease->flags & ABANDONED_LEASE)) {
if (packet->packet_type == DHCPREQUEST) {
warn("Reclaiming REQUESTed abandoned IP address %s.",
- piaddr (lease->ip_addr));
+ piaddr(lease->ip_addr));
lease->flags &= ~ABANDONED_LEASE;
} else
lease = NULL;
@@ -1710,7 +1608,7 @@ mockup_lease(struct packet *packet, struct shared_network *share,
if (hp->group->options[DHO_DHCP_CLIENT_IDENTIFIER]) {
mock.uid = hp->group->options[DHO_DHCP_CLIENT_IDENTIFIER]->value;
- mock.uid_len = hp->group ->options[DHO_DHCP_CLIENT_IDENTIFIER]->len;
+ mock.uid_len = hp->group->options[DHO_DHCP_CLIENT_IDENTIFIER]->len;
} else {
mock.uid = NULL;
mock.uid_len = 0;
diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c
index 6574af82679..ead62341689 100644
--- a/usr.sbin/dhcpd/dhcpd.c
+++ b/usr.sbin/dhcpd/dhcpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.c,v 1.13 2004/04/18 00:30:33 henning Exp $ */
+/* $OpenBSD: dhcpd.c,v 1.14 2004/04/18 00:43:27 deraadt Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org>
@@ -61,15 +61,14 @@ char *path_dhcpd_db = _PATH_DHCPD_DB;
int
main(int argc, char *argv[])
{
- int ch, status;
- int cftest = 0, quiet = 0, daemonize = 1;
+ int ch, status, cftest = 0, quiet = 0, daemonize = 1;
struct servent *ent;
struct passwd *pw;
extern char *__progname;
/* Initially, log errors to stderr as well as to syslogd. */
openlog(__progname, LOG_NDELAY, DHCPD_LOG_FACILITY);
- setlogmask(LOG_UPTO (LOG_INFO));
+ setlogmask(LOG_UPTO(LOG_INFO));
while ((ch = getopt(argc, argv, "c:dfl:p:tq")) != -1)
switch (ch) {
@@ -125,9 +124,9 @@ main(int argc, char *argv[])
/* Default to the DHCP/BOOTP port. */
if (!local_port) {
- ent = getservbyname ("dhcp", "udp");
+ ent = getservbyname("dhcp", "udp");
if (!ent)
- local_port = htons (67);
+ local_port = htons(67);
else
local_port = ent->s_port;
endservent();
@@ -135,7 +134,7 @@ main(int argc, char *argv[])
remote_port = htons(ntohs(local_port) + 1);
time(&cur_time);
- if (!readconf ())
+ if (!readconf())
error("Configuration file errors encountered -- exiting");
if (cftest)
@@ -183,7 +182,7 @@ usage(void)
void
lease_pinged(struct iaddr from, u_int8_t *packet, int length)
{
- struct lease *lp;
+ struct lease *lp;
/*
* Don't try to look up a pinged lease if we aren't trying to
diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h
index 3b614c63ce4..2d98c03cb28 100644
--- a/usr.sbin/dhcpd/dhcpd.h
+++ b/usr.sbin/dhcpd/dhcpd.h
@@ -99,7 +99,7 @@ extern int h_errno;
#include "dhcp.h"
#include "tree.h"
-#define LOCAL_PORT 68
+#define LOCAL_PORT 68
struct iaddr {
int len;
@@ -194,13 +194,13 @@ struct lease {
struct hardware hardware_addr;
int flags;
-# define STATIC_LEASE 1
-# define BOOTP_LEASE 2
-# define DYNAMIC_BOOTP_OK 4
-# define PERSISTENT_FLAGS (DYNAMIC_BOOTP_OK)
-# define EPHEMERAL_FLAGS (BOOTP_LEASE)
-# define MS_NULL_TERMINATION 8
-# define ABANDONED_LEASE 16
+#define STATIC_LEASE 1
+#define BOOTP_LEASE 2
+#define DYNAMIC_BOOTP_OK 4
+#define PERSISTENT_FLAGS (DYNAMIC_BOOTP_OK)
+#define EPHEMERAL_FLAGS (BOOTP_LEASE)
+#define MS_NULL_TERMINATION 8
+#define ABANDONED_LEASE 16
struct lease_state *state;
u_int8_t releasing;
@@ -325,17 +325,17 @@ struct class {
/* DHCP client lease structure... */
struct client_lease {
- struct client_lease *next; /* Next lease in list. */
- time_t expiry, renewal, rebind; /* Lease timeouts. */
- struct iaddr address; /* Address being leased. */
- char *server_name; /* Name of boot server. */
- char *filename; /* Name of file we're supposed to boot. */
- struct string_list *medium; /* Network medium. */
+ struct client_lease *next; /* Next lease in list. */
+ time_t expiry, renewal, rebind; /* Lease timeouts. */
+ struct iaddr address; /* Address being leased. */
+ char *server_name; /* Name of boot server. */
+ char *filename; /* File to boot. */
+ struct string_list *medium; /* Network medium. */
- unsigned int is_static : 1; /* If set, lease is from config file. */
- unsigned int is_bootp: 1; /* If set, lease was aquired with BOOTP. */
+ unsigned int is_static : 1; /* If set, lease is from config file. */
+ unsigned int is_bootp: 1; /* If set, lease was aquired with BOOTP. */
- struct option_data options [256]; /* Options supplied with lease. */
+ struct option_data options [256]; /* Options supplied with lease. */
};
/* Possible states in which the client can be. */
diff --git a/usr.sbin/dhcpd/dispatch.c b/usr.sbin/dhcpd/dispatch.c
index be2af3acaaa..b2bfbac4305 100644
--- a/usr.sbin/dhcpd/dispatch.c
+++ b/usr.sbin/dhcpd/dispatch.c
@@ -106,7 +106,7 @@ discover_interfaces(int state)
if ((ifa->ifa_flags & IFF_LOOPBACK) ||
(ifa->ifa_flags & IFF_POINTOPOINT) ||
(!(ifa->ifa_flags & IFF_UP) &&
- state != DISCOVER_UNCONFIGURED))
+ state != DISCOVER_UNCONFIGURED))
continue;
/* See if we've seen an interface that matches this one. */
@@ -216,7 +216,7 @@ discover_interfaces(int state)
return;
/* Weed out the interfaces that did not have IP addresses. */
- last = (struct interface_info *)0;
+ last = NULL;
for (tmp = interfaces; tmp; tmp = next) {
next = tmp->next;
if ((tmp->flags & INTERFACE_AUTOMATIC) &&
@@ -388,10 +388,10 @@ another:
i = 0;
for (l = protocols; l; l = l->next) {
- struct interface_info *ip = l->local;
+ struct interface_info *ip = l->local;
- if ((fds [i].revents & POLLIN)) {
- fds [i].revents = 0;
+ if ((fds[i].revents & POLLIN)) {
+ fds[i].revents = 0;
if (ip && (l->handler != got_one ||
!ip->dead))
(*(l->handler))(l);
@@ -413,7 +413,7 @@ got_one(struct protocol *l)
struct iaddr ifrom;
size_t result;
union {
- unsigned char packbuf [4095];
+ unsigned char packbuf[4095];
struct dhcp_packet packet;
} u;
struct interface_info *ip = l->local;
@@ -460,8 +460,7 @@ interface_status(struct interface_info *ifinfo)
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m",
- ifname);
+ syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", ifname);
goto inactive;
}
/*
@@ -538,7 +537,7 @@ add_timeout(time_t when, void (*where)(void *), void *what)
struct timeout *t, *q;
/* See if this timeout supersedes an existing timeout. */
- t = (struct timeout *)0;
+ t = NULL;
for (q = timeouts; q; q = q->next) {
if (q->func == where && q->what == what) {
if (t)
@@ -598,7 +597,7 @@ cancel_timeout(void (*where)(void *), void *what)
struct timeout *t, *q;
/* Look for this timeout on the list, and unlink it if we find it. */
- t = (struct timeout *)0;
+ t = NULL;
for (q = timeouts; q; q = q->next) {
if (q->func == where && q->what == what) {
if (t)
diff --git a/usr.sbin/dhcpd/icmp.c b/usr.sbin/dhcpd/icmp.c
index d9bc592a136..d8e09fa312e 100644
--- a/usr.sbin/dhcpd/icmp.c
+++ b/usr.sbin/dhcpd/icmp.c
@@ -1,6 +1,6 @@
/*
* icmp.c
- *
+ *
* ICMP Protocol engine - for sending out pings and receiving responses.
*/
@@ -53,7 +53,7 @@ static int icmp_protocol_fd;
/* Initialize the ICMP protocol. */
void
-icmp_startup(int routep, void (*handler) (struct iaddr, u_int8_t *, int))
+icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int))
{
struct protoent *proto;
int protocol = 1, state;
@@ -76,14 +76,14 @@ icmp_startup(int routep, void (*handler) (struct iaddr, u_int8_t *, int))
/* Make sure it does routing... */
state = 0;
if (setsockopt(icmp_protocol_fd, SOL_SOCKET, SO_DONTROUTE,
- (char *) &state, sizeof state) < 0)
+ (char *)&state, sizeof state) < 0)
error("Unable to disable SO_DONTROUTE on ICMP socket: %m");
add_protocol("icmp", icmp_protocol_fd, icmp_echoreply,
- (void *) handler);
+ (void *)handler);
}
-int
+int
icmp_echorequest(struct iaddr *addr)
{
struct sockaddr_in to;
@@ -110,12 +110,12 @@ icmp_echorequest(struct iaddr *addr)
icmp.icmp_id = (u_int32_t) addr;
#endif
- icmp.icmp_cksum = wrapsum(checksum((unsigned char *) &icmp,
+ icmp.icmp_cksum = wrapsum(checksum((unsigned char *)&icmp,
sizeof icmp, 0));
/* Send the ICMP packet... */
- status = sendto(icmp_protocol_fd, (char *) &icmp, sizeof icmp, 0,
- (struct sockaddr *) & to, sizeof to);
+ status = sendto(icmp_protocol_fd, (char *)&icmp, sizeof icmp, 0,
+ (struct sockaddr *)& to, sizeof to);
if (status < 0)
warn("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr));
@@ -124,7 +124,7 @@ icmp_echorequest(struct iaddr *addr)
return 1;
}
-void
+void
icmp_echoreply(struct protocol *protocol)
{
void (*handler)(struct iaddr, u_int8_t *, int);
@@ -148,7 +148,7 @@ icmp_echoreply(struct protocol *protocol)
return;
len = status - sizeof(struct ip);
- icfrom = (struct icmp *) (icbuf + sizeof(struct ip));
+ icfrom = (struct icmp *)(icbuf + sizeof(struct ip));
/* Silently discard ICMP packets that aren't echoreplies. */
if (icfrom->icmp_type != ICMP_ECHOREPLY)
diff --git a/usr.sbin/dhcpd/memory.c b/usr.sbin/dhcpd/memory.c
index 3d814ef10a1..c94fe845821 100644
--- a/usr.sbin/dhcpd/memory.c
+++ b/usr.sbin/dhcpd/memory.c
@@ -848,7 +848,7 @@ dump_subnets(void)
struct shared_network *s;
struct subnet *n;
- note ("Subnets:");
+ note("Subnets:");
for (n = subnets; n; n = n->next_subnet) {
debug(" Subnet %s", piaddr(n->net));
debug(" netmask %s", piaddr(n->netmask));
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 4d26936c8cc..432da72185c 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.4 2004/04/15 22:22:21 hshoexer Exp $ */
+/* $OpenBSD: parse.c,v 1.5 2004/04/18 00:43:27 deraadt Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -43,7 +43,7 @@
#include "dhcpd.h"
#include "dhctoken.h"
-/*
+/*
* Skip to the semicolon ending the current statement. If we encounter
* braces, the matching closing brace terminates the statement. If we
* encounter a right brace but haven't encountered a left brace, return
@@ -96,8 +96,8 @@ skip_to_semi(FILE *cfile)
int
parse_semi(FILE *cfile)
{
- int token;
- char *val;
+ int token;
+ char *val;
token = next_token(&val, cfile);
if (token != SEMI) {
@@ -114,9 +114,8 @@ parse_semi(FILE *cfile)
char *
parse_string(FILE *cfile)
{
- char *val;
- int token;
- char *s;
+ char *val, *s;
+ int token;
token = next_token(&val, cfile);
if (token != STRING) {
@@ -140,12 +139,9 @@ parse_string(FILE *cfile)
char *
parse_host_name(FILE *cfile)
{
- char *val;
- int token;
- int len = 0;
- char *s;
- char *t;
- pair c = NULL;
+ char *val, *s, *t;
+ int token, len = 0;
+ pair c = NULL;
/* Read a dotted hostname... */
do {
@@ -177,8 +173,9 @@ parse_host_name(FILE *cfile)
t = s + len;
*--t = '\0';
while (c) {
- pair cdr = c->cdr;
- int l = strlen((char *)c->car);
+ pair cdr = c->cdr;
+ int l = strlen((char *)c->car);
+
t -= l;
memcpy(t, (char *)c->car, l);
/* Free up temp space. */
@@ -208,10 +205,9 @@ parse_ip_addr(FILE *cfile, struct iaddr *addr)
void
parse_hardware_param(FILE *cfile, struct hardware *hardware)
{
- char *val;
- int token;
- int hlen;
- unsigned char *t;
+ char *val;
+ int token, hlen;
+ unsigned char *t;
token = next_token(&val, cfile);
switch (token) {
@@ -248,8 +244,7 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
parse_warn("hardware address too long");
} else {
hardware->hlen = hlen;
- memcpy((unsigned char *)&hardware->haddr[0], t,
- hardware->hlen);
+ memcpy((unsigned char *)&hardware->haddr[0], t, hardware->hlen);
if (hlen < sizeof(hardware->haddr))
memset(&hardware->haddr[hlen], 0,
sizeof(hardware->haddr) - hlen);
@@ -269,8 +264,8 @@ parse_hardware_param(FILE *cfile, struct hardware *hardware)
void
parse_lease_time(FILE *cfile, time_t *timep)
{
- char *val;
- int token;
+ char *val;
+ int token;
token = next_token(&val, cfile);
if (token != NUMBER) {
@@ -297,12 +292,10 @@ unsigned char *
parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
int separator, int base, int size)
{
- char *val;
- int token;
- unsigned char *bufp = buf, *s = NULL;
- char *t;
- int count = 0;
- pair c = NULL;
+ char *val, *t;
+ int token, count = 0;
+ unsigned char *bufp = buf, *s = NULL;
+ pair c = NULL;
if (!bufp && *max) {
bufp = malloc(*max * size / 8);
@@ -378,11 +371,9 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max,
void
convert_num(unsigned char *buf, char *str, int base, int size)
{
- char *ptr = str;
- int negative = 0;
- u_int32_t val = 0;
- int tval;
- int max;
+ int negative = 0, tval, max;
+ char *ptr = str;
+ u_int32_t val = 0;
if (*ptr == '-') {
negative = 1;
@@ -443,7 +434,7 @@ convert_num(unsigned char *buf, char *str, int base, int size)
break;
}
}
- if (negative)
+ if (negative) {
switch (size) {
case 8:
*buf = -(unsigned long)val;
@@ -458,7 +449,7 @@ convert_num(unsigned char *buf, char *str, int base, int size)
warn("Unexpected integer size: %d", size);
break;
}
- else
+ } else {
switch (size) {
case 8:
*buf = (u_int8_t)val;
@@ -473,6 +464,7 @@ convert_num(unsigned char *buf, char *str, int base, int size)
warn("Unexpected integer size: %d", size);
break;
}
+ }
}
/*
@@ -486,11 +478,10 @@ convert_num(unsigned char *buf, char *str, int base, int size)
time_t
parse_date(FILE * cfile)
{
- struct tm tm;
- int guess;
- char *val;
- int token;
- static int months[11] = {31, 59, 90, 120, 151, 181,
+ struct tm tm;
+ int guess, token;
+ char *val;
+ static int months[11] = {31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334};
/* Day of week... */
diff --git a/usr.sbin/dhcpd/print.c b/usr.sbin/dhcpd/print.c
index 226a59ac91e..3223a08b2e8 100644
--- a/usr.sbin/dhcpd/print.c
+++ b/usr.sbin/dhcpd/print.c
@@ -1,4 +1,4 @@
-/* $Id: print.c,v 1.4 2004/04/16 04:30:09 deraadt Exp $ */
+/* $Id: print.c,v 1.5 2004/04/18 00:43:27 deraadt Exp $ */
/* Turn data structures into printable text. */
@@ -73,7 +73,7 @@ bad:
}
-void
+void
print_lease(struct lease *lease)
{
struct tm *t;
@@ -99,7 +99,7 @@ print_lease(struct lease *lease)
debug(" host %s ", lease->host ? lease->host->name : "<none>");
}
-void
+void
dump_packet(struct packet *tp)
{
struct dhcp_packet *tdp = tp->raw;
@@ -114,7 +114,7 @@ dump_packet(struct packet *tp)
debug("siaddr = %s", inet_ntoa(tdp->siaddr));
debug("giaddr = %s", inet_ntoa(tdp->giaddr));
debug("chaddr = %02x:%02x:%02x:%02x:%02x:%02x",
- ((unsigned char *)(tdp->chaddr))[0],
+ ((unsigned char *)(tdp->chaddr))[0],
((unsigned char *)(tdp->chaddr))[1],
((unsigned char *)(tdp->chaddr))[2],
((unsigned char *)(tdp->chaddr))[3],
@@ -135,7 +135,7 @@ dump_packet(struct packet *tp)
debug("%s", "");
}
-void
+void
dump_raw(unsigned char *buf, int len)
{
char lbuf[80];
@@ -146,7 +146,7 @@ dump_raw(unsigned char *buf, int len)
for (i = 0; i < len; i++) {
if ((i & 15) == 0) {
if (lbix)
- note(lbuf);
+ note("%s", lbuf);
j = snprintf(lbuf, llen, "%03x:", i);
if (j >= llen)
return;
@@ -162,10 +162,10 @@ dump_raw(unsigned char *buf, int len)
lbix += j;
llen -= j;
}
- note(lbuf);
+ note("%s", lbuf);
}
-void
+void
hash_dump(struct hash_table *table)
{
struct hash_bucket *bp;
@@ -182,7 +182,7 @@ hash_dump(struct hash_table *table)
if (bp->len)
dump_raw(bp->name, bp->len);
else
- note((char *) bp->name);
+ note("%s", (char *)bp->name);
}
}
}
diff --git a/usr.sbin/dhcpd/tables.c b/usr.sbin/dhcpd/tables.c
index eafe86650c3..49e9256b629 100644
--- a/usr.sbin/dhcpd/tables.c
+++ b/usr.sbin/dhcpd/tables.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tables.c,v 1.2 2004/04/14 01:27:49 henning Exp $ */
+/* $OpenBSD: tables.c,v 1.3 2004/04/18 00:43:27 deraadt Exp $ */
/* Tables of information... */
@@ -667,7 +667,6 @@ char *hardware_types[] = {
};
-
struct hash_table universe_hash;
void
diff --git a/usr.sbin/dhcpd/tree.c b/usr.sbin/dhcpd/tree.c
index fe8bce94c86..c6267688dee 100644
--- a/usr.sbin/dhcpd/tree.c
+++ b/usr.sbin/dhcpd/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.6 2004/04/16 04:30:09 deraadt Exp $ */
+/* $Id: tree.c,v 1.7 2004/04/18 00:43:27 deraadt Exp $ */
/* Routines for manipulating parse trees... */
@@ -67,7 +67,7 @@ tree_cache(struct tree *tree)
tc = new_tree_cache("tree_cache");
if (!tc)
return 0;
- tc->value = (unsigned char *)0;
+ tc->value = NULL;
tc->len = tc->buf_size = 0;
tc->timeout = 0;
tc->tree = tree;
@@ -98,7 +98,7 @@ enter_dns_host(char *name)
!(dh->hostname = dmalloc(len, "enter_dns_host")))
error("Can't allocate space for new host.");
strlcpy(dh->hostname, name, len);
- dh->data = (unsigned char *)0;
+ dh->data = NULL;
dh->data_len = 0;
dh->buf_len = 0;
dh->timeout = 0;
@@ -124,7 +124,7 @@ tree_concat(struct tree *left, struct tree *right)
{
struct tree *nt;
- /*
+ /*
* If we're concatenating a null tree to a non-null tree, just
* return the non-null tree; if both trees are null, return
* a null tree.
@@ -177,7 +177,7 @@ tree_limit(struct tree *tree, int limit)
/* Otherwise, put in a node which enforces the limit on evaluation. */
rv = new_tree("tree_limit");
if (!rv)
- return(struct tree *)0;
+ return NULL;
rv->op = TREE_LIMIT;
rv->data.limit.tree = tree;
rv->data.limit.limit = limit;
@@ -191,7 +191,7 @@ tree_evaluate(struct tree_cache *tree_cache)
int bc = tree_cache->buf_size;
int bufix = 0;
- /*
+ /*
* If there's no tree associated with this cache, it evaluates to a
* constant and that was detected at startup.
*/
@@ -219,7 +219,7 @@ tree_evaluate(struct tree_cache *tree_cache)
bc = bufix;
bufix = 0;
- /*
+ /*
* Note that the size of the result shouldn't change on the
* second call to tree_evaluate_recurse, since we haven't
* changed the ``current'' time.
@@ -314,7 +314,7 @@ do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount,
break;
case TRY_AGAIN:
warn("%s: temporary name server failure",
- dns->hostname);
+ dns->hostname);
break;
case NO_RECOVERY:
warn("%s: name server failed", dns->hostname);
@@ -328,8 +328,7 @@ do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount,
}
#ifdef DEBUG_EVAL
- debug("Lookup succeeded; first address is %x",
- h->h_addr_list[0]);
+ debug("Lookup succeeded; first address is %x", h->h_addr_list[0]);
#endif
/* Count the number of addresses we got... */