Solaris DHCP Service Developer's Guide

Description

Searches the dhcptab container for instances that match the query described by the combination of query and targetp. If the partial argument is B_TRUE, then partial query results are acceptable to the caller. Thus, when partial is B_TRUE, any query that returns at least one matching record is considered successful. When partial is B_FALSE, the query returns DSVC_SUCCESS only if it has been applied to the entire container.

The query argument consists of 2 fields, each 16 bits long. The lower 16 bits select which fields {key, type} of targetp are to be considered in the query. The upper 16 bits identify whether a particular field value selected in the lower 16 bits must match (bit set) or not match (bit clear). Bits 2 through 15 in both 16-bit fields are currently unused, and must be set to 0. Useful macros for constructing queries can be found in Example 3–1.

The count field specifies the maximum number of matching records to return. A count value of -1 requests the return of all records that match, regardless of the number. A count value of 0 causes lookup_dt to return immediately with no data.

resultp is set to point to the returned list of records. If resultp is NULL, then the caller is simply interested in knowing how many records match the query. Note that these records are dynamically allocated, and therefore the caller is responsible for freeing them. lookup_dt() returns the number of matching records in the records argument. A records value of 0 means that no records matched the query.

The following example includes macros you might find useful for constructing and manipulating lookup queries for the DHCP network and dhcptab containers.


Example 3–1 Useful Macros for Lookup Queries

/*
* Query macros - used for initializing query fields (lookup_d?)
*/
/* dhcp network container */
#define DN_QCID 0x0001
#define DN_QCIP 0x0002
#define DN_QSIP 0x0004
#define DN_QLEASE 0x0008
#define DN_QMACRO 0x0010
#define DN_QFDYNAMIC 0x0020
#define DN_QFAUTOMATIC 0x0040
#define DN_QFMANUAL 0x0080
#define DN_QFUNUSABLE 0x0100
#define DN_QFBOOTP_ONLY 0x0200
#define DN_QALL (DN_QCID | DN_QCIP | DN_QSIP | DN_QLEASE | \
DN_QMACRO | DN_QFDYNAMIC DN_QFAUTOMATIC |\
DN_QFMANUAL | DN_QFUNUSABLE | \
DN_QFBOOTP_ONLY)

/* dhcptab */
#define DT_DHCPTAB "dhcptab"  /* default name of container */
#define DT_QKEY 0x01
#define DT_QTYPE 0x02
#define DT_QALL (DT_QKEY | DT_QTYPE)

/* general query macros */
#define DSVC_QINIT(q) ((q) = 0)
#define DSVC_QEQ(q, v) ((q) = ((q) | (v) | ((v) << 16)))
#define DSVC_QNEQ(q, v) ((q) = ((~(v << 16)) & (q)) | (v)))
#define DSVC_QISEQ(q, v) (((q) & (v)) && ((q) & ((v) << 16)))
#define DSVC_QISNEQ(q, v) (((q) & (v)) && (!((q) & ((v) << 16))))

/* Examples */
uint_t query;
/* search for dhcptab record with key value, but not flags value */
DSVC_QINIT(query);
DSVC_QEQ(query, DT_QKEY);
DSVC_QNEQ(query, DT_QTYPE);
/* search for dhcp network record that matches cid, client ip, server ip.
*/
DSVC_QINIT(query);
DSVC_QEQ(query, (DN_QCID | DN_QCIP | DN_QSIP));