Date: Wed, 16 Jan 2013 04:35:35 +0000 (UTC) From: Sean Bruno <sbruno@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r245489 - user/sbruno/pxestuff/sys/boot/i386/loader Message-ID: <201301160435.r0G4ZZDE078289@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: sbruno Date: Wed Jan 16 04:35:35 2013 New Revision: 245489 URL: http://svnweb.freebsd.org/changeset/base/245489 Log: Merge last changes from pxe_http tree into the head version of /boot looks like I've got some include files problems, clang doesn't handle this part of the tree yet and I've found unsupported clang bits? Note: doesn't compile yet, try again after I get some sleep Modified: user/sbruno/pxestuff/sys/boot/i386/loader/Makefile user/sbruno/pxestuff/sys/boot/i386/loader/conf.c user/sbruno/pxestuff/sys/boot/i386/loader/main.c Modified: user/sbruno/pxestuff/sys/boot/i386/loader/Makefile ============================================================================== --- user/sbruno/pxestuff/sys/boot/i386/loader/Makefile Wed Jan 16 03:59:42 2013 (r245488) +++ user/sbruno/pxestuff/sys/boot/i386/loader/Makefile Wed Jan 16 04:35:35 2013 (r245489) @@ -26,6 +26,8 @@ LIBZFSBOOT= ${.OBJDIR}/../../zfs/libzfsb # Enable PXE TFTP or NFS support, not both. .if defined(LOADER_TFTP_SUPPORT) CFLAGS+= -DLOADER_TFTP_SUPPORT +.elif defined(LOADER_HTTP_SUPPORT) +CFLAGS+= -DLOADER_HTTP_SUPPORT .else CFLAGS+= -DLOADER_NFS_SUPPORT .endif @@ -37,6 +39,9 @@ HAVE_BCACHE= yes HAVE_PNP= yes HAVE_ISABUS= yes +# Enable more pxe_http functions +#CFLAGS+= -DPXE_MORE + .if ${MK_FORTH} != "no" # Enable BootForth BOOT_FORTH= yes @@ -66,12 +71,15 @@ CFLAGS+= -Wall LDFLAGS= -static -Ttext 0x0 # i386 standalone support library -LIBI386= ${.OBJDIR}/../libi386/libi386.a +LIBI386= ${.OBJDIR}/../libi386/libi386.a ${.OBJDIR}/../pxehttp/libpxe_http.a CFLAGS+= -I${.CURDIR}/.. # BTX components CFLAGS+= -I${.CURDIR}/../btx/lib +# PXE HTTP components +CFLAGS+= -I$(.CURDIR)/../pxe_http + # Debug me! #CFLAGS+= -g #LDFLAGS+= -g Modified: user/sbruno/pxestuff/sys/boot/i386/loader/conf.c ============================================================================== --- user/sbruno/pxestuff/sys/boot/i386/loader/conf.c Wed Jan 16 03:59:42 2013 (r245488) +++ user/sbruno/pxestuff/sys/boot/i386/loader/conf.c Wed Jan 16 04:35:35 2013 (r245489) @@ -45,6 +45,11 @@ __FBSDID("$FreeBSD$"); * XXX as libi386 and biosboot merge, some of these can become linker sets. */ +#ifdef LOADER_HTTP_SUPORT +#undef LOADER_NFS_SUPPORT +#undef LOADER_TFTP_SUPPO +#endif + #if defined(LOADER_NFS_SUPPORT) && defined(LOADER_TFTP_SUPPORT) #error "Cannot have both tftp and nfs support yet." #endif @@ -57,7 +62,8 @@ extern struct devsw fwohci; 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) @@ -69,14 +75,32 @@ struct devsw *devsw[] = { NULL }; +#if defined(LOADER_HTTP_SUPPORT) +/* free as much as possible memory, by removing unused by PXE filesystems */ +#undef LOADER_EXT2_SUPPORT +#undef LOADER_DOS_SUPPORT +#undef LOADER_CD9660_SUPPORT +#undef LOADER_SPLITFS_SUPPORT +#undef LOADER_NFS_SUPPORT +#undef LOADER_TFTP_SUPPORT +#else +#define LOADER_NFS_SUPPORT +#endif + struct fs_ops *file_system[] = { #if defined(LOADER_ZFS_SUPPORT) &zfs_fsops, #endif &ufs_fsops, +#if defined(LOADER_EXT2_SUPPORT) &ext2fs_fsops, +#endif +#if defined(LOADER_DOS_SUPPORT) &dosfs_fsops, +#endif +#if defined(LOADER_CD9660_SUPPORT) &cd9660_fsops, +#endif #if defined(LOADER_NANDFS_SUPPORT) &nandfs_fsops, #endif @@ -95,6 +119,9 @@ struct fs_ops *file_system[] = { #ifdef LOADER_TFTP_SUPPORT &tftp_fsops, #endif +#ifdef LOADER_HTTP_SUPPORT + &http_fsops, +#endif NULL }; Modified: user/sbruno/pxestuff/sys/boot/i386/loader/main.c ============================================================================== --- user/sbruno/pxestuff/sys/boot/i386/loader/main.c Wed Jan 16 03:59:42 2013 (r245488) +++ user/sbruno/pxestuff/sys/boot/i386/loader/main.c Wed Jan 16 04:35:35 2013 (r245489) @@ -49,6 +49,19 @@ __FBSDID("$FreeBSD$"); #include "../zfs/libzfs.h" #endif +#ifdef PXE_MORE +#include "pxe_arp.h" +#include "pxe_connection.h" +#include "pxe_dns.h" +#include "pxe_filter.h" +#include "pxe_http.h" +#include "pxe_httpls.h" +#include "pxe_icmp.h" +#include "pxe_ip.h" +#include "pxe_sock.h" +#include "pxe_tcp.h" +#include "pxe_udp.h" +#endif CTASSERT(sizeof(struct bootargs) == BOOTARGS_SIZE); CTASSERT(offsetof(struct bootargs, bootinfo) == BA_BOOTINFO); CTASSERT(offsetof(struct bootargs, bootflags) == BA_BOOTFLAGS); @@ -101,7 +114,8 @@ main(void) bios_getmem(); #if defined(LOADER_BZIP2_SUPPORT) || defined(LOADER_FIREWIRE_SUPPORT) || \ - defined(LOADER_GPT_SUPPORT) || defined(LOADER_ZFS_SUPPORT) + defined(LOADER_GPT_SUPPORT) || defined(LOADER_ZFS_SUPPORT) || \ + defined(LOADER_HTTP_SUPPORT) if (high_heap_size > 0) { heap_top = PTOV(high_heap_base + high_heap_size); heap_bottom = PTOV(high_heap_base); @@ -368,6 +382,290 @@ isa_outb(int port, int value) outb(port, value); } +#ifdef PXE_MORE +/* added for pxe_http */ +static int +command_route(int argc, char *argv[]) +{ + PXE_IPADDR net; + PXE_IPADDR gw; + + if (argc < 2) { + printf("use: route add|del|print [default|net_addr gw_addr] \n"); + return (CMD_OK); + } + + if (!strcmp(argv[1], "print")) { + 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); + + 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, ":"); + else + 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()) { + twiddle(); + delay(10000); + } + } + + return (0); +} + +static int +command_sock(int argc, char *argv[]) +{ + if (argc < 2) { + printf("use: socket stats|tcptest\n"); + return (CMD_OK); + } + + if (!strcmp(argv[1], "stats")) { + pxe_sock_stats(); + return (CMD_OK); + } + + return (CMD_OK); +} + +static int +command_resolve(int argc, char *argv[]) +{ + if (argc < 2) { + printf("use: resolve dns_name\n"); + return (CMD_OK); + } + + 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); + 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; + + if (argc == 1) { + ip = pxe_get_ip32(PXE_IP_NAMESERVER); + printf("primary nameserver: %s\n", inet_ntoa(ip->ip)); + return (CMD_OK); + } + + PXE_IPADDR addr; + + addr.ip = pxe_convert_ipstr(argv[1]); + + if (addr.ip != 0) + pxe_set_ip32(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 == '/') { + *filename = '\0'; + ++filename; + break; + } + ++filename; + } + + /* retrieve all file */ + pxe_fetch(server_name, filename, 0LL, 0L); + + return (CMD_OK); +} + +static int +command_ls(int argc, char *argv[]) +{ + + if (argc == 1) { + printf("usage: ls /path/to/dir\n"); + return (CMD_OK); + } + + int fd = open(argv[1], O_RDONLY); + + if (fd == -1) + return (CMD_OK); + + http_parse_index(fd); + + close(fd); + + 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"); + 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]); + + + if (!strcmp(argv[1], "await")) + return command_await(); + + if (!strcmp(argv[1], "connections")) { + pxe_connection_stats(); + return (CMD_OK); + } + + if (!strcmp(argv[1], "fetch")) { + return command_fetch(argc - 1, &argv[1]); + } + + if (!strcmp(argv[1], "ls")) { + return command_ls(argc - 1, &argv[1]); + } + + printf("unknown pxe command '%s'\n", argv[1]); + + return (CMD_OK); +} +/* pxe_http add end */ +#endif + #ifdef LOADER_ZFS_SUPPORT static void i386_zfs_probe(void)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301160435.r0G4ZZDE078289>