bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] new command


From: Eugene A. Doudine
Subject: [PATCH] new command
Date: Wed, 10 Jan 2001 04:08:12 +0700 (KRAT)

Hi,

I needed to netboot from tftp, but without any dhcp, bootp or rarp
servers, so I had to add a simple command to set IP address, subnet mask,
default gateway. It also can set address of the tftp server, but this 
is probably ambiguous, since there is 'tftpserver' command.

The command sintax is:

  ifconfig [--address=IP] [--mask=MASK] [--gateway=IP] [--tftpserver=IP]

if used without arguments, it will print current network settings.

Here is the patch, could you add these changes to grub source tree?  

Regards,
Eugene 


diff -urbB ./grub-0.5.96.1/ChangeLog ./grub-0.5.96.1-ifconfig/ChangeLog
--- ./grub-0.5.96.1/ChangeLog   Fri Oct 20 03:44:35 2000
+++ ./grub-0.5.96.1-ifconfig/ChangeLog  Wed Jan 10 03:10:57 2001
@@ -1,3 +1,16 @@
+2001-01-09  Eugene Doudine   <address@hidden>
+       * stage2/builtins.c (ifconfig_func): New function to configure
+       network interface from command line without bootp/dhcp/rarp 
+       servers. 
+       (builtin_ifconfig): New variable.
+       (builtin_table): Added pointer to builtin_ifconfig.
+       * netboot/main.c (ifconfig): New function.
+       * netboot/etherboot.h: Added prototype for ifconfig.
+       * stage2/char_io.c (grub_strchr): New function.
+       (grub_strtok): New function.
+       * stage2/shared.h: Added prototypes for grub_strchr and grub_strtok
+               
+
 2000-10-17  OKUJI Yoshinori  <address@hidden>
 
        * stage2/builtins.c (setkey_func): Clear the all elements of
diff -urbB ./grub-0.5.96.1/netboot/etherboot.h 
./grub-0.5.96.1-ifconfig/netboot/etherboot.h
--- ./grub-0.5.96.1/netboot/etherboot.h Tue Jun  6 19:04:01 2000
+++ ./grub-0.5.96.1-ifconfig/netboot/etherboot.h        Wed Jan 10 01:11:36 2001
@@ -476,6 +476,7 @@
 extern void nfs_umountall P((int));
 #endif /* ! GRUB */
 extern int bootp P((void));
+extern int ifconfig P((char *arg));
 extern int rarp P((void));
 extern int udp_transmit P((unsigned long destip, unsigned int srcsock,
        unsigned int destsock, int len, const void *buf));
diff -urbB ./grub-0.5.96.1/netboot/main.c 
./grub-0.5.96.1-ifconfig/netboot/main.c
--- ./grub-0.5.96.1/netboot/main.c      Sun Jul 30 03:22:54 2000
+++ ./grub-0.5.96.1-ifconfig/netboot/main.c     Wed Jan 10 01:13:21 2001
@@ -206,6 +206,50 @@
     return (htonl (0xffffff00));
 }
 
+
+/* ifconfig - configure network interface */
+int ifconfig (char *arg) {
+  struct {
+    char *name;
+    unsigned long *ptr;
+  } args[]={
+    {"--address=",&arptable[ARP_CLIENT].ipaddr.s_addr},
+    {"--tftpserver=",&arptable[ARP_SERVER].ipaddr.s_addr},
+    {"--gateway=",&arptable[ARP_GATEWAY].ipaddr.s_addr},
+    {"--mask=",&netmask},
+    {NULL,NULL}
+  };
+
+  char *token;
+  int i;
+  in_addr taddr;
+  token=grub_strtok(arg,"\t ");
+  while (token) {
+    for (i=0;args[i].name!=0;i++) {
+      if (!grub_memcmp(args[i].name,token,grub_strlen(args[i].name))) {
+       if (!inet_aton(token+grub_strlen(args[i].name),&taddr)) {
+         errnum = ERR_BAD_ARGUMENT;
+         return 1;
+       }
+       *(args[i].ptr)=taddr.s_addr;
+       if (!grub_strcmp("--address=",args[i].name) && !netmask) {
+         netmask=default_netmask();
+       }
+       break;
+      }
+    }
+    if (!args[i].name) {
+      errnum = ERR_BAD_ARGUMENT;
+      return 1;
+    }
+    token=grub_strtok(NULL," \t");
+  }
+  network_ready = 1;
+
+  return 0;
+}
+
+
 /**************************************************************************
 UDP_TRANSMIT - Send a UDP datagram
 **************************************************************************/
