From 7519621c595c00a958e9f27280d92c350ceba57a Mon Sep 17 00:00:00 2001 From: okuji Date: Thu, 11 Jan 2001 08:08:15 +0000 Subject: [PATCH] add a new command, ifconfig. --- ChangeLog | 10 +++++++ NEWS | 1 + THANKS | 1 + netboot/etherboot.h | 1 + netboot/main.c | 43 +++++++++++++++++++++++++++++++ stage2/builtins.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+) diff --git a/ChangeLog b/ChangeLog index a2dd3504a..9a09457dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2001-01-11 Eugene Doudine + + * stage2/builtins.c [SUPPORT_NETBOOT] (ifconfig_func): New + function to configure network interface from command line. + [SUPPORT_NETBOOT] (builtin_ifconfig): New variable. + [SUPPORT_NETBOOT] (builtin_table): Added a pointer to + BUILTIN_IFCONFIG. + * netboot/main.c (ifconfig): New function. + * netboot/etherboot.h (ifconfig): Added the prototype. + 2001-01-11 OKUJI Yoshinori * docs/Makefile.am [BUILD_EXAMPLE_KERNEL] (noinst_DATA): New diff --git a/NEWS b/NEWS index 5305dfaf7..be4392734 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ New in 1.0 - XXXX-XX-XX: * Booting Windows from a logical partition is supported. * The example Multiboot kernel in the directory "docs" is built, if you specify the option `--enable-example-kernel' to the configure script. +* New command, "ifconfig". New in 0.5.96 - 2000-10-04: * New commands, "reboot" and "halt". diff --git a/THANKS b/THANKS index d38817ee2..8546692a3 100644 --- a/THANKS +++ b/THANKS @@ -22,6 +22,7 @@ Edmund GRIMLEY EVANS Edward Killips Eric Hanchrow Erik Schoenfelder +Eugene Doudine Frank Mehnert Goran Koruga Hal Snyder diff --git a/netboot/etherboot.h b/netboot/etherboot.h index b492077dc..2bd62a475 100644 --- a/netboot/etherboot.h +++ b/netboot/etherboot.h @@ -462,6 +462,7 @@ External prototypes #ifdef GRUB extern void print_network_configuration P((void)); extern int arp_server_override P((const char *buf)); +extern int ifconfig P((char *ip, char *sm, char *gw, char *svr)); #endif /* GRUB */ #ifndef GRUB diff --git a/netboot/main.c b/netboot/main.c index aaa42a350..9229c6f0c 100644 --- a/netboot/main.c +++ b/netboot/main.c @@ -206,6 +206,49 @@ default_netmask (void) return (htonl (0xffffff00)); } +/* ifconfig - configure network interface. */ +int +ifconfig (char *ip, char *sm, char *gw, char *svr) +{ + in_addr tmp; + + if (sm) + { + if (! inet_aton (sm, &tmp)) + return 0; + + netmask = tmp.s_addr; + } + + if (ip) + { + if (! inet_aton (ip, &arptable[ARP_CLIENT].ipaddr)) + return 0; + + if (! netmask && ! sm) + netmask = default_netmask (); + } + + if (gw && ! inet_aton (gw, &arptable[ARP_GATEWAY].ipaddr)) + return 0; + + if (svr && ! inet_aton (svr, &arptable[ARP_SERVER].ipaddr)) + return 0; + + if (ip || sm) + { + if (IP_BROADCAST == (netmask | arptable[ARP_CLIENT].ipaddr.s_addr) + || netmask == (netmask | arptable[ARP_CLIENT].ipaddr.s_addr) + || ! netmask) + network_ready = 0; + else + network_ready = 1; + } + + return 1; +} + + /************************************************************************** UDP_TRANSMIT - Send a UDP datagram **************************************************************************/ diff --git a/stage2/builtins.c b/stage2/builtins.c index 4d9559fd1..8aff14f41 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -1516,6 +1516,66 @@ static struct builtin builtin_hide = " its partition type code." }; + +#ifdef SUPPORT_NETBOOT +/* ifconfig */ +static int +ifconfig_func (char *arg, int flags) +{ + char *svr = 0, *ip = 0, *gw = 0, *sm = 0; + + if (! eth_probe ()) + { + grub_printf ("No ethernet card found.\n"); + errnum = ERR_DEV_VALUES; + return 1; + } + + if (! *arg) + { + print_network_configuration (); + return 0; + } + + while (*arg) + { + if (! grub_memcmp ("--server=", arg, sizeof ("--server=") - 1)) + svr = arg + sizeof("--server=") - 1; + else if (! grub_memcmp ("--address=", arg, sizeof ("--address=") - 1)) + ip = arg + sizeof ("--address=") - 1; + else if (! grub_memcmp ("--gateway=", arg, sizeof ("--gateway=") - 1)) + gw = arg + sizeof ("--gateway=") - 1; + else if (! grub_memcmp ("--mask=", arg, sizeof("--mask=") - 1)) + sm = arg + sizeof ("--mask=") - 1; + else + { + errnum = ERR_BAD_ARGUMENT; + return 1; + } + + arg = skip_to (0, arg); + } + + if (! ifconfig (ip, sm, gw, svr)) + { + errnum = ERR_BAD_ARGUMENT; + return 1; + } + + return 0; +} + +static struct builtin builtin_ifconfig = +{ + "ifconfig", + ifconfig_func, + BUILTIN_CMDLINE | BUILTIN_MENU, + "ifconfig [--address=IP] [--gateway=IP] [--mask=MASK] [--server=IP]", + "Configure the IP address, the netmask, the gateway and the server" + " address or print current network configuration." +}; +#endif /* SUPPORT_NETBOOT */ + /* impsprobe */ static int @@ -4349,6 +4409,9 @@ struct builtin *builtin_table[] = &builtin_help, &builtin_hiddenmenu, &builtin_hide, +#ifdef SUPPORT_NETBOOT + &builtin_ifconfig, +#endif /* SUPPORT_NETBOOT */ &builtin_impsprobe, &builtin_initrd, &builtin_install,