Module Name: src
Committed By: roy
Date: Fri Jul 10 12:16:31 UTC 2009
Modified Files:
src/sys/lib/libsa: bootp.c
src/sys/nfs: nfs_bootdhcp.c
Log Message:
Use a function to add extra data to the vendor area so that data added
remains constant for both DISCOVER and REQUEST messages.
To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/lib/libsa/bootp.c
cvs rdiff -u -r1.50 -r1.51 src/sys/nfs/nfs_bootdhcp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/lib/libsa/bootp.c
diff -u src/sys/lib/libsa/bootp.c:1.36 src/sys/lib/libsa/bootp.c:1.37
--- src/sys/lib/libsa/bootp.c:1.36 Fri Jul 10 02:55:42 2009
+++ src/sys/lib/libsa/bootp.c Fri Jul 10 12:16:31 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: bootp.c,v 1.36 2009/07/10 02:55:42 roy Exp $ */
+/* $NetBSD: bootp.c,v 1.37 2009/07/10 12:16:31 roy Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@@ -89,6 +89,33 @@
*/
int bootp_flags;
+static void
+bootp_addvend(u_char *area)
+{
+#ifdef SUPPORT_DHCP
+ char vci[64];
+ int vcilen;
+
+ *area++ = TAG_PARAM_REQ;
+ *area++ = 6;
+ *area++ = TAG_SUBNET_MASK;
+ *area++ = TAG_GATEWAY;
+ *area++ = TAG_HOSTNAME;
+ *area++ = TAG_DOMAINNAME;
+ *area++ = TAG_ROOTPATH;
+ *area++ = TAG_SWAPSERVER;
+
+ /* Insert a NetBSD Vendor Class Identifier option. */
+ sprintf(vci, "NetBSD:%s:libsa", MACHINE);
+ vcilen = strlen(vci);
+ *area++ = TAG_CLASSID;
+ *area++ = vcilen;
+ (void)memcpy(area, vci, vcilen);
+ area += vcilen;
+#endif
+ *area = TAG_END;
+}
+
/* Fetch required bootp information */
void
bootp(int sock)
@@ -103,11 +130,7 @@
u_char header[HEADER_SIZE];
struct bootp rbootp;
} rbuf;
-#ifdef SUPPORT_DHCP
- char vci[64];
- int vcilen;
unsigned int index;
-#endif
#ifdef BOOTP_DEBUG
if (debug)
@@ -135,33 +158,13 @@
MACPY(d->myea, bp->bp_chaddr);
(void)strncpy((char *)bp->bp_file, bootfile, sizeof(bp->bp_file));
(void)memcpy(bp->bp_vend, vm_rfc1048, sizeof(vm_rfc1048));
-#ifdef SUPPORT_DHCP
index = 4;
+#ifdef SUPPORT_DHCP
bp->bp_vend[index++] = TAG_DHCP_MSGTYPE;
bp->bp_vend[index++] = 1;
bp->bp_vend[index++] = DHCPDISCOVER;
- /* Request the parameters we need. */
- bp->bp_vend[index++] = TAG_PARAM_REQ;
- bp->bp_vend[index++] = 6;
- bp->bp_vend[index++] = TAG_SUBNET_MASK;
- bp->bp_vend[index++] = TAG_GATEWAY;
- bp->bp_vend[index++] = TAG_HOSTNAME;
- bp->bp_vend[index++] = TAG_DOMAINNAME;
- bp->bp_vend[index++] = TAG_ROOTPATH;
- bp->bp_vend[index++] = TAG_SWAPSERVER;
- /*
- * Insert a NetBSD Vendor Class Identifier option.
- */
- sprintf(vci, "NetBSD:%s:libsa", MACHINE);
- vcilen = strlen(vci);
- bp->bp_vend[index++] = TAG_CLASSID;
- bp->bp_vend[index++] = vcilen;
- (void)memcpy(&bp->bp_vend[index], vci, vcilen);
- index += vcilen;
- bp->bp_vend[9 + vcilen] = TAG_END;
-#else
- bp->bp_vend[4] = TAG_END;
#endif
+ bootp_addvend(&bp->bp_vend[index]);
d->myip.s_addr = INADDR_ANY;
d->myport = htons(IPPORT_BOOTPC);
@@ -199,25 +202,7 @@
leasetime = htonl(300);
(void)memcpy(&bp->bp_vend[index], &leasetime, 4);
index += 4;
- /* Request the parameters we need. */
- bp->bp_vend[index++] = TAG_PARAM_REQ;
- bp->bp_vend[index++] = 6;
- bp->bp_vend[index++] = TAG_SUBNET_MASK;
- bp->bp_vend[index++] = TAG_GATEWAY;
- bp->bp_vend[index++] = TAG_HOSTNAME;
- bp->bp_vend[index++] = TAG_DOMAINNAME;
- bp->bp_vend[index++] = TAG_ROOTPATH;
- bp->bp_vend[index++] = TAG_SWAPSERVER;
- /*
- * Insert a NetBSD Vendor Class Identifier option.
- */
- sprintf(vci, "NetBSD:%s:libsa", MACHINE);
- vcilen = strlen(vci);
- bp->bp_vend[index++] = TAG_CLASSID;
- bp->bp_vend[index++] = vcilen;
- (void)memcpy(&bp->bp_vend[index], vci, vcilen);
- index += vcilen;
- bp->bp_vend[index] = TAG_END;
+ bootp_addvend(&bp->bp_vend[index]);
expected_dhcpmsgtype = DHCPACK;
Index: src/sys/nfs/nfs_bootdhcp.c
diff -u src/sys/nfs/nfs_bootdhcp.c:1.50 src/sys/nfs/nfs_bootdhcp.c:1.51
--- src/sys/nfs/nfs_bootdhcp.c:1.50 Fri Jul 10 02:41:39 2009
+++ src/sys/nfs/nfs_bootdhcp.c Fri Jul 10 12:16:31 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_bootdhcp.c,v 1.50 2009/07/10 02:41:39 roy Exp $ */
+/* $NetBSD: nfs_bootdhcp.c,v 1.51 2009/07/10 12:16:31 roy Exp $ */
/*-
* Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.50 2009/07/10 02:41:39 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_bootdhcp.c,v 1.51 2009/07/10 12:16:31 roy Exp $");
#ifdef _KERNEL_OPT
#include "opt_nfs_boot.h"
@@ -445,6 +445,34 @@
return (-1);
}
+static void
+bootp_addvend(u_char *area)
+{
+#ifdef NFS_BOOT_DHCP
+ char vci[64];
+ int vcilen;
+
+ *area++ = TAG_PARAM_REQ;
+ *area++ = 6;
+ *area++ = TAG_SUBNET_MASK;
+ *area++ = TAG_GATEWAY;
+ *area++ = TAG_HOST_NAME;
+ *area++ = TAG_DOMAIN_NAME;
+ *area++ = TAG_ROOT_PATH;
+ *area++ = TAG_SWAP_SERVER;
+
+ /* Insert a NetBSD Vendor Class Identifier option. */
+ snprintf(vci, sizeof(vci), "%s:%s:kernel:%s", ostype, MACHINE,
+ osrelease);
+ vcilen = strlen(vci);
+ *area++ = TAG_CLASSID;
+ *area++ = vcilen;
+ (void)memcpy(area, vci, vcilen);
+ area += vcilen;
+#endif
+ *area = TAG_END;
+}
+
static int
bootpc_call(struct nfs_diskless *nd, struct lwp *lwp, int *flags)
{
@@ -458,11 +486,7 @@
const u_char *haddr;
u_char hafmt, halen;
struct bootpcontext bpc;
-#ifdef NFS_BOOT_DHCP
- char vci[64];
- int vcilen;
unsigned int index;
-#endif
error = socreate(AF_INET, &so, SOCK_DGRAM, 0, lwp, NULL);
if (error) {
@@ -586,34 +610,13 @@
#endif
/* Fill-in the vendor data. */
memcpy(bootp->bp_vend, vm_rfc1048, 4);
-#ifdef NFS_BOOT_DHCP
index = 4;
+#ifdef NFS_BOOT_DHCP
bootp->bp_vend[index++] = TAG_DHCP_MSGTYPE;
bootp->bp_vend[index++] = 1;
bootp->bp_vend[index++] = DHCPDISCOVER;
- /* Request the paramters we need. */
- bootp->bp_vend[index++] = TAG_PARAM_REQ;
- bootp->bp_vend[index++] = 6;
- bootp->bp_vend[index++] = TAG_SUBNET_MASK;
- bootp->bp_vend[index++] = TAG_GATEWAY;
- bootp->bp_vend[index++] = TAG_HOST_NAME;
- bootp->bp_vend[index++] = TAG_DOMAIN_NAME;
- bootp->bp_vend[index++] = TAG_ROOT_PATH;
- bootp->bp_vend[index++] = TAG_SWAP_SERVER;
- /*
- * Insert a NetBSD Vendor Class Identifier option.
- */
- snprintf(vci, sizeof(vci), "%s:%s:kernel:%s", ostype, MACHINE,
- osrelease);
- vcilen = strlen(vci);
- bootp->bp_vend[index++] = TAG_CLASSID;
- bootp->bp_vend[index++] = vcilen;
- memcpy(&bootp->bp_vend[index], vci, vcilen);
- index += vcilen;
- bootp->bp_vend[index] = TAG_END;
-#else
- bootp->bp_vend[index] = TAG_END;
#endif
+ bootp_addvend(&bootp->bp_vend[index]);
bpc.xid = xid;
bpc.haddr = haddr;
@@ -649,23 +652,7 @@
leasetime = htonl(300);
memcpy(&bootp->bp_vend[index], &leasetime, 4);
index += 4;
- /* Request the paramters we need. */
- bootp->bp_vend[index++] = TAG_PARAM_REQ;
- bootp->bp_vend[index++] = 6;
- bootp->bp_vend[index++] = TAG_SUBNET_MASK;
- bootp->bp_vend[index++] = TAG_GATEWAY;
- bootp->bp_vend[index++] = TAG_HOST_NAME;
- bootp->bp_vend[index++] = TAG_DOMAIN_NAME;
- bootp->bp_vend[index++] = TAG_ROOT_PATH;
- bootp->bp_vend[index++] = TAG_SWAP_SERVER;
- /*
- * Insert a NetBSD Vendor Class Identifier option.
- */
- bootp->bp_vend[index++] = TAG_CLASSID;
- bootp->bp_vend[index++] = vcilen;
- memcpy(&bootp->bp_vend[index], vci, vcilen);
- index += vcilen;
- bootp->bp_vend[index] = TAG_END;
+ bootp_addvend(&bootp->bp_vend[index]);
bpc.expected_dhcpmsgtype = DHCPACK;