diff options
author | Thomas Huth <thuth@redhat.com> | 2016-10-12 12:44:07 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-10-17 11:02:16 +1100 |
commit | 87404ee220a370a133b417bca2224dd5a651ba3c (patch) | |
tree | ca8076e3d9d4611aa2b67de80971ff75c6f13110 /lib | |
parent | f7eb3a5728042a659b66806f4654ef0da16d58b4 (diff) | |
download | SLOF-87404ee220a370a133b417bca2224dd5a651ba3c.zip SLOF-87404ee220a370a133b417bca2224dd5a651ba3c.tar.gz SLOF-87404ee220a370a133b417bca2224dd5a651ba3c.tar.bz2 |
libnet: Simplify the net-load arguments passing
There is no need anymore to pass most of the arguments as
strings, we can use integers and pointers now instead.
While we're at it, change the maximum TFTP packet block size
in obp-tftp.fs from 1432 to 1428, since this is the correct
value (with 1432, there might be problems with networking
over VLANs). The code in tftp.c forces this value to 1428
anyway (see the MAX_BLOCKSIZE constant there), so this change
is just cosmetical, and should not change the behavior of
the TFTP loading process.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libnet/libnet.code | 23 | ||||
-rw-r--r-- | lib/libnet/netapps.h | 3 | ||||
-rw-r--r-- | lib/libnet/netload.c | 21 |
3 files changed, 23 insertions, 24 deletions
diff --git a/lib/libnet/libnet.code b/lib/libnet/libnet.code index ab67fac..3602543 100644 --- a/lib/libnet/libnet.code +++ b/lib/libnet/libnet.code @@ -2,20 +2,15 @@ #include <netapps.h> PRIM(NET_X2d_LOAD) - int slen = TOS.n; POP; - char *arg = TOS.a; - char *argvs[8]; - int i, p; - argvs[0] = arg; - i = 1; - for (p = 0; p < slen; p++) { - if (arg[p] == ' ') { - arg[p] = 0; - argvs[i] = &arg[p + 1]; - i++; - } - } - TOS.n = netboot(i, argvs); + int alen = TOS.n; POP; + char *arg = TOS.a; POP; + int blocksize = TOS.n; POP; + int hugeload = TOS.n; POP; + void *replybuf = TOS.a; POP; + long maxlen = TOS.n; POP; + void *loadaddr = TOS.a; + TOS.n = netload(loadaddr, maxlen, replybuf, hugeload, blocksize, + arg, alen); MIRP PRIM(NET_X2d_PING) diff --git a/lib/libnet/netapps.h b/lib/libnet/netapps.h index 00b6318..91c1ebd 100644 --- a/lib/libnet/netapps.h +++ b/lib/libnet/netapps.h @@ -18,7 +18,8 @@ struct filename_ip; -extern int netboot(int argc, char *argv[]); +extern int netload(char *buffer, int len, char *ret_buffer, int huge_load, + int block_size, char *args_fs, int alen); extern int netsave(int argc, char *argv[]); extern int ping(char *args_fs, int alen); extern int dhcp(char *ret_buffer, struct filename_ip *fn_ip, diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c index 6429405..848609d 100644 --- a/lib/libnet/netload.c +++ b/lib/libnet/netload.c @@ -386,14 +386,11 @@ static void seed_rng(uint8_t mac[]) srand(seed); } -int -netboot(int argc, char *argv[]) +int netload(char *buffer, int len, char *ret_buffer, int huge_load, + int block_size, char *args_fs, int alen) { char buf[256]; int rc; - int len = strtol(argv[2], 0, 16); - char *buffer = (char *) strtol(argv[1], 0, 16); - char *ret_buffer = (char *) strtol(argv[3], 0, 16); filename_ip_t fn_ip; int fd_device; tftp_err_t tftp_err; @@ -403,8 +400,6 @@ netboot(int argc, char *argv[]) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int huge_load = strtol(argv[4], 0, 10); - int32_t block_size = strtol(argv[5], 0, 10); uint8_t own_mac[6]; puts("\n Initializing NIC"); @@ -458,8 +453,16 @@ netboot(int argc, char *argv[]) seed_rng(own_mac); - if (argc > 6) { - parse_args(argv[6], &obp_tftp_args); + if (alen > 0) { + char args[256]; + if (alen > sizeof(args) - 1) { + puts("ERROR: Parameter string is too long."); + return -7; + } + /* Convert forth string into NUL-terminated C-string */ + strncpy(args, args_fs, alen); + args[alen] = 0; + parse_args(args, &obp_tftp_args); if(obp_tftp_args.bootp_retries - rc < DEFAULT_BOOT_RETRIES) obp_tftp_args.bootp_retries = DEFAULT_BOOT_RETRIES; else |