From bfbcbe125ea6385912815b78a4a4c68dffbe8a0c Mon Sep 17 00:00:00 2001 From: okuji Date: Fri, 11 Feb 2000 02:50:36 +0000 Subject: [PATCH] fix some bugs in netboot, print out the network configuration if bootp or arp succeeds. --- ChangeLog | 21 +++++++++++++++++++++ netboot/config.c | 3 +++ netboot/etherboot.h | 8 +++++++- netboot/main.c | 38 +++++++++++++++++++++++++++++++++++--- netboot/misc.c | 27 +++++++++++++++++++++------ stage2/builtins.c | 4 ++++ stage2/shared.h | 5 +++++ 7 files changed, 96 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c8389d86..4555dea3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2000-02-11 OKUJI Yoshinori + + From Pavel Roskin: + * stage2/shared.h [!GRUB_SHARED_HEADER] (GRUB_SHARED_HEADER): + Defined. + [GRUB_SHARED_HEADER]: Don't declare or define anything. + + * netboot/main.c (print_network_configuration): New function. + (await_reply): Check for Control-C instead of ESC, because GRUB + already uses ESC for another purpose. + (rfc951_sleep): Check for the key input in the loop. If + Control-C is pushed, return immediately. + * netboot/etherboot (print_network_configuration): Declared. + (CTRL_C): New macro. + (ESC): Undefined. + * netboot/config.c (eth_probe): Clear ARPTABLE after clearing + NETWORK_READY. + * stage2/builtins.c (bootp_func): Call + print_network_configuration if bootp succeeds. + (rarp_func): Call print_network_configuration if rarp succeeds. + 2000-02-11 OKUJI Yoshinori From Per Lundberg : diff --git a/netboot/config.c b/netboot/config.c index 6663d3253..021d1ca8e 100644 --- a/netboot/config.c +++ b/netboot/config.c @@ -433,6 +433,9 @@ int eth_probe(void) /* Clear the ready flag. */ network_ready = 0; + /* Clear the ARP table. */ + grub_memset ((char *) arptable, 0, + MAX_ARP * sizeof (struct arptable_t)); p = 0; #ifdef INCLUDE_PCI diff --git a/netboot/etherboot.h b/netboot/etherboot.h index 4c3c4b8c1..cf8e2ab47 100644 --- a/netboot/etherboot.h +++ b/netboot/etherboot.h @@ -29,7 +29,11 @@ Author: Martin Renters #define TAGGED_IMAGE /* choose at least one */ #endif -#define ESC 0x1B +#if 0 +# define ESC 0x1B +#else +# define CTRL_C 3 +#endif #ifndef DEFAULT_BOOTFILE #define DEFAULT_BOOTFILE "/tftpboot/kernel" @@ -338,6 +342,8 @@ extern int rarp P((void)); External prototypes ***************************************************************************/ /* main.c */ +extern void print_network_configuration (void); + #if 0 extern void print_bytes P((unsigned char *bytes, int len)); extern void load P((void)); diff --git a/netboot/main.c b/netboot/main.c index ea35b4447..fa950687e 100644 --- a/netboot/main.c +++ b/netboot/main.c @@ -36,7 +36,7 @@ Author: Martin Renters struct arptable_t arptable[MAX_ARP]; -/* Set if the user pushes the ESC key. */ +/* Set if the user pushes Control-C. */ int ip_abort = 0; /* Set if an ethernet card is probed and IP addresses are set. */ int network_ready = 0; @@ -123,6 +123,34 @@ static char dhcprequest[] = static char broadcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +void +print_network_configuration (void) +{ + static void sprint_ip_addr (char *buf, unsigned long addr) + { + grub_sprintf (buf, "%d.%d.%d.%d", + addr >> 24, (addr >> 16) & 0xFF, + (addr >> 8) & 0xFF, addr & 0xFF); + } + + if (! eth_probe ()) + grub_printf ("No ethernet card found.\n"); + else if (! network_ready) + grub_printf ("Not initialized yet.\n"); + else + { + char me[16], my_mask[16], server[16], gw[16]; + + sprint_ip_addr (me, arptable[ARP_CLIENT].ipaddr.s_addr); + sprint_ip_addr (my_mask, netmask); + sprint_ip_addr (server, arptable[ARP_SERVER].ipaddr.s_addr); + sprint_ip_addr (gw, arptable[ARP_GATEWAY].ipaddr.s_addr); + + grub_printf ("Address: %s Netmask: %s\nServer: %s Gateway: %s\n", + me, my_mask, server, gw); + } +} + /************************************************************************** DEFAULT_NETMASK - Return default netmask for IP address **************************************************************************/ @@ -591,6 +619,7 @@ await_reply (int type, int ival, char *ptr, int timeout) int protohdrlen = (ETHER_HDR_SIZE + sizeof (struct iphdr) + sizeof (struct udphdr)); + /* Clear the abort flag. */ ip_abort = 0; #ifdef CONGESTED @@ -600,7 +629,8 @@ await_reply (int type, int ival, char *ptr, int timeout) #endif while (time > currticks ()) { - if (checkkey () != -1 && getkey () == ESC) + /* If Control-C is pushed, return immediately. */ + if (checkkey () != -1 && ASCII_CHAR (getkey ()) == CTRL_C) { ip_abort = 1; return 0; @@ -979,5 +1009,7 @@ rfc951_sleep (int exp) grub_printf ("\n"); for (tmo = (tmo & seed) + currticks (); currticks () < tmo;) - ; + /* If the user interrupts, return immediately. */ + if (checkkey () != -1 && ASCII_CHAR (getkey ()) == CTRL_C) + break; } diff --git a/netboot/misc.c b/netboot/misc.c index 20852d9d1..c5c7dabe5 100644 --- a/netboot/misc.c +++ b/netboot/misc.c @@ -1,3 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2000 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Based on "src/misc.c" in etherboot-4.4.2. */ + /************************************************************************** MISC Support Routines **************************************************************************/ @@ -320,9 +341,3 @@ iskey(void) } #endif /* ETHERBOOT32 */ #endif - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/stage2/builtins.c b/stage2/builtins.c index aaee78e4b..ead35eabe 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -256,6 +256,8 @@ bootp_func (char *arg, int flags) return 1; } + /* Notify the configuration. */ + print_network_configuration (); return 0; #else errnum = ERR_UNRECOGNIZED; @@ -1994,6 +1996,8 @@ rarp_func (char *arg, int flags) return 1; } + /* Notify the configuration. */ + print_network_configuration (); return 0; #else errnum = ERR_UNRECOGNIZED; diff --git a/stage2/shared.h b/stage2/shared.h index a595a93a9..3d0a49a69 100644 --- a/stage2/shared.h +++ b/stage2/shared.h @@ -23,6 +23,9 @@ * Generic defines to use anywhere */ +#ifndef GRUB_SHARED_HEADER +#define GRUB_SHARED_HEADER 1 + #include /* Add an underscore to a C symbol in assembler code if needed. */ @@ -780,3 +783,5 @@ int load_initrd (char *initrd); void init_bios_info (void); #endif /* ASM_FILE */ + +#endif /* ! GRUB_SHARED_HEADER */