Port-sparc64 archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[PATCH] ofwboot bootp/bootparams mixup
Hi List
I've been netbooting my Sparc64 U60 for some time now, and I need to run
the attached patches.
The first part clears the retrieved data when it changes from bootp ->
bootparams -> bootp. If we don't do this then ofwboot crashes with
incomplete data.
The second part isn't technically required, but it does ensure that we
have enough space reserved for the DHCP information sent to avoid
potential overflows.
OK to commit?
Thanks
Roy
Index: sys/arch/sparc/stand/ofwboot/net.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/stand/ofwboot/net.c,v
retrieving revision 1.4
diff -u -p -r1.4 net.c
--- sys/arch/sparc/stand/ofwboot/net.c 12 May 2008 11:16:31 -0000 1.4
+++ sys/arch/sparc/stand/ofwboot/net.c 4 May 2009 10:05:51 -0000
@@ -116,24 +116,31 @@ net_close(struct of_dev *op)
}
}
+static void
+net_clear_params(void)
+{
+
+ myip.s_addr = 0;
+ netmask = 0;
+ gateip.s_addr = 0;
+ *hostname = '\0';
+ rootip.s_addr = 0;
+ *rootpath = '\0';
+}
+
int
net_mountroot_bootparams(void)
{
+ net_clear_params();
+
/* Get our IP address. (rarp.c) */
if (rarp_getipaddress(netdev_sock) == -1)
return (errno);
-
- printf("Using BOOTPARAMS protocol: ");
- printf("ip address: %s", inet_ntoa(myip));
-
- /* Get our hostname, server IP address. */
+ printf("Using BOOTPARAMS protocol:\n ip addr=%s\n", inet_ntoa(myip));
if (bp_whoami(netdev_sock))
return (errno);
-
- printf(", hostname: %s\n", hostname);
-
- /* Get the root pathname. */
+ printf(" hostname=%s\n", hostname);
if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
return (errno);
@@ -143,22 +150,27 @@ net_mountroot_bootparams(void)
int
net_mountroot_bootp(void)
{
+ int attempts;
- bootp(netdev_sock);
-
+ /* We need a few attempts here as some DHCP servers
+ * require >1 packet and my wireless bridge is always
+ * in learning mode until the 2nd attempt ... */
+ for (attempts = 0; attempts < 3; attempts++) {
+ net_clear_params();
+ bootp(netdev_sock);
+ if (myip.s_addr != 0)
+ break;
+ }
if (myip.s_addr == 0)
return(ENOENT);
- printf("Using BOOTP protocol: ");
- printf("ip address: %s", inet_ntoa(myip));
-
+ printf("Using BOOTP protocol:\n ip addr=%s\n", inet_ntoa(myip));
if (hostname[0])
- printf(", hostname: %s", hostname);
+ printf(" hostname=%s\n", hostname);
if (netmask)
- printf(", netmask: %s", intoa(netmask));
+ printf(" netmask=%s\n", intoa(netmask));
if (gateip.s_addr)
- printf(", gateway: %s", inet_ntoa(gateip));
- printf("\n");
+ printf(" gateway=%s\n", inet_ntoa(gateip));
return (0);
}
@@ -167,22 +179,10 @@ int
net_tftp_bootp(int **sock)
{
- bootp(netdev_sock);
-
+ net_mountroot_bootp();
if (myip.s_addr == 0)
return(ENOENT);
- printf("Using BOOTP protocol: ");
- printf("ip address: %s", inet_ntoa(myip));
-
- if (hostname[0])
- printf(", hostname: %s", hostname);
- if (netmask)
- printf(", netmask: %s", intoa(netmask));
- if (gateip.s_addr)
- printf(", gateway: %s", inet_ntoa(gateip));
- printf("\n");
-
*sock = &netdev_sock;
return (0);
}
@@ -211,7 +211,7 @@ net_mountroot(void)
if (error != 0)
return (error);
- printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
+ printf(" root addr=%s\n path=%s\n", inet_ntoa(rootip), rootpath);
/* Get the NFS file handle (mount). */
if (nfs_mount(netdev_sock, rootip, rootpath) != 0)
Index: sys/arch/sparc/stand/ofwboot/version
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/stand/ofwboot/version,v
retrieving revision 1.16
diff -u -p -r1.16 version
--- sys/arch/sparc/stand/ofwboot/version 25 Aug 2008 22:31:12 -0000
1.16
+++ sys/arch/sparc/stand/ofwboot/version 4 May 2009 10:05:51 -0000
@@ -17,3 +17,4 @@ is taken as the current.
1.11: Improve partition handling and allow changing the device at the boot
prompt
1.12: Add support to boot from newer Solaris UFS partitions
1.13: Deal with kernels missing a separate read-only text segment
+1.14: Make 3 attempts at BOOTP/DHCP for to allow for bridges and clear prior
data read
Index: sys/lib/libsa/bootp.c
===================================================================
RCS file: /cvsroot/src/sys/lib/libsa/bootp.c,v
retrieving revision 1.34
diff -u -p -r1.34 bootp.c
--- sys/lib/libsa/bootp.c 17 Jan 2009 14:00:36 -0000 1.34
+++ sys/lib/libsa/bootp.c 4 May 2009 10:06:03 -0000
@@ -372,21 +372,21 @@ vend_rfc1048(u_char *cp, u_int len)
if (tag == TAG_END)
break;
- if (tag == TAG_SUBNET_MASK) {
+ if (tag == TAG_SUBNET_MASK && size >= sizeof(smask)) {
(void)memcpy(&smask, cp, sizeof(smask));
}
- if (tag == TAG_GATEWAY) {
+ if (tag == TAG_GATEWAY && size >= sizeof(gateip.s_addr)) {
(void)memcpy(&gateip.s_addr, cp, sizeof(gateip.s_addr));
}
- if (tag == TAG_SWAPSERVER) {
+ if (tag == TAG_SWAPSERVER && size >= sizeof(rootip.s_addr)) {
/* let it override bp_siaddr */
(void)memcpy(&rootip.s_addr, cp, sizeof(rootip.s_addr));
}
- if (tag == TAG_ROOTPATH) {
+ if (tag == TAG_ROOTPATH && size <= sizeof(rootpath)) {
strncpy(rootpath, (char *)cp, sizeof(rootpath));
rootpath[size] = '\0';
}
- if (tag == TAG_HOSTNAME) {
+ if (tag == TAG_HOSTNAME && size <= sizeof(hostname)) {
strncpy(hostname, (char *)cp, sizeof(hostname));
hostname[size] = '\0';
}
@@ -396,7 +396,9 @@ vend_rfc1048(u_char *cp, u_int len)
return -1;
dhcp_ok = 1;
}
- if (tag == TAG_SERVERID) {
+ if (tag == TAG_SERVERID &&
+ size >= sizeof(dhcp_serverip.s_addr))
+ {
(void)memcpy(&dhcp_serverip.s_addr, cp,
sizeof(dhcp_serverip.s_addr));
}
Home |
Main Index |
Thread Index |
Old Index