Date: Fri, 19 Oct 2007 13:38:03 GMT From: Alexey Tarasov <taleks@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 127775 for review Message-ID: <200710191338.l9JDc3M0039052@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=127775 Change 127775 by taleks@taleks_th on 2007/10/19 13:37:43 updated modified sources to FreeBSD7-CURRENT. removed unused code, related to 'pxe sock tcptest' command. Affected files ... .. //depot/projects/soc2007/taleks-pxe_http/i386_mod/Makefile#2 edit .. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/Makefile#2 edit .. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#6 edit .. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.h#2 edit .. //depot/projects/soc2007/taleks-pxe_http/libstand_mod/printf.c#2 edit .. //depot/projects/soc2007/taleks-pxe_http/libstand_mod/stand.h#2 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/Makefile#4 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/conf.c#3 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/main.c#4 edit Differences ... ==== //depot/projects/soc2007/taleks-pxe_http/i386_mod/Makefile#2 (text+ko) ==== @@ -1,6 +1,7 @@ -# $FreeBSD: src/sys/boot/i386/Makefile,v 1.20 2003/12/08 19:02:06 obrien Exp $ +# $FreeBSD: src/sys/boot/i386/Makefile,v 1.21 2007/05/29 14:35:57 simokawa Exp $ -SUBDIR= mbr boot0 boot0sio btx boot2 cdboot kgzldr pxe_http libi386 loader +SUBDIR= mbr boot0 boot0sio btx boot2 cdboot kgzldr libi386 libfirewire \ + pxe_http loader # special boot programs, 'self-extracting boot2+loader' SUBDIR+= pxeldr ==== //depot/projects/soc2007/taleks-pxe_http/libi386_mod/Makefile#2 (text+ko) ==== @@ -1,4 +1,4 @@ -# $FreeBSD: src/sys/boot/i386/libi386/Makefile,v 1.37 2004/10/24 15:32:49 ru Exp $ +# $FreeBSD: src/sys/boot/i386/libi386/Makefile,v 1.43 2007/10/12 17:09:43 ps Exp $ # LIB= i386 INTERNALLIB= @@ -6,9 +6,16 @@ SRCS= biosacpi.c bioscd.c biosdisk.c biosmem.c biospnp.c \ biospci.c biossmap.c bootinfo.c bootinfo32.c bootinfo64.c \ comconsole.c devicename.c elf32_freebsd.c \ - elf64_freebsd.c gatea20.c \ - i386_copy.c i386_module.c nullconsole.c pxe.c \ - time.c vidconsole.c amd64_tramp.S + elf64_freebsd.c \ + i386_copy.c i386_module.c nullconsole.c pxe.c pxetramp.s \ + smbios.c time.c vidconsole.c amd64_tramp.S + +# Enable PXE TFTP or NFS support, not both. +.if defined(LOADER_TFTP_SUPPORT) +CFLAGS+= -DLOADER_TFTP_SUPPORT +.else +CFLAGS+= -DLOADER_NFS_SUPPORT +.endif BOOT_COMCONSOLE_PORT?= 0x3f8 CFLAGS+= -DCOMPORT=${BOOT_COMCONSOLE_PORT} @@ -21,13 +28,23 @@ CFLAGS+= -DDISK_DEBUG .endif +.if !defined(BOOT_HIDE_SERIAL_NUMBERS) +# Export serial numbers, UUID, and asset tag from loader. +CFLAGS+= -DSMBIOS_SERIAL_NUMBERS +.endif + # Include simple terminal emulation (cons25-compatible) CFLAGS+= -DTERM_EMU + +# Enable PXE debugging CDLAGS+= -DPXE_DEBUG -# allow pxe_http perform udpread/udpwrite +# Allow pxe_http perform udpread/udpwrite CFLAGS+= -DPXEHTTP_UDP_FOR_LIBSTAND +# XXX: make alloca() useable +CFLAGS+= -Dalloca=__builtin_alloca + CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../btx/lib \ -I${.CURDIR}/../../../contrib/dev/acpica \ -I${.CURDIR}/../../.. -I. -I${.CURDIR}/../pxe_http/ ==== //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#6 (text+ko) ==== @@ -27,8 +27,9 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/boot/i386/libi386/pxe.c,v 1.22 2005/04/17 21:38:22 wollman Exp $"); +__FBSDID("$FreeBSD: src/sys/boot/i386/libi386/pxe.c,v 1.23 2007/10/12 17:09:43 ps Exp $"); +/* #include <stand.h> #include <string.h> #include <stdarg.h> @@ -73,10 +74,11 @@ static int pxe_init(void); static int pxe_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); - + static int pxe_open(struct open_file *f, ...); static int pxe_close(struct open_file *f); static void pxe_cleanup(void); +static void pxe_setnfshandle(char *rootpath); static void pxe_print(int verbose); static int pxe_netif_match(struct netif *nif, void *machdep_hint); @@ -239,6 +241,10 @@ if (pxe_opens > 0) return (0); +#ifdef LOADER_NFS_SUPPORT + /* get an NFS filehandle for our root filesystem */ + pxe_setnfshandle(rootpath); +#endif if (pxe_sock >= 0) { #ifdef PXE_DEBUG printf("pxe_close: calling netif_close()\n"); ==== //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.h#2 (text+ko) ==== ==== //depot/projects/soc2007/taleks-pxe_http/libstand_mod/printf.c#2 (text+ko) ==== @@ -15,10 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -39,7 +35,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/lib/libstand/printf.c,v 1.8 2003/04/06 05:25:48 peter Exp $"); +__FBSDID("$FreeBSD: src/lib/libstand/printf.c,v 1.10 2007/01/09 01:02:04 imp Exp $"); /* * Standaloneified version of the FreeBSD kernel printf family. @@ -60,8 +56,8 @@ #define MAXNBUF (sizeof(intmax_t) * CHAR_BIT + 1) -static char *ksprintn (char *buf, uintmax_t num, int base, int *len); -static int kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, size_t size, va_list ap); +static char *ksprintn (char *buf, uintmax_t num, int base, int *len, int upper); +static int kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, size_t size, va_list ap); int printf(const char *fmt, ...) @@ -98,25 +94,26 @@ int snprintf(char *buf, size_t size, const char *cfmt, ...) { - int retval; - va_list ap; - size_t maxsize = (size > 1) ? size - 1 : 0; - - if (maxsize == 0) { - buf[0] = '\0'; - return (0); - } + int retval; + va_list ap; + size_t maxsize = (size > 1) ? size - 1 : 0; + + if (maxsize == 0) { + buf[0] = '\0'; + return (0); + } - va_start(ap, cfmt); - retval = kvprintf(cfmt, NULL, (void *)buf, 10, maxsize, ap); + va_start(ap, cfmt); + retval = kvprintf(cfmt, NULL, (void *)buf, 10, maxsize, ap); - if (retval < maxsize) - buf[retval] = '\0'; - else - buf[maxsize] = '\0'; + if (retval < maxsize) + buf[retval] = '\0'; + else + buf[maxsize] = '\0'; va_end(ap); - return retval; + + return (retval); } void @@ -135,14 +132,15 @@ * The buffer pointed to by `nbuf' must have length >= MAXNBUF. */ static char * -ksprintn(char *nbuf, uintmax_t num, int base, int *lenp) +ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) { - char *p; + char *p, c; p = nbuf; *p = '\0'; do { - *++p = hex2ascii(num % base); + c = hex2ascii(num % base); + *++p = upper ? toupper(c) : c; } while (num /= base); if (lenp) *lenp = p - nbuf; @@ -179,7 +177,7 @@ kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, size_t maxsize, va_list ap) { #define PCHAR(c) { int cc=(c); if (func) (*func)(cc); else *d++ = cc; retval++; \ - if (maxsize && (retval == maxsize)) return (retval); \ + if (maxsize && (retval == maxsize)) return (retval); \ } char nbuf[MAXNBUF]; char *d; @@ -189,7 +187,7 @@ uintmax_t num; int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot; int jflag, tflag, zflag; - int dwidth; + int dwidth, upper; char padc; int retval = 0; @@ -215,7 +213,7 @@ } percent = fmt - 1; qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; - sign = 0; dot = 0; dwidth = 0; + sign = 0; dot = 0; dwidth = 0; upper = 0; jflag = 0; tflag = 0; zflag = 0; reswitch: switch (ch = (u_char)*fmt++) { case '.': @@ -265,7 +263,7 @@ case 'b': num = va_arg(ap, int); p = va_arg(ap, char *); - for (q = ksprintn(nbuf, num, *p++, NULL); *q;) + for (q = ksprintn(nbuf, num, *p++, NULL, 0); *q;) PCHAR(*q--); if (num == 0) @@ -373,8 +371,9 @@ case 'u': base = 10; goto handle_nosign; + case 'X': + upper = 1; case 'x': - case 'X': base = 16; goto handle_nosign; case 'y': @@ -417,7 +416,7 @@ neg = 1; num = -(intmax_t)num; } - p = ksprintn(nbuf, num, base, &tmp); + p = ksprintn(nbuf, num, base, &tmp, upper); if (sharpflag && num != 0) { if (base == 8) tmp++; ==== //depot/projects/soc2007/taleks-pxe_http/libstand_mod/stand.h#2 (text+ko) ==== @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libstand/stand.h,v 1.41 2005/05/17 17:46:29 obrien Exp $ + * $FreeBSD: src/lib/libstand/stand.h,v 1.42 2007/01/09 01:02:04 imp Exp $ * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $ */ @@ -39,10 +39,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -250,7 +246,7 @@ extern int printf(const char *fmt, ...) __printflike(1, 2); extern void vprintf(const char *fmt, __va_list); extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3); -extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); +extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4); extern void vsprintf(char *buf, const char *cfmt, __va_list); extern void twiddle(void); ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/Makefile#4 (text+ko) ==== @@ -1,4 +1,6 @@ -# $FreeBSD: src/sys/boot/i386/loader/Makefile,v 1.81.4.1 2005/10/30 14:40:39 scottl Exp $ +# $FreeBSD: src/sys/boot/i386/loader/Makefile,v 1.85 2007/05/29 14:35:57 simokawa Exp $ + +.include <bsd.own.mk> PROG= loader.sym INTERNALPROG= @@ -7,31 +9,41 @@ # architecture-specific loader code SRCS= main.c conf.c vers.c -CFLAGS+= -DLOADER_HTTP_SUPPORT +# Put LOADER_FIREWIRE_SUPPORT=yes in /etc/make.conf for FireWire/dcons support +.if defined(LOADER_FIREWIRE_SUPPORT) +CFLAGS+= -DLOADER_FIREWIRE_SUPPORT +LIBFIREWIRE= ${.OBJDIR}/../libfirewire/libfirewire.a +.endif + +CFLAGS+= -DLOADER_HTTP_SUPPORT # Enable HTTP support for PXE .if !defined(LOADER_HTTP_SUPPORT) # Enable PXE TFTP or NFS support, not both. .if defined(LOADER_TFTP_SUPPORT) -CFLAGS+= -DLOADER_TFTP_SUPPORT +CFLAGS+= -DLOADER_TFTP_SUPPORT .else -CFLAGS+= -DLOADER_NFS_SUPPORT +CFLAGS+= -DLOADER_NFS_SUPPORT .endif .endif .if ${MACHINE_ARCH} == "amd64" -CFLAGS+= -DLOADER_AMD64_ELF_SUPPORT +CFLAGS+= -DLOADER_AMD64_ELF_SUPPORT .endif +# Include bcache code. +HAVE_BCACHE= yes + # Enable PnP and ISA-PnP code. HAVE_PNP= yes HAVE_ISABUS= yes -#CFLAGS+= -DPXE_MORE +# Enable more pxe_http functions +#CFLAGS+= -DPXE_MORE -.if !defined(NO_FORTH) +.if ${MK_FORTH} != "no" # Enable BootForth BOOT_FORTH= yes CFLAGS+= -DBOOT_FORTH -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/i386 @@ -62,7 +74,10 @@ # BTX components CFLAGS+= -I${.CURDIR}/../btx/lib -CFLAGS+= -I$(.CURDIR)/../pxe_http + +# pxe_http includes +CFLAGS+= -I${.CURDIR}/../pxe_http + # Debug me! #CFLAGS+= -g #LDFLAGS+= -g @@ -98,8 +113,8 @@ # XXX crt0.o needs to be first for pxeboot(8) to work OBJS= ${BTXCRT} -DPADD= ${LIBFICL} ${LIBI386} ${LIBSTAND} -LDADD= ${LIBFICL} ${LIBI386} -lstand +DPADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBI386} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBI386} -lstand .include <bsd.prog.mk> ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/conf.c#3 (text+ko) ==== @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/boot/i386/loader/conf.c,v 1.25 2004/08/29 00:48:42 iedowse Exp $"); +__FBSDID("$FreeBSD: src/sys/boot/i386/loader/conf.c,v 1.26 2007/05/29 14:35:57 simokawa Exp $"); #include <stand.h> #include <bootstrap.h> @@ -42,6 +42,7 @@ * * XXX as libi386 and biosboot merge, some of these can become linker sets. */ + #ifdef LOADER_HTTP_SUPPORT #undef LOADER_NFS_SUPPORT #undef LOADER_TFTP_SUPPORT @@ -51,14 +52,21 @@ #error "Cannot have both tftp and nfs support yet." #endif +#if defined(LOADER_FIREWIRE_SUPPORT) +extern struct devsw fwohci; +#endif + /* Exported for libstand */ struct devsw *devsw[] = { &bioscd, &biosdisk, -#if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) || \ +#if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) || \ defined(LOADER_HTTP_SUPPORT) &pxedisk, #endif +#if defined(LOADER_FIREWIRE_SUPPORT) + &fwohci, +#endif NULL }; @@ -68,10 +76,10 @@ #undef LOADER_DOS_SUPPORT #undef LOADER_CD9660_SUPPORT #undef LOADER_SPLITFS_SUPPORT -#undef LOADER_NFS_SUPPORT +#undef LOADER_NFS_SUPPORT #undef LOADER_TFTP_SUPPORT #else -#define LOADER_NFS_SUPPORT +#define LOADER_NFS_SUPPORT #endif struct fs_ops *file_system[] = { @@ -136,12 +144,16 @@ */ extern struct console vidconsole; extern struct console comconsole; +#if defined(LOADER_FIREWIRE_SUPPORT) +extern struct console dconsole; +#endif extern struct console nullconsole; struct console *consoles[] = { &vidconsole, -#ifdef LOADER_COMCONSOLE_SUPPORT &comconsole, +#if defined(LOADER_FIREWIRE_SUPPORT) + &dconsole, #endif &nullconsole, NULL ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/main.c#4 (text+ko) ==== @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/boot/i386/loader/main.c,v 1.31 2005/05/27 19:31:00 jhb Exp $"); +__FBSDID("$FreeBSD: src/sys/boot/i386/loader/main.c,v 1.40 2007/05/29 14:35:57 simokawa Exp $"); /* * MD bootstrap main() and assorted miscellaneous @@ -40,7 +40,6 @@ #include "bootstrap.h" #include "libi386/libi386.h" #include "btxv86.h" - #ifdef PXE_MORE #include "pxe_arp.h" #include "pxe_connection.h" @@ -54,6 +53,7 @@ #include "pxe_udp.h" #endif + #define KARGS_FLAGS_CD 0x1 #define KARGS_FLAGS_PXE 0x2 @@ -85,6 +85,9 @@ /* XXX debugging */ extern char end[]; +static void *heap_top; +static void *heap_bottom; + int main(void) { @@ -101,16 +104,27 @@ */ bios_getmem(); +#if defined(LOADER_BZIP2_SUPPORT) || defined(LOADER_FIREWIRE_SUPPORT) + heap_top = PTOV(memtop_copyin); + memtop_copyin -= 0x300000; + heap_bottom = PTOV(memtop_copyin); +#else + heap_top = (void *)bios_basemem; + heap_bottom = (void *)end; +#endif + #if defined(LOADER_HTTP_SUPPORT) || defined (LOADER_TFTP_SUPPORT) || \ defined(LOADER_NFS_SUPPORT) /* 0x8d000-0x9f800 memory area is used by UNDI/BC data/code segments * and PXE stack */ - setheap((void *)end, 0x8d000); -#else - setheap((void *)end, (void *)bios_basemem); + /* TODO: check, if conflict with LOADER_BZIP2_SUPPORT exists */ + heap_top = 0x8d000; + heap_bottom = (void *)end; #endif - + + setheap(heap_bottom, heap_top); + /* * XXX Chicken-and-egg problem; we want to have console output early, but some * console attributes may depend on reading from eg. the boot device, which we @@ -119,8 +133,8 @@ * We can use printf() etc. once this is done. * If the previous boot stage has requested a serial console, prefer that. */ + bi_setboothowto(initial_howto); if (initial_howto & RB_MULTIPLE) { - setenv("boot_multicons", "YES", 1); if (initial_howto & RB_SERIAL) setenv("console", "comconsole vidconsole", 1); else @@ -165,6 +179,9 @@ /* detect ACPI for future reference */ biosacpi_detect(); + /* detect SMBIOS for future reference */ + smbios_detect(); + printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); @@ -198,7 +215,7 @@ extract_currdev(void) { struct i386_devdesc new_currdev; - int major, biosdev = -1; + int biosdev = -1; /* Assume we are booting from a BIOS disk by default */ new_currdev.d_dev = &biosdisk; @@ -208,11 +225,11 @@ if ((kargs->bootflags & KARGS_FLAGS_CD) != 0) { /* we are booting from a CD with cdboot */ new_currdev.d_dev = &bioscd; - new_currdev.d_kind.bioscd.unit = bc_bios2unit(initial_bootdev); + new_currdev.d_unit = bc_bios2unit(initial_bootdev); } else if ((kargs->bootflags & KARGS_FLAGS_PXE) != 0) { /* we are booting from pxeldr */ new_currdev.d_dev = &pxedisk; - new_currdev.d_kind.netif.unit = 0; + new_currdev.d_unit = 0; } else { /* we don't know what our boot device is */ new_currdev.d_kind.biosdisk.slice = -1; @@ -229,11 +246,10 @@ B_CONTROLLER(initial_bootdev) - 1; new_currdev.d_kind.biosdisk.partition = B_PARTITION(initial_bootdev); biosdev = initial_bootinfo->bi_bios_dev; - major = B_TYPE(initial_bootdev); /* * If we are booted by an old bootstrap, we have to guess at the BIOS - * unit number. We will loose if there is more than one disk type + * unit number. We will lose if there is more than one disk type * and we are not booting from the lowest-numbered disk type * (ie. SCSI when IDE also exists). */ @@ -247,10 +263,10 @@ * which one we booted off of, just use disk0: as a reasonable default. */ if ((new_currdev.d_type == biosdisk.dv_type) && - ((new_currdev.d_kind.biosdisk.unit = bd_bios2unit(biosdev)) == -1)) { + ((new_currdev.d_unit = bd_bios2unit(biosdev)) == -1)) { printf("Can't work out which disk we are booting from.\n" "Guessed BIOS device 0x%x not found by probes, defaulting to disk0:\n", biosdev); - new_currdev.d_kind.biosdisk.unit = 0; + new_currdev.d_unit = 0; } env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&new_currdev), i386_setcurrdev, env_nounset); @@ -287,7 +303,8 @@ command_heap(int argc, char *argv[]) { mallocstats(); - printf("heap base at %p, top at %p\n", end, sbrk(0)); + printf("heap base at %p, top at %p, upper limit at %p\n", heap_bottom, + sbrk(0), heap_top); return(CMD_OK); } @@ -305,324 +322,250 @@ } if (!strcmp(argv[1], "print")) { - pxe_ip_route_stat(); + pxe_ip_route_stat(); return (CMD_OK); } - + if (argc < 4) { printf("use: route add|del default|net_addr gw_addr\n"); return (CMD_OK); } - + if ( (strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "del") != 0)) - return (CMD_OK); - + return (CMD_OK); + if (!strcmp(argv[2], "default")) { if (!strcmp(argv[1], "del")) { printf("Cannot delete default gateway.\n"); return (CMD_OK); } - + gw.ip = pxe_convert_ipstr(argv[3]); - + pxe_ip_route_default(&gw); - + return (CMD_OK); } - + gw.ip = pxe_convert_ipstr(argv[3]); net.ip = pxe_convert_ipstr(argv[2]); - + if (!strcmp(argv[1], "add")) { pxe_ip_route_add(&net, pxe_ip_get_netmask(&net), &gw); return (CMD_OK); } - + pxe_ip_route_del(&net, pxe_ip_get_netmask(&net), &gw); - + return (CMD_OK); } - + static int command_arp(int argc, char *argv[]) { PXE_IPADDR *ip; - + if (argc > 1) { - + if (strcmp(argv[1], "stats") != 0) ip = pxe_gethostbyname(argv[1]); else { pxe_arp_stats(); return (CMD_OK); } - } else { printf("use: arp ip4_address|stats\n"); return (CMD_OK); } - + printf("searching ip: %s\n", (ip != NULL) ? inet_ntoa(ip->ip) : "?"); - + const uint8_t* mac = (const uint8_t *)pxe_arp_ip4mac(ip); - + if (mac != NULL) - printf("MAC: %6D\n", mac, ":"); + printf("MAC: %6D\n", mac, ":"); else - printf("MAC search failed.\n"); - + printf("MAC search failed.\n"); + return (CMD_OK); } - + static int command_ping(int argc, char *argv[]) { PXE_IPADDR* ip = NULL; - + pxe_icmp_init(); - + if (argc > 1) ip = pxe_gethostbyname(argv[1]); else { printf("use: ping ip4_address\n"); return (CMD_OK); } - + pxe_ping(ip, 5, 1); - + return (CMD_OK); } - + static int command_await() { while (1) { - if (!pxe_core_recv_packets()) { + if (!pxe_core_recv_packets()) { twiddle(); delay(10000); } } - + return (0); } - + static int command_sock(int argc, char *argv[]) { + if (argc < 2) { - printf("use: socket stats|tcptest\n"); + printf("use: socket stats\n"); return (CMD_OK); } - + if (!strcmp(argv[1], "stats")) { pxe_sock_stats(); return (CMD_OK); } - - if (argc < 3) { - printf("use: socket tcptest ip4.addr\n"); - return (CMD_OK); - } - - if (!strcmp(argv[1], "tcptest")) { - int socket = pxe_socket(); - PXE_IPADDR ip; - uint32_t bps = 0; - uint32_t start_time = 0; - int index2 = 0; - - ip.ip = pxe_convert_ipstr(argv[2]); - - int res = pxe_connect(socket, &ip, 26, PXE_TCP_PROTOCOL); - if (res == -1) - printf("tcptest: failed to connect socket.\n"); - else { - int index = 0; - int recvc = 0; - uint8_t data; - start_time = pxe_get_secs(); - - index = 0; - recvc = 0; - - data = 1; - - while ( data != 0) { - recvc = pxe_recv(socket, &data, 1); - - if (recvc == -1) { - printf("tcptest: %d bytes recv, but next failed.\n", index); - pxe_close(socket); - return (CMD_OK); - } - - if (recvc == 0) { - printf("!"); - continue; - } - - recvc = (index % 149) + 1; - - if (data == 0) { - printf("tcptest: end of test.\n"); - break; - } - - if (data != recvc) - printf("tcptest: error: step %d, waited %d, got %d.\n", - index, recvc, data); - - index += 1; - index2 += 1; - - if ( index2 > 100000) { - uint32_t delta = pxe_get_secs() - start_time; - bps = ((double)index) / ((delta != 0) ? delta : 1); - - printf("tcptest: %d bytes received, %d bytes/sec.\n", - index, bps); - - index2 = 0; - } - } - - uint32_t delta = pxe_get_secs() - start_time; - bps = ((double)index) / ((delta != 0) ? delta : 1); - - printf("tcptest: ok (recv: %d), avg %d bytes/sec.\n", index, bps); - } - pxe_close(socket); - } - return (CMD_OK); } - + static int command_resolve(int argc, char *argv[]) { + if (argc < 2) { - printf("use: resolve dns_name\n"); + printf("use: resolve dns_name\n"); return (CMD_OK); } - - PXE_IPADDR *ip; - - char* name = argv[1]; - + + PXE_IPADDR *ip; + + char* name = argv[1]; + ip = pxe_gethostbyname(name); - + if ( (ip == NULL) || (ip->ip == 0)) - printf("failed to resolve domain %s\n", name); + printf("failed to resolve domain %s\n", name); else printf("%s resolved as %s\n", name, inet_ntoa(ip->ip)); - + return (CMD_OK); } - + static int command_ns(int argc, char *argv[]) { - PXE_IPADDR *ip; - + PXE_IPADDR *ip; + if (argc == 1) { ip = pxe_get_ip(PXE_IP_NAMESERVER); - - printf("primary nameserver: %s\n", inet_ntoa(ip->ip)); - + + printf("primary nameserver: %s\n", inet_ntoa(ip->ip)); + return (CMD_OK); } - - PXE_IPADDR addr; - + + PXE_IPADDR addr; + addr.ip = pxe_convert_ipstr(argv[1]); - + if (addr.ip != 0) pxe_set_ip(PXE_IP_NAMESERVER, &addr); else printf("Syntax error in ip address.\n"); - + return (CMD_OK); } - + static int command_fetch(int argc, char *argv[]) { + if (argc == 1) { printf("usage: fetch server/path/to/file.ext\n"); return (CMD_OK); } - + char *server_name = argv[1]; char *filename = server_name; - + while (*filename) { - if (*filename == '/') { + if (*filename == '/') { *filename = '\0'; ++filename; break; - } - ++filename; + } + ++filename; } - - /* retrieve all file */ + + /* retrieve all file */ pxe_fetch(server_name, filename, 0LL, 0L); - + return (CMD_OK); } COMMAND_SET(pxe, "pxe", "pxe test module", command_pxe); - + static int command_pxe(int argc, char *argv[]) { + if (argc<2) { - printf("PXE test module (built at %s %s)\n", __DATE__, __TIME__); - printf(" use: pxe arp|await|connections|fetch|filters|\n" - "\tping|resolve|route|socket\n"); + printf("PXE test module (built at %s %s)\n", __DATE__, __TIME__); + printf(" use: pxe arp|await|connections|fetch|filters|\n" + "\tping|resolve|route|socket\n"); return (CMD_OK); } - + if (!strcmp(argv[1], "arp")) return command_arp(argc - 1, &argv[1]); - + if (!strcmp(argv[1], "ping")) return command_ping(argc - 1, &argv[1]); - + if (!strcmp(argv[1], "route")) return command_route(argc - 1, &argv[1]); - + if (!strcmp(argv[1], "filters")) { pxe_filter_stats(); return (CMD_OK); } - + if (!strcmp(argv[1], "socket")) return command_sock(argc - 1, &argv[1]); - + if (!strcmp(argv[1], "resolve")) return command_resolve(argc - 1, &argv[1]); - + if (!strcmp(argv[1], "ns")) return command_ns(argc - 1, &argv[1]); - - + >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710191338.l9JDc3M0039052>