diff -urbB ./grub-0.5.96.1/stage2/builtins.c 
./grub-0.5.96.1-ifconfig/stage2/builtins.c
--- ./grub-0.5.96.1/stage2/builtins.c   Fri Oct 20 03:50:00 2000
+++ ./grub-0.5.96.1-ifconfig/stage2/builtins.c  Wed Jan 10 03:11:30 2001
@@ -1428,6 +1429,33 @@
 };
 
 
+
+#ifdef SUPPORT_NETBOOT
+/* ifconfig */
+static int 
+ifconfig_func (char *arg, int flags)
+{
+  if (! eth_probe ())
+    return 0;
+  if (!arg || !grub_strlen(arg)) {
+    print_network_configuration();
+    return 0;
+  }
+  return ifconfig(arg);
+}
+
+static struct builtin builtin_ifconfig =
+{
+  "ifconfig",
+  ifconfig_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "ifconfig [--address=IP] [--gateway=IP] [--mask=MASK] [--tftpserver=IP]",
+  "Configure IP address, mask, gateway and tftp server from command line"
+  " or print current network configuration"
+};
+
+#endif /* SUPPORT_NETBOOT */
+
 /* impsprobe */
 static int
 impsprobe_func (char *arg, int flags)
@@ -4001,6 +4029,9 @@
   &builtin_help,
   &builtin_hiddenmenu,
   &builtin_hide,
+#ifdef SUPPORT_NETBOOT
+  &builtin_ifconfig,
+#endif /* SUPPORT_NETBOOT */
   &builtin_impsprobe,
   &builtin_initrd,
   &builtin_install,
diff -urbB ./grub-0.5.96.1/stage2/char_io.c 
./grub-0.5.96.1-ifconfig/stage2/char_io.c
--- ./grub-0.5.96.1/stage2/char_io.c    Wed Sep 27 03:52:29 2000
+++ ./grub-0.5.96.1-ifconfig/stage2/char_io.c   Wed Jan 10 01:16:51 2001
@@ -1407,4 +1407,37 @@
   grub_memmove (dest, src, grub_strlen (src) + 1);
   return dest;
 }
+
+
+char *
+grub_strchr(const char *s,const int c) {
+  int i,slen;
+  slen=grub_strlen(s);
+  for(i=0;i<slen && s[i]!=c;i++);
+  if (i==slen) return NULL;
+  return s+i;
+}
+
+
+
+char *
+grub_strtok(char *s,const char *delim) {
+  static char *ptr;
+  static int slen,i,b;
+  if (s) {
+    ptr=s;
+    slen=grub_strlen(s);
+    i=0;
+  }
+  for(;i<slen && grub_strchr(delim,*(ptr+i));i++);
+  if (i>=slen) return NULL;
+  b=i;
+  for(;i<slen && !grub_strchr(delim,*(ptr+i));i++);
+  *(ptr+i)=0;
+  i++;
+  return ptr+b;
+}
+
+
+
 #endif /* ! STAGE1_5 */
diff -urbB ./grub-0.5.96.1/stage2/shared.h 
./grub-0.5.96.1-ifconfig/stage2/shared.h
--- ./grub-0.5.96.1/stage2/shared.h     Thu Oct 19 23:27:52 2000
+++ ./grub-0.5.96.1-ifconfig/stage2/shared.h    Wed Jan 10 00:38:08 2001
@@ -784,6 +784,8 @@
 int grub_strcmp (const char *s1, const char *s2);
 int grub_strlen (const char *str);
 char *grub_strcpy (char *dest, const char *src);
+char *grub_strchr (const char *s, const int c);
+char *grub_strtok (char *s,const char *delim);
 
 #ifndef GRUB_UTIL
 typedef unsigned long grub_jmp_buf[6];





reply via email to

[Prev in Thread] Current Thread [Next in Thread]