da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER START
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner * The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Common Development and Distribution License (the "License").
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You may not use this file except in compliance with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * When distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If applicable, add the following below this CDDL HEADER, with the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * fields enclosed by brackets "[]" replaced with your own identifying
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * information: Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Use is subject to license terms.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * ADOPTING state of the client state machine. This is used only during
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * diskless boot with IPv4.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic boolean_t get_prom_prop(const char *, const char *, uchar_t **,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * dhcp_adopt(): adopts the interface managed by the kernel for diskless boot
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * input: void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * output: boolean_t: B_TRUE success, B_FALSE on failure
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (retval == 0 || kcache_size < sizeof (dhcp_kcache_t)) {
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dhcpmsg(MSG_CRIT, "dhcp_adopt: cannot fetch kernel cache");
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dhcpmsg(MSG_DEBUG, "dhcp_adopt: fetched %s kcache", kcache->dk_if_name);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * convert the kernel's ACK into binary
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin plp = alloc_pkt_entry(strlen(kcache->dk_ack) / 2, B_FALSE);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "dhcp_adopt: allocated ACK of %d bytes", plp->len);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (hexascii_to_octet(kcache->dk_ack, plp->len * 2, plp->pkt,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_CRIT, "dhcp_adopt: cannot convert kernel ACK");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_CRIT, "dhcp_adopt: cannot parse kernel ACK");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * make an interface to represent the "cached interface" in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the kernel, hook up the ACK packet we made, and send out
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the extend request (to attempt to renew the lease).
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * we do a send_extend() instead of doing a dhcp_init_reboot()
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * because although dhcp_init_reboot() is more correct from a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * protocol perspective, it introduces a window where a
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * diskless client has no IP address but may need to page in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * more of this program. we could mlockall(), but that's
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * going to be a mess, especially with handling malloc() and
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * stack growth, so it's easier to just renew(). the only
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * catch here is that if we are not granted a renewal, we're
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * totally hosed and can only bail out.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((lif = attach_lif(kcache->dk_if_name, B_FALSE, &retval)) == NULL) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_ERROR, "dhcp_adopt: unable to attach %s: %d",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_ERROR, "dhcp_adopt: unable to create state "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If the agent is adopting a lease, then OBP is initially
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * searched for a client-id.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "dhcp_adopt: getting /chosen:clientid property");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!get_prom_prop("chosen", "client-id", &dsmp->dsm_cid,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * a failure occurred trying to acquire the client-id
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "dhcp_adopt: cannot allocate client id for %s",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } else if (dsmp->dsm_hwtype == ARPHRD_IB && dsmp->dsm_cid == NULL) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * when the interface is infiniband and the agent
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * is adopting the lease there must be an OBP
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * client-id.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "dhcp_adopt: no /chosen:clientid id for %s",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * move to BOUND and use the information in our ACK packet.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * adoption will continue after DAD via dhcp_adopt_complete.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_CRIT, "dhcp_adopt: cannot use cached packet");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* Note: no need to free lif; dsmp holds reference */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * dhcp_adopt_complete(): completes interface adoption process after kernel
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * duplicate address detection (DAD) is done.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * input: dhcp_smach_t *: the state machine on which a lease is being adopted
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * output: none
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "dhcp_adopt_complete: completing adoption");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_CRIT, "dhcp_adopt_complete: async_start failed");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "dhcp_adopt_complete: cannot send renew request");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "adoption complete, signalling parent (%ld)"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * get_dhcp_kcache(): fetches the DHCP ACK and interface name from the kernel
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * input: dhcp_kcache_t **: a dynamically-allocated cache packet
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * size_t *: the length of that packet (on return)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * output: int: nonzero on success, zero on failure
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinget_dhcp_kcache(dhcp_kcache_t **kernel_cachep, size_t *kcache_size)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (void) sysinfo(SI_DHCP_CACHE, (caddr_t)*kernel_cachep, size);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * get_prom_prop(): get the value of the named property on the named node in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * devinfo root.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * input: const char *: The name of the node containing the property.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * const char *: The name of the property.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * uchar_t **: The property value, modified iff B_TRUE is returned.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If no value is found the value is set to NULL.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * uint_t *: The length of the property value
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * output: boolean_t: Returns B_TRUE if successful (no problems),
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * otherwise B_FALSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * note: The memory allocated by this function must be freed by
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the caller. This code is derived from
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinget_prom_prop(const char *nodename, const char *propname, uchar_t **propvaluep,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * locate root node
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL ||
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_DEBUG, "get_prom_prop: property root node "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "not found");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * locate nodename within '/'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * scan all properties of /nodename for the 'propname' property
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (pp = di_prom_prop_next(phdl, node, DI_PROM_PROP_NIL);
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin dhcpmsg(MSG_DEBUG, "get_prom_prop: property not found");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * get the property; allocate some memory copy it out
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * property data read problems
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin dhcpmsg(MSG_ERR, "get_prom_prop: cannot read property data");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * allocate somewhere to copy the property value to
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * allocation problems
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "memory for property value");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * copy data out
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * copy out the length if a suitable pointer has
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * been supplied