+ /* FIXME: It may be possible to run off the end of a packet here /if/
+ * it's malformed. :( */
+ while (options[i] != DHCP_END) {
+ __u8 tag = options[i++], len;
+ __u32 value = 0;
+
+ if (tag == DHCP_PAD)
+ continue;
+
+ len = options[i++];
+ /* Clamp the maxium length of the memcpy() to the right size for
+ * value. */
+ if (len > sizeof(value))
+ memcpy(&value, &options[i], sizeof(value));
+ else
+ memcpy(&value, &options[i], len);
+
+#if DEBUG
+{
+ DEBUG_F("tag=%2d, len=%2d, data=", tag, len);
+ int j;
+ for (j=0; j<len; j++)
+ prom_printf("%02x", options[i+j]);
+ prom_printf("\n");
+}
+#endif
+
+ switch (tag) {
+ case DHCP_NETMASK:
+ if ((result->subnetmask == NULL ||
+ *(result->subnetmask) == '\x0') && value != 0) {
+ result->subnetmask = ipv4_to_str(value);
+ DEBUG_F("Storing %s as subnetmask from options\n",
+ result->subnetmask);
+ }
+ break;
+ case DHCP_ROUTERS:
+ if ((result->giaddr == NULL || *(result->giaddr) == '\x0')
+ && value != 0) {
+ result->giaddr = ipv4_to_str(value);
+ DEBUG_F("Storing %s as gateway from options\n",
+ result->giaddr);
+ }
+ break;
+ }
+ i += len;
+ }
+}
+
+/*
+ * Check netinfo for ipv4 parameters and add them to the fspec iff the
+ * fspec has no existing value.
+ */
+static void
+extract_netinfo_args(struct boot_fspec_t *result)
+{
+ struct bootp_packet *packet;
+
+ /* Check to see if we can get the [scyg]iaddr fields from netinfo */
+ packet = prom_get_netinfo();
+ if (!packet)
+ return;
+
+ DEBUG_F("We have a boot packet\n");
+ DEBUG_F(" siaddr = <%x>\n", packet->siaddr);
+ DEBUG_F(" ciaddr = <%x>\n", packet->ciaddr);
+ DEBUG_F(" yiaddr = <%x>\n", packet->yiaddr);
+ DEBUG_F(" giaddr = <%x>\n", packet->giaddr);
+
+ /* Try to fallback to yiaddr if ciaddr is empty. Broken? */
+ if (packet->ciaddr == 0 && packet->yiaddr != 0)
+ packet->ciaddr = packet->yiaddr;
+
+ if ((result->siaddr == NULL || *(result->siaddr) == '\x0')
+ && packet->siaddr != 0)
+ result->siaddr = ipv4_to_str(packet->siaddr);
+ if ((result->ciaddr == NULL || *(result->ciaddr) == '\x0')
+ && packet->ciaddr != 0)
+ result->ciaddr = ipv4_to_str(packet->ciaddr);
+ if ((result->giaddr == NULL || *(result->giaddr) == '\x0')
+ && packet->giaddr != 0)
+ result->giaddr = ipv4_to_str(packet->giaddr);
+
+ extract_vendor_options(packet, result);
+
+ /* FIXME: Yck! if we /still/ do not have a gateway then "cheat" and use
+ * the server. This will be okay if the client and server are on
+ * the same IP network, if not then lets hope the server does ICMP
+ * redirections */
+ if (result->giaddr == NULL) {
+ result->giaddr = ipv4_to_str(packet->siaddr);
+ DEBUG_F("Forcing giaddr to siaddr <%s>\n", result->giaddr);
+ }
+}
+
+/*
+ * Extract all the ipv6 arguments from the bootpath provided and fill result
+ * Syntax: ipv6,[dhcpv6[=diaddr,]]ciaddr=c_iaddr,giaddr=g_iaddr,siaddr=s_iaddr,
+ * filename=file_name,tftp-retries=tftp_retries,blksize=block_size
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+extract_ipv6_args(char *imagepath, struct boot_fspec_t *result)
+{
+ char *str, *tmp;
+ int total_len;
+
+ result->is_ipv6 = 1;
+
+ /* Just allocate the max required size */
+ total_len = strlen(imagepath) + 1;
+ str = malloc(total_len);
+ if (!str)
+ return 0;
+
+ if ((tmp = strstr(imagepath, "dhcpv6=")) != NULL)
+ result->dhcpv6 = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "ciaddr=")) != NULL)
+ result->ciaddr = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "giaddr=")) != NULL)
+ result->giaddr = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "siaddr=")) != NULL)
+ result->siaddr = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "filename=")) != NULL)
+ result->file = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "tftp-retries=")) != NULL)
+ result->tftp_retries = scopy(&str, &tmp);
+
+ if ((tmp = strstr(imagepath, "blksize=")) != NULL)
+ result->blksize = scopy(&str, &tmp);
+
+ return 1;
+}