2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * This file contains public functions for managing DHCP network 2N/A * containers. For the semantics of these functions, please see the 2N/A * Enterprise DHCP Architecture Document. 2N/A * We just created the per-network container; put the 2N/A * header on for future use... 2N/A (
void)
fprintf(
fp,
"#\n# Do NOT edit this file by hand -- use");
2N/A (
void)
fprintf(
fp,
" pntadm(1M) or dhcpmgr(1M) instead\n#\n");
2N/A * Container already exists; sanity check against the 2N/A * header that's on-disk. 2N/A * Internal version lookup routine used by both lookup_dn() and 2N/A * update_dn(); same semantics as lookup_dn() except that the `partial' 2N/A * argument has been generalized into a `flags' field. 2N/A * Page the whole container into memory via mmap() so we can scan it 2N/A * quickly; map it MAP_PRIVATE so that we can change newlines to 2N/A * NULs without changing the actual container itself. 2N/A * NUL-terminate the last byte (which should be a newline) so that 2N/A * we can safely use string functions on the mapped container. 2N/A * If we're searching by client IP address, then build a target 2N/A * string we can use to find it quickly. 2N/A * Bail if we've reached the end of the container. 2N/A * If we're searching by client IP address, locate it 2N/A * quickly using strstr(3C); if we can't find it by this 2N/A * technique then it's not in the container. 2N/A * If we've already found the DN_QCIP record, bail. 2N/A * Find the end of the record and change it a NUL byte so 2N/A * that it is interpreted correctly with field_split() and 2N/A * record_match() below. If we can't find a trailing 2N/A * newline, then it must be the last record (whose newline 2N/A * we already changed to a NUL above). 2N/A * Skip pure comment lines; for now this just skips the 2N/A * header information at the top of the container. 2N/A * Split the buffer up into DNF_FIELDS fields. 2N/A * See if we've got a match, filling in dnf.dnf_rec as 2N/A * we go. If record_match() succeeds, dnf.dnf_rec will 2N/A * be completely filled in. 2N/A * Caller just wants a count of the number of matching 2N/A * records, not the records themselves; continue. 2N/A * Allocate record; if FIND_POSITION flag is set, then 2N/A * we need to allocate an extended (dn_recpos_t) record. 2N/A * Fill in record; do a structure copy from our automatic 2N/A * dn. If FIND_POSITION flag is on, pass back additional 2N/A * position information. 2N/A * Chuck the record on the list; up the counter. 2N/A * Compares the fields in fields[] agains the fields in target `targetp', 2N/A * using `query' to decide what fields to compare. Returns B_TRUE if `dnp' 2N/A * matches `targetp', B_FALSE if not. On success, `dnp' is completely 2N/A * We use dn_cid_len since dnp->dn_cid_len is of type uchar_t but 2N/A * hexascii_to_octet() expects an uint_t * 2N/A for (i = 0; i <
sizeof (
qflags) /
sizeof (
unsigned int); i++) {
2N/A * Internal dhcp_network record update routine, used to factor out the 2N/A * common code between add_dn(), delete_dn(), and modify_dn(). If 2N/A * `origp' is NULL, then act like add_dn(); if `newp' is NULL, then 2N/A * act like delete_dn(); otherwise act like modify_dn(). 2N/A * Open the container to update and a new container file which we 2N/A * will store the updated version of the container in. When the 2N/A * update is done, rename the new file to be the real container. 2N/A * If we're changing the key for this record, make sure the key 2N/A * we're changing to doesn't already exist. 2N/A * If we're adding a new record, make sure the record doesn't 2N/A * If we're deleting or modifying record, make sure the record 2N/A * still exists and that our copy isn't stale. Note that we don't 2N/A * check signatures if we're deleting the record and origp->dn_sig 2N/A * is zero, so that records that weren't looked up can be deleted. 2N/A * Note the offset of the record we're modifying or deleting 2N/A * for use down below. 2N/A * No record to modify or delete, so set `recoff' and 2N/A * `recnext' appropriately. 2N/A * Make a new copy of the container. If we're deleting or 2N/A * modifying a record, don't copy that record to the new container. 2N/A * Note: we close these descriptors before the rename(2) (rather 2N/A * than just having the `out:' label clean them up) to save NFS 2N/A * some work (otherwise, NFS has to save `dnpath' to an alternate 2N/A * name since its vnode would still be active). 2N/A * Compile a regular expression matching "SUNWfilesX_" (where X is 2N/A * a container version number) followed by an IP address (roughly 2N/A * speaking). Note that the $N constructions allow us to get the 2N/A * container version and IP address when calling regex(3C). 2N/A "(([0-9]{1,3}_){3}[0-9]{1,3})$1$", (
char *)0);
2N/A * Given a buffer `path' of `pathlen' bytes, fill it in with a path to the 2N/A * DHCP Network table for IP network `ip' located in directory `dir' with a 2N/A * suffix of `suffix'. 2N/A * Write the dn_rec_t `recp' into the open container `fd' at offset 2N/A * `recoff'. Returns DSVC_* error code. 2N/A * Copy data into a dn_filerec_t, since that's what we can 2N/A * actually put on disk.