From: Damien Neil Date: Fri, 20 Oct 2000 01:01:41 +0000 (+0000) Subject: Fixed OMAPI lookups based on hardware-address. The hardware type X-Git-Tag: V3-BETA-1-PATCH-11~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e3e0f9214954f2f96e41906b2d55c1e01835bb3;p=thirdparty%2Fdhcp.git Fixed OMAPI lookups based on hardware-address. The hardware type is now specified via the hardware-type field. --- diff --git a/server/omapi.c b/server/omapi.c index 497c08af5..557f97ad8 100644 --- a/server/omapi.c +++ b/server/omapi.c @@ -50,7 +50,7 @@ #ifndef lint static char copyright[] = -"$Id: omapi.c,v 1.39 2000/10/10 19:14:37 mellon Exp $ Copyright (c) 1999-2000 The Internet Software Consortium. All rights reserved.\n"; +"$Id: omapi.c,v 1.40 2000/10/20 01:01:41 neild Exp $ Copyright (c) 1999-2000 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -1204,11 +1204,53 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp, /* Now look for a hardware address. */ status = omapi_get_value_str (ref, id, "hardware-address", &tv); if (status == ISC_R_SUCCESS) { - host = (struct host_decl *)0; - host_hash_lookup (&host, host_hw_addr_hash, - tv -> value -> u.buffer.value, - tv -> value -> u.buffer.len, MDL); + unsigned char *haddr; + unsigned int len; + + len = tv -> value -> u.buffer.len + 1; + haddr = dmalloc (len, MDL); + if (!haddr) { + omapi_value_dereference (&tv, MDL); + return ISC_R_NOMEMORY; + } + + memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1); omapi_value_dereference (&tv, MDL); + + status = omapi_get_value_str (ref, id, "hardware-type", &tv); + if (status == ISC_R_SUCCESS) { + if (tv -> value -> type == omapi_datatype_data) { + if ((tv -> value -> u.buffer.len != 4) || + (tv -> value -> u.buffer.value[0] != 0) || + (tv -> value -> u.buffer.value[1] != 0) || + (tv -> value -> u.buffer.value[2] != 0)) { + omapi_value_dereference (&tv, MDL); + dfree (haddr, MDL); + return ISC_R_INVALIDARG; + } + + haddr[0] = tv -> value -> u.buffer.value[3]; + } else if (tv -> value -> type == omapi_datatype_int) { + haddr[0] = (unsigned char) + tv -> value -> u.integer; + } else { + omapi_value_dereference (&tv, MDL); + dfree (haddr, MDL); + return ISC_R_INVALIDARG; + } + + omapi_value_dereference (&tv, MDL); + } else { + /* If no hardware-type is specified, default to + ethernet. This may or may not be a good idea, + but Telus is currently relying on this behavior. + - DPN */ + haddr[0] = HTYPE_ETHER; + } + + host = (struct host_decl *)0; + host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL); + dfree (haddr, MDL); if (*lp && *lp != (omapi_object_t *)host) { omapi_object_dereference (lp, MDL);